tRandr wrapper to retrieve a monitor info structure - libwm - X windows manipulation library
(HTM) git clone git://z3bra.org/libwm
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 71c9d52b8c7f57d9078e83a4812689ecc885d4e7
(DIR) parent 5730e9aad5fa689dc05aee3f0f44d3354bbd0041
(HTM) Author: Willy Goiffon <dev@z3bra.org>
Date: Tue, 16 Jun 2020 16:53:57 +0200
Randr wrapper to retrieve a monitor info structure
Diffstat:
M libwm.c | 35 +++++++++++++++++++++++++++++++
M wm.h | 5 +++++
2 files changed, 40 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/libwm.c b/libwm.c
t@@ -539,3 +539,38 @@ wm_get_monitors(xcb_window_t wid, int *l)
return n;
}
+
+xcb_randr_monitor_info_t *
+wm_get_monitor(int index)
+{
+ xcb_randr_monitor_info_t *monitor;
+ 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, scrn->root, 0);
+ r = xcb_randr_get_monitors_reply(conn, c, NULL);
+ if (!r)
+ return NULL;
+
+ i = xcb_randr_get_monitors_monitors_iterator(r);
+ if (!i.data)
+ return NULL;
+
+ for (; i.rem > 0; xcb_randr_monitor_info_next(&i)) {
+ if (i.index != index)
+ continue;
+
+ monitor = calloc(1, sizeof(*monitor));
+ if (!monitor)
+ return NULL;
+
+ memcpy(monitor, i.data, sizeof(*monitor));
+ free(r);
+ return monitor;
+ }
+
+ free(r);
+ return NULL;
+}
(DIR) diff --git a/wm.h b/wm.h
t@@ -242,4 +242,9 @@ int wm_reg_cursor_event(xcb_window_t wid, uint32_t mask, char *cursor);
*/
int wm_get_monitors(xcb_window_t wid, int *list);
+/*
+ * Return the info scructure defining monitor with index number `index`.
+ */
+xcb_randr_monitor_info_t *wm_get_monitor(int index);
+
#endif /* __LIBWM_H__ */