]> code.delx.au - spectrwm/commitdiff
Change libswmhack.so to use RTLD_NEXT functionality when _GNU_SOURCE is defined,...
authorAndreas Eriksson <andreas@eriksson.cc>
Wed, 6 May 2015 18:36:37 +0000 (20:36 +0200)
committerReginald Kennedy <rk@rejii.com>
Wed, 20 May 2015 19:22:24 +0000 (03:22 +0800)
lib/swm_hack.c

index c5f5b5b8945d7a0c8f114197ede767f436e4d7f8..40fa2246322261cc313b966ac3f95b6f9fd86fb7 100644 (file)
@@ -95,13 +95,26 @@ set_property(Display *dpy, Window id, char *name, char *val)
        static XIA              *xia = NULL;
        static XCP              *xcp = NULL;
 
+#ifdef _GNU_SOURCE
+       /* load the function pointer with RTLD_NEXT
+        * this might be the real X function or another
+        * preloaded intercept
+        */
+       if (!lib_xlib)
+               lib_xlib = RTLD_NEXT;
+#else
        /* find the real Xlib and the real X function */
        if (!lib_xlib)
                lib_xlib = dlopen("libX11.so", RTLD_GLOBAL | RTLD_LAZY);
-       if (!xia)
+#endif
+       if (lib_xlib && !xia)
                xia = (XIA *) dlsym(lib_xlib, "XInternAtom");
-       if (!xcp)
+       if (lib_xlib && !xcp)
                xcp = (XCP *) dlsym(lib_xlib, "XChangeProperty");
+       if (!xia || !xcp) {
+               fprintf(stderr, "libswmhack.so: ERROR: %s\n", dlerror());
+               return;
+       }
 
        /* Try to update the window's workspace property */
        atom = (*xia)(dpy, name, False);
@@ -132,13 +145,26 @@ XCreateWindow(Display *dpy, Window parent, int x, int y,
        char            *env;
        Window          id;
 
+#ifdef _GNU_SOURCE
+       /* load the function pointer with RTLD_NEXT
+        * this might be the real X function or another
+        * preloaded intercept
+        */
+       if (!lib_xlib)
+               lib_xlib = RTLD_NEXT;
+#else
        /* find the real Xlib and the real X function */
        if (!lib_xlib)
                lib_xlib = dlopen("libX11.so", RTLD_GLOBAL | RTLD_LAZY);
-       if (!func) {
+#endif
+       if (lib_xlib && !func) {
                func = (CWF *) dlsym(lib_xlib, "XCreateWindow");
                display = dpy;
        }
+       if (!func) {
+               fprintf(stderr, "libswmhack.so: ERROR: %s\n", dlerror());
+               return BadImplementation;
+       }
 
        if (parent == DefaultRootWindow(dpy))
                parent = MyRoot(dpy);
@@ -177,11 +203,24 @@ XCreateSimpleWindow(Display *dpy, Window parent, int x, int y,
        char            *env;
        Window          id;
 
+#ifdef _GNU_SOURCE
+       /* load the function pointer with RTLD_NEXT
+        * this might be the real X function or another
+        * preloaded intercept
+        */
+       if (!lib_xlib)
+               lib_xlib = RTLD_NEXT;
+#else
        /* find the real Xlib and the real X function */
        if (!lib_xlib)
                lib_xlib = dlopen("libX11.so", RTLD_GLOBAL | RTLD_LAZY);
-       if (!func)
+#endif
+       if (lib_xlib && !func)
                func = (CSWF *) dlsym(lib_xlib, "XCreateSimpleWindow");
+       if (!func) {
+               fprintf(stderr, "libswmhack.so: ERROR: %s\n", dlerror());
+               return BadImplementation;
+       }
 
        if (parent == DefaultRootWindow(dpy))
                parent = MyRoot(dpy);
@@ -211,11 +250,24 @@ XReparentWindow(Display *dpy, Window window, Window parent, int x, int y)
 {
        static RWF         *func = NULL;
 
+#ifdef _GNU_SOURCE
+       /* load the function pointer with RTLD_NEXT
+        * this might be the real X function or another
+        * preloaded intercept
+        */
+       if (!lib_xlib)
+               lib_xlib = RTLD_NEXT;
+#else
        /* find the real Xlib and the real X function */
        if (!lib_xlib)
                lib_xlib = dlopen("libX11.so", RTLD_GLOBAL | RTLD_LAZY);
-       if (!func)
+#endif
+       if (lib_xlib && !func)
                func = (RWF *) dlsym(lib_xlib, "XReparentWindow");
+       if (!func) {
+               fprintf(stderr, "libswmhack.so: ERROR: %s\n", dlerror());
+               return BadImplementation;
+       }
 
        if (parent == DefaultRootWindow(dpy))
                parent = MyRoot(dpy);
@@ -238,16 +290,29 @@ XtAppNextEvent(XtAppContext app_context, XEvent *event_return)
        static ANEF     *func = NULL;
        static KeyCode  kp_add = 0, kp_subtract = 0;
 
+#ifdef _GNU_SOURCE
+       /* load the function pointer with RTLD_NEXT
+        * this might be the real X function or another
+        * preloaded intercept
+        */
+       if (!lib_xtlib)
+               lib_xtlib = RTLD_NEXT;
+#else
        /* find the real Xlib and the real X function */
        if (!lib_xtlib)
                lib_xtlib = dlopen("libXt.so", RTLD_GLOBAL | RTLD_LAZY);
-       if (!func) {
+#endif
+       if (lib_xtlib && !func) {
                func = (ANEF *) dlsym(lib_xtlib, "XtAppNextEvent");
                if (display != NULL) {
                        kp_add = XKeysymToKeycode(display, XK_KP_Add);
                        kp_subtract = XKeysymToKeycode(display, XK_KP_Subtract);
                }
        }
+       if (!func) {
+               fprintf(stderr, "libswmhack.so: ERROR: %s\n", dlerror());
+               return;
+       }
 
        (*func) (app_context, event_return);