From c35e98f984467d945ad5ff7bd376763417584d84 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Fri, 11 Sep 2020 10:26:07 +0000 Subject: [PATCH] fix opengl on glx, cleanup --- GLWidget/GLWidget.cs | 15 +- GLWidget/GLWidget.csproj | 1 - GLWidget/GTKBindingHelper.cs | 111 - GLWidget/GraphicsContext.cs | 204 -- GLWidget/OpenTK/BindingsBase.cs | 2 +- GLWidget/OpenTK/DisplayDevice.cs | 223 -- GLWidget/OpenTK/Platform/DisplayDeviceBase.cs | 3 - .../OpenTK/Platform/IDisplayDeviceDriver.cs | 2 - .../Platform/Linux/LinuxDisplayDriver.cs | 28 - .../MacOS/QuartzDisplayDeviceDriver.cs | 65 - GLWidget/OpenTK/Platform/Windows/API.cs | 1801 +---------------- .../OpenTK/Platform/Windows/Bindings/Wgl.cs | 114 +- GLWidget/OpenTK/Platform/Windows/WglHelper.cs | 12 +- .../Platform/Windows/WinDisplayDevice.cs | 27 - .../OpenTK/Platform/Windows/WinGLContext.cs | 6 +- .../Platform/Windows/WinGraphicsMode.cs | 8 +- GLWidget/OpenTK/Platform/X11/API.cs | 1149 +---------- GLWidget/OpenTK/Platform/X11/Bindings/Glx.cs | 94 - GLWidget/OpenTK/Platform/X11/Bindings/Xkb.cs | 304 --- GLWidget/OpenTK/Platform/X11/Functions.cs | 26 +- .../OpenTK/Platform/X11/X11DisplayDevice.cs | 82 +- GLWidgetTestGTK3/GLWidgetTestGTK3.csproj | 3 +- 22 files changed, 83 insertions(+), 4197 deletions(-) delete mode 100644 GLWidget/GraphicsContext.cs delete mode 100644 GLWidget/OpenTK/Platform/X11/Bindings/Xkb.cs diff --git a/GLWidget/GLWidget.cs b/GLWidget/GLWidget.cs index eb88efa..4dac0ef 100644 --- a/GLWidget/GLWidget.cs +++ b/GLWidget/GLWidget.cs @@ -198,10 +198,7 @@ namespace OpenTK private static void OnGraphicsContextInitialized() { - if (GraphicsContextInitialized != null) - { - GraphicsContextInitialized(null, EventArgs.Empty); - } + GraphicsContextInitialized?.Invoke(null, EventArgs.Empty); } // Called when the first GraphicsContext is being destroyed in the case of GraphicsContext.ShareContexts == True; @@ -209,10 +206,7 @@ namespace OpenTK private static void OnGraphicsContextShuttingDown() { - if (GraphicsContextShuttingDown != null) - { - GraphicsContextShuttingDown(null, EventArgs.Empty); - } + GraphicsContextShuttingDown?.Invoke(null, EventArgs.Empty); } // Called when this GLWidget has a valid GraphicsContext @@ -220,10 +214,7 @@ namespace OpenTK protected virtual void OnInitialized() { - if (Initialized != null) - { - Initialized(this, EventArgs.Empty); - } + Initialized?.Invoke(this, EventArgs.Empty); } // Called when this GLWidget needs to render a frame diff --git a/GLWidget/GLWidget.csproj b/GLWidget/GLWidget.csproj index b86b1cb..1908253 100644 --- a/GLWidget/GLWidget.csproj +++ b/GLWidget/GLWidget.csproj @@ -9,7 +9,6 @@ - diff --git a/GLWidget/GTKBindingHelper.cs b/GLWidget/GTKBindingHelper.cs index 74c149c..98b4cb0 100644 --- a/GLWidget/GTKBindingHelper.cs +++ b/GLWidget/GTKBindingHelper.cs @@ -115,11 +115,6 @@ namespace OpenTK LoadBindings("OpenGL4"); } - private static IntPtr GetProcAddressWgl(string function) - { - return UnsafeNativeMethods.wglGetProcAddress(function); - } - private static void LoadLibraries() { if (Loaded) @@ -142,30 +137,6 @@ namespace OpenTK Loaded = true; } - public static IntPtr GetWindowHandle(IntPtr handle) - { - if(CurrentPlatform == OSPlatform.Windows) - { - return UnsafeNativeMethods.gdk_win32_window_get_handle(handle); - } - else - { - return UnsafeNativeMethods.gdk_x11_window_get_xid(handle); - } - } - - public static IntPtr GetDisplayHandle(IntPtr handle) - { - if (CurrentPlatform == OSPlatform.Windows) - { - return IntPtr.Zero; - } - else - { - return UnsafeNativeMethods.gdk_x11_display_get_xdisplay(handle); - } - } - internal static IntPtr GetLibraryHandle(string libraryPath, bool throws) { IntPtr libraryHandle; @@ -205,44 +176,8 @@ namespace OpenTK return symbol; } - public static void InitXThreads() - { - if (_threadsInitialized) - { - return; - } - - if (CurrentPlatform == OSPlatform.Linux) - { - _threadsInitialized = true; - - UnsafeNativeMethods.XInitThreads(); - } - } - internal static class UnsafeNativeMethods { - [DllImport("kernel32.dll", SetLastError = true)] - internal static extern IntPtr GetProcAddress(IntPtr handle, string funcname); - - [DllImport("kernel32.dll", SetLastError = true)] - internal static extern IntPtr LoadLibrary(string dllName); - - [DllImport(WglLibrary, EntryPoint = "wglGetProcAddress", ExactSpelling = true, SetLastError = true)] - public static extern IntPtr wglGetProcAddress(string lpszProc); - - [DllImport(WglLibrary, EntryPoint = "wglGetCurrentContext")] - public extern static IntPtr wglGetCurrentContext(); - - [DllImport(WglLibrary, EntryPoint = "wglGetCurrentDC")] - public static extern IntPtr wglGetCurrentDC(); - - [DllImport(WglLibrary, EntryPoint = "wglSwapBuffers", ExactSpelling = true)] - public static extern bool wglSwapBuffers(IntPtr hdc); - - [DllImport("opengl32.dll", SetLastError = true, EntryPoint = "wglMakeCurrent")] - public static extern bool WglMakeCurrent(IntPtr hdc, IntPtr hglrc); - [DllImport(OSXLibrary, EntryPoint = "NSIsSymbolNameDefined")] public static extern bool NSIsSymbolNameDefined(string s); @@ -251,41 +186,6 @@ namespace OpenTK [DllImport(OSXLibrary, EntryPoint = "NSAddressOfSymbol")] public static extern IntPtr NSAddressOfSymbol(IntPtr symbol); - - [DllImport("libX11.so.6")] - public extern static int XInitThreads(); - - [DllImport(OSXLibrary)] - public extern static int CGLSetCurrentContext(IntPtr ctx); - - [DllImport(OSXLibrary)] - public extern static IntPtr CGLGetCurrentContext(); - [DllImport(OSXLibrary)] - public extern static void CGLReleaseContext(IntPtr ctx); - [DllImport(OSXLibrary)] - public extern static int CGLFlushDrawable(IntPtr ctx); - - [DllImport(OSXLibrary)] - internal static extern int CGLDestroyContext(IntPtr ctx); - - [DllImport(OSXLibrary)] - internal static extern int CGLSetParameter(IntPtr ctx, int parameter, ref int value); - - [DllImport(GlxLibrary, EntryPoint = "glXGetCurrentContext")] - public static extern IntPtr glXGetCurrentContext(); - - [DllImport(GlxLibrary, EntryPoint = "glXGetProcAddress")] - public static extern IntPtr glXGetProcAddress(); - - [DllImport(GlxLibrary, EntryPoint = "glXSwapIntervalEXT")] - public static extern IntPtr glXSwapIntervalEXT(int interval); - - [DllImport(GlxLibrary, EntryPoint = "glXMakeCurrent")] - public static extern bool glXMakeCurrent(IntPtr display, IntPtr drawable, IntPtr context); - - [DllImport(GlxLibrary, EntryPoint = "glXSwapBuffers")] - public static extern void glXSwapBuffers(IntPtr display, IntPtr drawable); - public const int RTLD_LAZY = 1; public const int RTLD_NOW = 2; @@ -298,17 +198,6 @@ namespace OpenTK [DllImport("dl")] public static extern string dlerror(); - - public const string GdkNativeDll = "libgdk-3-0.dll"; - - [DllImport(GdkNativeDll, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr gdk_win32_window_get_handle(IntPtr raw); - - [DllImport("libgdk-3.so.0", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr gdk_x11_display_get_xdisplay(IntPtr raw); - - [DllImport("libgdk-3.so.0", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr gdk_x11_window_get_xid(IntPtr raw); } private static class Delegates diff --git a/GLWidget/GraphicsContext.cs b/GLWidget/GraphicsContext.cs deleted file mode 100644 index 90cf619..0000000 --- a/GLWidget/GraphicsContext.cs +++ /dev/null @@ -1,204 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using OpenGL; - -using static OpenTK.GTKBindingHelper; - -namespace OpenTK -{ - public interface ILegacyGraphicsContext - { - void MakeCurrent(); - void SwapBuffers(); - void ClearCurrent(); - void SwapInterval(int interval); - } - - public abstract class LegacyGraphicsContext : ILegacyGraphicsContext - { - public static IntPtr Display{ get; set; } - - public abstract void MakeCurrent(); - - public abstract void SwapBuffers(); - - public static void InitializeDefaults(IntPtr handle) - { - if (CurrentPlatform == OSPlatform.Windows) - { - IntPtr deviceContext = Wgl.GetDC(UnsafeNativeMethods.gdk_win32_window_get_handle(handle)); - - Wgl.PIXELFORMATDESCRIPTOR pfd = new Wgl.PIXELFORMATDESCRIPTOR(24); - - pfd.dwFlags |= Wgl.PixelFormatDescriptorFlags.DepthDontCare | Wgl.PixelFormatDescriptorFlags.DoublebufferDontCare | Wgl.PixelFormatDescriptorFlags.StereoDontCare; - - int pFormat = Wgl.ChoosePixelFormat(deviceContext, ref pfd); - - bool res = Wgl.DescribePixelFormat(deviceContext, pFormat, (uint)pfd.nSize, ref pfd) != 0; - - res = Wgl.SetPixelFormat(deviceContext, pFormat, ref pfd); - } - } - - public static ILegacyGraphicsContext GetCurrentContext(IntPtr handle) - { - var currentPlatform = CurrentPlatform; - - if(currentPlatform == OSPlatform.Windows){ - return WglGraphicsContext.GetCurrent(handle); - } - else if(currentPlatform == OSPlatform.Linux){ - if (Display == null || Display == IntPtr.Zero) - { - throw new InvalidOperationException("No Display set"); - } - return GlxGraphicsContext.GetCurrent(handle, Display); - } - else if (currentPlatform == OSPlatform.OSX) - { - return CglGraphicsContext.GetCurrent(); - } - - return null; - } - - public abstract void ClearCurrent(); - public abstract void SwapInterval(int interval); - } - - public class WglGraphicsContext : LegacyGraphicsContext - { - private delegate int wglSwapIntervalExtDelegate(int interval); - private static wglSwapIntervalExtDelegate wglSwapIntervalExt = null; - - private IntPtr _windowHandle; - private IntPtr _deviceContext; - - public WglGraphicsContext(IntPtr deviceContext, IntPtr graphicsContext, IntPtr windowHandle = default) - { - _deviceContext = deviceContext; - _graphicsContext = graphicsContext; - _windowHandle = windowHandle; - - IntPtr swapIntervalPointer = UnsafeNativeMethods.wglGetProcAddress("wglSwapIntervalEXT"); - - if(swapIntervalPointer != null && swapIntervalPointer != IntPtr.Zero) - { - wglSwapIntervalExt = (wglSwapIntervalExtDelegate)Marshal.GetDelegateForFunctionPointer( - swapIntervalPointer, typeof(wglSwapIntervalExtDelegate)); - } - } - - private IntPtr _graphicsContext; - - public static WglGraphicsContext GetCurrent(IntPtr windowHandle) - { - IntPtr dc = UnsafeNativeMethods.wglGetCurrentDC(); - IntPtr gc = UnsafeNativeMethods.wglGetCurrentContext(); - - return new WglGraphicsContext(dc, gc, windowHandle); - } - - public override void MakeCurrent() - { - UnsafeNativeMethods.WglMakeCurrent(_deviceContext, _graphicsContext); - } - - public override void SwapBuffers() - { - UnsafeNativeMethods.wglSwapBuffers(_deviceContext); - } - - public override void ClearCurrent() - { - UnsafeNativeMethods.WglMakeCurrent(_deviceContext, IntPtr.Zero); - } - - public override void SwapInterval(int interval) - { - wglSwapIntervalExt?.Invoke(interval); - } - } - - public class GlxGraphicsContext : LegacyGraphicsContext - { - private IntPtr _windowHandle; - - public static GlxGraphicsContext GetCurrent(IntPtr windowHandle, IntPtr display) - { - var gc = UnsafeNativeMethods.glXGetCurrentContext(); - - return new GlxGraphicsContext(windowHandle, gc, display); - } - - public GlxGraphicsContext(IntPtr windowHandle, IntPtr graphicsContext, IntPtr display) - { - _windowHandle = UnsafeNativeMethods.gdk_x11_window_get_xid(windowHandle); - _display = UnsafeNativeMethods.gdk_x11_display_get_xdisplay(display); - _graphicsContext = graphicsContext; - } - - private IntPtr _graphicsContext; - private IntPtr _display; - - public override void MakeCurrent() - { - UnsafeNativeMethods.glXMakeCurrent(_display, _windowHandle, _graphicsContext); - } - - public override void SwapBuffers() - { - UnsafeNativeMethods.glXSwapBuffers(_display, _windowHandle); - } - - public override void ClearCurrent() - { - UnsafeNativeMethods.glXMakeCurrent(_display, _windowHandle, IntPtr.Zero); - } - - public override void SwapInterval(int interval) - { - UnsafeNativeMethods.glXSwapIntervalEXT(interval); - } - } - - public class CglGraphicsContext : LegacyGraphicsContext - { - private IntPtr _windowHandle; - - public static CglGraphicsContext GetCurrent() - { - var gc = UnsafeNativeMethods.CGLGetCurrentContext(); - - return new CglGraphicsContext(gc); - } - - public CglGraphicsContext(IntPtr graphicsContext) - { - _graphicsContext = graphicsContext; - } - - private IntPtr _graphicsContext; - private IntPtr _display; - - public override void MakeCurrent() - { - UnsafeNativeMethods.CGLSetCurrentContext(_graphicsContext); - } - - public override void SwapBuffers() - { - UnsafeNativeMethods.CGLFlushDrawable(_graphicsContext); - } - - public override void ClearCurrent() - { - UnsafeNativeMethods.CGLSetCurrentContext(IntPtr.Zero); - } - - public override void SwapInterval(int interval) - { - UnsafeNativeMethods.CGLSetParameter(_graphicsContext, 222 , ref interval); - } - } -} \ No newline at end of file diff --git a/GLWidget/OpenTK/BindingsBase.cs b/GLWidget/OpenTK/BindingsBase.cs index aa40693..ed9aeee 100644 --- a/GLWidget/OpenTK/BindingsBase.cs +++ b/GLWidget/OpenTK/BindingsBase.cs @@ -178,7 +178,7 @@ namespace OpenTK } catch (OutOfMemoryException) { - for (i = i - 1; i >= 0; --i) + for (i -= 1; i >= 0; --i) { Marshal.FreeHGlobal(Marshal.ReadIntPtr(ptr, i * IntPtr.Size)); } diff --git a/GLWidget/OpenTK/DisplayDevice.cs b/GLWidget/OpenTK/DisplayDevice.cs index 180c484..ed8f5f3 100644 --- a/GLWidget/OpenTK/DisplayDevice.cs +++ b/GLWidget/OpenTK/DisplayDevice.cs @@ -181,80 +181,6 @@ namespace OpenTK } } - /// Changes the resolution of the DisplayDevice. - /// The resolution to set. - /// Thrown if the requested resolution could not be set. - /// If the specified resolution is null, this function will restore the original DisplayResolution. - public void ChangeResolution(DisplayResolution resolution) - { - if (resolution == null) - { - this.RestoreResolution(); - } - - if (resolution == current_resolution) - { - return; - } - - //effect.FadeOut(); - - if (implementation.TryChangeResolution(this, resolution)) - { - if (OriginalResolution == null) - { - OriginalResolution = current_resolution; - } - current_resolution = resolution; - } - else - { - throw new Graphics.GraphicsModeException(String.Format("Device {0}: Failed to change resolution to {1}.", - this, resolution)); - } - - //effect.FadeIn(); - } - - /// Changes the resolution of the DisplayDevice. - /// The new width of the DisplayDevice. - /// The new height of the DisplayDevice. - /// The new bits per pixel of the DisplayDevice. - /// The new refresh rate of the DisplayDevice. - /// Thrown if the requested resolution could not be set. - public void ChangeResolution(int width, int height, int bitsPerPixel, float refreshRate) - { - this.ChangeResolution(this.SelectResolution(width, height, bitsPerPixel, refreshRate)); - } - - /// Restores the original resolution of the DisplayDevice. - /// Thrown if the original resolution could not be restored. - public void RestoreResolution() - { - if (OriginalResolution != null) - { - //effect.FadeOut(); - - if (implementation.TryRestoreResolution(this)) - { - current_resolution = OriginalResolution; - OriginalResolution = null; - } - else - { - throw new Graphics.GraphicsModeException(String.Format("Device {0}: Failed to restore resolution.", this)); - } - - //effect.FadeIn(); - } - } - - /// Gets the default (primary) display of this system. - public static DisplayDevice Default - { - get { return implementation.GetDisplay(DisplayIndex.Primary); } - } - /// /// Gets the for the specified . /// @@ -270,22 +196,6 @@ namespace OpenTK /// internal DisplayResolution OriginalResolution { get; set; } - internal static DisplayDevice FromPoint(int x, int y) - { - for (DisplayIndex i = DisplayIndex.First; i < DisplayIndex.Sixth; i++) - { - DisplayDevice display = DisplayDevice.GetDisplay(i); - if (display != null) - { - if (display.Bounds.Contains(x, y)) - { - return display; - } - } - } - return null; - } - private DisplayResolution FindResolution(int width, int height, int bitsPerPixel, float refreshRate) { return available_resolutions.Find(delegate(DisplayResolution test) @@ -308,138 +218,5 @@ namespace OpenTK Bounds.ToString(), available_resolutions.Count); } - ///// Determines whether the specified DisplayDevices are equal. - ///// The System.Object to check against. - ///// True if the System.Object is an equal DisplayDevice; false otherwise. - //public override bool Equals(object obj) - //{ - // if (obj is DisplayDevice) - // { - // DisplayDevice dev = (DisplayDevice)obj; - // return - // IsPrimary == dev.IsPrimary && - // current_resolution == dev.current_resolution && - // available_resolutions.Count == dev.available_resolutions.Count; - // } - - // return false; - //} - - ///// Returns a unique hash representing this DisplayDevice. - ///// A System.Int32 that may serve as a hash code for this DisplayDevice. - ////public override int GetHashCode() - //{ - // return current_resolution.GetHashCode() ^ IsPrimary.GetHashCode() ^ available_resolutions.Count; - //} } -#if false - class FadeEffect : IDisposable - { - List
forms = new List(); - double opacity_step = 0.04; - int sleep_step; - - internal FadeEffect() - { - foreach (Screen s in Screen.AllScreens) - { - Form form = new Form(); - form.ShowInTaskbar = false; - form.StartPosition = FormStartPosition.Manual; - form.WindowState = FormWindowState.Maximized; - form.FormBorderStyle = FormBorderStyle.None; - form.TopMost = true; - - form.BackColor = System.Drawing.Color.Black; - forms.Add(form); - } - - sleep_step = 10 / forms.Count; - MoveToStartPositions(); - } - - void MoveToStartPositions() - { - int count = 0; - foreach (Screen s in Screen.AllScreens) - { - // forms[count++].Location = new System.Drawing.Point(s.Bounds.X, s.Bounds.Y); - //forms[count].Size = new System.Drawing.Size(4096, 4096); - count++; - } - } - - bool FadedOut - { - get - { - bool ready = true; - foreach (Form form in forms) - ready = ready && form.Opacity >= 1.0; - - return ready; - } - } - - bool FadedIn - { - get - { - bool ready = true; - foreach (Form form in forms) - ready = ready && form.Opacity <= 0.0; - - return ready; - } - } - - internal void FadeOut() - { - MoveToStartPositions(); - - foreach (Form form in forms) - { - form.Opacity = 0.0; - form.Visible = true; - } - - while (!FadedOut) - { - foreach (Form form in forms) - { - form.Opacity += opacity_step; - form.Refresh(); - } - Thread.Sleep(sleep_step); - } - } - - internal void FadeIn() - { - MoveToStartPositions(); - - foreach (Form form in forms) - form.Opacity = 1.0; - - while (!FadedIn) - { - foreach (Form form in forms) - { - form.Opacity -= opacity_step; - form.Refresh(); - } - Thread.Sleep(sleep_step); - } - - foreach (Form form in forms) - form.Visible = false; - } - - public void Dispose() - { - foreach (Form form in forms) - form.Dispose(); - } - } -#endif } diff --git a/GLWidget/OpenTK/Platform/DisplayDeviceBase.cs b/GLWidget/OpenTK/Platform/DisplayDeviceBase.cs index 9e95330..dd00b5a 100644 --- a/GLWidget/OpenTK/Platform/DisplayDeviceBase.cs +++ b/GLWidget/OpenTK/Platform/DisplayDeviceBase.cs @@ -38,9 +38,6 @@ namespace OpenTK.Platform protected readonly List AvailableDevices = new List(); protected DisplayDevice Primary; - public abstract bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution); - public abstract bool TryRestoreResolution(DisplayDevice device); - // Gets the DisplayDevice that corresponds to the specified index. public virtual DisplayDevice GetDisplay(DisplayIndex index) { diff --git a/GLWidget/OpenTK/Platform/IDisplayDeviceDriver.cs b/GLWidget/OpenTK/Platform/IDisplayDeviceDriver.cs index 8ae9c37..af702c8 100644 --- a/GLWidget/OpenTK/Platform/IDisplayDeviceDriver.cs +++ b/GLWidget/OpenTK/Platform/IDisplayDeviceDriver.cs @@ -27,8 +27,6 @@ namespace OpenTK.Platform { internal interface IDisplayDeviceDriver { - bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution); - bool TryRestoreResolution(DisplayDevice device); DisplayDevice GetDisplay(DisplayIndex displayIndex); } } diff --git a/GLWidget/OpenTK/Platform/Linux/LinuxDisplayDriver.cs b/GLWidget/OpenTK/Platform/Linux/LinuxDisplayDriver.cs index dec3b60..8a78177 100644 --- a/GLWidget/OpenTK/Platform/Linux/LinuxDisplayDriver.cs +++ b/GLWidget/OpenTK/Platform/Linux/LinuxDisplayDriver.cs @@ -380,34 +380,6 @@ namespace OpenTK.Platform.Linux } return null; } - - public override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution) - { - unsafe - { - LinuxDisplay display = (LinuxDisplay)device.Id; - ModeInfo* mode = GetModeInfo(display, resolution); - int connector_id = display.pConnector->connector_id; - if (mode != null) - { - return Drm.ModeSetCrtc(FD, display.Id, 0, 0, 0, - &connector_id, 1, mode) == 0; - } - return false; - } - } - - public override bool TryRestoreResolution(DisplayDevice device) - { - unsafe - { - LinuxDisplay display = (LinuxDisplay)device.Id; - ModeInfo mode = display.OriginalMode; - int connector_id = display.pConnector->connector_id; - return Drm.ModeSetCrtc(FD, display.Id, 0, 0, 0, - &connector_id, 1, &mode) == 0; - } - } } } diff --git a/GLWidget/OpenTK/Platform/MacOS/QuartzDisplayDeviceDriver.cs b/GLWidget/OpenTK/Platform/MacOS/QuartzDisplayDeviceDriver.cs index 666a8bd..451a622 100644 --- a/GLWidget/OpenTK/Platform/MacOS/QuartzDisplayDeviceDriver.cs +++ b/GLWidget/OpenTK/Platform/MacOS/QuartzDisplayDeviceDriver.cs @@ -140,70 +140,5 @@ namespace OpenTK.Platform.MacOS } } - static internal IntPtr HandleTo(DisplayDevice displayDevice) - { - return (IntPtr)displayDevice.Id; - } - - private Dictionary storedModes = new Dictionary(); - private List displaysCaptured = new List(); - - public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution) - { - IntPtr display = HandleTo(device); - IntPtr currentModePtr = CG.DisplayCurrentMode(display); - - if (storedModes.ContainsKey(display) == false) - { - storedModes.Add(display, currentModePtr); - } - - IntPtr displayModesPtr = CG.DisplayAvailableModes(display); - CFArray displayModes = new CFArray(displayModesPtr); - - for (int j = 0; j < displayModes.Count; j++) - { - CFDictionary dict = new CFDictionary(displayModes[j]); - - int width = (int)dict.GetNumberValue("Width"); - int height = (int)dict.GetNumberValue("Height"); - int bpp = (int)dict.GetNumberValue("BitsPerPixel"); - double freq = dict.GetNumberValue("RefreshRate"); - - if (width == resolution.Width && height == resolution.Height && bpp == resolution.BitsPerPixel && System.Math.Abs(freq - resolution.RefreshRate) < 1e-6) - { -// if (displaysCaptured.Contains(display) == false) -// { -// CG.DisplayCapture(display); -// } - - Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq); - - CG.DisplaySwitchToMode(display, displayModes[j]); - - return true; - } - - } - return false; - } - - public sealed override bool TryRestoreResolution(DisplayDevice device) - { - IntPtr display = HandleTo(device); - - if (storedModes.ContainsKey(display)) - { - Debug.Print("Restoring resolution."); - - CG.DisplaySwitchToMode(display, storedModes[display]); - //CG.DisplayRelease(display); - displaysCaptured.Remove(display); - - return true; - } - - return false; - } } } diff --git a/GLWidget/OpenTK/Platform/Windows/API.cs b/GLWidget/OpenTK/Platform/Windows/API.cs index a3a97c7..790f571 100644 --- a/GLWidget/OpenTK/Platform/Windows/API.cs +++ b/GLWidget/OpenTK/Platform/Windows/API.cs @@ -113,310 +113,6 @@ namespace OpenTK.Platform.Windows internal static class Functions { - [DllImport("shell32.dll", CharSet = CharSet.Auto)] - internal static extern bool DragAcceptFiles( - IntPtr handle, - [MarshalAs(UnmanagedType.Bool)] bool fAccept - ); - - [DllImport("shell32.dll", CharSet = CharSet.Auto)] - internal static extern uint DragQueryFile( - HDROP hDrop, - uint iFile, - IntPtr lpszFile, - uint cch - ); - - [DllImport("shell32.dll")] - internal static extern void DragFinish( - HDROP hDrop - ); - - // WINUSERAPI BOOL WINAPI SetWindowPos(__in HWND hWnd, __in_opt HWND hWndInsertAfter, - // __in int X, __in int Y, __in int cx, __in int cy, __in UINT uFlags); - - [DllImport("user32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool SetWindowPos( - IntPtr handle, - IntPtr insertAfter, - int x, int y, int cx, int cy, - SetWindowPosFlags flags - ); - - /// - /// Calculates the required size of the window rectangle, based on the desired client-rectangle size. The window rectangle can then be passed to the CreateWindow function to create a window whose client area is the desired size. - /// - /// [in, out] Pointer to a RECT structure that contains the coordinates of the top-left and bottom-right corners of the desired client area. When the function returns, the structure contains the coordinates of the top-left and bottom-right corners of the window to accommodate the desired client area. - /// [in] Specifies the window style of the window whose required size is to be calculated. Note that you cannot specify the WS_OVERLAPPED style. - /// [in] Specifies whether the window has a menu. - /// - /// If the function succeeds, the return value is nonzero. - /// If the function fails, the return value is zero. To get extended error information, call GetLastError. - /// - /// - /// A client rectangle is the smallest rectangle that completely encloses a client area. A window rectangle is the smallest rectangle that completely encloses the window, which includes the client area and the nonclient area. - /// The AdjustWindowRect function does not add extra space when a menu bar wraps to two or more rows. - /// The AdjustWindowRect function does not take the WS_VSCROLL or WS_HSCROLL styles into account. To account for the scroll bars, call the GetSystemMetrics function with SM_CXVSCROLL or SM_CYHSCROLL. - /// Found Winuser.h, user32.dll - /// - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal static extern BOOL AdjustWindowRect([In, Out] ref Win32Rectangle lpRect, WindowStyle dwStyle, BOOL bMenu); - - [DllImport("user32.dll", EntryPoint = "AdjustWindowRectEx", CallingConvention = CallingConvention.StdCall, SetLastError = true), SuppressUnmanagedCodeSecurity] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool AdjustWindowRectEx( - ref Win32Rectangle lpRect, - WindowStyle dwStyle, - [MarshalAs(UnmanagedType.Bool)] bool bMenu, - ExtendedWindowStyle dwExStyle); - - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - internal static extern IntPtr CreateWindowEx( - ExtendedWindowStyle ExStyle, - IntPtr ClassAtom, - IntPtr WindowName, - WindowStyle Style, - int X, int Y, - int Width, int Height, - IntPtr HandleToParentWindow, - IntPtr Menu, - IntPtr Instance, - IntPtr Param); - - [DllImport("user32.dll", SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool DestroyWindow(IntPtr windowHandle); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - internal static extern ushort RegisterClass(ref WindowClass window_class); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - internal static extern ushort RegisterClassEx(ref ExtendedWindowClass window_class); - - [DllImport("user32.dll", SetLastError = true)] - internal static extern BOOL IsWindowUnicode(HWND hwnd); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - internal static extern short UnregisterClass([MarshalAs(UnmanagedType.LPTStr)] LPCTSTR className, IntPtr instance); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - internal static extern short UnregisterClass(IntPtr className, IntPtr instance); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - internal static extern BOOL GetClassInfoEx(HINSTANCE hinst, - [MarshalAs(UnmanagedType.LPTStr)] LPCTSTR lpszClass, ref ExtendedWindowClass lpwcx); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - internal static extern BOOL GetClassInfoEx(HINSTANCE hinst, UIntPtr lpszClass, ref ExtendedWindowClass lpwcx); - - [SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - internal static extern LRESULT CallWindowProc(WNDPROC lpPrevWndFunc, HWND hWnd, WindowMessage Msg, - WPARAM wParam, LPARAM lParam); - - // SetWindowLongPtr does not exist on x86 platforms (it's a macro that resolves to SetWindowLong). - // We need to detect if we are on x86 or x64 at runtime and call the correct function - // (SetWindowLongPtr on x64 or SetWindowLong on x86). Fun! - internal static IntPtr SetWindowLong(IntPtr handle, GetWindowLongOffsets item, IntPtr newValue) - { - // SetWindowPos defines its error condition as an IntPtr.Zero retval and a non-0 GetLastError. - // We need to SetLastError(0) to ensure we are not detecting on older error condition (from another function). - - IntPtr retval = IntPtr.Zero; - SetLastError(0); - - if (IntPtr.Size == 4) - { - retval = new IntPtr(SetWindowLongInternal(handle, item, newValue.ToInt32())); - } - else - { - retval = SetWindowLongPtrInternal(handle, item, newValue); - } - - if (retval == IntPtr.Zero) - { - int error = Marshal.GetLastWin32Error(); - if (error != 0) - { - throw new PlatformException(String.Format("Failed to modify window border. Error: {0}", error)); - } - } - - return retval; - } - - internal static IntPtr SetWindowLong(IntPtr handle, WindowProcedure newValue) - { - return SetWindowLong(handle, GetWindowLongOffsets.WNDPROC, Marshal.GetFunctionPointerForDelegate(newValue)); - } - - [SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true, EntryPoint = "SetWindowLong")] - private static extern LONG SetWindowLongInternal(HWND hWnd, GetWindowLongOffsets nIndex, LONG dwNewLong); - - [SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true, EntryPoint = "SetWindowLongPtr")] - private static extern LONG_PTR SetWindowLongPtrInternal(HWND hWnd, GetWindowLongOffsets nIndex, LONG_PTR dwNewLong); - - [SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true, EntryPoint = "SetWindowLong")] - private static extern LONG SetWindowLongInternal(HWND hWnd, GetWindowLongOffsets nIndex, - [MarshalAs(UnmanagedType.FunctionPtr)]WindowProcedure dwNewLong); - - [SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true, EntryPoint = "SetWindowLongPtr")] - private static extern LONG_PTR SetWindowLongPtrInternal(HWND hWnd, GetWindowLongOffsets nIndex, - [MarshalAs(UnmanagedType.FunctionPtr)]WindowProcedure dwNewLong); - - internal static UIntPtr GetWindowLong(IntPtr handle, GetWindowLongOffsets index) - { - if (IntPtr.Size == 4) - { - return (UIntPtr)GetWindowLongInternal(handle, index); - } - - return GetWindowLongPtrInternal(handle, index); - } - - [SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true, EntryPoint = "GetWindowLong")] - private static extern ULONG GetWindowLongInternal(HWND hWnd, GetWindowLongOffsets nIndex); - - [SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true, EntryPoint = "GetWindowLongPtr")] - private static extern UIntPtr GetWindowLongPtrInternal(HWND hWnd, GetWindowLongOffsets nIndex); - - /// - /// Low-level WINAPI function that checks the next message in the queue. - /// - /// The pending message (if any) is stored here. - /// Not used - /// Not used - /// Not used - /// Not used - /// True if there is a message pending. - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("User32.dll", CharSet = CharSet.Unicode), CLSCompliant(false)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, PeekMessageFlags flags); - - /// - /// Low-level WINAPI function that retrieves the next message in the queue. - /// - /// The pending message (if any) is stored here. - /// Not used - /// Not used - /// Not used - /// - /// Nonzero indicates that the function retrieves a message other than WM_QUIT. - /// Zero indicates that the function retrieves the WM_QUIT message, or that lpMsg is an invalid pointer. - /// –1 indicates that an error occurred — for example, the function fails if hWnd is an invalid window handle. - /// To get extended error information, call GetLastError. - /// - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("User32.dll", CharSet = CharSet.Unicode), CLSCompliant(false)] - //[return: MarshalAs(UnmanagedType.Bool)] - internal static extern INT GetMessage(ref MSG msg, - IntPtr windowHandle, int messageFilterMin, int messageFilterMax); - - /// - /// Retrieves the message time for the last message retrieved by the - /// GetMessage function. The time is a long integer that specifies the - /// elapsed time, in milliseconds, from the time the system was started - /// to the time the message was created (that is, placed in the thread's - /// message queue). - /// - /// The return value specifies the message time. - [DllImport("User32.dll")] - internal static extern int GetMessageTime(); - - [DllImport("user32.dll", CharSet = CharSet.Unicode)] - internal static extern LRESULT SendMessage(HWND hWnd, WindowMessage Msg, WPARAM wParam, LPARAM lParam); - - [CLSCompliant(false)] - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("User32.dll", CharSet = CharSet.Unicode)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern BOOL PostMessage( - HWND hWnd, - WindowMessage Msg, - WPARAM wParam, - LPARAM lParam - ); - - [DllImport("User32.dll", CharSet = CharSet.Auto)] - internal static extern void PostQuitMessage(int exitCode); - - [SuppressUnmanagedCodeSecurity] - [DllImport("User32.dll", CharSet = CharSet.Unicode), CLSCompliant(false)] - internal static extern LRESULT DispatchMessage(ref MSG msg); - - [SuppressUnmanagedCodeSecurity] - [DllImport("User32.dll", CharSet = CharSet.Unicode), CLSCompliant(false)] - internal static extern BOOL TranslateMessage(ref MSG lpMsg); - - /// - /// Indicates the type of messages found in the calling thread's message queue. - /// - /// - /// - /// The high-order word of the return value indicates the types of messages currently in the queue. - /// The low-order word indicates the types of messages that have been added to the queue and that are still - /// in the queue since the last call to the GetQueueStatus, GetMessage, or PeekMessage function. - /// - /// - /// The presence of a QS_ flag in the return value does not guarantee that - /// a subsequent call to the GetMessage or PeekMessage function will return a message. - /// GetMessage and PeekMessage perform some internal filtering that may cause the message - /// to be processed internally. For this reason, the return value from GetQueueStatus - /// should be considered only a hint as to whether GetMessage or PeekMessage should be called. - /// - /// The QS_ALLPOSTMESSAGE and QS_POSTMESSAGE flags differ in when they are cleared. - /// QS_POSTMESSAGE is cleared when you call GetMessage or PeekMessage, whether or not you are filtering messages. - /// QS_ALLPOSTMESSAGE is cleared when you call GetMessage or PeekMessage without filtering messages - /// (wMsgFilterMin and wMsgFilterMax are 0). This can be useful when you call PeekMessage multiple times - /// to get messages in different ranges. - /// - /// - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("User32.dll", CharSet = CharSet.Auto)] - internal static extern DWORD GetQueueStatus([MarshalAs(UnmanagedType.U4)] QueueStatusFlags flags); - - [DllImport("User32.dll", CharSet = CharSet.Unicode)] - public extern static IntPtr DefWindowProc(HWND hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam); - - /// - /// Sets the timing resolution of the GetTime (?) method. - /// - /// Timing resolution in msec (?) - /// (?) - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("winmm.dll")] - internal static extern IntPtr TimeBeginPeriod(int period); - - /// - /// - /// - /// - /// - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("kernel32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency); - - /// - /// - /// - /// - /// - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("kernel32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool QueryPerformanceCounter(ref long PerformanceCount); - /// /// /// @@ -463,13 +159,6 @@ namespace OpenTK.Platform.Windows [DllImport("kernel32.dll")] internal static extern IntPtr GetProcAddress(IntPtr handle, IntPtr funcname); - - [DllImport("kernel32.dll")] - internal static extern void SetLastError(DWORD dwErrCode); - - [DllImport("kernel32.dll")] - internal static extern IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPTStr)]string module_name); - /// /// /// @@ -487,285 +176,12 @@ namespace OpenTK.Platform.Windows [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool FreeLibrary(IntPtr handle); - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true)] - internal static extern SHORT GetAsyncKeyState(VirtualKeys vKey); - - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true)] - internal static extern SHORT GetKeyState(VirtualKeys vKey); - - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true)] - internal static extern UINT MapVirtualKey(UINT uCode, MapVirtualKeyType uMapType); - - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport("user32.dll", SetLastError = true)] - internal static extern UINT MapVirtualKey(VirtualKeys vkey, MapVirtualKeyType uMapType); - - /// - /// The ShowWindow function sets the specified window's show state. - /// - /// [in] Handle to the window. - /// [in] Specifies how the window is to be shown. This parameter is ignored the first time an application calls ShowWindow, if the program that launched the application provides a STARTUPINFO structure. Otherwise, the first time ShowWindow is called, the value should be the value obtained by the WinMain function in its nCmdShow parameter. In subsequent calls, this parameter can be one of the ShowWindowEnum values. - /// If the window was previously visible, the return value is true. Otherwise false. - /// - /// To perform certain special effects when showing or hiding a window, use AnimateWindow. - /// The first time an application calls ShowWindow, it should use the WinMain function's nCmdShow parameter as its nCmdShow parameter. Subsequent calls to ShowWindow must use one of the values in the given list, instead of the one specified by the WinMain function's nCmdShow parameter. - /// As noted in the discussion of the nCmdShow parameter, the nCmdShow value is ignored in the first call to ShowWindow if the program that launched the application specifies startup information in the structure. In this case, ShowWindow uses the information specified in the STARTUPINFO structure to show the window. On subsequent calls, the application must call ShowWindow with nCmdShow set to SW_SHOWDEFAULT to use the startup information provided by the program that launched the application. This behavior is designed for the following situations: - /// - /// Applications create their main window by calling CreateWindow with the WS_VISIBLE flag set. - /// Applications create their main window by calling CreateWindow with the WS_VISIBLE flag cleared, and later call ShowWindow with the SW_SHOW flag set to make it visible. - /// - /// - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal static extern BOOL ShowWindow(HWND hWnd, ShowWindowCommand nCmdShow); - - /// - /// The SetWindowText function changes the text of the specified window's title bar (if it has one). If the specified window is a control, the text of the control is changed. However, SetWindowText cannot change the text of a control in another application. - /// - /// [in] Handle to the window or control whose text is to be changed. - /// [in] Pointer to a null-terminated string to be used as the new title or control text. - /// - /// If the function succeeds, the return value is nonzero. - /// If the function fails, the return value is zero. To get extended error information, call GetLastError. - /// - /// - /// If the target window is owned by the current process, SetWindowText causes a WM_SETTEXT message to be sent to the specified window or control. If the control is a list box control created with the WS_CAPTION style, however, SetWindowText sets the text for the control, not for the list box entries. - /// To set the text of a control in another process, send the WM_SETTEXT message directly instead of calling SetWindowText. - /// The SetWindowText function does not expand tab characters (ASCII code 0x09). Tab characters are displayed as vertical bar (|) characters. - /// Windows 95/98/Me: SetWindowTextW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems . - /// - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - internal static extern BOOL SetWindowText(HWND hWnd, [MarshalAs(UnmanagedType.LPTStr)] string lpString); - - /// - /// The GetWindowText function copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied. However, GetWindowText cannot retrieve the text of a control in another application. - /// - /// [in] Handle to the window or control containing the text. - /// [out] Pointer to the buffer that will receive the text. If the string is as long or longer than the buffer, the string is truncated and terminated with a NULL character. - /// [in] Specifies the maximum number of characters to copy to the buffer, including the NULL character. If the text exceeds this limit, it is truncated. - /// - /// If the function succeeds, the return value is the length, in characters, of the copied string, not including the terminating NULL character. If the window has no title bar or text, if the title bar is empty, or if the window or control handle is invalid, the return value is zero. To get extended error information, call GetLastError. - /// This function cannot retrieve the text of an edit control in another application. - /// - /// - /// If the target window is owned by the current process, GetWindowText causes a WM_GETTEXT message to be sent to the specified window or control. If the target window is owned by another process and has a caption, GetWindowText retrieves the window caption text. If the window does not have a caption, the return value is a null string. This behavior is by design. It allows applications to call GetWindowText without becoming unresponsive if the process that owns the target window is not responding. However, if the target window is not responding and it belongs to the calling application, GetWindowText will cause the calling application to become unresponsive. - /// To retrieve the text of a control in another process, send a WM_GETTEXT message directly instead of calling GetWindowText. - /// Windows 95/98/Me: GetWindowTextW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me - /// - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - internal static extern int GetWindowText(HWND hWnd, [MarshalAs(UnmanagedType.LPTStr), In, Out] StringBuilder lpString, int nMaxCount); - - /// - /// Converts the screen coordinates of a specified point on the screen to client-area coordinates. - /// - /// Handle to the window whose client area will be used for the conversion. - /// Pointer to a POINT structure that specifies the screen coordinates to be converted. - /// If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT/2000/XP: To get extended error information, call GetLastError. - /// - /// The function uses the window identified by the hWnd parameter and the screen coordinates given in the POINT structure to compute client coordinates. It then replaces the screen coordinates with the client coordinates. The new coordinates are relative to the upper-left corner of the specified window's client area. - /// The ScreenToClient function assumes the specified point is in screen coordinates. - /// All coordinates are in device units. - /// Do not use ScreenToClient when in a mirroring situation, that is, when changing from left-to-right layout to right-to-left layout. Instead, use MapWindowPoints. For more information, see "Window Layout and Mirroring" in Window Features. - /// - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - //internal static extern BOOL ScreenToClient(HWND hWnd, ref POINT point); - internal static extern BOOL ScreenToClient(HWND hWnd, ref Point point); - - /// - /// Converts the client-area coordinates of a specified point to screen coordinates. - /// - /// Handle to the window whose client area will be used for the conversion. - /// Pointer to a POINT structure that contains the client coordinates to be converted. The new screen coordinates are copied into this structure if the function succeeds. - /// If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT/2000/XP: To get extended error information, call GetLastError. - /// - /// The ClientToScreen function replaces the client-area coordinates in the POINT structure with the screen coordinates. The screen coordinates are relative to the upper-left corner of the screen. Note, a screen-coordinate point that is above the window's client area has a negative y-coordinate. Similarly, a screen coordinate to the left of a client area has a negative x-coordinate. - /// All coordinates are device coordinates. - /// - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal static extern BOOL ClientToScreen(HWND hWnd, ref Point point); - - /// - /// The GetClientRect function retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0). - /// - /// Handle to the window whose client coordinates are to be retrieved. - /// Pointer to a RECT structure that receives the client coordinates. The left and top members are zero. The right and bottom members contain the width and height of the window. - /// - /// If the function succeeds, the return value is nonzero. - /// If the function fails, the return value is zero. To get extended error information, call GetLastError. - /// - /// In conformance with conventions for the RECT structure, the bottom-right coordinates of the returned rectangle are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle. - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal extern static BOOL GetClientRect(HWND windowHandle, out Win32Rectangle clientRectangle); - - /// - /// The GetWindowRect function retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen. - /// - /// Handle to the window whose client coordinates are to be retrieved. - /// Pointer to a structure that receives the screen coordinates of the upper-left and lower-right corners of the window. - /// - /// If the function succeeds, the return value is nonzero. - /// If the function fails, the return value is zero. To get extended error information, call GetLastError. - /// - /// In conformance with conventions for the RECT structure, the bottom-right coordinates of the returned rectangle are exclusive. In other words, the pixel at (right, bottom) lies immediately outside the rectangle. - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal extern static BOOL GetWindowRect(HWND windowHandle, out Win32Rectangle windowRectangle); - - [DllImport("user32.dll"), SuppressUnmanagedCodeSecurity] - internal static extern BOOL GetWindowInfo(HWND hwnd, ref WindowInfo wi); - - [DllImport("dwmapi.dll")] - unsafe public static extern HRESULT DwmGetWindowAttribute(HWND hwnd, DwmWindowAttribute dwAttribute, void* pvAttribute, DWORD cbAttribute); - - [DllImport("user32.dll")] - public static extern HWND GetFocus(); - - [DllImport("user32.dll")] - public static extern bool IsWindowVisible(IntPtr intPtr); - - [DllImport("user32.dll")] - public static extern HICON LoadIcon(HINSTANCE hInstance, LPCTSTR lpIconName); - - [DllImport("user32.dll")] - public static extern HCURSOR LoadCursor(HINSTANCE hInstance, LPCTSTR lpCursorName); - - [DllImport("user32.dll")] - public static extern HCURSOR LoadCursor(HINSTANCE hInstance, IntPtr lpCursorName); - - public static HCURSOR LoadCursor(CursorName lpCursorName) - { - return LoadCursor(IntPtr.Zero, new IntPtr((int)lpCursorName)); - } - - /// - /// Creates an icon or cursor from an IconInfo structure. - /// - /// - /// A pointer to an IconInfo structure the function uses to create the - /// icon or cursor. - /// - /// - /// If the function succeeds, the return value is a handle to the icon - /// or cursor that is created. - /// - /// If the function fails, the return value is null. To get extended - /// error information, call Marshal.GetLastWin32Error. - /// - /// - /// The system copies the bitmaps in the IconInfo structure before - /// creating the icon or cursor. Because the system may temporarily - /// select the bitmaps in a device context, the hbmMask and hbmColor - /// members of the IconInfo structure should not already be selected - /// into a device context. The application must continue to manage the - /// original bitmaps and delete them when they are no longer necessary. - /// When you are finished using the icon, destroy it using the - /// DestroyIcon function. - /// - [DllImport("user32.dll", SetLastError = true)] - public static extern HICON CreateIconIndirect(ref IconInfo iconInfo); - - /// - /// Retrieves information about the specified icon or cursor. - /// - /// A handle to the icon or cursor. - /// - /// A pointer to an IconInfo structure. The function fills in the - /// structure's members. - /// - /// - /// If the function succeeds, the return value is nonzero and the - /// function fills in the members of the specified IconInfo structure. - /// - /// If the function fails, the return value is zero. To get extended - /// error information, call Marshal.GetLastWin32Error. - /// - /// - /// GetIconInfo creates bitmaps for the hbmMask and hbmColor members - /// of IconInfo. The calling application must manage these bitmaps and - /// delete them when they are no longer necessary. - /// - [DllImport("user32.dll", SetLastError = true)] - public static extern BOOL GetIconInfo(HICON hIcon, out IconInfo pIconInfo); - - /// - /// Destroys an icon and frees any memory the icon occupied. - /// - /// - /// A handle to the icon to be destroyed. The icon must not be in use. - /// - /// - /// If the function succeeds, the return value is nonzero. - /// - /// If the function fails, the return value is zero. To get extended - /// error information, call Marshal.GetLastWin32Error. - /// - /// - /// It is only necessary to call DestroyIcon for icons and cursors - /// created with the following functions: CreateIconFromResourceEx - /// (if called without the LR_SHARED flag), CreateIconIndirect, and - /// CopyIcon. Do not use this function to destroy a shared icon. A - /// shared icon is valid as long as the module from which it was loaded - /// remains in memory. The following functions obtain a shared icon. - /// - /// LoadIcon - /// LoadImage (if you use the LR_SHARED flag) - /// CopyImage (if you use the LR_COPYRETURNORG flag and the hImage parameter is a shared icon) - /// CreateIconFromResource - /// CreateIconFromResourceEx (if you use the LR_SHARED flag) - /// - [DllImport("user32.dll", SetLastError = true)] - public static extern BOOL DestroyIcon(HICON hIcon); - - - [DllImport("user32.dll", SetLastError = true)] - public static extern BOOL SetForegroundWindow(HWND hWnd); - - [DllImport("user32.dll", SetLastError = true)] - public static extern BOOL BringWindowToTop(HWND hWnd); - - [DllImport("user32.dll", SetLastError = true)] - public static extern BOOL SetParent(HWND child, HWND newParent); - - [DllImport("user32.dll", SetLastError = true)] - public static extern HDEVNOTIFY RegisterDeviceNotification(HANDLE hRecipient, - LPVOID NotificationFilter, DeviceNotification Flags); - - [DllImport("user32.dll", SetLastError = true)] - public static extern BOOL UnregisterDeviceNotification(HDEVNOTIFY Handle); - - /// - /// The ChangeDisplaySettings function changes the settings of the default display device to the specified graphics mode. - /// - /// [in] Pointer to a DEVMODE structure that describes the new graphics mode. If lpDevMode is NULL, all the values currently in the registry will be used for the display setting. Passing NULL for the lpDevMode parameter and 0 for the dwFlags parameter is the easiest way to return to the default mode after a dynamic mode change. - /// [in] Indicates how the graphics mode should be changed. - /// - /// To change the settings of a specified display device, use the ChangeDisplaySettingsEx function. - /// To ensure that the DEVMODE structure passed to ChangeDisplaySettings is valid and contains only values supported by the display driver, use the DEVMODE returned by the EnumDisplaySettings function. - /// When the display mode is changed dynamically, the WM_DISPLAYCHANGE message is sent to all running applications. - /// - [DllImport("user32.dll", SetLastError = true)] - internal static extern int ChangeDisplaySettings(DeviceMode device_mode, ChangeDisplaySettingsEnum flags); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern LONG ChangeDisplaySettingsEx([MarshalAs(UnmanagedType.LPTStr)] LPCTSTR lpszDeviceName, - LPDEVMODE lpDevMode, HWND hwnd, ChangeDisplaySettingsEnum dwflags, LPVOID lParam); - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] [return: MarshalAs(UnmanagedType.Bool)] public static extern BOOL EnumDisplayDevices([MarshalAs(UnmanagedType.LPTStr)] LPCTSTR lpDevice, DWORD iDevNum, [In, Out] WindowsDisplayDevice lpDisplayDevice, DWORD dwFlags); - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern BOOL EnumDisplaySettings([MarshalAs(UnmanagedType.LPTStr)] string device_name, - int graphics_mode, [In, Out] DeviceMode device_mode); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern BOOL EnumDisplaySettings([MarshalAs(UnmanagedType.LPTStr)] string device_name, - DisplayModeSettingsEnum graphics_mode, [In, Out] DeviceMode device_mode); - + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern BOOL EnumDisplaySettingsEx([MarshalAs(UnmanagedType.LPTStr)] LPCTSTR lpszDeviceName, DisplayModeSettingsEnum iModeNum, [In, Out] DeviceMode lpDevMode, DWORD dwFlags); @@ -774,15 +190,6 @@ namespace OpenTK.Platform.Windows public static extern BOOL EnumDisplaySettingsEx([MarshalAs(UnmanagedType.LPTStr)] LPCTSTR lpszDeviceName, DWORD iModeNum, [In, Out] DeviceMode lpDevMode, DWORD dwFlags); - [DllImport("user32.dll", SetLastError = true)] - public static extern BOOL GetMonitorInfo(IntPtr hMonitor, ref MonitorInfo lpmi); - - [DllImport("user32.dll", SetLastError = true)] - public static extern HMONITOR MonitorFromPoint(POINT pt, MonitorFrom dwFlags); - - [DllImport("user32.dll", SetLastError = true)] - public static extern HMONITOR MonitorFromWindow(HWND hwnd, MonitorFrom dwFlags); - /// /// Sets the current process as dots per inch (dpi) aware. /// Note: SetProcessDPIAware is subject to a possible race condition @@ -803,60 +210,8 @@ namespace OpenTK.Platform.Windows [DllImport("user32.dll")] internal static extern BOOL SetProcessDPIAware(); - [DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] - public static extern int GetDeviceCaps(IntPtr hDC, DeviceCaps nIndex); - - [DllImport("user32.dll", SetLastError = true)] - public static extern BOOL TrackMouseEvent(ref TrackMouseEventStructure lpEventTrack); - - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] - public static extern bool ReleaseCapture(); - - [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] - public static extern IntPtr SetCapture(IntPtr hwnd); - - [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] - public static extern IntPtr GetCapture(); - - [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] - public static extern IntPtr SetFocus(IntPtr hwnd); - - [DllImport("gdi32.dll", SetLastError = true)] - internal static extern IntPtr GetStockObject(StockObjects fnObject); - - [DllImport("gdi32.dll", SetLastError = true)] - internal static extern BOOL DeleteObject([In]IntPtr hObject); - - - [DllImport("user32.dll", SetLastError = true)] - public static extern UINT_PTR SetTimer(HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc); - - [DllImport("user32.dll", SetLastError = true)] - public static extern BOOL KillTimer(HWND hWnd, UINT_PTR uIDEvent); - [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void TimerProc(HWND hwnd, WindowMessage uMsg, UINT_PTR idEvent, DWORD dwTime); - - [DllImport("shell32.dll")] - public static extern DWORD_PTR SHGetFileInfo(LPCTSTR pszPath, DWORD dwFileAttributes, ref SHFILEINFO psfi, UINT cbFileInfo, ShGetFileIconFlags uFlags); - - [DllImport("Advapi32.dll")] - internal static extern int RegOpenKeyEx( - HKEY hKey, - [MarshalAs(UnmanagedType.LPTStr)] LPCTSTR lpSubKey, - DWORD ulOptions, - REGSAM samDesired, - out PHKEY phkResult); - - [DllImport("Advapi32.dll")] - internal static extern int RegGetValue( - HKEY hkey, - [MarshalAs(UnmanagedType.LPTStr)] LPCTSTR lpSubKey, - [MarshalAs(UnmanagedType.LPTStr)] LPCTSTR lpValue, - DWORD dwFlags, - out DWORD pdwType, - StringBuilder pvData, - ref DWORD pcbData); } internal static class Constants @@ -974,104 +329,6 @@ namespace OpenTK.Platform.Windows internal const int GMMP_USE_HIGH_RESOLUTION_POINTS = 2; } - internal struct CreateStruct - { - /// - /// Contains additional data which may be used to create the window. - /// - /// - /// If the window is being created as a result of a call to the CreateWindow - /// or CreateWindowEx function, this member contains the value of the lpParam - /// parameter specified in the function call. - /// - /// If the window being created is a multiple-document interface (MDI) client window, - /// this member contains a pointer to a CLIENTCREATESTRUCT structure. If the window - /// being created is a MDI child window, this member contains a pointer to an - /// MDICREATESTRUCT structure. - /// - /// - /// Windows NT/2000/XP: If the window is being created from a dialog template, - /// this member is the address of a SHORT value that specifies the size, in bytes, - /// of the window creation data. The value is immediately followed by the creation data. - /// - /// - /// Windows NT/2000/XP: You should access the data represented by the lpCreateParams member - /// using a pointer that has been declared using the UNALIGNED type, because the pointer - /// may not be DWORD aligned. - /// - /// - internal LPVOID lpCreateParams; - /// - /// Handle to the module that owns the new window. - /// - internal HINSTANCE hInstance; - /// - /// Handle to the menu to be used by the new window. - /// - internal HMENU hMenu; - /// - /// Handle to the parent window, if the window is a child window. - /// If the window is owned, this member identifies the owner window. - /// If the window is not a child or owned window, this member is NULL. - /// - internal HWND hwndParent; - /// - /// Specifies the height of the new window, in pixels. - /// - internal int cy; - /// - /// Specifies the width of the new window, in pixels. - /// - internal int cx; - /// - /// Specifies the y-coordinate of the upper left corner of the new window. - /// If the new window is a child window, coordinates are relative to the parent window. - /// Otherwise, the coordinates are relative to the screen origin. - /// - internal int y; - /// - /// Specifies the x-coordinate of the upper left corner of the new window. - /// If the new window is a child window, coordinates are relative to the parent window. - /// Otherwise, the coordinates are relative to the screen origin. - /// - internal int x; - /// - /// Specifies the style for the new window. - /// - internal LONG style; - /// - /// Pointer to a null-terminated string that specifies the name of the new window. - /// - [MarshalAs(UnmanagedType.LPTStr)] - internal LPCTSTR lpszName; - /// - /// Either a pointer to a null-terminated string or an atom that specifies the class name - /// of the new window. - /// - /// Note Because the lpszClass member can contain a pointer to a local (and thus inaccessable) atom, - /// do not obtain the class name by using this member. Use the GetClassName function instead. - /// - /// - [MarshalAs(UnmanagedType.LPTStr)] - internal LPCTSTR lpszClass; - /// - /// Specifies the extended window style for the new window. - /// - internal DWORD dwExStyle; - } - - internal struct StyleStruct - { - public WindowStyle Old; - public WindowStyle New; - } - - internal struct ExtendedStyleStruct - { - public ExtendedWindowStyle Old; - public ExtendedWindowStyle New; - } - /// \internal /// /// Describes a pixel format. It is used when interfacing with the WINAPI to create a new Context. @@ -1362,130 +619,6 @@ namespace OpenTK.Platform.Windows public static uint SizeInBytes = (uint)Marshal.SizeOf(default(ExtendedWindowClass)); } - /// \internal - /// - /// Struct pointed to by WM_GETMINMAXINFO lParam - /// - [StructLayout(LayoutKind.Sequential)] - internal struct MINMAXINFO - { - private Point Reserved; - public Size MaxSize; - public Point MaxPosition; - public Size MinTrackSize; - public Size MaxTrackSize; - } - - /// \internal - /// - /// The WindowPosition structure contains information about the size and position of a window. - /// - [StructLayout(LayoutKind.Sequential)] - internal struct WindowPosition - { - /// - /// Handle to the window. - /// - internal HWND hwnd; - /// - /// Specifies the position of the window in Z order (front-to-back position). - /// This member can be a handle to the window behind which this window is placed, - /// or can be one of the special values listed with the SetWindowPos function. - /// - internal HWND hwndInsertAfter; - /// - /// Specifies the position of the left edge of the window. - /// - internal int x; - /// - /// Specifies the position of the top edge of the window. - /// - internal int y; - /// - /// Specifies the window width, in pixels. - /// - internal int cx; - /// - /// Specifies the window height, in pixels. - /// - internal int cy; - /// - /// Specifies the window position. - /// - [MarshalAs(UnmanagedType.U4)] - internal SetWindowPosFlags flags; - } - - [Flags] - internal enum SetWindowPosFlags : int - { - /// - /// Retains the current size (ignores the cx and cy parameters). - /// - NOSIZE = 0x0001, - /// - /// Retains the current position (ignores the x and y parameters). - /// - NOMOVE = 0x0002, - /// - /// Retains the current Z order (ignores the hwndInsertAfter parameter). - /// - NOZORDER = 0x0004, - /// - /// Does not redraw changes. If this flag is set, no repainting of any kind occurs. - /// This applies to the client area, the nonclient area (including the title bar and scroll bars), - /// and any part of the parent window uncovered as a result of the window being moved. - /// When this flag is set, the application must explicitly invalidate or redraw any parts - /// of the window and parent window that need redrawing. - /// - NOREDRAW = 0x0008, - /// - /// Does not activate the window. If this flag is not set, - /// the window is activated and moved to the top of either the topmost or non-topmost group - /// (depending on the setting of the hwndInsertAfter member). - /// - NOACTIVATE = 0x0010, - /// - /// Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. - /// If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed. - /// - FRAMECHANGED = 0x0020, /* The frame changed: send WM_NCCALCSIZE */ - /// - /// Displays the window. - /// - SHOWWINDOW = 0x0040, - /// - /// Hides the window. - /// - HIDEWINDOW = 0x0080, - /// - /// Discards the entire contents of the client area. If this flag is not specified, - /// the valid contents of the client area are saved and copied back into the client area - /// after the window is sized or repositioned. - /// - NOCOPYBITS = 0x0100, - /// - /// Does not change the owner window's position in the Z order. - /// - NOOWNERZORDER = 0x0200, /* Don't do owner Z ordering */ - /// - /// Prevents the window from receiving the WM_WINDOWPOSCHANGING message. - /// - NOSENDCHANGING = 0x0400, /* Don't send WM_WINDOWPOSCHANGING */ - - /// - /// Draws a frame (defined in the window's class description) around the window. - /// - DRAWFRAME = FRAMECHANGED, - /// - /// Same as the NOOWNERZORDER flag. - /// - NOREPOSITION = NOOWNERZORDER, - - DEFERERASE = 0x2000, - ASYNCWINDOWPOS = 0x4000 - } - /// \internal /// /// Defines the coordinates of the upper-left and lower-right corners of a rectangle. @@ -1520,31 +653,6 @@ namespace OpenTK.Platform.Windows { return String.Format("({0},{1})-({2},{3})", left, top, right, bottom); } - - internal Rectangle ToRectangle() - { - return Rectangle.FromLTRB(left, top, right, bottom); - } - - internal static Win32Rectangle From(Rectangle value) - { - Win32Rectangle rect = new Win32Rectangle(); - rect.left = value.Left; - rect.right = value.Right; - rect.top = value.Top; - rect.bottom = value.Bottom; - return rect; - } - - internal static Win32Rectangle From(Size value) - { - Win32Rectangle rect = new Win32Rectangle(); - rect.left = 0; - rect.right = value.Width; - rect.top = 0; - rect.bottom = value.Height; - return rect; - } } /// \internal @@ -1606,27 +714,6 @@ namespace OpenTK.Platform.Windows public static readonly int SizeInBytes = Marshal.SizeOf(default(MonitorInfo)); } - [StructLayout(LayoutKind.Sequential, Pack = 1)] - internal struct NcCalculateSize - { - public Win32Rectangle NewBounds; - public Win32Rectangle OldBounds; - public Win32Rectangle OldClientRectangle; - unsafe public WindowPosition* Position; - } - - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] - internal struct SHFILEINFO - { - public IntPtr hIcon; - public int iIcon; - public uint dwAttributes; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] - public string szDisplayName; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] - public string szTypeName; - }; - internal struct TrackMouseEventStructure { public DWORD Size; @@ -1637,109 +724,6 @@ namespace OpenTK.Platform.Windows public static readonly int SizeInBytes = Marshal.SizeOf(typeof(TrackMouseEventStructure)); } - internal struct BroadcastHeader - { - public DWORD Size; - public DeviceBroadcastType DeviceType; - private DWORD dbch_reserved; - } - - internal struct BroadcastDeviceInterface - { - public DWORD Size; - public DeviceBroadcastType DeviceType; - private DWORD dbcc_reserved; - public Guid ClassGuid; - public char dbcc_name; - } - /// \internal - /// - /// Contains information about an icon or a cursor. - /// - [StructLayout(LayoutKind.Sequential)] - internal struct IconInfo - { - /// - /// Specifies whether this structure defines an icon or a cursor. A - /// value of TRUE specifies an icon; FALSE specifies a cursor - /// - public bool fIcon; - - /// - /// The x-coordinate of a cursor's hot spot. If this structure defines - /// an icon, the hot spot is always in the center of the icon, and - /// this member is ignored. - /// - public Int32 xHotspot; - - /// - /// The y-coordinate of a cursor's hot spot. If this structure defines - /// an icon, the hot spot is always in the center of the icon, and - /// this member is ignored. - /// - public Int32 yHotspot; - - /// - /// The icon bitmask bitmap. If this structure defines a black and - /// white icon, this bitmask is formatted so that the upper half is - /// the icon AND bitmask and the lower half is the icon XOR bitmask. - /// Under this condition, the height should be an even multiple of - /// two. If this structure defines a color icon, this mask only - /// defines the AND bitmask of the icon. - /// - public IntPtr hbmMask; - - /// - /// A handle to the icon color bitmap. This member can be optional if - /// this structure defines a black and white icon. The AND bitmask of - /// hbmMask is applied with the SRCAND flag to the destination; - /// subsequently, the color bitmap is applied (using XOR) to the - /// destination by using the SRCINVERT flag. - /// - public IntPtr hbmColor; - } - - /// - /// Window field offsets for GetWindowLong() and GetWindowLongPtr(). - /// - internal enum GWL - { - WNDPROC = (-4), - HINSTANCE = (-6), - HWNDPARENT = (-8), - STYLE = (-16), - EXSTYLE = (-20), - USERDATA = (-21), - ID = (-12), - } - - internal enum SizeMessage - { - MAXHIDE = 4, - MAXIMIZED = 2, - MAXSHOW = 3, - MINIMIZED = 1, - RESTORED = 0 - } - - internal enum NcCalcSizeOptions - { - ALIGNTOP = 0x10, - ALIGNRIGHT = 0x80, - ALIGNLEFT = 0x20, - ALIGNBOTTOM = 0x40, - HREDRAW = 0x100, - VREDRAW = 0x200, - REDRAW = (HREDRAW | VREDRAW), - VALIDRECTS = 0x400 - } - - internal enum DeviceCaps - { - LogPixelsX = 88, - LogPixelsY = 90 - } - internal enum DisplayModeSettingsEnum { CurrentSettings = -1, @@ -1765,15 +749,6 @@ namespace OpenTK.Platform.Windows Attached = 0x00000002, } - [Flags] - internal enum ChangeDisplaySettingsEnum - { - // ChangeDisplaySettings types (found in winuser.h) - UpdateRegistry = 0x00000001, - Test = 0x00000002, - Fullscreen = 0x00000004, - } - [Flags] internal enum WindowStyle : uint { @@ -1861,16 +836,6 @@ namespace OpenTK.Platform.Windows // #endif /* _WIN32_WINNT >= 0x0500 */ } - internal enum GetWindowLongOffsets : int - { - WNDPROC = (-4), - HINSTANCE = (-6), - HWNDPARENT = (-8), - STYLE = (-16), - EXSTYLE = (-20), - USERDATA = (-21), - ID = (-12), - } [Flags] internal enum PixelFormatDescriptorFlags : int { @@ -1902,13 +867,6 @@ namespace OpenTK.Platform.Windows INDEXED = 1 } - internal enum WindowPlacementOptions - { - TOP = 0, - BOTTOM = 1, - TOPMOST = -1, - NOTOPMOST = -2 - } [Flags] internal enum ClassStyle { @@ -1931,499 +889,7 @@ namespace OpenTK.Platform.Windows DropShadow = 0x00020000 // #endif /* _WIN32_WINNT >= 0x0501 */ } - [Flags] - internal enum RawInputDeviceFlags : int - { - /// - /// If set, this removes the top level collection from the inclusion list. - /// This tells the operating system to stop reading from a device which matches the top level collection. - /// - REMOVE = 0x00000001, - /// - /// If set, this specifies the top level collections to exclude when reading a complete usage page. - /// This flag only affects a TLC whose usage page is already specified with RawInputDeviceEnum.PAGEONLY. - /// - EXCLUDE = 0x00000010, - /// - /// If set, this specifies all devices whose top level collection is from the specified UsagePage. - /// Note that usUsage must be zero. To exclude a particular top level collection, use EXCLUDE. - /// - PAGEONLY = 0x00000020, - /// - /// If set, this prevents any devices specified by UsagePage or Usage from generating legacy messages. - /// This is only for the mouse and keyboard. See RawInputDevice Remarks. - /// - NOLEGACY = 0x00000030, - /// - /// If set, this enables the caller to receive the input even when the caller is not in the foreground. - /// Note that Target must be specified in RawInputDevice. - /// - INPUTSINK = 0x00000100, - /// - /// If set, the mouse button click does not activate the other window. - /// - CAPTUREMOUSE = 0x00000200, // effective when mouse nolegacy is specified, otherwise it would be an error - /// - /// If set, the application-defined keyboard device hotkeys are not handled. - /// However, the system hotkeys; for example, ALT+TAB and CTRL+ALT+DEL, are still handled. - /// By default, all keyboard hotkeys are handled. - /// NOHOTKEYS can be specified even if NOLEGACY is not specified and Target is NULL in RawInputDevice. - /// - NOHOTKEYS = 0x00000200, // effective for keyboard. - /// - /// Microsoft Windows XP Service Pack 1 (SP1): If set, the application command keys are handled. APPKEYS can be specified only if NOLEGACY is specified for a keyboard device. - /// - APPKEYS = 0x00000400, // effective for keyboard. - /// - /// If set, this enables the caller to receive input in the background only if the foreground application - /// does not process it. In other words, if the foreground application is not registered for raw input, - /// then the background application that is registered will receive the input. - /// - EXINPUTSINK = 0x00001000, - DEVNOTIFY = 0x00002000, - //EXMODEMASK = 0x000000F0 - } - - internal enum GetRawInputDataEnum - { - INPUT = 0x10000003, - HEADER = 0x10000005 - } - - internal enum RawInputDeviceInfoEnum - { - PREPARSEDDATA = 0x20000005, - DEVICENAME = 0x20000007, // the return valus is the character length, not the byte size - DEVICEINFO = 0x2000000b - } - - [Flags] - internal enum RawInputMouseState : ushort - { - LEFT_BUTTON_DOWN = 0x0001, // Left Button changed to down. - LEFT_BUTTON_UP = 0x0002, // Left Button changed to up. - RIGHT_BUTTON_DOWN = 0x0004, // Right Button changed to down. - RIGHT_BUTTON_UP = 0x0008, // Right Button changed to up. - MIDDLE_BUTTON_DOWN = 0x0010, // Middle Button changed to down. - MIDDLE_BUTTON_UP = 0x0020, // Middle Button changed to up. - - BUTTON_1_DOWN = LEFT_BUTTON_DOWN, - BUTTON_1_UP = LEFT_BUTTON_UP, - BUTTON_2_DOWN = RIGHT_BUTTON_DOWN, - BUTTON_2_UP = RIGHT_BUTTON_UP, - BUTTON_3_DOWN = MIDDLE_BUTTON_DOWN, - BUTTON_3_UP = MIDDLE_BUTTON_UP, - - BUTTON_4_DOWN = 0x0040, - BUTTON_4_UP = 0x0080, - BUTTON_5_DOWN = 0x0100, - BUTTON_5_UP = 0x0200, - - WHEEL = 0x0400, - HWHEEL = 0x0800, - } - - internal enum RawInputKeyboardDataFlags : short //: ushort - { - MAKE = 0, - BREAK = 1, - E0 = 2, - E1 = 4, - TERMSRV_SET_LED = 8, - TERMSRV_SHADOW = 0x10 - } - - internal enum RawInputDeviceType : int - { - MOUSE = 0, - KEYBOARD = 1, - HID = 2 - } - - /// - /// Mouse indicator flags (found in winuser.h). - /// - [Flags] - internal enum RawMouseFlags : ushort - { - /// - /// LastX/Y indicate relative motion. - /// - MOUSE_MOVE_RELATIVE = 0x00, - /// - /// LastX/Y indicate absolute motion. - /// - MOUSE_MOVE_ABSOLUTE = 0x01, - /// - /// The coordinates are mapped to the virtual desktop. - /// - MOUSE_VIRTUAL_DESKTOP = 0x02, - /// - /// Requery for mouse attributes. - /// - MOUSE_ATTRIBUTES_CHANGED = 0x04, - } - - internal enum VirtualKeys : short - { - /* - * Virtual Key, Standard Set - */ - LBUTTON = 0x01, - RBUTTON = 0x02, - CANCEL = 0x03, - MBUTTON = 0x04, /* NOT contiguous with L & RBUTTON */ - - XBUTTON1 = 0x05, /* NOT contiguous with L & RBUTTON */ - XBUTTON2 = 0x06, /* NOT contiguous with L & RBUTTON */ - - /* - * 0x07 : unassigned - */ - - BACK = 0x08, - TAB = 0x09, - - /* - * 0x0A - 0x0B : reserved - */ - - CLEAR = 0x0C, - RETURN = 0x0D, - - SHIFT = 0x10, - CONTROL = 0x11, - MENU = 0x12, - PAUSE = 0x13, - CAPITAL = 0x14, - - KANA = 0x15, - HANGEUL = 0x15, /* old name - should be here for compatibility */ - HANGUL = 0x15, - JUNJA = 0x17, - FINAL = 0x18, - HANJA = 0x19, - KANJI = 0x19, - - ESCAPE = 0x1B, - - CONVERT = 0x1C, - NONCONVERT = 0x1D, - ACCEPT = 0x1E, - MODECHANGE = 0x1F, - - SPACE = 0x20, - PRIOR = 0x21, - NEXT = 0x22, - END = 0x23, - HOME = 0x24, - LEFT = 0x25, - UP = 0x26, - RIGHT = 0x27, - DOWN = 0x28, - SELECT = 0x29, - PRINT = 0x2A, - EXECUTE = 0x2B, - SNAPSHOT = 0x2C, - INSERT = 0x2D, - DELETE = 0x2E, - HELP = 0x2F, - - /* - * 0 - 9 are the same as ASCII '0' - '9' (0x30 - 0x39) - * 0x40 : unassigned - * A - Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A) - */ - - LWIN = 0x5B, - RWIN = 0x5C, - APPS = 0x5D, - - /* - * 0x5E : reserved - */ - - SLEEP = 0x5F, - - NUMPAD0 = 0x60, - NUMPAD1 = 0x61, - NUMPAD2 = 0x62, - NUMPAD3 = 0x63, - NUMPAD4 = 0x64, - NUMPAD5 = 0x65, - NUMPAD6 = 0x66, - NUMPAD7 = 0x67, - NUMPAD8 = 0x68, - NUMPAD9 = 0x69, - MULTIPLY = 0x6A, - ADD = 0x6B, - SEPARATOR = 0x6C, - SUBTRACT = 0x6D, - DECIMAL = 0x6E, - DIVIDE = 0x6F, - F1 = 0x70, - F2 = 0x71, - F3 = 0x72, - F4 = 0x73, - F5 = 0x74, - F6 = 0x75, - F7 = 0x76, - F8 = 0x77, - F9 = 0x78, - F10 = 0x79, - F11 = 0x7A, - F12 = 0x7B, - F13 = 0x7C, - F14 = 0x7D, - F15 = 0x7E, - F16 = 0x7F, - F17 = 0x80, - F18 = 0x81, - F19 = 0x82, - F20 = 0x83, - F21 = 0x84, - F22 = 0x85, - F23 = 0x86, - F24 = 0x87, - - /* - * 0x88 - 0x8F : unassigned - */ - - NUMLOCK = 0x90, - SCROLL = 0x91, - - /* - * NEC PC-9800 kbd definitions - */ - OEM_NEC_EQUAL = 0x92, // '=' key on numpad - - /* - * Fujitsu/OASYS kbd definitions - */ - OEM_FJ_JISHO = 0x92, // 'Dictionary' key - OEM_FJ_MASSHOU = 0x93, // 'Unregister word' key - OEM_FJ_TOUROKU = 0x94, // 'Register word' key - OEM_FJ_LOYA = 0x95, // 'Left OYAYUBI' key - OEM_FJ_ROYA = 0x96, // 'Right OYAYUBI' key - - /* - * 0x97 - 0x9F : unassigned - */ - - /* - * L* & R* - left and right Alt, Ctrl and Shift virtual keys. - * Used only as parameters to GetAsyncKeyState() and GetKeyState(). - * No other API or message will distinguish left and right keys in this way. - */ - LSHIFT = 0xA0, - RSHIFT = 0xA1, - LCONTROL = 0xA2, - RCONTROL = 0xA3, - LMENU = 0xA4, - RMENU = 0xA5, - - BROWSER_BACK = 0xA6, - BROWSER_FORWARD = 0xA7, - BROWSER_REFRESH = 0xA8, - BROWSER_STOP = 0xA9, - BROWSER_SEARCH = 0xAA, - BROWSER_FAVORITES = 0xAB, - BROWSER_HOME = 0xAC, - - VOLUME_MUTE = 0xAD, - VOLUME_DOWN = 0xAE, - VOLUME_UP = 0xAF, - MEDIA_NEXT_TRACK = 0xB0, - MEDIA_PREV_TRACK = 0xB1, - MEDIA_STOP = 0xB2, - MEDIA_PLAY_PAUSE = 0xB3, - LAUNCH_MAIL = 0xB4, - LAUNCH_MEDIA_SELECT = 0xB5, - LAUNCH_APP1 = 0xB6, - LAUNCH_APP2 = 0xB7, - - /* - * 0xB8 - 0xB9 : reserved - */ - - OEM_1 = 0xBA, // ';:' for US - OEM_PLUS = 0xBB, // '+' any country - OEM_COMMA = 0xBC, // ',' any country - OEM_MINUS = 0xBD, // '-' any country - OEM_PERIOD = 0xBE, // '.' any country - OEM_2 = 0xBF, // '/?' for US - OEM_3 = 0xC0, // '`~' for US - - /* - * 0xC1 - 0xD7 : reserved - */ - - /* - * 0xD8 - 0xDA : unassigned - */ - - OEM_4 = 0xDB, // '[{' for US - OEM_5 = 0xDC, // '\|' for US - OEM_6 = 0xDD, // ']}' for US - OEM_7 = 0xDE, // ''"' for US - OEM_8 = 0xDF, - - /* - * 0xE0 : reserved - */ - - /* - * Various extended or enhanced keyboards - */ - OEM_AX = 0xE1, // 'AX' key on Japanese AX kbd - OEM_102 = 0xE2, // "<>" or "\|" on RT 102-key kbd. - ICO_HELP = 0xE3, // Help key on ICO - ICO_00 = 0xE4, // 00 key on ICO - - PROCESSKEY = 0xE5, - - ICO_CLEAR = 0xE6, - - - PACKET = 0xE7, - - /* - * 0xE8 : unassigned - */ - - /* - * Nokia/Ericsson definitions - */ - OEM_RESET = 0xE9, - OEM_JUMP = 0xEA, - OEM_PA1 = 0xEB, - OEM_PA2 = 0xEC, - OEM_PA3 = 0xED, - OEM_WSCTRL = 0xEE, - OEM_CUSEL = 0xEF, - OEM_ATTN = 0xF0, - OEM_FINISH = 0xF1, - OEM_COPY = 0xF2, - OEM_AUTO = 0xF3, - OEM_ENLW = 0xF4, - OEM_BACKTAB = 0xF5, - - ATTN = 0xF6, - CRSEL = 0xF7, - EXSEL = 0xF8, - EREOF = 0xF9, - PLAY = 0xFA, - ZOOM = 0xFB, - NONAME = 0xFC, - PA1 = 0xFD, - OEM_CLEAR = 0xFE, - - Last - } - - /// - /// Enumerates available mouse keys (suitable for use in WM_MOUSEMOVE messages). - /// - internal enum MouseKeys - { - // Summary: - // No mouse button was pressed. - None = 0, - // - // Summary: - // The left mouse button was pressed. - Left = 0x0001, - // - // Summary: - // The right mouse button was pressed. - Right = 0x0002, - // - // Summary: - // The middle mouse button was pressed. - Middle = 0x0010, - // - // Summary: - // The first XButton was pressed. - XButton1 = 0x0020, - // - // Summary: - // The second XButton was pressed. - XButton2 = 0x0040, - } - - /// \internal - /// - /// Queue status flags for GetQueueStatus() and MsgWaitForMultipleObjects() - /// - [Flags] - internal enum QueueStatusFlags - { - /// - /// A WM_KEYUP, WM_KEYDOWN, WM_SYSKEYUP, or WM_SYSKEYDOWN message is in the queue. - /// - KEY = 0x0001, - /// - /// A WM_MOUSEMOVE message is in the queue. - /// - MOUSEMOVE = 0x0002, - /// - /// A mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on). - /// - MOUSEBUTTON = 0x0004, - /// - /// A posted message (other than those listed here) is in the queue. - /// - POSTMESSAGE = 0x0008, - /// - /// A WM_TIMER message is in the queue. - /// - TIMER = 0x0010, - /// - /// A WM_PAINT message is in the queue. - /// - PAINT = 0x0020, - /// - /// A message sent by another thread or application is in the queue. - /// - SENDMESSAGE = 0x0040, - /// - /// A WM_HOTKEY message is in the queue. - /// - HOTKEY = 0x0080, - /// - /// A posted message (other than those listed here) is in the queue. - /// - ALLPOSTMESSAGE = 0x0100, - /// - /// A raw input message is in the queue. For more information, see Raw Input. - /// Windows XP and higher only. - /// - RAWINPUT = 0x0400, - /// - /// A WM_MOUSEMOVE message or mouse-button message (WM_LBUTTONUP, WM_RBUTTONDOWN, and so on). - /// - MOUSE = MOUSEMOVE | MOUSEBUTTON, - /// - /// An input message is in the queue. This is composed of KEY, MOUSE and RAWINPUT. - /// Windows XP and higher only. - /// - INPUT = MOUSE | KEY | RAWINPUT, - /// - /// An input message is in the queue. This is composed of QS_KEY and QS_MOUSE. - /// Windows 2000 and earlier. - /// - INPUT_LEGACY = MOUSE | KEY, - /// - /// An input, WM_TIMER, WM_PAINT, WM_HOTKEY, or posted message is in the queue. - /// - ALLEVENTS = INPUT | POSTMESSAGE | TIMER | PAINT | HOTKEY, - /// - /// Any message is in the queue. - /// - ALLINPUT = INPUT | POSTMESSAGE | TIMER | PAINT | HOTKEY | SENDMESSAGE - } - + internal enum WindowMessage : int { NULL = 0x0000, @@ -2705,228 +1171,6 @@ namespace OpenTK.Platform.Windows BALLOONUSERCLICK = USER + 0x0005 } - [Flags] - internal enum PeekMessageFlags : uint - { - NoRemove = 0, - Remove = 1, - NoYield = 2 - } - - /// - /// ShowWindow() Commands - /// - internal enum ShowWindowCommand - { - /// - /// Hides the window and activates another window. - /// - HIDE = 0, - /// - /// Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time. - /// - SHOWNORMAL = 1, - NORMAL = 1, - /// - /// Activates the window and displays it as a minimized window. - /// - SHOWMINIMIZED = 2, - /// - /// Activates the window and displays it as a maximized window. - /// - SHOWMAXIMIZED = 3, - MAXIMIZE = 3, - /// - /// Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated. - /// - SHOWNOACTIVATE = 4, - /// - /// Activates the window and displays it in its current size and position. - /// - SHOW = 5, - /// - /// Minimizes the specified window and activates the next top-level window in the Z order. - /// - MINIMIZE = 6, - /// - /// Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated. - /// - SHOWMINNOACTIVE = 7, - /// - /// Displays the window in its current size and position. This value is similar to SW_SHOW, except the window is not activated. - /// - SHOWNA = 8, - /// - /// Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window. - /// - RESTORE = 9, - /// - /// Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. - /// - SHOWDEFAULT = 10, - /// - /// Windows 2000/XP: Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread. - /// - FORCEMINIMIZE = 11, - //MAX = 11, - - // Old ShowWindow() Commands - //HIDE_WINDOW = 0, - //SHOW_OPENWINDOW = 1, - //SHOW_ICONWINDOW = 2, - //SHOW_FULLSCREEN = 3, - //SHOW_OPENNOACTIVATE= 4, - } - - /// - /// Identifiers for the WM_SHOWWINDOW message - /// - internal enum ShowWindowMessageIdentifiers - { - PARENTCLOSING = 1, - OTHERZOOM = 2, - PARENTOPENING = 3, - OTHERUNZOOM = 4, - } - - /// - /// Enumerates the available character sets. - /// - internal enum GdiCharset - { - Ansi = 0, - Default = 1, - Symbol = 2, - ShiftJIS = 128, - Hangeul = 129, - Hangul = 129, - GB2312 = 134, - ChineseBig5 = 136, - OEM = 255, - //#if(WINVER >= 0x0400) - Johab = 130, - Hebrew = 177, - Arabic = 178, - Greek = 161, - Turkish = 162, - Vietnamese = 163, - Thai = 222, - EastEurope = 238, - Russian = 204, - Mac = 77, - Baltic = 186, - } - - /// - /// Identifiers for the GetStockObject method. - /// - internal enum StockObjects - { - WHITE_BRUSH = 0, - LTGRAY_BRUSH = 1, - GRAY_BRUSH = 2, - DKGRAY_BRUSH = 3, - BLACK_BRUSH = 4, - NULL_BRUSH = 5, - HOLLOW_BRUSH = NULL_BRUSH, - WHITE_PEN = 6, - BLACK_PEN = 7, - NULL_PEN = 8, - OEM_FIXED_FONT = 10, - ANSI_FIXED_FONT = 11, - ANSI_VAR_FONT = 12, - SYSTEM_FONT = 13, - DEVICE_DEFAULT_FONT = 14, - DEFAULT_PALETTE = 15, - SYSTEM_FIXED_FONT = 16, - DEFAULT_GUI_FONT = 17, - DC_BRUSH = 18, - DC_PEN = 19, - } - - internal enum MapVirtualKeyType - { - /// uCode is a virtual-key code and is translated into a scan code. If it is a virtual-key code that does not distinguish between left- and right-hand keys, the left-hand scan code is returned. If there is no translation, the function returns 0. - VirtualKeyToScanCode = 0, - /// uCode is a scan code and is translated into a virtual-key code that does not distinguish between left- and right-hand keys. If there is no translation, the function returns 0. - ScanCodeToVirtualKey = 1, - /// uCode is a virtual-key code and is translated into an unshifted character value in the low-order word of the return value. Dead keys (diacritics) are indicated by setting the top bit of the return value. If there is no translation, the function returns 0. - VirtualKeyToCharacter = 2, - /// Windows NT/2000/XP: uCode is a scan code and is translated into a virtual-key code that distinguishes between left- and right-hand keys. If there is no translation, the function returns 0. - ScanCodeToVirtualKeyExtended = 3, - VirtualKeyToScanCodeExtended = 4, - } - - internal enum DwmWindowAttribute - { - NCRENDERING_ENABLED = 1, - NCRENDERING_POLICY, - TRANSITIONS_FORCEDISABLED, - ALLOW_NCPAINT, - CAPTION_BUTTON_BOUNDS, - NONCLIENT_RTL_LAYOUT, - FORCE_ICONIC_REPRESENTATION, - FLIP3D_POLICY, - EXTENDED_FRAME_BOUNDS, - HAS_ICONIC_BITMAP, - DISALLOW_PEEK, - EXCLUDED_FROM_PEEK, - LAST - } - - [Flags] - internal enum ShGetFileIconFlags : int - { - /// get icon - Icon = 0x000000100, - /// get display name - DisplayName = 0x000000200, - /// get type name - TypeName = 0x000000400, - /// get attributes - Attributes = 0x000000800, - /// get icon location - IconLocation = 0x000001000, - /// return exe type - ExeType = 0x000002000, - /// get system icon index - SysIconIndex = 0x000004000, - /// put a link overlay on icon - LinkOverlay = 0x000008000, - /// show icon in selected state - Selected = 0x000010000, - /// get only specified attributes - Attr_Specified = 0x000020000, - /// get large icon - LargeIcon = 0x000000000, - /// get small icon - SmallIcon = 0x000000001, - /// get open icon - OpenIcon = 0x000000002, - /// get shell size icon - ShellIconSize = 0x000000004, - /// pszPath is a pidl - PIDL = 0x000000008, - /// use passed dwFileAttribute - UseFileAttributes = 0x000000010, - /// apply the appropriate overlays - AddOverlays = 0x000000020, - /// Get the index of the overlay in the upper 8 bits of the iIcon - OverlayIndex = 0x000000040, - } - - internal enum MonitorFrom - { - Null = 0, - Primary = 1, - Nearest = 2, - } - - internal enum CursorName : int - { - Arrow = 32512 - } - [Flags] internal enum TrackMouseEventFlags : uint { @@ -2937,51 +1181,10 @@ namespace OpenTK.Platform.Windows CANCEL = 0x80000000, } - internal enum MouseActivate - { - ACTIVATE = 1, - ACTIVATEANDEAT = 2, - NOACTIVATE = 3, - NOACTIVATEANDEAT = 4, - } - - internal enum DeviceNotification - { - WINDOW_HANDLE = 0x00000000, - SERVICE_HANDLE = 0x00000001, - ALL_INTERFACE_CLASSES = 0x00000004, - } - - internal enum DeviceBroadcastType - { - OEM = 0, - VOLUME = 2, - PORT = 3, - INTERFACE = 5, - HANDLE = 6, - } - [SuppressUnmanagedCodeSecurity] [UnmanagedFunctionPointer(CallingConvention.Winapi)] internal delegate IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam); - [StructLayout(LayoutKind.Sequential), CLSCompliant(false)] - internal struct MSG - { - internal IntPtr HWnd; - internal WindowMessage Message; - internal IntPtr WParam; - internal IntPtr LParam; - internal uint Time; - internal POINT Point; - //internal object RefObject; - - public override string ToString() - { - return String.Format("msg=0x{0:x} ({1}) hwnd=0x{2:x} wparam=0x{3:x} lparam=0x{4:x} pt=0x{5:x}", (int)Message, Message.ToString(), HWnd.ToInt32(), WParam.ToInt32(), LParam.ToInt32(), Point); - } - } - [StructLayout(LayoutKind.Sequential)] internal struct POINT { diff --git a/GLWidget/OpenTK/Platform/Windows/Bindings/Wgl.cs b/GLWidget/OpenTK/Platform/Windows/Bindings/Wgl.cs index c2a6db7..f2a5685 100644 --- a/GLWidget/OpenTK/Platform/Windows/Bindings/Wgl.cs +++ b/GLWidget/OpenTK/Platform/Windows/Bindings/Wgl.cs @@ -61,6 +61,50 @@ namespace OpenTK.Platform.Windows EntryPoints = new IntPtr[EntryPointNames.Length]; } + public delegate IntPtr CreateContextAttribsARBDelegate(IntPtr hDC, IntPtr shareHGLRC, int[] attribs); + public static CreateContextAttribsARBDelegate wglCreateContextAttribs; + + public delegate bool SwapIntervalEXT(int interval); + public static SwapIntervalEXT wglSwapIntervalEXT; + + public delegate int GetSwapIntervalEXT(); + public static GetSwapIntervalEXT wglGetSwapIntervalEXT; + + internal delegate IntPtr GetExtensionsStringARBDelegate(IntPtr hdc); + internal static GetExtensionsStringARBDelegate wglGetExtensionsStringARB; + + internal delegate IntPtr GetExtensionsStringEXTDelegate(); + internal static GetExtensionsStringEXTDelegate wglGetExtensionsStringEXT; + + public delegate bool ChoosePixelFormatARB(IntPtr hdc, int[] piAttribIList, float[] pfAttribFList, uint nMaxFormats, int[] piFormats, ref uint nNumFormats); + public static ChoosePixelFormatARB wglChoosePixelFormatARB; + + public delegate bool GetPixelFormatAttribivARB(IntPtr hdc, int iPixelFormat, int iLayerPlane, uint nAttributes, int[] piAttributes, int[] piValues); + public static GetPixelFormatAttribivARB WglGetPixelFormatAttribivARB; + + public static string GetExtensionsStringARB(IntPtr hdc) + { + unsafe + { + return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(wglGetExtensionsStringARB(hdc)); + } + } + + public static string GetExtensionsStringEXT() + { + unsafe + { + return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(wglGetExtensionsStringEXT()); + } + } + + public static TDelegate GetProcAddress(string name) where TDelegate : class + { + IntPtr addr = GetProcAddress(name); + if (addr == IntPtr.Zero) return null; + return (TDelegate)(object)System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(addr, typeof(TDelegate)); + } + [SuppressUnmanagedCodeSecurity] [DllImport(Wgl.Library, EntryPoint = "wglCreateContext", ExactSpelling = true, SetLastError = true)] internal extern static IntPtr CreateContext(IntPtr hDc); @@ -74,12 +118,6 @@ namespace OpenTK.Platform.Windows [DllImport(Wgl.Library, EntryPoint = "wglMakeCurrent", ExactSpelling = true, SetLastError = true)] internal extern static Boolean MakeCurrent(IntPtr hDc, IntPtr newContext); [SuppressUnmanagedCodeSecurity] - [DllImport(Wgl.Library, EntryPoint = "wglChoosePixelFormat", ExactSpelling = true, SetLastError = true)] - internal extern static unsafe int ChoosePixelFormat(IntPtr hDc, ref PixelFormatDescriptor pPfd); - [SuppressUnmanagedCodeSecurity] - [DllImport(Wgl.Library, EntryPoint = "wglDescribePixelFormat", ExactSpelling = true, SetLastError = true)] - internal extern static unsafe int DescribePixelFormat(IntPtr hdc, int ipfd, int cjpfd, ref PixelFormatDescriptor ppfd); - [SuppressUnmanagedCodeSecurity] [DllImport(Wgl.Library, EntryPoint = "wglGetCurrentDC", ExactSpelling = true, SetLastError = true)] internal extern static IntPtr GetCurrentDC(); [SuppressUnmanagedCodeSecurity] @@ -89,71 +127,7 @@ namespace OpenTK.Platform.Windows [DllImport(Wgl.Library, EntryPoint = "wglGetProcAddress", ExactSpelling = true, SetLastError = true)] internal extern static IntPtr GetProcAddress(IntPtr lpszProc); [SuppressUnmanagedCodeSecurity] - [DllImport(Wgl.Library, EntryPoint = "wglGetPixelFormat", ExactSpelling = true, SetLastError = true)] - internal extern static int GetPixelFormat(IntPtr hdc); - [SuppressUnmanagedCodeSecurity] - [DllImport(Wgl.Library, EntryPoint = "wglSetPixelFormat", ExactSpelling = true, SetLastError = true)] - internal extern static Boolean SetPixelFormat(IntPtr hdc, int ipfd, ref PixelFormatDescriptor ppfd); - [SuppressUnmanagedCodeSecurity] - [DllImport(Wgl.Library, EntryPoint = "wglSwapBuffers", ExactSpelling = true, SetLastError = true)] - internal extern static Boolean SwapBuffers(IntPtr hdc); - [SuppressUnmanagedCodeSecurity] [DllImport(Wgl.Library, EntryPoint = "wglShareLists", ExactSpelling = true, SetLastError = true)] internal extern static Boolean ShareLists(IntPtr hrcSrvShare, IntPtr hrcSrvSource); - - [Slot(0)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal unsafe static extern IntPtr wglCreateContextAttribsARB(IntPtr hDC, IntPtr hShareContext, int* attribList); - [Slot(1)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal static extern IntPtr wglGetExtensionsStringARB(IntPtr hdc); - [Slot(2)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal unsafe static extern Boolean wglGetPixelFormatAttribivARB(IntPtr hdc, int iPixelFormat, int iLayerPlane, UInt32 nAttributes, int* piAttributes, [Out] int* piValues); - [Slot(3)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal unsafe static extern Boolean wglGetPixelFormatAttribfvARB(IntPtr hdc, int iPixelFormat, int iLayerPlane, UInt32 nAttributes, int* piAttributes, [Out] Single* pfValues); - [Slot(4)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal unsafe static extern Boolean wglChoosePixelFormatARB(IntPtr hdc, int* piAttribIList, Single* pfAttribFList, UInt32 nMaxFormats, [Out] int* piFormats, [Out] UInt32* nNumFormats); - [Slot(5)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal static extern Boolean wglMakeContextCurrentARB(IntPtr hDrawDC, IntPtr hReadDC, IntPtr hglrc); - [Slot(6)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal static extern IntPtr wglGetCurrentReadDCARB(); - [Slot(7)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal unsafe static extern IntPtr wglCreatePbufferARB(IntPtr hDC, int iPixelFormat, int iWidth, int iHeight, int* piAttribList); - [Slot(8)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal static extern IntPtr wglGetPbufferDCARB(IntPtr hPbuffer); - [Slot(9)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal static extern int wglReleasePbufferDCARB(IntPtr hPbuffer, IntPtr hDC); - [Slot(10)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal static extern Boolean wglDestroyPbufferARB(IntPtr hPbuffer); - [Slot(11)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal unsafe static extern Boolean wglQueryPbufferARB(IntPtr hPbuffer, int iAttribute, [Out] int* piValue); - [Slot(12)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal static extern Boolean wglBindTexImageARB(IntPtr hPbuffer, int iBuffer); - [Slot(13)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal static extern Boolean wglReleaseTexImageARB(IntPtr hPbuffer, int iBuffer); - [Slot(14)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal unsafe static extern Boolean wglSetPbufferAttribARB(IntPtr hPbuffer, int* piAttribList); - [Slot(15)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal static extern IntPtr wglGetExtensionsStringEXT(); - [Slot(16)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal static extern Boolean wglSwapIntervalEXT(int interval); - [Slot(17)] - [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)] - internal static extern int wglGetSwapIntervalEXT(); } } diff --git a/GLWidget/OpenTK/Platform/Windows/WglHelper.cs b/GLWidget/OpenTK/Platform/Windows/WglHelper.cs index 93d1715..170fc9e 100644 --- a/GLWidget/OpenTK/Platform/Windows/WglHelper.cs +++ b/GLWidget/OpenTK/Platform/Windows/WglHelper.cs @@ -51,8 +51,8 @@ namespace OpenTK.Platform.Windows bool get_arb = SupportsFunction("wglGetExtensionsStringARB"); bool get_ext = SupportsFunction("wglGetExtensionsStringEXT"); string str = - get_arb ? OpenGL.Wgl.GetExtensionsStringARB(dc) : - get_ext ? OpenGL.Wgl.GetExtensionsStringEXT(): + get_arb ? Wgl.GetExtensionsStringARB(dc) : + get_ext ? Wgl.GetExtensionsStringEXT(): String.Empty; if (!String.IsNullOrEmpty(str)) @@ -123,6 +123,14 @@ namespace OpenTK.Platform.Windows EntryPoints[i] = GetAddress(EntryPointNames[i]); } extensions.Clear(); + + wglSwapIntervalEXT = GetProcAddress("wglSwapIntervalEXT"); + wglGetSwapIntervalEXT = GetProcAddress("wglGetSwapIntervalEXT"); + wglGetExtensionsStringARB = GetProcAddress("wglGetExtensionsStringARB"); + wglGetExtensionsStringEXT = GetProcAddress("wglGetExtensionsStringEXT"); + wglCreateContextAttribs = GetProcAddress("wglCreateContextAttribsARB"); + wglChoosePixelFormatARB = GetProcAddress("wglChoosePixelFormatARB"); + WglGetPixelFormatAttribivARB = GetProcAddress("wglGetPixelFormatAttribivARB"); } } } diff --git a/GLWidget/OpenTK/Platform/Windows/WinDisplayDevice.cs b/GLWidget/OpenTK/Platform/Windows/WinDisplayDevice.cs index 7e42444..a68e87e 100644 --- a/GLWidget/OpenTK/Platform/Windows/WinDisplayDevice.cs +++ b/GLWidget/OpenTK/Platform/Windows/WinDisplayDevice.cs @@ -41,33 +41,6 @@ namespace OpenTK.Platform.Windows HandleDisplaySettingsChanged; } - public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution) - { - DeviceMode mode = null; - - if (resolution != null) - { - mode = new DeviceMode(); - mode.PelsWidth = resolution.Width; - mode.PelsHeight = resolution.Height; - mode.BitsPerPel = resolution.BitsPerPixel; - mode.DisplayFrequency = (int)resolution.RefreshRate; - mode.Fields = Constants.DM_BITSPERPEL - | Constants.DM_PELSWIDTH - | Constants.DM_PELSHEIGHT - | Constants.DM_DISPLAYFREQUENCY; - } - - return Constants.DISP_CHANGE_SUCCESSFUL == - Functions.ChangeDisplaySettingsEx((string)device.Id, mode, IntPtr.Zero, - ChangeDisplaySettingsEnum.Fullscreen, IntPtr.Zero); - } - - public sealed override bool TryRestoreResolution(DisplayDevice device) - { - return TryChangeResolution(device, null); - } - public void RefreshDisplayDevices() { lock (display_lock) diff --git a/GLWidget/OpenTK/Platform/Windows/WinGLContext.cs b/GLWidget/OpenTK/Platform/Windows/WinGLContext.cs index f04af2d..321cda4 100644 --- a/GLWidget/OpenTK/Platform/Windows/WinGLContext.cs +++ b/GLWidget/OpenTK/Platform/Windows/WinGLContext.cs @@ -160,7 +160,7 @@ namespace OpenTK.Platform.Windows attributes.Add(0); Handle = new ContextHandle( - OpenGL.Wgl.CreateContextAttribsARB( + Wgl.wglCreateContextAttribs( window.DeviceContext, sharedContext != null ? (sharedContext as IGraphicsContextInternal).Context.Handle : IntPtr.Zero, attributes.ToArray())); @@ -304,7 +304,7 @@ namespace OpenTK.Platform.Windows { if (vsync_supported) { - return OpenGL.Wgl.GetSwapIntervalEXT(); + return Wgl.wglGetSwapIntervalEXT(); } else { @@ -322,7 +322,7 @@ namespace OpenTK.Platform.Windows { value = 1; } - if (!OpenGL.Wgl.SwapIntervalEXT(value)) + if (!Wgl.wglSwapIntervalEXT(value)) { Debug.Print("wglSwapIntervalEXT call failed."); } diff --git a/GLWidget/OpenTK/Platform/Windows/WinGraphicsMode.cs b/GLWidget/OpenTK/Platform/Windows/WinGraphicsMode.cs index 8c5cd21..60a788b 100644 --- a/GLWidget/OpenTK/Platform/Windows/WinGraphicsMode.cs +++ b/GLWidget/OpenTK/Platform/Windows/WinGraphicsMode.cs @@ -184,10 +184,10 @@ namespace OpenTK.Platform.Windows attributes.Add(0); attributes.Add(0); - uint[] count = new uint[attributes.Count]; + uint count = (uint)attributes.Count; - if (OpenGL.Wgl.ChoosePixelFormatARB(device, attributes.ToArray(), null, (uint)format.Length, format, count) - && count.Length > 0) + if (Wgl.wglChoosePixelFormatARB(device, attributes.ToArray(), null, (uint)format.Length, format, ref count) + && count > 0) { created_mode = DescribePixelFormatARB(device, format[0]); retry = false; @@ -377,7 +377,7 @@ namespace OpenTK.Platform.Windows int[] values = new int[attribs.Length]; // Get the format attributes for this pixel format - if (!OpenGL.Wgl.GetPixelFormatAttribARB(device, pixelformat, 0, (uint)attribs.Length - 1, attribs, values)) + if (!Wgl.WglGetPixelFormatAttribivARB(device, pixelformat, 0, (uint)attribs.Length - 1, attribs, values)) { Debug.Print("[Warning] Failed to detect attributes for PixelFormat: {0}.", pixelformat); } diff --git a/GLWidget/OpenTK/Platform/X11/API.cs b/GLWidget/OpenTK/Platform/X11/API.cs index 5a9f0ee..125f337 100644 --- a/GLWidget/OpenTK/Platform/X11/API.cs +++ b/GLWidget/OpenTK/Platform/X11/API.cs @@ -47,33 +47,13 @@ namespace OpenTK.Platform.X11 using Status = System.Int32; using SizeID = System.UInt16; - /// - /// X11 has some defined values they are defined with c's #define in X.h - /// - internal static class Consts - { - /// - /// Universal null resource or null atom. From header: #define None 0L - /// - public static readonly IntPtr None = IntPtr.Zero; - // - /// - /// Special time value. From header: #define CurrentTime 0L - /// - public static readonly IntPtr CurrentTime = IntPtr.Zero; // - } - internal static class API { private const string _dll_name = "libX11"; private const string _dll_name_vid = "libXxf86vm"; - private static Window rootWindow; - internal static Display DefaultDisplay { get; private set; } - private static int DefaultScreen { get; set; } - //internal static Window RootWindow { get { return rootWindow; } } internal static int ScreenCount { get; } @@ -100,189 +80,6 @@ namespace OpenTK.Platform.X11 //AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); } - private static void CurrentDomain_ProcessExit(object sender, EventArgs e) - { - if (DefaultDisplay != IntPtr.Zero) - { - Functions.XCloseDisplay(DefaultDisplay); - DefaultDisplay = IntPtr.Zero; - DefaultScreen = 0; - rootWindow = IntPtr.Zero; - } - } - - // Display management - //[DllImport(_dll_name, EntryPoint = "XOpenDisplay")] - //extern public static IntPtr OpenDisplay([MarshalAs(UnmanagedType.LPTStr)] string display_name); - - //[DllImport(_dll_name, EntryPoint = "XCloseDisplay")] - //extern public static void CloseDisplay(Display display); - - //[DllImport(_dll_name, EntryPoint = "XCreateColormap")] - //extern public static IntPtr CreateColormap(Display display, Window window, IntPtr visual, int alloc); - - [DllImport(_dll_name, EntryPoint = "XCreateSimpleWindow")] - public extern static Window CreateSimpleWindow( - Display display, - Window parent, - int x, int y, - int width, int height, - int border_width, - long border, - long background - ); - - [DllImport(_dll_name, EntryPoint = "XResizeWindow")] - public extern static int XResizeWindow(Display display, Window window, int width, int height); - - [DllImport(_dll_name, EntryPoint = "XDestroyWindow")] - public extern static void DestroyWindow(Display display, Window window); - - [DllImport(_dll_name, EntryPoint = "XMapWindow")] - extern public static void MapWindow(Display display, Window window); - - [DllImport(_dll_name, EntryPoint = "XMapRaised")] - extern public static void MapRaised(Display display, Window window); - - [DllImport(_dll_name, EntryPoint = "XDefaultVisual")] - extern public static IntPtr DefaultVisual(Display display, int screen_number); - - /// - /// Frees the memory used by an X structure. Only use on unmanaged structures! - /// - /// A pointer to the structure that will be freed. - [DllImport(_dll_name, EntryPoint = "XFree")] - extern public static void Free(IntPtr buffer); - - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport(_dll_name, EntryPoint = "XEventsQueued")] - extern public static int EventsQueued(Display display, int mode); - - [System.Security.SuppressUnmanagedCodeSecurity] - [DllImport(_dll_name, EntryPoint = "XPending")] - extern public static int Pending(Display display); - - //[System.Security.SuppressUnmanagedCodeSecurity] - [DllImport(_dll_name, EntryPoint = "XNextEvent")] - extern public static void NextEvent( - Display display, - [MarshalAs(UnmanagedType.AsAny)][In, Out]object e); - - [DllImport(_dll_name, EntryPoint = "XNextEvent")] - extern public static void NextEvent(Display display, [In, Out] IntPtr e); - - [DllImport(_dll_name, EntryPoint = "XPeekEvent")] - extern public static void PeekEvent( - Display display, - [MarshalAs(UnmanagedType.AsAny)][In, Out]object event_return - ); - - [DllImport(_dll_name, EntryPoint = "XPeekEvent")] - extern public static void PeekEvent(Display display, [In, Out]XEvent event_return); - - [DllImport(_dll_name, EntryPoint = "XSendEvent")] - [return: MarshalAs(UnmanagedType.Bool)] - extern public static bool SendEvent(Display display, Window window, bool propagate, - [MarshalAs(UnmanagedType.SysInt)]EventMask event_mask, ref XEvent event_send); - - /// - /// The XSelectInput() function requests that the X server report the events associated - /// with the specified event mask. - /// - /// Specifies the connection to the X server. - /// Specifies the window whose events you are interested in. - /// Specifies the event mask. - /// - /// Initially, X will not report any of these events. - /// Events are reported relative to a window. - /// If a window is not interested in a device event, - /// it usually propagates to the closest ancestor that is interested, - /// unless the do_not_propagate mask prohibits it. - /// Setting the event-mask attribute of a window overrides any previous call for the same window but not for other clients. Multiple clients can select for the same events on the same window with the following restrictions: - /// Multiple clients can select events on the same window because their event masks are disjoint. When the X server generates an event, it reports it to all interested clients. - /// Only one client at a time can select CirculateRequest, ConfigureRequest, or MapRequest events, which are associated with the event mask SubstructureRedirectMask. - /// Only one client at a time can select a ResizeRequest event, which is associated with the event mask ResizeRedirectMask. - /// Only one client at a time can select a ButtonPress event, which is associated with the event mask ButtonPressMask. - /// The server reports the event to all interested clients. - /// XSelectInput() can generate a BadWindow error. - /// - [DllImport(_dll_name, EntryPoint = "XSelectInput")] - public static extern void SelectInput(Display display, Window w, EventMask event_mask); - - /// - /// When the predicate procedure finds a match, XCheckIfEvent() copies the matched event into the client-supplied XEvent structure and returns True. (This event is removed from the queue.) If the predicate procedure finds no match, XCheckIfEvent() returns False, and the output buffer will have been flushed. All earlier events stored in the queue are not discarded. - /// - /// Specifies the connection to the X server. - /// Returns a copy of the matched event's associated structure. - /// Specifies the procedure that is to be called to determine if the next event in the queue matches what you want - /// Specifies the user-supplied argument that will be passed to the predicate procedure. - /// true if the predicate returns true for some event, false otherwise - [DllImport(_dll_name, EntryPoint = "XCheckIfEvent")] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool CheckIfEvent(Display display, ref XEvent event_return, - /*[MarshalAs(UnmanagedType.FunctionPtr)] */ CheckEventPredicate predicate, /*XPointer*/ IntPtr arg); - - [DllImport(_dll_name, EntryPoint = "XIfEvent")] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool IfEvent(Display display, ref XEvent event_return, - /*[MarshalAs(UnmanagedType.FunctionPtr)] */ CheckEventPredicate predicate, /*XPointer*/ IntPtr arg); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool CheckEventPredicate(Display display, ref XEvent @event, IntPtr arg); - - [DllImport(_dll_name, EntryPoint = "XCheckMaskEvent")] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool CheckMaskEvent(Display display, EventMask event_mask, ref XEvent event_return); - - [DllImport(_dll_name, EntryPoint = "XGrabPointer")] - extern public static ErrorCodes GrabPointer(Display display, IntPtr grab_window, - bool owner_events, int event_mask, GrabMode pointer_mode, GrabMode keyboard_mode, - IntPtr confine_to, IntPtr cursor, int time); - - [DllImport(_dll_name, EntryPoint = "XUngrabPointer")] - extern public static ErrorCodes UngrabPointer(Display display, int time); - - [DllImport(_dll_name, EntryPoint = "XGrabKeyboard")] - extern public static ErrorCodes GrabKeyboard(Display display, IntPtr grab_window, - bool owner_events, GrabMode pointer_mode, GrabMode keyboard_mode, int time); - - [DllImport(_dll_name, EntryPoint = "XUngrabKeyboard")] - extern public static void UngrabKeyboard(Display display, int time); - - /// - /// The XGetKeyboardMapping() function returns the symbols for the specified number of KeyCodes starting with first_keycode. - /// - /// Specifies the connection to the X server. - /// Specifies the first KeyCode that is to be returned. - /// Specifies the number of KeyCodes that are to be returned - /// Returns the number of KeySyms per KeyCode. - /// - /// - /// The value specified in first_keycode must be greater than or equal to min_keycode as returned by XDisplayKeycodes(), or a BadValue error results. In addition, the following expression must be less than or equal to max_keycode as returned by XDisplayKeycodes(): - /// first_keycode + keycode_count - 1 - /// If this is not the case, a BadValue error results. The number of elements in the KeySyms list is: - /// keycode_count * keysyms_per_keycode_return - /// KeySym number N, counting from zero, for KeyCode K has the following index in the list, counting from zero: - /// (K - first_code) * keysyms_per_code_return + N - /// The X server arbitrarily chooses the keysyms_per_keycode_return value to be large enough to report all requested symbols. A special KeySym value of NoSymbol is used to fill in unused elements for individual KeyCodes. To free the storage returned by XGetKeyboardMapping(), use XFree(). - /// XGetKeyboardMapping() can generate a BadValue error. - /// Diagnostics: - /// BadValue: Some numeric value falls outside the range of values accepted by the request. Unless a specific range is specified for an argument, the full range defined by the argument's type is accepted. Any argument defined as a set of alternatives can generate this error. - /// - [DllImport(_dll_name, EntryPoint = "XGetKeyboardMapping")] - public static extern KeySym GetKeyboardMapping(Display display, KeyCode first_keycode, int keycode_count, - ref int keysyms_per_keycode_return); - - /// - /// The XDisplayKeycodes() function returns the min-keycodes and max-keycodes supported by the specified display. - /// - /// Specifies the connection to the X server. - /// Returns the minimum number of KeyCodes - /// Returns the maximum number of KeyCodes. - /// The minimum number of KeyCodes returned is never less than 8, and the maximum number of KeyCodes returned is never greater than 255. Not all KeyCodes in this range are required to have corresponding keys. - [DllImport(_dll_name, EntryPoint = "XDisplayKeycodes")] - public static extern void DisplayKeycodes(Display display, ref int min_keycodes_return, ref int max_keycodes_return); - [StructLayout(LayoutKind.Sequential)] internal struct XF86VidModeModeLine { @@ -369,74 +166,6 @@ namespace OpenTK.Platform.X11 private IntPtr _private; /* Server privates */ } - //Monitor information: - [StructLayout(LayoutKind.Sequential)] - internal struct XF86VidModeMonitor - { - [MarshalAs(UnmanagedType.LPStr)] private string vendor; /* Name of manufacturer */ - [MarshalAs(UnmanagedType.LPStr)] private string model; /* Model name */ - private float EMPTY; /* unused, for backward compatibility */ - - private byte nhsync; /* Number of horiz sync ranges */ - /*XF86VidModeSyncRange* */ - private IntPtr hsync; /* Horizontal sync ranges */ - - private byte nvsync; /* Number of vert sync ranges */ - /*XF86VidModeSyncRange* */ - private IntPtr vsync; /* Vertical sync ranges */ - } - - [StructLayout(LayoutKind.Sequential)] - internal struct XF86VidModeSyncRange - { - private float hi; /* Top of range */ - private float lo; /* Bottom of range */ - } - - [StructLayout(LayoutKind.Sequential)] - internal struct XF86VidModeNotifyEvent - { - private int type; /* of event */ - private ulong serial; /* # of last request processed by server */ - private bool send_event; /* true if this came from a SendEvent req */ - private Display display; /* Display the event was read from */ - private IntPtr root; /* root window of event screen */ - private int state; /* What happened */ - private int kind; /* What happened */ - - private bool forced; /* extents of new region */ - /* Time */ - private IntPtr time; /* event timestamp */ - } - - [StructLayout(LayoutKind.Sequential)] - internal struct XF86VidModeGamma - { - private float red; /* Red Gamma value */ - private float green; /* Green Gamma value */ - private float blue; /* Blue Gamma value */ - } - [DllImport(_dll_name_vid)] - extern public static bool XF86VidModeQueryExtension( - Display display, - out int event_base_return, - out int error_base_return); - /* - [DllImport(_dll_name_vid)] - extern public static bool XF86VidModeSwitchMode( - Display display, - int screen, - int zoom); - */ - - [DllImport(_dll_name_vid)] - extern public static bool XF86VidModeSwitchToMode( - Display display, - int screen, - IntPtr - /*XF86VidModeModeInfo* */ modeline); - - [DllImport(_dll_name_vid)] extern public static bool XF86VidModeQueryVersion( Display display, @@ -465,121 +194,6 @@ namespace OpenTK.Platform.X11 out int x_return, out int y_return); - [DllImport(_dll_name_vid)] - extern public static bool XF86VidModeSetViewPort( - Display display, - int screen, - int x, - int y); - - /* -Bool XF86VidModeSetClientVersion( - Display *display); - -Bool XF86VidModeDeleteModeLine( - Display *display, - int screen, - XF86VidModeModeInfo *modeline); - -Bool XF86VidModeModModeLine( - Display *display, - int screen, - XF86VidModeModeLine *modeline); - -Status XF86VidModeValidateModeLine( - Display *display, - int screen, - XF86VidModeModeLine *modeline); - -Bool XF86VidModeLockModeSwitch( - Display *display, - int screen, - int lock); - -Bool XF86VidModeGetMonitor( - Display *display, - int screen, - XF86VidModeMonitor *monitor); - -XF86VidModeGetDotClocks( - Display *display, - int screen, - int *flags return, - int *number of clocks return, - int *max dot clock return, - int **clocks return); - -XF86VidModeGetGamma( - Display *display, - int screen, - XF86VidModeGamma *Gamma); - -XF86VidModeSetGamma( - Display *display, - int screen, - XF86VidModeGamma *Gamma); - -XF86VidModeGetGammaRamp( - Display *display, - int screen, - int size, - unsigned short *red array, - unsigned short *green array, - unsigned short *blue array); - -XF86VidModeSetGammaRamp( - Display *display, - int screen, - int size, - unsigned short *red array, - unsigned short *green array, - unsigned short *blue array); - -XF86VidModeGetGammaRampSize( - Display *display, - int screen, - int *size); - * */ - - [DllImport(_dll_name, EntryPoint = "XLookupKeysym")] - public static extern KeySym LookupKeysym(ref XKeyEvent key_event, int index); - - } - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct XcursorImage - { - public XcursorUInt version; - public XcursorDim size; - public XcursorDim width; - public XcursorDim height; - public XcursorDim xhot; - public XcursorDim yhot; - public XcursorUInt delay; - public XcursorPixel* pixels; - } - - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct XcursorImages - { - public int nimage; - public XcursorImage **images; - public char *name; - } - - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct XcursorCursors - { - public Display dpy; - public int refcount; - public int ncursor; - public Cursor *cursors; - } - - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct XcursorAnimate - { - public XcursorCursors *cursors; - public int sequence; } [StructLayout(LayoutKind.Sequential)] @@ -603,68 +217,12 @@ XF86VidModeGetGammaRampSize( } } - [StructLayout(LayoutKind.Sequential)] - internal struct SizeHints - { - public long flags; /* marks which fields in this structure are defined */ - public int x, y; /* Obsolete */ - public int width, height; /* Obsolete */ - public int min_width, min_height; - public int max_width, max_height; - public int width_inc, height_inc; - public Rectangle min_aspect, max_aspect; - public int base_width, base_height; - public int win_gravity; - internal struct Rectangle - { - public int x; /* numerator */ - public int y; /* denominator */ - private void stop_the_compiler_warnings() { x = y = 0; } - } - /* this structure may be extended in the future */ - } - internal struct XRRScreenSize { internal int Width, Height; internal int MWidth, MHeight; }; - unsafe internal struct Screen - { - private XExtData ext_data; /* hook for extension to hang buffer */ - private IntPtr display; /* back pointer to display structure */ /* _XDisplay */ - private Window root; /* Root window id. */ - - private int width, height; /* width and height of screen */ - private int mwidth, mheight; /* width and height of in millimeters */ - - private int ndepths; /* number of depths possible */ - //Depth *depths; /* list of allowable depths on the screen */ - private int root_depth; /* bits per pixel */ - //Visual* root_visual; /* root visual */ - private IntPtr default_gc; /* GC for the root root visual */ // GC - - private Colormap cmap; /* default color map */ - private UIntPtr white_pixel; // unsigned long - private UIntPtr black_pixel; /* White and Black pixel values */ // unsigned long - private int max_maps, min_maps; /* max and min color maps */ - - private int backing_store; /* Never, WhenMapped, Always */ - private Bool save_unders; - private long root_input_mask; /* initial root input mask */ - } - - unsafe internal class XExtData - { - private int number; /* number returned by XRegisterExtension */ - private XExtData next; /* next item on list of buffer for structure */ - - private delegate int FreePrivateDelegate(XExtData extension); - - private FreePrivateDelegate FreePrivate; /* called to free private storage */ - private XPointer private_data; /* buffer private to this extension. */ - }; [StructLayout(LayoutKind.Sequential)] internal struct MotifWmHints @@ -723,69 +281,6 @@ XF86VidModeGetGammaRampSize( FullApplicationModal = 3 } - internal struct Constants - { - public const int QueuedAlready = 0; - public const int QueuedAfterReading = 1; - public const int QueuedAfterFlush = 2; - - public const int CopyFromParent = 0; - public const int CWX = 1; - public const int InputOutput = 1; - public const int InputOnly = 2; - - /* The hints we recognize */ - public const string XA_WIN_PROTOCOLS = "_WIN_PROTOCOLS"; - public const string XA_WIN_ICONS = "_WIN_ICONS"; - public const string XA_WIN_WORKSPACE = "_WIN_WORKSPACE"; - public const string XA_WIN_WORKSPACE_COUNT = "_WIN_WORKSPACE_COUNT"; - public const string XA_WIN_WORKSPACE_NAMES = "_WIN_WORKSPACE_NAMES"; - public const string XA_WIN_LAYER = "_WIN_LAYER"; - public const string XA_WIN_STATE = "_WIN_STATE"; - public const string XA_WIN_HINTS = "_WIN_HINTS"; - public const string XA_WIN_WORKAREA = "_WIN_WORKAREA"; - public const string XA_WIN_CLIENT_LIST = "_WIN_CLIENT_LIST"; - public const string XA_WIN_APP_STATE = "_WIN_APP_STATE"; - public const string XA_WIN_EXPANDED_SIZE = "_WIN_EXPANDED_SIZE"; - public const string XA_WIN_CLIENT_MOVING = "_WIN_CLIENT_MOVING"; - public const string XA_WIN_SUPPORTING_WM_CHECK = "_WIN_SUPPORTING_WM_CHECK"; - } - - internal enum WindowLayer - { - Desktop = 0, - Below = 2, - Normal = 4, - OnTop = 6, - Dock = 8, - AboveDock = 10, - Menu = 12, - } - - internal enum WindowState - { - Sticky = (1 << 0), /* everyone knows sticky */ - Minimized = (1 << 1), /* ??? */ - MaximizedVertically = (1 << 2), /* window in maximized V state */ - MaximizedHorizontally = (1 << 3), /* window in maximized H state */ - Hidden = (1 << 4), /* not on taskbar but window visible */ - Shaded = (1 << 5), /* shaded (NeXT style), */ - HID_WORKSPACE = (1 << 6), /* not on current desktop */ - HID_TRANSIENT = (1 << 7), /* owner of transient is hidden */ - FixedPosition = (1 << 8), /* window is fixed in position even */ - ArrangeIgnore = (1 << 9), /* ignore for auto arranging */ - } - - internal enum WindowHints - { - SkipFocus = (1 << 0), /* "alt-tab" skips this win */ - SkipWinlist = (1 << 1), /* not in win list */ - SkipTaskbar = (1 << 2), /* not on taskbar */ - GroupTransient = (1 << 3), /* ??????? */ - FocusOnClick = (1 << 4), /* app only accepts focus when clicked */ - DoNotCover = (1 << 5), /* attempt to not cover this window */ - } - internal enum ErrorCodes : int { Success = 0, @@ -808,430 +303,6 @@ XF86VidModeGetGammaRampSize( BadImplementation = 17, } - [Flags] - internal enum CreateWindowMask : long//: ulong - { - CWBackPixmap = (1L << 0), - CWBackPixel = (1L << 1), - CWSaveUnder = (1L << 10), - CWEventMask = (1L << 11), - CWDontPropagate = (1L << 12), - CWColormap = (1L << 13), - CWCursor = (1L << 14), - CWBorderPixmap = (1L << 2), - CWBorderPixel = (1L << 3), - CWBitGravity = (1L << 4), - CWWinGravity = (1L << 5), - CWBackingStore = (1L << 6), - CWBackingPlanes = (1L << 7), - CWBackingPixel = (1L << 8), - CWOverrideRedirect = (1L << 9), - - //CWY = (1 << 1), - //CWWidth = (1 << 2), - //CWHeight = (1 << 3), - //CWBorderWidth = (1 << 4), - //CWSibling = (1 << 5), - //CWStackMode = (1 << 6), - } - - /// - /// Defines LATIN-1 and miscellaneous keys. - /// - [CLSCompliant(false)] - internal enum XKey - { - /* - * TTY function keys, cleverly chosen to map to ASCII, for convenience of - * programming, but could have been arbitrary (at the cost of lookup - * tables in client code). - */ - - BackSpace = 0xff08, /* Back space, back char */ - Tab = 0xff09, - Linefeed = 0xff0a, /* Linefeed, LF */ - Clear = 0xff0b, - Return = 0xff0d, /* Return, enter */ - Pause = 0xff13, /* Pause, hold */ - Scroll_Lock = 0xff14, - Sys_Req = 0xff15, - Escape = 0xff1b, - Delete = 0xffff, /* Delete, rubout */ - - - - /* International & multi-key character composition */ - - Multi_key = 0xff20, /* Multi-key character compose */ - Codeinput = 0xff37, - SingleCandidate = 0xff3c, - MultipleCandidate = 0xff3d, - PreviousCandidate = 0xff3e, - - /* Japanese keyboard support */ - - Kanji = 0xff21, /* Kanji, Kanji convert */ - Muhenkan = 0xff22, /* Cancel Conversion */ - Henkan_Mode = 0xff23, /* Start/Stop Conversion */ - Henkan = 0xff23, /* Alias for Henkan_Mode */ - Romaji = 0xff24, /* to Romaji */ - Hiragana = 0xff25, /* to Hiragana */ - Katakana = 0xff26, /* to Katakana */ - Hiragana_Katakana = 0xff27, /* Hiragana/Katakana toggle */ - Zenkaku = 0xff28, /* to Zenkaku */ - Hankaku = 0xff29, /* to Hankaku */ - Zenkaku_Hankaku = 0xff2a, /* Zenkaku/Hankaku toggle */ - Touroku = 0xff2b, /* Add to Dictionary */ - Massyo = 0xff2c, /* Delete from Dictionary */ - Kana_Lock = 0xff2d, /* Kana Lock */ - Kana_Shift = 0xff2e, /* Kana Shift */ - Eisu_Shift = 0xff2f, /* Alphanumeric Shift */ - Eisu_toggle = 0xff30, /* Alphanumeric toggle */ - Kanji_Bangou = 0xff37, /* Codeinput */ - Zen_Koho = 0xff3d, /* Multiple/All Candidate(s) */ - Mae_Koho = 0xff3e, /* Previous Candidate */ - - /* 0xff31 thru 0xff3f are under XK_KOREAN */ - - /* Cursor control & motion */ - - Home = 0xff50, - Left = 0xff51, /* Move left, left arrow */ - Up = 0xff52, /* Move up, up arrow */ - Right = 0xff53, /* Move right, right arrow */ - Down = 0xff54, /* Move down, down arrow */ - Prior = 0xff55, /* Prior, previous */ - Page_Up = 0xff55, - Next = 0xff56, /* Next */ - Page_Down = 0xff56, - End = 0xff57, /* EOL */ - Begin = 0xff58, /* BOL */ - - - /* Misc functions */ - - Select = 0xff60, /* Select, mark */ - Print = 0xff61, - Execute = 0xff62, /* Execute, run, do */ - Insert = 0xff63, /* Insert, insert here */ - Undo = 0xff65, - Redo = 0xff66, /* Redo, again */ - Menu = 0xff67, - Find = 0xff68, /* Find, search */ - Cancel = 0xff69, /* Cancel, stop, abort, exit */ - Help = 0xff6a, /* Help */ - Break = 0xff6b, - Mode_switch = 0xff7e, /* Character set switch */ - script_switch = 0xff7e, /* Alias for mode_switch */ - Num_Lock = 0xff7f, - - /* Keypad functions, keypad numbers cleverly chosen to map to ASCII */ - - KP_Space = 0xff80, /* Space */ - KP_Tab = 0xff89, - KP_Enter = 0xff8d, /* Enter */ - KP_F1 = 0xff91, /* PF1, KP_A, ... */ - KP_F2 = 0xff92, - KP_F3 = 0xff93, - KP_F4 = 0xff94, - KP_Home = 0xff95, - KP_Left = 0xff96, - KP_Up = 0xff97, - KP_Right = 0xff98, - KP_Down = 0xff99, - KP_Prior = 0xff9a, - KP_Page_Up = 0xff9a, - KP_Next = 0xff9b, - KP_Page_Down = 0xff9b, - KP_End = 0xff9c, - KP_Begin = 0xff9d, - KP_Insert = 0xff9e, - KP_Delete = 0xff9f, - KP_Equal = 0xffbd, /* Equals */ - KP_Multiply = 0xffaa, - KP_Add = 0xffab, - KP_Separator = 0xffac, /* Separator, often comma */ - KP_Subtract = 0xffad, - KP_Decimal = 0xffae, - KP_Divide = 0xffaf, - - KP_0 = 0xffb0, - KP_1 = 0xffb1, - KP_2 = 0xffb2, - KP_3 = 0xffb3, - KP_4 = 0xffb4, - KP_5 = 0xffb5, - KP_6 = 0xffb6, - KP_7 = 0xffb7, - KP_8 = 0xffb8, - KP_9 = 0xffb9, - - /* - * Auxiliary functions; note the duplicate definitions for left and right - * function keys; Sun keyboards and a few other manufacturers have such - * function key groups on the left and/or right sides of the keyboard. - * We've not found a keyboard with more than 35 function keys total. - */ - - F1 = 0xffbe, - F2 = 0xffbf, - F3 = 0xffc0, - F4 = 0xffc1, - F5 = 0xffc2, - F6 = 0xffc3, - F7 = 0xffc4, - F8 = 0xffc5, - F9 = 0xffc6, - F10 = 0xffc7, - F11 = 0xffc8, - L1 = 0xffc8, - F12 = 0xffc9, - L2 = 0xffc9, - F13 = 0xffca, - L3 = 0xffca, - F14 = 0xffcb, - L4 = 0xffcb, - F15 = 0xffcc, - L5 = 0xffcc, - F16 = 0xffcd, - L6 = 0xffcd, - F17 = 0xffce, - L7 = 0xffce, - F18 = 0xffcf, - L8 = 0xffcf, - F19 = 0xffd0, - L9 = 0xffd0, - F20 = 0xffd1, - L10 = 0xffd1, - F21 = 0xffd2, - R1 = 0xffd2, - F22 = 0xffd3, - R2 = 0xffd3, - F23 = 0xffd4, - R3 = 0xffd4, - F24 = 0xffd5, - R4 = 0xffd5, - F25 = 0xffd6, - R5 = 0xffd6, - F26 = 0xffd7, - R6 = 0xffd7, - F27 = 0xffd8, - R7 = 0xffd8, - F28 = 0xffd9, - R8 = 0xffd9, - F29 = 0xffda, - R9 = 0xffda, - F30 = 0xffdb, - R10 = 0xffdb, - F31 = 0xffdc, - R11 = 0xffdc, - F32 = 0xffdd, - R12 = 0xffdd, - F33 = 0xffde, - R13 = 0xffde, - F34 = 0xffdf, - R14 = 0xffdf, - F35 = 0xffe0, - R15 = 0xffe0, - - /* Modifiers */ - - Shift_L = 0xffe1, /* Left shift */ - Shift_R = 0xffe2, /* Right shift */ - Control_L = 0xffe3, /* Left control */ - Control_R = 0xffe4, /* Right control */ - Caps_Lock = 0xffe5, /* Caps lock */ - Shift_Lock = 0xffe6, /* Shift lock */ - - Meta_L = 0xffe7, /* Left meta */ - Meta_R = 0xffe8, /* Right meta */ - Alt_L = 0xffe9, /* Left alt */ - Alt_R = 0xffea, /* Right alt */ - Super_L = 0xffeb, /* Left super */ - Super_R = 0xffec, /* Right super */ - Hyper_L = 0xffed, /* Left hyper */ - Hyper_R = 0xffee, /* Right hyper */ - - ISO_Level3_Shift = 0xfe03, - - /* - * Latin 1 - * (ISO/IEC 8859-1 = Unicode U+0020..U+00FF) - * Byte 3 = 0 - */ - - space = 0x0020, /* U+0020 SPACE */ - exclam = 0x0021, /* U+0021 EXCLAMATION MARK */ - quotedbl = 0x0022, /* U+0022 QUOTATION MARK */ - numbersign = 0x0023, /* U+0023 NUMBER SIGN */ - dollar = 0x0024, /* U+0024 DOLLAR SIGN */ - percent = 0x0025, /* U+0025 PERCENT SIGN */ - ampersand = 0x0026, /* U+0026 AMPERSAND */ - apostrophe = 0x0027, /* U+0027 APOSTROPHE */ - quoteright = 0x0027, /* deprecated */ - parenleft = 0x0028, /* U+0028 LEFT PARENTHESIS */ - parenright = 0x0029, /* U+0029 RIGHT PARENTHESIS */ - asterisk = 0x002a, /* U+002A ASTERISK */ - plus = 0x002b, /* U+002B PLUS SIGN */ - comma = 0x002c, /* U+002C COMMA */ - minus = 0x002d, /* U+002D HYPHEN-MINUS */ - period = 0x002e, /* U+002E FULL STOP */ - slash = 0x002f, /* U+002F SOLIDUS */ - Number0 = 0x0030, /* U+0030 DIGIT ZERO */ - Number1 = 0x0031, /* U+0031 DIGIT ONE */ - Number2 = 0x0032, /* U+0032 DIGIT TWO */ - Number3 = 0x0033, /* U+0033 DIGIT THREE */ - Number4 = 0x0034, /* U+0034 DIGIT FOUR */ - Number5 = 0x0035, /* U+0035 DIGIT FIVE */ - Number6 = 0x0036, /* U+0036 DIGIT SIX */ - Number7 = 0x0037, /* U+0037 DIGIT SEVEN */ - Number8 = 0x0038, /* U+0038 DIGIT EIGHT */ - Number9 = 0x0039, /* U+0039 DIGIT NINE */ - colon = 0x003a, /* U+003A COLON */ - semicolon = 0x003b, /* U+003B SEMICOLON */ - less = 0x003c, /* U+003C LESS-THAN SIGN */ - equal = 0x003d, /* U+003D EQUALS SIGN */ - greater = 0x003e, /* U+003E GREATER-THAN SIGN */ - question = 0x003f, /* U+003F QUESTION MARK */ - at = 0x0040, /* U+0040 COMMERCIAL AT */ - A = 0x0041, /* U+0041 LATIN CAPITAL LETTER A */ - B = 0x0042, /* U+0042 LATIN CAPITAL LETTER B */ - C = 0x0043, /* U+0043 LATIN CAPITAL LETTER C */ - D = 0x0044, /* U+0044 LATIN CAPITAL LETTER D */ - E = 0x0045, /* U+0045 LATIN CAPITAL LETTER E */ - F = 0x0046, /* U+0046 LATIN CAPITAL LETTER F */ - G = 0x0047, /* U+0047 LATIN CAPITAL LETTER G */ - H = 0x0048, /* U+0048 LATIN CAPITAL LETTER H */ - I = 0x0049, /* U+0049 LATIN CAPITAL LETTER I */ - J = 0x004a, /* U+004A LATIN CAPITAL LETTER J */ - K = 0x004b, /* U+004B LATIN CAPITAL LETTER K */ - L = 0x004c, /* U+004C LATIN CAPITAL LETTER L */ - M = 0x004d, /* U+004D LATIN CAPITAL LETTER M */ - N = 0x004e, /* U+004E LATIN CAPITAL LETTER N */ - O = 0x004f, /* U+004F LATIN CAPITAL LETTER O */ - P = 0x0050, /* U+0050 LATIN CAPITAL LETTER P */ - Q = 0x0051, /* U+0051 LATIN CAPITAL LETTER Q */ - R = 0x0052, /* U+0052 LATIN CAPITAL LETTER R */ - S = 0x0053, /* U+0053 LATIN CAPITAL LETTER S */ - T = 0x0054, /* U+0054 LATIN CAPITAL LETTER T */ - U = 0x0055, /* U+0055 LATIN CAPITAL LETTER U */ - V = 0x0056, /* U+0056 LATIN CAPITAL LETTER V */ - W = 0x0057, /* U+0057 LATIN CAPITAL LETTER W */ - X = 0x0058, /* U+0058 LATIN CAPITAL LETTER X */ - Y = 0x0059, /* U+0059 LATIN CAPITAL LETTER Y */ - Z = 0x005a, /* U+005A LATIN CAPITAL LETTER Z */ - bracketleft = 0x005b, /* U+005B LEFT SQUARE BRACKET */ - backslash = 0x005c, /* U+005C REVERSE SOLIDUS */ - bracketright = 0x005d, /* U+005D RIGHT SQUARE BRACKET */ - asciicircum = 0x005e, /* U+005E CIRCUMFLEX ACCENT */ - underscore = 0x005f, /* U+005F LOW LINE */ - grave = 0x0060, /* U+0060 GRAVE ACCENT */ - quoteleft = 0x0060, /* deprecated */ - a = 0x0061, /* U+0061 LATIN SMALL LETTER A */ - b = 0x0062, /* U+0062 LATIN SMALL LETTER B */ - c = 0x0063, /* U+0063 LATIN SMALL LETTER C */ - d = 0x0064, /* U+0064 LATIN SMALL LETTER D */ - e = 0x0065, /* U+0065 LATIN SMALL LETTER E */ - f = 0x0066, /* U+0066 LATIN SMALL LETTER F */ - g = 0x0067, /* U+0067 LATIN SMALL LETTER G */ - h = 0x0068, /* U+0068 LATIN SMALL LETTER H */ - i = 0x0069, /* U+0069 LATIN SMALL LETTER I */ - j = 0x006a, /* U+006A LATIN SMALL LETTER J */ - k = 0x006b, /* U+006B LATIN SMALL LETTER K */ - l = 0x006c, /* U+006C LATIN SMALL LETTER L */ - m = 0x006d, /* U+006D LATIN SMALL LETTER M */ - n = 0x006e, /* U+006E LATIN SMALL LETTER N */ - o = 0x006f, /* U+006F LATIN SMALL LETTER O */ - p = 0x0070, /* U+0070 LATIN SMALL LETTER P */ - q = 0x0071, /* U+0071 LATIN SMALL LETTER Q */ - r = 0x0072, /* U+0072 LATIN SMALL LETTER R */ - s = 0x0073, /* U+0073 LATIN SMALL LETTER S */ - t = 0x0074, /* U+0074 LATIN SMALL LETTER T */ - u = 0x0075, /* U+0075 LATIN SMALL LETTER U */ - v = 0x0076, /* U+0076 LATIN SMALL LETTER V */ - w = 0x0077, /* U+0077 LATIN SMALL LETTER W */ - x = 0x0078, /* U+0078 LATIN SMALL LETTER X */ - y = 0x0079, /* U+0079 LATIN SMALL LETTER Y */ - z = 0x007a, /* U+007A LATIN SMALL LETTER Z */ - braceleft = 0x007b, /* U+007B LEFT CURLY BRACKET */ - bar = 0x007c, /* U+007C VERTICAL LINE */ - braceright = 0x007d, /* U+007D RIGHT CURLY BRACKET */ - asciitilde = 0x007e, /* U+007E TILDE */ - - // Extra keys - - XF86AudioMute = 0x1008ff12, - XF86AudioLowerVolume = 0x1008ff11, - XF86AudioRaiseVolume = 0x1008ff13, - XF86PowerOff = 0x1008ff2a, - XF86Suspend = 0x1008ffa7, - XF86Copy = 0x1008ff57, - XF86Paste = 0x1008ff6d, - XF86Cut = 0x1008ff58, - XF86MenuKB = 0x1008ff65, - XF86Calculator = 0x1008ff1d, - XF86Sleep = 0x1008ff2f, - XF86WakeUp = 0x1008ff2b, - XF86Explorer = 0x1008ff5d, - XF86Send = 0x1008ff7b, - XF86Xfer = 0x1008ff8a, - XF86Launch1 = 0x1008ff41, - XF86Launch2 = 0x1008ff42, - XF86Launch3 = 0x1008ff43, - XF86Launch4 = 0x1008ff44, - XF86Launch5 = 0x1008ff45, - XF86LaunchA = 0x1008ff4a, - XF86LaunchB = 0x1008ff4b, - XF86WWW = 0x1008ff2e, - XF86DOS = 0x1008ff5a, - XF86ScreenSaver = 0x1008ff2d, - XF86RotateWindows = 0x1008ff74, - XF86Mail = 0x1008ff19, - XF86Favorites = 0x1008ff30, - XF86MyComputer = 0x1008ff33, - XF86Back = 0x1008ff26, - XF86Forward = 0x1008ff27, - XF86Eject = 0x1008ff2c, - XF86AudioPlay = 0x1008ff14, - XF86AudioStop = 0x1008ff15, - XF86AudioPrev = 0x1008ff16, - XF86AudioNext = 0x1008ff17, - XF86AudioRecord = 0x1008ff1c, - XF86AudioPause = 0x1008ff31, - XF86AudioRewind = 0x1008ff3e, - XF86AudioForward = 0x1008ff97, - XF86Phone = 0x1008ff6e, - XF86Tools = 0x1008ff81, - XF86HomePage = 0x1008ff18, - XF86Close = 0x1008ff56, - XF86Reload = 0x1008ff73, - XF86ScrollUp = 0x1008ff78, - XF86ScrollDown = 0x1008ff79, - XF86New = 0x1008ff68, - XF86TouchpadToggle = 0x1008ffa9, - XF86WebCam = 0x1008ff8f, - XF86Search = 0x1008ff1b, - XF86Finance = 0x1008ff3c, - XF86Shop = 0x1008ff36, - XF86MonBrightnessDown = 0x1008ff03, - XF86MonBrightnessUp = 0x1008ff02, - XF86AudioMedia = 0x1008ff32, - XF86Display = 0x1008ff59, - XF86KbdLightOnOff = 0x1008ff04, - XF86KbdBrightnessDown = 0x1008ff06, - XF86KbdBrightnessUp = 0x1008ff05, - XF86Reply = 0x1008ff72, - XF86MailForward = 0x1008ff90, - XF86Save = 0x1008ff77, - XF86Documents = 0x1008ff5b, - XF86Battery = 0x1008ff93, - XF86Bluetooth = 0x1008ff94, - XF86WLAN = 0x1008ff95, - - SunProps = 0x1005ff70, - SunOpen = 0x1005ff73, - } - public enum XVisualClass : int { StaticGray = 0, @@ -1257,144 +328,13 @@ XF86VidModeGetGammaRampSize( BitsPerRGB = 0x100, All = 0x1FF, } - - internal enum MouseMask - { - Button1MotionMask = (1 << 8), - Button2MotionMask = (1 << 9), - Button3MotionMask = (1 << 10), - Button4MotionMask = (1 << 11), - Button5MotionMask = (1 << 12), - Button1Mask = (1 << 8), - Button2Mask = (1 << 9), - Button3Mask = (1 << 10), - Button4Mask = (1 << 11), - Button5Mask = (1 << 12), - Button6Mask = (1 << 13), - Button7Mask = (1 << 14), - Button8Mask = (1 << 15), - ShiftMask = (1 << 0), - LockMask = (1 << 1), - ControlMask = (1 << 2), - Mod1Mask = (1 << 3), - Mod2Mask = (1 << 4), - Mod3Mask = (1 << 5), - Mod4Mask = (1 << 6), - Mod5Mask = (1 << 7), - } - + internal static partial class Functions { internal const string X11Library = "libX11"; - internal const string XcursorLibrary = "libXcursor.so.1"; - - /// - /// The XCreateWindow function creates an unmapped subwindow for a specified parent window, returns the window ID of the created window, and causes the X server to generate a CreateNotify event. The created window is placed on top in the stacking order with respect to siblings. - /// - /// Specifies the connection to the X server. - /// Specifies the parent window. - /// Specify the x coordinates, which are the top-left outside corner of the window's borders and are relative to the inside of the parent window's borders. - /// Specify the y coordinates, which are the top-left outside corner of the window's borders and are relative to the inside of the parent window's borders. - /// Specify the width, which is the created window's inside dimensions and do not include the created window's borders. - /// Specify the height, which is the created window's inside dimensions and do not include the created window's borders. - /// Specifies the width of the created window's border in pixels. - /// Specifies the window's depth. A depth of CopyFromParent means the depth is taken from the parent. - /// Specifies the created window's class. You can pass InputOutput, InputOnly, or CopyFromParent. A class of CopyFromParent means the class is taken from the parent. - /// Specifies the visual type. A visual of CopyFromParent means the visual type is taken from the parent. - /// Specifies which window attributes are defined in the attributes argument. This mask is the bitwise inclusive OR of the valid attribute mask bits. If valuemask is zero, the attributes are ignored and are not referenced. - /// Specifies the structure from which the values (as specified by the value mask) are to be taken. The value mask should have the appropriate bits set to indicate which attributes have been set in the structure. - /// The window ID of the created window. - /// - /// The coordinate system has the X axis horizontal and the Y axis vertical with the origin [0, 0] at the upper-left corner. Coordinates are integral, in terms of pixels, and coincide with pixel centers. Each window and pixmap has its own coordinate system. For a window, the origin is inside the border at the inside, upper-left corner. - /// The border_width for an InputOnly window must be zero, or a BadMatch error results. For class InputOutput, the visual type and depth must be a combination supported for the screen, or a BadMatch error results. The depth need not be the same as the parent, but the parent must not be a window of class InputOnly, or a BadMatch error results. For an InputOnly window, the depth must be zero, and the visual must be one supported by the screen. If either condition is not met, a BadMatch error results. The parent window, however, may have any depth and class. If you specify any invalid window attribute for a window, a BadMatch error results. - /// The created window is not yet displayed (mapped) on the user's display. To display the window, call XMapWindow(). The new window initially uses the same cursor as its parent. A new cursor can be defined for the new window by calling XDefineCursor(). The window will not be visible on the screen unless it and all of its ancestors are mapped and it is not obscured by any of its ancestors. - /// XCreateWindow can generate BadAlloc BadColor, BadCursor, BadMatch, BadPixmap, BadValue, and BadWindow errors. - /// The XCreateSimpleWindow function creates an unmapped InputOutput subwindow for a specified parent window, returns the window ID of the created window, and causes the X server to generate a CreateNotify event. The created window is placed on top in the stacking order with respect to siblings. Any part of the window that extends outside its parent window is clipped. The border_width for an InputOnly window must be zero, or a BadMatch error results. XCreateSimpleWindow inherits its depth, class, and visual from its parent. All other window attributes, except background and border, have their default values. - /// XCreateSimpleWindow can generate BadAlloc, BadMatch, BadValue, and BadWindow errors. - /// - public static Window XCreateWindow(Display display, Window parent, - int x, int y, int width, int height, int border_width, int depth, - CreateWindowArgs @class, IntPtr visual, SetWindowValuemask valuemask, - XSetWindowAttributes? attributes) - { - unsafe - { - if (attributes.HasValue) - { - XSetWindowAttributes attr = attributes.Value; - return XCreateWindow(display, parent, x, y, width, height, border_width, depth, - (int)@class, visual, (IntPtr)valuemask, &attr); - } - else - { - return XCreateWindow(display, parent, x, y, width, height, border_width, depth, - (int)@class, visual, (IntPtr)valuemask, null); - } - } - } - - [DllImport(X11Library)] - internal static extern void XChangeWindowAttributes(Display display, Window w, UIntPtr valuemask, ref XSetWindowAttributes attributes); - - internal static void XChangeWindowAttributes(Display display, Window w, SetWindowValuemask valuemask, ref XSetWindowAttributes attributes) - { - XChangeWindowAttributes(display, w, (UIntPtr)valuemask, ref attributes); - } - - [DllImport(XcursorLibrary)] - internal static unsafe extern XcursorImage* XcursorImageCreate(int width, int height); - - [DllImport(XcursorLibrary)] - internal static unsafe extern void XcursorImageDestroy(XcursorImage* image); - - [DllImport(XcursorLibrary)] - internal static unsafe extern Cursor XcursorImageLoadCursor(Display dpy, XcursorImage* image); - - /* - /// - /// The XQueryKeymap() function returns a bit vector for the logical state of the keyboard, where each bit set to 1 indicates that the corresponding key is currently pressed down. The vector is represented as 32 bytes. Byte N (from 0) contains the bits for keys 8N to 8N + 7 with the least-significant bit in the byte representing key 8N. - /// - /// Specifies the connection to the X server. - /// Returns an array of bytes that identifies which keys are pressed down. Each bit represents one key of the keyboard. - /// Note that the logical state of a device (as seen by client applications) may lag the physical state if device event processing is frozen. - [DllImport(_dll_name, EntryPoint = "XQueryKeymap")] - extern public static void XQueryKeymap(IntPtr display, [MarshalAs(UnmanagedType.LPArray, SizeConst = 32), In, Out] Keymap keys); - */ - - /// - /// The XQueryKeymap() function returns a bit vector for the logical state of the keyboard, where each bit set to 1 indicates that the corresponding key is currently pressed down. The vector is represented as 32 bytes. Byte N (from 0) contains the bits for keys 8N to 8N + 7 with the least-significant bit in the byte representing key 8N. - /// - /// Specifies the connection to the X server. - /// Returns an array of bytes that identifies which keys are pressed down. Each bit represents one key of the keyboard. - /// Note that the logical state of a device (as seen by client applications) may lag the physical state if device event processing is frozen. - [DllImport(X11Library, EntryPoint = "XQueryKeymap")] - extern public static void XQueryKeymap(IntPtr display, byte[] keys); - - /// - /// The XMaskEvent() function searches the event queue for the events associated with the specified mask. When it finds a match, XMaskEvent() removes that event and copies it into the specified XEvent structure. The other events stored in the queue are not discarded. If the event you requested is not in the queue, XMaskEvent() flushes the output buffer and blocks until one is received. - /// - /// Specifies the connection to the X server. - /// Specifies the event mask. - /// Returns the matched event's associated structure. - [DllImport(X11Library, EntryPoint = "XMaskEvent")] - extern public static void XMaskEvent(IntPtr display, EventMask event_mask, ref XEvent e); - - /// - /// The XPutBackEvent() function pushes an event back onto the head of the display's event queue by copying the event into the queue. This can be useful if you read an event and then decide that you would rather deal with it later. There is no limit to the number of times in succession that you can call XPutBackEvent(). - /// - /// Specifies the connection to the X server. - /// Specifies the event. - [DllImport(X11Library, EntryPoint = "XPutBackEvent")] - public static extern void XPutBackEvent(IntPtr display, ref XEvent @event); private const string XrandrLibrary = "libXrandr.so.2"; - [DllImport(XrandrLibrary)] - public static extern Bool XRRQueryExtension(Display dpy, ref int event_basep, ref int error_basep); - - [DllImport(XrandrLibrary)] - public static extern Status XRRQueryVersion(Display dpy, ref int major_versionp, ref int minor_versionp); - [DllImport(XrandrLibrary)] public static extern XRRScreenConfiguration XRRGetScreenInfo(Display dpy, Drawable draw); @@ -1405,56 +345,12 @@ XF86VidModeGetGammaRampSize( public static extern Status XRRSetScreenConfig(Display dpy, XRRScreenConfiguration config, Drawable draw, int size_index, Rotation rotation, Time timestamp); - [DllImport(XrandrLibrary)] - public static extern Status XRRSetScreenConfigAndRate(Display dpy, XRRScreenConfiguration config, - Drawable draw, int size_index, Rotation rotation, short rate, Time timestamp); - - [DllImport(XrandrLibrary)] - public static extern Rotation XRRConfigRotations(XRRScreenConfiguration config, ref Rotation current_rotation); - - [DllImport(XrandrLibrary)] - public static extern Time XRRConfigTimes(XRRScreenConfiguration config, ref Time config_timestamp); - - [DllImport(XrandrLibrary)] - [return: MarshalAs(UnmanagedType.LPStruct)] - public static extern XRRScreenSize XRRConfigSizes(XRRScreenConfiguration config, int[] nsizes); - - [DllImport(XrandrLibrary)] - unsafe public static extern short* XRRConfigRates(XRRScreenConfiguration config, int size_index, int[] nrates); - [DllImport(XrandrLibrary)] public static extern SizeID XRRConfigCurrentConfiguration(XRRScreenConfiguration config, out Rotation rotation); [DllImport(XrandrLibrary)] public static extern short XRRConfigCurrentRate(XRRScreenConfiguration config); - [DllImport(XrandrLibrary)] - public static extern int XRRRootToScreen(Display dpy, Window root); - - [DllImport(XrandrLibrary)] - public static extern XRRScreenConfiguration XRRScreenConfig(Display dpy, int screen); - - [DllImport(XrandrLibrary)] - public static extern XRRScreenConfiguration XRRConfig(ref Screen screen); - - [DllImport(XrandrLibrary)] - public static extern void XRRSelectInput(Display dpy, Window window, int mask); - - /* - * intended to take RRScreenChangeNotify, or - * ConfigureNotify (on the root window) - * returns 1 if it is an event type it understands, 0 if not - */ - [DllImport(XrandrLibrary)] - public static extern int XRRUpdateConfiguration(ref XEvent @event); - - /* - * the following are always safe to call, even if RandR is - * not implemented on a screen - */ - [DllImport(XrandrLibrary)] - public static extern Rotation XRRRotations(Display dpy, int screen, ref Rotation current_rotation); - [DllImport(XrandrLibrary)] private unsafe static extern IntPtr XRRSizes(Display dpy, int screen, int* nsizes); @@ -1535,50 +431,7 @@ XF86VidModeGetGammaRampSize( return depths; } } - - public static Pixmap XCreateBitmapFromData(Display display, Window d, byte[,] data) - { - if (data == null) - { - throw new ArgumentNullException("data"); - } - - unsafe - { - fixed (byte* pdata = data) - { - return XCreateBitmapFromData(display, d, pdata, data.GetLength(0), data.GetLength(1)); - } - } - } - - [DllImport(X11Library)] - unsafe public static extern Pixmap XCreateBitmapFromData(Display display, Window d, byte* data, int width, int height); - - [DllImport("libX11", EntryPoint = "XAllocColor")] - public static extern Status XAllocNamedColor(Display display, Colormap colormap, string color_name, out XColor screen_def_return, out XColor exact_def_return); } - /* - [StructLayout(LayoutKind.Sequential)] - internal struct Keymap - { - unsafe fixed byte bits[32]; - - public bool this[KeyCode key] - { - get - { - unsafe - { - fixed (Keymap* ptr = &this) - { - return ((ptr->bits[key / 8] >> (key % 8)) & 0x01) != 0; - } - } - } - } - } - */ // Helper structure for calling XLock/UnlockDisplay internal struct XLock : IDisposable diff --git a/GLWidget/OpenTK/Platform/X11/Bindings/Glx.cs b/GLWidget/OpenTK/Platform/X11/Bindings/Glx.cs index d1e0a3e..4d38307 100644 --- a/GLWidget/OpenTK/Platform/X11/Bindings/Glx.cs +++ b/GLWidget/OpenTK/Platform/X11/Bindings/Glx.cs @@ -5,7 +5,6 @@ using System; using System.Runtime.InteropServices; -using OpenTK.Core.Native; #pragma warning disable 1591 @@ -140,19 +139,6 @@ namespace OpenTK.Platform.X11 HYPERPIPE_PIXEL_AVERAGE_SGIX = 0x00000004, } - internal enum GLXStringName : int - { - EXTENSIONS = 0x3, - VERSION = 0x2, - VENDOR = 0x1, - } - - internal enum GLXEventMask : int - { - PBUFFER_CLOBBER_MASK = 0x08000000, - BUFFER_CLOBBER_MASK_SGIX = 0x08000000, - } - internal enum GLXRenderTypeMask : int { COLOR_INDEX_BIT_SGIX = 0x00000002, @@ -162,67 +148,6 @@ namespace OpenTK.Platform.X11 COLOR_INDEX_BIT = 0x00000002, } - internal enum GLXHyperpipeTypeMask : int - { - HYPERPIPE_RENDER_PIPE_SGIX = 0x00000002, - HYPERPIPE_DISPLAY_PIPE_SGIX = 0x00000001, - } - - internal enum GLXPbufferClobberMask : int - { - ACCUM_BUFFER_BIT_SGIX = 0x00000080, - FRONT_LEFT_BUFFER_BIT = 0x00000001, - BACK_RIGHT_BUFFER_BIT = 0x00000008, - FRONT_RIGHT_BUFFER_BIT_SGIX = 0x00000002, - STENCIL_BUFFER_BIT_SGIX = 0x00000040, - SAMPLE_BUFFERS_BIT_SGIX = 0x00000100, - STENCIL_BUFFER_BIT = 0x00000040, - BACK_RIGHT_BUFFER_BIT_SGIX = 0x00000008, - BACK_LEFT_BUFFER_BIT_SGIX = 0x00000004, - AUX_BUFFERS_BIT = 0x00000010, - DEPTH_BUFFER_BIT_SGIX = 0x00000020, - ACCUM_BUFFER_BIT = 0x00000080, - AUX_BUFFERS_BIT_SGIX = 0x00000010, - DEPTH_BUFFER_BIT = 0x00000020, - FRONT_LEFT_BUFFER_BIT_SGIX = 0x00000001, - BACK_LEFT_BUFFER_BIT = 0x00000004, - FRONT_RIGHT_BUFFER_BIT = 0x00000002, - } - - internal enum GLXHyperpipeMisc : int - { - HYPERPIPE_PIPE_NAME_LENGTH_SGIX = 80, - } - - internal enum GLXErrorCode : int - { - BAD_CONTEXT = 5, - NO_EXTENSION = 3, - BAD_HYPERPIPE_SGIX = 92, - BAD_ENUM = 7, - BAD_SCREEN = 1, - BAD_VALUE = 6, - BAD_ATTRIBUTE = 2, - BAD_VISUAL = 4, - BAD_HYPERPIPE_CONFIG_SGIX = 91, - } - - internal enum GLXSyncType : int - { - SYNC_SWAP_SGIX = 0x00000001, - SYNC_FRAME_SGIX = 0x00000000, - } - - internal enum GLXDrawableTypeMask : int - { - WINDOW_BIT = 0x00000001, - PIXMAP_BIT = 0x00000002, - PBUFFER_BIT_SGIX = 0x00000004, - PBUFFER_BIT = 0x00000004, - WINDOW_BIT_SGIX = 0x00000001, - PIXMAP_BIT_SGIX = 0x00000002, - } - internal enum ArbCreateContext : int { DebugBit = 0x0001, @@ -300,12 +225,6 @@ namespace OpenTK.Platform.X11 protected override object SyncRoot { get { return sync_root; } } - public override IntPtr GetAddress(string funcname) - { - byte[] procName = System.Text.Encoding.ASCII.GetBytes(funcname); - return OpenGL.Glx.GetProcAddressARB(procName); - } - internal override void LoadEntryPoints() { unsafe @@ -354,16 +273,6 @@ namespace OpenTK.Platform.X11 public delegate int SwapIntervalSGI(int interval); public static SwapIntervalSGI glXSwapIntervalSGI; - internal static bool SupportsFunction(string name) - { - int index = Array.IndexOf(EntryPointNames, name); - if (index >= 0) - { - return EntryPoints[index] != IntPtr.Zero; - } - return false; - } - [DllImport(Library, EntryPoint = "glXIsDirect")] public static extern bool IsDirect(IntPtr dpy, IntPtr context); @@ -424,9 +333,6 @@ namespace OpenTK.Platform.X11 [DllImport(Library, EntryPoint = "glXChooseVisual")] public extern static IntPtr ChooseVisual(IntPtr dpy, int screen, IntPtr attriblist); - [DllImport(Library, EntryPoint = "glXChooseVisual")] - public extern static IntPtr ChooseVisual(IntPtr dpy, int screen, ref int attriblist); - public static IntPtr ChooseVisual(IntPtr dpy, int screen, int[] attriblist) { unsafe diff --git a/GLWidget/OpenTK/Platform/X11/Bindings/Xkb.cs b/GLWidget/OpenTK/Platform/X11/Bindings/Xkb.cs deleted file mode 100644 index 9270e08..0000000 --- a/GLWidget/OpenTK/Platform/X11/Bindings/Xkb.cs +++ /dev/null @@ -1,304 +0,0 @@ -// -// Xkb.cs -// -// Author: -// Stefanos Apostolopoulos -// -// Copyright (c) 2006-2014 -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; - -#pragma warning disable 0169 - -namespace OpenTK.Platform.X11 -{ - using Atom = IntPtr; - using KeyCode = Byte; - using XkbControlsPtr = IntPtr; - using XkbServerMapPtr = IntPtr; - using XkbClientMapPtr = IntPtr; - using XkbIndicatorPtr = IntPtr; - using XkbCompatMapPtr = IntPtr; - using XkbGeometryPtr = IntPtr; - - internal class Xkb - { - private const string lib = "libX11"; - - internal const int KeyNameLength = 4; - internal const int NumModifiers = 8; - internal const int NumVirtualMods = 16; - internal const int NumIndicators = 32; - internal const int NumKbdGroups = 4; - internal const int UseCoreKeyboard = 0x0100; - - [DllImport(lib, EntryPoint = "XkbFreeKeyboard")] - unsafe internal extern static void FreeKeyboard(XkbDesc* descr, int which, bool free); - - [DllImport(lib, EntryPoint = "XkbAllocKeyboard")] - unsafe internal extern static XkbDesc* AllocKeyboard(IntPtr display); - - [DllImport(lib, EntryPoint = "XkbGetKeyboard")] - internal extern static IntPtr GetKeyboard(IntPtr display, XkbKeyboardMask which, int device_id); - - [DllImport(lib, EntryPoint = "XkbGetMap")] - internal extern static IntPtr GetMap(IntPtr display, XkbKeyboardMask which, int device_spec); - - [DllImport(lib, EntryPoint = "XkbGetNames")] - unsafe internal extern static IntPtr GetNames(IntPtr display, XkbNamesMask which, XkbDesc* xkb); - - [DllImport(lib, EntryPoint = "XkbKeycodeToKeysym")] - internal extern static XKey KeycodeToKeysym(IntPtr display, int keycode, int group, int level); - - [DllImport(lib, EntryPoint = "XkbQueryExtension")] - internal extern static bool QueryExtension(IntPtr display, out int opcode_rtrn, out int event_rtrn, - out int error_rtrn, ref int major_in_out, ref int minor_in_out); - - [DllImport(lib, EntryPoint = "XkbSetDetectableAutoRepeat")] - internal extern static bool SetDetectableAutoRepeat(IntPtr display, bool detectable, out bool supported); - - internal static bool IsSupported(IntPtr display) - { - // The XkbQueryExtension manpage says that we cannot - // use XQueryExtension with XKB. - int opcode, error, ev; - int major = 1; - int minor = 0; - bool supported = QueryExtension(display, out opcode, out ev, out error, ref major, ref minor); - Debug.Print("XKB extension is {0}.", supported ? "supported" : "not supported"); - if (supported) - { - Debug.Print("XKB version is {0}.{1}", major, minor); - } - return supported; - } - } - - [Flags] - internal enum XkbKeyboardMask - { - Controls = 1 << 0, - ServerMap = 1 << 1, - IClientMap = 1 << 2, - IndicatorMap = 1 << 3, - Names = 1 << 4, - CompatibilityMap = 1 << 5, - Geometry = 1 << 6, - AllComponents = 1 << 7, - } - - [Flags] - internal enum XkbNamesMask - { - Keycodes = 1 << 0, - Geometry = 1 << 1, - Symbols = 1 << 2, - PhysSymbols = 1 << 3, - Types = 1 << 4, - Compat = 1 << 5, - KeyType = 1 << 6, - KTLevel = 1 << 7, - Indicator = 1 << 8, - Key = 1 << 9, - KeyAliasesMask = 1 << 10, - VirtualMod = 1 << 11, - Group = 1 << 12, - RG = 1 << 13, - Component = 0x3f, - All = 0x3fff - } - - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct XkbDesc - { - internal IntPtr dpy; - internal ushort flags; - internal ushort device_spec; - internal KeyCode min_key_code; - internal KeyCode max_key_code; - - internal XkbControlsPtr ctrls; - internal XkbServerMapPtr server; - internal XkbClientMapPtr map; - internal XkbIndicatorPtr indicators; - internal XkbNames* names; - internal XkbCompatMapPtr compat; - internal XkbGeometryPtr geom; - } - - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct XkbKeyAlias - { - internal fixed byte real[Xkb.KeyNameLength]; - internal fixed byte alias[Xkb.KeyNameLength]; - } - - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct XkbKeyName - { - internal fixed byte name[Xkb.KeyNameLength]; - } - - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct XkbNames - { - [StructLayout(LayoutKind.Sequential)] - internal struct Groups - { - private Atom groups0; - private Atom groups1; - private Atom groups2; - private Atom groups3; - internal Atom this[int i] - { - get - { - if (i < 0 || i > 3) - { - throw new IndexOutOfRangeException(); - } - - unsafe - { - fixed (Atom* ptr = &groups0) - { - return *(ptr + i); - } - } - } - } - } - - [StructLayout(LayoutKind.Sequential)] - internal struct Indicators - { - private Atom indicators0; - private Atom indicators1; - private Atom indicators2; - private Atom indicators3; - private Atom indicators4; - private Atom indicators5; - private Atom indicators6; - private Atom indicators7; - private Atom indicators8; - private Atom indicators9; - private Atom indicators10; - private Atom indicators11; - private Atom indicators12; - private Atom indicators13; - private Atom indicators14; - private Atom indicators15; - private Atom indicators16; - private Atom indicators17; - private Atom indicators18; - private Atom indicators19; - private Atom indicators20; - private Atom indicators21; - private Atom indicators22; - private Atom indicators23; - private Atom indicators24; - private Atom indicators25; - private Atom indicators26; - private Atom indicators27; - private Atom indicators28; - private Atom indicators29; - private Atom indicators30; - private Atom indicators31; - internal Atom this[int i] - { - get - { - if (i < 0 || i > 31) - { - throw new IndexOutOfRangeException(); - } - - unsafe - { - fixed (Atom* ptr = &indicators0) - { - return *(ptr + i); - } } - } - } - } - - [StructLayout(LayoutKind.Sequential)] - internal struct VMods - { - private Atom vmods0; - private Atom vmods1; - private Atom vmods2; - private Atom vmods3; - private Atom vmods4; - private Atom vmods5; - private Atom vmods6; - private Atom vmods7; - private Atom vmods8; - private Atom vmods9; - private Atom vmods10; - private Atom vmods11; - private Atom vmods12; - private Atom vmods13; - private Atom vmods14; - private Atom vmods15; - internal Atom this[int i] - { - get - { - if (i < 0 || i > 15) - { - throw new IndexOutOfRangeException(); - } - - unsafe - { - fixed (Atom* ptr = &vmods0) - { - return *(ptr + i); - } - } - } - } - } - - internal Atom keycodes; - internal Atom geometry; - internal Atom symbols; - internal Atom types; - internal Atom compat; - internal VMods vmods; - internal Indicators indicators; - internal Groups groups; - internal XkbKeyName* keys; - internal XkbKeyAlias* key_aliases; - internal Atom *radio_groups; - internal Atom phys_symbols; - - internal byte num_keys; - internal byte num_key_aliases; - internal byte num_rg; - } -} - diff --git a/GLWidget/OpenTK/Platform/X11/Functions.cs b/GLWidget/OpenTK/Platform/X11/Functions.cs index 235d06d..e25603a 100644 --- a/GLWidget/OpenTK/Platform/X11/Functions.cs +++ b/GLWidget/OpenTK/Platform/X11/Functions.cs @@ -61,7 +61,7 @@ namespace OpenTK.Platform.X11 [DllImport("libX11", EntryPoint = "XCreateWindow")] public unsafe extern static IntPtr XCreateWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, int depth, int xclass, IntPtr visual, IntPtr valuemask, XSetWindowAttributes* attributes); - [DllImport("libX11", EntryPoint = "XCreateSimpleWindow")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XCreateSimpleWindow")]//] public extern static IntPtr XCreateSimpleWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, UIntPtr border, UIntPtr background); [DllImport("libX11", EntryPoint = "XCreateSimpleWindow")] public extern static IntPtr XCreateSimpleWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, IntPtr border, IntPtr background); @@ -151,10 +151,10 @@ namespace OpenTK.Platform.X11 [DllImport("libX11", EntryPoint = "XRaiseWindow")] public extern static int XRaiseWindow(IntPtr display, IntPtr window); - [DllImport("libX11", EntryPoint = "XLowerWindow")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XLowerWindow")]//] public extern static uint XLowerWindow(IntPtr display, IntPtr window); - [DllImport("libX11", EntryPoint = "XConfigureWindow")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XConfigureWindow")]//] public extern static uint XConfigureWindow(IntPtr display, IntPtr window, ChangeWindowAttributes value_mask, ref XWindowChanges values); [DllImport("libX11", EntryPoint = "XInternAtom")] @@ -222,7 +222,7 @@ namespace OpenTK.Platform.X11 [DllImport("libX11", EntryPoint = "XGetGeometry")] public extern static bool XGetGeometry(IntPtr display, IntPtr window, IntPtr root, IntPtr x, IntPtr y, out int width, out int height, IntPtr border_width, IntPtr depth); - [DllImport("libX11", EntryPoint = "XWarpPointer")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XWarpPointer")]//] public extern static uint XWarpPointer(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, uint src_width, uint src_height, int dest_x, int dest_y); [DllImport("libX11", EntryPoint = "XClearWindow")] @@ -241,7 +241,7 @@ namespace OpenTK.Platform.X11 [DllImport("libX11", EntryPoint = "XDefaultVisual")] public extern static IntPtr XDefaultVisual(IntPtr display, int screen_number); - [DllImport("libX11", EntryPoint = "XDefaultDepth")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XDefaultDepth")]//] public extern static uint XDefaultDepth(IntPtr display, int screen_number); [DllImport("libX11", EntryPoint = "XDefaultScreen")] @@ -250,10 +250,10 @@ namespace OpenTK.Platform.X11 [DllImport("libX11", EntryPoint = "XDefaultColormap")] public extern static IntPtr XDefaultColormap(IntPtr display, int screen_number); - [DllImport("libX11", EntryPoint = "XLookupColor")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XLookupColor")]//] public extern static int XLookupColor(IntPtr display, IntPtr Colormap, string Coloranem, ref XColor exact_def_color, ref XColor screen_def_color); - [DllImport("libX11", EntryPoint = "XAllocColor")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XAllocColor")]//] public extern static int XAllocColor(IntPtr display, IntPtr Colormap, ref XColor colorcell_def); [DllImport("libX11", EntryPoint = "XSetTransientForHint")] @@ -262,15 +262,15 @@ namespace OpenTK.Platform.X11 [DllImport("libX11", EntryPoint = "XChangeProperty")] public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref MotifWmHints data, int nelements); - [DllImport("libX11", EntryPoint = "XChangeProperty")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XChangeProperty")]//] public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref uint value, int nelements); [DllImport("libX11", EntryPoint = "XChangeProperty")] public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref int value, int nelements); - [DllImport("libX11", EntryPoint = "XChangeProperty")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XChangeProperty")]//] public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, ref IntPtr value, int nelements); - [DllImport("libX11", EntryPoint = "XChangeProperty")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XChangeProperty")]//] public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, uint[] data, int nelements); [DllImport("libX11", EntryPoint = "XChangeProperty")] @@ -337,7 +337,7 @@ namespace OpenTK.Platform.X11 [DllImport("libX11", EntryPoint = "XCreateFontCursor")] public extern static IntPtr XCreateFontCursor(IntPtr display, CursorFontShape shape); - [DllImport("libX11", EntryPoint = "XCreatePixmapCursor")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XCreatePixmapCursor")]//] public extern static IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask, ref XColor foreground_color, ref XColor background_color, int x_hot, int y_hot); [DllImport("libX11", EntryPoint = "XCreatePixmapFromBitmapData")] @@ -409,12 +409,12 @@ namespace OpenTK.Platform.X11 [DllImport("libX11", EntryPoint = "XSetPlaneMask")] public extern static int XSetPlaneMask(IntPtr display, IntPtr gc, IntPtr mask); - [DllImport("libX11", EntryPoint = "XSetForeground")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XSetForeground")]//] public extern static int XSetForeground(IntPtr display, IntPtr gc, UIntPtr foreground); [DllImport("libX11", EntryPoint = "XSetForeground")] public extern static int XSetForeground(IntPtr display, IntPtr gc, IntPtr foreground); - [DllImport("libX11", EntryPoint = "XSetBackground")]//, CLSCompliant(false)] + [DllImport("libX11", EntryPoint = "XSetBackground")]//] public extern static int XSetBackground(IntPtr display, IntPtr gc, UIntPtr background); [DllImport("libX11", EntryPoint = "XSetBackground")] public extern static int XSetBackground(IntPtr display, IntPtr gc, IntPtr background); diff --git a/GLWidget/OpenTK/Platform/X11/X11DisplayDevice.cs b/GLWidget/OpenTK/Platform/X11/X11DisplayDevice.cs index 0609e3e..7d1f095 100644 --- a/GLWidget/OpenTK/Platform/X11/X11DisplayDevice.cs +++ b/GLWidget/OpenTK/Platform/X11/X11DisplayDevice.cs @@ -318,84 +318,7 @@ namespace OpenTK.Platform.X11 { return (int)Functions.XDefaultDepth(API.DefaultDisplay, screen); } - - private bool ChangeResolutionXRandR(DisplayDevice device, DisplayResolution resolution) - { - using (new XLock(API.DefaultDisplay)) - { - int screen = deviceToScreen[device]; - IntPtr root = Functions.XRootWindow(API.DefaultDisplay, screen); - IntPtr screen_config = Functions.XRRGetScreenInfo(API.DefaultDisplay, root); - - ushort current_rotation; - int current_resolution_index = Functions.XRRConfigCurrentConfiguration(screen_config, out current_rotation); - int new_resolution_index; - if (resolution != null) - { - new_resolution_index = screenResolutionToIndex[screen] - [new DisplayResolution(0, 0, resolution.Width, resolution.Height, resolution.BitsPerPixel, 0)]; - } - else - { - new_resolution_index = deviceToDefaultResolution[device]; - } - - Debug.Print("Changing size of screen {0} from {1} to {2}", - screen, current_resolution_index, new_resolution_index); - - int ret = 0; - short refresh_rate = (short)(resolution != null ? resolution.RefreshRate : 0); - if (refresh_rate > 0) - { - ret = Functions.XRRSetScreenConfigAndRate(API.DefaultDisplay, - screen_config, root, new_resolution_index, current_rotation, - refresh_rate, IntPtr.Zero); - } - else - { - ret = Functions.XRRSetScreenConfig(API.DefaultDisplay, - screen_config, root, new_resolution_index, current_rotation, - IntPtr.Zero); - } - - if (ret != 0) - { - Debug.Print("[Error] Change to resolution {0} failed with error {1}.", - resolution, (ErrorCode)ret); - } - - return ret == 0; - } - } - - private static bool ChangeResolutionXF86(DisplayDevice device, DisplayResolution resolution) - { - return false; - } - - public sealed override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution) - { - // If resolution is null, restore the default resolution (new_resolution_index = 0). - - if (xrandr_supported) - { - return ChangeResolutionXRandR(device, resolution); - } - else if (xf86_supported) - { - return ChangeResolutionXF86(device, resolution); - } - else - { - return false; - } - } - - public sealed override bool TryRestoreResolution(DisplayDevice device) - { - return TryChangeResolution(device, null); - } - + private static class NativeMethods { private const string Xinerama = "libXinerama"; @@ -403,9 +326,6 @@ namespace OpenTK.Platform.X11 [DllImport(Xinerama)] public static extern bool XineramaQueryExtension(IntPtr dpy, out int event_basep, out int error_basep); - [DllImport(Xinerama)] - public static extern int XineramaQueryVersion (IntPtr dpy, out int major_versionp, out int minor_versionp); - [DllImport(Xinerama)] public static extern bool XineramaIsActive(IntPtr dpy); diff --git a/GLWidgetTestGTK3/GLWidgetTestGTK3.csproj b/GLWidgetTestGTK3/GLWidgetTestGTK3.csproj index 591a7a3..bdc0b9a 100644 --- a/GLWidgetTestGTK3/GLWidgetTestGTK3.csproj +++ b/GLWidgetTestGTK3/GLWidgetTestGTK3.csproj @@ -1,4 +1,4 @@ - + netcoreapp3.1 8.0 @@ -17,7 +17,6 @@ -