diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-11-13 14:48:41 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-11-13 14:48:41 +0100 |
| commit | e6541b353e7a0ecfd2e514e5c9c6f6c9c1ba96b1 (patch) | |
| tree | 8f3e5ecd92e3a6b5a328e514d6c14fa703bba9e6 /src/XLib/Display.cs | |
| parent | 65820f61457262b631eba35283c55135aecbc5f2 (diff) | |
first try with xlib
Diffstat (limited to 'src/XLib/Display.cs')
| -rw-r--r-- | src/XLib/Display.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/XLib/Display.cs b/src/XLib/Display.cs new file mode 100644 index 00000000..7e973b88 --- /dev/null +++ b/src/XLib/Display.cs @@ -0,0 +1,64 @@ +using System; +using System.Runtime.InteropServices; + +namespace XLib +{ + public class Display : IDisposable + { + internal IntPtr handle; + internal Int32 screen; + IntPtr lastEvent; + + public Display() + { + handle = NativeMethods.XOpenDisplay(IntPtr.Zero); + if (handle == IntPtr.Zero) + throw new NotSupportedException("[XLib] Failed to open display."); + + screen = NativeMethods.XDefaultScreen(handle); + lastEvent = Marshal.AllocHGlobal(96); + } + + /*public IntPtr NextEvent { + get { + NativeMethods.XNextEvent(handle, lastEvent); + return lastEvent; + } + }*/ + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + //Marshal.FreeHGlobal (lastEvent); + NativeMethods.XCloseDisplay (handle); + + disposedValue = true; + } + } + + // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~Display() { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + #endregion + + + } +} |