[PATCH] compositor-x11: convert (some) of X11 buttons to linux input

Tiago Vignatti vignatti at freedesktop.org
Thu Dec 8 07:03:17 PST 2011


From: Tiago Vignatti <tiago.vignatti at intel.com>

Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---
 compositor/compositor-x11.c |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/compositor/compositor-x11.c b/compositor/compositor-x11.c
index 544d7e2..870d57a 100644
--- a/compositor/compositor-x11.c
+++ b/compositor/compositor-x11.c
@@ -453,6 +453,31 @@ x11_compositor_find_output(struct x11_compositor *c, xcb_window_t window)
 	return NULL;
 }
 
+/*
+ * x11_to_rawinput - convert X11 button detail to linux input
+ */
+static int
+x11_to_rawinput(int detail)
+{
+	switch (detail) {
+	case 1:
+		return BTN_LEFT;
+	case 2:
+		return BTN_MIDDLE;
+	case 3:
+		return BTN_RIGHT;
+	case 4:
+	case 5:
+		/* X11 sends wheel button up and down respectively as 4 and 5.
+		 * But linux input treats as REL_WHEEL, therefore not button
+		 * type at all. If we care about them we have to implement a
+		 * different logic and forward as notify_motion.  */
+		return -2;
+	}
+
+	return -1;
+}
+
 static int
 x11_compositor_next_event(struct x11_compositor *c,
 			  xcb_generic_event_t **event, uint32_t mask)
@@ -556,13 +581,15 @@ x11_compositor_handle_event(int fd, uint32_t mask, void *data)
 			button_press = (xcb_button_press_event_t *) event;
 			notify_button(c->base.input_device,
 				      wlsc_compositor_get_time(),
-				      button_press->detail + BTN_LEFT - 1, 1);
+				      x11_to_rawinput(button_press->detail),
+				      1);
 			break;
 		case XCB_BUTTON_RELEASE:
 			button_press = (xcb_button_press_event_t *) event;
 			notify_button(c->base.input_device,
 				      wlsc_compositor_get_time(),
-				      button_press->detail + BTN_LEFT - 1, 0);
+				      x11_to_rawinput(button_press->detail),
+				      0);
 			break;
 
 		case XCB_MOTION_NOTIFY:
-- 
1.7.5.4



More information about the wayland-devel mailing list