Browse Source

X11: Add dynamic loading of libXcursor

Camilla Löwy 8 years ago
parent
commit
99e72830ea
3 changed files with 35 additions and 3 deletions
  1. 1 3
      CMakeLists.txt
  2. 20 0
      src/x11_init.c
  3. 14 0
      src/x11_platform.h

+ 1 - 3
CMakeLists.txt

@@ -266,12 +266,10 @@ if (_GLFW_X11)
 
     # Check for Xcursor
     if (NOT X11_Xcursor_FOUND)
-        message(FATAL_ERROR "The Xcursor libraries and headers were not found")
+        message(FATAL_ERROR "The Xcursor headers were not found")
     endif()
 
     list(APPEND glfw_INCLUDE_DIR "${X11_Xcursor_INCLUDE_PATH}")
-    list(APPEND glfw_LIBRARIES "${X11_Xcursor_LIB}")
-    list(APPEND glfw_PKG_DEPS "xcursor")
 
 endif()
 

+ 20 - 0
src/x11_init.c

@@ -593,6 +593,17 @@ static GLFWbool initExtensions(void)
                        RROutputChangeNotifyMask);
     }
 
+    _glfw.x11.xcursor.handle = dlopen("libXcursor.so.1", RTLD_LAZY | RTLD_GLOBAL);
+    if (_glfw.x11.xcursor.handle)
+    {
+        _glfw.x11.xcursor.ImageCreate = (PFN_XcursorImageCreate)
+            dlsym(_glfw.x11.xcursor.handle, "XcursorImageCreate");
+        _glfw.x11.xcursor.ImageDestroy = (PFN_XcursorImageDestroy)
+            dlsym(_glfw.x11.xcursor.handle, "XcursorImageDestroy");
+        _glfw.x11.xcursor.ImageLoadCursor = (PFN_XcursorImageLoadCursor)
+            dlsym(_glfw.x11.xcursor.handle, "XcursorImageLoadCursor");
+    }
+
     _glfw.x11.xinerama.handle = dlopen("libXinerama.so.1", RTLD_LAZY | RTLD_GLOBAL);
     if (_glfw.x11.xinerama.handle)
     {
@@ -782,6 +793,9 @@ Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot)
     int i;
     Cursor cursor;
 
+    if (!_glfw.x11.xcursor.handle)
+        return None;
+
     XcursorImage* native = XcursorImageCreate(image->width, image->height);
     if (native == NULL)
         return None;
@@ -894,6 +908,12 @@ void _glfwPlatformTerminate(void)
         _glfw.x11.randr.handle = NULL;
     }
 
+    if (_glfw.x11.xcursor.handle)
+    {
+        dlclose(_glfw.x11.xcursor.handle);
+        _glfw.x11.xcursor.handle = NULL;
+    }
+
     if (_glfw.x11.xinerama.handle)
     {
         dlclose(_glfw.x11.xinerama.handle);

+ 14 - 0
src/x11_platform.h

@@ -82,6 +82,13 @@ typedef int (* PFN_XRRUpdateConfiguration)(XEvent*);
 #define XRRSetCrtcGamma _glfw.x11.randr.SetCrtcGamma
 #define XRRUpdateConfiguration _glfw.x11.randr.UpdateConfiguration
 
+typedef XcursorImage* (* PFN_XcursorImageCreate)(int,int);
+typedef void (* PFN_XcursorImageDestroy)(XcursorImage*);
+typedef Cursor (* PFN_XcursorImageLoadCursor)(Display*,const XcursorImage*);
+#define XcursorImageCreate _glfw.x11.xcursor.ImageCreate
+#define XcursorImageDestroy _glfw.x11.xcursor.ImageDestroy
+#define XcursorImageLoadCursor _glfw.x11.xcursor.ImageLoadCursor
+
 typedef Bool (* PFN_XineramaIsActive)(Display*);
 typedef Bool (* PFN_XineramaQueryExtension)(Display*,int*,int*);
 typedef XineramaScreenInfo* (* PFN_XineramaQueryScreens)(Display*,int*);
@@ -319,6 +326,13 @@ typedef struct _GLFWlibraryX11
         Atom        format;
     } xdnd;
 
+    struct {
+        void*       handle;
+        PFN_XcursorImageCreate ImageCreate;
+        PFN_XcursorImageDestroy ImageDestroy;
+        PFN_XcursorImageLoadCursor ImageLoadCursor;
+    } xcursor;
+
     struct {
         GLFWbool    available;
         void*       handle;