tAdd function to find a monitor from an absolute coordinate - libwm - X windows manipulation library
HTML git clone git://z3bra.org/libwm
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit d10dc9ebb2ef7eaed2bc48331b50e808354beebb
DIR parent 71c9d52b8c7f57d9078e83a4812689ecc885d4e7
HTML Author: Willy Goiffon <dev@z3bra.org>
Date: Wed, 17 Jun 2020 10:11:42 +0200
Add function to find a monitor from an absolute coordinate
Diffstat:
M README.md | 1 +
M libwm.c | 24 ++++++++++++++++++++++++
M wm.h | 6 ++++++
3 files changed, 31 insertions(+), 0 deletions(-)
---
DIR diff --git a/README.md b/README.md
t@@ -47,6 +47,7 @@ Here is the list of all functions provided by `libwm`:
wm_restack(wid, mode);
wm_reg_event(wid, mask);
wm_get_monitors(wid, list);
+ wm_get_monitor(index);
Their usage is specified in the `wm.h` header file, as it is quite small for
now.
DIR diff --git a/libwm.c b/libwm.c
t@@ -574,3 +574,27 @@ wm_get_monitor(int index)
free(r);
return NULL;
}
+
+int
+wm_find_monitor(int x, int y)
+{
+ /* patch me if you use more than 64 monitors, and get a reward! */
+ int i, n, monitors[64];
+ xcb_randr_monitor_info_t *p;
+
+ n = wm_get_monitors(scrn->root, monitors);
+ for (i = 0; i < n; i++) {
+ p = wm_get_monitor(monitors[i]);
+ if (!p)
+ continue;
+
+ if (p->x <= x && p->x + p->width >= x
+ && p->y <= y && p->y + p->height >= y) {
+ free(p);
+ return monitors[i];
+ }
+ free(p);
+ }
+
+ return -1;
+}
DIR diff --git a/wm.h b/wm.h
t@@ -247,4 +247,10 @@ int wm_get_monitors(xcb_window_t wid, int *list);
*/
xcb_randr_monitor_info_t *wm_get_monitor(int index);
+/*
+ * Return the index of the (first) monitor associated with the
+ * coordinates.
+ */
+int wm_find_monitor(int x, int y);
+
#endif /* __LIBWM_H__ */