From 1176b5c36928bd2f3fe8607963bc253a871ae9fd Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Thu, 7 Mar 2013 21:53:45 +0100 Subject: [PATCH] Lower the motion recorder when querying The current implementation of `focus_follows_pointer` requires that the motion recorder be lowered when `xcb_query_pointer` is called, otherwise, the response will specify the motion recorder as child attribute. --- events.c | 21 ++++++++------------- tree.c | 2 +- window.c | 7 +++++-- window.h | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/events.c b/events.c index 57b0d03..97a6bd0 100644 --- a/events.c +++ b/events.c @@ -247,7 +247,7 @@ void motion_notify(void) disable_motion_recorder(); xcb_window_t win = XCB_NONE; - get_pointed_window(&win); + query_pointer(&win, NULL); if (win != XCB_NONE) window_focus(win); } @@ -269,17 +269,13 @@ void grab_pointer(pointer_action_t pac) { 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)) { @@ -423,10 +419,9 @@ void track_pointer(int root_x, int root_y) 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); + xcb_window_t pwin = XCB_NONE; + query_pointer(&pwin, NULL); + if (pwin != XCB_NONE) { window_location_t loc; if (locate_window(pwin, &loc) && is_tiled(loc.node->client)) { swap_nodes(d, n, loc.desktop, loc.node); diff --git a/tree.c b/tree.c index ec45aa3..130df1c 100644 --- a/tree.c +++ b/tree.c @@ -388,7 +388,7 @@ void focus_node(monitor_t *m, desktop_t *d, node_t *n, bool is_mapped) if (focus_follows_pointer) { xcb_window_t win = XCB_NONE; - get_pointed_window(&win); + query_pointer(&win, NULL); if (win != n->client->window) enable_motion_recorder(); else diff --git a/window.c b/window.c index 9bd32e3..ea0b9d6 100644 --- a/window.c +++ b/window.c @@ -412,12 +412,15 @@ void update_floating_rectangle(client_t *c) } -void get_pointed_window(xcb_window_t *win) +void query_pointer(xcb_window_t *win, xcb_point_t *pt) { window_lower(motion_recorder); xcb_query_pointer_reply_t *qpr = xcb_query_pointer_reply(dpy, xcb_query_pointer(dpy, root), NULL); if (qpr != NULL) { - *win = qpr->child; + if (win != NULL) + *win = qpr->child; + if (pt != NULL) + *pt = (xcb_point_t) {qpr->root_x, qpr->root_y}; free(qpr); } window_raise(motion_recorder); diff --git a/window.h b/window.h index cb72b12..9dc4456 100644 --- a/window.h +++ b/window.h @@ -39,7 +39,7 @@ void disable_motion_recorder(void); void toggle_visibility(void); uint32_t get_border_color(client_t *, bool, bool); void update_floating_rectangle(client_t *); -void get_pointed_window(xcb_window_t *); +void query_pointer(xcb_window_t *, xcb_point_t *); void list_windows(char *); #endif -- 2.44.0