*/
#include <stdlib.h>
+#include <stdbool.h>
#include "bspwm.h"
#include "ewmh.h"
#include "monitor.h"
#include "subscribe.h"
#include "tree.h"
#include "window.h"
+#include "pointer.h"
#include "events.h"
void handle_event(xcb_generic_event_t *evt)
case XCB_ENTER_NOTIFY:
enter_notify(evt);
break;
+ case XCB_BUTTON_PRESS:
+ button_press(evt);
+ break;
case XCB_MOTION_NOTIFY:
motion_notify(evt);
break;
process_error(evt);
break;
default:
- if (randr && resp_type == randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY)
+ if (randr && resp_type == randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY) {
update_monitors();
+ }
break;
}
}
coordinates_t loc;
bool is_managed = locate_window(e->window, &loc);
client_t *c = (is_managed ? loc.node->client : NULL);
- int w = 0, h = 0;
-
- if (is_managed && !IS_FLOATING(c)) {
- if (e->value_mask & XCB_CONFIG_WINDOW_X)
- c->floating_rectangle.x = e->x;
- if (e->value_mask & XCB_CONFIG_WINDOW_Y)
- c->floating_rectangle.y = e->y;
- if (e->value_mask & XCB_CONFIG_WINDOW_WIDTH)
- w = e->width;
- if (e->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
- h = e->height;
-
- if (w != 0) {
- restrain_floating_width(c, &w);
- c->floating_rectangle.width = w;
- }
-
- if (h != 0) {
- restrain_floating_height(c, &h);
- c->floating_rectangle.height = h;
- }
-
- xcb_configure_notify_event_t evt;
- xcb_window_t win = c->window;
- unsigned int bw = c->border_width;
+ uint16_t width, height;
- xcb_rectangle_t rect = get_rectangle(loc.monitor, c);
-
- evt.response_type = XCB_CONFIGURE_NOTIFY;
- evt.event = win;
- evt.window = win;
- evt.above_sibling = XCB_NONE;
- evt.x = rect.x;
- evt.y = rect.y;
- evt.width = rect.width;
- evt.height = rect.height;
- evt.border_width = bw;
- evt.override_redirect = false;
-
- xcb_send_event(dpy, false, win, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (const char *) &evt);
-
- if (c->state == STATE_PSEUDO_TILED) {
- arrange(loc.monitor, loc.desktop);
- }
- } else {
+ if (!is_managed) {
uint16_t mask = 0;
uint32_t values[7];
unsigned short i = 0;
if (e->value_mask & XCB_CONFIG_WINDOW_X) {
mask |= XCB_CONFIG_WINDOW_X;
values[i++] = e->x;
- if (is_managed)
- c->floating_rectangle.x = e->x;
}
if (e->value_mask & XCB_CONFIG_WINDOW_Y) {
mask |= XCB_CONFIG_WINDOW_Y;
values[i++] = e->y;
- if (is_managed)
- c->floating_rectangle.y = e->y;
}
if (e->value_mask & XCB_CONFIG_WINDOW_WIDTH) {
mask |= XCB_CONFIG_WINDOW_WIDTH;
- w = e->width;
- if (is_managed) {
- restrain_floating_width(c, &w);
- c->floating_rectangle.width = w;
- }
- values[i++] = w;
+ values[i++] = e->width;
}
if (e->value_mask & XCB_CONFIG_WINDOW_HEIGHT) {
mask |= XCB_CONFIG_WINDOW_HEIGHT;
- h = e->height;
- if (is_managed) {
- restrain_floating_height(c, &h);
- c->floating_rectangle.height = h;
- }
- values[i++] = h;
+ values[i++] = e->height;
}
- if (!is_managed && e->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH) {
+ if (e->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH) {
mask |= XCB_CONFIG_WINDOW_BORDER_WIDTH;
values[i++] = e->border_width;
}
xcb_configure_window(dpy, e->window, mask, values);
- if (is_managed && (mask & XCB_CONFIG_WINDOW_X_Y_WIDTH_HEIGHT)) {
- xcb_rectangle_t r = c->floating_rectangle;
- put_status(SBSC_MASK_WINDOW_GEOMETRY, "window_geometry %s %s 0x%X %ux%u+%i+%i\n", loc.monitor->name, loc.desktop->name, c->window, r.width, r.height, r.x, r.y);
+ } else if (IS_FLOATING(c)) {
+ width = c->floating_rectangle.width;
+ height = c->floating_rectangle.height;
+
+ if (e->value_mask & XCB_CONFIG_WINDOW_X) {
+ c->floating_rectangle.x = e->x;
}
- }
- if (is_managed) {
- translate_client(monitor_from_client(c), loc.monitor, c);
+ if (e->value_mask & XCB_CONFIG_WINDOW_Y) {
+ c->floating_rectangle.y = e->y;
+ }
+
+ if (e->value_mask & XCB_CONFIG_WINDOW_WIDTH) {
+ width = e->width;
+ }
+
+ if (e->value_mask & XCB_CONFIG_WINDOW_HEIGHT) {
+ height = e->height;
+ }
+
+ apply_size_hints(c, &width, &height);
+ c->floating_rectangle.width = width;
+ c->floating_rectangle.height = height;
+ xcb_rectangle_t r = c->floating_rectangle;
+
+ window_move_resize(e->window, r.x, r.y, r.width, r.height);
+
+ 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);
+ if (m != loc.monitor) {
+ transfer_node(loc.monitor, loc.desktop, loc.node, m, m->desk, m->desk->focus);
+ }
+ } else {
+ if (c->state == STATE_PSEUDO_TILED) {
+ width = c->floating_rectangle.width;
+ height = c->floating_rectangle.height;
+ if (e->value_mask & XCB_CONFIG_WINDOW_WIDTH) {
+ width = e->width;
+ }
+ if (e->value_mask & XCB_CONFIG_WINDOW_HEIGHT) {
+ height = e->height;
+ }
+ apply_size_hints(c, &width, &height);
+ if (width != c->floating_rectangle.width || height != c->floating_rectangle.height) {
+ c->floating_rectangle.width = width;
+ c->floating_rectangle.height = height;
+ arrange(loc.monitor, loc.desktop);
+ }
+ }
+
+
+ xcb_configure_notify_event_t evt;
+ unsigned int bw = c->border_width;
+
+ xcb_rectangle_t r = IS_FULLSCREEN(c) ? loc.monitor->rectangle : c->tiled_rectangle;
+
+ evt.response_type = XCB_CONFIGURE_NOTIFY;
+ evt.event = e->window;
+ evt.window = e->window;
+ evt.above_sibling = XCB_NONE;
+ evt.x = r.x;
+ evt.y = r.y;
+ evt.width = r.width;
+ evt.height = r.height;
+ evt.border_width = bw;
+ evt.override_redirect = false;
+
+ xcb_send_event(dpy, false, e->window, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (const char *) &evt);
}
}
}
coordinates_t loc;
- if (!locate_window(e->window, &loc))
+ if (!locate_window(e->window, &loc)) {
return;
+ }
if (e->atom == XCB_ATOM_WM_HINTS) {
xcb_icccm_wm_hints_t hints;
if (xcb_icccm_get_wm_hints_reply(dpy, xcb_icccm_get_wm_hints(dpy, e->window), &hints, NULL) == 1 &&
(hints.flags & XCB_ICCCM_WM_HINT_X_URGENCY))
- set_urgency(loc.monitor, loc.desktop, loc.node, xcb_icccm_wm_hints_get_urgency(&hints));
+ set_urgent(loc.monitor, loc.desktop, loc.node, xcb_icccm_wm_hints_get_urgency(&hints));
} else if (e->atom == XCB_ATOM_WM_NORMAL_HINTS) {
client_t *c = loc.node->client;
- xcb_size_hints_t size_hints;
- if (xcb_icccm_get_wm_normal_hints_reply(dpy, xcb_icccm_get_wm_normal_hints(dpy, e->window), &size_hints, NULL) == 1 &&
- (size_hints.flags & (XCB_ICCCM_SIZE_HINT_P_MIN_SIZE | XCB_ICCCM_SIZE_HINT_P_MAX_SIZE))) {
- c->min_width = size_hints.min_width;
- c->max_width = size_hints.max_width;
- c->min_height = size_hints.min_height;
- c->max_height = size_hints.max_height;
- int w = c->floating_rectangle.width;
- int h = c->floating_rectangle.height;
- restrain_floating_size(c, &w, &h);
- c->floating_rectangle.width = w;
- c->floating_rectangle.height = h;
+ if (xcb_icccm_get_wm_normal_hints_reply(dpy, xcb_icccm_get_wm_normal_hints(dpy, e->window), &c->size_hints, NULL) == 1) {
arrange(loc.monitor, loc.desktop);
}
}
if (e->type == ewmh->_NET_CURRENT_DESKTOP) {
coordinates_t loc;
- if (ewmh_locate_desktop(e->data.data32[0], &loc))
+ if (ewmh_locate_desktop(e->data.data32[0], &loc)) {
focus_node(loc.monitor, loc.desktop, loc.desktop->focus);
+ }
return;
}
coordinates_t loc;
- if (!locate_window(e->window, &loc))
+ if (!locate_window(e->window, &loc)) {
return;
+ }
if (e->type == ewmh->_NET_WM_STATE) {
handle_state(loc.monitor, loc.desktop, loc.node, e->data.data32[1], e->data.data32[0]);
handle_state(loc.monitor, loc.desktop, loc.node, e->data.data32[2], e->data.data32[0]);
} else if (e->type == ewmh->_NET_ACTIVE_WINDOW) {
if ((ignore_ewmh_focus && e->data.data32[0] == XCB_EWMH_CLIENT_SOURCE_TYPE_NORMAL) ||
- loc.node == mon->desk->focus)
+ loc.node == mon->desk->focus) {
return;
+ }
focus_node(loc.monitor, loc.desktop, loc.node);
} else if (e->type == ewmh->_NET_WM_DESKTOP) {
coordinates_t dloc;
- if (ewmh_locate_desktop(e->data.data32[0], &dloc))
+ if (ewmh_locate_desktop(e->data.data32[0], &dloc)) {
transfer_node(loc.monitor, loc.desktop, loc.node, dloc.monitor, dloc.desktop, dloc.desktop->focus);
+ }
} else if (e->type == ewmh->_NET_CLOSE_WINDOW) {
- window_close(loc.node);
+ close_node(loc.node);
}
}
{
xcb_focus_in_event_t *e = (xcb_focus_in_event_t *) evt;
- if (e->mode == XCB_NOTIFY_MODE_GRAB ||
- e->mode == XCB_NOTIFY_MODE_UNGRAB)
+ if (e->mode == XCB_NOTIFY_MODE_GRAB || e->mode == XCB_NOTIFY_MODE_UNGRAB
+ || e->detail == XCB_NOTIFY_DETAIL_POINTER || e->detail == XCB_NOTIFY_DETAIL_POINTER_ROOT
+ || e->detail == XCB_NOTIFY_DETAIL_NONE) {
+ return;
+ }
+
+ if (mon->desk->focus != NULL && e->event == mon->desk->focus->id) {
return;
- /* prevent focus stealing */
- 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))
+ }
+
+ coordinates_t loc;
+ if (locate_window(e->event, &loc)) {
+ // prevent input focus stealing
update_input_focus();
+ }
+}
+
+void button_press(xcb_generic_event_t *evt)
+{
+ xcb_button_press_event_t *e = (xcb_button_press_event_t *) evt;
+ switch (e->detail) {
+ case XCB_BUTTON_INDEX_1:
+ if (click_to_focus && cleaned_mask(e->state) == XCB_NONE) {
+ xcb_allow_events(dpy, XCB_ALLOW_REPLAY_POINTER, e->time);
+ xcb_flush(dpy);
+ grab_pointer(ACTION_FOCUS);
+ } else {
+ grab_pointer(ACTION_MOVE);
+ }
+ break;
+ case XCB_BUTTON_INDEX_2:
+ grab_pointer(ACTION_RESIZE_SIDE);
+ break;
+ case XCB_BUTTON_INDEX_3:
+ grab_pointer(ACTION_RESIZE_CORNER);
+ break;
+ }
}
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->id == win)) {
return;
}
{
xcb_motion_notify_event_t *e = (xcb_motion_notify_event_t *) evt;
- int dtime = e->time - last_motion_time;
+ static uint16_t last_motion_x = 0, last_motion_y = 0;
+ static xcb_timestamp_t last_motion_time = 0;
+
+ int64_t dtime = e->time - last_motion_time;
+
if (dtime > 1000) {
last_motion_time = e->time;
last_motion_x = e->event_x;
if (action == XCB_EWMH_WM_STATE_ADD) {
set_state(m, d, n, STATE_FULLSCREEN);
} else if (action == XCB_EWMH_WM_STATE_REMOVE) {
- set_state(m, d, n, n->client->last_state);
+ if (n->client->state == STATE_FULLSCREEN) {
+ set_state(m, d, n, n->client->last_state);
+ }
} else if (action == XCB_EWMH_WM_STATE_TOGGLE) {
set_state(m, d, n, IS_FULLSCREEN(n->client) ? n->client->last_state : STATE_FULLSCREEN);
}
if (action == XCB_EWMH_WM_STATE_ADD) {
set_layer(m, d, n, LAYER_BELOW);
} else if (action == XCB_EWMH_WM_STATE_REMOVE) {
- set_layer(m, d, n, LAYER_NORMAL);
+ if (n->client->layer == LAYER_BELOW) {
+ set_layer(m, d, n, n->client->last_layer);
+ }
} else if (action == XCB_EWMH_WM_STATE_TOGGLE) {
set_layer(m, d, n, n->client->layer == LAYER_BELOW ? n->client->last_layer : LAYER_BELOW);
}
if (action == XCB_EWMH_WM_STATE_ADD) {
set_layer(m, d, n, LAYER_ABOVE);
} else if (action == XCB_EWMH_WM_STATE_REMOVE) {
- set_layer(m, d, n, n->client->last_layer);
+ if (n->client->layer == LAYER_ABOVE) {
+ set_layer(m, d, n, n->client->last_layer);
+ }
} else if (action == XCB_EWMH_WM_STATE_TOGGLE) {
set_layer(m, d, n, n->client->layer == LAYER_ABOVE ? n->client->last_layer : LAYER_ABOVE);
}
} else if (action == XCB_EWMH_WM_STATE_REMOVE) {
set_sticky(m, d, n, false);
} else if (action == XCB_EWMH_WM_STATE_TOGGLE) {
- set_sticky(m, d, n, !n->client->sticky);
+ set_sticky(m, d, n, !n->sticky);
}
} else if (state == ewmh->_NET_WM_STATE_DEMANDS_ATTENTION) {
if (action == XCB_EWMH_WM_STATE_ADD) {
- set_urgency(m, d, n, true);
+ set_urgent(m, d, n, true);
} else if (action == XCB_EWMH_WM_STATE_REMOVE) {
- set_urgency(m, d, n, false);
+ set_urgent(m, d, n, false);
} else if (action == XCB_EWMH_WM_STATE_TOGGLE) {
- set_urgency(m, d, n, !n->client->urgent);
+ set_urgent(m, d, n, !n->client->urgent);
}
+#define HANDLE_WM_STATE(s) \
+ } else if (state == ewmh->_NET_WM_STATE_##s) { \
+ if (action == XCB_EWMH_WM_STATE_ADD) { \
+ n->client->wm_flags |= WM_FLAG_##s; \
+ } else if (action == XCB_EWMH_WM_STATE_REMOVE) { \
+ n->client->wm_flags &= ~WM_FLAG_##s; \
+ } else if (action == XCB_EWMH_WM_STATE_TOGGLE) { \
+ n->client->wm_flags ^= WM_FLAG_##s; \
+ } \
+ ewmh_wm_state_update(n);
+ HANDLE_WM_STATE(MODAL)
+ HANDLE_WM_STATE(MAXIMIZED_VERT)
+ HANDLE_WM_STATE(MAXIMIZED_HORZ)
+ HANDLE_WM_STATE(SHADED)
+ HANDLE_WM_STATE(SKIP_TASKBAR)
+ HANDLE_WM_STATE(SKIP_PAGER)
+ HANDLE_WM_STATE(HIDDEN)
}
+#undef HANDLE_WM_STATE
}
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);
+ warn("Failed request: %s, %s: 0x%08X.\n", xcb_event_get_request_label(e->major_opcode), xcb_event_get_error_label(e->error_code), e->bad_value);
}