]> git.lizzy.rs Git - bspwm.git/blobdiff - events.c
Rewrite the stacking engine
[bspwm.git] / events.c
index 559030d61301e8d590b2cd447837f2de357da4c4..131f0a780bb4da03840724c7a2d176a6b57e5bd5 100644 (file)
--- a/events.c
+++ b/events.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2014, Bastien Dejean
+/* Copyright (c) 2012, Bastien Dejean
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and documentation are those
- * of the authors and should not be interpreted as representing official policies,
- * either expressed or implied, of the FreeBSD Project.
  */
 
 #include <stdlib.h>
@@ -67,9 +63,12 @@ void handle_event(xcb_generic_event_t *evt)
                case XCB_FOCUS_IN:
                        focus_in(evt);
                        break;
+               case 0:
+                       process_error(evt);
+                       break;
                default:
                        if (randr && resp_type == randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY)
-                               import_monitors();
+                               update_monitors();
                        break;
        }
 }
@@ -94,7 +93,7 @@ void configure_request(xcb_generic_event_t *evt)
        client_t *c = (is_managed ? loc.node->client : NULL);
        int w = 0, h = 0;
 
-       if (is_managed && !is_floating(c)) {
+       if (is_managed && !c->floating) {
                if (e->value_mask & XCB_CONFIG_WINDOW_X)
                        c->floating_rectangle.x = e->x;
                if (e->value_mask & XCB_CONFIG_WINDOW_Y)
@@ -279,10 +278,6 @@ void client_message(xcb_generic_event_t *evt)
                if ((ignore_ewmh_focus && e->data.data32[0] == XCB_EWMH_CLIENT_SOURCE_TYPE_NORMAL) ||
                    loc.node == mon->desk->focus)
                        return;
-               if (loc.desktop->focus->client->fullscreen && loc.desktop->focus != loc.node) {
-                       set_fullscreen(loc.desktop->focus, false);
-                       arrange(loc.monitor, loc.desktop);
-               }
                focus_node(loc.monitor, loc.desktop, loc.node);
        } else if (e->type == ewmh->_NET_WM_DESKTOP) {
                coordinates_t dloc;
@@ -321,18 +316,29 @@ void enter_notify(xcb_generic_event_t *evt)
 
        if (e->mode != XCB_NOTIFY_MODE_NORMAL ||
            (mon->desk->focus != NULL &&
-            mon->desk->focus->client->window == win))
+            mon->desk->focus->client->window == win)) {
+               return;
+       }
+
+       xcb_get_window_attributes_reply_t *wa = xcb_get_window_attributes_reply(dpy, xcb_get_window_attributes(dpy, motion_recorder), NULL);
+
+       if (wa == NULL) {
                return;
+       }
 
-       enable_motion_recorder();
+       if (wa->map_state == XCB_MAP_STATE_UNMAPPED) {
+               enable_motion_recorder();
+       } else {
+               disable_motion_recorder();
+       }
 }
 
 void motion_notify(xcb_generic_event_t *evt)
 {
-       PUTS("motion notify");
-
        xcb_motion_notify_event_t *e = (xcb_motion_notify_event_t *) evt;
 
+       PRINTF("motion notify %X %i %i\n", e->event, e->root_x, e->root_y);
+
        int dtime = e->time - last_motion_time;
        if (dtime > 1000) {
                last_motion_time = e->time;
@@ -342,25 +348,35 @@ void motion_notify(xcb_generic_event_t *evt)
        }
 
        int mdist = abs(e->event_x - last_motion_x) + abs(e->event_y - last_motion_y);
-       if (mdist < 10)
+       if (mdist < 10) {
                return;
-
-       disable_motion_recorder();
+       }
 
        xcb_window_t win = XCB_NONE;
        xcb_point_t pt = {e->root_x, e->root_y};
        query_pointer(&win, NULL);
 
-       bool backup = pointer_follows_monitor;
+       bool pfm_backup = pointer_follows_monitor;
+       bool pff_backup = pointer_follows_focus;
        auto_raise = false;
        pointer_follows_monitor = false;
-       if (!window_focus(win)) {
+       pointer_follows_focus = false;
+       coordinates_t loc;
+       if (locate_window(win, &loc)) {
+               if (loc.node != mon->desk->focus) {
+                       focus_node(loc.monitor, loc.desktop, loc.node);
+               }
+       } else {
                monitor_t *m = monitor_from_point(pt);
-               if (m != NULL && m != mon)
+               if (m != NULL && m != mon) {
                        focus_node(m, m->desk, m->desk->focus);
+               }
        }
-       pointer_follows_monitor = backup;
+       pointer_follows_monitor = pfm_backup;
+       pointer_follows_focus = pff_backup;
        auto_raise = true;
+
+       disable_motion_recorder();
 }
 
 void handle_state(monitor_t *m, desktop_t *d, node_t *n, xcb_atom_t state, unsigned int action)
@@ -373,6 +389,20 @@ void handle_state(monitor_t *m, desktop_t *d, node_t *n, xcb_atom_t state, unsig
                else if (action == XCB_EWMH_WM_STATE_TOGGLE)
                        set_fullscreen(n, !n->client->fullscreen);
                arrange(m, d);
+       } else if (state == ewmh->_NET_WM_STATE_BELOW) {
+               if (action == XCB_EWMH_WM_STATE_ADD)
+                       set_layer(n, LAYER_BELOW);
+               else if (action == XCB_EWMH_WM_STATE_REMOVE)
+                       set_layer(n, LAYER_NORMAL);
+               else if (action == XCB_EWMH_WM_STATE_TOGGLE)
+                       set_layer(n, n->client->layer == LAYER_BELOW ? LAYER_NORMAL : LAYER_BELOW);
+       } else if (state == ewmh->_NET_WM_STATE_ABOVE) {
+               if (action == XCB_EWMH_WM_STATE_ADD)
+                       set_layer(n, LAYER_ABOVE);
+               else if (action == XCB_EWMH_WM_STATE_REMOVE)
+                       set_layer(n, LAYER_NORMAL);
+               else if (action == XCB_EWMH_WM_STATE_TOGGLE)
+                       set_layer(n, n->client->layer == LAYER_ABOVE ? LAYER_NORMAL : LAYER_ABOVE);
        } else if (state == ewmh->_NET_WM_STATE_STICKY) {
                if (action == XCB_EWMH_WM_STATE_ADD)
                        set_sticky(m, d, n, true);
@@ -389,3 +419,9 @@ void handle_state(monitor_t *m, desktop_t *d, node_t *n, xcb_atom_t state, unsig
                        set_urgency(m, d, n, !n->client->urgent);
        }
 }
+
+void process_error(xcb_generic_event_t *evt)
+{
+       xcb_request_error_t *e = (xcb_request_error_t *) evt;
+       warn("Failed request: %s, %s: %d.\n", xcb_event_get_request_label(e->major_opcode), xcb_event_get_error_label(e->error_code), e->bad_value);
+}