Open a different X11 display connection - reusing the one from Windows.Forms results in messages getting routed to the wrong windows.

This commit is contained in:
the_fiddler 2008-03-10 11:37:41 +00:00
parent f23d7929be
commit ac0209a575

View file

@ -82,23 +82,22 @@ namespace OpenTK.Platform.X11
//Utilities.ThrowOnX11Error = true; // Not very reliable //Utilities.ThrowOnX11Error = true; // Not very reliable
// We reuse the display connection of System.Windows.Forms. // We *cannot* reuse the display connection of System.Windows.Forms (events get mixed with Windows.Forms).
// TODO: Multiple screens. // TODO: Multiple screens.
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms"); //Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
window.Display = (IntPtr)xplatui.GetField("DisplayHandle", //window.Display = (IntPtr)xplatui.GetField("DisplayHandle",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null); // System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
window.RootWindow = (IntPtr)xplatui.GetField("RootWindow", //window.RootWindow = (IntPtr)xplatui.GetField("RootWindow",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null); // System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
window.Screen = (int)xplatui.GetField("ScreenNo", //window.Screen = (int)xplatui.GetField("ScreenNo",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null); // System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic).GetValue(null);
// Open the display 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.OpenDisplay(null); // null == default display //window.Display = API.DefaultDisplay; window.Display = API.OpenDisplay(null); // null == default display //window.Display = API.DefaultDisplay;
//if (window.Display == IntPtr.Zero) if (window.Display == IntPtr.Zero)
// throw new Exception("Could not open connection to X"); throw new Exception("Could not open connection to X");
window.Screen = Functions.XDefaultScreen(window.Display); //API.DefaultScreen;
//window.Screen = Functions.XDefaultScreen(window.Display); //API.DefaultScreen; window.RootWindow = Functions.XRootWindow(window.Display, window.Screen); // API.RootWindow;
//window.RootWindow = Functions.XRootWindow(window.Display, window.Screen); // API.RootWindow;
Debug.Print("Display: {0}, Screen {1}, Root window: {2}", window.Display, window.Screen, window.RootWindow); Debug.Print("Display: {0}, Screen {1}, Root window: {2}", window.Display, window.Screen, window.RootWindow);
RegisterAtoms(window); RegisterAtoms(window);
@ -663,9 +662,14 @@ namespace OpenTK.Platform.X11
{ {
if (!disposed) if (!disposed)
{ {
//Functions.XUnmapWindow(window.Display, window.WindowHandle); if (window != null)
if (window.WindowHandle != IntPtr.Zero) {
Functions.XDestroyWindow(window.Display, window.WindowHandle); if (window.WindowHandle != IntPtr.Zero)
Functions.XDestroyWindow(window.Display, window.WindowHandle);
if (window.Display != IntPtr.Zero)
Functions.XCloseDisplay(window.Display);
window = null;
}
if (manuallyCalled) if (manuallyCalled)
{ {