tMove newly created windows under the cursor at creation time - glazier - window management experiments
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
(DIR) commit a468ee5a0585aa7c3f7ebceb633340107dc544c5
(DIR) parent 71849f9ba305db6903b744fb882ea3037c234918
(HTM) Author: Willy Goiffon <dev@z3bra.org>
Date: Mon, 15 Jun 2020 14:06:29 +0200
Move newly created windows under the cursor at creation time
Diffstat:
M glazier.c | 42 ++++++++++++++++----------------
1 file changed, 21 insertions(+), 21 deletions(-)
---
(DIR) diff --git a/glazier.c b/glazier.c
t@@ -136,30 +136,9 @@ usage(char *name)
int
adopt(xcb_window_t wid)
{
- int x, y, w, h;
- struct geom_t *m;
-
if (wm_is_ignored(wid))
return -1;
- x = wm_get_attribute(wid, ATTR_X);
- y = wm_get_attribute(wid, ATTR_Y);
- m = monitor(x, y);
-
- if (!wm_is_mapped(wid)) {
- w = wm_get_attribute(wid, ATTR_W);
- h = wm_get_attribute(wid, ATTR_H);
-
- if (!x && !y) {
- wm_get_cursor(0, scrn->root, &x, &y);
- m = monitor(x, y);
- x = MAX(m->x, x - w/2);
- y = MAX(m->y, y - h/2);
- }
-
- wm_teleport(wid, MAX(m->x, x), MAX(m->y, y), w, h);
- }
-
return wm_reg_window_event(wid, XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_FOCUS_CHANGE
| XCB_EVENT_MASK_STRUCTURE_NOTIFY);
t@@ -287,6 +266,8 @@ cb_default(xcb_generic_event_t *ev)
int
cb_create(xcb_generic_event_t *ev)
{
+ int x, y, w, h;
+ struct geom_t *m;
xcb_create_notify_event_t *e;
e = (xcb_create_notify_event_t *)ev;
t@@ -297,6 +278,21 @@ cb_create(xcb_generic_event_t *ev)
if (verbose)
fprintf(stderr, "%s 0x%08x\n", XEV(e), e->window);
+ if (!wm_is_mapped(e->window)) {
+ wm_get_cursor(0, scrn->root, &x, &y);
+ m = monitor(x, y);
+
+ /* move window under the cursor */
+ if (m) {
+ w = wm_get_attribute(e->window, ATTR_W);
+ h = wm_get_attribute(e->window, ATTR_H);
+ x = MAX(m->x, x - w/2);
+ y = MAX(m->y, y - h/2);
+
+ wm_teleport(e->window, MAX(m->x, x), MAX(m->y, y), w, h);
+ }
+ }
+
adopt(e->window);
return 0;
t@@ -724,6 +720,8 @@ crossedge(xcb_window_t wid)
w.w = wm_get_attribute(wid, ATTR_W);
w.h = wm_get_attribute(wid, ATTR_H);
m = monitor(w.x, w.y);
+ if (!m)
+ return -1;
if ((w.x + w.w + 2*b > m->x + m->w)
|| (w.y + w.h + 2*b > m->y + m->h))
t@@ -747,6 +745,8 @@ snaptoedge(xcb_window_t wid)
w.w = wm_get_attribute(wid, ATTR_W);
w.h = wm_get_attribute(wid, ATTR_H);
m = monitor(w.x, w.y);
+ if (!m)
+ return -1;
if (w.w + 2*b > m->w) w.w = m->w - 2*b;
if (w.h + 2*b > m->h) w.h = m->h - 2*b;