more tidy up

This commit is contained in:
UnknownShadow200 2018-07-12 19:08:22 +10:00
parent 752a038530
commit 17e434afa3
26 changed files with 747 additions and 964 deletions

View File

@ -3,7 +3,7 @@ using System;
using System.Drawing; using System.Drawing;
using ClassicalSharp; using ClassicalSharp;
using OSStatus = OpenTK.Platform.MacOS.OSStatus; using OSStatus = OpenTK.Platform.MacOS.OSStatus;
using OSX = OpenTK.Platform.MacOS.Carbon; using OSX = OpenTK.Platform.MacOS;
namespace Launcher.Drawing { namespace Launcher.Drawing {
public sealed class OSXPlatformDrawer : PlatformDrawer { public sealed class OSXPlatformDrawer : PlatformDrawer {
@ -25,7 +25,7 @@ namespace Launcher.Drawing {
IntPtr colorSpace = OSX.API.CGColorSpaceCreateDeviceRGB(); IntPtr colorSpace = OSX.API.CGColorSpaceCreateDeviceRGB();
IntPtr provider = OSX.API.CGDataProviderCreateWithData(IntPtr.Zero, scan0, size, IntPtr.Zero); IntPtr provider = OSX.API.CGDataProviderCreateWithData(IntPtr.Zero, scan0, size, IntPtr.Zero);
const uint flags = 4 | (2 << 12); 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); colorSpace, flags, provider, IntPtr.Zero, 0, 0);
IntPtr context = IntPtr.Zero; IntPtr context = IntPtr.Zero;
OSStatus err = OSX.API.QDBeginCGContext(windowPort, ref context); OSStatus err = OSX.API.QDBeginCGContext(windowPort, ref context);

View File

@ -17,7 +17,7 @@ namespace Launcher.Drawing {
} }
/// <summary> Updates the variables when the native window changes dimensions. </summary> /// <summary> Updates the variables when the native window changes dimensions. </summary>
public abstract void Resize(); public virtual void Resize() { }
/// <summary> Redraws a portion of the framebuffer to the window. </summary> /// <summary> Redraws a portion of the framebuffer to the window. </summary>
/// <remarks> r is only a hint, the entire framebuffer may still be /// <remarks> r is only a hint, the entire framebuffer may still be

View File

@ -3,34 +3,28 @@ using System;
using System.Drawing; using System.Drawing;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using OpenTK.Platform.Windows;
namespace Launcher.Drawing { namespace Launcher.Drawing {
[SuppressUnmanagedCodeSecurity]
public sealed class WinPlatformDrawer : PlatformDrawer { public sealed class WinPlatformDrawer : PlatformDrawer {
const uint SRCCOPY = 0xCC0020; 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, static extern int BitBlt(IntPtr dcDst, int dstX, int dstY, int width, int height,
IntPtr dcSrc, int srcX, int srcY, uint drawOp); IntPtr dcSrc, int srcX, int srcY, uint drawOp);
[DllImport("user32.dll"), SuppressUnmanagedCodeSecurity] [DllImport("gdi32.dll")]
static extern IntPtr GetDC(IntPtr hwnd); static extern IntPtr CreateCompatibleDC(IntPtr dc);
[DllImport("gdi32.dll")]
[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]
static extern IntPtr CreateDIBSection(IntPtr hdc, [In] ref BITMAPINFO pbmi, static extern IntPtr CreateDIBSection(IntPtr hdc, [In] ref BITMAPINFO pbmi,
uint pila, out IntPtr ppvBits, IntPtr hSection, uint dwOffset); 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)] [StructLayout(LayoutKind.Sequential)]
public struct BITMAPINFO { public struct BITMAPINFO {
public int biSize; public int biSize;
@ -47,10 +41,10 @@ namespace Launcher.Drawing {
public uint bmiColors; public uint bmiColors;
} }
IntPtr dc, srcDC, srcHB; IntPtr winDc, srcDC, srcHB;
public override void Init() { public override void Init() {
dc = GetDC(window.WinHandle); winDc = ((WinWindow)window).DeviceContext;
srcDC = CreateCompatibleDC(dc); srcDC = CreateCompatibleDC(winDc);
} }
public override Bitmap CreateFrameBuffer(int width, int height) { public override Bitmap CreateFrameBuffer(int width, int height) {
@ -70,18 +64,9 @@ namespace Launcher.Drawing {
System.Drawing.Imaging.PixelFormat.Format32bppArgb, pointer); 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) { public override void Redraw(Bitmap framebuffer, Rectangle r) {
IntPtr oldSrc = SelectObject(srcDC, srcHB); 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); SelectObject(srcDC, oldSrc);
} }
} }
@ -94,8 +79,7 @@ namespace Launcher.Drawing {
} }
public override void Resize() { public override void Resize() {
if (g != null) if (g != null) g.Dispose();
g.Dispose();
g = Graphics.FromHwnd(window.WinHandle); g = Graphics.FromHwnd(window.WinHandle);
} }

View File

@ -12,11 +12,6 @@ namespace Launcher.Drawing {
gc = API.XCreateGC(API.DefaultDisplay, window.WinHandle, IntPtr.Zero, IntPtr.Zero); 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) { public override void Redraw(Bitmap framebuffer, Rectangle r) {
X11Window x11Win = (X11Window)window; X11Window x11Win = (X11Window)window;
using (FastBitmap bmp = new FastBitmap(framebuffer, true, true)) { using (FastBitmap bmp = new FastBitmap(framebuffer, true, true)) {

View File

@ -48,8 +48,8 @@ namespace OpenTK.Graphics {
public static GraphicsMode Default { public static GraphicsMode Default {
get { get {
if (defaultMode == null) { if (defaultMode == null) {
Debug.Print( "Creating default GraphicsMode ({0}, {1}, {2}, {3}).", 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 ); defaultMode = new GraphicsMode(DisplayDevice.Primary.BitsPerPixel, 24, 0, 2);
} }
return defaultMode; return defaultMode;
} }

View File

@ -52,7 +52,7 @@ namespace OpenTK.Graphics {
public void Dispose() { public void Dispose() {
Dispose(true); Dispose(true);
GC.SuppressFinalize( this ); GC.SuppressFinalize(this);
} }
protected abstract void Dispose(bool calledManually); protected abstract void Dispose(bool calledManually);

View File

@ -50,7 +50,7 @@ namespace OpenTK {
public static readonly Vector4 One = new Vector4(1, 1, 1, 1); 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) { public Vector4(float x, float y, float z, float w) {

View File

@ -1,67 +1,67 @@
using System; using System;
namespace OpenTK { namespace OpenTK {
public static class MemUtils { public static class MemUtils {
static MemUtils() { static MemUtils() {
use64Bit = IntPtr.Size == 8; use64Bit = IntPtr.Size == 8;
} }
static bool use64Bit; static bool use64Bit;
public static unsafe void memcpy( IntPtr srcPtr, IntPtr dstPtr, int bytes ) { public static unsafe void memcpy(IntPtr srcPtr, IntPtr dstPtr, int bytes) {
byte* srcByte, dstByte; byte* srcByte, dstByte;
if( use64Bit ) { if (use64Bit) {
ulong* srcLong = (ulong*)srcPtr, dstLong = (ulong*)dstPtr; ulong* srcLong = (ulong*)srcPtr, dstLong = (ulong*)dstPtr;
while( bytes >= 8 ) { while (bytes >= 8) {
*dstLong++ = *srcLong++; *dstLong++ = *srcLong++;
bytes -= 8; bytes -= 8;
} }
srcByte = (byte*)srcLong; dstByte = (byte*)dstLong; srcByte = (byte*)srcLong; dstByte = (byte*)dstLong;
} else { } else {
uint* srcInt = (uint*)srcPtr, dstInt = (uint*)dstPtr; uint* srcInt = (uint*)srcPtr, dstInt = (uint*)dstPtr;
while( bytes >= 4 ) { while (bytes >= 4) {
*dstInt++ = *srcInt++; *dstInt++ = *srcInt++;
bytes -= 4; bytes -= 4;
} }
srcByte = (byte*)srcInt; dstByte = (byte*)dstInt; srcByte = (byte*)srcInt; dstByte = (byte*)dstInt;
} }
for( int i = 0; i < bytes; i++ ) { for(int i = 0; i < bytes; i++) {
*dstByte++ = *srcByte++; *dstByte++ = *srcByte++;
} }
} }
public static unsafe void memset( IntPtr srcPtr, byte value, int startIndex, int bytes ) { public static unsafe void memset(IntPtr srcPtr, byte value, int startIndex, int bytes) {
byte* srcByte = (byte*)srcPtr + startIndex; byte* srcByte = (byte*)srcPtr + startIndex;
// Make sure we do an aligned write/read for the bulk copy // Make sure we do an aligned write/read for the bulk copy
while( bytes > 0 && ( startIndex & 0x7 ) != 0 ) { while (bytes > 0 && (startIndex & 0x7) != 0) {
*srcByte++ = value; *srcByte++ = value;
startIndex++; startIndex++;
bytes--; bytes--;
} }
uint valueInt = (uint)( ( value << 24 ) | ( value << 16 ) | ( value << 8 ) | value ); uint valueInt = (uint)((value << 24) | (value << 16) | (value << 8) | value);
if( use64Bit ) { if (use64Bit) {
ulong valueLong = ( (ulong)valueInt << 32 ) | valueInt; ulong valueLong = ((ulong)valueInt << 32) | valueInt;
ulong* srcLong = (ulong*)srcByte; ulong* srcLong = (ulong*)srcByte;
while( bytes >= 8 ) { while (bytes >= 8) {
*srcLong++ = valueLong; *srcLong++ = valueLong;
bytes -= 8; bytes -= 8;
} }
srcByte = (byte*)srcLong; srcByte = (byte*)srcLong;
} else { } else {
uint* srcInt = (uint*)srcByte; uint* srcInt = (uint*)srcByte;
while( bytes >= 4 ) { while (bytes >= 4) {
*srcInt++ = valueInt; *srcInt++ = valueInt;
bytes -= 4; bytes -= 4;
} }
srcByte = (byte*)srcInt; srcByte = (byte*)srcInt;
} }
for( int i = 0; i < bytes; i++ ) { for(int i = 0; i < bytes; i++) {
*srcByte++ = value; *srcByte++ = value;
} }
} }
} }
} }

View File

@ -41,19 +41,19 @@ namespace OpenTK {
// Detects the underlying OS and runtime. // Detects the underlying OS and runtime.
unsafe static Configuration() { unsafe static Configuration() {
PlatformID platform = Environment.OSVersion.Platform; PlatformID platform = Environment.OSVersion.Platform;
if( platform == PlatformID.Win32NT || platform == PlatformID.Win32S || if (platform == PlatformID.Win32NT || platform == PlatformID.Win32S ||
platform == PlatformID.Win32Windows || platform == PlatformID.WinCE ) platform == PlatformID.Win32Windows || platform == PlatformID.WinCE)
RunningOnWindows = true; RunningOnWindows = true;
else if ( platform == PlatformID.Unix || platform == (PlatformID)4 ) { else if (platform == PlatformID.Unix || platform == (PlatformID)4) {
sbyte* ascii = stackalloc sbyte[8192]; sbyte* ascii = stackalloc sbyte[8192];
uname( ascii ); uname(ascii);
// Distinguish between Linux, Mac OS X and other Unix operating systems. // Distinguish between Linux, Mac OS X and other Unix operating systems.
string kernel = new String( ascii ); string kernel = new String(ascii);
if( kernel == "Linux" ) { if (kernel == "Linux") {
RunningOnLinux = RunningOnUnix = true; RunningOnLinux = RunningOnUnix = true;
} else if( kernel == "Darwin" ) { } else if (kernel == "Darwin") {
RunningOnMacOS = RunningOnUnix = true; RunningOnMacOS = RunningOnUnix = true;
} else if( !String.IsNullOrEmpty( kernel ) ) { } else if (!String.IsNullOrEmpty(kernel)) {
RunningOnUnix = true; RunningOnUnix = true;
} else { } else {
throw new PlatformNotSupportedException("Unknown platform. Please file a bug report at http://www.opentk.com/"); 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. // Detect whether X is present.
// Hack: it seems that this check will cause X to initialize itself on Mac OS X Leopard and newer. // 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. // 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; } try { RunningOnX11 = OpenTK.Platform.X11.API.DefaultDisplay != IntPtr.Zero; }
catch { } catch { }
} }
// Detect the Mono runtime (code taken from http://mono.wikia.com/wiki/Detecting_if_program_is_running_in_Mono). // 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; RunningOnMono = true;
Debug.Print("Detected configuration: {0} / {1}", Debug.Print("Detected configuration: {0} / {1}",

View File

@ -55,7 +55,7 @@ namespace OpenTK.Platform {
if (Configuration.RunningOnWindows) Default = new Windows.WinFactory(); if (Configuration.RunningOnWindows) Default = new Windows.WinFactory();
else if (Configuration.RunningOnMacOS) Default = new MacOS.MacOSFactory(); else if (Configuration.RunningOnMacOS) Default = new MacOS.MacOSFactory();
else if (Configuration.RunningOnX11) Default = new X11.X11Factory(); 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.");
} }
} }
} }

View File

@ -80,18 +80,18 @@ namespace OpenTK.Platform.MacOS {
} }
} else { } else {
aglPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attribs.ToArray()); aglPixelFormat = Agl.aglChoosePixelFormat(IntPtr.Zero, 0, attribs.ToArray());
Agl.CheckReturnValue( 0, "aglChoosePixelFormat" ); Agl.CheckReturnValue(0, "aglChoosePixelFormat");
} }
Debug.Print("Creating AGL context."); Debug.Print("Creating AGL context.");
// create the context and share it with the share reference. // create the context and share it with the share reference.
ContextHandle = Agl.aglCreateContext(aglPixelFormat, IntPtr.Zero); ContextHandle = Agl.aglCreateContext(aglPixelFormat, IntPtr.Zero);
Agl.CheckReturnValue( 0, "aglCreateContext" ); Agl.CheckReturnValue(0, "aglCreateContext");
// Free the pixel format from memory. // Free the pixel format from memory.
Agl.aglDestroyPixelFormat(aglPixelFormat); Agl.aglDestroyPixelFormat(aglPixelFormat);
Agl.CheckReturnValue( 0, "aglDestroyPixelFormat" ); Agl.CheckReturnValue(0, "aglDestroyPixelFormat");
SetDrawable(wind); SetDrawable(wind);
Update(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); //Debug.Print("Setting drawable for context {0} to window port: {1}", Handle.Handle, windowPort);
byte code = Agl.aglSetDrawable(ContextHandle, windowPort); byte code = Agl.aglSetDrawable(ContextHandle, windowPort);
Agl.CheckReturnValue( code, "aglSetDrawable" ); Agl.CheckReturnValue(code, "aglSetDrawable");
} }
public override void Update(INativeWindow window) { public override void Update(INativeWindow window) {
@ -157,9 +157,9 @@ namespace OpenTK.Platform.MacOS {
internal void UnsetFullScreen(CarbonWindow window) { internal void UnsetFullScreen(CarbonWindow window) {
Debug.Print("Unsetting AGL fullscreen."); Debug.Print("Unsetting AGL fullscreen.");
byte code = Agl.aglSetDrawable(ContextHandle, IntPtr.Zero); byte code = Agl.aglSetDrawable(ContextHandle, IntPtr.Zero);
Agl.CheckReturnValue( code, "aglSetDrawable" ); Agl.CheckReturnValue(code, "aglSetDrawable");
code = Agl.aglUpdateContext(ContextHandle); code = Agl.aglUpdateContext(ContextHandle);
Agl.CheckReturnValue( code, "aglUpdateContext" ); Agl.CheckReturnValue(code, "aglUpdateContext");
CG.CGDisplayRelease(GetQuartzDevice(window)); CG.CGDisplayRelease(GetQuartzDevice(window));
Debug.Print("Resetting drawable."); Debug.Print("Resetting drawable.");
@ -173,12 +173,12 @@ namespace OpenTK.Platform.MacOS {
public override void SwapBuffers() { public override void SwapBuffers() {
Agl.aglSwapBuffers(ContextHandle); Agl.aglSwapBuffers(ContextHandle);
Agl.CheckReturnValue( 0, "aglSwapBuffers" ); Agl.CheckReturnValue(0, "aglSwapBuffers");
} }
public override void MakeCurrent(INativeWindow window) { public override void MakeCurrent(INativeWindow window) {
byte code = Agl.aglSetCurrentContext(ContextHandle); byte code = Agl.aglSetCurrentContext(ContextHandle);
Agl.CheckReturnValue(code, "aglSetCurrentContext" ); Agl.CheckReturnValue(code, "aglSetCurrentContext");
} }
public override bool IsCurrent { public override bool IsCurrent {
@ -214,12 +214,12 @@ namespace OpenTK.Platform.MacOS {
Debug.Print("Destroying context"); Debug.Print("Destroying context");
byte code = Agl.aglDestroyContext(ContextHandle); byte code = Agl.aglDestroyContext(ContextHandle);
try { try {
Agl.CheckReturnValue(code, "aglDestroyContext" ); Agl.CheckReturnValue(code, "aglDestroyContext");
ContextHandle = IntPtr.Zero; ContextHandle = IntPtr.Zero;
Debug.Print("Context destruction completed successfully."); Debug.Print("Context destruction completed successfully.");
} catch( MacOSException ) { } catch(MacOSException) {
Debug.Print("Failed to destroy context."); Debug.Print("Failed to destroy context.");
if( disposing ) if (disposing)
throw; throw;
} }
IsDisposed = true; IsDisposed = true;

View File

@ -45,7 +45,7 @@ namespace OpenTK.Platform.MacOS.Carbon
private static void TransformProcessToForeground() private static void TransformProcessToForeground()
{ {
Carbon.ProcessSerialNumber psn = new ProcessSerialNumber(); ProcessSerialNumber psn = new ProcessSerialNumber();
Debug.Print("Setting process to be foreground application."); Debug.Print("Setting process to be foreground application.");

View File

@ -3,7 +3,8 @@ using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
namespace OpenTK.Platform.MacOS.Carbon { namespace OpenTK.Platform.MacOS {
// Core foundation services // Core foundation services
internal class CF { internal class CF {
const string appServices = "/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/ApplicationServices"; const string appServices = "/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/ApplicationServices";

View File

@ -1,102 +1,102 @@
// Created by Erik Ylvisaker on 3/17/08. // Created by Erik Ylvisaker on 3/17/08.
// Copyright 2008. All rights reserved. // Copyright 2008. All rights reserved.
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using AGLContext = System.IntPtr; using AGLContext = System.IntPtr;
using AGLDevice = System.IntPtr; using AGLDevice = System.IntPtr;
using AGLDrawable = System.IntPtr; using AGLDrawable = System.IntPtr;
using AGLPixelFormat = System.IntPtr; using AGLPixelFormat = System.IntPtr;
namespace OpenTK.Platform.MacOS { namespace OpenTK.Platform.MacOS {
public unsafe static class Agl { public unsafe static class Agl {
const string agl = "/System/Library/Frameworks/AGL.framework/Versions/Current/AGL"; const string agl = "/System/Library/Frameworks/AGL.framework/Versions/Current/AGL";
// Attribute names for aglChoosePixelFormat and aglDescribePixelFormat. // Attribute names for aglChoosePixelFormat and aglDescribePixelFormat.
internal enum PixelFormatAttribute { internal enum PixelFormatAttribute {
AGL_NONE = 0, AGL_NONE = 0,
AGL_RGBA = 4, AGL_RGBA = 4,
AGL_DOUBLEBUFFER = 5, AGL_DOUBLEBUFFER = 5,
AGL_RED_SIZE = 8, AGL_RED_SIZE = 8,
AGL_GREEN_SIZE = 9, AGL_GREEN_SIZE = 9,
AGL_BLUE_SIZE = 10, AGL_BLUE_SIZE = 10,
AGL_ALPHA_SIZE = 11, AGL_ALPHA_SIZE = 11,
AGL_DEPTH_SIZE = 12, AGL_DEPTH_SIZE = 12,
AGL_STENCIL_SIZE = 13, AGL_STENCIL_SIZE = 13,
AGL_FULLSCREEN = 54, AGL_FULLSCREEN = 54,
} }
// Integer parameter names // Integer parameter names
internal enum ParameterNames { internal enum ParameterNames {
AGL_SWAP_INTERVAL = 222, /* 0 -> Don't sync, n -> Sync every n retrace */ AGL_SWAP_INTERVAL = 222, /* 0 -> Don't sync, n -> Sync every n retrace */
} }
// Error return values from aglGetError. // Error return values from aglGetError.
internal enum AglError { internal enum AglError {
NoError = 0, /* no error */ NoError = 0, /* no error */
BadAttribute = 10000, /* invalid pixel format attribute */ BadAttribute = 10000, /* invalid pixel format attribute */
BadProperty = 10001, /* invalid renderer property */ BadProperty = 10001, /* invalid renderer property */
BadPixelFormat = 10002, /* invalid pixel format */ BadPixelFormat = 10002, /* invalid pixel format */
BadRendererInfo = 10003, /* invalid renderer info */ BadRendererInfo = 10003, /* invalid renderer info */
BadContext = 10004, /* invalid context */ BadContext = 10004, /* invalid context */
BadDrawable = 10005, /* invalid drawable */ BadDrawable = 10005, /* invalid drawable */
BadGraphicsDevice = 10006, /* invalid graphics device */ BadGraphicsDevice = 10006, /* invalid graphics device */
BadState = 10007, /* invalid context state */ BadState = 10007, /* invalid context state */
BadValue = 10008, /* invalid numerical value */ BadValue = 10008, /* invalid numerical value */
BadMatch = 10009, /* invalid share context */ BadMatch = 10009, /* invalid share context */
BadEnum = 10010, /* invalid enumerant */ BadEnum = 10010, /* invalid enumerant */
BadOffscreen = 10011, /* invalid offscreen drawable */ BadOffscreen = 10011, /* invalid offscreen drawable */
BadFullscreen = 10012, /* invalid offscreen drawable */ BadFullscreen = 10012, /* invalid offscreen drawable */
BadWindow = 10013, /* invalid window */ BadWindow = 10013, /* invalid window */
BadPointer = 10014, /* invalid pointer */ BadPointer = 10014, /* invalid pointer */
BadModule = 10015, /* invalid code module */ BadModule = 10015, /* invalid code module */
BadAlloc = 10016, /* memory allocation failure */ BadAlloc = 10016, /* memory allocation failure */
BadConnection = 10017, /* invalid CoreGraphics connection */ BadConnection = 10017, /* invalid CoreGraphics connection */
} }
// Pixel format functions // Pixel format functions
[DllImport(agl)] internal static extern AGLPixelFormat aglChoosePixelFormat(ref AGLDevice gdevs, int ndev, int[] attribs); [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 AGLPixelFormat aglChoosePixelFormat(IntPtr gdevs, int ndev, int[] attribs);
[DllImport(agl)] internal static extern void aglDestroyPixelFormat(AGLPixelFormat pix); [DllImport(agl)] internal static extern void aglDestroyPixelFormat(AGLPixelFormat pix);
// Context functions // Context functions
[DllImport(agl)] internal static extern AGLContext aglCreateContext(AGLPixelFormat pix, AGLContext share); [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 aglDestroyContext(AGLContext ctx);
[DllImport(agl)] internal static extern byte aglUpdateContext(AGLContext ctx); [DllImport(agl)] internal static extern byte aglUpdateContext(AGLContext ctx);
// Current state functions // Current state functions
[DllImport(agl)] internal static extern byte aglSetCurrentContext(AGLContext ctx); [DllImport(agl)] internal static extern byte aglSetCurrentContext(AGLContext ctx);
[DllImport(agl)] internal static extern AGLContext aglGetCurrentContext(); [DllImport(agl)] internal static extern AGLContext aglGetCurrentContext();
// Drawable Functions // Drawable Functions
[DllImport(agl)] internal static extern byte aglSetDrawable(AGLContext ctx, AGLDrawable draw); [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); [DllImport(agl)] internal static extern byte aglSetFullScreen(AGLContext ctx, int width, int height, int freq, int device);
// Virtual screen functions // Virtual screen functions
[DllImport(agl)] static extern byte aglSetVirtualScreen(AGLContext ctx, int screen); [DllImport(agl)] static extern byte aglSetVirtualScreen(AGLContext ctx, int screen);
[DllImport(agl)] static extern int aglGetVirtualScreen(AGLContext ctx); [DllImport(agl)] static extern int aglGetVirtualScreen(AGLContext ctx);
// Swap functions // Swap functions
[DllImport(agl)] internal static extern void aglSwapBuffers(AGLContext ctx); [DllImport(agl)] internal static extern void aglSwapBuffers(AGLContext ctx);
// Per context options // Per context options
[DllImport(agl)] internal static extern byte aglSetInteger(AGLContext ctx, ParameterNames pname, ref int @params); [DllImport(agl)] internal static extern byte aglSetInteger(AGLContext ctx, ParameterNames pname, ref int @params);
// Error functions // Error functions
[DllImport(agl)] internal static extern AglError aglGetError(); [DllImport(agl)] internal static extern AglError aglGetError();
[DllImport(agl)] static extern IntPtr aglErrorString(AglError code); [DllImport(agl)] static extern IntPtr aglErrorString(AglError code);
internal static void CheckReturnValue( byte code, string function ) { internal static void CheckReturnValue(byte code, string function) {
if( code != 0 ) return; if (code != 0) return;
AglError errCode = aglGetError(); AglError errCode = aglGetError();
if( errCode == AglError.NoError ) return; if (errCode == AglError.NoError) return;
string error = new String( (sbyte*)aglErrorString( errCode ) ); string error = new String((sbyte*)aglErrorString(errCode));
throw new MacOSException( (OSStatus)errCode, String.Format( throw new MacOSException((OSStatus)errCode, String.Format(
"AGL Error from function {0}: {1} {2}", "AGL Error from function {0}: {1} {2}",
function, errCode, error) ); function, errCode, error));
} }
} }
} }

View File

@ -6,28 +6,21 @@ using System.Runtime.InteropServices;
using System.Drawing; using System.Drawing;
using EventTime = System.Double; using EventTime = System.Double;
namespace OpenTK.Platform.MacOS {
namespace OpenTK.Platform.MacOS.Carbon
{
#region --- Types defined in MacTypes.h ---
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct CarbonPoint public struct CarbonPoint {
{
public short V; public short V;
public short H; public short H;
public CarbonPoint(int x, int y) public CarbonPoint(int x, int y) {
{
V = (short)x; V = (short)x;
H = (short)y; H = (short)y;
} }
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct Rect public struct Rect {
{
short top; short top;
short left; short left;
short bottom; short bottom;
@ -40,21 +33,10 @@ namespace OpenTK.Platform.MacOS.Carbon
right = (short)(_left + _width); right = (short)(_left + _width);
} }
public short X { public short X { get { return left; } }
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 Y {
get { return top; }
}
public short Width {
get { return (short)(right - left); }
}
public short Height {
get { return (short)(bottom - top); }
}
public override string ToString() { public override string ToString() {
return string.Format( return string.Format(
@ -66,26 +48,23 @@ namespace OpenTK.Platform.MacOS.Carbon
} }
} }
#endregion
#region --- Types defined in HIGeometry.h ---
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct HIPoint { public struct HIPoint {
public IntPtr xVal; public IntPtr xVal;
public IntPtr yVal; public IntPtr yVal;
public float X { public float X {
get { return GetFloat( xVal ); } get { return GetFloat(xVal); }
set { SetFloat( ref xVal, value ); } set { SetFloat(ref xVal, value); }
} }
public float Y { public float Y {
get { return GetFloat( yVal ); } get { return GetFloat(yVal); }
set { SetFloat( ref yVal, value ); } set { SetFloat(ref yVal, value); }
} }
static unsafe float GetFloat( IntPtr val ) { static unsafe float GetFloat(IntPtr val) {
if( IntPtr.Size == 8 ) { if (IntPtr.Size == 8) {
long raw = val.ToInt64(); long raw = val.ToInt64();
return (float)(*((double*)&raw)); return (float)(*((double*)&raw));
} else { } else {
@ -94,15 +73,15 @@ namespace OpenTK.Platform.MacOS.Carbon
} }
} }
static unsafe void SetFloat( ref IntPtr val, float x ) { static unsafe void SetFloat(ref IntPtr val, float x) {
if( IntPtr.Size == 8 ) { if (IntPtr.Size == 8) {
long raw = 0; long raw = 0;
*((double*)&raw) = x; *((double*)&raw) = x;
val = new IntPtr( raw ); val = new IntPtr(raw);
} else { } else {
int raw = 0; int raw = 0;
*((float*)&raw) = x; *((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) { public EventInfo(IntPtr eventRef) {
EventClass = API.GetEventClass(eventRef); EventClass = API.GetEventClass(eventRef);
EventKind = API.GetEventKind(eventRef); EventKind = API.GetEventKind(eventRef);
@ -129,10 +105,6 @@ namespace OpenTK.Platform.MacOS.Carbon
public uint EventKind; public uint EventKind;
public EventClass EventClass; public EventClass EventClass;
public override string ToString() {
return "Event: " + EventClass + ",kind: " + EventKind;
}
} }
#region --- Types defined in CarbonEvents.h --- #region --- Types defined in CarbonEvents.h ---
@ -404,35 +376,24 @@ namespace OpenTK.Platform.MacOS.Carbon
} }
#endregion #endregion
#region --- Enums from gestalt.h ---
public enum GestaltSelector public enum GestaltSelector {
{
SystemVersion = 0x73797376, // FOUR_CHAR_CODE("sysv"), /* system version*/ 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 */ 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 */ 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 */ SystemVersionBugFix = 0x73797333, // FOUR_CHAR_CODE("sys3") /* The bug fix system version number; in 10.4.17 this would be the decimal value 17 */
}; };
#endregion public enum ProcessApplicationTransformState : int {
#region --- Process Manager ---
public enum ProcessApplicationTransformState : int
{
kProcessTransformToForegroundApplication = 1, kProcessTransformToForegroundApplication = 1,
} }
public struct ProcessSerialNumber public struct ProcessSerialNumber {
{
public ulong high; public ulong high;
public ulong low; public ulong low;
} }
#endregion public enum HICoordinateSpace {
public enum HICoordinateSpace
{
_72DPIGlobal = 1, _72DPIGlobal = 1,
ScreenPixel = 2, ScreenPixel = 2,
Window = 3, Window = 3,
@ -441,7 +402,7 @@ namespace OpenTK.Platform.MacOS.Carbon
#region --- Carbon API Methods --- #region --- Carbon API Methods ---
public class API public static class API
{ {
const string carbon = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon"; const string carbon = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
@ -450,17 +411,11 @@ namespace OpenTK.Platform.MacOS.Carbon
[DllImport(carbon)] [DllImport(carbon)]
public static extern uint GetEventKind(IntPtr inEvent); public static extern uint GetEventKind(IntPtr inEvent);
#region --- Window Construction ---
[DllImport(carbon)] [DllImport(carbon)]
public static extern OSStatus CreateNewWindow(WindowClass @class, WindowAttributes attributes, ref Rect r, out IntPtr window); public static extern OSStatus CreateNewWindow(WindowClass @class, WindowAttributes attributes, ref Rect r, out IntPtr window);
[DllImport(carbon)] [DllImport(carbon)]
public static extern void DisposeWindow(IntPtr window); public static extern void DisposeWindow(IntPtr window);
#endregion
#region --- Showing / Hiding Windows ---
[DllImport(carbon)] [DllImport(carbon)]
public static extern void ShowWindow(IntPtr window); public static extern void ShowWindow(IntPtr window);
[DllImport(carbon)] [DllImport(carbon)]
@ -470,9 +425,6 @@ namespace OpenTK.Platform.MacOS.Carbon
[DllImport(carbon)] [DllImport(carbon)]
public static extern void SelectWindow(IntPtr window); public static extern void SelectWindow(IntPtr window);
#endregion
#region --- Window Boundaries ---
[DllImport(carbon)] [DllImport(carbon)]
public static extern OSStatus RepositionWindow(IntPtr window, IntPtr parentWindow, WindowPositionMethod method); public static extern OSStatus RepositionWindow(IntPtr window, IntPtr parentWindow, WindowPositionMethod method);
[DllImport(carbon)] [DllImport(carbon)]
@ -482,23 +434,15 @@ namespace OpenTK.Platform.MacOS.Carbon
[DllImport(carbon)] [DllImport(carbon)]
static extern OSStatus GetWindowBounds(IntPtr window, WindowRegionCode regionCode, out Rect globalBounds); 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; Rect retval;
OSStatus error = GetWindowBounds(window, regionCode, out retval); OSStatus error = GetWindowBounds(window, regionCode, out retval);
CheckReturn( error ); CheckReturn(error);
return retval; return retval;
} }
//[DllImport(carbon)]
//public static extern void MoveWindow(IntPtr window, short hGlobal, short vGlobal, bool front);
#endregion
#region --- Processing Events ---
[DllImport(carbon)] [DllImport(carbon)]
static extern IntPtr GetEventDispatcherTarget(); static extern IntPtr GetEventDispatcherTarget();
[DllImport(carbon,EntryPoint="ReceiveNextEvent")] [DllImport(carbon,EntryPoint="ReceiveNextEvent")]
static extern OSStatus ReceiveNextEvent(uint inNumTypes, static extern OSStatus ReceiveNextEvent(uint inNumTypes,
IntPtr inList, IntPtr inList,
@ -589,7 +533,7 @@ namespace OpenTK.Platform.MacOS.Carbon
#region --- Getting Event Parameters --- #region --- Getting Event Parameters ---
[DllImport(carbon)] [DllImport(carbon)]
static extern OSStatus CreateEvent( IntPtr inAllocator, static extern OSStatus CreateEvent(IntPtr inAllocator,
EventClass inClassID, UInt32 kind, EventTime when, EventClass inClassID, UInt32 kind, EventTime when,
EventAttributes flags, out IntPtr outEvent); EventAttributes flags, out IntPtr outEvent);
@ -697,7 +641,7 @@ namespace OpenTK.Platform.MacOS.Carbon
#region --- Event Handlers --- #region --- Event Handlers ---
[DllImport(carbon)] [DllImport(carbon)]
static extern OSStatus InstallEventHandler( IntPtr eventTargetRef, IntPtr handlerProc, static extern OSStatus InstallEventHandler(IntPtr eventTargetRef, IntPtr handlerProc,
int numtypes, EventTypeSpec[] typeList, int numtypes, EventTypeSpec[] typeList,
IntPtr userData, IntPtr handlerRef); IntPtr userData, IntPtr handlerRef);
@ -708,7 +652,7 @@ namespace OpenTK.Platform.MacOS.Carbon
OSStatus error = InstallEventHandler(windowTarget, uppHandlerProc, OSStatus error = InstallEventHandler(windowTarget, uppHandlerProc,
eventTypes.Length, eventTypes, eventTypes.Length, eventTypes,
userData, handlerRef); userData, handlerRef);
CheckReturn( error ); CheckReturn(error);
} }
public static void InstallApplicationEventHandler(IntPtr uppHandlerProc, public static void InstallApplicationEventHandler(IntPtr uppHandlerProc,
@ -717,7 +661,7 @@ namespace OpenTK.Platform.MacOS.Carbon
OSStatus error = InstallEventHandler(GetApplicationEventTarget(), uppHandlerProc, OSStatus error = InstallEventHandler(GetApplicationEventTarget(), uppHandlerProc,
eventTypes.Length, eventTypes, eventTypes.Length, eventTypes,
userData, handlerRef); userData, handlerRef);
CheckReturn( error ); CheckReturn(error);
} }
[DllImport(carbon)] [DllImport(carbon)]
@ -745,11 +689,11 @@ namespace OpenTK.Platform.MacOS.Carbon
#region --- Process Manager --- #region --- Process Manager ---
[DllImport(carbon)] [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)] [DllImport(carbon)]
public static extern int GetCurrentProcess(ref Carbon.ProcessSerialNumber psn); public static extern int GetCurrentProcess(ref ProcessSerialNumber psn);
[DllImport(carbon)] [DllImport(carbon)]
public static extern int SetFrontProcess(ref Carbon.ProcessSerialNumber psn); public static extern int SetFrontProcess(ref ProcessSerialNumber psn);
#endregion #endregion
#region --- Setting Dock Tile --- #region --- Setting Dock Tile ---
@ -772,13 +716,13 @@ namespace OpenTK.Platform.MacOS.Carbon
[DllImport(carbon)] [DllImport(carbon)]
public extern static void CGColorSpaceRelease(IntPtr space); public extern static void CGColorSpaceRelease(IntPtr space);
[DllImport(carbon)] [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)] [DllImport(carbon)]
public extern static void CGContextSynchronize( IntPtr context ); public extern static void CGContextSynchronize(IntPtr context);
[DllImport(carbon)] [DllImport(carbon)]
public extern static OSStatus QDBeginCGContext( IntPtr port, ref IntPtr context ); public extern static OSStatus QDBeginCGContext(IntPtr port, ref IntPtr context);
[DllImport(carbon)] [DllImport(carbon)]
public extern static OSStatus QDEndCGContext( IntPtr port, ref IntPtr context ); public extern static OSStatus QDEndCGContext(IntPtr port, ref IntPtr context);
#endregion #endregion
#region --- Clipboard --- #region --- Clipboard ---
@ -861,9 +805,9 @@ namespace OpenTK.Platform.MacOS.Carbon
[DllImport(carbon)] [DllImport(carbon)]
public static extern OSStatus CollapseWindow(IntPtr windowRef, bool collapse); public static extern OSStatus CollapseWindow(IntPtr windowRef, bool collapse);
public static void CheckReturn(OSStatus error ) { public static void CheckReturn(OSStatus error) {
if( error != OSStatus.NoError ) if (error != OSStatus.NoError)
throw new MacOSException( error ); throw new MacOSException(error);
} }
[DllImport(carbon, EntryPoint="IsWindowInStandardState")] [DllImport(carbon, EntryPoint="IsWindowInStandardState")]
@ -882,7 +826,7 @@ namespace OpenTK.Platform.MacOS.Carbon
IntPtr displayID, out IntPtr displayDevice, Boolean failToMain); IntPtr displayID, out IntPtr displayDevice, Boolean failToMain);
[DllImport(carbon)] [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 #region Nonworking HIPointConvert routines
@ -911,7 +855,7 @@ namespace OpenTK.Platform.MacOS.Carbon
//[DllImport(carbon, EntryPoint = "HIViewConvertPoint")] //[DllImport(carbon, EntryPoint = "HIViewConvertPoint")]
//extern static OSStatus _HIViewConvertPoint(ref HIPoint inPoint, IntPtr inSourceView, IntPtr inDestView); //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.Rect window_bounds = new Carbon.Rect();
// //Carbon.API.GetWindowBounds(handle, WindowRegionCode.StructureRegion /*32*/, out window_bounds); // //Carbon.API.GetWindowBounds(handle, WindowRegionCode.StructureRegion /*32*/, out window_bounds);
@ -932,12 +876,7 @@ namespace OpenTK.Platform.MacOS.Carbon
#endregion #endregion
const string gestaltlib = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon"; const string gestaltlib = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
[DllImport(gestaltlib)] [DllImport(gestaltlib)]
public static extern OSStatus Gestalt(GestaltSelector selector, out int response); public static extern OSStatus Gestalt(GestaltSelector selector, out int response);
} }
#endregion
} }

View File

@ -1,122 +1,122 @@
using System; using System;
namespace OpenTK.Platform.MacOS.Carbon namespace OpenTK.Platform.MacOS
{ {
public enum MacOSKeyCode public enum MacOSKeyCode
{ {
A = 0, A = 0,
B = 11, B = 11,
C = 8, C = 8,
D = 2, D = 2,
E = 14, E = 14,
F = 3, F = 3,
G = 5, G = 5,
H = 4, H = 4,
I = 34, I = 34,
J = 38, J = 38,
K = 40, K = 40,
L = 37, L = 37,
M = 46, M = 46,
N = 45, N = 45,
O = 31, O = 31,
P = 35, P = 35,
Q = 12, Q = 12,
R = 15, R = 15,
S = 1, S = 1,
T = 17, T = 17,
U = 32, U = 32,
V = 9, V = 9,
W = 13, W = 13,
X = 7, X = 7,
Y = 16, Y = 16,
Z = 6, Z = 6,
Key_1 = 18, Key_1 = 18,
Key_2 = 19, Key_2 = 19,
Key_3 = 20, Key_3 = 20,
Key_4 = 21, Key_4 = 21,
Key_5 = 23, Key_5 = 23,
Key_6 = 22, Key_6 = 22,
Key_7 = 26, Key_7 = 26,
Key_8 = 28, Key_8 = 28,
Key_9 = 25, Key_9 = 25,
Key_0 = 29, Key_0 = 29,
Space = 49, Space = 49,
Tilde = 50, Tilde = 50,
Minus = 27, Minus = 27,
Equals = 24, Equals = 24,
BracketLeft = 33, BracketLeft = 33,
BracketRight = 30, BracketRight = 30,
Backslash = 42, Backslash = 42,
Semicolon = 41, Semicolon = 41,
Quote = 39, Quote = 39,
Comma = 43, Comma = 43,
Period = 47, Period = 47,
Slash = 44, Slash = 44,
Enter = 36, Enter = 36,
Tab = 48, Tab = 48,
Backspace = 51, Backspace = 51,
Return = 52, Return = 52,
Esc = 53, Esc = 53,
KeyPad_Decimal = 65, KeyPad_Decimal = 65,
KeyPad_Multiply = 67, KeyPad_Multiply = 67,
KeyPad_Add = 69, KeyPad_Add = 69,
KeyPad_Divide = 75, KeyPad_Divide = 75,
KeyPad_Enter = 76, KeyPad_Enter = 76,
KeyPad_Subtract = 78, KeyPad_Subtract = 78,
KeyPad_Equal = 81, KeyPad_Equal = 81,
KeyPad_0 = 82, KeyPad_0 = 82,
KeyPad_1 = 83, KeyPad_1 = 83,
KeyPad_2 = 84, KeyPad_2 = 84,
KeyPad_3 = 85, KeyPad_3 = 85,
KeyPad_4 = 86, KeyPad_4 = 86,
KeyPad_5 = 87, KeyPad_5 = 87,
KeyPad_6 = 88, KeyPad_6 = 88,
KeyPad_7 = 89, KeyPad_7 = 89,
KeyPad_8 = 91, KeyPad_8 = 91,
KeyPad_9 = 92, KeyPad_9 = 92,
F1 = 122, F1 = 122,
F2 = 120, F2 = 120,
F3 = 99, F3 = 99,
F4 = 118, F4 = 118,
F5 = 96, F5 = 96,
F6 = 97, F6 = 97,
F7 = 98, F7 = 98,
F8 = 100, F8 = 100,
F9 = 101, F9 = 101,
F10 = 109, F10 = 109,
F11 = 103, F11 = 103,
F12 = 111, F12 = 111,
F13 = 105, F13 = 105,
F14 = 107, F14 = 107,
F15 = 113, F15 = 113,
Menu = 110, Menu = 110,
Insert = 114, Insert = 114,
Home = 115, Home = 115,
Pageup = 116, Pageup = 116,
Del = 117, Del = 117,
End = 119, End = 119,
Pagedown = 121, Pagedown = 121,
Up = 126, Up = 126,
Down = 125, Down = 125,
Left = 123, Left = 123,
Right = 124, Right = 124,
} }
[Flags]
public enum MacOSKeyModifiers [Flags]
{ public enum MacOSKeyModifiers {
None = 0, None = 0,
Shift = 0x0200, Shift = 0x0200,
CapsLock = 0x0400, CapsLock = 0x0400,
Control = 0x1000, // Control = 0x1000, //
Command = 0x0100, // Open-Apple - Windows key Command = 0x0100, // Open-Apple - Windows key
Option = 0x0800, // Option key is same position as the alt key on non-mac keyboards. Option = 0x0800, // Option key is same position as the alt key on non-mac keyboards.
} }
} }

View File

@ -99,8 +99,8 @@ namespace OpenTK.Platform.MacOS {
IntPtr windowRef; IntPtr windowRef;
OSStatus err = API.CreateNewWindow(@class, attrib, ref r, out windowRef); OSStatus err = API.CreateNewWindow(@class, attrib, ref r, out windowRef);
API.CheckReturn( err ); API.CheckReturn(err);
Debug.Print( "Created window " + windowRef.ToString() ); Debug.Print("Created window " + windowRef.ToString());
API.SetWindowTitle(windowRef, title); API.SetWindowTitle(windowRef, title);
SetLocation(r.X, r.Y); SetLocation(r.X, r.Y);
@ -143,20 +143,6 @@ namespace OpenTK.Platform.MacOS {
Application.WindowEventHandler = this; 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) { internal void SetFullscreen(AglContext context) {
windowedBounds = bounds; windowedBounds = bounds;
int width, height; int width, height;
@ -219,8 +205,8 @@ namespace OpenTK.Platform.MacOS {
} }
Key tkKey; Key tkKey;
if( !Keymap.TryGetValue( code, out tkKey ) ) { if (!Keymap.TryGetValue(code, out tkKey)) {
Debug.Print( "{0} not mapped, ignoring press.", code ); Debug.Print("{0} not mapped, ignoring press.", code);
return OSStatus.NoError; return OSStatus.NoError;
} }
@ -470,74 +456,74 @@ namespace OpenTK.Platform.MacOS {
IntPtr pbStr, utf16, utf8; IntPtr pbStr, utf16, utf8;
public override string GetClipboardText() { public override string GetClipboardText() {
IntPtr pbRef = GetPasteboard(); IntPtr pbRef = GetPasteboard();
API.PasteboardSynchronize( pbRef ); API.PasteboardSynchronize(pbRef);
uint itemCount; uint itemCount;
OSStatus err = API.PasteboardGetItemCount( pbRef, out itemCount ); OSStatus err = API.PasteboardGetItemCount(pbRef, out itemCount);
if( err != OSStatus.NoError ) if (err != OSStatus.NoError)
throw new MacOSException( err, "Getting item count from Pasteboard." ); throw new MacOSException(err, "Getting item count from Pasteboard.");
if( itemCount < 1 ) return ""; if (itemCount < 1) return "";
uint itemID; uint itemID;
err = API.PasteboardGetItemIdentifier( pbRef, 1, out itemID ); err = API.PasteboardGetItemIdentifier(pbRef, 1, out itemID);
if( err != OSStatus.NoError ) if (err != OSStatus.NoError)
throw new MacOSException( err, "Getting item identifier from Pasteboard." ); throw new MacOSException(err, "Getting item identifier from Pasteboard.");
IntPtr outData; IntPtr outData;
if ( (err = API.PasteboardCopyItemFlavorData( pbRef, itemID, utf16, out outData )) == OSStatus.NoError ) { if ((err = API.PasteboardCopyItemFlavorData(pbRef, itemID, utf16, out outData)) == OSStatus.NoError) {
IntPtr ptr = API.CFDataGetBytePtr( outData ); IntPtr ptr = API.CFDataGetBytePtr(outData);
if( ptr == IntPtr.Zero ) if (ptr == IntPtr.Zero)
throw new InvalidOperationException( "CFDataGetBytePtr() returned null pointer." ); throw new InvalidOperationException("CFDataGetBytePtr() returned null pointer.");
return Marshal.PtrToStringUni( ptr ); return Marshal.PtrToStringUni(ptr);
} else if ( (err = API.PasteboardCopyItemFlavorData( pbRef, itemID, utf8, out outData )) == OSStatus.NoError ) { } else if ((err = API.PasteboardCopyItemFlavorData(pbRef, itemID, utf8, out outData)) == OSStatus.NoError) {
IntPtr ptr = API.CFDataGetBytePtr( outData ); IntPtr ptr = API.CFDataGetBytePtr(outData);
if( ptr == IntPtr.Zero ) if (ptr == IntPtr.Zero)
throw new InvalidOperationException( "CFDataGetBytePtr() returned null pointer." ); throw new InvalidOperationException("CFDataGetBytePtr() returned null pointer.");
return GetUTF8( ptr ); return GetUTF8(ptr);
} }
return ""; return "";
} }
unsafe static string GetUTF8( IntPtr ptr ) { unsafe static string GetUTF8(IntPtr ptr) {
byte* countPtr = (byte*)ptr, readPtr = (byte*)ptr; byte* countPtr = (byte*)ptr, readPtr = (byte*)ptr;
int length = 0; int length = 0;
while( *countPtr != 0 ) { length++; countPtr++; } while (*countPtr != 0) { length++; countPtr++; }
byte[] text = new byte[length]; 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++; 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(); IntPtr pbRef = GetPasteboard();
OSStatus err = API.PasteboardClear( pbRef ); OSStatus err = API.PasteboardClear(pbRef);
if( err != OSStatus.NoError ) if (err != OSStatus.NoError)
throw new MacOSException( err, "Cleaing Pasteboard." ); throw new MacOSException(err, "Cleaing Pasteboard.");
API.PasteboardSynchronize( pbRef ); API.PasteboardSynchronize(pbRef);
IntPtr ptr = Marshal.StringToHGlobalUni( value ); IntPtr ptr = Marshal.StringToHGlobalUni(value);
IntPtr cfData = API.CFDataCreate( IntPtr.Zero, ptr, (value.Length + 1) * 2 ); IntPtr cfData = API.CFDataCreate(IntPtr.Zero, ptr, (value.Length + 1) * 2);
if( cfData == IntPtr.Zero ) if (cfData == IntPtr.Zero)
throw new InvalidOperationException( "CFDataCreate() returned null pointer." ); throw new InvalidOperationException("CFDataCreate() returned null pointer.");
API.PasteboardPutItemFlavor( pbRef, 1, utf16, cfData, 0 ); API.PasteboardPutItemFlavor(pbRef, 1, utf16, cfData, 0);
Marshal.FreeHGlobal( ptr ); Marshal.FreeHGlobal(ptr);
} }
IntPtr GetPasteboard() { IntPtr GetPasteboard() {
if( pbStr == IntPtr.Zero ) { if (pbStr == IntPtr.Zero) {
pbStr = CF.CFSTR( "com.apple.pasteboard.clipboard" ); pbStr = CF.CFSTR("com.apple.pasteboard.clipboard");
utf16 = CF.CFSTR( "public.utf16-plain-text" ); utf16 = CF.CFSTR("public.utf16-plain-text");
utf8 = CF.CFSTR( "public.utf8-plain-text" ); utf8 = CF.CFSTR("public.utf8-plain-text");
} }
IntPtr pbRef; IntPtr pbRef;
OSStatus err = API.PasteboardCreate( pbStr, out pbRef ); OSStatus err = API.PasteboardCreate(pbStr, out pbRef);
if( err != OSStatus.NoError ) if (err != OSStatus.NoError)
throw new MacOSException( err, "Creating Pasteboard reference." ); throw new MacOSException(err, "Creating Pasteboard reference.");
API.PasteboardSynchronize( pbRef ); API.PasteboardSynchronize(pbRef);
return pbRef; return pbRef;
} }
@ -546,14 +532,12 @@ namespace OpenTK.Platform.MacOS {
} }
public override Point PointToClient(Point point) { public override Point PointToClient(Point point) {
IntPtr handle = WinHandle; Rect r = API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion);
Rect r = Carbon.API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion);
return new Point(point.X - r.X, point.Y - r.Y); return new Point(point.X - r.X, point.Y - r.Y);
} }
public override Point PointToScreen(Point point) { public override Point PointToScreen(Point point) {
IntPtr handle = WinHandle; Rect r = API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion);
Rect r = Carbon.API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion);
return new Point(point.X + r.X, point.Y + r.Y); 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 r = (byte)((pixel >> 16) & 0xFF);
byte g = (byte)((pixel >> 8) & 0xFF); byte g = (byte)((pixel >> 8) & 0xFF);
byte b = (byte)(pixel & 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 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 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); API.SetApplicationDockTileImage(image);
} }
} }
@ -622,10 +608,13 @@ namespace OpenTK.Platform.MacOS {
public override bool Visible { public override bool Visible {
get { return API.IsWindowVisible(WinHandle); } get { return API.IsWindowVisible(WinHandle); }
set { set {
if (value && Visible == false) if (value && Visible == false) {
Show(); API.ShowWindow(WinHandle);
else API.RepositionWindow(WinHandle, IntPtr.Zero, mPositionMethod);
Hide(); API.SelectWindow(WinHandle);
} else {
API.HideWindow(WinHandle);
}
} }
} }
@ -678,13 +667,10 @@ namespace OpenTK.Platform.MacOS {
if (windowState == WindowState.Fullscreen) if (windowState == WindowState.Fullscreen)
return WindowState.Fullscreen; return WindowState.Fullscreen;
if (Carbon.API.IsWindowCollapsed(WinHandle)) if (API.IsWindowCollapsed(WinHandle))
return WindowState.Minimized; return WindowState.Minimized;
if (API.IsWindowInStandardState(WinHandle))
if (Carbon.API.IsWindowInStandardState(WinHandle)) {
return WindowState.Maximized; return WindowState.Maximized;
}
return WindowState.Normal; return WindowState.Normal;
} }
@ -695,10 +681,8 @@ namespace OpenTK.Platform.MacOS {
windowState = value; windowState = value;
if (oldState == WindowState.Fullscreen) if (oldState == WindowState.Fullscreen) {
{
goWindowedHack = true; goWindowedHack = true;
// when returning from full screen, wait until the context is updated // when returning from full screen, wait until the context is updated
// to actually do the work. // to actually do the work.
return; return;
@ -706,7 +690,7 @@ namespace OpenTK.Platform.MacOS {
if (oldState == WindowState.Minimized) { if (oldState == WindowState.Minimized) {
OSStatus err = API.CollapseWindow(WinHandle, false); OSStatus err = API.CollapseWindow(WinHandle, false);
API.CheckReturn( err ); API.CheckReturn(err);
} }
SetCarbonWindowState(); SetCarbonWindowState();
@ -729,7 +713,7 @@ namespace OpenTK.Platform.MacOS {
// large ideal size. // large ideal size.
idealSize = new CarbonPoint(9000, 9000); idealSize = new CarbonPoint(9000, 9000);
err = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomOut, ref idealSize); err = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomOut, ref idealSize);
API.CheckReturn( err ); API.CheckReturn(err);
break; break;
case WindowState.Normal: case WindowState.Normal:
@ -737,13 +721,13 @@ namespace OpenTK.Platform.MacOS {
{ {
idealSize = new CarbonPoint(); idealSize = new CarbonPoint();
err = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomIn, ref idealSize); err = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomIn, ref idealSize);
API.CheckReturn( err ); API.CheckReturn(err);
} }
break; break;
case WindowState.Minimized: case WindowState.Minimized:
err = API.CollapseWindow(WinHandle, true); err = API.CollapseWindow(WinHandle, true);
API.CheckReturn( err ); API.CheckReturn(err);
break; break;
} }
@ -771,17 +755,17 @@ namespace OpenTK.Platform.MacOS {
public override Point DesktopCursorPos { public override Point DesktopCursorPos {
get { get {
HIPoint point = default( HIPoint ); HIPoint point = default(HIPoint);
// NOTE: HIGetMousePosition is only available on OSX 10.5 or later // NOTE: HIGetMousePosition is only available on OSX 10.5 or later
API.HIGetMousePosition( HICoordinateSpace.ScreenPixel, IntPtr.Zero, ref point ); API.HIGetMousePosition(HICoordinateSpace.ScreenPixel, IntPtr.Zero, ref point);
return new Point( (int)point.X, (int)point.Y ); return new Point((int)point.X, (int)point.Y);
} }
set { set {
HIPoint point = default( HIPoint ); HIPoint point = default(HIPoint);
point.X = value.X; point.Y = value.Y; point.X = value.X; point.Y = value.Y;
CG.CGAssociateMouseAndMouseCursorPosition( 0 ); CG.CGAssociateMouseAndMouseCursorPosition(0);
CG.CGDisplayMoveCursorToPoint(CG.CGMainDisplayID(), point); CG.CGDisplayMoveCursorToPoint(CG.CGMainDisplayID(), point);
CG.CGAssociateMouseAndMouseCursorPosition( 1 ); CG.CGAssociateMouseAndMouseCursorPosition(1);
} }
} }

View File

@ -14,162 +14,128 @@ using RECT = OpenTK.Platform.Windows.Win32Rectangle;
namespace OpenTK.Platform.Windows { namespace OpenTK.Platform.Windows {
[SuppressUnmanagedCodeSecurity]
internal static class API { internal static class API {
[DllImport("shell32.dll")] [DllImport("shell32.dll", CharSet = CharSet.Unicode)]
public static extern int SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID); public static extern int SetCurrentProcessExplicitAppUserModelID(string AppID);
[DllImport("user32.dll"), SuppressUnmanagedCodeSecurity] [DllImport("user32.dll")]
internal static extern bool SetWindowPos(IntPtr handle, IntPtr insertAfter, int x, int y, int cx, int cy, SetWindowPosFlags flags); internal static extern bool SetWindowPos(IntPtr handle, IntPtr insertAfter, int x, int y, int cx, int cy, SetWindowPosFlags flags);
[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern bool AdjustWindowRect([In, Out] ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu); internal static extern bool AdjustWindowRect([In, Out] ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu);
[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern bool AdjustWindowRectEx(ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle); 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, 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); int X, int Y, int Width, int Height, IntPtr HandleToParentWindow, IntPtr Menu, IntPtr Instance, IntPtr Param);
[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern bool DestroyWindow(IntPtr windowHandle); 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); internal static extern ushort RegisterClassEx(ref ExtendedWindowClass window_class);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
internal static extern short UnregisterClass(IntPtr className, IntPtr instance); 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); internal static extern int SetWindowLong(IntPtr hWnd, GetWindowLongOffsets nIndex, int dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern uint GetWindowLong(IntPtr hWnd, GetWindowLongOffsets nIndex); 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(); internal static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", SetLastError = true)]
[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]
public static extern bool SetForegroundWindow(IntPtr hWnd); public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
public static extern bool BringWindowToTop(IntPtr hWnd); 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, public static extern bool EnumDisplayDevices([MarshalAs(UnmanagedType.LPTStr)] string lpDevice,
int iDevNum, [In, Out] WindowsDisplayDevice lpDisplayDevice, uint dwFlags); 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, internal static extern bool EnumDisplaySettings([MarshalAs(UnmanagedType.LPTStr)] string device_name,
int graphics_mode, [In, Out] DeviceMode device_mode); int graphics_mode, [In, Out] DeviceMode device_mode);
[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
public static extern bool OpenClipboard(IntPtr hWndNewOwner); public static extern bool OpenClipboard(IntPtr hWndNewOwner);
[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] public static extern bool EmptyClipboard();
public static extern bool EmptyClipboard(); [DllImport("user32.dll", SetLastError = true)]
public static extern bool CloseClipboard();
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity] [DllImport("user32.dll", SetLastError = true)]
public static extern bool CloseClipboard(); public static extern IntPtr GetClipboardData(uint uFormat);
[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
public static extern IntPtr GetClipboardData(uint uFormat);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
public static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem); public static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem);
[DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity] [DllImport("kernel32.dll")]
public static extern IntPtr GlobalAlloc(uint uFlags, UIntPtr dwBytes); public static extern IntPtr GlobalAlloc(uint uFlags, UIntPtr dwBytes);
[DllImport("kernel32.dll")]
[DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity] public static extern IntPtr GlobalFree(IntPtr hMem);
public static extern IntPtr GlobalFree(IntPtr hMem); [DllImport("kernel32.dll")]
public static extern IntPtr GlobalLock(IntPtr hMem);
[DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity] [DllImport("kernel32.dll")]
public static extern IntPtr GlobalLock(IntPtr hMem); public static extern bool GlobalUnlock(IntPtr hMem);
[DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity]
public static extern bool GlobalUnlock(IntPtr hMem);
[DllImport("user32.dll"), SuppressUnmanagedCodeSecurity] [DllImport("user32.dll")]
public static extern IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName); public static extern IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName);
[DllImport("user32.dll")]
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern bool GetCursorPos(ref POINT point); internal static extern bool GetCursorPos(ref POINT point);
[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern bool SetCursorPos(int x, int y); 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] [DllImport("user32.dll", SetLastError = true)]
internal static extern bool ShowCursor( int value ); internal static extern ushort GetKeyState(int code);
[DllImport("user32.dll", SetLastError = true)]
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern ushort GetKeyState( int code );
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern uint MapVirtualKey(short vkey, MapVirtualKeyType uMapType); internal static extern uint MapVirtualKey(short vkey, MapVirtualKeyType uMapType);
} }

View File

@ -4,15 +4,16 @@ using System.Security;
namespace OpenTK.Platform.Windows { namespace OpenTK.Platform.Windows {
[SuppressUnmanagedCodeSecurity]
internal class Wgl : BindingsBase { internal class Wgl : BindingsBase {
protected override IntPtr GetAddress( string funcname ) { protected override IntPtr GetAddress(string funcname) {
return Wgl.wglGetProcAddress( funcname ); return Wgl.wglGetProcAddress(funcname);
} }
internal void LoadEntryPoints() { internal void LoadEntryPoints() {
LoadDelegate( "wglGetSwapIntervalEXT", out wglGetSwapIntervalEXT ); LoadDelegate("wglGetSwapIntervalEXT", out wglGetSwapIntervalEXT);
LoadDelegate( "wglSwapIntervalEXT", out wglSwapIntervalEXT ); LoadDelegate("wglSwapIntervalEXT", out wglSwapIntervalEXT);
} }
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
@ -23,22 +24,22 @@ namespace OpenTK.Platform.Windows {
internal delegate int GetSwapIntervalEXT(); internal delegate int GetSwapIntervalEXT();
internal static GetSwapIntervalEXT wglGetSwapIntervalEXT; internal static GetSwapIntervalEXT wglGetSwapIntervalEXT;
[SuppressUnmanagedCodeSecurity,DllImport("OPENGL32.DLL", SetLastError = true)] [DllImport("OPENGL32.DLL", SetLastError = true)]
internal extern static IntPtr wglCreateContext(IntPtr hDc); 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); internal extern static Boolean wglDeleteContext(IntPtr oldContext);
[SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)] [DllImport("OPENGL32.DLL", SetLastError = true)]
internal extern static IntPtr wglGetCurrentContext(); 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); 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(); internal extern static IntPtr wglGetCurrentDC();
[SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)] [DllImport("OPENGL32.DLL", SetLastError = true)]
internal extern static IntPtr wglGetProcAddress(String lpszProc); internal extern static IntPtr wglGetProcAddress(String lpszProc);
} }
} }

View File

@ -23,14 +23,14 @@ namespace OpenTK.Platform.Windows {
if (opengl32Handle == IntPtr.Zero) if (opengl32Handle == IntPtr.Zero)
throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}", throw new ApplicationException(String.Format("LoadLibrary(\"{0}\") call failed with code {1}",
opengl32Name, Marshal.GetLastWin32Error())); opengl32Name, Marshal.GetLastWin32Error()));
Debug.Print( "Loaded opengl32.dll: {0}", opengl32Handle ); Debug.Print("Loaded opengl32.dll: {0}", opengl32Handle);
} }
} }
public WinGLContext(GraphicsMode format, WinWindow window) { public WinGLContext(GraphicsMode format, WinWindow window) {
Debug.Print("OpenGL will be bound to handle: {0}", window.WinHandle); Debug.Print("OpenGL will be bound to handle: {0}", window.WinHandle);
SelectGraphicsModePFD(format, window); SelectGraphicsModePFD(format, window);
Debug.Print("Setting pixel format... " ); Debug.Print("Setting pixel format... ");
SetGraphicsModePFD(format, window); SetGraphicsModePFD(format, window);
ContextHandle = Wgl.wglCreateContext(window.DeviceContext); ContextHandle = Wgl.wglCreateContext(window.DeviceContext);
@ -39,7 +39,7 @@ namespace OpenTK.Platform.Windows {
if (ContextHandle == IntPtr.Zero) if (ContextHandle == IntPtr.Zero)
throw new GraphicsContextException("Context creation failed. Wgl.CreateContext() error: " + Marshal.GetLastWin32Error()); 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() { public override void SwapBuffers() {
@ -87,9 +87,9 @@ namespace OpenTK.Platform.Windows {
public override IntPtr GetAddress(string funcName) { public override IntPtr GetAddress(string funcName) {
IntPtr dynAddress = Wgl.wglGetProcAddress(funcName); IntPtr dynAddress = Wgl.wglGetProcAddress(funcName);
if( !BindingsBase.IsInvalidAddress( dynAddress ) ) if (!BindingsBase.IsInvalidAddress(dynAddress))
return dynAddress; return dynAddress;
return API.GetProcAddress( opengl32Handle, funcName ); return API.GetProcAddress(opengl32Handle, funcName);
} }

View File

@ -33,7 +33,7 @@ using System.Threading;
using OpenTK.Input; using OpenTK.Input;
namespace OpenTK.Platform.Windows { namespace OpenTK.Platform.Windows {
internal sealed class WinWindow : INativeWindow { public sealed class WinWindow : INativeWindow {
const ExtendedWindowStyle ParentStyleEx = ExtendedWindowStyle.WindowEdge | ExtendedWindowStyle.ApplicationWindow; const ExtendedWindowStyle ParentStyleEx = ExtendedWindowStyle.WindowEdge | ExtendedWindowStyle.ApplicationWindow;
readonly IntPtr Instance = Marshal.GetHINSTANCE(typeof(WinWindow).Module); readonly IntPtr Instance = Marshal.GetHINSTANCE(typeof(WinWindow).Module);
readonly IntPtr ClassName = Marshal.StringToHGlobalAuto("CS_WindowClass"); 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 // 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 // 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). // may result in both keys being held down (but not always).
bool lShiftDown = (API.GetKeyState( (int)VirtualKeys.LSHIFT ) >> 15) == 1; bool lShiftDown = (API.GetKeyState((int)VirtualKeys.LSHIFT) >> 15) == 1;
bool rShiftDown = (API.GetKeyState( (int)VirtualKeys.RSHIFT ) >> 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.ShiftLeft, lShiftDown);
Keyboard.Set(Key.ShiftRight, rShiftDown); Keyboard.Set(Key.ShiftRight, rShiftDown);
} }
@ -379,7 +379,7 @@ namespace OpenTK.Platform.Windows {
} }
} }
void SetHiddenBorder( bool hidden ) { void SetHiddenBorder(bool hidden) {
suppress_resize++; suppress_resize++;
HiddenBorder = hidden; HiddenBorder = hidden;
ProcessEvents(); ProcessEvents();
@ -421,7 +421,7 @@ namespace OpenTK.Platform.Windows {
return ""; return "";
} }
public override unsafe void SetClipboardText( string value ) { public override unsafe void SetClipboardText(string value) {
UIntPtr dstSize = (UIntPtr)((value.Length + 1) * Marshal.SystemDefaultCharSize); UIntPtr dstSize = (UIntPtr)((value.Length + 1) * Marshal.SystemDefaultCharSize);
// retry up to 10 times // retry up to 10 times
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
@ -504,8 +504,8 @@ namespace OpenTK.Platform.Windows {
icon = value; icon = value;
if (WinHandle != IntPtr.Zero) if (WinHandle != IntPtr.Zero)
{ {
//Icon small = new Icon( value, 16, 16 ); //Icon small = new Icon(value, 16, 16);
//GC.KeepAlive( small ); //GC.KeepAlive(small);
API.SendMessage(WinHandle, WindowMessage.SETICON, (IntPtr)0, icon == null ? IntPtr.Zero : value.Handle); 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); 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. // Reset state to avoid strange side-effects from maximized/minimized windows.
ResetWindowState(); ResetWindowState();
previous_bounds = Bounds; previous_bounds = Bounds;
SetHiddenBorder( true ); SetHiddenBorder(true);
command = ShowWindowCommand.MAXIMIZE; command = ShowWindowCommand.MAXIMIZE;
API.SetForegroundWindow(WinHandle); API.SetForegroundWindow(WinHandle);
break; break;
} }
if( command != 0 ) if (command != 0)
API.ShowWindow(WinHandle, command); API.ShowWindow(WinHandle, command);
// Restore previous window border or apply pending border change when leaving fullscreen mode. // Restore previous window border or apply pending border change when leaving fullscreen mode.
if( exiting_fullscreen ) if (exiting_fullscreen)
SetHiddenBorder( false ); SetHiddenBorder(false);
// Restore previous window size/location if necessary // Restore previous window size/location if necessary
if (command == ShowWindowCommand.RESTORE && previous_bounds != Rectangle.Empty) { if (command == ShowWindowCommand.RESTORE && previous_bounds != Rectangle.Empty) {
@ -598,7 +598,7 @@ namespace OpenTK.Platform.Windows {
bool hiddenBorder; bool hiddenBorder;
bool HiddenBorder { bool HiddenBorder {
set { set {
if( hiddenBorder == value ) return; if (hiddenBorder == value) return;
// We wish to avoid making an invisible window visible just to change the border. // 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 // 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); style |= (value ? WindowStyle.Popup : WindowStyle.OverlappedWindow);
// Make sure client size doesn't change when changing the border style. // Make sure client size doesn't change when changing the border style.
Win32Rectangle rect = Win32Rectangle.From( bounds ); Win32Rectangle rect = Win32Rectangle.From(bounds);
API.AdjustWindowRectEx( ref rect, style, false, ParentStyleEx ); API.AdjustWindowRectEx(ref rect, style, false, ParentStyleEx);
// This avoids leaving garbage on the background window. // This avoids leaving garbage on the background window.
if( was_visible ) if (was_visible)
Visible = false; Visible = false;
API.SetWindowLong(WinHandle, GetWindowLongOffsets.STYLE, (int)style); 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 // Force window to redraw update its borders, but only if it's
// already visible (invisible windows will change borders when // already visible (invisible windows will change borders when
// they become visible, so no need to make them visiable prematurely). // they become visible, so no need to make them visiable prematurely).
if ( was_visible ) if (was_visible)
Visible = true; Visible = true;
WindowState = state; WindowState = state;
} }
@ -654,22 +654,22 @@ namespace OpenTK.Platform.Windows {
MSG msg; MSG msg;
public override void ProcessEvents() { 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.TranslateMessage(ref msg);
API.DispatchMessage(ref msg); API.DispatchMessage(ref msg);
} }
IntPtr foreground = API.GetForegroundWindow(); IntPtr foreground = API.GetForegroundWindow();
if( foreground != IntPtr.Zero ) if (foreground != IntPtr.Zero)
focused = foreground == WinHandle; focused = foreground == WinHandle;
} }
public override Point DesktopCursorPos { public override Point DesktopCursorPos {
get { get {
POINT pos = default( POINT ); POINT pos = default(POINT);
API.GetCursorPos( ref pos ); API.GetCursorPos(ref pos);
return new Point( pos.X, pos.Y ); return new Point(pos.X, pos.Y);
} }
set { API.SetCursorPos( value.X, value.Y ); } set { API.SetCursorPos(value.X, value.Y); }
} }
bool cursorVisible = true; bool cursorVisible = true;
@ -677,7 +677,7 @@ namespace OpenTK.Platform.Windows {
get { return cursorVisible; } get { return cursorVisible; }
set { set {
cursorVisible = value; cursorVisible = value;
API.ShowCursor( value ? 1 : 0 ); API.ShowCursor(value ? 1 : 0);
} }
} }

View File

@ -23,193 +23,164 @@ using KeyCode = System.Byte; // Or maybe ushort?
namespace OpenTK.Platform.X11 { namespace OpenTK.Platform.X11 {
[SuppressUnmanagedCodeSecurity]
public static class API { public static class API {
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11")]
public extern static IntPtr XOpenDisplay(IntPtr display); public extern static IntPtr XOpenDisplay(IntPtr display);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XCloseDisplay(IntPtr display); 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); 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")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] public extern static int XDestroyWindow(IntPtr display, IntPtr window);
[DllImport("libX11")]
public extern static int XMapWindow(IntPtr display, IntPtr window); public extern static int XMapWindow(IntPtr display, IntPtr window);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11")]
public extern static int XUnmapWindow(IntPtr display, IntPtr window); public extern static int XUnmapWindow(IntPtr display, IntPtr window);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11")]
public extern static IntPtr XRootWindow(IntPtr display, int screen_number); 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); public extern static Bool XCheckWindowEvent(Display display, Window w, EventMask event_mask, ref XEvent event_return);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11")]
public extern static Bool XCheckTypedWindowEvent(Display display, Window w, XEventName event_type, ref XEvent event_return); 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"), SuppressUnmanagedCodeSecurity] [DllImport("libX11")]
public extern static int XMoveResizeWindow(IntPtr display, IntPtr window, int x, int y, int width, int height); public extern static int XMoveResizeWindow(IntPtr display, IntPtr window, int x, int y, int width, int height);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] public extern static int XMoveWindow(IntPtr display, IntPtr w, int x, int y);
public extern static int XMoveWindow(IntPtr display, IntPtr w, int x, int y); [DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XResizeWindow(IntPtr display, IntPtr window, int width, int height); 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); public extern static int XFlush(IntPtr display);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11")]
public extern static int XStoreName(IntPtr display, IntPtr window, string window_name); public extern static int XStoreName(IntPtr display, IntPtr window, string window_name);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XFetchName(IntPtr display, IntPtr window, ref IntPtr window_name); 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 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) { 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); return XSendEvent(display, window, propagate, new IntPtr((int)event_mask), ref send_event);
} }
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [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); 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] [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); 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); 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); 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); 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); 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); 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 // Colormaps
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11")]
public extern static int XDefaultDepth(IntPtr display, int screen_number); public extern static int XDefaultDepth(IntPtr display, int screen_number);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XDefaultScreen(IntPtr display); public extern static int XDefaultScreen(IntPtr display);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] public static extern IntPtr XDefaultRootWindow(IntPtr display);
public extern static int XSetTransientForHint(IntPtr display, IntPtr window, IntPtr prop_window);
[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); public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr[] data, int nelements);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr data, int nelements);
public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr data, int nelements); [DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XDeleteProperty(IntPtr display, IntPtr window, IntPtr property); 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); public extern static int XDefineCursor(IntPtr display, IntPtr window, IntPtr cursor);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XUndefineCursor(IntPtr display, IntPtr window); public extern static int XUndefineCursor(IntPtr display, IntPtr window);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XFreeCursor(IntPtr display, IntPtr cursor); public extern static int XFreeCursor(IntPtr display, IntPtr cursor);
// Drawing // Drawing
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11")]
public extern static IntPtr XCreateGC(IntPtr display, IntPtr window, IntPtr valuemask, IntPtr values); public extern static IntPtr XCreateGC(IntPtr display, IntPtr window, IntPtr valuemask, IntPtr values);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XFreeGC(IntPtr display, IntPtr gc); public extern static int XFreeGC(IntPtr display, IntPtr gc);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [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]
public extern static int XIconifyWindow(IntPtr display, IntPtr window, int screen_number); 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); public extern static IntPtr XCreatePixmapFromBitmapData(IntPtr display, IntPtr drawable, byte[] data, int width, int height, IntPtr fg, IntPtr bg, int depth);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static IntPtr XCreatePixmap(IntPtr display, IntPtr d, int width, int height, int depth); public extern static IntPtr XCreatePixmap(IntPtr display, IntPtr d, int width, int height, int depth);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] public extern static IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask,
public extern static IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask, ref XColor foregroundCol, ref XColor backgroundCol, int x_hot, int y_hot); ref XColor foregroundCol, ref XColor backgroundCol, int x_hot, int y_hot);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static IntPtr XFreePixmap(IntPtr display, IntPtr pixmap); 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); public extern static int XGetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints, out IntPtr supplied_return);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static void XSetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints); 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* public static extern IntPtr XGetWMHints(Display display, Window w); // returns XWMHints*
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public static extern void XSetWMHints(Display display, Window w, ref XWMHints wmhints); public static extern void XSetWMHints(Display display, Window w, ref XWMHints wmhints);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public static extern IntPtr XAllocWMHints(); public static extern IntPtr XAllocWMHints();
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11")]
public extern static bool XkbSetDetectableAutoRepeat(IntPtr display, bool detectable, out bool supported); 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); public static extern IntPtr XCreateColormap(Display display, Window window, IntPtr visual, int alloc);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11")]
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]
public static extern int XBitmapBitOrder(Display display); public static extern int XBitmapBitOrder(Display display);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public static extern IntPtr XCreateImage(Display display, IntPtr visual, public static extern IntPtr XCreateImage(Display display, IntPtr visual,
uint depth, ImageFormat format, int offset, IntPtr data, int width, int height, uint depth, ImageFormat format, int offset, IntPtr data, int width, int height,
int bitmap_pad, int bytes_per_line); int bitmap_pad, int bytes_per_line);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public static extern void XPutImage(Display display, IntPtr drawable, 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); 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, public static extern int XLookupString(ref XKeyEvent event_struct, [Out] byte[] buffer_return,
int bytes_buffer, [Out] KeySym[] keysym_return, IntPtr status_in_out); 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); public static extern int XRefreshKeyboardMapping(ref XMappingEvent event_map);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11")]
public extern static IntPtr XGetSelectionOwner(IntPtr display, IntPtr selection); public extern static IntPtr XGetSelectionOwner(IntPtr display, IntPtr selection);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XConvertSelection(IntPtr display, IntPtr selection, IntPtr target, IntPtr property, IntPtr requestor, IntPtr time); public extern static int XConvertSelection(IntPtr display, IntPtr selection, IntPtr target, IntPtr property, IntPtr requestor, IntPtr time);
[DllImport("libX11")]
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XSetSelectionOwner(IntPtr display, IntPtr selection, IntPtr owner, IntPtr time); public extern static int XSetSelectionOwner(IntPtr display, IntPtr selection, IntPtr owner, IntPtr time);
static readonly IntPtr CopyFromParent = IntPtr.Zero; 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(); XEvent xev = new XEvent();
xev.ClientMessageEvent.type = XEventName.ClientMessage; xev.ClientMessageEvent.type = XEventName.ClientMessage;
xev.ClientMessageEvent.send_event = true; xev.ClientMessageEvent.send_event = true;
@ -224,8 +195,7 @@ namespace OpenTK.Platform.X11 {
EventMask.SubstructureRedirectMask | EventMask.SubstructureNotifyMask, ref xev); 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; int width = image.Width, height = image.Height;
System.Drawing.Imaging.BitmapData data = image.LockBits(new System.Drawing.Rectangle(0, 0, width, 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; 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 width = image.Width;
int height = image.Height; int height = image.Height;
int stride = (width + 7) >> 3; int stride = (width + 7) >> 3;
byte[] mask = new byte[stride * height]; byte[] mask = new byte[stride * height];
bool msbfirst = (XBitmapBitOrder(display) == 1); // 1 = MSBFirst bool msbfirst = (XBitmapBitOrder(display) == 1); // 1 = MSBFirst
for (int y = 0; y < height; ++y) for (int y = 0; y < height; ++y) {
{ for (int x = 0; x < width; ++x) {
for (int x = 0; x < width; ++x) byte bit = (byte)(1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
{
byte bit = (byte) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
int offset = y * stride + (x >> 3); int offset = y * stride + (x >> 3);
if (image.GetPixel(x, y).A >= 128) if (image.GetPixel(x, y).A >= 128)
@ -270,80 +237,25 @@ namespace OpenTK.Platform.X11 {
mask, width, height, new IntPtr(1), IntPtr.Zero, 1); 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); public static extern XRRScreenConfiguration XRRGetScreenInfo(Display dpy, Drawable draw);
[DllImport(Xrandr)]
[DllImport(XrandrLibrary)]
public static extern void XRRFreeScreenConfigInfo(XRRScreenConfiguration config); public static extern void XRRFreeScreenConfigInfo(XRRScreenConfiguration config);
[DllImport(XrandrLibrary)] [DllImport(Xrandr)]
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)]
public static extern ushort XRRConfigCurrentConfiguration(XRRScreenConfiguration config, out ushort rotation); public static extern ushort XRRConfigCurrentConfiguration(XRRScreenConfiguration config, out ushort rotation);
[DllImport(Xrandr)]
[DllImport(XrandrLibrary)]
public static extern short XRRConfigCurrentRate(XRRScreenConfiguration config); 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 // the following are always safe to call, even if RandR is not implemented on a screen
[DllImport(XrandrLibrary)] [DllImport(Xrandr)]
unsafe static extern XRRScreenSize* XRRSizes(Display dpy, int screen, int* nsizes); public unsafe static extern XRRScreenSize* XRRSizes(Display dpy, int screen, int* nsizes);
public unsafe static XRRScreenSize[] XRRSizes(Display dpy, int screen) { [DllImport("libX11")]
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]
public static extern int XScreenCount(Display display); 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 Display DefaultDisplay;
public static int DefaultScreen; public static int DefaultScreen;
public static IntPtr RootWindow; 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, public static extern KeySym XGetKeyboardMapping(Display display, KeyCode first_keycode, int keycode_count,
ref int keysyms_per_keycode_return); 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); 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); public static extern KeySym XLookupKeysym(ref XKeyEvent key_event, int index);
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct XVisualInfo { public struct XVisualInfo {
public IntPtr Visual; public IntPtr Visual;

View File

@ -50,6 +50,7 @@ namespace OpenTK.Platform.X11
#endregion #endregion
[SuppressUnmanagedCodeSecurity]
class Glx : BindingsBase class Glx : BindingsBase
{ {
const string Library = "libGL.so.1"; const string Library = "libGL.so.1";
@ -62,45 +63,45 @@ namespace OpenTK.Platform.X11
} }
internal void LoadEntryPoints() { 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); 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); 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); public static extern void glXDestroyContext(IntPtr dpy, IntPtr context);
[SuppressUnmanagedCodeSecurity, DllImport( Library )] [DllImport(Library)]
public static extern IntPtr glXGetCurrentContext(); public static extern IntPtr glXGetCurrentContext();
[SuppressUnmanagedCodeSecurity, DllImport( Library )] [DllImport(Library)]
public static extern bool glXMakeCurrent(IntPtr display, IntPtr drawable, IntPtr context); 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); public static extern void glXSwapBuffers(IntPtr display, IntPtr drawable);
[SuppressUnmanagedCodeSecurity, DllImport( Library )] [DllImport(Library)]
public static extern IntPtr glXGetProcAddress([MarshalAs(UnmanagedType.LPTStr)] string procName); 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); 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); public static extern IntPtr glXChooseVisual(IntPtr dpy, int screen, int[] attriblist);
// Returns an array of GLXFBConfig structures. // 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); public unsafe extern static IntPtr* glXChooseFBConfig(IntPtr dpy, int screen, int[] attriblist, out int fbount);
// Returns a pointer to an XVisualInfo structure. // Returns a pointer to an XVisualInfo structure.
[SuppressUnmanagedCodeSecurity, DllImport( Library )] [DllImport(Library)]
public unsafe extern static IntPtr glXGetVisualFromFBConfig(IntPtr dpy, IntPtr fbconfig); 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); public extern static bool glXQueryVersion(IntPtr dpy, ref int major, ref int minor);
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]

