瀏覽代碼

X11: Add dynamic loading of libXinerama

Camilla Löwy 8 年之前
父節點
當前提交
3f852c321f
共有 3 個文件被更改,包括 34 次插入8 次删除
  1. 1 3
      CMakeLists.txt
  2. 22 5
      src/x11_init.c
  3. 11 0
      src/x11_platform.h

+ 1 - 3
CMakeLists.txt

@@ -252,12 +252,10 @@ if (_GLFW_X11)
 
 
     # Check for Xinerama (legacy multi-monitor support)
     # Check for Xinerama (legacy multi-monitor support)
     if (NOT X11_Xinerama_FOUND)
     if (NOT X11_Xinerama_FOUND)
-        message(FATAL_ERROR "The Xinerama library and headers were not found")
+        message(FATAL_ERROR "The Xinerama headers were not found")
     endif()
     endif()
 
 
     list(APPEND glfw_INCLUDE_DIRS "${X11_Xinerama_INCLUDE_PATH}")
     list(APPEND glfw_INCLUDE_DIRS "${X11_Xinerama_INCLUDE_PATH}")
-    list(APPEND glfw_LIBRARIES "${X11_Xinerama_LIB}")
-    list(APPEND glfw_PKG_DEPS "xinerama")
 
 
     # Check for Xkb (X keyboard extension)
     # Check for Xkb (X keyboard extension)
     if (NOT X11_Xkb_FOUND)
     if (NOT X11_Xkb_FOUND)

+ 22 - 5
src/x11_init.c

@@ -593,12 +593,23 @@ static GLFWbool initExtensions(void)
                        RROutputChangeNotifyMask);
                        RROutputChangeNotifyMask);
     }
     }
 
 
-    if (XineramaQueryExtension(_glfw.x11.display,
-                               &_glfw.x11.xinerama.major,
-                               &_glfw.x11.xinerama.minor))
+    _glfw.x11.xinerama.handle = dlopen("libXinerama.so.1", RTLD_LAZY | RTLD_GLOBAL);
+    if (_glfw.x11.xinerama.handle)
     {
     {
-        if (XineramaIsActive(_glfw.x11.display))
-            _glfw.x11.xinerama.available = GLFW_TRUE;
+        _glfw.x11.xinerama.IsActive = (PFN_XineramaIsActive)
+            dlsym(_glfw.x11.xinerama.handle, "XineramaIsActive");
+        _glfw.x11.xinerama.QueryExtension = (PFN_XineramaQueryExtension)
+            dlsym(_glfw.x11.xinerama.handle, "XineramaQueryExtension");
+        _glfw.x11.xinerama.QueryScreens = (PFN_XineramaQueryScreens)
+            dlsym(_glfw.x11.xinerama.handle, "XineramaQueryScreens");
+
+        if (XineramaQueryExtension(_glfw.x11.display,
+                                   &_glfw.x11.xinerama.major,
+                                   &_glfw.x11.xinerama.minor))
+        {
+            if (XineramaIsActive(_glfw.x11.display))
+                _glfw.x11.xinerama.available = GLFW_TRUE;
+        }
     }
     }
 
 
     _glfw.x11.xkb.major = 1;
     _glfw.x11.xkb.major = 1;
@@ -883,6 +894,12 @@ void _glfwPlatformTerminate(void)
         _glfw.x11.randr.handle = NULL;
         _glfw.x11.randr.handle = NULL;
     }
     }
 
 
+    if (_glfw.x11.xinerama.handle)
+    {
+        dlclose(_glfw.x11.xinerama.handle);
+        _glfw.x11.xinerama.handle = NULL;
+    }
+
     if (_glfw.x11.helperWindowHandle)
     if (_glfw.x11.helperWindowHandle)
     {
     {
         if (XGetSelectionOwner(_glfw.x11.display, _glfw.x11.CLIPBOARD) ==
         if (XGetSelectionOwner(_glfw.x11.display, _glfw.x11.CLIPBOARD) ==

+ 11 - 0
src/x11_platform.h

@@ -82,6 +82,13 @@ typedef int (* PFN_XRRUpdateConfiguration)(XEvent*);
 #define XRRSetCrtcGamma _glfw.x11.randr.SetCrtcGamma
 #define XRRSetCrtcGamma _glfw.x11.randr.SetCrtcGamma
 #define XRRUpdateConfiguration _glfw.x11.randr.UpdateConfiguration
 #define XRRUpdateConfiguration _glfw.x11.randr.UpdateConfiguration
 
 
+typedef Bool (* PFN_XineramaIsActive)(Display*);
+typedef Bool (* PFN_XineramaQueryExtension)(Display*,int*,int*);
+typedef XineramaScreenInfo* (* PFN_XineramaQueryScreens)(Display*,int*);
+#define XineramaIsActive _glfw.x11.xinerama.IsActive
+#define XineramaQueryExtension _glfw.x11.xinerama.QueryExtension
+#define XineramaQueryScreens _glfw.x11.xinerama.QueryScreens
+
 typedef XID xcb_window_t;
 typedef XID xcb_window_t;
 typedef XID xcb_visualid_t;
 typedef XID xcb_visualid_t;
 typedef struct xcb_connection_t xcb_connection_t;
 typedef struct xcb_connection_t xcb_connection_t;
@@ -314,8 +321,12 @@ typedef struct _GLFWlibraryX11
 
 
     struct {
     struct {
         GLFWbool    available;
         GLFWbool    available;
+        void*       handle;
         int         major;
         int         major;
         int         minor;
         int         minor;
+        PFN_XineramaIsActive IsActive;
+        PFN_XineramaQueryExtension QueryExtension;
+        PFN_XineramaQueryScreens QueryScreens;
     } xinerama;
     } xinerama;
 
 
     struct {
     struct {