mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-26 20:28:49 -05:00
Made invisible cursor object shared by windows.
This commit is contained in:
parent
93979781af
commit
93bfa847ff
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user