]> git.sur5r.net Git - i3/i3lock/blobdiff - i3lock.c
Use RandR for learning about attached monitors
[i3/i3lock] / i3lock.c
index 1bb7b0c8b40c91f1a25e4b3fa4520d323bd08a12..702c6b3e7fcda45fa558c17e4c2a612a9d5de5f5 100644 (file)
--- a/i3lock.c
+++ b/i3lock.c
@@ -36,6 +36,7 @@
 #include <strings.h> /* explicit_bzero(3) */
 #endif
 #include <xcb/xcb_aux.h>
+#include <xcb/randr.h>
 
 #include "i3lock.h"
 #include "xcb.h"
@@ -85,6 +86,7 @@ static struct xkb_compose_table *xkb_compose_table;
 static struct xkb_compose_state *xkb_compose_state;
 static uint8_t xkb_base_event;
 static uint8_t xkb_base_error;
+static int randr_base = -1;
 
 cairo_surface_t *img = NULL;
 bool tile = false;
@@ -620,7 +622,7 @@ void handle_screen_resize(void) {
     xcb_configure_window(conn, win, mask, last_resolution);
     xcb_flush(conn);
 
-    xinerama_query_screens();
+    randr_query(screen->root);
     redraw_screen();
 }
 
@@ -743,8 +745,14 @@ static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
                 break;
 
             default:
-                if (type == xkb_base_event)
+                if (type == xkb_base_event) {
                     process_xkb_event(event);
+                }
+                if (randr_base > -1 &&
+                    type == randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY) {
+                    randr_query(screen->root);
+                    handle_screen_resize();
+                }
         }
 
         free(event);
@@ -987,11 +995,11 @@ int main(int argc, char *argv[]) {
 
     load_compose_table(locale);
 
-    xinerama_init();
-    xinerama_query_screens();
-
     screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
 
+    randr_init(&randr_base, screen->root);
+    randr_query(screen->root);
+
     last_resolution[0] = screen->width_in_pixels;
     last_resolution[1] = screen->height_in_pixels;