summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2012-03-14 11:28:19 +0000
committerWill Thompson <will.thompson@collabora.co.uk>2012-03-14 12:47:31 +0000
commit96d0ddedb79e2fb44cb207a294b096e5ed557399 (patch)
tree886e7062542e228cd0f7dee5ab0d51b92057e748
parentb99606420c8d39bd6c0388ee112b76f7503d2289 (diff)
Push absolute cursor position out to a single listener
Absolute cursor position is useless given that clients don't know where their surfaces are, so the next step will be to provide more useful information.
-rw-r--r--clients/Makefile.am2
-rw-r--r--clients/eyes.c36
-rw-r--r--src/compositor.c2
-rw-r--r--src/compositor.h3
-rw-r--r--src/pointer-tracking.c16
5 files changed, 58 insertions, 1 deletions
diff --git a/clients/Makefile.am b/clients/Makefile.am
index e80a299..f94d3fc 100644
--- a/clients/Makefile.am
+++ b/clients/Makefile.am
@@ -63,7 +63,7 @@ toolkit_libs = \
../shared/libconfig-parser.la \
$(CLIENT_LIBS) $(CAIRO_EGL_LIBS) -lrt -lm
-eyes_SOURCES = eyes.c
+eyes_SOURCES = eyes.c pointer-tracking-protocol.c
eyes_LDADD = $(toolkit_libs)
flower_SOURCES = flower.c
diff --git a/clients/eyes.c b/clients/eyes.c
index f91f2ad..6fdc138 100644
--- a/clients/eyes.c
+++ b/clients/eyes.c
@@ -31,6 +31,7 @@
#include <linux/input.h>
#include <wayland-client.h>
#include "window.h"
+#include "pointer-tracking-client-protocol.h"
struct eyes {
struct display *display;
@@ -38,6 +39,7 @@ struct eyes {
struct widget *widget;
int width, height;
int32_t pointer_x, pointer_y;
+ struct pointer_tracking *pointer_tracking;
};
static void
@@ -162,6 +164,36 @@ button_handler(struct widget *widget,
}
}
+static void
+eyes_pointer_moved(void *data, struct pointer_tracking *pointer_tracking,
+ int32_t x, int32_t y)
+{
+ struct eyes *eyes = data;
+
+ motion_handler(eyes->widget, NULL, 0, x, y, eyes);
+}
+
+static struct pointer_tracking_listener eyes_pointer_tracking_listener = {
+ eyes_pointer_moved
+};
+
+static void
+eyes_display_handle_global(struct wl_display *display, uint32_t id,
+ const char *interface, uint32_t version, void *data)
+{
+ struct eyes *eyes = data;
+
+ if (strcmp(interface, "pointer_tracking") == 0) {
+ eyes->pointer_tracking =
+ wl_display_bind(display, id,
+ &pointer_tracking_interface);
+ pointer_tracking_add_listener(eyes->pointer_tracking,
+ &eyes_pointer_tracking_listener,
+ eyes);
+ widget_set_motion_handler(eyes->widget, NULL);
+ }
+}
+
int main(int argc, char *argv[])
{
struct eyes eyes;
@@ -181,9 +213,13 @@ int main(int argc, char *argv[])
widget_set_resize_handler(eyes.widget, resize_handler);
widget_set_redraw_handler(eyes.widget, redraw_handler);
+ /* Just in case the server doesn't have the pointer-tracking extension. */
widget_set_motion_handler(eyes.widget, motion_handler);
widget_set_button_handler(eyes.widget, button_handler);
+ wl_display_add_global_listener(display_get_display(d),
+ eyes_display_handle_global, &eyes);
+
window_schedule_resize(eyes.window, eyes.width, eyes.height);
display_run(d);
diff --git a/src/compositor.c b/src/compositor.c
index e3f3f05..72a1424 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1497,6 +1497,8 @@ notify_motion(struct wl_input_device *device, uint32_t time, int x, int y)
weston_device_repick(device, time);
interface = device->pointer_grab->interface;
+
+ pointer_tracking_push(ec->pointer_tracking, x, y);
interface->motion(device->pointer_grab, time,
device->pointer_grab->x, device->pointer_grab->y);
diff --git a/src/compositor.h b/src/compositor.h
index 772971c..5ad5439 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -512,6 +512,9 @@ struct pointer_tracking *
pointer_tracking_create(struct weston_compositor *ec);
void
+pointer_tracking_push(struct pointer_tracking *pt, int32_t x, int32_t y);
+
+void
pointer_tracking_destroy(struct pointer_tracking *s);
uint32_t *
diff --git a/src/pointer-tracking.c b/src/pointer-tracking.c
index 72c4209..2c06830 100644
--- a/src/pointer-tracking.c
+++ b/src/pointer-tracking.c
@@ -29,11 +29,17 @@ struct pointer_tracking {
struct wl_object base;
struct weston_compositor *ec;
struct wl_global *global;
+
+ /* FIXME: this should not be singular */
+ struct wl_resource *resource;
};
static void
unbind_pointer_tracking(struct wl_resource *resource)
{
+ struct pointer_tracking *pt = resource->data;
+
+ pt->resource = NULL;
free(resource);
}
@@ -48,6 +54,7 @@ bind_pointer_tracking(struct wl_client *client,
NULL, id, data);
resource->destroy = unbind_pointer_tracking;
+ pt->resource = resource;
}
struct pointer_tracking *
@@ -72,6 +79,15 @@ 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)
+ return;
+
+ pointer_tracking_send_pointer_moved(pt->resource, x, y);
+}
+
+void
pointer_tracking_destroy(struct pointer_tracking *pt)
{
wl_display_remove_global(pt->ec->wl_display, pt->global);