[PATCH fullscreen-shell v5 11/18] weston-fullscreen: Add cursor drawing support and properly handle WL_FULLSCREEN_SHELL_CAPABILITY_CURSOR_PLANE

Jason Ekstrand jason at jlekstrand.net
Mon Mar 17 17:35:30 PDT 2014


Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
 clients/fullscreen.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 98 insertions(+), 4 deletions(-)

diff --git a/clients/fullscreen.c b/clients/fullscreen.c
index 247232b..1bf36b1 100644
--- a/clients/fullscreen.c
+++ b/clients/fullscreen.c
@@ -48,6 +48,7 @@ struct fullscreen {
 	int width, height;
 	int fullscreen;
 	float pointer_x, pointer_y;
+	int focussed, draw_cursor;
 
 	struct wl_list output_list;
 	struct fs_output *current_output;
@@ -186,7 +187,8 @@ redraw_handler(struct widget *widget, void *data)
 		x = 50;
 		cairo_set_line_width (cr, border);
 		while (x + 70 < fullscreen->width) {
-			if (fullscreen->pointer_x >= x && fullscreen->pointer_x < x + 50 &&
+			if (fullscreen->focussed &&
+			    fullscreen->pointer_x >= x && fullscreen->pointer_x < x + 50 &&
 			    fullscreen->pointer_y >= y && fullscreen->pointer_y < y + 40) {
 				cairo_set_source_rgb(cr, 1, 0, 0);
 				cairo_rectangle(cr,
@@ -205,6 +207,44 @@ redraw_handler(struct widget *widget, void *data)
 		y += 50;
 	}
 
+	if (fullscreen->focussed && fullscreen->draw_cursor) {
+		cairo_set_source_rgb(cr, 1, 1, 1);
+		cairo_set_line_width (cr, 8);
+		cairo_move_to(cr,
+			      fullscreen->pointer_x - 12,
+			      fullscreen->pointer_y - 12);
+		cairo_line_to(cr,
+			      fullscreen->pointer_x + 12,
+			      fullscreen->pointer_y + 12);
+		cairo_stroke(cr);
+
+		cairo_move_to(cr,
+			      fullscreen->pointer_x + 12,
+			      fullscreen->pointer_y - 12);
+		cairo_line_to(cr,
+			      fullscreen->pointer_x - 12,
+			      fullscreen->pointer_y + 12);
+		cairo_stroke(cr);
+
+		cairo_set_source_rgb(cr, 0, 0, 0);
+		cairo_set_line_width (cr, 4);
+		cairo_move_to(cr,
+			      fullscreen->pointer_x - 10,
+			      fullscreen->pointer_y - 10);
+		cairo_line_to(cr,
+			      fullscreen->pointer_x + 10,
+			      fullscreen->pointer_y + 10);
+		cairo_stroke(cr);
+
+		cairo_move_to(cr,
+			      fullscreen->pointer_x + 10,
+			      fullscreen->pointer_y - 10);
+		cairo_line_to(cr,
+			      fullscreen->pointer_x - 10,
+			      fullscreen->pointer_y + 10);
+		cairo_stroke(cr);
+	}
+
 	cairo_destroy(cr);
 }
 
@@ -336,9 +376,37 @@ motion_handler(struct widget *widget,
 	fullscreen->pointer_y = y;
 
 	widget_schedule_redraw(widget);
-	return 0;
+
+	return fullscreen->draw_cursor ? CURSOR_BLANK : CURSOR_LEFT_PTR;
 }
 
+static int
+enter_handler(struct widget *widget,
+	      struct input *input,
+	      float x, float y, void *data)
+{
+	struct fullscreen *fullscreen = data;
+
+	fullscreen->focussed++;
+
+	fullscreen->pointer_x = x;
+	fullscreen->pointer_y = y;
+
+	widget_schedule_redraw(widget);
+
+	return fullscreen->draw_cursor ? CURSOR_BLANK : CURSOR_LEFT_PTR;
+}
+
+static void
+leave_handler(struct widget *widget,
+	      struct input *input, void *data)
+{
+	struct fullscreen *fullscreen = data;
+
+	fullscreen->focussed--;
+
+	widget_schedule_redraw(widget);
+}
 
 static void
 button_handler(struct widget *widget,
@@ -370,6 +438,25 @@ touch_handler(struct widget *widget, struct input *input,
 }
 
 static void
+fshell_capability_handler(void *data, struct _wl_fullscreen_shell *fshell,
+			  uint32_t capability)
+{
+	struct fullscreen *fullscreen = data;
+
+	switch (capability) {
+	case _WL_FULLSCREEN_SHELL_CAPABILITY_CURSOR_PLANE:
+		fullscreen->draw_cursor = 0;
+		break;
+	default:
+		break;
+	}
+}
+
+struct _wl_fullscreen_shell_listener fullscreen_shell_listener = {
+	fshell_capability_handler
+};
+
+static void
 usage(int error_code)
 {
 	fprintf(stderr, "Usage: fullscreen [OPTIONS]\n\n"
@@ -406,6 +493,9 @@ global_handler(struct display *display, uint32_t id, const char *interface,
 		fullscreen->fshell = display_bind(display, id,
 						  &_wl_fullscreen_shell_interface,
 						  1);
+		_wl_fullscreen_shell_add_listener(fullscreen->fshell,
+						  &fullscreen_shell_listener,
+						  fullscreen);
 	}
 }
 
@@ -418,6 +508,7 @@ int main(int argc, char *argv[])
 	fullscreen.width = 640;
 	fullscreen.height = 480;
 	fullscreen.fullscreen = 0;
+	fullscreen.focussed = 0;
 	fullscreen.present_method = _WL_FULLSCREEN_SHELL_PRESENT_METHOD_DEFAULT;
 	wl_list_init(&fullscreen.output_list);
 	fullscreen.current_output = NULL;
@@ -457,7 +548,8 @@ int main(int argc, char *argv[])
 						     window_get_wl_surface(fullscreen.window),
 						     fullscreen.present_method,
 						     NULL);
-
+		/* If we get the CURSOR_PLANE capability, we'll change this */
+		fullscreen.draw_cursor = 1;
 	} else {
 		fullscreen.window = window_create(d);
 	}
@@ -468,12 +560,14 @@ int main(int argc, char *argv[])
 	window_set_title(fullscreen.window, "Fullscreen");
 
 	widget_set_transparent(fullscreen.widget, 0);
-	widget_set_default_cursor(fullscreen.widget, CURSOR_LEFT_PTR);
 
+	widget_set_default_cursor(fullscreen.widget, CURSOR_LEFT_PTR);
 	widget_set_resize_handler(fullscreen.widget, resize_handler);
 	widget_set_redraw_handler(fullscreen.widget, redraw_handler);
 	widget_set_button_handler(fullscreen.widget, button_handler);
 	widget_set_motion_handler(fullscreen.widget, motion_handler);
+	widget_set_enter_handler(fullscreen.widget, enter_handler);
+	widget_set_leave_handler(fullscreen.widget, leave_handler);
 
 	widget_set_touch_down_handler(fullscreen.widget, touch_handler);
 
-- 
1.8.5.3



More information about the wayland-devel mailing list