[PATCH weston v1 3/3] compositor-x11: remove manual mouse button grab/ungrab

Benoit Gschwind gschwind at gnu-log.net
Fri May 13 11:34:57 UTC 2016


In current compositor-x11, the mouse buttons are grabbed and ungrabbed
manually that may produce weird cases like starting a grab while the
buttons are already released, due to asynchronous X11 events dispatching.

The patch avoid the issue by using the better passive button grab, that
automatically grab buttons as soon as they occur. The passive grab
include an automatic ungrab when all mouse button are released.

This probably fix some mysterious bugs.

Signed-off-by: Benoit Gschwind <gschwind at gnu-log.net>
---
 src/compositor-x11.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index 5b76dba..ae155d1 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -882,6 +882,19 @@ x11_backend_create_output(struct x11_backend *b, int x, int y,
 
 	x11_output_set_wm_protocols(b, output);
 
+	/* Automatically grab and ungrab mouse buttons */
+	xcb_grab_button(b->conn, 0, output->window,
+			XCB_EVENT_MASK_BUTTON_PRESS |
+			XCB_EVENT_MASK_BUTTON_RELEASE |
+			XCB_EVENT_MASK_POINTER_MOTION |
+			XCB_EVENT_MASK_ENTER_WINDOW |
+			XCB_EVENT_MASK_LEAVE_WINDOW,
+			XCB_GRAB_MODE_ASYNC,
+			XCB_GRAB_MODE_ASYNC,
+			output->window, XCB_CURSOR_NONE,
+			XCB_BUTTON_INDEX_ANY,
+			XCB_MOD_MASK_ANY);
+
 	xcb_map_window(b->conn, output->window);
 
 	if (fullscreen)
@@ -1052,20 +1065,6 @@ x11_backend_deliver_button_event(struct x11_backend *b,
 	if (!output)
 		return;
 
-	if (is_button_pressed)
-		xcb_grab_pointer(b->conn, 0, output->window,
-				 XCB_EVENT_MASK_BUTTON_PRESS |
-				 XCB_EVENT_MASK_BUTTON_RELEASE |
-				 XCB_EVENT_MASK_POINTER_MOTION |
-				 XCB_EVENT_MASK_ENTER_WINDOW |
-				 XCB_EVENT_MASK_LEAVE_WINDOW,
-				 XCB_GRAB_MODE_ASYNC,
-				 XCB_GRAB_MODE_ASYNC,
-				 output->window, XCB_CURSOR_NONE,
-				 button_event->time);
-	else
-		xcb_ungrab_pointer(b->conn, button_event->time);
-
 	if (!b->has_xkb)
 		update_xkb_state_from_core(b, button_event->state);
 
-- 
2.7.3



More information about the wayland-devel mailing list