#include <stdlib.h>
#include <string.h>
#include <xcb/xcb.h>
+#include <xcb/randr.h>
#include <xcb/xcb_event.h>
#include <xcb/xcb_icccm.h>
#include "types.h"
void handle_event(xcb_generic_event_t *evt)
{
- switch (XCB_EVENT_RESPONSE_TYPE(evt)) {
+ uint8_t resp_type = XCB_EVENT_RESPONSE_TYPE(evt);
+ switch (resp_type) {
case XCB_MAP_REQUEST:
map_request(evt);
break;
enter_notify(evt);
break;
case XCB_MOTION_NOTIFY:
- motion_notify(evt);
+ motion_notify();
break;
default:
+ if (resp_type == randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY)
+ import_monitors();
break;
}
}
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)
if (e->type == ewmh->_NET_CURRENT_DESKTOP) {
desktop_location_t loc;
- if (ewmh_locate_desktop(e->data.data32[0], &loc)) {
- select_monitor(loc.monitor);
- select_desktop(loc.desktop);
- }
+ if (ewmh_locate_desktop(e->data.data32[0], &loc))
+ focus_node(loc.monitor, loc.desktop, loc.desktop->focus);
return;
}
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 (loc.desktop->focus->client->fullscreen && loc.desktop->focus != loc.node)
+ if (loc.desktop->focus->client->fullscreen && loc.desktop->focus != loc.node) {
toggle_fullscreen(loc.monitor, loc.desktop->focus->client);
- select_monitor(loc.monitor);
- select_desktop(loc.desktop);
- focus_node(loc.monitor, loc.desktop, loc.node, true);
- arrange(loc.monitor, loc.desktop);
+ arrange(loc.monitor, loc.desktop);
+ }
+ focus_node(loc.monitor, loc.desktop, loc.node);
}
}
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)
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);
}
}
{
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)) {
switch (pac) {
case ACTION_FOCUS:
- focus_node(loc.monitor, loc.desktop, loc.node, true);
+ if (loc.node != mon->desk->focus)
+ focus_node(loc.monitor, loc.desktop, loc.node);
break;
case ACTION_MOVE:
case ACTION_RESIZE_SIDE:
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(n, 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;
{
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);
- select_monitor(m);
+ focus_node(m, m->desk, m->desk->focus);
}
}