summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@blame.services>2021-12-18 20:38:51 +0100
committerDave Davenport <qball@blame.services>2021-12-18 20:38:51 +0100
commit91050eaf74bb8766ee4fb82c29af7da475653bc6 (patch)
tree41177dc5f5fd7c2edffe8a3c6a1f4fb348bb3d5d
parent5f7563dae38d10ba9a2fa21bb827f5fcbf315475 (diff)
[XCB] Cache lookup of monitor.
-rw-r--r--source/xcb.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/source/xcb.c b/source/xcb.c
index 3fbdb16a..fbf36b30 100644
--- a/source/xcb.c
+++ b/source/xcb.c
@@ -784,6 +784,7 @@ static int pointer_get(xcb_window_t root, int *x, int *y) {
return FALSE;
}
+
static int monitor_active_from_winid(xcb_drawable_t id, workarea *mon) {
xcb_window_t root = xcb->screen->root;
xcb_get_geometry_cookie_t c = xcb_get_geometry(xcb->connection, id);
@@ -939,11 +940,24 @@ static int monitor_active_from_id(int mon_id, workarea *mon) {
// determine which monitor holds the active window, or failing that the mouse
// pointer
+
+gboolean mon_set = FALSE;
+workarea mon_cache = {
+ 0,
+};
int monitor_active(workarea *mon) {
+ if (mon_set) {
+ if (mon) {
+ *mon = mon_cache;
+ return TRUE;
+ }
+ }
if (config.monitor != NULL) {
for (workarea *iter = xcb->monitors; iter; iter = iter->next) {
if (g_strcmp0(config.monitor, iter->name) == 0) {
*mon = *iter;
+ mon_cache = *mon;
+ mon_set = TRUE;
return TRUE;
}
}
@@ -953,6 +967,8 @@ int monitor_active(workarea *mon) {
for (workarea *iter = xcb->monitors; iter; iter = iter->next) {
if (iter->primary) {
*mon = *iter;
+ mon_cache = *mon;
+ mon_set = TRUE;
return TRUE;
}
}
@@ -962,6 +978,8 @@ int monitor_active(workarea *mon) {
xcb_drawable_t win = g_ascii_strtoll(config.monitor + 4, &end, 0);
if (end != config.monitor) {
if (monitor_active_from_winid(win, mon)) {
+ mon_cache = *mon;
+ mon_set = TRUE;
return TRUE;
}
}
@@ -973,16 +991,23 @@ int monitor_active(workarea *mon) {
if (end != config.monitor) {
if (mon_id >= 0) {
if (monitor_get_dimension(mon_id, mon)) {
+ mon_cache = *mon;
+ mon_set = TRUE;
return TRUE;
}
g_warning("Failed to find selected monitor.");
} else {
- return monitor_active_from_id(mon_id, mon);
+ int val = monitor_active_from_id(mon_id, mon);
+ mon_cache = *mon;
+ mon_set = TRUE;
+ return val;
}
}
}
// Fallback.
monitor_dimensions(0, 0, mon);
+ mon_cache = *mon;
+ mon_set = TRUE;
return FALSE;
}