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

View File

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

View File

@ -12,11 +12,6 @@ namespace Launcher.Drawing {
gc = API.XCreateGC(API.DefaultDisplay, window.WinHandle, IntPtr.Zero, IntPtr.Zero);
}
public override void Resize() {
if (gc != IntPtr.Zero) API.XFreeGC(API.DefaultDisplay, gc);
gc = API.XCreateGC(API.DefaultDisplay, window.WinHandle, IntPtr.Zero, IntPtr.Zero);
}
public override void Redraw(Bitmap framebuffer, Rectangle r) {
X11Window x11Win = (X11Window)window;
using (FastBitmap bmp = new FastBitmap(framebuffer, true, true)) {

View File

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

View File

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

View File

@ -6,28 +6,21 @@ using System.Runtime.InteropServices;
using System.Drawing;
using EventTime = System.Double;
namespace OpenTK.Platform.MacOS.Carbon
{
#region --- Types defined in MacTypes.h ---
namespace OpenTK.Platform.MacOS {
[StructLayout(LayoutKind.Sequential)]
public struct CarbonPoint
{
public struct CarbonPoint {
public short V;
public short H;
public CarbonPoint(int x, int y)
{
public CarbonPoint(int x, int y) {
V = (short)x;
H = (short)y;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct Rect
{
public struct Rect {
short top;
short left;
short bottom;
@ -40,21 +33,10 @@ namespace OpenTK.Platform.MacOS.Carbon
right = (short)(_left + _width);
}
public short X {
get { return left; }
}
public short Y {
get { return top; }
}
public short Width {
get { return (short)(right - left); }
}
public short Height {
get { return (short)(bottom - top); }
}
public short X { get { return left; } }
public short Y { get { return top; } }
public short Width { get { return (short)(right - left); } }
public short Height { get { return (short)(bottom - top); } }
public override string ToString() {
return string.Format(
@ -66,9 +48,6 @@ namespace OpenTK.Platform.MacOS.Carbon
}
}
#endregion
#region --- Types defined in HIGeometry.h ---
[StructLayout(LayoutKind.Sequential)]
public struct HIPoint {
public IntPtr xVal;
@ -118,10 +97,7 @@ namespace OpenTK.Platform.MacOS.Carbon
}
}
#endregion
public struct EventInfo {
public EventInfo(IntPtr eventRef) {
EventClass = API.GetEventClass(eventRef);
EventKind = API.GetEventKind(eventRef);
@ -129,10 +105,6 @@ namespace OpenTK.Platform.MacOS.Carbon
public uint EventKind;
public EventClass EventClass;
public override string ToString() {
return "Event: " + EventClass + ",kind: " + EventKind;
}
}
#region --- Types defined in CarbonEvents.h ---
@ -404,35 +376,24 @@ namespace OpenTK.Platform.MacOS.Carbon
}
#endregion
#region --- Enums from gestalt.h ---
public enum GestaltSelector
{
public enum GestaltSelector {
SystemVersion = 0x73797376, // FOUR_CHAR_CODE("sysv"), /* system version*/
SystemVersionMajor = 0x73797331, // FOUR_CHAR_CODE("sys1"), /* The major system version number; in 10.4.17 this would be the decimal value 10 */
SystemVersionMinor = 0x73797332, // FOUR_CHAR_CODE("sys2"), /* The minor system version number; in 10.4.17 this would be the decimal value 4 */
SystemVersionBugFix = 0x73797333, // FOUR_CHAR_CODE("sys3") /* The bug fix system version number; in 10.4.17 this would be the decimal value 17 */
};
#endregion
#region --- Process Manager ---
public enum ProcessApplicationTransformState : int
{
public enum ProcessApplicationTransformState : int {
kProcessTransformToForegroundApplication = 1,
}
public struct ProcessSerialNumber
{
public struct ProcessSerialNumber {
public ulong high;
public ulong low;
}
#endregion
public enum HICoordinateSpace
{
public enum HICoordinateSpace {
_72DPIGlobal = 1,
ScreenPixel = 2,
Window = 3,
@ -441,7 +402,7 @@ namespace OpenTK.Platform.MacOS.Carbon
#region --- Carbon API Methods ---
public class API
public static class API
{
const string carbon = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
@ -450,17 +411,11 @@ namespace OpenTK.Platform.MacOS.Carbon
[DllImport(carbon)]
public static extern uint GetEventKind(IntPtr inEvent);
#region --- Window Construction ---
[DllImport(carbon)]
public static extern OSStatus CreateNewWindow(WindowClass @class, WindowAttributes attributes, ref Rect r, out IntPtr window);
[DllImport(carbon)]
public static extern void DisposeWindow(IntPtr window);
#endregion
#region --- Showing / Hiding Windows ---
[DllImport(carbon)]
public static extern void ShowWindow(IntPtr window);
[DllImport(carbon)]
@ -470,9 +425,6 @@ namespace OpenTK.Platform.MacOS.Carbon
[DllImport(carbon)]
public static extern void SelectWindow(IntPtr window);
#endregion
#region --- Window Boundaries ---
[DllImport(carbon)]
public static extern OSStatus RepositionWindow(IntPtr window, IntPtr parentWindow, WindowPositionMethod method);
[DllImport(carbon)]
@ -482,23 +434,15 @@ namespace OpenTK.Platform.MacOS.Carbon
[DllImport(carbon)]
static extern OSStatus GetWindowBounds(IntPtr window, WindowRegionCode regionCode, out Rect globalBounds);
public static Rect GetWindowBounds(IntPtr window, WindowRegionCode regionCode)
{
public static Rect GetWindowBounds(IntPtr window, WindowRegionCode regionCode) {
Rect retval;
OSStatus error = GetWindowBounds(window, regionCode, out retval);
CheckReturn(error);
return retval;
}
//[DllImport(carbon)]
//public static extern void MoveWindow(IntPtr window, short hGlobal, short vGlobal, bool front);
#endregion
#region --- Processing Events ---
[DllImport(carbon)]
static extern IntPtr GetEventDispatcherTarget();
[DllImport(carbon,EntryPoint="ReceiveNextEvent")]
static extern OSStatus ReceiveNextEvent(uint inNumTypes,
IntPtr inList,
@ -745,11 +689,11 @@ namespace OpenTK.Platform.MacOS.Carbon
#region --- Process Manager ---
[DllImport(carbon)]
public static extern int TransformProcessType(ref Carbon.ProcessSerialNumber psn, ProcessApplicationTransformState type);
public static extern int TransformProcessType(ref ProcessSerialNumber psn, ProcessApplicationTransformState type);
[DllImport(carbon)]
public static extern int GetCurrentProcess(ref Carbon.ProcessSerialNumber psn);
public static extern int GetCurrentProcess(ref ProcessSerialNumber psn);
[DllImport(carbon)]
public static extern int SetFrontProcess(ref Carbon.ProcessSerialNumber psn);
public static extern int SetFrontProcess(ref ProcessSerialNumber psn);
#endregion
#region --- Setting Dock Tile ---
@ -932,12 +876,7 @@ namespace OpenTK.Platform.MacOS.Carbon
#endregion
const string gestaltlib = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
[DllImport(gestaltlib)]
public static extern OSStatus Gestalt(GestaltSelector selector, out int response);
}
#endregion
}

View File

@ -1,6 +1,6 @@
using System;
namespace OpenTK.Platform.MacOS.Carbon
namespace OpenTK.Platform.MacOS
{
public enum MacOSKeyCode
{
@ -109,9 +109,9 @@ namespace OpenTK.Platform.MacOS.Carbon
}
[Flags]
public enum MacOSKeyModifiers
{
public enum MacOSKeyModifiers {
None = 0,
Shift = 0x0200,
CapsLock = 0x0400,

View File

@ -143,20 +143,6 @@ namespace OpenTK.Platform.MacOS {
Application.WindowEventHandler = this;
}
void Activate() {
API.SelectWindow(WinHandle);
}
void Show() {
API.ShowWindow(WinHandle);
API.RepositionWindow(WinHandle, IntPtr.Zero, mPositionMethod);
API.SelectWindow(WinHandle);
}
void Hide() {
API.HideWindow(WinHandle);
}
internal void SetFullscreen(AglContext context) {
windowedBounds = bounds;
int width, height;
@ -546,14 +532,12 @@ namespace OpenTK.Platform.MacOS {
}
public override Point PointToClient(Point point) {
IntPtr handle = WinHandle;
Rect r = Carbon.API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion);
Rect r = API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion);
return new Point(point.X - r.X, point.Y - r.Y);
}
public override Point PointToScreen(Point point) {
IntPtr handle = WinHandle;
Rect r = Carbon.API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion);
Rect r = API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion);
return new Point(point.X + r.X, point.Y + r.Y);
}
@ -602,7 +586,7 @@ namespace OpenTK.Platform.MacOS {
byte r = (byte)((pixel >> 16) & 0xFF);
byte g = (byte)((pixel >> 8) & 0xFF);
byte b = (byte)(pixel & 0xFF);
data[index++] = (IntPtr)(a + (r << 8) + (g << 16) + (b << 24));
data[index++] = (IntPtr)(a | (r << 8) | (g << 16) | (b << 24));
}
else
{
@ -613,7 +597,9 @@ namespace OpenTK.Platform.MacOS {
fixed (IntPtr* ptr = data) {
IntPtr provider = API.CGDataProviderCreateWithData(IntPtr.Zero, (IntPtr)(void*)ptr, size * 4, IntPtr.Zero);
IntPtr image = API.CGImageCreate(128, 128, 8, 32, 4 * 128, API.CGColorSpaceCreateDeviceRGB(), 4, provider, IntPtr.Zero, 0, 0);
IntPtr colorSpace = API.CGColorSpaceCreateDeviceRGB();
IntPtr image = API.CGImageCreate(128, 128, 8, 32, 4 * 128,
colorSpace, 4, provider, IntPtr.Zero, 0, 0);
API.SetApplicationDockTileImage(image);
}
}
@ -622,10 +608,13 @@ namespace OpenTK.Platform.MacOS {
public override bool Visible {
get { return API.IsWindowVisible(WinHandle); }
set {
if (value && Visible == false)
Show();
else
Hide();
if (value && Visible == false) {
API.ShowWindow(WinHandle);
API.RepositionWindow(WinHandle, IntPtr.Zero, mPositionMethod);
API.SelectWindow(WinHandle);
} else {
API.HideWindow(WinHandle);
}
}
}
@ -678,13 +667,10 @@ namespace OpenTK.Platform.MacOS {
if (windowState == WindowState.Fullscreen)
return WindowState.Fullscreen;
if (Carbon.API.IsWindowCollapsed(WinHandle))
if (API.IsWindowCollapsed(WinHandle))
return WindowState.Minimized;
if (Carbon.API.IsWindowInStandardState(WinHandle)) {
if (API.IsWindowInStandardState(WinHandle))
return WindowState.Maximized;
}
return WindowState.Normal;
}
@ -695,10 +681,8 @@ namespace OpenTK.Platform.MacOS {
windowState = value;
if (oldState == WindowState.Fullscreen)
{
if (oldState == WindowState.Fullscreen) {
goWindowedHack = true;
// when returning from full screen, wait until the context is updated
// to actually do the work.
return;

View File

@ -14,162 +14,128 @@ using RECT = OpenTK.Platform.Windows.Win32Rectangle;
namespace OpenTK.Platform.Windows {
[SuppressUnmanagedCodeSecurity]
internal static class API {
[DllImport("shell32.dll")]
public static extern int SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID);
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
public static extern int SetCurrentProcessExplicitAppUserModelID(string AppID);
[DllImport("user32.dll"), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll")]
internal static extern bool SetWindowPos(IntPtr handle, IntPtr insertAfter, int x, int y, int cx, int cy, SetWindowPosFlags flags);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool AdjustWindowRect([In, Out] ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool AdjustWindowRectEx(ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern IntPtr CreateWindowEx(ExtendedWindowStyle ExStyle, IntPtr ClassAtom, IntPtr WindowName, WindowStyle Style,
int X, int Y, int Width, int Height, IntPtr HandleToParentWindow, IntPtr Menu, IntPtr Instance, IntPtr Param);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool DestroyWindow(IntPtr windowHandle);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern ushort RegisterClassEx(ref ExtendedWindowClass window_class);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern short UnregisterClass(IntPtr className, IntPtr instance);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
internal static extern int SetWindowLong(IntPtr hWnd, GetWindowLongOffsets nIndex, int dwNewLong);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
internal static extern uint GetWindowLong(IntPtr hWnd, GetWindowLongOffsets nIndex);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
internal static extern IntPtr GetForegroundWindow();
[DllImport("User32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, int flags);
[DllImport("user32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
internal static extern IntPtr SendMessage(IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
internal static extern bool PostMessage(IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
internal static extern IntPtr DispatchMessage(ref MSG msg);
[DllImport("User32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
internal static extern bool TranslateMessage(ref MSG lpMsg);
[DllImport("User32.dll", CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
public extern static IntPtr DefWindowProc(IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll"), SuppressUnmanagedCodeSecurity]
internal static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("user32.dll"), SuppressUnmanagedCodeSecurity]
internal static extern bool ReleaseDC(IntPtr hwnd, IntPtr DC);
[DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity]
internal static extern int ChoosePixelFormat(IntPtr dc, ref PixelFormatDescriptor pfd);
[DllImport("gdi32.dll"), SuppressUnmanagedCodeSecurity]
internal static extern int DescribePixelFormat(IntPtr deviceContext, int pixel, int pfdSize, ref PixelFormatDescriptor pixelFormat);
[DllImport("gdi32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern bool SetPixelFormat(IntPtr dc, int format, ref PixelFormatDescriptor pfd);
[DllImport("gdi32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern bool SwapBuffers(IntPtr dc);
[DllImport("kernel32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern IntPtr LoadLibrary(string dllName);
[DllImport("kernel32", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommand nCmdShow);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
//internal static extern bool ScreenToClient(IntPtr hWnd, ref POINT point);
internal static extern bool ScreenToClient(IntPtr hWnd, ref Point point);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
//internal static extern bool ClientToScreen(IntPtr hWnd, ref POINT point);
internal static extern bool ClientToScreen(IntPtr hWnd, ref Point point);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
internal extern static bool GetClientRect(IntPtr windowHandle, out Win32Rectangle clientRectangle);
[DllImport("user32.dll"), SuppressUnmanagedCodeSecurity]
public static extern bool IsWindowVisible(IntPtr intPtr);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool BringWindowToTop(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true, CharSet=CharSet.Auto), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll")]
public static extern bool IsWindowVisible(IntPtr intPtr);
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommand nCmdShow);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, int flags);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SendMessage(IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern bool PostMessage(IntPtr hWnd, WindowMessage Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr DispatchMessage(ref MSG msg);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern bool TranslateMessage(ref MSG lpMsg);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public extern static IntPtr DefWindowProc(IntPtr hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
internal static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("user32.dll")]
internal static extern bool ReleaseDC(IntPtr hwnd, IntPtr DC);
[DllImport("gdi32.dll")]
internal static extern int ChoosePixelFormat(IntPtr dc, ref PixelFormatDescriptor pfd);
[DllImport("gdi32.dll")]
internal static extern int DescribePixelFormat(IntPtr deviceContext, int pixel, int pfdSize, ref PixelFormatDescriptor pixelFormat);
[DllImport("gdi32.dll", SetLastError = true)]
internal static extern bool SetPixelFormat(IntPtr dc, int format, ref PixelFormatDescriptor pfd);
[DllImport("gdi32.dll", SetLastError = true)]
internal static extern bool SwapBuffers(IntPtr dc);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr LoadLibrary(string dllName);
[DllImport("kernel32", SetLastError = true)]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
[DllImport("user32.dll", SetLastError = true)]
//internal static extern bool ScreenToClient(IntPtr hWnd, ref POINT point);
internal static extern bool ScreenToClient(IntPtr hWnd, ref Point point);
[DllImport("user32.dll", SetLastError = true)]
//internal static extern bool ClientToScreen(IntPtr hWnd, ref POINT point);
internal static extern bool ClientToScreen(IntPtr hWnd, ref Point point);
[DllImport("user32.dll", SetLastError = true)]
internal extern static bool GetClientRect(IntPtr windowHandle, out Win32Rectangle clientRectangle);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool EnumDisplayDevices([MarshalAs(UnmanagedType.LPTStr)] string lpDevice,
int iDevNum, [In, Out] WindowsDisplayDevice lpDisplayDevice, uint dwFlags);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern bool EnumDisplaySettings([MarshalAs(UnmanagedType.LPTStr)] string device_name,
int graphics_mode, [In, Out] DeviceMode device_mode);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool OpenClipboard(IntPtr hWndNewOwner);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool EmptyClipboard();
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
public static extern bool CloseClipboard();
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetClipboardData(uint uFormat);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
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);
[DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity]
[DllImport("kernel32.dll")]
public static extern IntPtr GlobalFree(IntPtr hMem);
[DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity]
[DllImport("kernel32.dll")]
public static extern IntPtr GlobalLock(IntPtr hMem);
[DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity]
[DllImport("kernel32.dll")]
public static extern bool GlobalUnlock(IntPtr hMem);
[DllImport("user32.dll"), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll")]
public static extern IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll")]
internal static extern bool GetCursorPos(ref POINT point);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool SetCursorPos(int x, int y);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[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 ushort GetKeyState(int code);
[DllImport("user32.dll", SetLastError = true), SuppressUnmanagedCodeSecurity]
[DllImport("user32.dll", SetLastError = true)]
internal static extern uint MapVirtualKey(short vkey, MapVirtualKeyType uMapType);
}

View File

@ -4,6 +4,7 @@ using System.Security;
namespace OpenTK.Platform.Windows {
[SuppressUnmanagedCodeSecurity]
internal class Wgl : BindingsBase {
protected override IntPtr GetAddress(string funcname) {
@ -23,22 +24,22 @@ namespace OpenTK.Platform.Windows {
internal delegate int GetSwapIntervalEXT();
internal static GetSwapIntervalEXT wglGetSwapIntervalEXT;
[SuppressUnmanagedCodeSecurity,DllImport("OPENGL32.DLL", SetLastError = true)]
[DllImport("OPENGL32.DLL", SetLastError = true)]
internal extern static IntPtr wglCreateContext(IntPtr hDc);
[SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)]
[DllImport("OPENGL32.DLL", SetLastError = true)]
internal extern static Boolean wglDeleteContext(IntPtr oldContext);
[SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)]
[DllImport("OPENGL32.DLL", SetLastError = true)]
internal extern static IntPtr wglGetCurrentContext();
[SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)]
[DllImport("OPENGL32.DLL", SetLastError = true)]
internal extern static Boolean wglMakeCurrent(IntPtr hDc, IntPtr newContext);
[SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)]
[DllImport("OPENGL32.DLL", SetLastError = true)]
internal extern static IntPtr wglGetCurrentDC();
[SuppressUnmanagedCodeSecurity, DllImport("OPENGL32.DLL", SetLastError = true)]
[DllImport("OPENGL32.DLL", SetLastError = true)]
internal extern static IntPtr wglGetProcAddress(String lpszProc);
}
}

View File

@ -33,7 +33,7 @@ using System.Threading;
using OpenTK.Input;
namespace OpenTK.Platform.Windows {
internal sealed class WinWindow : INativeWindow {
public sealed class WinWindow : INativeWindow {
const ExtendedWindowStyle ParentStyleEx = ExtendedWindowStyle.WindowEdge | ExtendedWindowStyle.ApplicationWindow;
readonly IntPtr Instance = Marshal.GetHINSTANCE(typeof(WinWindow).Module);
readonly IntPtr ClassName = Marshal.StringToHGlobalAuto("CS_WindowClass");

View File

@ -23,193 +23,164 @@ using KeyCode = System.Byte; // Or maybe ushort?
namespace OpenTK.Platform.X11 {
[SuppressUnmanagedCodeSecurity]
public static class API {
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static IntPtr XOpenDisplay(IntPtr display);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XCloseDisplay(IntPtr display);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static IntPtr XCreateWindow(IntPtr display, IntPtr parent, int x, int y, int width, int height, int border_width, int depth, int xclass, IntPtr visual, IntPtr valuemask, ref XSetWindowAttributes attributes);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XMapWindow(IntPtr display, IntPtr window);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XUnmapWindow(IntPtr display, IntPtr window);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static IntPtr XRootWindow(IntPtr display, int screen_number);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static Bool XCheckWindowEvent(Display display, Window w, EventMask event_mask, ref XEvent event_return);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static Bool XCheckTypedWindowEvent(Display display, Window w, XEventName event_type, ref XEvent event_return);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XDestroyWindow(IntPtr display, IntPtr window);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XMapWindow(IntPtr display, IntPtr window);
[DllImport("libX11")]
public extern static int XUnmapWindow(IntPtr display, IntPtr window);
[DllImport("libX11")]
public extern static IntPtr XRootWindow(IntPtr display, int screen_number);
[DllImport("libX11")]
public extern static Bool XCheckWindowEvent(Display display, Window w, EventMask event_mask, ref XEvent event_return);
[DllImport("libX11")]
public extern static Bool XCheckTypedWindowEvent(Display display, Window w, XEventName event_type, ref XEvent event_return);
[DllImport("libX11")]
public extern static int XMoveResizeWindow(IntPtr display, IntPtr window, int x, int y, int width, int height);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XMoveWindow(IntPtr display, IntPtr w, int x, int y);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XResizeWindow(IntPtr display, IntPtr window, int width, int height);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XFlush(IntPtr display);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XStoreName(IntPtr display, IntPtr window, string window_name);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XFetchName(IntPtr display, IntPtr window, ref IntPtr window_name);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XSendEvent(IntPtr display, IntPtr window, bool propagate, IntPtr event_mask, ref XEvent send_event);
public static int XSendEvent(IntPtr display, IntPtr window, bool propagate, EventMask event_mask, ref XEvent send_event) {
return XSendEvent(display, window, propagate, new IntPtr((int)event_mask), ref send_event);
}
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static bool XQueryPointer(IntPtr display, IntPtr window, out IntPtr root, out IntPtr child, out int root_x, out int root_y, out int win_x, out int win_y, out int keys_buttons);
[DllImport("libX11")]
public extern static bool XQueryPointer(IntPtr display, IntPtr window, out IntPtr root, out IntPtr child,
out int root_x, out int root_y, out int win_x, out int win_y, out int keys_buttons);
[DllImport("libX11")]
public extern static uint XWarpPointer(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y,
uint src_width, uint src_height, int dest_x, int dest_y);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static uint XWarpPointer(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, uint src_width, uint src_height, int dest_x, int dest_y);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XFree(IntPtr data);
[DllImport("libX11")]
public static extern void XSync(Display display, bool discard);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XRaiseWindow(IntPtr display, IntPtr window);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static IntPtr XInternAtom(IntPtr display, string atom_name, bool only_if_exists);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XSetWMProtocols(IntPtr display, IntPtr window, IntPtr[] protocols, int count);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static bool XTranslateCoordinates(IntPtr display, IntPtr src_w, IntPtr dest_w, int src_x, int src_y, out int intdest_x_return, out int dest_y_return, out IntPtr child_return);
// Colormaps
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XDefaultDepth(IntPtr display, int screen_number);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XDefaultScreen(IntPtr display);
[DllImport("libX11")]
public static extern IntPtr XDefaultRootWindow(IntPtr display);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
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);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, int format, PropertyMode mode, IntPtr data, int nelements);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XDeleteProperty(IntPtr display, IntPtr window, IntPtr property);
[DllImport("libX11")]
public extern static int XGetWindowProperty(IntPtr display, IntPtr window, IntPtr atom, IntPtr long_offset, IntPtr long_length, bool delete, IntPtr req_type, out IntPtr actual_type, out int actual_format, out IntPtr nitems, out IntPtr bytes_after, ref IntPtr prop);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XDefineCursor(IntPtr display, IntPtr window, IntPtr cursor);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XUndefineCursor(IntPtr display, IntPtr window);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XFreeCursor(IntPtr display, IntPtr cursor);
// Drawing
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static IntPtr XCreateGC(IntPtr display, IntPtr window, IntPtr valuemask, IntPtr values);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XFreeGC(IntPtr display, IntPtr gc);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XGetWindowProperty(IntPtr display, IntPtr window, IntPtr atom, IntPtr long_offset, IntPtr long_length, bool delete, IntPtr req_type, out IntPtr actual_type, out int actual_format, out IntPtr nitems, out IntPtr bytes_after, ref IntPtr prop);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XIconifyWindow(IntPtr display, IntPtr window, int screen_number);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static IntPtr XCreatePixmapFromBitmapData(IntPtr display, IntPtr drawable, byte[] data, int width, int height, IntPtr fg, IntPtr bg, int depth);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static IntPtr XCreatePixmap(IntPtr display, IntPtr d, int width, int height, int depth);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask, ref XColor foregroundCol, ref XColor backgroundCol, int x_hot, int y_hot);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask,
ref XColor foregroundCol, ref XColor backgroundCol, int x_hot, int y_hot);
[DllImport("libX11")]
public extern static IntPtr XFreePixmap(IntPtr display, IntPtr pixmap);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XGetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints, out IntPtr supplied_return);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static void XSetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern IntPtr XGetWMHints(Display display, Window w); // returns XWMHints*
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern void XSetWMHints(Display display, Window w, ref XWMHints wmhints);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern IntPtr XAllocWMHints();
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static bool XkbSetDetectableAutoRepeat(IntPtr display, bool detectable, out bool supported);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern IntPtr XCreateColormap(Display display, Window window, IntPtr visual, int alloc);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public static extern Status XGetTransientForHint(Display display, Window w, out Window prop_window_return);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public static extern void XSync(Display display, bool discard);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public static extern IntPtr XDefaultRootWindow(IntPtr display);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern int XBitmapBitOrder(Display display);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern IntPtr XCreateImage(Display display, IntPtr visual,
uint depth, ImageFormat format, int offset, IntPtr data, int width, int height,
int bitmap_pad, int bytes_per_line);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern void XPutImage(Display display, IntPtr drawable,
IntPtr gc, IntPtr image, int src_x, int src_y, int dest_x, int dest_y, int width, int height);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern int XLookupString(ref XKeyEvent event_struct, [Out] byte[] buffer_return,
int bytes_buffer, [Out] KeySym[] keysym_return, IntPtr status_in_out);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern int XRefreshKeyboardMapping(ref XMappingEvent event_map);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static IntPtr XGetSelectionOwner(IntPtr display, IntPtr selection);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XConvertSelection(IntPtr display, IntPtr selection, IntPtr target, IntPtr property, IntPtr requestor, IntPtr time);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public extern static int XSetSelectionOwner(IntPtr display, IntPtr selection, IntPtr owner, IntPtr time);
static readonly IntPtr CopyFromParent = IntPtr.Zero;
internal static void SendNetWMMessage(X11Window window, IntPtr message_type, IntPtr l0, IntPtr l1, IntPtr l2)
{
internal static void SendNetWMMessage(X11Window window, IntPtr message_type, IntPtr l0, IntPtr l1, IntPtr l2) {
XEvent xev = new XEvent();
xev.ClientMessageEvent.type = XEventName.ClientMessage;
xev.ClientMessageEvent.send_event = true;
@ -224,8 +195,7 @@ namespace OpenTK.Platform.X11 {
EventMask.SubstructureRedirectMask | EventMask.SubstructureNotifyMask, ref xev);
}
internal static IntPtr CreatePixmapFromImage(Display display, System.Drawing.Bitmap image)
{
internal static IntPtr CreatePixmapFromImage(Display display, System.Drawing.Bitmap image) {
int width = image.Width, height = image.Height;
System.Drawing.Imaging.BitmapData data = image.LockBits(new System.Drawing.Rectangle(0, 0, width, height),
@ -246,18 +216,15 @@ namespace OpenTK.Platform.X11 {
return pixmap;
}
public static IntPtr CreateMaskFromImage(Display display, System.Drawing.Bitmap image)
{
public static IntPtr CreateMaskFromImage(Display display, System.Drawing.Bitmap image) {
int width = image.Width;
int height = image.Height;
int stride = (width + 7) >> 3;
byte[] mask = new byte[stride * height];
bool msbfirst = (XBitmapBitOrder(display) == 1); // 1 = MSBFirst
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
byte bit = (byte)(1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
int offset = y * stride + (x >> 3);
@ -270,80 +237,25 @@ namespace OpenTK.Platform.X11 {
mask, width, height, new IntPtr(1), IntPtr.Zero, 1);
}
const string XrandrLibrary = "libXrandr.so.2";
const string Xrandr = "libXrandr.so.2";
[DllImport(XrandrLibrary)]
[DllImport(Xrandr)]
public static extern XRRScreenConfiguration XRRGetScreenInfo(Display dpy, Drawable draw);
[DllImport(XrandrLibrary)]
[DllImport(Xrandr)]
public static extern void XRRFreeScreenConfigInfo(XRRScreenConfiguration config);
[DllImport(XrandrLibrary)]
public static extern Status XRRSetScreenConfig(Display dpy, XRRScreenConfiguration config,
Drawable draw, int size_index, ref ushort rotation, Time timestamp);
[DllImport(XrandrLibrary)]
public static extern Status XRRSetScreenConfigAndRate(Display dpy, XRRScreenConfiguration config,
Drawable draw, int size_index, ushort rotation, short rate, Time timestamp);
[DllImport(XrandrLibrary)]
[DllImport(Xrandr)]
public static extern ushort XRRConfigCurrentConfiguration(XRRScreenConfiguration config, out ushort rotation);
[DllImport(XrandrLibrary)]
[DllImport(Xrandr)]
public static extern short XRRConfigCurrentRate(XRRScreenConfiguration config);
[DllImport(XrandrLibrary)]
public static extern int XRRRootToScreen(Display dpy, Window root);
// the following are always safe to call, even if RandR is not implemented on a screen
[DllImport(XrandrLibrary)]
unsafe static extern XRRScreenSize* XRRSizes(Display dpy, int screen, int* nsizes);
[DllImport(Xrandr)]
public unsafe static extern XRRScreenSize* XRRSizes(Display dpy, int screen, int* nsizes);
public unsafe static XRRScreenSize[] XRRSizes(Display dpy, int screen) {
int count;
XRRScreenSize* data = XRRSizes(dpy, screen, &count);
if (count == 0) return null;
XRRScreenSize[] sizes = new XRRScreenSize[count];
for (int i = 0; i < count; i++)
sizes[i] = *data++;
return sizes;
}
[DllImport(XrandrLibrary)]
unsafe static extern short* XRRRates(Display dpy, int screen, int size_index, int* nrates);
public unsafe static short[] XRRRates(Display dpy, int screen, int size_index) {
int count;
short* data = XRRRates(dpy, screen, size_index, &count);
if (count == 0) return null;
short[] rates = new short[count];
for (int i = 0; i < count; i++)
rates[i] = *data++;
return rates;
}
[DllImport(XrandrLibrary)]
public static extern Time XRRTimes(Display dpy, int screen, out Time config_timestamp);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern int XScreenCount(Display display);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
unsafe static extern int* XListDepths(Display display, int screen_number, int* count_return);
public unsafe static int[] XListDepths(Display display, int screen_number) {
int count;
int* data = XListDepths(display, screen_number, &count);
if (count == 0) return null;
int[] depths = new int[count];
for (int i = 0; i < count; i++)
depths[i] = *data++;
return depths;
}
public static Display DefaultDisplay;
public static int DefaultScreen;
public static IntPtr RootWindow;
@ -369,14 +281,14 @@ namespace OpenTK.Platform.X11 {
}
}
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern KeySym XGetKeyboardMapping(Display display, KeyCode first_keycode, int keycode_count,
ref int keysyms_per_keycode_return);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern void XDisplayKeycodes(Display display, ref int min_keycodes_return, ref int max_keycodes_return);
[DllImport("libX11"), SuppressUnmanagedCodeSecurity]
[DllImport("libX11")]
public static extern KeySym XLookupKeysym(ref XKeyEvent key_event, int index);
}

View File

@ -50,6 +50,7 @@ namespace OpenTK.Platform.X11
#endregion
[SuppressUnmanagedCodeSecurity]
class Glx : BindingsBase
{
const string Library = "libGL.so.1";
@ -65,42 +66,42 @@ namespace OpenTK.Platform.X11
LoadDelegate("glXSwapIntervalSGI", out glXSwapIntervalSGI);
}
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public static extern bool glXIsDirect(IntPtr dpy, IntPtr context);
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public static extern IntPtr glXCreateContext(IntPtr dpy, ref XVisualInfo vis, IntPtr shareList, bool direct);
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public static extern void glXDestroyContext(IntPtr dpy, IntPtr context);
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public static extern IntPtr glXGetCurrentContext();
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public static extern bool glXMakeCurrent(IntPtr display, IntPtr drawable, IntPtr context);
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public static extern void glXSwapBuffers(IntPtr display, IntPtr drawable);
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public static extern IntPtr glXGetProcAddress([MarshalAs(UnmanagedType.LPTStr)] string procName);
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public static extern int glXGetConfig(IntPtr dpy, ref XVisualInfo vis, GLXAttribute attrib, out int value);
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public static extern IntPtr glXChooseVisual(IntPtr dpy, int screen, int[] attriblist);
// Returns an array of GLXFBConfig structures.
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public unsafe extern static IntPtr* glXChooseFBConfig(IntPtr dpy, int screen, int[] attriblist, out int fbount);
// Returns a pointer to an XVisualInfo structure.
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public unsafe extern static IntPtr glXGetVisualFromFBConfig(IntPtr dpy, IntPtr fbconfig);
[SuppressUnmanagedCodeSecurity, DllImport( Library )]
[DllImport(Library)]
public extern static bool glXQueryVersion(IntPtr dpy, ref int major, ref int minor);
[SuppressUnmanagedCodeSecurity]

View File

@ -75,24 +75,24 @@ namespace OpenTK.Platform.X11 {
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.
foreach (DisplayDevice dev in devices) {
int screen = (int)dev.Metadata;
XRRScreenSize[] sizes = API.XRRSizes(API.DefaultDisplay, screen);
if (sizes == null)
int screen = (int)dev.Metadata, count = 0;
XRRScreenSize* sizes = API.XRRSizes(API.DefaultDisplay, screen, &count);
if (count == 0)
throw new NotSupportedException("XRandR extensions not available.");
IntPtr screenConfig = API.XRRGetScreenInfo(API.DefaultDisplay, API.XRootWindow(API.DefaultDisplay, screen));
ushort curRotation;
int curSizesIndex = API.XRRConfigCurrentConfiguration(screenConfig, out curRotation);
int idx = API.XRRConfigCurrentConfiguration(screenConfig, out curRotation);
int curRefreshRate = API.XRRConfigCurrentRate(screenConfig);
int curDepth = API.XDefaultDepth(API.DefaultDisplay, screen);
API.XRRFreeScreenConfigInfo(screenConfig);
if (dev.Bounds == Rectangle.Empty)
dev.Bounds = new Rectangle(0, 0, sizes[curSizesIndex].Width, sizes[curSizesIndex].Height);
dev.Bounds = new Rectangle(0, 0, sizes[idx].Width, sizes[idx].Height);
dev.BitsPerPixel = curDepth;
dev.RefreshRate = curRefreshRate;
}