[PATCH weston 3/3] resizor: Make resizor also use pointer locks for resizing

Jonas Ådahl jadahl at gmail.com
Wed Sep 17 12:39:53 PDT 2014


Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---
 clients/resizor.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/clients/resizor.c b/clients/resizor.c
index 19c6eeb..66e1c2f 100644
--- a/clients/resizor.c
+++ b/clients/resizor.c
@@ -219,13 +219,70 @@ show_menu(struct resizor *resizor, struct input *input, uint32_t time)
 }
 
 static void
+pointer_lock_handle_motion(struct window *window,
+			   struct input *input,
+			   uint32_t time,
+			   float dx,
+			   float dy,
+			   void *data)
+{
+	struct resizor *resizor = data;
+
+	resizor->width.current += dx;
+	resizor->width.previous = resizor->width.current;
+	resizor->width.target = resizor->width.current;
+
+	resizor->height.current += dy;
+	resizor->height.previous = resizor->height.current;
+	resizor->height.target = resizor->height.current;
+
+	widget_schedule_resize(resizor->widget,
+			       resizor->width.current,
+			       resizor->height.current);
+}
+
+static void
+pointer_lock_handle_button(struct window *window,
+			   struct input *input,
+			   uint32_t time,
+			   uint32_t button,
+			   uint32_t state,
+			   void *data)
+{
+	struct resizor *resizor = data;
+
+	if (state != WL_POINTER_BUTTON_STATE_PRESSED)
+		return;
+
+	window_unlock_pointer(resizor->window);
+}
+
+static void
 button_handler(struct widget *widget,
 	       struct input *input, uint32_t time,
 	       uint32_t button, enum wl_pointer_button_state state, void *data)
 {
 	struct resizor *resizor = data;
+	struct rectangle allocation;
 
 	switch (button) {
+	case BTN_LEFT:
+		if (state != WL_POINTER_BUTTON_STATE_PRESSED)
+			break;
+
+		window_get_allocation(resizor->window, &allocation);
+
+		resizor->width.current = allocation.width;
+		resizor->width.previous = allocation.width;
+		resizor->width.target = allocation.width;
+
+		resizor->height.current = allocation.height;
+		resizor->height.previous = allocation.height;
+		resizor->height.target = allocation.height;
+
+		window_lock_pointer(resizor->window, input);
+		break;
+
 	case BTN_RIGHT:
 		if (state == WL_POINTER_BUTTON_STATE_PRESSED)
 			show_menu(resizor, input, time);
@@ -250,6 +307,11 @@ resizor_create(struct display *display)
 	window_set_keyboard_focus_handler(resizor->window,
 					  keyboard_focus_handler);
 
+	window_set_pointer_lock_motion_handler(resizor->window,
+					       pointer_lock_handle_motion);
+	window_set_pointer_lock_button_handler(resizor->window,
+					       pointer_lock_handle_button);
+
 	widget_set_button_handler(resizor->widget, button_handler);
 
 	resizor->height.previous = 400;
-- 
1.8.5.1



More information about the wayland-devel mailing list