[weston,v1,11/17] add get_geometry & geometry request/event

Submitted by Marek Chalupa on Dec. 5, 2014, 1:36 p.m.

Details

Message ID 1417786610-2440-12-git-send-email-mchqwerty@gmail.com
State Changes Requested
Headers show

Not browsing as part of any series.

Commit Message

Marek Chalupa Dec. 5, 2014, 1:36 p.m.
---
 protocol/wayland-test.xml         | 11 +++++++++++
 tests/weston-test-client-helper.c | 18 ++++++++++++++++++
 tests/weston-test-client-helper.h |  6 ++++++
 tests/weston-test.c               | 23 +++++++++++++++++++++++
 4 files changed, 58 insertions(+)

Patch hide | download patch | download mbox

diff --git a/protocol/wayland-test.xml b/protocol/wayland-test.xml
index 18b6625..b4a6bc7 100644
--- a/protocol/wayland-test.xml
+++ b/protocol/wayland-test.xml
@@ -3,6 +3,7 @@ 
 
   <copyright>
     Copyright © 2012 Intel Corporation
+    Copyright © 2014 Red Hat, Inc.
 
     Permission to use, copy, modify, distribute, and sell this
     software and its documentation for any purpose is hereby granted
@@ -58,5 +59,15 @@ 
     <event name="n_egl_buffers">
       <arg name="n" type="uint"/>
     </event>
+    <request name="get_geometry">
+      <arg name="surface" type="object" interface="wl_surface"/>
+    </request>
+    <event name="geometry">
+      <arg name="surface" type="object" interface="wl_surface"/>
+      <arg name="width" type="uint"/>
+      <arg name="height" type="uint"/>
+      <arg name="x" type="int"/>
+      <arg name="y" type="int"/>
+    </event>
   </interface>
 </protocol>
diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index abc41e9..23b2048 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -428,9 +428,27 @@  test_handle_n_egl_buffers(void *data, struct wl_test *wl_test, uint32_t n)
 	test->n_egl_buffers = n;
 }
 
+static void
+test_handle_geometry(void *data, struct wl_test *wl_test,
+		     struct wl_surface *surface,
+		     uint32_t width, uint32_t height,
+		     int32_t x, int32_t y)
+{
+	struct test *test = data;
+
+	test->geometry.width = width;
+	test->geometry.height = height;
+	test->geometry.x = x;
+	test->geometry.y = y;
+
+	fprintf(stderr, "test-client: got geometry w: %u, h: %u, x: %d y: %d\n",
+		width, height, x, y);
+}
+
 static const struct wl_test_listener test_listener = {
 	test_handle_pointer_position,
 	test_handle_n_egl_buffers,
+	test_handle_geometry,
 };
 
 static void
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index dba47a0..3998c6d 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -64,6 +64,12 @@  struct test {
 	int pointer_x;
 	int pointer_y;
 	uint32_t n_egl_buffers;
+	struct {
+		uint32_t width;
+		uint32_t height;
+		int32_t x;
+		int32_t y;
+	} geometry;
 };
 
 struct input {
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 17c93f5..d1539e7 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -221,6 +221,28 @@  get_n_buffers(struct wl_client *client, struct wl_resource *resource)
 	wl_test_send_n_egl_buffers(resource, n_buffers);
 }
 
