[RFC weston 2/3] toytoolkit: add support for relative pointers

Philipp Brüschweiler blei42 at gmail.com
Sat Sep 1 08:50:56 PDT 2012


Only the motion events of relative_pointers are acted upon, as the other
events are identical to the "normal" pointer.
---
 clients/window.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 clients/window.h |  7 ++++++
 2 Dateien geändert, 81 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)

diff --git a/clients/window.c b/clients/window.c
index 330d96f..cc89050 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -183,6 +183,7 @@ struct widget {
 	widget_enter_handler_t enter_handler;
 	widget_leave_handler_t leave_handler;
 	widget_motion_handler_t motion_handler;
+	widget_relative_motion_handler_t relative_motion_handler;
 	widget_button_handler_t button_handler;
 	widget_axis_handler_t axis_handler;
 	void *user_data;
@@ -194,6 +195,7 @@ struct input {
 	struct display *display;
 	struct wl_seat *seat;
 	struct wl_pointer *pointer;
+	struct wl_relative_pointer *relative_pointer;
 	struct wl_keyboard *keyboard;
 	struct window *pointer_focus;
 	struct window *keyboard_focus;
@@ -1143,6 +1145,13 @@ widget_set_motion_handler(struct widget *widget,
 }
 
 void
+widget_set_relative_motion_handler(struct widget *widget,
+				   widget_relative_motion_handler_t handler)
+{
+	widget->relative_motion_handler = handler;
+}
+
+void
 widget_set_button_handler(struct widget *widget,
 			  widget_button_handler_t handler)
 {
@@ -2071,6 +2080,63 @@ static const struct wl_pointer_listener pointer_listener = {
 };
 
 static void
+relative_pointer_handle_enter(void *data, struct wl_relative_pointer *pointer,
+			      uint32_t serial, struct wl_surface *surface,
+			      wl_fixed_t sx_w, wl_fixed_t sy_w)
+{
+	/* ignore */
+}
+
+static void
+relative_pointer_handle_leave(void *data, struct wl_relative_pointer *pointer,
+			      uint32_t serial, struct wl_surface *surface)
+{
+	/* ignore */
+}
+
+static void
+relative_pointer_handle_motion(void *data, struct wl_relative_pointer *pointer,
+			       uint32_t time, wl_fixed_t dx_w, wl_fixed_t dy_w)
+{
+	struct input *input = data;
+	struct widget *widget;
+	float dx = wl_fixed_to_double(dx_w);
+	float dy = wl_fixed_to_double(dy_w);
+
+	if (input->grab)
+		widget = input->grab;
+	else
+		widget = input->focus_widget;
+	if (widget && widget->relative_motion_handler)
+		widget->relative_motion_handler(widget,
+						input, time, dx, dy,
+						widget->user_data);
+}
+
+static void
+relative_pointer_handle_button(void *data, struct wl_relative_pointer *pointer,
+			       uint32_t serial, uint32_t time, uint32_t button,
+			       uint32_t state_w)
+{
+	/* ignored */
+}
+
+static void
+relative_pointer_handle_axis(void *data, struct wl_relative_pointer *pointer,
+			     uint32_t time, uint32_t axis, wl_fixed_t value)
+{
+	/* ignored */
+}
+
+static const struct wl_relative_pointer_listener relative_pointer_listener = {
+	relative_pointer_handle_enter,
+	relative_pointer_handle_leave,
+	relative_pointer_handle_motion,
+	relative_pointer_handle_button,
+	relative_pointer_handle_axis,
+};
+
+static void
 input_remove_keyboard_focus(struct input *input)
 {
 	struct window *window = input->keyboard_focus;
@@ -2298,17 +2364,23 @@ seat_handle_capabilities(void *data, struct wl_seat *seat,
 
 	if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
 		input->pointer = wl_seat_get_pointer(seat);
-		wl_pointer_set_user_data(input->pointer, input);
 		wl_pointer_add_listener(input->pointer, &pointer_listener,
 					input);
+
+		input->relative_pointer = wl_seat_get_relative_pointer(seat);
+		wl_relative_pointer_add_listener(input->relative_pointer,
+						 &relative_pointer_listener,
+						 input);
 	} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
 		wl_pointer_destroy(input->pointer);
 		input->pointer = NULL;
+
+		wl_relative_pointer_destroy(input->relative_pointer);
+		input->relative_pointer = NULL;
 	}
 
 	if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
 		input->keyboard = wl_seat_get_keyboard(seat);
-		wl_keyboard_set_user_data(input->keyboard, input);
 		wl_keyboard_add_listener(input->keyboard, &keyboard_listener,
 					 input);
 	} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
diff --git a/clients/window.h b/clients/window.h
index 41f63da..066e698 100644
--- a/clients/window.h
+++ b/clients/window.h
@@ -191,6 +191,10 @@ typedef void (*widget_leave_handler_t)(struct widget *widget,
 typedef int (*widget_motion_handler_t)(struct widget *widget,
 				       struct input *input, uint32_t time,
 				       float x, float y, void *data);
+typedef void (*widget_relative_motion_handler_t)(struct widget *widget,
+						 struct input *input,
+						 uint32_t time, float dx,
+						 float dy, void *data);
 typedef void (*widget_button_handler_t)(struct widget *widget,
 					struct input *input, uint32_t time,
 					uint32_t button,
@@ -368,6 +372,9 @@ void
 widget_set_motion_handler(struct widget *widget,
 			  widget_motion_handler_t handler);
 void
+widget_set_relative_motion_handler(struct widget *widget,
+				   widget_relative_motion_handler_t handler);
+void
 widget_set_button_handler(struct widget *widget,
 			  widget_button_handler_t handler);
 void
-- 
1.7.12



More information about the wayland-devel mailing list