tAdd support for multi-monitor through Xrandr(3) - libwm - X windows manipulation library
(HTM) git clone git://z3bra.org/libwm
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 5730e9aad5fa689dc05aee3f0f44d3354bbd0041
(DIR) parent 9d0180e7638d3ed2aee875484219b43490f9cc36
(HTM) Author: Willy Goiffon <dev@z3bra.org>
Date: Tue, 16 Jun 2020 16:09:48 +0200
Add support for multi-monitor through Xrandr(3)
Diffstat:
M README.md | 1 +
M config.mk | 2 +-
M libwm.c | 28 ++++++++++++++++++++++++++++
M wm.h | 9 +++++++++
4 files changed, 39 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/README.md b/README.md
t@@ -46,6 +46,7 @@ Here is the list of all functions provided by `libwm`:
wm_resize(wid, mode, w, h);
wm_restack(wid, mode);
wm_reg_event(wid, mask);
+ wm_get_monitors(wid, list);
Their usage is specified in the `wm.h` header file, as it is quite small for
now.
(DIR) diff --git a/config.mk b/config.mk
t@@ -4,4 +4,4 @@ CC = cc
LD = $(CC)
CFLAGS = -std=c99 -pedantic -Wall -fPIC -Os
-LDFLAGS = -lxcb
+LDFLAGS = -lxcb -lxcb-randr
(DIR) diff --git a/libwm.c b/libwm.c
t@@ -1,5 +1,6 @@
#include <xcb/xcb.h>
#include <xcb/xcb_cursor.h>
+#include <xcb/randr.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
t@@ -511,3 +512,30 @@ wm_reg_cursor_event(xcb_window_t wid, uint32_t mask, char *cursor)
xcb_cursor_context_free(cx);
return 0;
}
+
+int
+wm_get_monitors(xcb_window_t wid, int *l)
+{
+ int n;
+ xcb_randr_get_monitors_cookie_t c;
+ xcb_randr_get_monitors_reply_t *r;
+ xcb_randr_monitor_info_iterator_t i;
+
+ /* get_active: ignore inactive monitors */
+ c = xcb_randr_get_monitors(conn, wid, 0);
+ r = xcb_randr_get_monitors_reply(conn, c, NULL);
+ if (!r)
+ return -1;
+
+ i = xcb_randr_get_monitors_monitors_iterator(r);
+ if (!i.data)
+ return 0;
+
+ for (n = 0; l && i.rem > 0; xcb_randr_monitor_info_next(&i))
+ l[n++] = i.index;
+
+ n = r->nMonitors;
+ free(r);
+
+ return n;
+}
(DIR) diff --git a/wm.h b/wm.h
t@@ -233,4 +233,13 @@ int wm_reg_window_event(xcb_window_t wid, uint32_t mask);
*/
int wm_reg_cursor_event(xcb_window_t wid, uint32_t mask, char *cursor);
+/*
+ * Return the number of active monitors connected to the display where
+ * window `wid` is sitting.
+ * The `list` argument, if not NULL, will be filled with the monitor's
+ * index numbers. Note that `list` must be big enough to hold all indexes,
+ * as it is not reallocated.
+ */
+int wm_get_monitors(xcb_window_t wid, int *list);
+
#endif /* __LIBWM_H__ */