From 18f6ab107f1b57dda947386c8c074a604ce08244 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 5 Jul 2015 16:14:41 +0200 Subject: [PATCH] Mousegrabber: Correctly handle press/release events When you run a mousegrabber, the C code calls this callback when the pointer is moved or when a button is pressed/released. However, the button state is totally bogus on press/release events, always claiming that the button that was pressed/released is the only button that is pressed (even for release events!). This commit fixes up the code so that the button state after the press/release event is passed to the mousegrabber callback function. Fixes: #280 Signed-off-by: Uli Schlachter --- event.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/event.c b/event.c index ca789907b..0428b12d8 100644 --- a/event.c +++ b/event.c @@ -173,8 +173,18 @@ event_handle_button(xcb_button_press_event_t *ev) globalconf.timestamp = ev->time; - if(event_handle_mousegrabber(ev->root_x, ev->root_y, 1 << (ev->detail - 1 + 8))) - return; + { + /* ev->state contains the state before the event. Compute the state + * after the event for the mousegrabber. + */ + uint16_t state = ev->state, change = 1 << (ev->detail - 1 + 8); + if (XCB_EVENT_RESPONSE_TYPE(ev) == XCB_BUTTON_PRESS) + state |= change; + else + state &= ~change; + if(event_handle_mousegrabber(ev->root_x, ev->root_y, state)) + return; + } /* ev->state is * button status (8 bits) + modifiers status (8 bits)