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);
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Con * con_by_window_id(xcb_window_t window)
Returns the container with the given client window ID or NULL if no such container exists.
bool con_exists(Con *con)
Returns true if the given container (still) exists.
static void xcb_drag_prepare_cb(EV_P_ ev_prepare *w, int revents)
static bool threshold_exceeded(uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2)
static bool drain_drag_events(EV_P, struct drag_x11_cb *dragloop)
drag_result_t drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_window_t confine_to, int cursor, bool use_threshold, callback_t callback, const void *extra)
This function grabs your pointer and keyboard and lets you drag stuff around (borders).
void handle_event(int type, xcb_generic_event_t *event)
Takes an xcb_generic_event_t and calls the appropriate handler, based on the event type.
xcb_connection_t * conn
XCB connection and root screen.
void main_set_x11_cb(bool enable)
Enable or disable the main X11 event handling function.
struct ev_loop * main_loop
xcb_cursor_t xcursor_get_cursor(enum xcursor_cursor_t c)
void(* callback_t)(Con *, Rect *, uint32_t, uint32_t, const xcb_button_press_event_t *, const void *)
Callback for dragging.
drag_result_t
This is the return value of a drag operation like drag_pointer.
const xcb_button_press_event_t * event
Stores a rectangle, for example the size of a window, the child window etc.
A 'Con' represents everything from the X11 root window down to a single X11 window.