From 93bfa847ff26d677acdb1994ce37b60c8b02db12 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sat, 11 Sep 2010 15:39:21 +0200 Subject: [PATCH] Made invisible cursor object shared by windows. --- src/x11/platform.h | 2 +- src/x11/x11_init.c | 38 ++++++++++++++++++++++++++++++++++++++ src/x11/x11_window.c | 41 +---------------------------------------- 3 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/x11/platform.h b/src/x11/platform.h index e98f0fab..8cf160f9 100644 --- a/src/x11/platform.h +++ b/src/x11/platform.h @@ -208,7 +208,6 @@ typedef struct _GLFWwindowX11 Atom wmState; // _NET_WM_STATE atom Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom Atom wmActiveWindow; // _NET_ACTIVE_WINDOW atom - Cursor cursor; // Invisible cursor for hidden cursor // Various platform specific internal variables GLboolean hasEWMH; // True if window manager supports EWMH @@ -230,6 +229,7 @@ typedef struct _GLFWlibraryX11 Display* display; int screen; Window root; + Cursor cursor; // Invisible cursor for hidden cursor // Server-side GLX version int glxMajor, glxMinor; diff --git a/src/x11/x11_init.c b/src/x11/x11_init.c index 089f81f3..6c9793f8 100644 --- a/src/x11/x11_init.c +++ b/src/x11/x11_init.c @@ -139,12 +139,48 @@ static GLboolean initDisplay(void) } +//======================================================================== +// Create a blank cursor (for locked mouse mode) +//======================================================================== + +static Cursor createNULLCursor(void) +{ + Pixmap cursormask; + XGCValues xgc; + GC gc; + XColor col; + Cursor cursor; + + // TODO: Add error checks + + cursormask = XCreatePixmap(_glfwLibrary.X11.display, _glfwLibrary.X11.root, 1, 1, 1); + xgc.function = GXclear; + gc = XCreateGC(_glfwLibrary.X11.display, cursormask, GCFunction, &xgc); + XFillRectangle(_glfwLibrary.X11.display, cursormask, gc, 0, 0, 1, 1); + col.pixel = 0; + col.red = 0; + col.flags = 4; + cursor = XCreatePixmapCursor(_glfwLibrary.X11.display, cursormask, cursormask, + &col, &col, 0, 0); + XFreePixmap(_glfwLibrary.X11.display, cursormask); + XFreeGC(_glfwLibrary.X11.display, gc); + + return cursor; +} + + //======================================================================== // Terminate X11 display //======================================================================== static void terminateDisplay(void) { + if (_glfwLibrary.X11.cursor) + { + XFreeCursor(_glfwLibrary.X11.display, _glfwLibrary.X11.cursor); + _glfwLibrary.X11.cursor = (Cursor) 0; + } + if (_glfwLibrary.X11.display) { XCloseDisplay(_glfwLibrary.X11.display); @@ -166,6 +202,8 @@ int _glfwPlatformInit(void) if (!initDisplay()) return GL_FALSE; + _glfwLibrary.X11.cursor = createNULLCursor(); + // Try to load libGL.so if necessary initLibraries(); diff --git a/src/x11/x11_window.c b/src/x11/x11_window.c index 2c97c68d..8fee22e5 100644 --- a/src/x11/x11_window.c +++ b/src/x11/x11_window.c @@ -347,36 +347,6 @@ static int translateChar(XKeyEvent* event) } -//======================================================================== -// Create a blank cursor (for locked mouse mode) -//======================================================================== - -static Cursor createNULLCursor(Display* display, Window root) -{ - Pixmap cursormask; - XGCValues xgc; - GC gc; - XColor col; - Cursor cursor; - - // TODO: Add error checks - - cursormask = XCreatePixmap(display, root, 1, 1, 1); - xgc.function = GXclear; - gc = XCreateGC(display, cursormask, GCFunction, &xgc); - XFillRectangle(display, cursormask, gc, 0, 0, 1, 1); - col.pixel = 0; - col.red = 0; - col.flags = 4; - cursor = XCreatePixmapCursor(display, cursormask, cursormask, - &col,&col, 0,0); - XFreePixmap(display, cursormask); - XFreeGC(display, gc); - - return cursor; -} - - //======================================================================== // Returns the specified attribute of the specified GLXFBConfig // NOTE: Do not call this unless we have found GLX 1.3+ or GLX_SGIX_fbconfig @@ -1409,9 +1379,6 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, window->refreshRate = wndconfig->refreshRate; window->windowNoResize = wndconfig->windowNoResize; - // Create the invisible cursor for hidden cursor mode - window->X11.cursor = createNULLCursor(_glfwLibrary.X11.display, _glfwLibrary.X11.root); - initGLXExtensions(window); // Choose the best available fbconfig @@ -1534,12 +1501,6 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) XFreeColormap(_glfwLibrary.X11.display, window->X11.colormap); window->X11.colormap = (Colormap) 0; } - - if (window->X11.cursor) - { - XFreeCursor(_glfwLibrary.X11.display, window->X11.cursor); - window->X11.cursor = (Cursor) 0; - } } @@ -1838,7 +1799,7 @@ void _glfwPlatformHideMouseCursor(_GLFWwindow* window) // Hide cursor if (!window->X11.pointerHidden) { - XDefineCursor(_glfwLibrary.X11.display, window->X11.handle, window->X11.cursor); + XDefineCursor(_glfwLibrary.X11.display, window->X11.handle, _glfwLibrary.X11.cursor); window->X11.pointerHidden = GL_TRUE; }