Simplify various stuff in X11 api.

This commit is contained in:
UnknownShadow200 2015-09-20 18:01:18 +10:00
parent 868a62230f
commit b0a180b1db
8 changed files with 41 additions and 171 deletions

View File

@ -34,7 +34,7 @@ namespace ClassicalSharp {
public virtual Vector3 CollisionSize { public virtual Vector3 CollisionSize {
get { return new Vector3( 8/16f, 28.5f/16f, 8/16f ); get { return new Vector3( 8/16f, 28.5f/16f, 8/16f );
//Model.CollisionSize; TODO: for non humanoid models, we also need to offset eye position. //Model.CollisionSize; TODO: for non humanoid models
} }
} }

View File

@ -613,28 +613,6 @@ namespace OpenTK.Platform.Windows {
DECIMAL = 0x6E, DECIMAL = 0x6E,
DIVIDE = 0x6F, DIVIDE = 0x6F,
F1 = 0x70, F1 = 0x70,
F2 = 0x71,
F3 = 0x72,
F4 = 0x73,
F5 = 0x74,
F6 = 0x75,
F7 = 0x76,
F8 = 0x77,
F9 = 0x78,
F10 = 0x79,
F11 = 0x7A,
F12 = 0x7B,
F13 = 0x7C,
F14 = 0x7D,
F15 = 0x7E,
F16 = 0x7F,
F17 = 0x80,
F18 = 0x81,
F19 = 0x82,
F20 = 0x83,
F21 = 0x84,
F22 = 0x85,
F23 = 0x86,
F24 = 0x87, F24 = 0x87,
NUMLOCK = 0x90, NUMLOCK = 0x90,

View File

@ -191,41 +191,7 @@ namespace OpenTK.Platform.X11 {
* function key groups on the left and/or right sides of the keyboard. * function key groups on the left and/or right sides of the keyboard.
* We've not found a keyboard with more than 35 function keys total. * We've not found a keyboard with more than 35 function keys total.
*/ */
F1 = 0xffbe, F1 = 0xffbe,
F2 = 0xffbf,
F3 = 0xffc0,
F4 = 0xffc1,
F5 = 0xffc2,
F6 = 0xffc3,
F7 = 0xffc4,
F8 = 0xffc5,
F9 = 0xffc6,
F10 = 0xffc7,
F11 = 0xffc8,
F12 = 0xffc9,
F13 = 0xffca,
F14 = 0xffcb,
F15 = 0xffcc,
F16 = 0xffcd,
F17 = 0xffce,
F18 = 0xffcf,
F19 = 0xffd0,
F20 = 0xffd1,
F21 = 0xffd2,
F22 = 0xffd3,
F23 = 0xffd4,
F24 = 0xffd5,
F25 = 0xffd6,
F26 = 0xffd7,
F27 = 0xffd8,
F28 = 0xffd9,
F29 = 0xffda,
F30 = 0xffdb,
F31 = 0xffdc,
F32 = 0xffdd,
F33 = 0xffde,
F34 = 0xffdf,
F35 = 0xffe0, F35 = 0xffe0,
/* Modifiers */ /* Modifiers */
@ -243,8 +209,6 @@ namespace OpenTK.Platform.X11 {
Alt_R = 0xffea, /* Right alt */ Alt_R = 0xffea, /* Right alt */
Super_L = 0xffeb, /* Left super */ Super_L = 0xffeb, /* Left super */
Super_R = 0xffec, /* Right super */ Super_R = 0xffec, /* Right super */
Hyper_L = 0xffed, /* Left hyper */
Hyper_R = 0xffee, /* Right hyper */
/* /*
* Latin 1 * Latin 1
@ -287,30 +251,6 @@ namespace OpenTK.Platform.X11 {
question = 0x003f, /* U+003F QUESTION MARK */ question = 0x003f, /* U+003F QUESTION MARK */
at = 0x0040, /* U+0040 COMMERCIAL AT */ at = 0x0040, /* U+0040 COMMERCIAL AT */
A = 0x0041, /* U+0041 LATIN CAPITAL LETTER A */ A = 0x0041, /* U+0041 LATIN CAPITAL LETTER A */
B = 0x0042, /* U+0042 LATIN CAPITAL LETTER B */
C = 0x0043, /* U+0043 LATIN CAPITAL LETTER C */
D = 0x0044, /* U+0044 LATIN CAPITAL LETTER D */
E = 0x0045, /* U+0045 LATIN CAPITAL LETTER E */
F = 0x0046, /* U+0046 LATIN CAPITAL LETTER F */
G = 0x0047, /* U+0047 LATIN CAPITAL LETTER G */
H = 0x0048, /* U+0048 LATIN CAPITAL LETTER H */
I = 0x0049, /* U+0049 LATIN CAPITAL LETTER I */
J = 0x004a, /* U+004A LATIN CAPITAL LETTER J */
K = 0x004b, /* U+004B LATIN CAPITAL LETTER K */
L = 0x004c, /* U+004C LATIN CAPITAL LETTER L */
M = 0x004d, /* U+004D LATIN CAPITAL LETTER M */
N = 0x004e, /* U+004E LATIN CAPITAL LETTER N */
O = 0x004f, /* U+004F LATIN CAPITAL LETTER O */
P = 0x0050, /* U+0050 LATIN CAPITAL LETTER P */
Q = 0x0051, /* U+0051 LATIN CAPITAL LETTER Q */
R = 0x0052, /* U+0052 LATIN CAPITAL LETTER R */
S = 0x0053, /* U+0053 LATIN CAPITAL LETTER S */
T = 0x0054, /* U+0054 LATIN CAPITAL LETTER T */
U = 0x0055, /* U+0055 LATIN CAPITAL LETTER U */
V = 0x0056, /* U+0056 LATIN CAPITAL LETTER V */
W = 0x0057, /* U+0057 LATIN CAPITAL LETTER W */
X = 0x0058, /* U+0058 LATIN CAPITAL LETTER X */
Y = 0x0059, /* U+0059 LATIN CAPITAL LETTER Y */
Z = 0x005a, /* U+005A LATIN CAPITAL LETTER Z */ Z = 0x005a, /* U+005A LATIN CAPITAL LETTER Z */
bracketleft = 0x005b, /* U+005B LEFT SQUARE BRACKET */ bracketleft = 0x005b, /* U+005B LEFT SQUARE BRACKET */
backslash = 0x005c, /* U+005C REVERSE SOLIDUS */ backslash = 0x005c, /* U+005C REVERSE SOLIDUS */
@ -320,30 +260,6 @@ namespace OpenTK.Platform.X11 {
grave = 0x0060, /* U+0060 GRAVE ACCENT */ grave = 0x0060, /* U+0060 GRAVE ACCENT */
quoteleft = 0x0060, /* deprecated */ quoteleft = 0x0060, /* deprecated */
a = 0x0061, /* U+0061 LATIN SMALL LETTER A */ a = 0x0061, /* U+0061 LATIN SMALL LETTER A */
b = 0x0062, /* U+0062 LATIN SMALL LETTER B */
c = 0x0063, /* U+0063 LATIN SMALL LETTER C */
d = 0x0064, /* U+0064 LATIN SMALL LETTER D */
e = 0x0065, /* U+0065 LATIN SMALL LETTER E */
f = 0x0066, /* U+0066 LATIN SMALL LETTER F */
g = 0x0067, /* U+0067 LATIN SMALL LETTER G */
h = 0x0068, /* U+0068 LATIN SMALL LETTER H */
i = 0x0069, /* U+0069 LATIN SMALL LETTER I */
j = 0x006a, /* U+006A LATIN SMALL LETTER J */
k = 0x006b, /* U+006B LATIN SMALL LETTER K */
l = 0x006c, /* U+006C LATIN SMALL LETTER L */
m = 0x006d, /* U+006D LATIN SMALL LETTER M */
n = 0x006e, /* U+006E LATIN SMALL LETTER N */
o = 0x006f, /* U+006F LATIN SMALL LETTER O */
p = 0x0070, /* U+0070 LATIN SMALL LETTER P */
q = 0x0071, /* U+0071 LATIN SMALL LETTER Q */
r = 0x0072, /* U+0072 LATIN SMALL LETTER R */
s = 0x0073, /* U+0073 LATIN SMALL LETTER S */
t = 0x0074, /* U+0074 LATIN SMALL LETTER T */
u = 0x0075, /* U+0075 LATIN SMALL LETTER U */
v = 0x0076, /* U+0076 LATIN SMALL LETTER V */
w = 0x0077, /* U+0077 LATIN SMALL LETTER W */
x = 0x0078, /* U+0078 LATIN SMALL LETTER X */
y = 0x0079, /* U+0079 LATIN SMALL LETTER Y */
z = 0x007a, /* U+007A LATIN SMALL LETTER Z */ z = 0x007a, /* U+007A LATIN SMALL LETTER Z */
braceleft = 0x007b, /* U+007B LEFT CURLY BRACKET */ braceleft = 0x007b, /* U+007B LEFT CURLY BRACKET */
bar = 0x007c, /* U+007C VERTICAL LINE */ bar = 0x007c, /* U+007C VERTICAL LINE */

View File

@ -23,15 +23,9 @@ using KeyCode = System.Byte; // Or maybe ushort?
namespace OpenTK.Platform.X11 { namespace OpenTK.Platform.X11 {
internal static class API { internal static class API {
internal static readonly object Lock = new object();
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static IntPtr XOpenDisplay(IntPtr display); public extern static IntPtr XOpenDisplay(IntPtr display);
public static IntPtr XOpenDisplay_Safe(IntPtr display) {
lock (Lock) {
return XOpenDisplay(display);
}
}
[DllImport("libX11"), SuppressUnmanagedCodeSecurity] [DllImport("libX11"), SuppressUnmanagedCodeSecurity]
public extern static int XCloseDisplay(IntPtr display); public extern static int XCloseDisplay(IntPtr display);
@ -355,27 +349,24 @@ namespace OpenTK.Platform.X11 {
return depths; return depths;
} }
static Display defaultDisplay; internal static Display DefaultDisplay;
static int screenCount; internal static int ScreenCount;
internal static Display DefaultDisplay { get { return defaultDisplay; } }
internal static int ScreenCount { get { return screenCount; } }
static API() { static API() {
defaultDisplay = API.XOpenDisplay_Safe(IntPtr.Zero); DefaultDisplay = API.XOpenDisplay(IntPtr.Zero);
if (defaultDisplay == IntPtr.Zero) if (DefaultDisplay == IntPtr.Zero)
throw new PlatformException("Could not establish connection to the X-Server."); throw new PlatformException("Could not establish connection to the X-Server.");
screenCount = API.XScreenCount(DefaultDisplay); ScreenCount = API.XScreenCount(DefaultDisplay);
Debug.Print("Display connection: {0}, Screen count: {1}", DefaultDisplay, ScreenCount); Debug.Print("Display connection: {0}, Screen count: {1}", DefaultDisplay, ScreenCount);
//AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); //AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
} }
static void CurrentDomain_ProcessExit(object sender, EventArgs e) { static void CurrentDomain_ProcessExit(object sender, EventArgs e) {
if (defaultDisplay != IntPtr.Zero) { if (DefaultDisplay != IntPtr.Zero) {
API.XCloseDisplay(defaultDisplay); API.XCloseDisplay(DefaultDisplay);
defaultDisplay = IntPtr.Zero; DefaultDisplay = IntPtr.Zero;
} }
} }

View File

@ -110,8 +110,7 @@ namespace OpenTK.Platform.X11 {
Debug.Print("[Warning] XRandR returned an invalid resolution ({0}) for display device {1}", size, screen); Debug.Print("[Warning] XRandR returned an invalid resolution ({0}) for display device {1}", size, screen);
continue; continue;
} }
short[] rates = null; short[] rates = API.XRRRates(API.DefaultDisplay, screen, resolution_count);
rates = API.XRRRates(API.DefaultDisplay, screen, resolution_count);
// It seems that XRRRates returns 0 for modes that are larger than the screen // It seems that XRRRates returns 0 for modes that are larger than the screen
// can support, as well as for all supported modes. On Ubuntu 7.10 the tool // can support, as well as for all supported modes. On Ubuntu 7.10 the tool
@ -172,11 +171,10 @@ namespace OpenTK.Platform.X11 {
} }
static float FindCurrentRefreshRate(int screen) { static float FindCurrentRefreshRate(int screen) {
short rate = 0;
IntPtr screen_config = API.XRRGetScreenInfo(API.DefaultDisplay, API.XRootWindow(API.DefaultDisplay, screen)); IntPtr screen_config = API.XRRGetScreenInfo(API.DefaultDisplay, API.XRootWindow(API.DefaultDisplay, screen));
ushort rotation = 0; ushort rotation = 0;
int size = API.XRRConfigCurrentConfiguration(screen_config, out rotation); int size = API.XRRConfigCurrentConfiguration(screen_config, out rotation);
rate = API.XRRConfigCurrentRate(screen_config); short rate = API.XRRConfigCurrentRate(screen_config);
API.XRRFreeScreenConfigInfo(screen_config); API.XRRFreeScreenConfigInfo(screen_config);
return (float)rate; return (float)rate;
} }

View File

@ -71,14 +71,12 @@ namespace OpenTK.Platform.X11 {
info.Screen = currentWindow.Screen; info.Screen = currentWindow.Screen;
int items; int items;
lock (API.Lock) {
IntPtr vs = API.XGetVisualInfo(Display, XVisualInfoMask.ID | XVisualInfoMask.Screen, ref info, out items); IntPtr vs = API.XGetVisualInfo(Display, XVisualInfoMask.ID | XVisualInfoMask.Screen, ref info, out items);
if (items == 0) if (items == 0)
throw new GraphicsModeException(String.Format("Invalid GraphicsMode specified ({0}).", mode)); throw new GraphicsModeException(String.Format("Invalid GraphicsMode specified ({0}).", mode));
info = (XVisualInfo)Marshal.PtrToStructure(vs, typeof(XVisualInfo)); info = (XVisualInfo)Marshal.PtrToStructure(vs, typeof(XVisualInfo));
API.XFree(vs); API.XFree(vs);
}
return info; return info;
} }

View File

@ -45,8 +45,6 @@ namespace OpenTK.Platform.X11 {
const int _min_width = 30, _min_height = 30; const int _min_width = 30, _min_height = 30;
X11WindowInfo window = new X11WindowInfo(); X11WindowInfo window = new X11WindowInfo();
const string MOTIF_WM_ATOM = "_MOTIF_WM_HINTS";
// The Atom class from Mono might be useful to avoid calling XInternAtom by hand (somewhat error prone). // The Atom class from Mono might be useful to avoid calling XInternAtom by hand (somewhat error prone).
IntPtr wm_destroy; IntPtr wm_destroy;
@ -63,6 +61,7 @@ namespace OpenTK.Platform.X11 {
IntPtr net_wm_icon; IntPtr net_wm_icon;
IntPtr net_frame_extents; IntPtr net_frame_extents;
IntPtr motif_wm_hints;
static readonly IntPtr xa_cardinal = (IntPtr)6; static readonly IntPtr xa_cardinal = (IntPtr)6;
static readonly IntPtr _remove = (IntPtr)0; static readonly IntPtr _remove = (IntPtr)0;
@ -102,7 +101,7 @@ namespace OpenTK.Platform.X11 {
Debug.Print("Creating X11GLNative window."); Debug.Print("Creating X11GLNative window.");
// Open a display connection to the X server, and obtain the screen and root window. // Open a display connection to the X server, and obtain the screen and root window.
window.Display = API.XOpenDisplay_Safe(IntPtr.Zero); window.Display = API.DefaultDisplay;
if (window.Display == IntPtr.Zero) if (window.Display == IntPtr.Zero)
throw new PlatformException("Could not open connection to X"); throw new PlatformException("Could not open connection to X");
@ -211,6 +210,7 @@ namespace OpenTK.Platform.X11 {
net_wm_action_maximize_vertically = API.XInternAtom(window.Display, "_NET_WM_ACTION_MAXIMIZE_VERT", false); net_wm_action_maximize_vertically = API.XInternAtom(window.Display, "_NET_WM_ACTION_MAXIMIZE_VERT", false);
net_wm_icon = API.XInternAtom(window.Display, "_NEW_WM_ICON", false); net_wm_icon = API.XInternAtom(window.Display, "_NEW_WM_ICON", false);
net_frame_extents = API.XInternAtom(window.Display, "_NET_FRAME_EXTENTS", false); net_frame_extents = API.XInternAtom(window.Display, "_NET_FRAME_EXTENTS", false);
motif_wm_hints = API.XInternAtom(window.Display, "_MOTIF_WM_HINTS", true);
} }
void SetWindowMinMax(short min_width, short min_height, short max_width, short max_height) { void SetWindowMinMax(short min_width, short min_height, short max_width, short max_height) {
@ -253,11 +253,8 @@ namespace OpenTK.Platform.X11 {
bool IsWindowBorderHidden { bool IsWindowBorderHidden {
get { get {
IntPtr prop = IntPtr.Zero;
// Test if decorations have been disabled through Motif. // Test if decorations have been disabled through Motif.
IntPtr motif_hints_atom = API.XInternAtom(this.window.Display, MOTIF_WM_ATOM, true); if (motif_wm_hints != IntPtr.Zero) {
if (motif_hints_atom != IntPtr.Zero) {
// TODO: How to check if MotifWMHints decorations have been really disabled? // TODO: How to check if MotifWMHints decorations have been really disabled?
if (_decorations_hidden) if (_decorations_hidden)
return true; return true;
@ -291,7 +288,7 @@ namespace OpenTK.Platform.X11 {
} }
bool DisableMotifDecorations() { bool DisableMotifDecorations() {
IntPtr atom = API.XInternAtom(this.window.Display, MOTIF_WM_ATOM, true); IntPtr atom = motif_wm_hints;
if (atom != IntPtr.Zero) { if (atom != IntPtr.Zero) {
//Functions.XGetWindowProperty(window.Display, window.WindowHandle, atom, IntPtr.Zero, IntPtr.Zero, false, //Functions.XGetWindowProperty(window.Display, window.WindowHandle, atom, IntPtr.Zero, IntPtr.Zero, false,
MotifWmHints hints = new MotifWmHints(); MotifWmHints hints = new MotifWmHints();
@ -317,7 +314,7 @@ namespace OpenTK.Platform.X11 {
} }
bool EnableMotifDecorations() { bool EnableMotifDecorations() {
IntPtr atom = API.XInternAtom(this.window.Display, MOTIF_WM_ATOM, true); IntPtr atom = motif_wm_hints;
if (atom != IntPtr.Zero) { if (atom != IntPtr.Zero) {
//Functions.XDeleteProperty(this.window.Display, this.Handle, atom); //Functions.XDeleteProperty(this.window.Display, this.Handle, atom);
MotifWmHints hints = new MotifWmHints(); MotifWmHints hints = new MotifWmHints();
@ -365,11 +362,6 @@ namespace OpenTK.Platform.X11 {
borderRight = Marshal.ReadIntPtr(prop, IntPtr.Size).ToInt32(); borderRight = Marshal.ReadIntPtr(prop, IntPtr.Size).ToInt32();
borderTop = Marshal.ReadIntPtr(prop, IntPtr.Size * 2).ToInt32(); borderTop = Marshal.ReadIntPtr(prop, IntPtr.Size * 2).ToInt32();
borderBottom = Marshal.ReadIntPtr(prop, IntPtr.Size * 3).ToInt32(); borderBottom = Marshal.ReadIntPtr(prop, IntPtr.Size * 3).ToInt32();
//Debug.WriteLine(border_left);
//Debug.WriteLine(border_right);
//Debug.WriteLine(border_top);
//Debug.WriteLine(border_bottom);
} }
API.XFree(prop); API.XFree(prop);
} }
@ -390,7 +382,7 @@ namespace OpenTK.Platform.X11 {
Size newSize = new Size( Size newSize = new Size(
e.ConfigureEvent.width + borderLeft + borderRight, e.ConfigureEvent.width + borderLeft + borderRight,
e.ConfigureEvent.height + borderTop + borderBottom); e.ConfigureEvent.height + borderTop + borderBottom);
if (Bounds.Size != newSize) { if (bounds.Size != newSize) {
bounds.Size = newSize; bounds.Size = newSize;
client_rectangle.Size = new Size(e.ConfigureEvent.width, e.ConfigureEvent.height); client_rectangle.Size = new Size(e.ConfigureEvent.width, e.ConfigureEvent.height);

View File

@ -65,7 +65,7 @@ namespace OpenTK.Platform.X11
// See http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.opengl/doc/openglrf/glXChooseFBConfig.htm // See http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.opengl/doc/openglrf/glXChooseFBConfig.htm
// 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.
IntPtr SelectVisualUsingFBConfig( int[] visualAttribs ) { unsafe IntPtr SelectVisualUsingFBConfig( int[] visualAttribs ) {
// Select a visual that matches the parameters set by the user. // Select a visual that matches the parameters set by the user.
IntPtr display = API.DefaultDisplay; IntPtr display = API.DefaultDisplay;
IntPtr visual = IntPtr.Zero; IntPtr visual = IntPtr.Zero;
@ -74,8 +74,6 @@ namespace OpenTK.Platform.X11
IntPtr root = API.XRootWindow(display, screen); IntPtr root = API.XRootWindow(display, screen);
Debug.Print("Display: {0}, Screen: {1}, RootWindow: {2}", display, screen, root); Debug.Print("Display: {0}, Screen: {1}, RootWindow: {2}", display, screen, root);
unsafe
{
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).
@ -86,7 +84,6 @@ namespace OpenTK.Platform.X11
visual = Glx.glXGetVisualFromFBConfig(display, *fbconfigs); visual = Glx.glXGetVisualFromFBConfig(display, *fbconfigs);
API.XFree((IntPtr)fbconfigs); API.XFree((IntPtr)fbconfigs);
} }
}
} catch (EntryPointNotFoundException) { } catch (EntryPointNotFoundException) {
Debug.Print("Function glXChooseFBConfig not supported."); Debug.Print("Function glXChooseFBConfig not supported.");
return IntPtr.Zero; return IntPtr.Zero;