+static void
+get_geometry(struct wl_client *client, struct wl_resource *resource,
+	     struct wl_resource *surface_resource)
+{
+	struct weston_view *view;
+	struct weston_surface *surface =
+		wl_resource_get_user_data (surface_resource);
+
+	if (surface->configure)
+		view = wl_container_of(surface->views.next, view, surface_link);
+	else
+		view = surface->configure_private;
+
+	/* not created yet */
+	if (!view)
+		return;
+
+	wl_test_send_geometry(resource, surface_resource,
+			      surface->width, surface->height,
+			      view->geometry.x, view->geometry.y);
+}
+
 static const struct wl_test_interface test_implementation = {
 	move_surface,
 	move_pointer,
@@ -228,6 +250,7 @@  static const struct wl_test_interface test_implementation = {
 	activate_surface,
 	send_key,
 	get_n_buffers,
+	get_geometry
 };
 
 static void

Comments

On 05/12/14 07:36 AM, Marek Chalupa wrote:
> ---
>  protocol/wayland-test.xml         | 11 +++++++++++
>  tests/weston-test-client-helper.c | 18 ++++++++++++++++++
>  tests/weston-test-client-helper.h |  6 ++++++
>  tests/weston-test.c               | 23 +++++++++++++++++++++++
>  4 files changed, 58 insertions(+)
> 
> diff --git a/protocol/wayland-test.xml b/protocol/wayland-test.xml
> index 18b6625..b4a6bc7 100644
> --- a/protocol/wayland-test.xml
> +++ b/protocol/wayland-test.xml
> @@ -3,6 +3,7 @@

I think we need to bump the interface version number when adding new stuff?

> +static void
> +get_geometry(struct wl_client *client, struct wl_resource *resource,
> +	     struct wl_resource *surface_resource)
> +{
> +	struct weston_view *view;
> +	struct weston_surface *surface =
> +		wl_resource_get_user_data (surface_resource);

I don't think we put a space there...
On 9 December 2014 at 21:39, Derek Foreman <derekf@osg.samsung.com> wrote:

> On 05/12/14 07:36 AM, Marek Chalupa wrote:
> > ---
> >  protocol/wayland-test.xml         | 11 +++++++++++
> >  tests/weston-test-client-helper.c | 18 ++++++++++++++++++
> >  tests/weston-test-client-helper.h |  6 ++++++
> >  tests/weston-test.c               | 23 +++++++++++++++++++++++
> >  4 files changed, 58 insertions(+)
> >
> > diff --git a/protocol/wayland-test.xml b/protocol/wayland-test.xml
> > index 18b6625..b4a6bc7 100644
> > --- a/protocol/wayland-test.xml
> > +++ b/protocol/wayland-test.xml
> > @@ -3,6 +3,7 @@
>
> I think we need to bump the interface version number when adding new stuff?
>
>
In previous commits to this protocol this was not true (e. g.
40c0c3f91eeb747b86df) - probably because nobody cares about it since its
testing..
Anyway, strictly speaking, yes, we should.


> > +static void
> > +get_geometry(struct wl_client *client, struct wl_resource *resource,
> > +          struct wl_resource *surface_resource)
> > +{
> > +     struct weston_view *view;
> > +     struct weston_surface *surface =
> > +             wl_resource_get_user_data (surface_resource);
>
> I don't think we put a space there...
>

Ooops.


Thanks,
Marek
On Fri,  5 Dec 2014 14:36:44 +0100
Marek Chalupa <mchqwerty@gmail.com> wrote:

> ---
>  protocol/wayland-test.xml         | 11 +++++++++++
>  tests/weston-test-client-helper.c | 18 ++++++++++++++++++
>  tests/weston-test-client-helper.h |  6 ++++++
>  tests/weston-test.c               | 23 +++++++++++++++++++++++
>  4 files changed, 58 insertions(+)
> 

> diff --git a/tests/weston-test.c b/tests/weston-test.c
> index 17c93f5..d1539e7 100644
> --- a/tests/weston-test.c
> +++ b/tests/weston-test.c
> @@ -221,6 +221,28 @@ get_n_buffers(struct wl_client *client, struct wl_resource *resource)
>  	wl_test_send_n_egl_buffers(resource, n_buffers);
>  }
>  
> +static void
> +get_geometry(struct wl_client *client, struct wl_resource *resource,
> +	     struct wl_resource *surface_resource)
> +{
> +	struct weston_view *view;
> +	struct weston_surface *surface =
> +		wl_resource_get_user_data (surface_resource);
> +
> +	if (surface->configure)
> +		view = wl_container_of(surface->views.next, view, surface_link);

This is kind of hardcoding the assumption that there is a main view,
and it is the first in the list. But I suppose this is not a new
assumption, so nevermind.

> +	else
> +		view = surface->configure_private;
> +
> +	/* not created yet */
> +	if (!view)
> +		return;
> +
> +	wl_test_send_geometry(resource, surface_resource,
> +			      surface->width, surface->height,
> +			      view->geometry.x, view->geometry.y);

This doesn't work for surfaces who are positioned relative to another
surface. You need to use weston_view_to_global_{float,fixed}() to
transform 0,0.

That is, if the goal here is to know where the surface is in global
coordinates. Would be good to start adding some explanations in the
wl_test spec, too.

Another case where the whole protocol fails is wackily transformed
surfaces, but I think we don't want to support those. :-)
Still, would be nice to send e.g. a protocol error if the surface is
wackily transformed.


Thanks,
pq