View File

@ -75,24 +75,24 @@ namespace OpenTK.Platform.X11 {
return true; return true;
} }
static bool QueryXRandR(List<DisplayDevice> devices) { unsafe static bool QueryXRandR(List<DisplayDevice> devices) {
// Get available resolutions. Then, for each resolution get all available rates. // Get available resolutions. Then, for each resolution get all available rates.
foreach (DisplayDevice dev in devices) { foreach (DisplayDevice dev in devices) {
int screen = (int)dev.Metadata; int screen = (int)dev.Metadata, count = 0;
XRRScreenSize[] sizes = API.XRRSizes(API.DefaultDisplay, screen); XRRScreenSize* sizes = API.XRRSizes(API.DefaultDisplay, screen, &count);
if (sizes == null) if (count == 0)
throw new NotSupportedException("XRandR extensions not available."); throw new NotSupportedException("XRandR extensions not available.");
IntPtr screenConfig = API.XRRGetScreenInfo(API.DefaultDisplay, API.XRootWindow(API.DefaultDisplay, screen)); IntPtr screenConfig = API.XRRGetScreenInfo(API.DefaultDisplay, API.XRootWindow(API.DefaultDisplay, screen));
ushort curRotation; ushort curRotation;
int curSizesIndex = API.XRRConfigCurrentConfiguration(screenConfig, out curRotation); int idx = API.XRRConfigCurrentConfiguration(screenConfig, out curRotation);
int curRefreshRate = API.XRRConfigCurrentRate(screenConfig); int curRefreshRate = API.XRRConfigCurrentRate(screenConfig);
int curDepth = API.XDefaultDepth(API.DefaultDisplay, screen); int curDepth = API.XDefaultDepth(API.DefaultDisplay, screen);
API.XRRFreeScreenConfigInfo(screenConfig); API.XRRFreeScreenConfigInfo(screenConfig);
if (dev.Bounds == Rectangle.Empty) 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.BitsPerPixel = curDepth;
dev.RefreshRate = curRefreshRate; dev.RefreshRate = curRefreshRate;
} }
@ -121,7 +121,7 @@ namespace OpenTK.Platform.X11 {
XineramaScreenInfo* ptr = (XineramaScreenInfo*)screen_ptr; XineramaScreenInfo* ptr = (XineramaScreenInfo*)screen_ptr;
XineramaScreenInfo[] screens = new XineramaScreenInfo[count]; XineramaScreenInfo[] screens = new XineramaScreenInfo[count];
for( int i = 0; i < screens.Length; i++ ) { for(int i = 0; i < screens.Length; i++) {
screens[i] = *ptr++; screens[i] = *ptr++;
} }
return screens; return screens;

View File

@ -16,10 +16,10 @@ namespace OpenTK.Platform.X11 {
int vsync_interval; int vsync_interval;
public X11GLContext(GraphicsMode mode, X11Window window) { public X11GLContext(GraphicsMode mode, X11Window window) {
Debug.Print( "Creating X11GLContext context: " ); Debug.Print("Creating X11GLContext context: ");
cur = window; cur = window;
XVisualInfo info = cur.VisualInfo; XVisualInfo info = cur.VisualInfo;
Mode = GetGraphicsMode( info ); Mode = GetGraphicsMode(info);
// Cannot pass a Property by reference. // Cannot pass a Property by reference.
IntPtr display = API.DefaultDisplay; IntPtr display = API.DefaultDisplay;
@ -111,65 +111,65 @@ namespace OpenTK.Platform.X11 {
ContextHandle = IntPtr.Zero; ContextHandle = IntPtr.Zero;
} }
internal static GraphicsMode SelectGraphicsMode( GraphicsMode template, out XVisualInfo info ) { internal static GraphicsMode SelectGraphicsMode(GraphicsMode template, out XVisualInfo info) {
int[] attribs = GetVisualAttribs( template.ColorFormat, template.Depth, template.Stencil, template.Buffers ); int[] attribs = GetVisualAttribs(template.ColorFormat, template.Depth, template.Stencil, template.Buffers);
IntPtr visual = SelectVisual( attribs ); IntPtr visual = SelectVisual(attribs);
if( visual == IntPtr.Zero ) if (visual == IntPtr.Zero)
throw new GraphicsModeException( "Requested GraphicsMode not available." ); throw new GraphicsModeException("Requested GraphicsMode not available.");
info = (XVisualInfo)Marshal.PtrToStructure( visual, typeof( XVisualInfo ) ); info = (XVisualInfo)Marshal.PtrToStructure(visual, typeof(XVisualInfo));
API.XFree( visual ); API.XFree(visual);
return GetGraphicsMode( info ); return GetGraphicsMode(info);
} }
internal static GraphicsMode GetGraphicsMode( XVisualInfo info ) { internal static GraphicsMode GetGraphicsMode(XVisualInfo info) {
// See what we *really* got: // See what we *really* got:
int r, g, b, a, depth, stencil, buffers; int r, g, b, a, depth, stencil, buffers;
IntPtr display = API.DefaultDisplay; IntPtr display = API.DefaultDisplay;
Glx.glXGetConfig( display, ref info, GLXAttribute.ALPHA_SIZE, out a ); 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.RED_SIZE, out r);
Glx.glXGetConfig( display, ref info, GLXAttribute.GREEN_SIZE, out g ); 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.BLUE_SIZE, out b);
Glx.glXGetConfig( display, ref info, GLXAttribute.DEPTH_SIZE, out depth ); 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.STENCIL_SIZE, out stencil);
Glx.glXGetConfig( display, ref info, GLXAttribute.DOUBLEBUFFER, out buffers ); Glx.glXGetConfig(display, ref info, GLXAttribute.DOUBLEBUFFER, out buffers);
++buffers; ++buffers;
// the above lines returns 0 - false and 1 - true. // 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_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 // 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. // 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; int major = 0, minor = 0;
if( !Glx.glXQueryVersion( API.DefaultDisplay, ref major, ref minor ) ) if (!Glx.glXQueryVersion(API.DefaultDisplay, ref major, ref minor))
throw new InvalidOperationException( "glXQueryVersion failed, potentially corrupt OpenGL driver" ); throw new InvalidOperationException("glXQueryVersion failed, potentially corrupt OpenGL driver");
int screen = API.XDefaultScreen( API.DefaultDisplay ); int screen = API.XDefaultScreen(API.DefaultDisplay);
if( major >= 1 && minor >= 3 ) { if (major >= 1 && minor >= 3) {
Debug.Print( "Getting FB config." ); Debug.Print("Getting FB config.");
int fbcount; int fbcount;
// Note that ChooseFBConfig returns an array of GLXFBConfig opaque structures (i.e. mapped to IntPtrs). // 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 ); IntPtr* fbconfigs = Glx.glXChooseFBConfig(API.DefaultDisplay, screen, visualAttribs, out fbcount);
if( fbcount > 0 && fbconfigs != null ) { if (fbcount > 0 && fbconfigs != null) {
// We want to use the first GLXFBConfig from the fbconfigs array (the first one is the best match). // 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 ); IntPtr visual = Glx.glXGetVisualFromFBConfig(API.DefaultDisplay, *fbconfigs);
API.XFree( (IntPtr)fbconfigs ); API.XFree((IntPtr)fbconfigs);
return visual; return visual;
} }
} }
Debug.Print( "Falling back to glXChooseVisual." ); Debug.Print("Falling back to glXChooseVisual.");
return Glx.glXChooseVisual( API.DefaultDisplay, screen, visualAttribs ); 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[] attribs = new int[16];
int index = 0; int index = 0;
Debug.Print("Bits per pixel: {0}", color.BitsPerPixel); Debug.Print("Bits per pixel: {0}", color.BitsPerPixel);
Debug.Print("Depth: {0}", depth); Debug.Print("Depth: {0}", depth);
if( !color.IsIndexed ) if (!color.IsIndexed)
attribs[index++] = (int)GLXAttribute.RGBA; attribs[index++] = (int)GLXAttribute.RGBA;
attribs[index++] = (int)GLXAttribute.RED_SIZE; attribs[index++] = (int)GLXAttribute.RED_SIZE;
attribs[index++] = color.Red; attribs[index++] = color.Red;
@ -180,15 +180,15 @@ namespace OpenTK.Platform.X11 {
attribs[index++] = (int)GLXAttribute.ALPHA_SIZE; attribs[index++] = (int)GLXAttribute.ALPHA_SIZE;
attribs[index++] = color.Alpha; attribs[index++] = color.Alpha;
if( depth > 0 ) { if (depth > 0) {
attribs[index++] = (int)GLXAttribute.DEPTH_SIZE; attribs[index++] = (int)GLXAttribute.DEPTH_SIZE;
attribs[index++] = depth; attribs[index++] = depth;
} }
if( stencil > 0 ) { if (stencil > 0) {
attribs[index++] = (int)GLXAttribute.STENCIL_SIZE; attribs[index++] = (int)GLXAttribute.STENCIL_SIZE;
attribs[index++] = stencil; attribs[index++] = stencil;
} }
if( buffers > 1 ) if (buffers > 1)
attribs[index++] = (int)GLXAttribute.DOUBLEBUFFER; attribs[index++] = (int)GLXAttribute.DOUBLEBUFFER;
attribs[index++] = 0; attribs[index++] = 0;

View File

@ -87,7 +87,7 @@ namespace OpenTK.Platform.X11 {
RegisterAtoms(); RegisterAtoms();
XVisualInfo info = new XVisualInfo(); XVisualInfo info = new XVisualInfo();
mode = X11GLContext.SelectGraphicsMode( mode, out info ); mode = X11GLContext.SelectGraphicsMode(mode, out info);
VisualInfo = info; VisualInfo = info;
// Create a window on this display using the visual above // Create a window on this display using the visual above
Debug.Print("Opening render window... "); Debug.Print("Opening render window... ");
@ -337,7 +337,7 @@ namespace OpenTK.Platform.X11 {
break; break;
case XEventName.KeyPress: 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); int status = API.XLookupString(ref e.KeyEvent, ascii, ascii.Length, null, IntPtr.Zero);
Encoding.Default.GetChars(ascii, 0, status, chars, 0); Encoding.Default.GetChars(ascii, 0, status, chars, 0);
@ -351,7 +351,7 @@ namespace OpenTK.Platform.X11 {
case XEventName.KeyRelease: case XEventName.KeyRelease:
// Todo: raise KeyPress event. Use code from // 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 // 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; break;
case XEventName.ButtonPress: case XEventName.ButtonPress:
@ -691,12 +691,12 @@ namespace OpenTK.Platform.X11 {
get { get {
IntPtr root, child; IntPtr root, child;
int rootX, rootY, childX, childY, mask; 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 ); 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 ); return new Point(rootX, rootY);
} }
set { set {
API.XWarpPointer( API.DefaultDisplay, IntPtr.Zero, API.RootWindow, 0, 0, 0, 0, value.X, value.Y ); 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.XFlush(API.DefaultDisplay); // TODO: not sure if XFlush call is necessary
} }
} }
@ -705,22 +705,22 @@ namespace OpenTK.Platform.X11 {
get { return cursorVisible; } get { return cursorVisible; }
set { set {
cursorVisible = value; cursorVisible = value;
if( value ) { if (value) {
API.XUndefineCursor( API.DefaultDisplay, WinHandle ); API.XUndefineCursor(API.DefaultDisplay, WinHandle);
} else { } else {
if( blankCursor == IntPtr.Zero ) if (blankCursor == IntPtr.Zero)
MakeBlankCursor(); MakeBlankCursor();
API.XDefineCursor( API.DefaultDisplay, WinHandle, blankCursor ); API.XDefineCursor(API.DefaultDisplay, WinHandle, blankCursor);
} }
} }
} }
IntPtr blankCursor; IntPtr blankCursor;
void MakeBlankCursor() { void MakeBlankCursor() {
XColor color = default( XColor ); XColor color = default(XColor);
IntPtr pixmap = API.XCreatePixmap( API.DefaultDisplay, API.RootWindow, 1, 1, 1 ); IntPtr pixmap = API.XCreatePixmap(API.DefaultDisplay, API.RootWindow, 1, 1, 1);
blankCursor = API.XCreatePixmapCursor( API.DefaultDisplay, pixmap, pixmap, ref color, ref color, 0, 0 ); blankCursor = API.XCreatePixmapCursor(API.DefaultDisplay, pixmap, pixmap, ref color, ref color, 0, 0);
API.XFreePixmap( API.DefaultDisplay, pixmap ); API.XFreePixmap(API.DefaultDisplay, pixmap);
} }
/// <summary> Returns true if a render window/context exists. </summary> /// <summary> Returns true if a render window/context exists. </summary>
@ -762,14 +762,14 @@ namespace OpenTK.Platform.X11 {
int ox, oy; int ox, oy;
IntPtr child; IntPtr child;
API.XTranslateCoordinates(API.DefaultDisplay, API.RootWindow, WinHandle, point.X, point.Y, out ox, out oy, out 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) { public override Point PointToScreen(Point point) {
int ox, oy; int ox, oy;
IntPtr child; IntPtr child;
API.XTranslateCoordinates(API.DefaultDisplay, WinHandle, API.RootWindow, point.X, point.Y, out ox, out oy, out 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) { protected override void Dispose(bool manuallyCalled) {