]> git.lizzy.rs Git - bspwm.git/blobdiff - events.c
Don't trust WM_PROTOCOLS
[bspwm.git] / events.c
index 7f2339f77bf08452337a3bd4550eae97231ed4f7..307861c6a717a862fa9c8a57d5d09280f58d2542 100644 (file)
--- a/events.c
+++ b/events.c
@@ -44,6 +44,9 @@ void handle_event(xcb_generic_event_t *evt)
         case XCB_MOTION_NOTIFY:
             motion_notify(evt);
             break;
+        case XCB_FOCUS_IN:
+            focus_in(evt);
+            break;
         default:
             if (randr && resp_type == randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY)
                 import_monitors();
@@ -226,6 +229,24 @@ void client_message(xcb_generic_event_t *evt)
     }
 }
 
+void focus_in(xcb_generic_event_t *evt)
+{
+    xcb_focus_in_event_t *e = (xcb_focus_in_event_t *) evt;
+
+    /* PRINTF("focus in %X %d %d\n", e->event, e->mode, e->detail); */
+
+    if (e->mode == XCB_NOTIFY_MODE_GRAB
+            || e->mode == XCB_NOTIFY_MODE_UNGRAB)
+        return;
+    if ((e->detail == XCB_NOTIFY_DETAIL_ANCESTOR ||
+                e->detail == XCB_NOTIFY_DETAIL_INFERIOR ||
+                e->detail == XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL ||
+                e->detail == XCB_NOTIFY_DETAIL_NONLINEAR) &&
+            (mon->desk->focus == NULL
+             || mon->desk->focus->client->window != e->event))
+        update_input_focus();
+}
+
 void enter_notify(xcb_generic_event_t *evt)
 {
     xcb_enter_notify_event_t *e = (xcb_enter_notify_event_t *) evt;
@@ -301,9 +322,6 @@ void grab_pointer(pointer_action_t pac)
 
     query_pointer(&win, &pos);
 
-    if (win == XCB_NONE)
-        return;
-
     coordinates_t loc;
     if (locate_window(win, &loc)) {
         client_t *c = NULL;
@@ -422,6 +440,11 @@ void grab_pointer(pointer_action_t pac)
                 break;
         }
     } else {
+        if (pac == ACTION_FOCUS) {
+            monitor_t *m = monitor_from_point(pos);
+            if (m != NULL)
+                focus_node(m, m->desk, m->desk->focus);
+        }
         frozen_pointer->action = ACTION_NONE;
     }
 }
@@ -431,7 +454,7 @@ void track_pointer(int root_x, int root_y)
     if (frozen_pointer->action == ACTION_NONE)
         return;
 
-    int16_t delta_x, delta_y, x, y, w, h;
+    int16_t delta_x, delta_y, x = 0, y = 0, w = 1, h = 1;
     uint16_t width, height;
 
     pointer_action_t pac = frozen_pointer->action;
@@ -444,9 +467,6 @@ void track_pointer(int root_x, int root_y)
     node_t *vertical_fence = frozen_pointer->vertical_fence;
     node_t *horizontal_fence = frozen_pointer->horizontal_fence;
 
-    x = y = 0;
-    w = h = 1;
-
     delta_x = root_x - frozen_pointer->position.x;
     delta_y = root_y - frozen_pointer->position.y;