diff options
Diffstat (limited to 'src/backends/Display.cs')
| -rw-r--r-- | src/backends/Display.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/backends/Display.cs b/src/backends/Display.cs new file mode 100644 index 00000000..05832ab1 --- /dev/null +++ b/src/backends/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 = XOpenDisplay(IntPtr.Zero); + if (handle == IntPtr.Zero) + throw new NotSupportedException("[XLib] Failed to open display."); + + screen = 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 + + + } +} |