]> git.lizzy.rs Git - bspwm.git/commitdiff
Consolidate focus_follows_pointer
authorBastien Dejean <nihilhill@gmail.com>
Mon, 18 Apr 2016 11:54:00 +0000 (13:54 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Mon, 18 Apr 2016 11:54:00 +0000 (13:54 +0200)
Fixes #454.

desktop.c
events.c
messages.c
tree.c
tree.h
window.c

index 6aa8657fd2da123307c8544facca011527b83e51..5cb8001fb68fc6ee416a5d2a843a5c1bbde6be8b 100644 (file)
--- a/desktop.c
+++ b/desktop.c
@@ -40,11 +40,19 @@ void focus_desktop(monitor_t *m, desktop_t *d)
 {
        focus_monitor(m);
 
+       if (focus_follows_pointer) {
+               listen_enter_notify(d->root, false);
+       }
+
        show_desktop(d);
        if (m->desk != d) {
                hide_desktop(m->desk);
        }
 
+       if (focus_follows_pointer) {
+               listen_enter_notify(d->root, true);
+       }
+
        m->desk = d;
        ewmh_update_current_desktop();
 
index 421576f1423c6524960d41387aafba8288e745bf..c194dfa8d5c9b75e0e80735400a3dc68f1a29cb8 100644 (file)
--- a/events.c
+++ b/events.c
@@ -160,8 +160,16 @@ void configure_request(xcb_generic_event_t *evt)
                c->floating_rectangle.height = height;
                xcb_rectangle_t r = c->floating_rectangle;
 
+               if (focus_follows_pointer) {
+                       listen_enter_notify(loc.desktop->root, false);
+               }
+
                window_move_resize(e->window, r.x, r.y, r.width, r.height);
 
+               if (focus_follows_pointer) {
+                       listen_enter_notify(loc.desktop->root, true);
+               }
+
                put_status(SBSC_MASK_NODE_GEOMETRY, "node_geometry 0x%08X 0x%08X 0x%08X %ux%u+%i+%i\n", loc.monitor->id, loc.desktop->id, e->window, r.width, r.height, r.x, r.y);
 
                monitor_t *m = monitor_from_client(c);
@@ -339,25 +347,36 @@ void enter_notify(xcb_generic_event_t *evt)
        xcb_enter_notify_event_t *e = (xcb_enter_notify_event_t *) evt;
        xcb_window_t win = e->event;
 
-       if (e->mode != XCB_NOTIFY_MODE_NORMAL) {
+       if (e->mode != XCB_NOTIFY_MODE_NORMAL || e->detail == XCB_NOTIFY_DETAIL_INFERIOR) {
+               return;
+       }
+
+       xcb_point_t pt = {e->root_x, e->root_y};
+       monitor_t *m = monitor_from_point(pt);
+
+       if (m == NULL) {
                return;
        }
 
-       coordinates_t loc;
        bool pff = pointer_follows_focus;
        bool pfm = pointer_follows_monitor;
        pointer_follows_focus = false;
        pointer_follows_monitor = false;
        auto_raise = false;
 
-       if (locate_window(win, &loc)) {
-               if (loc.monitor->desk == loc.desktop && loc.node != mon->desk->focus) {
-                       focus_node(loc.monitor, loc.desktop, loc.node);
+       desktop_t *d = m->desk;
+       node_t *n = NULL;
+
+       for (n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
+               if (n->id == win || (n->presel != NULL && n->presel->feedback == win)) {
+                       break;
                }
-       } else {
-               xcb_point_t pt = {e->root_x, e->root_y};
-               monitor_t *m = monitor_from_point(pt);
-               if (m != NULL && m != mon) {
+       }
+
+       if (n != mon->desk->focus) {
+               if (n != NULL) {
+                       focus_node(m, d, n);
+               } else if (m != mon) {
                        focus_node(m, m->desk, m->desk->focus);
                }
        }
index 4a9f48779c668f32fd7c13604562e341aaba1685..963f32c769edc80d7683e114b113f7c0cc298398 100644 (file)
@@ -1424,25 +1424,15 @@ void set_setting(coordinates_t loc, char *name, char *value, FILE *rsp)
                                return;
                        }
                        focus_follows_pointer = b;
-                       uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
                        for (monitor_t *m = mon_head; m != NULL; m = m->next) {
-                               for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
-                                       for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
-                                               if (n->client == NULL) {
-                                                       continue;
-                                               }
-                                               xcb_change_window_attributes(dpy, n->id, XCB_CW_EVENT_MASK, values);
-                                       }
-                               }
-                       }
-                       if (focus_follows_pointer) {
-                               for (monitor_t *m = mon_head; m != NULL; m = m->next) {
+                               if (b) {
                                        window_show(m->root);
-                               }
-                       } else {
-                               for (monitor_t *m = mon_head; m != NULL; m = m->next) {
+                               } else {
                                        window_hide(m->root);
                                }
+                               for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
+                                       listen_enter_notify(d->root, b);
+                               }
                        }
                        return;
                } else {
diff --git a/tree.c b/tree.c
index 9549b081603498ed77582c0558ca57abf40e8fac..88d13f60d821fdb7fb89f0a16521393b79a31235 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -69,8 +69,16 @@ void arrange(monitor_t *m, desktop_t *d)
                rect.height -= d->window_gap;
        }
 
+       if (focus_follows_pointer) {
+               listen_enter_notify(d->root, false);
+       }
+
        apply_layout(m, d, d->root, rect, rect);
 
+       if (focus_follows_pointer) {
+               listen_enter_notify(d->root, true);
+       }
+
        d->layout = last_layout;
 }
 
@@ -1790,6 +1798,11 @@ void set_hidden(monitor_t *m, desktop_t *d, node_t *n, bool value)
                return;
        }
 
