]> git.sur5r.net Git - i3/i3lock/commitdiff
Implement Xinerama support (not used yet)
authorMichael Stapelberg <michael@stapelberg.de>
Tue, 3 Jan 2012 23:10:56 +0000 (23:10 +0000)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 3 Jan 2012 23:10:56 +0000 (23:10 +0000)
Makefile
i3lock.c
xcb.h
xinerama.c [new file with mode: 0644]
xinerama.h [new file with mode: 0644]

index 37bd046b5297be0bb518a5eab4811152042cdeca..cc7dff90b60c6a36c88f4cb857c3e97500313c48 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,12 +12,12 @@ CFLAGS += -pipe
 CFLAGS += -Wall
 CPPFLAGS += -D_GNU_SOURCE
 ifndef NOLIBCAIRO
-CFLAGS += $(shell pkg-config --cflags cairo xcb-keysyms xcb-dpms)
-LIBS += $(shell pkg-config --libs cairo xcb-keysyms xcb-dpms xcb-image)
+CFLAGS += $(shell pkg-config --cflags cairo xcb-keysyms xcb-dpms xcb-xinerama)
+LIBS += $(shell pkg-config --libs cairo xcb-keysyms xcb-dpms xcb-xinerama xcb-image)
 else
 CPPFLAGS += -DNOLIBCAIRO
-CFLAGS += $(shell pkg-config --cflags xcb-keysyms xcb-dpms)
-LIBS += $(shell pkg-config --libs xcb-keysyms xcb-dpms xcb-image)
+CFLAGS += $(shell pkg-config --cflags xcb-keysyms xcb-dpms xcb-xinerama)
+LIBS += $(shell pkg-config --libs xcb-keysyms xcb-dpms xcb-image xcb-xinerama)
 endif
 LIBS += -lpam
 LIBS += -lev
index 72bd646ac612bfee8b7668ac01ee721736ca766c..d265009c71ac672f4747f9b9da0229d544e2b425 100644 (file)
--- a/i3lock.c
+++ b/i3lock.c
@@ -36,6 +36,7 @@
 #include "xcb.h"
 #include "cursors.h"
 #include "unlock_indicator.h"
+#include "xinerama.h"
 
 char color[7] = "ffffff";
 uint32_t last_resolution[2];
@@ -618,6 +619,9 @@ int main(int argc, char *argv[]) {
         xcb_connection_has_error(conn))
         errx(EXIT_FAILURE, "Could not connect to X11, maybe you need to set DISPLAY?");
 
+    xinerama_init();
+    xinerama_query_screens();
+
     /* if DPMS is enabled, check if the X server really supports it */
     if (dpms) {
         xcb_dpms_capable_cookie_t dpmsc = xcb_dpms_capable(conn);
diff --git a/xcb.h b/xcb.h
index e4f700c56e6856f00c45cf681aecac7c9a3a4955..a5786796226d7d7b50c3957b2e4a4e7cd6147733 100644 (file)
--- a/xcb.h
+++ b/xcb.h
@@ -2,6 +2,7 @@
 #define _XCB_H
 
 #include <xcb/xcb.h>
+#include <xcb/xcb_keysyms.h>
 
 extern xcb_connection_t *conn;
 extern xcb_screen_t *screen;
diff --git a/xinerama.c b/xinerama.c
new file mode 100644 (file)
index 0000000..91be487
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * vim:ts=4:sw=4:expandtab
+ *
+ * © 2010-2012 Michael Stapelberg
+ *
+ * See LICENSE for licensing information
+ *
+ */
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <xcb/xcb.h>
+#include <xcb/xinerama.h>
+
+#include "xcb.h"
+#include "xinerama.h"
+
+/* Number of Xinerama screens which are currently present. */
+int xr_screens = 0;
+
+/* The resolutions of the currently present Xinerama screens. */
+Rect *xr_resolutions;
+
+static bool xinerama_active;
+
+void xinerama_init() {
+    if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
+        printf("Xinerama extension not found, disabling.\n");
+        return;
+    }
+
+    xcb_xinerama_is_active_cookie_t cookie;
+    xcb_xinerama_is_active_reply_t *reply;
+
+    cookie = xcb_xinerama_is_active(conn);
+    reply = xcb_xinerama_is_active_reply(conn, cookie, NULL);
+    if (!reply)
+        return;
+
+    if (!reply->state) {
+        free(reply);
+        return;
+    }
+
+    xinerama_active = true;
+}
+
+void xinerama_query_screens() {
+    if (!xinerama_active)
+        return;
+
+    xcb_xinerama_query_screens_cookie_t cookie;
+    xcb_xinerama_query_screens_reply_t *reply;
+    xcb_xinerama_screen_info_t *screen_info;
+
+    cookie = xcb_xinerama_query_screens_unchecked(conn);
+    reply = xcb_xinerama_query_screens_reply(conn, cookie, NULL);
+    if (!reply) {
+        fprintf(stderr, "Couldn't get Xinerama screens\n");
+        return;
+    }
+    screen_info = xcb_xinerama_query_screens_screen_info(reply);
+    int screens = xcb_xinerama_query_screens_screen_info_length(reply);
+
+    Rect *resolutions = malloc(screens * sizeof(Rect));
+    /* No memory? Just keep on using the old information. */
+    if (!resolutions) {
+        free(reply);
+        return;
+    }
+    xr_resolutions = resolutions;
+    xr_screens = screens;
+
+    for (int screen = 0; screen < xr_screens; screen++) {
+        xr_resolutions[screen].x = screen_info[screen].x_org;
+        xr_resolutions[screen].y = screen_info[screen].y_org;
+        xr_resolutions[screen].width = screen_info[screen].width;
+        xr_resolutions[screen].height = screen_info[screen].height;
+        printf("found Xinerama screen: %d x %d at %d x %d\n",
+                        screen_info[screen].width, screen_info[screen].height,
+                        screen_info[screen].x_org, screen_info[screen].y_org);
+    }
+
+    free(reply);
+}
diff --git a/xinerama.h b/xinerama.h
new file mode 100644 (file)
index 0000000..ea1804e
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _XINERAMA_H
+#define _XINERAMA_H
+
+typedef struct Rect {
+    int16_t x;
+    int16_t y;
+    uint16_t width;
+    uint16_t height;
+} Rect;
+
+void xinerama_init();
+void xinerama_query_screens();
+
+#endif