From 17e434afa3ade0cb9cec613ef99f2280c77e2cd9 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 12 Jul 2018 19:08:22 +1000 Subject: [PATCH] more tidy up --- Launcher2/Drawing/Platform/OSXDrawer.cs | 4 +- Launcher2/Drawing/Platform/PlatformDrawer.cs | 2 +- Launcher2/Drawing/Platform/WindowsDrawer.cs | 48 ++-- Launcher2/Drawing/Platform/X11Drawer.cs | 5 - OpenTK/Graphics/GraphicsMode.cs | 4 +- OpenTK/Graphics/IGraphicsContext.cs | 2 +- OpenTK/Math/Vector4.cs | 2 +- OpenTK/MemUtils.cs | 134 ++++----- OpenTK/Platform/Configuration.cs | 20 +- OpenTK/Platform/IPlatformFactory.cs | 2 +- OpenTK/Platform/MacOS/AglContext.cs | 22 +- OpenTK/Platform/MacOS/Application.cs | 2 +- OpenTK/Platform/MacOS/CarbonBindings/API.cs | 3 +- OpenTK/Platform/MacOS/CarbonBindings/Agl.cs | 204 ++++++------- .../MacOS/CarbonBindings/CarbonAPI.cs | 145 +++------- .../MacOS/CarbonBindings/MacOSKeys.cs | 244 ++++++++-------- OpenTK/Platform/MacOS/CarbonWindow.cs | 160 +++++------ OpenTK/Platform/Windows/API.cs | 214 ++++++-------- OpenTK/Platform/Windows/Wgl.cs | 21 +- OpenTK/Platform/Windows/WinGLContext.cs | 10 +- OpenTK/Platform/Windows/WinWindow.cs | 48 ++-- OpenTK/Platform/X11/API.cs | 268 ++++++------------ OpenTK/Platform/X11/Glx.cs | 27 +- OpenTK/Platform/X11/X11DisplayDevice.cs | 14 +- OpenTK/Platform/X11/X11GLContext.cs | 72 ++--- OpenTK/Platform/X11/X11Window.cs | 34 +-- 26 files changed, 747 insertions(+), 964 deletions(-) diff --git a/Launcher2/Drawing/Platform/OSXDrawer.cs b/Launcher2/Drawing/Platform/OSXDrawer.cs index 8e44fe46e..00829eb32 100644 --- a/Launcher2/Drawing/Platform/OSXDrawer.cs +++ b/Launcher2/Drawing/Platform/OSXDrawer.cs @@ -3,7 +3,7 @@ using System; using System.Drawing; using ClassicalSharp; using OSStatus = OpenTK.Platform.MacOS.OSStatus; -using OSX = OpenTK.Platform.MacOS.Carbon; +using OSX = OpenTK.Platform.MacOS; namespace Launcher.Drawing { public sealed class OSXPlatformDrawer : PlatformDrawer { @@ -25,7 +25,7 @@ namespace Launcher.Drawing { IntPtr colorSpace = OSX.API.CGColorSpaceCreateDeviceRGB(); IntPtr provider = OSX.API.CGDataProviderCreateWithData(IntPtr.Zero, scan0, size, IntPtr.Zero); const uint flags = 4 | (2 << 12); - IntPtr image = OSX.API.CGImageCreate(bmp.Width, bmp.Height, 8, 8 * 4, bmp.Stride, + IntPtr image = OSX.API.CGImageCreate(bmp.Width, bmp.Height, 8, 32, bmp.Stride, colorSpace, flags, provider, IntPtr.Zero, 0, 0); IntPtr context = IntPtr.Zero; OSStatus err = OSX.API.QDBeginCGContext(windowPort, ref context); diff --git a/Launcher2/Drawing/Platform/PlatformDrawer.cs b/Launcher2/Drawing/Platform/PlatformDrawer.cs index 32d816936..5a4d15522 100644 --- a/Launcher2/Drawing/Platform/PlatformDrawer.cs +++ b/Launcher2/Drawing/Platform/PlatformDrawer.cs @@ -17,7 +17,7 @@ namespace Launcher.Drawing { } /// Updates the variables when the native window changes dimensions. - public abstract void Resize(); + public virtual void Resize() { } /// Redraws a portion of the framebuffer to the window. /// r is only a hint, the entire framebuffer may still be diff --git a/Launcher2/Drawing/Platform/WindowsDrawer.cs b/Launcher2/Drawing/Platform/WindowsDrawer.cs index bbfbfbad3..3fefdbe52 100644 --- a/Launcher2/Drawing/Platform/WindowsDrawer.cs +++ b/Launcher2/Drawing/Platform/WindowsDrawer.cs @@ -3,34 +3,28 @@ using System; using System.Drawing; using System.Runtime.InteropServices; using System.Security; +using OpenTK.Platform.Windows; namespace Launcher.Drawing { + [SuppressUnmanagedCodeSecurity] public sealed class WinPlatformDrawer : PlatformDrawer { const uint SRCCOPY = 0xCC0020; - [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity] + [DllImport("gdi32.dll")] static extern int BitBlt(IntPtr dcDst, int dstX, int dstY, int width, int height, IntPtr dcSrc, int srcX, int srcY, uint drawOp); - [DllImport("user32.dll"), SuppressUnmanagedCodeSecurity] - static extern IntPtr GetDC(IntPtr hwnd); - - [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity] - static extern IntPtr CreateCompatibleDC(IntPtr dc); - - [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity] - static extern IntPtr SelectObject(IntPtr dc, IntPtr handle); - - [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity] - static extern int DeleteObject(IntPtr handle); - - [DllImport("user32.dll"), SuppressUnmanagedCodeSecurity] - static extern int ReleaseDC(IntPtr dc, IntPtr hwnd); - - [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity] + [DllImport("gdi32.dll")] + static extern IntPtr CreateCompatibleDC(IntPtr dc); + [DllImport("gdi32.dll")] static extern IntPtr CreateDIBSection(IntPtr hdc, [In] ref BITMAPINFO pbmi, uint pila, out IntPtr ppvBits, IntPtr hSection, uint dwOffset); + [DllImport("gdi32.dll")] + static extern IntPtr SelectObject(IntPtr dc, IntPtr handle); + [DllImport("gdi32.dll")] + static extern int DeleteObject(IntPtr handle); + [StructLayout(LayoutKind.Sequential)] public struct BITMAPINFO { public int biSize; @@ -47,10 +41,10 @@ namespace Launcher.Drawing { public uint bmiColors; } - IntPtr dc, srcDC, srcHB; + IntPtr winDc, srcDC, srcHB; public override void Init() { - dc = GetDC(window.WinHandle); - srcDC = CreateCompatibleDC(dc); + winDc = ((WinWindow)window).DeviceContext; + srcDC = CreateCompatibleDC(winDc); } public override Bitmap CreateFrameBuffer(int width, int height) { @@ -70,18 +64,9 @@ namespace Launcher.Drawing { System.Drawing.Imaging.PixelFormat.Format32bppArgb, pointer); } - public override void Resize() { - if (dc != IntPtr.Zero) { - ReleaseDC(window.WinHandle, dc); - DeleteObject(srcDC); - } - dc = GetDC(window.WinHandle); - srcDC = CreateCompatibleDC(dc); - } - public override void Redraw(Bitmap framebuffer, Rectangle r) { IntPtr oldSrc = SelectObject(srcDC, srcHB); - int success = BitBlt(dc, r.X, r.Y, r.Width, r.Height, srcDC, r.X, r.Y, SRCCOPY); + int success = BitBlt(winDc, r.X, r.Y, r.Width, r.Height, srcDC, r.X, r.Y, SRCCOPY); SelectObject(srcDC, oldSrc); } } @@ -94,8 +79,7 @@ namespace Launcher.Drawing { } public override void Resize() { - if (g != null) - g.Dispose(); + if (g != null) g.Dispose(); g = Graphics.FromHwnd(window.WinHandle); } diff --git a/Launcher2/Drawing/Platform/X11Drawer.cs b/Launcher2/Drawing/Platform/X11Drawer.cs index a104c2ff6..2ee2bcafa 100644 --- a/Launcher2/Drawing/Platform/X11Drawer.cs +++ b/Launcher2/Drawing/Platform/X11Drawer.cs @@ -12,11 +12,6 @@ namespace Launcher.Drawing { gc = API.XCreateGC(API.DefaultDisplay, window.WinHandle, IntPtr.Zero, IntPtr.Zero); } - public override void Resize() { - if (gc != IntPtr.Zero) API.XFreeGC(API.DefaultDisplay, gc); - gc = API.XCreateGC(API.DefaultDisplay, window.WinHandle, IntPtr.Zero, IntPtr.Zero); - } - public override void Redraw(Bitmap framebuffer, Rectangle r) { X11Window x11Win = (X11Window)window; using (FastBitmap bmp = new FastBitmap(framebuffer, true, true)) { diff --git a/OpenTK/Graphics/GraphicsMode.cs b/OpenTK/Graphics/GraphicsMode.cs index 83b7a7f92..7e1c767b9 100644 --- a/OpenTK/Graphics/GraphicsMode.cs +++ b/OpenTK/Graphics/GraphicsMode.cs @@ -48,8 +48,8 @@ namespace OpenTK.Graphics { public static GraphicsMode Default { get { if (defaultMode == null) { - Debug.Print( "Creating default GraphicsMode ({0}, {1}, {2}, {3}).", DisplayDevice.Primary.BitsPerPixel, 24, 0, 2 ); - defaultMode = new GraphicsMode( DisplayDevice.Primary.BitsPerPixel, 24, 0, 2 ); + Debug.Print("Creating default GraphicsMode ({0}, {1}, {2}, {3}).", DisplayDevice.Primary.BitsPerPixel, 24, 0, 2); + defaultMode = new GraphicsMode(DisplayDevice.Primary.BitsPerPixel, 24, 0, 2); } return defaultMode; } diff --git a/OpenTK/Graphics/IGraphicsContext.cs b/OpenTK/Graphics/IGraphicsContext.cs index ef998e7c6..affc18253 100644 --- a/OpenTK/Graphics/IGraphicsContext.cs +++ b/OpenTK/Graphics/IGraphicsContext.cs @@ -52,7 +52,7 @@ namespace OpenTK.Graphics { public void Dispose() { Dispose(true); - GC.SuppressFinalize( this ); + GC.SuppressFinalize(this); } protected abstract void Dispose(bool calledManually); diff --git a/OpenTK/Math/Vector4.cs b/OpenTK/Math/Vector4.cs index 0ce4b423a..6a4171ef3 100644 --- a/OpenTK/Math/Vector4.cs +++ b/OpenTK/Math/Vector4.cs @@ -50,7 +50,7 @@ namespace OpenTK { public static readonly Vector4 One = new Vector4(1, 1, 1, 1); - public static readonly int SizeInBytes = 4 * sizeof( float ); + public static readonly int SizeInBytes = 4 * sizeof(float); public Vector4(float x, float y, float z, float w) { diff --git a/OpenTK/MemUtils.cs b/OpenTK/MemUtils.cs index d54677180..2d24e28a7 100644 --- a/OpenTK/MemUtils.cs +++ b/OpenTK/MemUtils.cs @@ -1,67 +1,67 @@ -using System; - -namespace OpenTK { - - public static class MemUtils { - - static MemUtils() { - use64Bit = IntPtr.Size == 8; - } - static bool use64Bit; - - public static unsafe void memcpy( IntPtr srcPtr, IntPtr dstPtr, int bytes ) { - byte* srcByte, dstByte; - if( use64Bit ) { - ulong* srcLong = (ulong*)srcPtr, dstLong = (ulong*)dstPtr; - while( bytes >= 8 ) { - *dstLong++ = *srcLong++; - bytes -= 8; - } - srcByte = (byte*)srcLong; dstByte = (byte*)dstLong; - } else { - uint* srcInt = (uint*)srcPtr, dstInt = (uint*)dstPtr; - while( bytes >= 4 ) { - *dstInt++ = *srcInt++; - bytes -= 4; - } - srcByte = (byte*)srcInt; dstByte = (byte*)dstInt; - } - - for( int i = 0; i < bytes; i++ ) { - *dstByte++ = *srcByte++; - } - } - - public static unsafe void memset( IntPtr srcPtr, byte value, int startIndex, int bytes ) { - byte* srcByte = (byte*)srcPtr + startIndex; - // Make sure we do an aligned write/read for the bulk copy - while( bytes > 0 && ( startIndex & 0x7 ) != 0 ) { - *srcByte++ = value; - startIndex++; - bytes--; - } - uint valueInt = (uint)( ( value << 24 ) | ( value << 16 ) | ( value << 8 ) | value ); - - if( use64Bit ) { - ulong valueLong = ( (ulong)valueInt << 32 ) | valueInt; - ulong* srcLong = (ulong*)srcByte; - while( bytes >= 8 ) { - *srcLong++ = valueLong; - bytes -= 8; - } - srcByte = (byte*)srcLong; - } else { - uint* srcInt = (uint*)srcByte; - while( bytes >= 4 ) { - *srcInt++ = valueInt; - bytes -= 4; - } - srcByte = (byte*)srcInt; - } - - for( int i = 0; i < bytes; i++ ) { - *srcByte++ = value; - } - } - } -} +using System; + +namespace OpenTK { + + public static class MemUtils { + + static MemUtils() { + use64Bit = IntPtr.Size == 8; + } + static bool use64Bit; + + public static unsafe void memcpy(IntPtr srcPtr, IntPtr dstPtr, int bytes) { + byte* srcByte, dstByte; + if (use64Bit) { + ulong* srcLong = (ulong*)srcPtr, dstLong = (ulong*)dstPtr; + while (bytes >= 8) { + *dstLong++ = *srcLong++; + bytes -= 8; + } + srcByte = (byte*)srcLong; dstByte = (byte*)dstLong; + } else { + uint* srcInt = (uint*)srcPtr, dstInt = (uint*)dstPtr; + while (bytes >= 4) { + *dstInt++ = *srcInt++; + bytes -= 4; + } + srcByte = (byte*)srcInt; dstByte = (byte*)dstInt; + } + + for(int i = 0; i < bytes; i++) { + *dstByte++ = *srcByte++; + } + } + + public static unsafe void memset(IntPtr srcPtr, byte value, int startIndex, int bytes) { + byte* srcByte = (byte*)srcPtr + startIndex; + // Make sure we do an aligned write/read for the bulk copy + while (bytes > 0 && (startIndex & 0x7) != 0) { + *srcByte++ = value; + startIndex++; + bytes--; + } + uint valueInt = (uint)((value << 24) | (value << 16) | (value << 8) | value); + + if (use64Bit) { + ulong valueLong = ((ulong)valueInt << 32) | valueInt; + ulong* srcLong = (ulong*)srcByte; + while (bytes >= 8) { + *srcLong++ = valueLong; + bytes -= 8; + } + srcByte = (byte*)srcLong; + } else { + uint* srcInt = (uint*)srcByte; + while (bytes >= 4) { + *srcInt++ = valueInt; + bytes -= 4; + } + srcByte = (byte*)srcInt; + } + + for(int i = 0; i < bytes; i++) { + *srcByte++ = value; + } + } + } +} diff --git a/OpenTK/Platform/Configuration.cs b/OpenTK/Platform/Configuration.cs index 7bb2b71f9..22ccbd0b7 100644 --- a/OpenTK/Platform/Configuration.cs +++ b/OpenTK/Platform/Configuration.cs @@ -41,19 +41,19 @@ namespace OpenTK { // Detects the underlying OS and runtime. unsafe static Configuration() { PlatformID platform = Environment.OSVersion.Platform; - if( platform == PlatformID.Win32NT || platform == PlatformID.Win32S || - platform == PlatformID.Win32Windows || platform == PlatformID.WinCE ) + if (platform == PlatformID.Win32NT || platform == PlatformID.Win32S || + platform == PlatformID.Win32Windows || platform == PlatformID.WinCE) RunningOnWindows = true; - else if ( platform == PlatformID.Unix || platform == (PlatformID)4 ) { + else if (platform == PlatformID.Unix || platform == (PlatformID)4) { sbyte* ascii = stackalloc sbyte[8192]; - uname( ascii ); + uname(ascii); // Distinguish between Linux, Mac OS X and other Unix operating systems. - string kernel = new String( ascii ); - if( kernel == "Linux" ) { + string kernel = new String(ascii); + if (kernel == "Linux") { RunningOnLinux = RunningOnUnix = true; - } else if( kernel == "Darwin" ) { + } else if (kernel == "Darwin") { RunningOnMacOS = RunningOnUnix = true; - } else if( !String.IsNullOrEmpty( kernel ) ) { + } else if (!String.IsNullOrEmpty(kernel)) { RunningOnUnix = true; } else { throw new PlatformNotSupportedException("Unknown platform. Please file a bug report at http://www.opentk.com/"); @@ -65,13 +65,13 @@ namespace OpenTK { // Detect whether X is present. // Hack: it seems that this check will cause X to initialize itself on Mac OS X Leopard and newer. // We don't want that (we'll be using the native interfaces anyway), so we'll avoid this check when we detect Mac OS X. - if( !RunningOnMacOS && !RunningOnWindows ) { + if (!RunningOnMacOS && !RunningOnWindows) { try { RunningOnX11 = OpenTK.Platform.X11.API.DefaultDisplay != IntPtr.Zero; } catch { } } // Detect the Mono runtime (code taken from http://mono.wikia.com/wiki/Detecting_if_program_is_running_in_Mono). - if( Type.GetType("Mono.Runtime") != null ) + if (Type.GetType("Mono.Runtime") != null) RunningOnMono = true; Debug.Print("Detected configuration: {0} / {1}", diff --git a/OpenTK/Platform/IPlatformFactory.cs b/OpenTK/Platform/IPlatformFactory.cs index 2a54d5c01..e997c5db5 100644 --- a/OpenTK/Platform/IPlatformFactory.cs +++ b/OpenTK/Platform/IPlatformFactory.cs @@ -55,7 +55,7 @@ namespace OpenTK.Platform { if (Configuration.RunningOnWindows) Default = new Windows.WinFactory(); else if (Configuration.RunningOnMacOS) Default = new MacOS.MacOSFactory(); else if (Configuration.RunningOnX11) Default = new X11.X11Factory(); - else throw new NotSupportedException( "Running on an unsupported platform, please refer to http://www.opentk.com for more information." ); + else throw new NotSupportedException("Running on an unsupported platform, please refer to http://www.opentk.com for more information."); } } } diff --git a/OpenTK/Platform/MacOS/AglContext.cs b/OpenTK/Platform/MacOS/AglContext.cs index a603b812d..5f1ade0bb 100644 --- a/OpenTK/Platform/MacOS/AglContext.cs +++ b/OpenTK/Platform/MacOS/AglContext.cs @@ -80,18 +80,18 @@ namespace OpenTK.Platform.MacOS { } } else { aglPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attribs.ToArray()); - Agl.CheckReturnValue( 0, "aglChoosePixelFormat" ); + Agl.CheckReturnValue(0, "aglChoosePixelFormat"); } Debug.Print("Creating AGL context."); // create the context and share it with the share reference. ContextHandle = Agl.aglCreateContext(aglPixelFormat, IntPtr.Zero); - Agl.CheckReturnValue( 0, "aglCreateContext" ); + Agl.CheckReturnValue(0, "aglCreateContext"); // Free the pixel format from memory. Agl.aglDestroyPixelFormat(aglPixelFormat); - Agl.CheckReturnValue( 0, "aglDestroyPixelFormat" ); + Agl.CheckReturnValue(0, "aglDestroyPixelFormat"); SetDrawable(wind); Update(wind); @@ -110,7 +110,7 @@ namespace OpenTK.Platform.MacOS { //Debug.Print("Setting drawable for context {0} to window port: {1}", Handle.Handle, windowPort); byte code = Agl.aglSetDrawable(ContextHandle, windowPort); - Agl.CheckReturnValue( code, "aglSetDrawable" ); + Agl.CheckReturnValue(code, "aglSetDrawable"); } public override void Update(INativeWindow window) { @@ -157,9 +157,9 @@ namespace OpenTK.Platform.MacOS { internal void UnsetFullScreen(CarbonWindow window) { Debug.Print("Unsetting AGL fullscreen."); byte code = Agl.aglSetDrawable(ContextHandle, IntPtr.Zero); - Agl.CheckReturnValue( code, "aglSetDrawable" ); + Agl.CheckReturnValue(code, "aglSetDrawable"); code = Agl.aglUpdateContext(ContextHandle); - Agl.CheckReturnValue( code, "aglUpdateContext" ); + Agl.CheckReturnValue(code, "aglUpdateContext"); CG.CGDisplayRelease(GetQuartzDevice(window)); Debug.Print("Resetting drawable."); @@ -173,12 +173,12 @@ namespace OpenTK.Platform.MacOS { public override void SwapBuffers() { Agl.aglSwapBuffers(ContextHandle); - Agl.CheckReturnValue( 0, "aglSwapBuffers" ); + Agl.CheckReturnValue(0, "aglSwapBuffers"); } public override void MakeCurrent(INativeWindow window) { byte code = Agl.aglSetCurrentContext(ContextHandle); - Agl.CheckReturnValue(code, "aglSetCurrentContext" ); + Agl.CheckReturnValue(code, "aglSetCurrentContext"); } public override bool IsCurrent { @@ -214,12 +214,12 @@ namespace OpenTK.Platform.MacOS { Debug.Print("Destroying context"); byte code = Agl.aglDestroyContext(ContextHandle); try { - Agl.CheckReturnValue(code, "aglDestroyContext" ); + Agl.CheckReturnValue(code, "aglDestroyContext"); ContextHandle = IntPtr.Zero; Debug.Print("Context destruction completed successfully."); - } catch( MacOSException ) { + } catch(MacOSException) { Debug.Print("Failed to destroy context."); - if( disposing ) + if (disposing) throw; } IsDisposed = true; diff --git a/OpenTK/Platform/MacOS/Application.cs b/OpenTK/Platform/MacOS/Application.cs index 851e15ecb..b70364f33 100644 --- a/OpenTK/Platform/MacOS/Application.cs +++ b/OpenTK/Platform/MacOS/Application.cs @@ -45,7 +45,7 @@ namespace OpenTK.Platform.MacOS.Carbon private static void TransformProcessToForeground() { - Carbon.ProcessSerialNumber psn = new ProcessSerialNumber(); + ProcessSerialNumber psn = new ProcessSerialNumber(); Debug.Print("Setting process to be foreground application."); diff --git a/OpenTK/Platform/MacOS/CarbonBindings/API.cs b/OpenTK/Platform/MacOS/CarbonBindings/API.cs index d5485da78..d85dedbcd 100644 --- a/OpenTK/Platform/MacOS/CarbonBindings/API.cs +++ b/OpenTK/Platform/MacOS/CarbonBindings/API.cs @@ -3,7 +3,8 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; -namespace OpenTK.Platform.MacOS.Carbon { +namespace OpenTK.Platform.MacOS { + // Core foundation services internal class CF { const string appServices = "/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/ApplicationServices"; diff --git a/OpenTK/Platform/MacOS/CarbonBindings/Agl.cs b/OpenTK/Platform/MacOS/CarbonBindings/Agl.cs index a5981c684..f7bf642c2 100644 --- a/OpenTK/Platform/MacOS/CarbonBindings/Agl.cs +++ b/OpenTK/Platform/MacOS/CarbonBindings/Agl.cs @@ -1,102 +1,102 @@ -// Created by Erik Ylvisaker on 3/17/08. -// Copyright 2008. All rights reserved. - -using System; -using System.Runtime.InteropServices; -using AGLContext = System.IntPtr; -using AGLDevice = System.IntPtr; -using AGLDrawable = System.IntPtr; -using AGLPixelFormat = System.IntPtr; - -namespace OpenTK.Platform.MacOS { - - public unsafe static class Agl { - const string agl = "/System/Library/Frameworks/AGL.framework/Versions/Current/AGL"; - - // Attribute names for aglChoosePixelFormat and aglDescribePixelFormat. - internal enum PixelFormatAttribute { - AGL_NONE = 0, - AGL_RGBA = 4, - AGL_DOUBLEBUFFER = 5, - AGL_RED_SIZE = 8, - AGL_GREEN_SIZE = 9, - AGL_BLUE_SIZE = 10, - AGL_ALPHA_SIZE = 11, - AGL_DEPTH_SIZE = 12, - AGL_STENCIL_SIZE = 13, - AGL_FULLSCREEN = 54, - } - - // Integer parameter names - internal enum ParameterNames { - AGL_SWAP_INTERVAL = 222, /* 0 -> Don't sync, n -> Sync every n retrace */ - } - - // Error return values from aglGetError. - internal enum AglError { - NoError = 0, /* no error */ - - BadAttribute = 10000, /* invalid pixel format attribute */ - BadProperty = 10001, /* invalid renderer property */ - BadPixelFormat = 10002, /* invalid pixel format */ - BadRendererInfo = 10003, /* invalid renderer info */ - BadContext = 10004, /* invalid context */ - BadDrawable = 10005, /* invalid drawable */ - BadGraphicsDevice = 10006, /* invalid graphics device */ - BadState = 10007, /* invalid context state */ - BadValue = 10008, /* invalid numerical value */ - BadMatch = 10009, /* invalid share context */ - BadEnum = 10010, /* invalid enumerant */ - BadOffscreen = 10011, /* invalid offscreen drawable */ - BadFullscreen = 10012, /* invalid offscreen drawable */ - BadWindow = 10013, /* invalid window */ - BadPointer = 10014, /* invalid pointer */ - BadModule = 10015, /* invalid code module */ - BadAlloc = 10016, /* memory allocation failure */ - BadConnection = 10017, /* invalid CoreGraphics connection */ - } - - // Pixel format functions - [DllImport(agl)] internal static extern AGLPixelFormat aglChoosePixelFormat(ref AGLDevice gdevs, int ndev, int[] attribs); - [DllImport(agl)] internal static extern AGLPixelFormat aglChoosePixelFormat(IntPtr gdevs, int ndev, int[] attribs); - [DllImport(agl)] internal static extern void aglDestroyPixelFormat(AGLPixelFormat pix); - - // Context functions - [DllImport(agl)] internal static extern AGLContext aglCreateContext(AGLPixelFormat pix, AGLContext share); - [DllImport(agl)] internal static extern byte aglDestroyContext(AGLContext ctx); - [DllImport(agl)] internal static extern byte aglUpdateContext(AGLContext ctx); - - // Current state functions - [DllImport(agl)] internal static extern byte aglSetCurrentContext(AGLContext ctx); - [DllImport(agl)] internal static extern AGLContext aglGetCurrentContext(); - - // Drawable Functions - [DllImport(agl)] internal static extern byte aglSetDrawable(AGLContext ctx, AGLDrawable draw); - [DllImport(agl)] internal static extern byte aglSetFullScreen(AGLContext ctx, int width, int height, int freq, int device); - - // Virtual screen functions - [DllImport(agl)] static extern byte aglSetVirtualScreen(AGLContext ctx, int screen); - [DllImport(agl)] static extern int aglGetVirtualScreen(AGLContext ctx); - - // Swap functions - [DllImport(agl)] internal static extern void aglSwapBuffers(AGLContext ctx); - - // Per context options - [DllImport(agl)] internal static extern byte aglSetInteger(AGLContext ctx, ParameterNames pname, ref int @params); - - // Error functions - [DllImport(agl)] internal static extern AglError aglGetError(); - [DllImport(agl)] static extern IntPtr aglErrorString(AglError code); - - internal static void CheckReturnValue( byte code, string function ) { - if( code != 0 ) return; - AglError errCode = aglGetError(); - if( errCode == AglError.NoError ) return; - - string error = new String( (sbyte*)aglErrorString( errCode ) ); - throw new MacOSException( (OSStatus)errCode, String.Format( - "AGL Error from function {0}: {1} {2}", - function, errCode, error) ); - } - } -} +// Created by Erik Ylvisaker on 3/17/08. +// Copyright 2008. All rights reserved. + +using System; +using System.Runtime.InteropServices; +using AGLContext = System.IntPtr; +using AGLDevice = System.IntPtr; +using AGLDrawable = System.IntPtr; +using AGLPixelFormat = System.IntPtr; + +namespace OpenTK.Platform.MacOS { + + public unsafe static class Agl { + const string agl = "/System/Library/Frameworks/AGL.framework/Versions/Current/AGL"; + + // Attribute names for aglChoosePixelFormat and aglDescribePixelFormat. + internal enum PixelFormatAttribute { + AGL_NONE = 0, + AGL_RGBA = 4, + AGL_DOUBLEBUFFER = 5, + AGL_RED_SIZE = 8, + AGL_GREEN_SIZE = 9, + AGL_BLUE_SIZE = 10, + AGL_ALPHA_SIZE = 11, + AGL_DEPTH_SIZE = 12, + AGL_STENCIL_SIZE = 13, + AGL_FULLSCREEN = 54, + } + + // Integer parameter names + internal enum ParameterNames { + AGL_SWAP_INTERVAL = 222, /* 0 -> Don't sync, n -> Sync every n retrace */ + } + + // Error return values from aglGetError. + internal enum AglError { + NoError = 0, /* no error */ + + BadAttribute = 10000, /* invalid pixel format attribute */ + BadProperty = 10001, /* invalid renderer property */ + BadPixelFormat = 10002, /* invalid pixel format */ + BadRendererInfo = 10003, /* invalid renderer info */ + BadContext = 10004, /* invalid context */ + BadDrawable = 10005, /* invalid drawable */ + BadGraphicsDevice = 10006, /* invalid graphics device */ + BadState = 10007, /* invalid context state */ + BadValue = 10008, /* invalid numerical value */ + BadMatch = 10009, /* invalid share context */ + BadEnum = 10010, /* invalid enumerant */ + BadOffscreen = 10011, /* invalid offscreen drawable */ + BadFullscreen = 10012, /* invalid offscreen drawable */ + BadWindow = 10013, /* invalid window */ + BadPointer = 10014, /* invalid pointer */ + BadModule = 10015, /* invalid code module */ + BadAlloc = 10016, /* memory allocation failure */ + BadConnection = 10017, /* invalid CoreGraphics connection */ + } + + // Pixel format functions + [DllImport(agl)] internal static extern AGLPixelFormat aglChoosePixelFormat(ref AGLDevice gdevs, int ndev, int[] attribs); + [DllImport(agl)] internal static extern AGLPixelFormat aglChoosePixelFormat(IntPtr gdevs, int ndev, int[] attribs); + [DllImport(agl)] internal static extern void aglDestroyPixelFormat(AGLPixelFormat pix); + + // Context functions + [DllImport(agl)] internal static extern AGLContext aglCreateContext(AGLPixelFormat pix, AGLContext share); + [DllImport(agl)] internal static extern byte aglDestroyContext(AGLContext ctx); + [DllImport(agl)] internal static extern byte aglUpdateContext(AGLContext ctx); + + // Current state functions + [DllImport(agl)] internal static extern byte aglSetCurrentContext(AGLContext ctx); + [DllImport(agl)] internal static extern AGLContext aglGetCurrentContext(); + + // Drawable Functions + [DllImport(agl)] internal static extern byte aglSetDrawable(AGLContext ctx, AGLDrawable draw); + [DllImport(agl)] internal static extern byte aglSetFullScreen(AGLContext ctx, int width, int height, int freq, int device); + + // Virtual screen functions + [DllImport(agl)] static extern byte aglSetVirtualScreen(AGLContext ctx, int screen); + [DllImport(agl)] static extern int aglGetVirtualScreen(AGLContext ctx); + + // Swap functions + [DllImport(agl)] internal static extern void aglSwapBuffers(AGLContext ctx); + + // Per context options + [DllImport(agl)] internal static extern byte aglSetInteger(AGLContext ctx, ParameterNames pname, ref int @params); + + // Error functions + [DllImport(agl)] internal static extern AglError aglGetError(); + [DllImport(agl)] static extern IntPtr aglErrorString(AglError code); + + internal static void CheckReturnValue(byte code, string function) { + if (code != 0) return; + AglError errCode = aglGetError(); + if (errCode == AglError.NoError) return; + + string error = new String((sbyte*)aglErrorString(errCode)); + throw new MacOSException((OSStatus)errCode, String.Format( + "AGL Error from function {0}: {1} {2}", + function, errCode, error)); + } + } +} diff --git a/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs b/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs index cbffd01b9..7d61b8658 100644 --- a/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs +++ b/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs @@ -6,28 +6,21 @@ using System.Runtime.InteropServices; using System.Drawing; using EventTime = System.Double; - -namespace OpenTK.Platform.MacOS.Carbon -{ - - #region --- Types defined in MacTypes.h --- +namespace OpenTK.Platform.MacOS { [StructLayout(LayoutKind.Sequential)] - public struct CarbonPoint - { + public struct CarbonPoint { public short V; public short H; - public CarbonPoint(int x, int y) - { + public CarbonPoint(int x, int y) { V = (short)x; H = (short)y; } } [StructLayout(LayoutKind.Sequential)] - public struct Rect - { + public struct Rect { short top; short left; short bottom; @@ -40,21 +33,10 @@ namespace OpenTK.Platform.MacOS.Carbon right = (short)(_left + _width); } - public short X { - get { return left; } - } - - public short Y { - get { return top; } - } - - public short Width { - get { return (short)(right - left); } - } - - public short Height { - get { return (short)(bottom - top); } - } + public short X { get { return left; } } + public short Y { get { return top; } } + public short Width { get { return (short)(right - left); } } + public short Height { get { return (short)(bottom - top); } } public override string ToString() { return string.Format( @@ -66,26 +48,23 @@ namespace OpenTK.Platform.MacOS.Carbon } } - #endregion - #region --- Types defined in HIGeometry.h --- - [StructLayout(LayoutKind.Sequential)] public struct HIPoint { public IntPtr xVal; public IntPtr yVal; public float X { - get { return GetFloat( xVal ); } - set { SetFloat( ref xVal, value ); } + get { return GetFloat(xVal); } + set { SetFloat(ref xVal, value); } } public float Y { - get { return GetFloat( yVal ); } - set { SetFloat( ref yVal, value ); } + get { return GetFloat(yVal); } + set { SetFloat(ref yVal, value); } } - static unsafe float GetFloat( IntPtr val ) { - if( IntPtr.Size == 8 ) { + static unsafe float GetFloat(IntPtr val) { + if (IntPtr.Size == 8) { long raw = val.ToInt64(); return (float)(*((double*)&raw)); } else { @@ -94,15 +73,15 @@ namespace OpenTK.Platform.MacOS.Carbon } } - static unsafe void SetFloat( ref IntPtr val, float x ) { - if( IntPtr.Size == 8 ) { + static unsafe void SetFloat(ref IntPtr val, float x) { + if (IntPtr.Size == 8) { long raw = 0; *((double*)&raw) = x; - val = new IntPtr( raw ); + val = new IntPtr(raw); } else { int raw = 0; *((float*)&raw) = x; - val = new IntPtr( raw ); + val = new IntPtr(raw); } } } @@ -118,10 +97,7 @@ namespace OpenTK.Platform.MacOS.Carbon } } - #endregion - - public struct EventInfo { - + public struct EventInfo { public EventInfo(IntPtr eventRef) { EventClass = API.GetEventClass(eventRef); EventKind = API.GetEventKind(eventRef); @@ -129,10 +105,6 @@ namespace OpenTK.Platform.MacOS.Carbon public uint EventKind; public EventClass EventClass; - - public override string ToString() { - return "Event: " + EventClass + ",kind: " + EventKind; - } } #region --- Types defined in CarbonEvents.h --- @@ -404,35 +376,24 @@ namespace OpenTK.Platform.MacOS.Carbon } #endregion - #region --- Enums from gestalt.h --- - public enum GestaltSelector - { + public enum GestaltSelector { SystemVersion = 0x73797376, // FOUR_CHAR_CODE("sysv"), /* system version*/ SystemVersionMajor = 0x73797331, // FOUR_CHAR_CODE("sys1"), /* The major system version number; in 10.4.17 this would be the decimal value 10 */ SystemVersionMinor = 0x73797332, // FOUR_CHAR_CODE("sys2"), /* The minor system version number; in 10.4.17 this would be the decimal value 4 */ SystemVersionBugFix = 0x73797333, // FOUR_CHAR_CODE("sys3") /* The bug fix system version number; in 10.4.17 this would be the decimal value 17 */ }; - #endregion - #region --- Process Manager --- - - public enum ProcessApplicationTransformState : int - { + public enum ProcessApplicationTransformState : int { kProcessTransformToForegroundApplication = 1, } - public struct ProcessSerialNumber - { + public struct ProcessSerialNumber { public ulong high; public ulong low; } - #endregion - - - public enum HICoordinateSpace - { + public enum HICoordinateSpace { _72DPIGlobal = 1, ScreenPixel = 2, Window = 3, @@ -441,7 +402,7 @@ namespace OpenTK.Platform.MacOS.Carbon #region --- Carbon API Methods --- - public class API + public static class API { const string carbon = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon"; @@ -450,17 +411,11 @@ namespace OpenTK.Platform.MacOS.Carbon [DllImport(carbon)] public static extern uint GetEventKind(IntPtr inEvent); - #region --- Window Construction --- - [DllImport(carbon)] public static extern OSStatus CreateNewWindow(WindowClass @class, WindowAttributes attributes, ref Rect r, out IntPtr window); - [DllImport(carbon)] public static extern void DisposeWindow(IntPtr window); - #endregion - #region --- Showing / Hiding Windows --- - [DllImport(carbon)] public static extern void ShowWindow(IntPtr window); [DllImport(carbon)] @@ -470,9 +425,6 @@ namespace OpenTK.Platform.MacOS.Carbon [DllImport(carbon)] public static extern void SelectWindow(IntPtr window); - #endregion - #region --- Window Boundaries --- - [DllImport(carbon)] public static extern OSStatus RepositionWindow(IntPtr window, IntPtr parentWindow, WindowPositionMethod method); [DllImport(carbon)] @@ -482,23 +434,15 @@ namespace OpenTK.Platform.MacOS.Carbon [DllImport(carbon)] static extern OSStatus GetWindowBounds(IntPtr window, WindowRegionCode regionCode, out Rect globalBounds); - public static Rect GetWindowBounds(IntPtr window, WindowRegionCode regionCode) - { + public static Rect GetWindowBounds(IntPtr window, WindowRegionCode regionCode) { Rect retval; OSStatus error = GetWindowBounds(window, regionCode, out retval); - CheckReturn( error ); + CheckReturn(error); return retval; } - //[DllImport(carbon)] - //public static extern void MoveWindow(IntPtr window, short hGlobal, short vGlobal, bool front); - - #endregion - #region --- Processing Events --- - [DllImport(carbon)] static extern IntPtr GetEventDispatcherTarget(); - [DllImport(carbon,EntryPoint="ReceiveNextEvent")] static extern OSStatus ReceiveNextEvent(uint inNumTypes, IntPtr inList, @@ -589,7 +533,7 @@ namespace OpenTK.Platform.MacOS.Carbon #region --- Getting Event Parameters --- [DllImport(carbon)] - static extern OSStatus CreateEvent( IntPtr inAllocator, + static extern OSStatus CreateEvent(IntPtr inAllocator, EventClass inClassID, UInt32 kind, EventTime when, EventAttributes flags, out IntPtr outEvent); @@ -697,7 +641,7 @@ namespace OpenTK.Platform.MacOS.Carbon #region --- Event Handlers --- [DllImport(carbon)] - static extern OSStatus InstallEventHandler( IntPtr eventTargetRef, IntPtr handlerProc, + static extern OSStatus InstallEventHandler(IntPtr eventTargetRef, IntPtr handlerProc, int numtypes, EventTypeSpec[] typeList, IntPtr userData, IntPtr handlerRef); @@ -708,7 +652,7 @@ namespace OpenTK.Platform.MacOS.Carbon OSStatus error = InstallEventHandler(windowTarget, uppHandlerProc, eventTypes.Length, eventTypes, userData, handlerRef); - CheckReturn( error ); + CheckReturn(error); } public static void InstallApplicationEventHandler(IntPtr uppHandlerProc, @@ -717,7 +661,7 @@ namespace OpenTK.Platform.MacOS.Carbon OSStatus error = InstallEventHandler(GetApplicationEventTarget(), uppHandlerProc, eventTypes.Length, eventTypes, userData, handlerRef); - CheckReturn( error ); + CheckReturn(error); } [DllImport(carbon)] @@ -745,11 +689,11 @@ namespace OpenTK.Platform.MacOS.Carbon #region --- Process Manager --- [DllImport(carbon)] - public static extern int TransformProcessType(ref Carbon.ProcessSerialNumber psn, ProcessApplicationTransformState type); + public static extern int TransformProcessType(ref ProcessSerialNumber psn, ProcessApplicationTransformState type); [DllImport(carbon)] - public static extern int GetCurrentProcess(ref Carbon.ProcessSerialNumber psn); + public static extern int GetCurrentProcess(ref ProcessSerialNumber psn); [DllImport(carbon)] - public static extern int SetFrontProcess(ref Carbon.ProcessSerialNumber psn); + public static extern int SetFrontProcess(ref ProcessSerialNumber psn); #endregion #region --- Setting Dock Tile --- @@ -772,13 +716,13 @@ namespace OpenTK.Platform.MacOS.Carbon [DllImport(carbon)] public extern static void CGColorSpaceRelease(IntPtr space); [DllImport(carbon)] - public extern static void CGContextDrawImage( IntPtr context, HIRect rect, IntPtr image ); + public extern static void CGContextDrawImage(IntPtr context, HIRect rect, IntPtr image); [DllImport(carbon)] - public extern static void CGContextSynchronize( IntPtr context ); + public extern static void CGContextSynchronize(IntPtr context); [DllImport(carbon)] - public extern static OSStatus QDBeginCGContext( IntPtr port, ref IntPtr context ); + public extern static OSStatus QDBeginCGContext(IntPtr port, ref IntPtr context); [DllImport(carbon)] - public extern static OSStatus QDEndCGContext( IntPtr port, ref IntPtr context ); + public extern static OSStatus QDEndCGContext(IntPtr port, ref IntPtr context); #endregion #region --- Clipboard --- @@ -861,9 +805,9 @@ namespace OpenTK.Platform.MacOS.Carbon [DllImport(carbon)] public static extern OSStatus CollapseWindow(IntPtr windowRef, bool collapse); - public static void CheckReturn(OSStatus error ) { - if( error != OSStatus.NoError ) - throw new MacOSException( error ); + public static void CheckReturn(OSStatus error) { + if (error != OSStatus.NoError) + throw new MacOSException(error); } [DllImport(carbon, EntryPoint="IsWindowInStandardState")] @@ -882,7 +826,7 @@ namespace OpenTK.Platform.MacOS.Carbon IntPtr displayID, out IntPtr displayDevice, Boolean failToMain); [DllImport(carbon)] - public unsafe static extern IntPtr HIGetMousePosition( HICoordinateSpace space, IntPtr obj, ref HIPoint point ); + public unsafe static extern IntPtr HIGetMousePosition(HICoordinateSpace space, IntPtr obj, ref HIPoint point); #region Nonworking HIPointConvert routines @@ -911,7 +855,7 @@ namespace OpenTK.Platform.MacOS.Carbon //[DllImport(carbon, EntryPoint = "HIViewConvertPoint")] //extern static OSStatus _HIViewConvertPoint(ref HIPoint inPoint, IntPtr inSourceView, IntPtr inDestView); - //public static HIPoint HIViewConvertPoint( HIPoint point, IntPtr sourceHandle, IntPtr destHandle) + //public static HIPoint HIViewConvertPoint(HIPoint point, IntPtr sourceHandle, IntPtr destHandle) //{ // //Carbon.Rect window_bounds = new Carbon.Rect(); // //Carbon.API.GetWindowBounds(handle, WindowRegionCode.StructureRegion /*32*/, out window_bounds); @@ -932,12 +876,7 @@ namespace OpenTK.Platform.MacOS.Carbon #endregion const string gestaltlib = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon"; - - [DllImport(gestaltlib)] public static extern OSStatus Gestalt(GestaltSelector selector, out int response); } - - #endregion - } diff --git a/OpenTK/Platform/MacOS/CarbonBindings/MacOSKeys.cs b/OpenTK/Platform/MacOS/CarbonBindings/MacOSKeys.cs index 9046190ca..74854e96b 100644 --- a/OpenTK/Platform/MacOS/CarbonBindings/MacOSKeys.cs +++ b/OpenTK/Platform/MacOS/CarbonBindings/MacOSKeys.cs @@ -1,122 +1,122 @@ -using System; - -namespace OpenTK.Platform.MacOS.Carbon -{ - public enum MacOSKeyCode - { - A = 0, - B = 11, - C = 8, - D = 2, - E = 14, - F = 3, - G = 5, - H = 4, - I = 34, - J = 38, - K = 40, - L = 37, - M = 46, - N = 45, - O = 31, - P = 35, - Q = 12, - R = 15, - S = 1, - T = 17, - U = 32, - V = 9, - W = 13, - X = 7, - Y = 16, - Z = 6, - - Key_1 = 18, - Key_2 = 19, - Key_3 = 20, - Key_4 = 21, - Key_5 = 23, - Key_6 = 22, - Key_7 = 26, - Key_8 = 28, - Key_9 = 25, - Key_0 = 29, - - Space = 49, - Tilde = 50, - - Minus = 27, - Equals = 24, - BracketLeft = 33, - BracketRight = 30, - Backslash = 42, - Semicolon = 41, - Quote = 39, - Comma = 43, - Period = 47, - Slash = 44, - - Enter = 36, - Tab = 48, - Backspace = 51, - Return = 52, - Esc = 53, - KeyPad_Decimal = 65, - KeyPad_Multiply = 67, - KeyPad_Add = 69, - KeyPad_Divide = 75, - KeyPad_Enter = 76, - KeyPad_Subtract = 78, - KeyPad_Equal = 81, - KeyPad_0 = 82, - KeyPad_1 = 83, - KeyPad_2 = 84, - KeyPad_3 = 85, - KeyPad_4 = 86, - KeyPad_5 = 87, - KeyPad_6 = 88, - KeyPad_7 = 89, - KeyPad_8 = 91, - KeyPad_9 = 92, - F1 = 122, - F2 = 120, - F3 = 99, - F4 = 118, - F5 = 96, - F6 = 97, - F7 = 98, - F8 = 100, - F9 = 101, - F10 = 109, - F11 = 103, - F12 = 111, - F13 = 105, - F14 = 107, - F15 = 113, - - Menu = 110, - - Insert = 114, - Home = 115, - Pageup = 116, - Del = 117, - End = 119, - Pagedown = 121, - Up = 126, - Down = 125, - Left = 123, - Right = 124, - - - } - [Flags] - public enum MacOSKeyModifiers - { - None = 0, - Shift = 0x0200, - CapsLock = 0x0400, - Control = 0x1000, // - Command = 0x0100, // Open-Apple - Windows key - Option = 0x0800, // Option key is same position as the alt key on non-mac keyboards. - } -} +using System; + +namespace OpenTK.Platform.MacOS +{ + public enum MacOSKeyCode + { + A = 0, + B = 11, + C = 8, + D = 2, + E = 14, + F = 3, + G = 5, + H = 4, + I = 34, + J = 38, + K = 40, + L = 37, + M = 46, + N = 45, + O = 31, + P = 35, + Q = 12, + R = 15, + S = 1, + T = 17, + U = 32, + V = 9, + W = 13, + X = 7, + Y = 16, + Z = 6, + + Key_1 = 18, + Key_2 = 19, + Key_3 = 20, + Key_4 = 21, + Key_5 = 23, + Key_6 = 22, + Key_7 = 26, + Key_8 = 28, + Key_9 = 25, + Key_0 = 29, + + Space = 49, + Tilde = 50, + + Minus = 27, + Equals = 24, + BracketLeft = 33, + BracketRight = 30, + Backslash = 42, + Semicolon = 41, + Quote = 39, + Comma = 43, + Period = 47, + Slash = 44, + + Enter = 36, + Tab = 48, + Backspace = 51, + Return = 52, + Esc = 53, + KeyPad_Decimal = 65, + KeyPad_Multiply = 67, + KeyPad_Add = 69, + KeyPad_Divide = 75, + KeyPad_Enter = 76, + KeyPad_Subtract = 78, + KeyPad_Equal = 81, + KeyPad_0 = 82, + KeyPad_1 = 83, + KeyPad_2 = 84, + KeyPad_3 = 85, + KeyPad_4 = 86, + KeyPad_5 = 87, + KeyPad_6 = 88, + KeyPad_7 = 89, + KeyPad_8 = 91, + KeyPad_9 = 92, + F1 = 122, + F2 = 120, + F3 = 99, + F4 = 118, + F5 = 96, + F6 = 97, + F7 = 98, + F8 = 100, + F9 = 101, + F10 = 109, + F11 = 103, + F12 = 111, + F13 = 105, + F14 = 107, + F15 = 113, + + Menu = 110, + + Insert = 114, + Home = 115, + Pageup = 116, + Del = 117, + End = 119, + Pagedown = 121, + Up = 126, + Down = 125, + Left = 123, + Right = 124, + + + } + + [Flags] + public enum MacOSKeyModifiers { + None = 0, + Shift = 0x0200, + CapsLock = 0x0400, + Control = 0x1000, // + Command = 0x0100, // Open-Apple - Windows key + Option = 0x0800, // Option key is same position as the alt key on non-mac keyboards. + } +} diff --git a/OpenTK/Platform/MacOS/CarbonWindow.cs b/OpenTK/Platform/MacOS/CarbonWindow.cs index da76a8f78..467ad2f1d 100644 --- a/OpenTK/Platform/MacOS/CarbonWindow.cs +++ b/OpenTK/Platform/MacOS/CarbonWindow.cs @@ -99,8 +99,8 @@ namespace OpenTK.Platform.MacOS { IntPtr windowRef; OSStatus err = API.CreateNewWindow(@class, attrib, ref r, out windowRef); - API.CheckReturn( err ); - Debug.Print( "Created window " + windowRef.ToString() ); + API.CheckReturn(err); + Debug.Print("Created window " + windowRef.ToString()); API.SetWindowTitle(windowRef, title); SetLocation(r.X, r.Y); @@ -143,20 +143,6 @@ namespace OpenTK.Platform.MacOS { Application.WindowEventHandler = this; } - void Activate() { - API.SelectWindow(WinHandle); - } - - void Show() { - API.ShowWindow(WinHandle); - API.RepositionWindow(WinHandle, IntPtr.Zero, mPositionMethod); - API.SelectWindow(WinHandle); - } - - void Hide() { - API.HideWindow(WinHandle); - } - internal void SetFullscreen(AglContext context) { windowedBounds = bounds; int width, height; @@ -219,8 +205,8 @@ namespace OpenTK.Platform.MacOS { } Key tkKey; - if( !Keymap.TryGetValue( code, out tkKey ) ) { - Debug.Print( "{0} not mapped, ignoring press.", code ); + if (!Keymap.TryGetValue(code, out tkKey)) { + Debug.Print("{0} not mapped, ignoring press.", code); return OSStatus.NoError; } @@ -470,74 +456,74 @@ namespace OpenTK.Platform.MacOS { IntPtr pbStr, utf16, utf8; public override string GetClipboardText() { IntPtr pbRef = GetPasteboard(); - API.PasteboardSynchronize( pbRef ); + API.PasteboardSynchronize(pbRef); uint itemCount; - OSStatus err = API.PasteboardGetItemCount( pbRef, out itemCount ); - if( err != OSStatus.NoError ) - throw new MacOSException( err, "Getting item count from Pasteboard." ); - if( itemCount < 1 ) return ""; + OSStatus err = API.PasteboardGetItemCount(pbRef, out itemCount); + if (err != OSStatus.NoError) + throw new MacOSException(err, "Getting item count from Pasteboard."); + if (itemCount < 1) return ""; uint itemID; - err = API.PasteboardGetItemIdentifier( pbRef, 1, out itemID ); - if( err != OSStatus.NoError ) - throw new MacOSException( err, "Getting item identifier from Pasteboard." ); + err = API.PasteboardGetItemIdentifier(pbRef, 1, out itemID); + if (err != OSStatus.NoError) + throw new MacOSException(err, "Getting item identifier from Pasteboard."); IntPtr outData; - if ( (err = API.PasteboardCopyItemFlavorData( pbRef, itemID, utf16, out outData )) == OSStatus.NoError ) { - IntPtr ptr = API.CFDataGetBytePtr( outData ); - if( ptr == IntPtr.Zero ) - throw new InvalidOperationException( "CFDataGetBytePtr() returned null pointer." ); - return Marshal.PtrToStringUni( ptr ); - } else if ( (err = API.PasteboardCopyItemFlavorData( pbRef, itemID, utf8, out outData )) == OSStatus.NoError ) { - IntPtr ptr = API.CFDataGetBytePtr( outData ); - if( ptr == IntPtr.Zero ) - throw new InvalidOperationException( "CFDataGetBytePtr() returned null pointer." ); - return GetUTF8( ptr ); + if ((err = API.PasteboardCopyItemFlavorData(pbRef, itemID, utf16, out outData)) == OSStatus.NoError) { + IntPtr ptr = API.CFDataGetBytePtr(outData); + if (ptr == IntPtr.Zero) + throw new InvalidOperationException("CFDataGetBytePtr() returned null pointer."); + return Marshal.PtrToStringUni(ptr); + } else if ((err = API.PasteboardCopyItemFlavorData(pbRef, itemID, utf8, out outData)) == OSStatus.NoError) { + IntPtr ptr = API.CFDataGetBytePtr(outData); + if (ptr == IntPtr.Zero) + throw new InvalidOperationException("CFDataGetBytePtr() returned null pointer."); + return GetUTF8(ptr); } return ""; } - unsafe static string GetUTF8( IntPtr ptr ) { + unsafe static string GetUTF8(IntPtr ptr) { byte* countPtr = (byte*)ptr, readPtr = (byte*)ptr; int length = 0; - while( *countPtr != 0 ) { length++; countPtr++; } + while (*countPtr != 0) { length++; countPtr++; } byte[] text = new byte[length]; - for( int i = 0; i < text.Length; i++ ) { + for(int i = 0; i < text.Length; i++) { text[i] = *readPtr; readPtr++; } - return Encoding.UTF8.GetString( text ); + return Encoding.UTF8.GetString(text); } - public override void SetClipboardText( string value ) { + public override void SetClipboardText(string value) { IntPtr pbRef = GetPasteboard(); - OSStatus err = API.PasteboardClear( pbRef ); - if( err != OSStatus.NoError ) - throw new MacOSException( err, "Cleaing Pasteboard." ); - API.PasteboardSynchronize( pbRef ); + OSStatus err = API.PasteboardClear(pbRef); + if (err != OSStatus.NoError) + throw new MacOSException(err, "Cleaing Pasteboard."); + API.PasteboardSynchronize(pbRef); - IntPtr ptr = Marshal.StringToHGlobalUni( value ); - IntPtr cfData = API.CFDataCreate( IntPtr.Zero, ptr, (value.Length + 1) * 2 ); - if( cfData == IntPtr.Zero ) - throw new InvalidOperationException( "CFDataCreate() returned null pointer." ); + IntPtr ptr = Marshal.StringToHGlobalUni(value); + IntPtr cfData = API.CFDataCreate(IntPtr.Zero, ptr, (value.Length + 1) * 2); + if (cfData == IntPtr.Zero) + throw new InvalidOperationException("CFDataCreate() returned null pointer."); - API.PasteboardPutItemFlavor( pbRef, 1, utf16, cfData, 0 ); - Marshal.FreeHGlobal( ptr ); + API.PasteboardPutItemFlavor(pbRef, 1, utf16, cfData, 0); + Marshal.FreeHGlobal(ptr); } IntPtr GetPasteboard() { - if( pbStr == IntPtr.Zero ) { - pbStr = CF.CFSTR( "com.apple.pasteboard.clipboard" ); - utf16 = CF.CFSTR( "public.utf16-plain-text" ); - utf8 = CF.CFSTR( "public.utf8-plain-text" ); + if (pbStr == IntPtr.Zero) { + pbStr = CF.CFSTR("com.apple.pasteboard.clipboard"); + utf16 = CF.CFSTR("public.utf16-plain-text"); + utf8 = CF.CFSTR("public.utf8-plain-text"); } IntPtr pbRef; - OSStatus err = API.PasteboardCreate( pbStr, out pbRef ); - if( err != OSStatus.NoError ) - throw new MacOSException( err, "Creating Pasteboard reference." ); - API.PasteboardSynchronize( pbRef ); + OSStatus err = API.PasteboardCreate(pbStr, out pbRef); + if (err != OSStatus.NoError) + throw new MacOSException(err, "Creating Pasteboard reference."); + API.PasteboardSynchronize(pbRef); return pbRef; } @@ -546,14 +532,12 @@ namespace OpenTK.Platform.MacOS { } public override Point PointToClient(Point point) { - IntPtr handle = WinHandle; - Rect r = Carbon.API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion); + Rect r = API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion); return new Point(point.X - r.X, point.Y - r.Y); } public override Point PointToScreen(Point point) { - IntPtr handle = WinHandle; - Rect r = Carbon.API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion); + Rect r = API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion); return new Point(point.X + r.X, point.Y + r.Y); } @@ -602,7 +586,7 @@ namespace OpenTK.Platform.MacOS { byte r = (byte)((pixel >> 16) & 0xFF); byte g = (byte)((pixel >> 8) & 0xFF); byte b = (byte)(pixel & 0xFF); - data[index++] = (IntPtr)(a + (r << 8) + (g << 16) + (b << 24)); + data[index++] = (IntPtr)(a | (r << 8) | (g << 16) | (b << 24)); } else { @@ -611,9 +595,11 @@ namespace OpenTK.Platform.MacOS { } } - fixed( IntPtr* ptr = data ) { + fixed (IntPtr* ptr = data) { IntPtr provider = API.CGDataProviderCreateWithData(IntPtr.Zero, (IntPtr)(void*)ptr, size * 4, IntPtr.Zero); - IntPtr image = API.CGImageCreate(128, 128, 8, 32, 4 * 128, API.CGColorSpaceCreateDeviceRGB(), 4, provider, IntPtr.Zero, 0, 0); + IntPtr colorSpace = API.CGColorSpaceCreateDeviceRGB(); + IntPtr image = API.CGImageCreate(128, 128, 8, 32, 4 * 128, + colorSpace, 4, provider, IntPtr.Zero, 0, 0); API.SetApplicationDockTileImage(image); } } @@ -622,10 +608,13 @@ namespace OpenTK.Platform.MacOS { public override bool Visible { get { return API.IsWindowVisible(WinHandle); } set { - if (value && Visible == false) - Show(); - else - Hide(); + if (value && Visible == false) { + API.ShowWindow(WinHandle); + API.RepositionWindow(WinHandle, IntPtr.Zero, mPositionMethod); + API.SelectWindow(WinHandle); + } else { + API.HideWindow(WinHandle); + } } } @@ -678,13 +667,10 @@ namespace OpenTK.Platform.MacOS { if (windowState == WindowState.Fullscreen) return WindowState.Fullscreen; - if (Carbon.API.IsWindowCollapsed(WinHandle)) + if (API.IsWindowCollapsed(WinHandle)) return WindowState.Minimized; - - if (Carbon.API.IsWindowInStandardState(WinHandle)) { + if (API.IsWindowInStandardState(WinHandle)) return WindowState.Maximized; - } - return WindowState.Normal; } @@ -695,10 +681,8 @@ namespace OpenTK.Platform.MacOS { windowState = value; - if (oldState == WindowState.Fullscreen) - { + if (oldState == WindowState.Fullscreen) { goWindowedHack = true; - // when returning from full screen, wait until the context is updated // to actually do the work. return; @@ -706,7 +690,7 @@ namespace OpenTK.Platform.MacOS { if (oldState == WindowState.Minimized) { OSStatus err = API.CollapseWindow(WinHandle, false); - API.CheckReturn( err ); + API.CheckReturn(err); } SetCarbonWindowState(); @@ -729,7 +713,7 @@ namespace OpenTK.Platform.MacOS { // large ideal size. idealSize = new CarbonPoint(9000, 9000); err = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomOut, ref idealSize); - API.CheckReturn( err ); + API.CheckReturn(err); break; case WindowState.Normal: @@ -737,13 +721,13 @@ namespace OpenTK.Platform.MacOS { { idealSize = new CarbonPoint(); err = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomIn, ref idealSize); - API.CheckReturn( err ); + API.CheckReturn(err); } break; case WindowState.Minimized: err = API.CollapseWindow(WinHandle, true); - API.CheckReturn( err ); + API.CheckReturn(err); break; } @@ -771,17 +755,17 @@ namespace OpenTK.Platform.MacOS { public override Point DesktopCursorPos { get { - HIPoint point = default( HIPoint ); + HIPoint point = default(HIPoint); // NOTE: HIGetMousePosition is only available on OSX 10.5 or later - API.HIGetMousePosition( HICoordinateSpace.ScreenPixel, IntPtr.Zero, ref point ); - return new Point( (int)point.X, (int)point.Y ); + API.HIGetMousePosition(HICoordinateSpace.ScreenPixel, IntPtr.Zero, ref point); + return new Point((int)point.X, (int)point.Y); } set { - HIPoint point = default( HIPoint ); + HIPoint point = default(HIPoint); point.X = value.X; point.Y = value.Y; - CG.CGAssociateMouseAndMouseCursorPosition( 0 ); + CG.CGAssociateMouseAndMouseCursorPosition(0); CG.CGDisplayMoveCursorToPoint(CG.CGMainDisplayID(), point); - CG.CGAssociateMouseAndMouseCursorPosition( 1 ); + CG.CGAssociateMouseAndMouseCursorPosition(1); } } diff --git a/OpenTK/Platform/Windows/API.cs b/OpenTK/Platform/Windows/API.cs index 9efb074b1..9943a3042 100644 --- a/OpenTK/Platform/Windows/API.cs +++ b/OpenTK/Platform/Windows/API.cs @@ -14,162 +14,128 @@ using RECT = OpenTK.Platform.Windows.Win32Rectangle; namespace OpenTK.Platform.Windows { + [SuppressUnmanagedCodeSecurity] internal static class API { - [DllImport("shell32.dll")] - public static extern int SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID); + [DllImport("shell32.dll", CharSet = CharSet.Unicode)] + public static extern int SetCurrentProcessExplicitAppUserModelID(string AppID); - [DllImport("user32.dll"), SuppressUnmanagedCodeSecurity] - internal static extern bool SetWindowPos(IntPtr handle, IntPtr insertAfter, int x, int y, int cx, int cy, SetWindowPosFlags flags); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll")] + internal static extern bool SetWindowPos(IntPtr handle, IntPtr insertAfter, int x, int y, int cx, int cy, SetWindowPosFlags flags); + [DllImport("user32.dll", SetLastError = true)] internal static extern bool AdjustWindowRect([In, Out] ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true)] internal static extern bool AdjustWindowRectEx(ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle); - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] 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), SuppressUnmanagedCodeSecurity] + int X, int Y, int Width, int Height, IntPtr HandleToParentWindow, IntPtr Menu, IntPtr Instance, IntPtr Param); + [DllImport("user32.dll", SetLastError = true)] internal static extern bool DestroyWindow(IntPtr windowHandle); - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] internal static extern ushort RegisterClassEx(ref ExtendedWindowClass window_class); - - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] internal static extern short UnregisterClass(IntPtr className, IntPtr instance); - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true)] internal static extern int SetWindowLong(IntPtr hWnd, GetWindowLongOffsets nIndex, int dwNewLong); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true)] internal static extern uint GetWindowLong(IntPtr hWnd, GetWindowLongOffsets nIndex); - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true)] internal static extern IntPtr GetForegroundWindow(); - - [DllImport("User32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity] - internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, int flags); - - [DllImport("user32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity] - internal static extern IntPtr SendMessage(IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam); - - [DllImport("User32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity] - internal static extern bool PostMessage(IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam); - - [DllImport("User32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity] - internal static extern IntPtr DispatchMessage(ref MSG msg); - - [DllImport("User32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity] - internal static extern bool TranslateMessage(ref MSG lpMsg); - - [DllImport("User32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity] - public extern static IntPtr DefWindowProc(IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam); - - - [DllImport("user32.dll"), SuppressUnmanagedCodeSecurity] - internal static extern IntPtr GetDC(IntPtr hwnd); - - [DllImport("user32.dll"), SuppressUnmanagedCodeSecurity] - internal static extern bool ReleaseDC(IntPtr hwnd, IntPtr DC); - - [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity] - internal static extern int ChoosePixelFormat(IntPtr dc, ref PixelFormatDescriptor pfd); - - [DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity] - internal static extern int DescribePixelFormat(IntPtr deviceContext, int pixel, int pfdSize, ref PixelFormatDescriptor pixelFormat); - - [DllImport("gdi32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal static extern bool SetPixelFormat(IntPtr dc, int format, ref PixelFormatDescriptor pfd); - - [DllImport("gdi32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal static extern bool SwapBuffers(IntPtr dc); - - - [DllImport("kernel32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal static extern IntPtr LoadLibrary(string dllName); - - [DllImport("kernel32", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal static extern IntPtr GetProcAddress(IntPtr hModule, string procName); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommand nCmdShow); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - //internal static extern bool ScreenToClient(IntPtr hWnd, ref POINT point); - internal static extern bool ScreenToClient(IntPtr hWnd, ref Point point); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - //internal static extern bool ClientToScreen(IntPtr hWnd, ref POINT point); - internal static extern bool ClientToScreen(IntPtr hWnd, ref Point point); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal extern static bool GetClientRect(IntPtr windowHandle, out Win32Rectangle clientRectangle); - - [DllImport("user32.dll"), SuppressUnmanagedCodeSecurity] - public static extern bool IsWindowVisible(IntPtr intPtr); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true)] public static extern bool SetForegroundWindow(IntPtr hWnd); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true)] public static extern bool BringWindowToTop(IntPtr hWnd); - [DllImport("user32.dll", SetLastError = true, CharSet=CharSet.Auto), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll")] + public static extern bool IsWindowVisible(IntPtr intPtr); + [DllImport("user32.dll", SetLastError = true)] + internal static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommand nCmdShow); + + [DllImport("User32.dll", CharSet = CharSet.Auto)] + internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, int flags); + [DllImport("user32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr SendMessage(IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam); + [DllImport("user32.dll", CharSet = CharSet.Auto)] + internal static extern bool PostMessage(IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam); + [DllImport("user32.dll", CharSet = CharSet.Auto)] + internal static extern IntPtr DispatchMessage(ref MSG msg); + [DllImport("user32.dll", CharSet = CharSet.Auto)] + internal static extern bool TranslateMessage(ref MSG lpMsg); + [DllImport("user32.dll", CharSet = CharSet.Auto)] + public extern static IntPtr DefWindowProc(IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam); + + [DllImport("user32.dll")] + internal static extern IntPtr GetDC(IntPtr hwnd); + [DllImport("user32.dll")] + internal static extern bool ReleaseDC(IntPtr hwnd, IntPtr DC); + + [DllImport("gdi32.dll")] + internal static extern int ChoosePixelFormat(IntPtr dc, ref PixelFormatDescriptor pfd); + [DllImport("gdi32.dll")] + internal static extern int DescribePixelFormat(IntPtr deviceContext, int pixel, int pfdSize, ref PixelFormatDescriptor pixelFormat); + [DllImport("gdi32.dll", SetLastError = true)] + internal static extern bool SetPixelFormat(IntPtr dc, int format, ref PixelFormatDescriptor pfd); + [DllImport("gdi32.dll", SetLastError = true)] + internal static extern bool SwapBuffers(IntPtr dc); + + [DllImport("kernel32.dll", SetLastError = true)] + internal static extern IntPtr LoadLibrary(string dllName); + [DllImport("kernel32", SetLastError = true)] + internal static extern IntPtr GetProcAddress(IntPtr hModule, string procName); + + [DllImport("user32.dll", SetLastError = true)] + //internal static extern bool ScreenToClient(IntPtr hWnd, ref POINT point); + internal static extern bool ScreenToClient(IntPtr hWnd, ref Point point); + [DllImport("user32.dll", SetLastError = true)] + //internal static extern bool ClientToScreen(IntPtr hWnd, ref POINT point); + internal static extern bool ClientToScreen(IntPtr hWnd, ref Point point); + [DllImport("user32.dll", SetLastError = true)] + internal extern static bool GetClientRect(IntPtr windowHandle, out Win32Rectangle clientRectangle); + + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern bool EnumDisplayDevices([MarshalAs(UnmanagedType.LPTStr)] string lpDevice, int iDevNum, [In, Out] WindowsDisplayDevice lpDisplayDevice, uint dwFlags); - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] internal static extern bool EnumDisplaySettings([MarshalAs(UnmanagedType.LPTStr)] string device_name, int graphics_mode, [In, Out] DeviceMode device_mode); - - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + + [DllImport("user32.dll", SetLastError = true)] public static extern bool OpenClipboard(IntPtr hWndNewOwner); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - public static extern bool EmptyClipboard(); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - public static extern bool CloseClipboard(); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - public static extern IntPtr GetClipboardData(uint uFormat); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true)] + public static extern bool EmptyClipboard(); + [DllImport("user32.dll", SetLastError = true)] + public static extern bool CloseClipboard(); + [DllImport("user32.dll", SetLastError = true)] + public static extern IntPtr GetClipboardData(uint uFormat); + [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem); - [DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity] - public static extern IntPtr GlobalAlloc(uint uFlags, UIntPtr dwBytes); - - [DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity] - public static extern IntPtr GlobalFree(IntPtr hMem); - - [DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity] - public static extern IntPtr GlobalLock(IntPtr hMem); - - [DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity] - public static extern bool GlobalUnlock(IntPtr hMem); - + [DllImport("kernel32.dll")] + public static extern IntPtr GlobalAlloc(uint uFlags, UIntPtr dwBytes); + [DllImport("kernel32.dll")] + public static extern IntPtr GlobalFree(IntPtr hMem); + [DllImport("kernel32.dll")] + public static extern IntPtr GlobalLock(IntPtr hMem); + [DllImport("kernel32.dll")] + public static extern bool GlobalUnlock(IntPtr hMem); - [DllImport("user32.dll"), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll")] public static extern IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll")] internal static extern bool GetCursorPos(ref POINT point); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true)] internal static extern bool SetCursorPos(int x, int y); + [DllImport("user32.dll", SetLastError = true)] + internal static extern bool ShowCursor(int value); - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal static extern bool ShowCursor( int value ); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] - internal static extern ushort GetKeyState( int code ); - - [DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] + [DllImport("user32.dll", SetLastError = true)] + internal static extern ushort GetKeyState(int code); + [DllImport("user32.dll", SetLastError = true)] internal static extern uint MapVirtualKey(short vkey, MapVirtualKeyType uMapType); } diff --git a/OpenTK/Platform/Windows/Wgl.cs b/OpenTK/Platform/Windows/Wgl.cs index 489d4a77b..f684fd04d 100644 --- a/OpenTK/Platform/Windows/Wgl.cs +++ b/OpenTK/Platform/Windows/Wgl.cs @@ -4,15 +4,16 @@ using System.Security; namespace OpenTK.Platform.Windows { + [SuppressUnmanagedCodeSecurity] internal class Wgl : BindingsBase { - protected override IntPtr GetAddress( string funcname ) { - return Wgl.wglGetProcAddress( funcname ); + protected override IntPtr GetAddress(string funcname) { + return Wgl.wglGetProcAddress(funcname); } internal void LoadEntryPoints() { - LoadDelegate( "wglGetSwapIntervalEXT", out wglGetSwapIntervalEXT ); - LoadDelegate( "wglSwapIntervalEXT", out wglSwapIntervalEXT ); + LoadDelegate("wglGetSwapIntervalEXT", out wglGetSwapIntervalEXT); + LoadDelegate("wglSwapIntervalEXT", out wglSwapIntervalEXT); } [SuppressUnmanagedCodeSecurity] @@ -23,22 +24,22 @@ namespace OpenTK.Platform.Windows { internal delegate int GetSwapIntervalEXT(); internal static GetSwapIntervalEXT wglGetSwapIntervalEXT; - [SuppressUnmanagedCodeSecurity,DllImport("OPENGL32.DLL", SetLastError = true)] + [DllImport("OPENGL32.DLL", SetLastError = true)] internal extern static IntPtr wglCreateContext(IntPtr hDc); - [SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)] + [DllImport("OPENGL32.DLL", SetLastError = true)] internal extern static Boolean wglDeleteContext(IntPtr oldContext); - [SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)] + [DllImport("OPENGL32.DLL", SetLastError = true)] internal extern static IntPtr wglGetCurrentContext(); - [SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)] + [DllImport("OPENGL32.DLL", SetLastError = true)] internal extern static Boolean wglMakeCurrent(IntPtr hDc, IntPtr newContext); - [SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)] + [DllImport("OPENGL32.DLL", SetLastError = true)] internal extern static IntPtr wglGetCurrentDC(); - [SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)] + [DllImport("OPENGL32.DLL", SetLastError = true)] internal extern static IntPtr wglGetProcAddress(String lpszProc); } } diff --git a/OpenTK/Platform/Windows/WinGLContext.cs b/OpenTK/Platform/Windows/WinGLContext.cs index 7a080de5d..6200ea457 100644 --- a/OpenTK/Platform/Windows/WinGLContext.cs +++ b/OpenTK/Platform/Windows/WinGLContext.cs @@ -23,14 +23,14 @@ namespace OpenTK.Platform.Windows { if (opengl32Handle == IntPtr.Zero) throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}", opengl32Name, Marshal.GetLastWin32Error())); - Debug.Print( "Loaded opengl32.dll: {0}", opengl32Handle ); + Debug.Print("Loaded opengl32.dll: {0}", opengl32Handle); } } public WinGLContext(GraphicsMode format, WinWindow window) { Debug.Print("OpenGL will be bound to handle: {0}", window.WinHandle); SelectGraphicsModePFD(format, window); - Debug.Print("Setting pixel format... " ); + Debug.Print("Setting pixel format... "); SetGraphicsModePFD(format, window); ContextHandle = Wgl.wglCreateContext(window.DeviceContext); @@ -39,7 +39,7 @@ namespace OpenTK.Platform.Windows { if (ContextHandle == IntPtr.Zero) throw new GraphicsContextException("Context creation failed. Wgl.CreateContext() error: " + Marshal.GetLastWin32Error()); - Debug.Print( "success! (id: {0})", ContextHandle ); + Debug.Print("success! (id: {0})", ContextHandle); } public override void SwapBuffers() { @@ -87,9 +87,9 @@ namespace OpenTK.Platform.Windows { public override IntPtr GetAddress(string funcName) { IntPtr dynAddress = Wgl.wglGetProcAddress(funcName); - if( !BindingsBase.IsInvalidAddress( dynAddress ) ) + if (!BindingsBase.IsInvalidAddress(dynAddress)) return dynAddress; - return API.GetProcAddress( opengl32Handle, funcName ); + return API.GetProcAddress(opengl32Handle, funcName); } diff --git a/OpenTK/Platform/Windows/WinWindow.cs b/OpenTK/Platform/Windows/WinWindow.cs index 272d3eb72..69a9136d8 100644 --- a/OpenTK/Platform/Windows/WinWindow.cs +++ b/OpenTK/Platform/Windows/WinWindow.cs @@ -33,7 +33,7 @@ using System.Threading; using OpenTK.Input; namespace OpenTK.Platform.Windows { - internal sealed class WinWindow : INativeWindow { + public sealed class WinWindow : INativeWindow { const ExtendedWindowStyle ParentStyleEx = ExtendedWindowStyle.WindowEdge | ExtendedWindowStyle.ApplicationWindow; readonly IntPtr Instance = Marshal.GetHINSTANCE(typeof(WinWindow).Module); readonly IntPtr ClassName = Marshal.StringToHGlobalAuto("CS_WindowClass"); @@ -235,10 +235,10 @@ namespace OpenTK.Platform.Windows { // The behavior of this key is very strange. Unlike Control and Alt, there is no extended bit // to distinguish between left and right keys. Moreover, pressing both keys and releasing one // may result in both keys being held down (but not always). - bool lShiftDown = (API.GetKeyState( (int)VirtualKeys.LSHIFT ) >> 15) == 1; - bool rShiftDown = (API.GetKeyState( (int)VirtualKeys.RSHIFT ) >> 15) == 1; + bool lShiftDown = (API.GetKeyState((int)VirtualKeys.LSHIFT) >> 15) == 1; + bool rShiftDown = (API.GetKeyState((int)VirtualKeys.RSHIFT) >> 15) == 1; - if( !pressed || lShiftDown != rShiftDown ) { + if (!pressed || lShiftDown != rShiftDown) { Keyboard.Set(Key.ShiftLeft, lShiftDown); Keyboard.Set(Key.ShiftRight, rShiftDown); } @@ -379,7 +379,7 @@ namespace OpenTK.Platform.Windows { } } - void SetHiddenBorder( bool hidden ) { + void SetHiddenBorder(bool hidden) { suppress_resize++; HiddenBorder = hidden; ProcessEvents(); @@ -421,7 +421,7 @@ namespace OpenTK.Platform.Windows { return ""; } - public override unsafe void SetClipboardText( string value ) { + public override unsafe void SetClipboardText(string value) { UIntPtr dstSize = (UIntPtr)((value.Length + 1) * Marshal.SystemDefaultCharSize); // retry up to 10 times for (int i = 0; i < 10; i++) { @@ -504,8 +504,8 @@ namespace OpenTK.Platform.Windows { icon = value; if (WinHandle != IntPtr.Zero) { - //Icon small = new Icon( value, 16, 16 ); - //GC.KeepAlive( small ); + //Icon small = new Icon(value, 16, 16); + //GC.KeepAlive(small); API.SendMessage(WinHandle, WindowMessage.SETICON, (IntPtr)0, icon == null ? IntPtr.Zero : value.Handle); API.SendMessage(WinHandle, WindowMessage.SETICON, (IntPtr)1, icon == null ? IntPtr.Zero : value.Handle); } @@ -573,19 +573,19 @@ namespace OpenTK.Platform.Windows { // Reset state to avoid strange side-effects from maximized/minimized windows. ResetWindowState(); previous_bounds = Bounds; - SetHiddenBorder( true ); + SetHiddenBorder(true); command = ShowWindowCommand.MAXIMIZE; API.SetForegroundWindow(WinHandle); break; } - if( command != 0 ) + if (command != 0) API.ShowWindow(WinHandle, command); // Restore previous window border or apply pending border change when leaving fullscreen mode. - if( exiting_fullscreen ) - SetHiddenBorder( false ); + if (exiting_fullscreen) + SetHiddenBorder(false); // Restore previous window size/location if necessary if (command == ShowWindowCommand.RESTORE && previous_bounds != Rectangle.Empty) { @@ -598,7 +598,7 @@ namespace OpenTK.Platform.Windows { bool hiddenBorder; bool HiddenBorder { set { - if( hiddenBorder == value ) return; + if (hiddenBorder == value) return; // We wish to avoid making an invisible window visible just to change the border. // However, it's a good idea to make a visible window invisible temporarily, to @@ -613,11 +613,11 @@ namespace OpenTK.Platform.Windows { style |= (value ? WindowStyle.Popup : WindowStyle.OverlappedWindow); // Make sure client size doesn't change when changing the border style. - Win32Rectangle rect = Win32Rectangle.From( bounds ); - API.AdjustWindowRectEx( ref rect, style, false, ParentStyleEx ); + Win32Rectangle rect = Win32Rectangle.From(bounds); + API.AdjustWindowRectEx(ref rect, style, false, ParentStyleEx); // This avoids leaving garbage on the background window. - if( was_visible ) + if (was_visible) Visible = false; API.SetWindowLong(WinHandle, GetWindowLongOffsets.STYLE, (int)style); @@ -628,7 +628,7 @@ namespace OpenTK.Platform.Windows { // Force window to redraw update its borders, but only if it's // already visible (invisible windows will change borders when // they become visible, so no need to make them visiable prematurely). - if ( was_visible ) + if (was_visible) Visible = true; WindowState = state; } @@ -654,22 +654,22 @@ namespace OpenTK.Platform.Windows { MSG msg; public override void ProcessEvents() { - while( API.PeekMessage(ref msg, IntPtr.Zero, 0, 0, 1) ) { + while (API.PeekMessage(ref msg, IntPtr.Zero, 0, 0, 1)) { API.TranslateMessage(ref msg); API.DispatchMessage(ref msg); } IntPtr foreground = API.GetForegroundWindow(); - if( foreground != IntPtr.Zero ) + if (foreground != IntPtr.Zero) focused = foreground == WinHandle; } public override Point DesktopCursorPos { get { - POINT pos = default( POINT ); - API.GetCursorPos( ref pos ); - return new Point( pos.X, pos.Y ); + POINT pos = default(POINT); + API.GetCursorPos(ref pos); + return new Point(pos.X, pos.Y); } - set { API.SetCursorPos( value.X, value.Y ); } + set { API.SetCursorPos(value.X, value.Y); } } bool cursorVisible = true; @@ -677,7 +677,7 @@ namespace OpenTK.Platform.Windows { get { return cursorVisible; } set { cursorVisible = value; - API.ShowCursor( value ? 1 : 0 ); + API.ShowCursor(value ? 1 : 0); } } diff --git a/OpenTK/Platform/X11/API.cs b/OpenTK/Platform/X11/API.cs index bd8cc229f..6d0176b8d 100644 --- a/OpenTK/Platform/X11/API.cs +++ b/OpenTK/Platform/X11/API.cs @@ -23,193 +23,164 @@ using KeyCode = System.Byte; // Or maybe ushort? namespace OpenTK.Platform.X11 { + [SuppressUnmanagedCodeSecurity] public static class API { - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static IntPtr XOpenDisplay(IntPtr display); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XCloseDisplay(IntPtr display); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public 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, ref XSetWindowAttributes attributes); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] + public extern static int XDestroyWindow(IntPtr display, IntPtr window); + + [DllImport("libX11")] public extern static int XMapWindow(IntPtr display, IntPtr window); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XUnmapWindow(IntPtr display, IntPtr window); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static IntPtr XRootWindow(IntPtr display, int screen_number); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static Bool XCheckWindowEvent(Display display, Window w, EventMask event_mask, ref XEvent event_return); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - public extern static Bool XCheckTypedWindowEvent(Display display, Window w, XEventName event_type, ref XEvent event_return); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - public extern static int XDestroyWindow(IntPtr display, IntPtr window); + [DllImport("libX11")] + public extern static Bool XCheckTypedWindowEvent(Display display, Window w, XEventName event_type, ref XEvent event_return); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XMoveResizeWindow(IntPtr display, IntPtr window, int x, int y, int width, int height); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - public extern static int XMoveWindow(IntPtr display, IntPtr w, int x, int y); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] + public extern static int XMoveWindow(IntPtr display, IntPtr w, int x, int y); + [DllImport("libX11")] public extern static int XResizeWindow(IntPtr display, IntPtr window, int width, int height); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XFlush(IntPtr display); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XStoreName(IntPtr display, IntPtr window, string window_name); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XFetchName(IntPtr display, IntPtr window, ref IntPtr window_name); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XSendEvent(IntPtr display, IntPtr window, bool propagate, IntPtr event_mask, ref XEvent send_event); - public static int XSendEvent(IntPtr display, IntPtr window, bool propagate, EventMask event_mask, ref XEvent send_event) { return XSendEvent(display, window, propagate, new IntPtr((int)event_mask), ref send_event); } - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - public extern static bool XQueryPointer(IntPtr display, IntPtr window, out IntPtr root, out IntPtr child, out int root_x, out int root_y, out int win_x, out int win_y, out int keys_buttons); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - 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")] + public extern static bool XQueryPointer(IntPtr display, IntPtr window, out IntPtr root, out IntPtr child, + out int root_x, out int root_y, out int win_x, out int win_y, out int keys_buttons); + [DllImport("libX11")] + 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"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XFree(IntPtr data); + [DllImport("libX11")] + public static extern void XSync(Display display, bool discard); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XRaiseWindow(IntPtr display, IntPtr window); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static IntPtr XInternAtom(IntPtr display, string atom_name, bool only_if_exists); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XSetWMProtocols(IntPtr display, IntPtr window, IntPtr[] protocols, int count); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static bool XTranslateCoordinates(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, out int intdest_x_return, out int dest_y_return, out IntPtr child_return); // Colormaps - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XDefaultDepth(IntPtr display, int screen_number); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XDefaultScreen(IntPtr display); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - public extern static int XSetTransientForHint(IntPtr display, IntPtr window, IntPtr prop_window); + [DllImport("libX11")] + public static extern IntPtr XDefaultRootWindow(IntPtr display); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr[] data, int nelements); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr data, int nelements); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] + public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr data, int nelements); + [DllImport("libX11")] public extern static int XDeleteProperty(IntPtr display, IntPtr window, IntPtr property); + [DllImport("libX11")] + public extern static int XGetWindowProperty(IntPtr display, IntPtr window, IntPtr atom, IntPtr long_offset, IntPtr long_length, bool delete, IntPtr req_type, out IntPtr actual_type, out int actual_format, out IntPtr nitems, out IntPtr bytes_after, ref IntPtr prop); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XDefineCursor(IntPtr display, IntPtr window, IntPtr cursor); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XUndefineCursor(IntPtr display, IntPtr window); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XFreeCursor(IntPtr display, IntPtr cursor); // Drawing - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static IntPtr XCreateGC(IntPtr display, IntPtr window, IntPtr valuemask, IntPtr values); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XFreeGC(IntPtr display, IntPtr gc); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - public extern static int XGetWindowProperty(IntPtr display, IntPtr window, IntPtr atom, IntPtr long_offset, IntPtr long_length, bool delete, IntPtr req_type, out IntPtr actual_type, out int actual_format, out IntPtr nitems, out IntPtr bytes_after, ref IntPtr prop); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XIconifyWindow(IntPtr display, IntPtr window, int screen_number); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static IntPtr XCreatePixmapFromBitmapData(IntPtr display, IntPtr drawable, byte[] data, int width, int height, IntPtr fg, IntPtr bg, int depth); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static IntPtr XCreatePixmap(IntPtr display, IntPtr d, int width, int height, int depth); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - public extern static IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask, ref XColor foregroundCol, ref XColor backgroundCol, int x_hot, int y_hot); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] + public extern static IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask, + ref XColor foregroundCol, ref XColor backgroundCol, int x_hot, int y_hot); + [DllImport("libX11")] public extern static IntPtr XFreePixmap(IntPtr display, IntPtr pixmap); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XGetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints, out IntPtr supplied_return); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static void XSetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern IntPtr XGetWMHints(Display display, Window w); // returns XWMHints* - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern void XSetWMHints(Display display, Window w, ref XWMHints wmhints); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern IntPtr XAllocWMHints(); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + + [DllImport("libX11")] public extern static bool XkbSetDetectableAutoRepeat(IntPtr display, bool detectable, out bool supported); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern IntPtr XCreateColormap(Display display, Window window, IntPtr visual, int alloc); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - public static extern Status XGetTransientForHint(Display display, Window w, out Window prop_window_return); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - public static extern void XSync(Display display, bool discard); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - public static extern IntPtr XDefaultRootWindow(IntPtr display); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern int XBitmapBitOrder(Display display); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern IntPtr XCreateImage(Display display, IntPtr visual, uint depth, ImageFormat format, int offset, IntPtr data, int width, int height, int bitmap_pad, int bytes_per_line); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern void XPutImage(Display display, IntPtr drawable, IntPtr gc, IntPtr image, int src_x, int src_y, int dest_x, int dest_y, int width, int height); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern int XLookupString(ref XKeyEvent event_struct, [Out] byte[] buffer_return, int bytes_buffer, [Out] KeySym[] keysym_return, IntPtr status_in_out); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern int XRefreshKeyboardMapping(ref XMappingEvent event_map); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static IntPtr XGetSelectionOwner(IntPtr display, IntPtr selection); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XConvertSelection(IntPtr display, IntPtr selection, IntPtr target, IntPtr property, IntPtr requestor, IntPtr time); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public extern static int XSetSelectionOwner(IntPtr display, IntPtr selection, IntPtr owner, IntPtr time); static readonly IntPtr CopyFromParent = IntPtr.Zero; - internal static void SendNetWMMessage(X11Window window, IntPtr message_type, IntPtr l0, IntPtr l1, IntPtr l2) - { + internal static void SendNetWMMessage(X11Window window, IntPtr message_type, IntPtr l0, IntPtr l1, IntPtr l2) { XEvent xev = new XEvent(); xev.ClientMessageEvent.type = XEventName.ClientMessage; xev.ClientMessageEvent.send_event = true; @@ -224,8 +195,7 @@ namespace OpenTK.Platform.X11 { EventMask.SubstructureRedirectMask | EventMask.SubstructureNotifyMask, ref xev); } - internal static IntPtr CreatePixmapFromImage(Display display, System.Drawing.Bitmap image) - { + internal static IntPtr CreatePixmapFromImage(Display display, System.Drawing.Bitmap image) { int width = image.Width, height = image.Height; System.Drawing.Imaging.BitmapData data = image.LockBits(new System.Drawing.Rectangle(0, 0, width, height), @@ -246,19 +216,16 @@ namespace OpenTK.Platform.X11 { return pixmap; } - public static IntPtr CreateMaskFromImage(Display display, System.Drawing.Bitmap image) - { + public static IntPtr CreateMaskFromImage(Display display, System.Drawing.Bitmap image) { int width = image.Width; int height = image.Height; int stride = (width + 7) >> 3; byte[] mask = new byte[stride * height]; bool msbfirst = (XBitmapBitOrder(display) == 1); // 1 = MSBFirst - for (int y = 0; y < height; ++y) - { - for (int x = 0; x < width; ++x) - { - byte bit = (byte) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + byte bit = (byte)(1 << (msbfirst ? (7 - (x & 7)) : (x & 7))); int offset = y * stride + (x >> 3); if (image.GetPixel(x, y).A >= 128) @@ -270,80 +237,25 @@ namespace OpenTK.Platform.X11 { mask, width, height, new IntPtr(1), IntPtr.Zero, 1); } - const string XrandrLibrary = "libXrandr.so.2"; + const string Xrandr = "libXrandr.so.2"; - [DllImport(XrandrLibrary)] + [DllImport(Xrandr)] public static extern XRRScreenConfiguration XRRGetScreenInfo(Display dpy, Drawable draw); - - [DllImport(XrandrLibrary)] + [DllImport(Xrandr)] public static extern void XRRFreeScreenConfigInfo(XRRScreenConfiguration config); - [DllImport(XrandrLibrary)] - public static extern Status XRRSetScreenConfig(Display dpy, XRRScreenConfiguration config, - Drawable draw, int size_index, ref ushort rotation, Time timestamp); - - [DllImport(XrandrLibrary)] - public static extern Status XRRSetScreenConfigAndRate(Display dpy, XRRScreenConfiguration config, - Drawable draw, int size_index, ushort rotation, short rate, Time timestamp); - - [DllImport(XrandrLibrary)] + [DllImport(Xrandr)] public static extern ushort XRRConfigCurrentConfiguration(XRRScreenConfiguration config, out ushort rotation); - - [DllImport(XrandrLibrary)] + [DllImport(Xrandr)] public static extern short XRRConfigCurrentRate(XRRScreenConfiguration config); - [DllImport(XrandrLibrary)] - public static extern int XRRRootToScreen(Display dpy, Window root); - // the following are always safe to call, even if RandR is not implemented on a screen - [DllImport(XrandrLibrary)] - unsafe static extern XRRScreenSize* XRRSizes(Display dpy, int screen, int* nsizes); + [DllImport(Xrandr)] + public unsafe static extern XRRScreenSize* XRRSizes(Display dpy, int screen, int* nsizes); - public unsafe static XRRScreenSize[] XRRSizes(Display dpy, int screen) { - int count; - XRRScreenSize* data = XRRSizes(dpy, screen, &count); - if (count == 0) return null; - - XRRScreenSize[] sizes = new XRRScreenSize[count]; - for (int i = 0; i < count; i++) - sizes[i] = *data++; - return sizes; - } - - [DllImport(XrandrLibrary)] - unsafe static extern short* XRRRates(Display dpy, int screen, int size_index, int* nrates); - - public unsafe static short[] XRRRates(Display dpy, int screen, int size_index) { - int count; - short* data = XRRRates(dpy, screen, size_index, &count); - if (count == 0) return null; - - short[] rates = new short[count]; - for (int i = 0; i < count; i++) - rates[i] = *data++; - return rates; - } - - [DllImport(XrandrLibrary)] - public static extern Time XRRTimes(Display dpy, int screen, out Time config_timestamp); - - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern int XScreenCount(Display display); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] - unsafe static extern int* XListDepths(Display display, int screen_number, int* count_return); - - public unsafe static int[] XListDepths(Display display, int screen_number) { - int count; - int* data = XListDepths(display, screen_number, &count); - if (count == 0) return null; - - int[] depths = new int[count]; - for (int i = 0; i < count; i++) - depths[i] = *data++; - return depths; - } - public static Display DefaultDisplay; public static int DefaultScreen; public static IntPtr RootWindow; @@ -369,17 +281,17 @@ namespace OpenTK.Platform.X11 { } } - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern KeySym XGetKeyboardMapping(Display display, KeyCode first_keycode, int keycode_count, ref int keysyms_per_keycode_return); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern void XDisplayKeycodes(Display display, ref int min_keycodes_return, ref int max_keycodes_return); - [DllImport("libX11"), SuppressUnmanagedCodeSecurity] + [DllImport("libX11")] public static extern KeySym XLookupKeysym(ref XKeyEvent key_event, int index); } - + [StructLayout(LayoutKind.Sequential)] public struct XVisualInfo { public IntPtr Visual; diff --git a/OpenTK/Platform/X11/Glx.cs b/OpenTK/Platform/X11/Glx.cs index b1e291b9a..9815ab1ab 100644 --- a/OpenTK/Platform/X11/Glx.cs +++ b/OpenTK/Platform/X11/Glx.cs @@ -50,6 +50,7 @@ namespace OpenTK.Platform.X11 #endregion + [SuppressUnmanagedCodeSecurity] class Glx : BindingsBase { const string Library = "libGL.so.1"; @@ -62,45 +63,45 @@ namespace OpenTK.Platform.X11 } internal void LoadEntryPoints() { - LoadDelegate( "glXSwapIntervalSGI", out glXSwapIntervalSGI ); + LoadDelegate("glXSwapIntervalSGI", out glXSwapIntervalSGI); } - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public static extern bool glXIsDirect(IntPtr dpy, IntPtr context); - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public static extern IntPtr glXCreateContext(IntPtr dpy, ref XVisualInfo vis, IntPtr shareList, bool direct); - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public static extern void glXDestroyContext(IntPtr dpy, IntPtr context); - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public static extern IntPtr glXGetCurrentContext(); - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public static extern bool glXMakeCurrent(IntPtr display, IntPtr drawable, IntPtr context); - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public static extern void glXSwapBuffers(IntPtr display, IntPtr drawable); - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public static extern IntPtr glXGetProcAddress([MarshalAs(UnmanagedType.LPTStr)] string procName); - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public static extern int glXGetConfig(IntPtr dpy, ref XVisualInfo vis, GLXAttribute attrib, out int value); - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public static extern IntPtr glXChooseVisual(IntPtr dpy, int screen, int[] attriblist); // Returns an array of GLXFBConfig structures. - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public unsafe extern static IntPtr* glXChooseFBConfig(IntPtr dpy, int screen, int[] attriblist, out int fbount); // Returns a pointer to an XVisualInfo structure. - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public unsafe extern static IntPtr glXGetVisualFromFBConfig(IntPtr dpy, IntPtr fbconfig); - [SuppressUnmanagedCodeSecurity, DllImport( Library )] + [DllImport(Library)] public extern static bool glXQueryVersion(IntPtr dpy, ref int major, ref int minor); [SuppressUnmanagedCodeSecurity] diff --git a/OpenTK/Platform/X11/X11DisplayDevice.cs b/OpenTK/Platform/X11/X11DisplayDevice.cs index d68624e66..f0fbd3290 100644 --- a/OpenTK/Platform/X11/X11DisplayDevice.cs +++ b/OpenTK/Platform/X11/X11DisplayDevice.cs @@ -75,24 +75,24 @@ namespace OpenTK.Platform.X11 { return true; } - static bool QueryXRandR(List devices) { + unsafe static bool QueryXRandR(List devices) { // Get available resolutions. Then, for each resolution get all available rates. foreach (DisplayDevice dev in devices) { - int screen = (int)dev.Metadata; - XRRScreenSize[] sizes = API.XRRSizes(API.DefaultDisplay, screen); - if (sizes == null) + int screen = (int)dev.Metadata, count = 0; + XRRScreenSize* sizes = API.XRRSizes(API.DefaultDisplay, screen, &count); + if (count == 0) throw new NotSupportedException("XRandR extensions not available."); IntPtr screenConfig = API.XRRGetScreenInfo(API.DefaultDisplay, API.XRootWindow(API.DefaultDisplay, screen)); ushort curRotation; - int curSizesIndex = API.XRRConfigCurrentConfiguration(screenConfig, out curRotation); + int idx = API.XRRConfigCurrentConfiguration(screenConfig, out curRotation); int curRefreshRate = API.XRRConfigCurrentRate(screenConfig); int curDepth = API.XDefaultDepth(API.DefaultDisplay, screen); API.XRRFreeScreenConfigInfo(screenConfig); if (dev.Bounds == Rectangle.Empty) - dev.Bounds = new Rectangle(0, 0, sizes[curSizesIndex].Width, sizes[curSizesIndex].Height); + dev.Bounds = new Rectangle(0, 0, sizes[idx].Width, sizes[idx].Height); dev.BitsPerPixel = curDepth; dev.RefreshRate = curRefreshRate; } @@ -121,7 +121,7 @@ namespace OpenTK.Platform.X11 { XineramaScreenInfo* ptr = (XineramaScreenInfo*)screen_ptr; XineramaScreenInfo[] screens = new XineramaScreenInfo[count]; - for( int i = 0; i < screens.Length; i++ ) { + for(int i = 0; i < screens.Length; i++) { screens[i] = *ptr++; } return screens; diff --git a/OpenTK/Platform/X11/X11GLContext.cs b/OpenTK/Platform/X11/X11GLContext.cs index 63926e80a..48878bd69 100644 --- a/OpenTK/Platform/X11/X11GLContext.cs +++ b/OpenTK/Platform/X11/X11GLContext.cs @@ -16,10 +16,10 @@ namespace OpenTK.Platform.X11 { int vsync_interval; public X11GLContext(GraphicsMode mode, X11Window window) { - Debug.Print( "Creating X11GLContext context: " ); + Debug.Print("Creating X11GLContext context: "); cur = window; XVisualInfo info = cur.VisualInfo; - Mode = GetGraphicsMode( info ); + Mode = GetGraphicsMode(info); // Cannot pass a Property by reference. IntPtr display = API.DefaultDisplay; @@ -111,65 +111,65 @@ namespace OpenTK.Platform.X11 { ContextHandle = IntPtr.Zero; } - internal static GraphicsMode SelectGraphicsMode( GraphicsMode template, out XVisualInfo info ) { - int[] attribs = GetVisualAttribs( template.ColorFormat, template.Depth, template.Stencil, template.Buffers ); - IntPtr visual = SelectVisual( attribs ); - if( visual == IntPtr.Zero ) - throw new GraphicsModeException( "Requested GraphicsMode not available." ); + internal static GraphicsMode SelectGraphicsMode(GraphicsMode template, out XVisualInfo info) { + int[] attribs = GetVisualAttribs(template.ColorFormat, template.Depth, template.Stencil, template.Buffers); + IntPtr visual = SelectVisual(attribs); + if (visual == IntPtr.Zero) + throw new GraphicsModeException("Requested GraphicsMode not available."); - info = (XVisualInfo)Marshal.PtrToStructure( visual, typeof( XVisualInfo ) ); - API.XFree( visual ); - return GetGraphicsMode( info ); + info = (XVisualInfo)Marshal.PtrToStructure(visual, typeof(XVisualInfo)); + API.XFree(visual); + return GetGraphicsMode(info); } - internal static GraphicsMode GetGraphicsMode( XVisualInfo info ) { + internal static GraphicsMode GetGraphicsMode(XVisualInfo info) { // See what we *really* got: int r, g, b, a, depth, stencil, buffers; IntPtr display = API.DefaultDisplay; - Glx.glXGetConfig( display, ref info, GLXAttribute.ALPHA_SIZE, out a ); - Glx.glXGetConfig( display, ref info, GLXAttribute.RED_SIZE, out r ); - Glx.glXGetConfig( display, ref info, GLXAttribute.GREEN_SIZE, out g ); - Glx.glXGetConfig( display, ref info, GLXAttribute.BLUE_SIZE, out b ); - Glx.glXGetConfig( display, ref info, GLXAttribute.DEPTH_SIZE, out depth ); - Glx.glXGetConfig( display, ref info, GLXAttribute.STENCIL_SIZE, out stencil ); - Glx.glXGetConfig( display, ref info, GLXAttribute.DOUBLEBUFFER, out buffers ); + Glx.glXGetConfig(display, ref info, GLXAttribute.ALPHA_SIZE, out a); + Glx.glXGetConfig(display, ref info, GLXAttribute.RED_SIZE, out r); + Glx.glXGetConfig(display, ref info, GLXAttribute.GREEN_SIZE, out g); + Glx.glXGetConfig(display, ref info, GLXAttribute.BLUE_SIZE, out b); + Glx.glXGetConfig(display, ref info, GLXAttribute.DEPTH_SIZE, out depth); + Glx.glXGetConfig(display, ref info, GLXAttribute.STENCIL_SIZE, out stencil); + Glx.glXGetConfig(display, ref info, GLXAttribute.DOUBLEBUFFER, out buffers); ++buffers; // the above lines returns 0 - false and 1 - true. - return new GraphicsMode( new ColorFormat(r, g, b, a), depth, stencil, buffers ); + return new GraphicsMode(new ColorFormat(r, g, b, a), depth, stencil, buffers); } // See http://www-01.ibm.com/support/knowledgecenter/ssw_aix_61/com.ibm.aix.opengl/doc/openglrf/glXChooseFBConfig.htm%23glxchoosefbconfig // See http://www-01.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.opengl/doc/openglrf/glXChooseVisual.htm%23b5c84be452rree // for the attribute declarations. Note that the attributes are different than those used in Glx.ChooseVisual. - static unsafe IntPtr SelectVisual( int[] visualAttribs ) { + static unsafe IntPtr SelectVisual(int[] visualAttribs) { int major = 0, minor = 0; - if( !Glx.glXQueryVersion( API.DefaultDisplay, ref major, ref minor ) ) - throw new InvalidOperationException( "glXQueryVersion failed, potentially corrupt OpenGL driver" ); - int screen = API.XDefaultScreen( API.DefaultDisplay ); + if (!Glx.glXQueryVersion(API.DefaultDisplay, ref major, ref minor)) + throw new InvalidOperationException("glXQueryVersion failed, potentially corrupt OpenGL driver"); + int screen = API.XDefaultScreen(API.DefaultDisplay); - if( major >= 1 && minor >= 3 ) { - Debug.Print( "Getting FB config." ); + if (major >= 1 && minor >= 3) { + Debug.Print("Getting FB config."); int fbcount; // Note that ChooseFBConfig returns an array of GLXFBConfig opaque structures (i.e. mapped to IntPtrs). - IntPtr* fbconfigs = Glx.glXChooseFBConfig( API.DefaultDisplay, screen, visualAttribs, out fbcount ); - if( fbcount > 0 && fbconfigs != null ) { + IntPtr* fbconfigs = Glx.glXChooseFBConfig(API.DefaultDisplay, screen, visualAttribs, out fbcount); + if (fbcount > 0 && fbconfigs != null) { // We want to use the first GLXFBConfig from the fbconfigs array (the first one is the best match). - IntPtr visual = Glx.glXGetVisualFromFBConfig( API.DefaultDisplay, *fbconfigs ); - API.XFree( (IntPtr)fbconfigs ); + IntPtr visual = Glx.glXGetVisualFromFBConfig(API.DefaultDisplay, *fbconfigs); + API.XFree((IntPtr)fbconfigs); return visual; } } - Debug.Print( "Falling back to glXChooseVisual." ); - return Glx.glXChooseVisual( API.DefaultDisplay, screen, visualAttribs ); + Debug.Print("Falling back to glXChooseVisual."); + return Glx.glXChooseVisual(API.DefaultDisplay, screen, visualAttribs); } - static int[] GetVisualAttribs( ColorFormat color, int depth, int stencil, int buffers ) { + static int[] GetVisualAttribs(ColorFormat color, int depth, int stencil, int buffers) { int[] attribs = new int[16]; int index = 0; Debug.Print("Bits per pixel: {0}", color.BitsPerPixel); Debug.Print("Depth: {0}", depth); - if( !color.IsIndexed ) + if (!color.IsIndexed) attribs[index++] = (int)GLXAttribute.RGBA; attribs[index++] = (int)GLXAttribute.RED_SIZE; attribs[index++] = color.Red; @@ -180,15 +180,15 @@ namespace OpenTK.Platform.X11 { attribs[index++] = (int)GLXAttribute.ALPHA_SIZE; attribs[index++] = color.Alpha; - if( depth > 0 ) { + if (depth > 0) { attribs[index++] = (int)GLXAttribute.DEPTH_SIZE; attribs[index++] = depth; } - if( stencil > 0 ) { + if (stencil > 0) { attribs[index++] = (int)GLXAttribute.STENCIL_SIZE; attribs[index++] = stencil; } - if( buffers > 1 ) + if (buffers > 1) attribs[index++] = (int)GLXAttribute.DOUBLEBUFFER; attribs[index++] = 0; diff --git a/OpenTK/Platform/X11/X11Window.cs b/OpenTK/Platform/X11/X11Window.cs index e5c3d16b7..269c6a80b 100644 --- a/OpenTK/Platform/X11/X11Window.cs +++ b/OpenTK/Platform/X11/X11Window.cs @@ -87,7 +87,7 @@ namespace OpenTK.Platform.X11 { RegisterAtoms(); XVisualInfo info = new XVisualInfo(); - mode = X11GLContext.SelectGraphicsMode( mode, out info ); + mode = X11GLContext.SelectGraphicsMode(mode, out info); VisualInfo = info; // Create a window on this display using the visual above Debug.Print("Opening render window... "); @@ -337,7 +337,7 @@ namespace OpenTK.Platform.X11 { break; case XEventName.KeyPress: - ToggleKey( ref e.KeyEvent, true ); + ToggleKey(ref e.KeyEvent, true); int status = API.XLookupString(ref e.KeyEvent, ascii, ascii.Length, null, IntPtr.Zero); Encoding.Default.GetChars(ascii, 0, status, chars, 0); @@ -351,7 +351,7 @@ namespace OpenTK.Platform.X11 { case XEventName.KeyRelease: // Todo: raise KeyPress event. Use code from // http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/X11Keyboard.cs?view=markup - ToggleKey( ref e.KeyEvent, false ); + ToggleKey(ref e.KeyEvent, false); break; case XEventName.ButtonPress: @@ -691,12 +691,12 @@ namespace OpenTK.Platform.X11 { get { IntPtr root, child; int rootX, rootY, childX, childY, mask; - API.XQueryPointer( API.DefaultDisplay, API.RootWindow, out root, out child, out rootX, out rootY, out childX, out childY, out mask ); - return new Point( rootX, rootY ); + API.XQueryPointer(API.DefaultDisplay, API.RootWindow, out root, out child, out rootX, out rootY, out childX, out childY, out mask); + return new Point(rootX, rootY); } set { - API.XWarpPointer( API.DefaultDisplay, IntPtr.Zero, API.RootWindow, 0, 0, 0, 0, value.X, value.Y ); - API.XFlush( API.DefaultDisplay ); // TODO: not sure if XFlush call is necessary + API.XWarpPointer(API.DefaultDisplay, IntPtr.Zero, API.RootWindow, 0, 0, 0, 0, value.X, value.Y); + API.XFlush(API.DefaultDisplay); // TODO: not sure if XFlush call is necessary } } @@ -705,22 +705,22 @@ namespace OpenTK.Platform.X11 { get { return cursorVisible; } set { cursorVisible = value; - if( value ) { - API.XUndefineCursor( API.DefaultDisplay, WinHandle ); + if (value) { + API.XUndefineCursor(API.DefaultDisplay, WinHandle); } else { - if( blankCursor == IntPtr.Zero ) + if (blankCursor == IntPtr.Zero) MakeBlankCursor(); - API.XDefineCursor( API.DefaultDisplay, WinHandle, blankCursor ); + API.XDefineCursor(API.DefaultDisplay, WinHandle, blankCursor); } } } IntPtr blankCursor; void MakeBlankCursor() { - XColor color = default( XColor ); - IntPtr pixmap = API.XCreatePixmap( API.DefaultDisplay, API.RootWindow, 1, 1, 1 ); - blankCursor = API.XCreatePixmapCursor( API.DefaultDisplay, pixmap, pixmap, ref color, ref color, 0, 0 ); - API.XFreePixmap( API.DefaultDisplay, pixmap ); + XColor color = default(XColor); + IntPtr pixmap = API.XCreatePixmap(API.DefaultDisplay, API.RootWindow, 1, 1, 1); + blankCursor = API.XCreatePixmapCursor(API.DefaultDisplay, pixmap, pixmap, ref color, ref color, 0, 0); + API.XFreePixmap(API.DefaultDisplay, pixmap); } /// Returns true if a render window/context exists. @@ -762,14 +762,14 @@ namespace OpenTK.Platform.X11 { int ox, oy; IntPtr child; API.XTranslateCoordinates(API.DefaultDisplay, API.RootWindow, WinHandle, point.X, point.Y, out ox, out oy, out child); - return new Point( ox, oy ); + return new Point(ox, oy); } public override Point PointToScreen(Point point) { int ox, oy; IntPtr child; API.XTranslateCoordinates(API.DefaultDisplay, WinHandle, API.RootWindow, point.X, point.Y, out ox, out oy, out child); - return new Point( ox, oy ); + return new Point(ox, oy); } protected override void Dispose(bool manuallyCalled) {