24 const xcb_button_press_event_t *
event;
44 uint32_t x2, uint32_t y2) {
45 const uint32_t threshold = 9;
46 return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) > threshold * threshold;
50 xcb_motion_notify_event_t *last_motion_notify = NULL;
51 xcb_generic_event_t *event;
53 while ((event = xcb_poll_for_event(
conn)) != NULL) {
54 if (event->response_type == 0) {
55 xcb_generic_error_t *error = (xcb_generic_error_t *)event;
56 DLOG(
"X11 Error received (probably harmless)! sequence 0x%x, error_code = %d\n",
57 error->sequence, error->error_code);
63 int type = (
event->response_type & 0x7F);
66 case XCB_BUTTON_RELEASE:
71 DLOG(
"A key was pressed during drag, reverting changes.\n");
76 case XCB_UNMAP_NOTIFY: {
77 xcb_unmap_notify_event_t *unmap_event = (xcb_unmap_notify_event_t *)event;
81 DLOG(
"UnmapNotify for window 0x%08x (container %p)\n", unmap_event->window, con);
84 DLOG(
"UnmapNotify for a managed window on the current workspace, aborting\n");
93 case XCB_MOTION_NOTIFY:
95 FREE(last_motion_notify);
96 last_motion_notify = (xcb_motion_notify_event_t *)event;
100 DLOG(
"Passing to original handler\n");
105 if (last_motion_notify != (xcb_motion_notify_event_t *)event)
109 ev_break(EV_A_ EVBREAK_ONE);
114 free(last_motion_notify);
120 if (last_motion_notify == NULL) {
126 dragloop->
event->root_x, dragloop->
event->root_y)) {
127 if (dragloop->
xcursor != XCB_NONE) {
128 xcb_change_active_pointer_grab(
132 XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION);
144 last_motion_notify->root_x,
145 last_motion_notify->root_y,
149 FREE(last_motion_notify);
175 xcb_window_t confine_to,
int cursor,
181 xcb_grab_pointer_cookie_t cookie;
182 xcb_grab_pointer_reply_t *reply;
183 xcb_generic_error_t *error;
185 cookie = xcb_grab_pointer(
conn,
188 XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION,
192 use_threshold ? XCB_NONE :
xcursor,
195 if ((reply = xcb_grab_pointer_reply(
conn, cookie, &error)) == NULL) {
196 ELOG(
"Could not grab pointer (error_code = %d)\n", error->error_code);
204 xcb_grab_keyboard_cookie_t keyb_cookie;
205 xcb_grab_keyboard_reply_t *keyb_reply;
207 keyb_cookie = xcb_grab_keyboard(
conn,
215 if ((keyb_reply = xcb_grab_keyboard_reply(
conn, keyb_cookie, &error)) == NULL) {
216 ELOG(
"Could not grab keyboard (error_code = %d)\n", error->error_code);
218 xcb_ungrab_pointer(
conn, XCB_CURRENT_TIME);
230 .threshold_exceeded = !use_threshold,
247 xcb_ungrab_keyboard(
conn, XCB_CURRENT_TIME);
248 xcb_ungrab_pointer(
conn, XCB_CURRENT_TIME);