[PATCH weston] compositor: add a mouse motion binding type
Giulio Camuffo
giuliocamuffo at gmail.com
Thu Apr 4 05:07:20 PDT 2013
when a mouse is moved the binding handler is called, passing it the
mouse position and the timestamp. a shell plugin can use this to
activate an effect when the mouse hits an output corner.
---
src/bindings.c | 36 ++++++++++++++++++++++++++++++++++++
src/compositor.c | 8 ++++++++
src/compositor.h | 16 ++++++++++++++++
3 files changed, 60 insertions(+)
diff --git a/src/bindings.c b/src/bindings.c
index 322736d..64f39e9 100644
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -110,6 +110,24 @@ weston_compositor_add_axis_binding(struct weston_compositor *compositor,
}
WL_EXPORT struct weston_binding *
+weston_compositor_add_motion_binding(struct weston_compositor *compositor,
+ enum weston_keyboard_modifier modifier,
+ weston_motion_binding_handler_t handler,
+ void *data)
+{
+ struct weston_binding *binding;
+
+ binding = weston_compositor_add_binding(compositor, 0, 0, 0,
+ modifier, handler, data);
+ if (binding == NULL)
+ return NULL;
+
+ wl_list_insert(compositor->motion_binding_list.prev, &binding->link);
+
+ return binding;
+}
+
+WL_EXPORT struct weston_binding *
weston_compositor_add_debug_binding(struct weston_compositor *compositor,
uint32_t key,
weston_key_binding_handler_t handler,
@@ -270,6 +288,24 @@ weston_compositor_run_axis_binding(struct weston_compositor *compositor,
}
WL_EXPORT int
+weston_compositor_run_motion_binding(struct weston_compositor *compositor,
+ struct weston_seat *seat,
+ uint32_t time,
+ wl_fixed_t x, wl_fixed_t y)
+{
+ struct weston_binding *b;
+
+ wl_list_for_each(b, &compositor->motion_binding_list, link) {
+ if (b->modifier == seat->modifier_state) {
+ weston_motion_binding_handler_t handler = b->handler;
+ handler(&seat->seat, time, x, y, b->data);
+ }
+ }
+
+ return 0;
+}
+
+WL_EXPORT int
weston_compositor_run_debug_binding(struct weston_compositor *compositor,
struct weston_seat *seat,
uint32_t time, uint32_t key,
diff --git a/src/compositor.c b/src/compositor.c
index e7c22db..e43fba4 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1845,6 +1845,9 @@ notify_motion(struct weston_seat *seat,
weston_compositor_wake(ec);
+ weston_compositor_run_motion_binding(ec, seat,
+ time, pointer->x + dx, pointer->y + dy);
+
move_pointer(seat, pointer->x + dx, pointer->y + dy);
interface = pointer->grab->interface;
@@ -1862,6 +1865,9 @@ notify_motion_absolute(struct weston_seat *seat,
weston_compositor_wake(ec);
+ weston_compositor_run_motion_binding(ec, seat,
+ time, x, y);
+
move_pointer(seat, x, y);
interface = pointer->grab->interface;
@@ -3167,6 +3173,7 @@ weston_compositor_init(struct weston_compositor *ec,
wl_list_init(&ec->key_binding_list);
wl_list_init(&ec->button_binding_list);
wl_list_init(&ec->axis_binding_list);
+ wl_list_init(&ec->motion_binding_list);
wl_list_init(&ec->debug_binding_list);
weston_plane_init(&ec->primary_plane, 0, 0);
@@ -3215,6 +3222,7 @@ weston_compositor_shutdown(struct weston_compositor *ec)
weston_binding_list_destroy_all(&ec->key_binding_list);
weston_binding_list_destroy_all(&ec->button_binding_list);
weston_binding_list_destroy_all(&ec->axis_binding_list);
+ weston_binding_list_destroy_all(&ec->motion_binding_list);
weston_binding_list_destroy_all(&ec->debug_binding_list);
weston_plane_release(&ec->primary_plane);
diff --git a/src/compositor.h b/src/compositor.h
index 7d1d68e..18dcd7a 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -326,6 +326,7 @@ struct weston_compositor {
struct wl_list key_binding_list;
struct wl_list button_binding_list;
struct wl_list axis_binding_list;
+ struct wl_list motion_binding_list;
struct wl_list debug_binding_list;
uint32_t state;
@@ -660,6 +661,17 @@ weston_compositor_add_axis_binding(struct weston_compositor *compositor,
enum weston_keyboard_modifier modifier,
weston_axis_binding_handler_t binding,
void *data);
+
+typedef void (*weston_motion_binding_handler_t)(struct wl_seat *seat,
+ uint32_t time,
+ wl_fixed_t x, wl_fixed_t y,
+ void *data);
+struct weston_binding *
+weston_compositor_add_motion_binding(struct weston_compositor *compositor,
+ enum weston_keyboard_modifier modifier,
+ weston_motion_binding_handler_t binding,
+ void *data);
+
struct weston_binding *
weston_compositor_add_debug_binding(struct weston_compositor *compositor,
uint32_t key,
@@ -686,6 +698,10 @@ weston_compositor_run_axis_binding(struct weston_compositor *compositor,
struct weston_seat *seat, uint32_t time,
uint32_t axis, int32_t value);
int
+weston_compositor_run_motion_binding(struct weston_compositor *compositor,
+ struct weston_seat *seat, uint32_t time,
+ wl_fixed_t x, wl_fixed_t y);
+int
weston_compositor_run_debug_binding(struct weston_compositor *compositor,
struct weston_seat *seat, uint32_t time,
uint32_t key,
--
1.8.2
More information about the wayland-devel
mailing list