+
+       if (focus_follows_pointer) {
+               listen_enter_notify(d->root, false);
+       }
+
        bool held_focus = is_descendant(d->focus, n);
 
        propagate_hidden_downward(m, d, n, value);
@@ -1808,6 +1821,10 @@ void set_hidden(monitor_t *m, desktop_t *d, node_t *n, bool value)
                        activate_node(m, d, d->focus);
                }
        }
+
+       if (focus_follows_pointer) {
+               listen_enter_notify(d->root, true);
+       }
 }
 
 void set_hidden_local(monitor_t *m, desktop_t *d, node_t *n, bool value)
@@ -1994,6 +2011,20 @@ void get_side_handle(desktop_t *d, node_t *n, direction_t dir, xcb_point_t *pt)
        }
 }
 
+void listen_enter_notify(node_t *n, bool enable)
+{
+       uint32_t mask = CLIENT_EVENT_MASK | (enable ? XCB_EVENT_MASK_ENTER_WINDOW : 0);
+       for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
+               if (f->client == NULL) {
+                       continue;
+               }
+               xcb_change_window_attributes(dpy, f->id, XCB_CW_EVENT_MASK, &mask);
+               if (f->presel != NULL) {
+                       xcb_change_window_attributes(dpy, f->presel->feedback, XCB_CW_EVENT_MASK, &mask);
+               }
+       }
+}
+
 #define DEF_FLAG_COUNT(flag) \
        unsigned int flag##_count(node_t *n) \
        { \
diff --git a/tree.h b/tree.h
index 37fcb995d280e606bcd0995a3a22ed54da90f4a8..c6d39c4e575029be58ad66273cb256f3f16f577b 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -108,6 +108,7 @@ void set_urgent(monitor_t *m, desktop_t *d, node_t *n, bool value);
 bool contains(xcb_rectangle_t a, xcb_rectangle_t b);
 xcb_rectangle_t get_rectangle(desktop_t *d, node_t *n);
 void get_side_handle(desktop_t *d, node_t *n, direction_t dir, xcb_point_t *pt);
+void listen_enter_notify(node_t *n, bool enable);
 
 unsigned int sticky_count(node_t *n);
 unsigned int private_count(node_t *n);
index f95ba211f763b1a546b5fd2ebd76bb2103e13207..40144d7ceb95b5b449a8d62fa915e12b5a93bc92 100644 (file)
--- a/window.c
+++ b/window.c
@@ -244,8 +244,8 @@ void initialize_presel_feedback(node_t *n)
        }
 
        xcb_window_t win = xcb_generate_id(dpy);
-       uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_SAVE_UNDER;
-       uint32_t values[] = {get_color_pixel(presel_feedback_color), 1};
+       uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_SAVE_UNDER | XCB_CW_EVENT_MASK;
+       uint32_t values[] = {get_color_pixel(presel_feedback_color), 1, XCB_EVENT_MASK_ENTER_WINDOW};
        xcb_create_window(dpy, XCB_COPY_FROM_PARENT, win, root, 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
                                  XCB_COPY_FROM_PARENT, mask, values);
 
@@ -473,7 +473,17 @@ bool move_client(coordinates_t *loc, int dx, int dy)
                xcb_rectangle_t rect = c->floating_rectangle;
                int16_t x = rect.x + dx;
                int16_t y = rect.y + dy;
+
+               if (focus_follows_pointer) {
+                       listen_enter_notify(loc->desktop->root, false);
+               }
+
                window_move(n->id, x, y);
+
+               if (focus_follows_pointer) {
+                       listen_enter_notify(loc->desktop->root, true);
+               }
+
                c->floating_rectangle.x = x;
                c->floating_rectangle.y = y;
                if (!grabbing) {
@@ -545,7 +555,16 @@ bool resize_client(coordinates_t *loc, resize_handle_t rh, int dx, int dy)
                }
                n->client->floating_rectangle = (xcb_rectangle_t) {x, y, width, height};
                if (n->client->state == STATE_FLOATING) {
+                       if (focus_follows_pointer) {
+                               listen_enter_notify(loc->desktop->root, false);
+                       }
+
                        window_move_resize(n->id, x, y, width, height);
+
+                       if (focus_follows_pointer) {
+                               listen_enter_notify(loc->desktop->root, true);
+                       }
+
                        if (!grabbing) {
                                put_status(SBSC_MASK_NODE_GEOMETRY, "node_geometry 0x%08X 0x%08X 0x%08X %ux%u+%i+%i\n", loc->monitor->id, loc->desktop->id, loc->node->id, width, height, x, y);
                        }