summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2012-03-14 11:28:20 +0000
committerWill Thompson <will.thompson@collabora.co.uk>2012-03-14 12:48:08 +0000
commitbb53531766cb9e213d381c4ae5f03a8111ab178d (patch)
tree7be8a7629441e0f70703736371634d46ac2baf47
parent96d0ddedb79e2fb44cb207a294b096e5ed557399 (diff)
Send pointer position relative to a surface
With this, clients have to specify a surface before they start receiving pointer position events. The coordinates are relative to that surface.
-rw-r--r--clients/eyes.c5
-rw-r--r--protocol/pointer-tracking.xml3
-rw-r--r--src/pointer-tracking.c36
3 files changed, 36 insertions, 8 deletions
diff --git a/clients/eyes.c b/clients/eyes.c
index 6fdc138..69b2fe8 100644
--- a/clients/eyes.c
+++ b/clients/eyes.c
@@ -165,7 +165,8 @@ button_handler(struct widget *widget,
}
static void
-eyes_pointer_moved(void *data, struct pointer_tracking *pointer_tracking,
+eyes_pointer_moved(void *data,
+ struct pointer_tracking *pointer_tracking,
int32_t x, int32_t y)
{
struct eyes *eyes = data;
@@ -187,6 +188,8 @@ eyes_display_handle_global(struct wl_display *display, uint32_t id,
eyes->pointer_tracking =
wl_display_bind(display, id,
&pointer_tracking_interface);
+ pointer_tracking_track_relative_to(eyes->pointer_tracking,
+ window_get_wl_surface(eyes->window));
pointer_tracking_add_listener(eyes->pointer_tracking,
&eyes_pointer_tracking_listener,
eyes);
diff --git a/protocol/pointer-tracking.xml b/protocol/pointer-tracking.xml
index 5cefd39..3c5fafe 100644
--- a/protocol/pointer-tracking.xml
+++ b/protocol/pointer-tracking.xml
@@ -1,5 +1,8 @@
<protocol name="pointer_tracking">
<interface name="pointer_tracking" version="1">
+ <request name="track_relative_to">
+ <arg name="surface" type="object" interface="wl_surface"/>
+ </request>
<event name="pointer_moved">
<arg name="x" type="int"/>
<arg name="y" type="int"/>
diff --git a/src/pointer-tracking.c b/src/pointer-tracking.c
index 2c06830..c742a94 100644
--- a/src/pointer-tracking.c
+++ b/src/pointer-tracking.c
@@ -32,6 +32,23 @@ struct pointer_tracking {
/* FIXME: this should not be singular */
struct wl_resource *resource;
+ struct weston_surface *surface;
+};
+
+static void
+pointer_track_relative_to(struct wl_client *client,
+ struct wl_resource *resource,
+ struct wl_resource *surface_resource)
+{
+ struct pointer_tracking *pt = resource->data;
+ struct weston_surface *surface = surface_resource->data;
+
+ pt->resource = resource;
+ pt->surface = surface;
+}
+
+static struct pointer_tracking_interface pointer_tracking_implementation = {
+ pointer_track_relative_to
};
static void
@@ -39,7 +56,11 @@ unbind_pointer_tracking(struct wl_resource *resource)
{
struct pointer_tracking *pt = resource->data;
- pt->resource = NULL;
+ if (pt->resource == resource) {
+ pt->resource = NULL;
+ pt->surface = NULL;
+ }
+
free(resource);
}
@@ -47,14 +68,12 @@ static void
bind_pointer_tracking(struct wl_client *client,
void *data, uint32_t version, uint32_t id)
{
- struct pointer_tracking *pt = data;
struct wl_resource *resource;
resource = wl_client_add_object(client, &pointer_tracking_interface,
- NULL, id, data);
+ &pointer_tracking_implementation,
+ id, data);
resource->destroy = unbind_pointer_tracking;
-
- pt->resource = resource;
}
struct pointer_tracking *
@@ -81,10 +100,13 @@ pointer_tracking_create(struct weston_compositor *ec)
void
pointer_tracking_push(struct pointer_tracking *pt, int32_t x, int32_t y)
{
- if (pt->resource == NULL)
+ int32_t sx, sy;
+
+ if (pt->resource == NULL || pt->surface == NULL)
return;
- pointer_tracking_send_pointer_moved(pt->resource, x, y);
+ weston_surface_from_global(pt->surface, x, y, &sx, &sy);
+ pointer_tracking_send_pointer_moved(pt->resource, sx, sy);
}
void