|
| 1 | +using System; |
| 2 | +using System.Runtime.InteropServices; |
| 3 | + |
| 4 | +namespace Avalonia.X11 |
| 5 | +{ |
| 6 | + internal static unsafe class SMLib |
| 7 | + { |
| 8 | + private const string LibSm = "libSM.so.6"; |
| 9 | + |
| 10 | + [DllImport(LibSm, CharSet = CharSet.Ansi)] |
| 11 | + public static extern IntPtr SmcOpenConnection( |
| 12 | + [MarshalAs(UnmanagedType.LPWStr)] string networkId, |
| 13 | + IntPtr content, |
| 14 | + int xsmpMajorRev, |
| 15 | + int xsmpMinorRev, |
| 16 | + ulong mask, |
| 17 | + ref SmcCallbacks callbacks, |
| 18 | + [MarshalAs(UnmanagedType.LPWStr)] [Out] |
| 19 | + out string previousId, |
| 20 | + [MarshalAs(UnmanagedType.LPWStr)] [Out] |
| 21 | + out string clientIdRet, |
| 22 | + int errorLength, |
| 23 | + [Out] char[] errorStringRet); |
| 24 | + |
| 25 | + [DllImport(LibSm, CallingConvention = CallingConvention.StdCall)] |
| 26 | + public static extern int SmcCloseConnection( |
| 27 | + IntPtr smcConn, |
| 28 | + int count, |
| 29 | + string[] reasonMsgs |
| 30 | + ); |
| 31 | + |
| 32 | + [DllImport(LibSm, CallingConvention = CallingConvention.StdCall)] |
| 33 | + public static extern void SmcSaveYourselfDone( |
| 34 | + IntPtr smcConn, |
| 35 | + bool success |
| 36 | + ); |
| 37 | + |
| 38 | + [DllImport(LibSm, CallingConvention = CallingConvention.StdCall)] |
| 39 | + public static extern int SmcInteractRequest( |
| 40 | + IntPtr smcConn, |
| 41 | + SmDialogValue dialogType, |
| 42 | + IntPtr interactProc, |
| 43 | + IntPtr clientData |
| 44 | + ); |
| 45 | + |
| 46 | + [DllImport(LibSm, CallingConvention = CallingConvention.StdCall)] |
| 47 | + public static extern void SmcInteractDone( |
| 48 | + IntPtr smcConn, |
| 49 | + bool success |
| 50 | + ); |
| 51 | + |
| 52 | + [DllImport(LibSm, CallingConvention = CallingConvention.StdCall)] |
| 53 | + public static extern IntPtr SmcGetIceConnection( |
| 54 | + IntPtr smcConn |
| 55 | + ); |
| 56 | + |
| 57 | + [DllImport(LibSm, CallingConvention = CallingConvention.StdCall)] |
| 58 | + public static extern IntPtr SmcSetErrorHandler( |
| 59 | + IntPtr handler |
| 60 | + ); |
| 61 | + |
| 62 | + public enum SmDialogValue |
| 63 | + { |
| 64 | + SmDialogError = 0 |
| 65 | + } |
| 66 | + |
| 67 | + [StructLayout(LayoutKind.Sequential)] |
| 68 | + public struct SmcCallbacks |
| 69 | + { |
| 70 | + public IntPtr SaveYourself; |
| 71 | + private readonly IntPtr Unused0; |
| 72 | + public IntPtr Die; |
| 73 | + private readonly IntPtr Unused1; |
| 74 | + public IntPtr SaveComplete; |
| 75 | + private readonly IntPtr Unused2; |
| 76 | + public IntPtr ShutdownCancelled; |
| 77 | + private readonly IntPtr Unused3; |
| 78 | + } |
| 79 | + |
| 80 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 81 | + public delegate void IceWatchProc( |
| 82 | + IntPtr iceConn, |
| 83 | + IntPtr clientData, |
| 84 | + bool opening, |
| 85 | + IntPtr* watchData |
| 86 | + ); |
| 87 | + |
| 88 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 89 | + public delegate void SmcDieProc( |
| 90 | + IntPtr smcConn, |
| 91 | + IntPtr clientData |
| 92 | + ); |
| 93 | + |
| 94 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 95 | + public delegate void SmcInteractProc( |
| 96 | + IntPtr smcConn, |
| 97 | + IntPtr clientData |
| 98 | + ); |
| 99 | + |
| 100 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 101 | + public delegate void SmcSaveCompleteProc( |
| 102 | + IntPtr smcConn, |
| 103 | + IntPtr clientData |
| 104 | + ); |
| 105 | + |
| 106 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 107 | + public delegate void SmcSaveYourselfProc( |
| 108 | + IntPtr smcConn, |
| 109 | + IntPtr clientData, |
| 110 | + int saveType, |
| 111 | + bool shutdown, |
| 112 | + int interactStyle, |
| 113 | + bool fast |
| 114 | + ); |
| 115 | + |
| 116 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 117 | + public delegate void SmcShutdownCancelledProc( |
| 118 | + IntPtr smcConn, |
| 119 | + IntPtr clientData |
| 120 | + ); |
| 121 | + |
| 122 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] |
| 123 | + public delegate void SmcErrorHandler( |
| 124 | + IntPtr smcConn, |
| 125 | + bool swap, |
| 126 | + int offendingMinorOpcode, |
| 127 | + ulong offendingSequence, |
| 128 | + int errorClass, |
| 129 | + int severity, |
| 130 | + IntPtr values |
| 131 | + ); |
| 132 | + } |
| 133 | +} |
0 commit comments