[PATCH 1/2] shell: Implement the probe_area request on the shell surface

Rob Bradford robert.bradford at intel.com
Mon Jan 28 09:19:26 PST 2013


From: Rob Bradford <rob at linux.intel.com>

---
 src/shell.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 80 insertions(+), 1 deletion(-)

diff --git a/src/shell.c b/src/shell.c
index aa1c7c1..58b5892 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -1914,6 +1914,84 @@ shell_surface_set_popup(struct wl_client *client,
 	shsurf->popup.y = y;
 }
 
+
+static void
+shell_surface_probe_area(struct wl_client *client,
+			 struct wl_resource *resource,
+			 int x,
+			 int y,
+			 int w,
+			 int h,
+			 uint32_t result_id)
+{
+	struct wl_resource result;
+	struct shell_surface *shsurf = resource->data;
+	struct {
+		struct {
+			int x;
+			int y;
+		} tl, br;
+	} orig, new;
+
+	int output_w, output_h;
+
+	int new_x, new_y, new_w, new_h;
+
+	output_w = shsurf->surface->output->current->width;
+	output_h = shsurf->surface->output->current->height;
+
+	/* orig and new are in global co-ordinates */
+	orig.tl.x = shsurf->surface->geometry.x + x;
+	orig.tl.y = shsurf->surface->geometry.y + y;
+	orig.br.x = orig.tl.x + w;
+	orig.br.y = orig.tl.y + h;
+
+	new = orig;
+
+	/* Clamp the top left so it is inside */
+	if (orig.tl.x < 0)
+	  new.tl.x = 0;
+	if (orig.tl.y < 0)
+	  new.tl.y = 0;
+	if (orig.tl.x > output_w)
+	  new.tl.x = output_w;
+	if (orig.tl.y > output_h)
+	  new.tl.y = output_h;
+
+	/* Clamp the bottom right so it is inside */
+	if (orig.br.x < 0)
+	  new.br.x = 0;
+	if (orig.br.y < 0)
+	  new.br.y = 0;
+	if (orig.br.x > output_w)
+	  new.br.x = output_w;
+	if (orig.br.y > output_h)
+	  new.br.y = output_h;
+
+	/* Translate back into relative co-ordinates */
+	new_x = new.tl.x - shsurf->surface->geometry.x;
+	new_y = new.tl.y - shsurf->surface->geometry.y;
+	new_w = new.br.x - new.tl.x;
+	new_h = new.br.y - new.tl.y;
+
+	memset(&result, 0, sizeof(result));
+
+	result.object.interface = &wl_probe_result_interface;
+	result.object.id = result_id;
+	result.destroy = NULL;
+	result.client = client;
+	result.data = NULL;
+
+	wl_client_add_resource(client, &result);
+
+	wl_resource_post_event(&result,
+			       WL_PROBE_RESULT_VISIBLE_AREA,
+			       new_x, new_y,
+			       new_w, new_h);
+
+	wl_resource_destroy(&result);
+}
+
 static const struct wl_shell_surface_interface shell_surface_implementation = {
 	shell_surface_pong,
 	shell_surface_move,
@@ -1924,7 +2002,8 @@ static const struct wl_shell_surface_interface shell_surface_implementation = {
 	shell_surface_set_popup,
 	shell_surface_set_maximized,
 	shell_surface_set_title,
-	shell_surface_set_class
+	shell_surface_set_class,
+	shell_surface_probe_area
 };
 
 static void
-- 
1.8.0.2



More information about the wayland-devel mailing list