]> Pileus Git - wmpus/commitdiff
Query all xinerama screens
authorAndy Spencer <andy753421@gmail.com>
Fri, 10 Apr 2015 05:37:50 +0000 (05:37 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 15 Apr 2015 19:54:07 +0000 (19:54 +0000)
makefile
sys-xcb.c

index d556e1451422dc6ced17642338989c5c04254d23..12c113937180465e658adc2038bc4c2ebe678672 100644 (file)
--- a/makefile
+++ b/makefile
@@ -13,7 +13,7 @@ MANPREFIX ?= ${PREFIX}/share/man
 ifeq ($(SYS),xcb)
 GCC       ?= gcc
 PROG      ?= wmpus
-LDFLAGS   += -lxcb
+LDFLAGS   += -lxcb -lxcb-xinerama
 endif
 
 ifeq ($(SYS),xlib)
index 26a105f059cbdb2550fe8563b52cab5f702b58db..7c73a4d67588d25ba3a2fca718e5fe7eb1750f8f 100644 (file)
--- a/sys-xcb.c
+++ b/sys-xcb.c
@@ -19,6 +19,7 @@
 #include <search.h>
 
 #include <xcb/xcb.h>
+#include <xcb/xinerama.h>
 
 #include "util.h"
 #include "conf.h"
@@ -138,6 +139,41 @@ static xcb_get_window_attributes_reply_t *do_get_window_attributes(xcb_window_t
        return reply;
 }
 
+static int do_xinerama_check(void)
+{
+       const xcb_query_extension_reply_t *data =
+               xcb_get_extension_data(conn, &xcb_xinerama_id);
+       if (!data || !data->present)
+               return printf("do_xinerama_check: no ext\n"), 0;
+
+       xcb_xinerama_is_active_cookie_t cookie =
+               xcb_xinerama_is_active(conn);
+       if (!cookie.sequence)
+               return printf("do_xinerama_check: no cookie\n"), 0;
+
+       xcb_xinerama_is_active_reply_t *reply =
+               xcb_xinerama_is_active_reply(conn, cookie, NULL);
+       if (!reply)
+               printf("do_xinerama_check: no reply\n"), 0;
+       else
+               printf("do_xinerama_check: %d\n", reply->state);
+       return reply && reply->state;
+}
+
+static xcb_xinerama_query_screens_reply_t *do_query_screens(void)
+{
+       xcb_xinerama_query_screens_cookie_t cookie =
+               xcb_xinerama_query_screens(conn);
+       xcb_xinerama_query_screens_reply_t *reply =
+               xcb_xinerama_query_screens_reply(conn, cookie, NULL);
+       if (!reply)
+               printf("do_query_screens: no reply\n");
+       else
+               printf("do_query_screens: %d screens\n",
+                       xcb_xinerama_query_screens_screen_info_length(reply));
+       return reply;
+}
+
 /**********************
  * X11 Event Handlers *
  **********************/
@@ -294,6 +330,32 @@ list_t *sys_info(void)
 {
        printf("sys_info\n");
 
+       if (screens == NULL && do_xinerama_check()) {
+               /* Add Xinerama screens */
+               xcb_xinerama_query_screens_reply_t *query;
+               unsigned int ninfo;
+               xcb_xinerama_screen_info_t *info;
+
+               query = do_query_screens();
+               ninfo = xcb_xinerama_query_screens_screen_info_length(query);
+               info  = xcb_xinerama_query_screens_screen_info(query);
+
+               for (int i = 0; i < ninfo; i++) {
+                       win_t *screen = new0(win_t);
+
+                       screen->x = info[i].x_org;
+                       screen->y = info[i].y_org;
+                       screen->w = info[i].width;
+                       screen->h = info[i].height;
+
+                       screens = list_insert(NULL, screen);
+
+                       printf("sys_info: xinerama screen - %dx%d @ %d,%d\n",
+                                       screen->w, screen->h,
+                                       screen->x, screen->y);
+               }
+       }
+
        if (screens == NULL) {
                /* No xinerama support */
                const xcb_setup_t *setup = xcb_get_setup(conn);