24 const xcb_button_press_event_t *
event;
44 uint32_t x2, uint32_t y2) {
47 return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) > threshold * threshold;
51 xcb_motion_notify_event_t *last_motion_notify = NULL;
52 xcb_generic_event_t *event;
54 while ((event = xcb_poll_for_event(
conn)) != NULL) {
55 if (event->response_type == 0) {
56 xcb_generic_error_t *error = (xcb_generic_error_t *)event;
57 DLOG(
"X11 Error received (probably harmless)! sequence 0x%x, error_code = %d\n",
58 error->sequence, error->error_code);
64 int type = (
event->response_type & 0x7F);
67 case XCB_BUTTON_RELEASE:
72 DLOG(
"A key was pressed during drag, reverting changes.\n");
77 case XCB_UNMAP_NOTIFY: {
78 xcb_unmap_notify_event_t *unmap_event = (xcb_unmap_notify_event_t *)event;
82 DLOG(
"UnmapNotify for window 0x%08x (container %p)\n", unmap_event->window, con);
85 DLOG(
"UnmapNotify for a managed window on the current workspace, aborting\n");
94 case XCB_MOTION_NOTIFY:
96 FREE(last_motion_notify);
97 last_motion_notify = (xcb_motion_notify_event_t *)event;
101 DLOG(
"Passing to original handler\n");
106 if (last_motion_notify != (xcb_motion_notify_event_t *)event) {
111 ev_break(EV_A_ EVBREAK_ONE);
116 free(last_motion_notify);
122 if (last_motion_notify == NULL) {
128 dragloop->
event->root_x, dragloop->
event->root_y)) {
129 if (dragloop->
xcursor != XCB_NONE) {
130 xcb_change_active_pointer_grab(
134 XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION);
146 last_motion_notify->root_x,
147 last_motion_notify->root_y,
151 FREE(last_motion_notify);
177 xcb_window_t confine_to,
int cursor,
183 xcb_grab_pointer_cookie_t cookie;
184 xcb_grab_pointer_reply_t *reply;
185 xcb_generic_error_t *error;
187 cookie = xcb_grab_pointer(
conn,
190 XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION,
194 use_threshold ? XCB_NONE :
xcursor,
197 if ((reply = xcb_grab_pointer_reply(
conn, cookie, &error)) == NULL) {
198 ELOG(
"Could not grab pointer (error_code = %d)\n", error->error_code);
206 xcb_grab_keyboard_cookie_t keyb_cookie;
207 xcb_grab_keyboard_reply_t *keyb_reply;
209 keyb_cookie = xcb_grab_keyboard(
conn,
217 if ((keyb_reply = xcb_grab_keyboard_reply(
conn, keyb_cookie, &error)) == NULL) {
218 ELOG(
"Could not grab keyboard (error_code = %d)\n", error->error_code);
220 xcb_ungrab_pointer(
conn, XCB_CURRENT_TIME);
232 .threshold_exceeded = !use_threshold,
250 xcb_ungrab_keyboard(
conn, XCB_CURRENT_TIME);
251 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_cursor_t xcursor_get_cursor(enum xcursor_cursor_t c)
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
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.
int logical_px(const int logical)
Convert a logical amount of pixels (e.g.
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.