From 527cdf862238c39bedc6322c33e3d740988f9513 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Wed, 20 Oct 2010 09:19:34 +0000 Subject: [PATCH] * Source/OpenTK/Platform/X11/X11GLNative.cs: Refactored empty cursor creation into its own function. Create one empty cursor for the lifetime of the window. --- Source/OpenTK/Platform/X11/X11GLNative.cs | 35 +++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/Source/OpenTK/Platform/X11/X11GLNative.cs b/Source/OpenTK/Platform/X11/X11GLNative.cs index 054b7c66..4277c54e 100644 --- a/Source/OpenTK/Platform/X11/X11GLNative.cs +++ b/Source/OpenTK/Platform/X11/X11GLNative.cs @@ -113,6 +113,8 @@ namespace OpenTK.Platform.X11 readonly char[] chars = new char[16]; readonly KeyPressEventArgs KPEventArgs = new KeyPressEventArgs('\0'); + readonly IntPtr EmptyCursor; + #endregion #region Constructors @@ -195,6 +197,8 @@ namespace OpenTK.Platform.X11 driver = new X11Input(window); + EmptyCursor = CreateEmptyCursor(window); + Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle)); Debug.Unindent(); @@ -677,6 +681,22 @@ namespace OpenTK.Platform.X11 } } + static IntPtr CreateEmptyCursor(X11WindowInfo window) + { + IntPtr cursor = IntPtr.Zero; + using (new XLock(window.Display)) + { + XColor black, dummy; + IntPtr cmap = Functions.XDefaultColormap(window.Display, window.Screen); + Functions.XAllocNamedColor(window.Display, cmap, "black", out black, out dummy); + IntPtr bmp_empty = Functions.XCreateBitmapFromData(window.Display, + window.WindowHandle, new byte[,] { { 0 } }); + cursor = Functions.XCreatePixmapCursor(window.Display, + bmp_empty, bmp_empty, ref black, ref black, 0, 0); + } + return cursor; + } + #endregion #region INativeWindow Members @@ -1302,7 +1322,7 @@ namespace OpenTK.Platform.X11 public bool CursorVisible { - get { return true; } + get { return true; } // Not used set { if (value) @@ -1316,17 +1336,7 @@ namespace OpenTK.Platform.X11 { using (new XLock(window.Display)) { - XColor black, dummy; - IntPtr cmap = Functions.XDefaultColormap(window.Display, window.Screen); - Functions.XAllocNamedColor(window.Display, cmap, "black", out black, out dummy); - IntPtr bmp_empty = Functions.XCreateBitmapFromData(window.Display, - window.WindowHandle, new byte[,] { { 0 } }); - IntPtr cursor_empty = Functions.XCreatePixmapCursor(window.Display, - bmp_empty, bmp_empty, ref black, ref black, 0, 0); - - Functions.XDefineCursor(window.Display, window.WindowHandle, cursor_empty); - - Functions.XFreeCursor(window.Display, cursor_empty); + Functions.XDefineCursor(window.Display, window.WindowHandle, EmptyCursor); } } } @@ -1553,6 +1563,7 @@ namespace OpenTK.Platform.X11 { using (new XLock(window.Display)) { + Functions.XFreeCursor(window.Display, EmptyCursor); Functions.XDestroyWindow(window.Display, window.WindowHandle); }