tAdopt all orphan windows on startup - glazier - window management experiments
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
(DIR) commit 1ecfca52d4636d72f63beee3c127398f6d1c3f3a
(DIR) parent c5b78cb7cb51a51de00d4effa34b06c9c9310128
(HTM) Author: Willy Goiffon <dev@z3bra.org>
Date: Wed, 23 Oct 2019 20:38:20 +0200
Adopt all orphan windows on startup
Diffstat:
M glazier.c | 48 +++++++++++++++++++++++++++++--
1 file changed, 46 insertions(+), 2 deletions(-)
---
(DIR) diff --git a/glazier.c b/glazier.c
t@@ -21,6 +21,7 @@ struct cursor_t {
int b;
};
+static int takeover();
static int ev_callback(xcb_generic_event_t *);
/* XCB events callbacks */
t@@ -92,6 +93,46 @@ usage(char *name)
}
static int
+adopt(xcb_window_t wid)
+{
+ int x, y, w, h;
+
+ if (!wm_is_mapped(wid)) {
+ w = wm_get_attribute(wid, ATTR_W);
+ h = wm_get_attribute(wid, ATTR_H);
+ wm_get_cursor(0, scrn->root, &x, &y);
+ wm_teleport(wid, x - w/2, y - h/2, w, h);
+ } else {
+ wm_set_border(border, border_color, wid);
+ }
+ wm_reg_event(wid, XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_STRUCTURE_NOTIFY);
+
+ return 0;
+}
+
+static int
+takeover()
+{
+ int i, c, n;
+ xcb_window_t *orphans;
+
+ n = wm_get_windows(scrn->root, &orphans);
+
+ for (i = 0, c = 0; i < n; i++) {
+ if (wm_is_ignored(orphans[i]))
+ continue;
+
+ adopt(orphans[i]);
+ c++;
+ }
+
+ if (verbose)
+ fprintf(stderr, "Adopted %d windows\n", c);
+
+ return n;
+}
+
+static int
cb_default(xcb_generic_event_t *ev)
{
if (verbose && XEV(ev)) {
t@@ -156,7 +197,7 @@ cb_mouse_press(xcb_generic_event_t *ev)
e = (xcb_button_press_event_t *)ev;
/* ignore some motion events if they happen too often */
- if (e->time - lasttime < 32)
+ if (e->time - lasttime < 8)
return 0;
if (verbose)
t@@ -167,7 +208,7 @@ cb_mouse_press(xcb_generic_event_t *ev)
exit(1);
}
- wm_restack(e->event, XCB_STACK_MODE_ABOVE);
+ wm_restack(e->child, XCB_STACK_MODE_ABOVE);
cursor.x = e->root_x - wm_get_attribute(e->child, ATTR_X);
cursor.y = e->root_y - wm_get_attribute(e->child, ATTR_Y);
t@@ -334,6 +375,7 @@ cb_configreq(xcb_generic_event_t *ev)
e->x, e->y);
wm_teleport(e->window, e->x, e->y, e->width, e->height);
+ wm_restack(e->window, e->stack_mode);
return 0;
}
t@@ -394,6 +436,8 @@ main (int argc, char *argv[])
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, scrn->root,
XCB_NONE, XCB_BUTTON_INDEX_ANY, modifier);
+ takeover();
+
for (;;) {
xcb_flush(conn);
ev = xcb_wait_for_event(conn);