]> git.lizzy.rs Git - bspwm.git/blobdiff - events.c
New setting: `split_ratio`
[bspwm.git] / events.c
index bd29a1944dd24066e5721b33f17e951bc1ccaee1..e3f9968cde830ebfba61f22cbafc31daaca06267 100644 (file)
--- a/events.c
+++ b/events.c
@@ -39,7 +39,7 @@ void handle_event(xcb_generic_event_t *evt)
             enter_notify(evt);
             break;
         case XCB_MOTION_NOTIFY:
-            motion_notify(evt);
+            motion_notify();
             break;
         default:
             break;
@@ -181,17 +181,9 @@ void property_notify(xcb_generic_event_t *evt)
         return;
 
     window_location_t loc;
-    if (locate_window(e->window, &loc)) {
-        if (xcb_icccm_get_wm_hints_reply(dpy, xcb_icccm_get_wm_hints(dpy, e->window), &hints, NULL) == 1) {
-            uint32_t urgent = xcb_icccm_wm_hints_get_urgency(&hints);
-            if (urgent != 0 && loc.node != mon->desk->focus) {
-                loc.node->client->urgent = urgent;
-                put_status();
-                if (loc.monitor->desk == loc.desktop)
-                    arrange(loc.monitor, loc.desktop);
-            }
-        }
-    }
+    if (locate_window(e->window, &loc)
+            && xcb_icccm_get_wm_hints_reply(dpy, xcb_icccm_get_wm_hints(dpy, e->window), &hints, NULL) == 1)
+        set_urgency(loc.monitor, loc.desktop, loc.node, xcb_icccm_wm_hints_get_urgency(&hints));
 }
 
 void client_message(xcb_generic_event_t *evt)
@@ -234,20 +226,22 @@ void enter_notify(xcb_generic_event_t *evt)
     PRINTF("enter notify %X %d %d\n", win, e->mode, e->detail);
 
     if (e->mode != XCB_NOTIFY_MODE_NORMAL
-            || (last_pointer_position.x = e->root_x && last_pointer_position.y == e->root_y))
+            || (mon->desk->focus != NULL && mon->desk->focus->client->window == win))
         return;
 
-    window_focus(win);
+    enable_motion_recorder();
 }
 
-void motion_notify(xcb_generic_event_t *evt)
+void motion_notify(void)
 {
-    xcb_motion_notify_event_t *e = (xcb_motion_notify_event_t *) evt;
-    xcb_window_t win = e->event;
+    PUTS("motion notify");
 
-    PRINTF("motion notify %X\n", win);
+    disable_motion_recorder();
 
-    window_focus(win);
+    xcb_window_t win = XCB_NONE;
+    query_pointer(&win, NULL);
+    if (win != XCB_NONE)
+        window_focus(win);
 }
 
 void handle_state(monitor_t *m, desktop_t *d, node_t *n, xcb_atom_t state, unsigned int action)
@@ -260,6 +254,13 @@ void handle_state(monitor_t *m, desktop_t *d, node_t *n, xcb_atom_t state, unsig
             toggle_fullscreen(m, n->client);
             arrange(m, d);
         }
+    } else if (state == ewmh->_NET_WM_STATE_DEMANDS_ATTENTION) {
+        if (action == XCB_EWMH_WM_STATE_ADD)
+            set_urgency(m, d, n, true);
+        else if (action == XCB_EWMH_WM_STATE_REMOVE)
+            set_urgency(m, d, n, false);
+        else if (action == XCB_EWMH_WM_STATE_TOGGLE)
+            set_urgency(m, d, n, !n->client->urgent);
     }
 }
 
@@ -267,17 +268,13 @@ void grab_pointer(pointer_action_t pac)
 {
     PRINTF("grab pointer %u\n", pac);
 
-    xcb_window_t win;
+    xcb_window_t win = XCB_NONE;
     xcb_point_t pos;
 
-    xcb_query_pointer_reply_t *qpr = xcb_query_pointer_reply(dpy, xcb_query_pointer(dpy, root), NULL);
-    if (qpr != NULL) {
-        pos = (xcb_point_t) {qpr->root_x, qpr->root_y};
-        win = qpr->child;
-        free(qpr);
-    } else {
+    query_pointer(&win, &pos);
+
+    if (win == XCB_NONE)
         return;
-    }
 
     window_location_t loc;
     if (locate_window(win, &loc)) {
@@ -421,20 +418,33 @@ void track_pointer(int root_x, int root_y)
     switch (pac) {
         case ACTION_MOVE:
             if (frozen_pointer->is_tiled) {
-                xcb_query_pointer_reply_t *qpr = xcb_query_pointer_reply(dpy, xcb_query_pointer(dpy, root), NULL);
-                if (qpr != NULL) {
-                    xcb_window_t pwin = qpr->child;
-                    free(qpr);
-                    window_location_t loc;
-                    if (locate_window(pwin, &loc) && is_tiled(loc.node->client)) {
-                        swap_nodes(n, loc.node);
-                        arrange(m, d);
-                        if (m != loc.monitor) {
-                            arrange(loc.monitor, loc.desktop);
-                            frozen_pointer->monitor = loc.monitor;
-                            frozen_pointer->desktop = loc.desktop;
+                xcb_window_t pwin = XCB_NONE;
+                query_pointer(&pwin, NULL);
+                if (pwin == win)
+                    return;
+                window_location_t loc;
+                bool is_managed = (pwin == XCB_NONE ? false : locate_window(pwin, &loc));
+                if (is_managed && is_tiled(loc.node->client) && loc.monitor == m) {
+                    swap_nodes(d, n, loc.desktop, loc.node);
+                    arrange(m, d);
+                } else {
+                    if (is_managed && loc.monitor == m) {
+                        return;
+                    } else if (!is_managed) {
+                        xcb_point_t pt = (xcb_point_t) {root_x, root_y};
+                        monitor_t *pmon = monitor_from_point(pt);
+                        if (pmon == NULL || pmon == m) {
+                            return;
+                        } else {
+                            loc.monitor = pmon;
+                            loc.desktop = pmon->desk;
                         }
                     }
+                    transfer_node(m, d, loc.monitor, loc.desktop, n);
+                    arrange(m, d);
+                    arrange(loc.monitor, loc.desktop);
+                    frozen_pointer->monitor = loc.monitor;
+                    frozen_pointer->desktop = loc.desktop;
                 }
             } else {
                 x = rect.x + delta_x;
@@ -536,11 +546,10 @@ void ungrab_pointer(void)
 {
     PUTS("ungrab pointer");
 
-    if (frozen_pointer->action == ACTION_NONE)
+    if (frozen_pointer->action == ACTION_NONE || frozen_pointer->is_tiled)
         return;
 
-    if (is_floating(frozen_pointer->client))
-        update_floating_rectangle(frozen_pointer->client);
+    update_floating_rectangle(frozen_pointer->client);
     monitor_t *m = underlying_monitor(frozen_pointer->client);
     if (m != NULL && m != frozen_pointer->monitor) {
         transfer_node(frozen_pointer->monitor, frozen_pointer->desktop, m, m->desk, frozen_pointer->node);