[PATCH weston 03/17] input: Make pointer grab motion callbacks take an event struct
Jonas Ådahl
jadahl at gmail.com
Tue Dec 2 05:49:11 PST 2014
Instead of only passing absolute pointer coordinates, effectively
loosing motion event data, pass a struct that can potentially contain
different types of motion events, currently being absolute and relative.
A helper function to get resulting absolute coordinates was added for
when previous callbacks simply used the (x, y) coordinates.
Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---
desktop-shell/exposay.c | 4 ++--
desktop-shell/shell.c | 22 ++++++++++--------
src/compositor-x11.c | 13 ++++++++---
src/compositor.h | 24 ++++++++++++++++---
src/data-device.c | 4 ++--
src/input.c | 61 ++++++++++++++++++++++++++++++++++++++++---------
src/libinput-device.c | 15 ++++++++----
tests/weston-test.c | 11 ++++++---
8 files changed, 115 insertions(+), 39 deletions(-)
diff --git a/desktop-shell/exposay.c b/desktop-shell/exposay.c
index dc3fee0..a44c1f7 100644
--- a/desktop-shell/exposay.c
+++ b/desktop-shell/exposay.c
@@ -340,12 +340,12 @@ exposay_focus(struct weston_pointer_grab *grab)
static void
exposay_motion(struct weston_pointer_grab *grab, uint32_t time,
- wl_fixed_t x, wl_fixed_t y)
+ struct weston_pointer_motion_event *event)
{
struct desktop_shell *shell =
container_of(grab, struct desktop_shell, exposay.grab_ptr);
- weston_pointer_move(grab->pointer, x, y);
+ weston_pointer_move(grab->pointer, event);
exposay_pick(shell,
wl_fixed_to_int(grab->pointer->x),
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 8fc6a48..b03dbaf 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -1657,14 +1657,14 @@ constrain_position(struct weston_move_grab *move, int *cx, int *cy)
static void
move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
- wl_fixed_t x, wl_fixed_t y)
+ struct weston_pointer_motion_event *event)
{
struct weston_move_grab *move = (struct weston_move_grab *) grab;
struct weston_pointer *pointer = grab->pointer;
struct shell_surface *shsurf = move->base.shsurf;
int cx, cy;
- weston_pointer_move(pointer, x, y);
+ weston_pointer_move(pointer, event);
if (!shsurf)
return;
@@ -1779,7 +1779,7 @@ struct weston_resize_grab {
static void
resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
- wl_fixed_t x, wl_fixed_t y)
+ struct weston_pointer_motion_event *event)
{
struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
struct weston_pointer *pointer = grab->pointer;
@@ -1788,7 +1788,7 @@ resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
wl_fixed_t from_x, from_y;
wl_fixed_t to_x, to_y;
- weston_pointer_move(pointer, x, y);
+ weston_pointer_move(pointer, event);
if (!shsurf)
return;
@@ -1989,9 +1989,9 @@ busy_cursor_grab_focus(struct weston_pointer_grab *base)
static void
busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
- wl_fixed_t x, wl_fixed_t y)
+ struct weston_pointer_motion_event *event)
{
- weston_pointer_move(grab->pointer, x, y);
+ weston_pointer_move(grab->pointer, event);
}
static void
@@ -3068,18 +3068,20 @@ popup_grab_focus(struct weston_pointer_grab *grab)
static void
popup_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
- wl_fixed_t x, wl_fixed_t y)
+ struct weston_pointer_motion_event *event)
{
struct weston_pointer *pointer = grab->pointer;
struct wl_resource *resource;
+ wl_fixed_t x, y;
wl_fixed_t sx, sy;
if (pointer->focus) {
+ weston_pointer_motion_to_abs(pointer, event, &x, &y);
weston_view_from_global_fixed(pointer->focus, x, y,
&pointer->sx, &pointer->sy);
}
- weston_pointer_move(pointer, x, y);
+ weston_pointer_move(pointer, event);
wl_resource_for_each(resource, &pointer->focus_resource_list) {
weston_view_from_global_fixed(pointer->focus,
@@ -4656,7 +4658,7 @@ terminate_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
static void
rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
- wl_fixed_t x, wl_fixed_t y)
+ struct weston_pointer_motion_event *event)
{
struct rotate_grab *rotate =
container_of(grab, struct rotate_grab, base.grab);
@@ -4664,7 +4666,7 @@ rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
struct shell_surface *shsurf = rotate->base.shsurf;
float cx, cy, dx, dy, cposx, cposy, dposx, dposy, r;
- weston_pointer_move(pointer, x, y);
+ weston_pointer_move(pointer, event);
if (!shsurf)
return;
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index a760f33..2454eab 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -1060,12 +1060,13 @@ x11_compositor_deliver_button_event(struct x11_compositor *c,
static void
x11_compositor_deliver_motion_event(struct x11_compositor *c,
- xcb_generic_event_t *event)
+ xcb_generic_event_t *xcb_event)
{
struct x11_output *output;
wl_fixed_t x, y;
+ struct weston_pointer_motion_event event = { 0 };
xcb_motion_notify_event_t *motion_notify =
- (xcb_motion_notify_event_t *) event;
+ (xcb_motion_notify_event_t *) xcb_event;
if (!c->has_xkb)
update_xkb_state_from_core(c, motion_notify->state);
@@ -1075,8 +1076,14 @@ x11_compositor_deliver_motion_event(struct x11_compositor *c,
wl_fixed_from_int(motion_notify->event_y),
&x, &y);
+ event = (struct weston_pointer_motion_event) {
+ .mask = WESTON_POINTER_MOTION_REL,
+ .dx = x - c->prev_x,
+ .dy = y - c->prev_y,
+ };
+
notify_motion(&c->core_seat, weston_compositor_get_time(),
- x - c->prev_x, y - c->prev_y);
+ &event);
c->prev_x = x;
c->prev_y = y;
diff --git a/src/compositor.h b/src/compositor.h
index ef1bc0f..e8fc8a7 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -236,11 +236,24 @@ struct weston_output {
uint16_t *b);
};
+enum weston_pointer_motion_mask {
+ WESTON_POINTER_MOTION_ABS = 1 << 0,
+ WESTON_POINTER_MOTION_REL = 1 << 1,
+};
+
+struct weston_pointer_motion_event {
+ uint32_t mask;
+ wl_fixed_t x;
+ wl_fixed_t y;
+ wl_fixed_t dx;
+ wl_fixed_t dy;
+};
+
struct weston_pointer_grab;
struct weston_pointer_grab_interface {
void (*focus)(struct weston_pointer_grab *grab);
void (*motion)(struct weston_pointer_grab *grab, uint32_t time,
- wl_fixed_t x, wl_fixed_t y);
+ struct weston_pointer_motion_event *event);
void (*button)(struct weston_pointer_grab *grab,
uint32_t time, uint32_t button, uint32_t state);
void (*axis)(struct weston_pointer_grab *grab,
@@ -362,6 +375,11 @@ struct weston_touch {
uint32_t grab_time;
};
+void
+weston_pointer_motion_to_abs(struct weston_pointer *pointer,
+ struct weston_pointer_motion_event *event,
+ wl_fixed_t *x, wl_fixed_t *y);
+
struct weston_pointer *
weston_pointer_create(struct weston_seat *seat);
void
@@ -380,7 +398,7 @@ weston_pointer_clamp(struct weston_pointer *pointer,
wl_fixed_t *fx, wl_fixed_t *fy);
void
weston_pointer_move(struct weston_pointer *pointer,
- wl_fixed_t x, wl_fixed_t y);
+ struct weston_pointer_motion_event *event);
void
weston_pointer_set_default_grab(struct weston_pointer *pointer,
const struct weston_pointer_grab_interface *interface);
@@ -1003,7 +1021,7 @@ weston_surface_activate(struct weston_surface *surface,
struct weston_seat *seat);
void
notify_motion(struct weston_seat *seat, uint32_t time,
- wl_fixed_t dx, wl_fixed_t dy);
+ struct weston_pointer_motion_event *event);
void
notify_motion_absolute(struct weston_seat *seat, uint32_t time,
wl_fixed_t x, wl_fixed_t y);
diff --git a/src/data-device.c b/src/data-device.c
index b26ad3e..af1c1ec 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -316,7 +316,7 @@ drag_grab_focus(struct weston_pointer_grab *grab)
static void
drag_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
- wl_fixed_t x, wl_fixed_t y)
+ struct weston_pointer_motion_event *event)
{
struct weston_pointer_drag *drag =
container_of(grab, struct weston_pointer_drag, grab);
@@ -324,7 +324,7 @@ drag_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
float fx, fy;
wl_fixed_t sx, sy;
- weston_pointer_move(pointer, x, y);
+ weston_pointer_move(pointer, event);
if (drag->base.icon) {
fx = wl_fixed_to_double(pointer->x) + drag->base.dx;
diff --git a/src/input.c b/src/input.c
index f40d44a..67f5cf4 100644
--- a/src/input.c
+++ b/src/input.c
@@ -163,17 +163,20 @@ default_grab_pointer_focus(struct weston_pointer_grab *grab)
static void
default_grab_pointer_motion(struct weston_pointer_grab *grab, uint32_t time,
- wl_fixed_t x, wl_fixed_t y)
+ struct weston_pointer_motion_event *event)
{
struct weston_pointer *pointer = grab->pointer;
struct wl_list *resource_list;
struct wl_resource *resource;
+ wl_fixed_t x, y;
- if (pointer->focus)
+ if (pointer->focus) {
+ weston_pointer_motion_to_abs(pointer, event, &x, &y);
weston_view_from_global_fixed(pointer->focus, x, y,
&pointer->sx, &pointer->sy);
+ }
- weston_pointer_move(pointer, x, y);
+ weston_pointer_move(pointer, event);
resource_list = &pointer->focus_resource_list;
wl_resource_for_each(resource, resource_list) {
@@ -882,9 +885,9 @@ weston_pointer_clamp(struct weston_pointer *pointer, wl_fixed_t *fx, wl_fixed_t
weston_pointer_clamp_for_output(pointer, prev, fx, fy);
}
-/* Takes absolute values */
-WL_EXPORT void
-weston_pointer_move(struct weston_pointer *pointer, wl_fixed_t x, wl_fixed_t y)
+static void
+weston_pointer_move_to(struct weston_pointer *pointer,
+ wl_fixed_t x, wl_fixed_t y)
{
int32_t ix, iy;
@@ -907,6 +910,33 @@ weston_pointer_move(struct weston_pointer *pointer, wl_fixed_t x, wl_fixed_t y)
wl_signal_emit(&pointer->motion_signal, pointer);
}
+WL_EXPORT void
+weston_pointer_motion_to_abs(struct weston_pointer *pointer,
+ struct weston_pointer_motion_event *event,
+ wl_fixed_t *x, wl_fixed_t *y)
+{
+ if (event->mask & WESTON_POINTER_MOTION_ABS) {
+ *x = event->x;
+ *y = event->y;
+ } else if (event->mask & WESTON_POINTER_MOTION_REL) {
+ *x = pointer->x + event->dx;
+ *y = pointer->y + event->dy;
+ } else {
+ assert(!"invalid motion event");
+ *x = *y = 0;
+ }
+}
+
+WL_EXPORT void
+weston_pointer_move(struct weston_pointer *pointer,
+ struct weston_pointer_motion_event *event)
+{
+ wl_fixed_t x, y;
+
+ weston_pointer_motion_to_abs(pointer, event, &x, &y);
+ weston_pointer_move_to(pointer, x, y);
+}
+
/** Verify if the pointer is in a valid position and move it if it isn't.
*/
static void
@@ -948,18 +978,19 @@ weston_pointer_handle_output_destroy(struct wl_listener *listener, void *data)
fy = pointer->y;
weston_pointer_clamp_for_output(pointer, closest, &fx, &fy);
- weston_pointer_move(pointer, fx, fy);
+ weston_pointer_move_to(pointer, fx, fy);
}
WL_EXPORT void
notify_motion(struct weston_seat *seat,
- uint32_t time, wl_fixed_t dx, wl_fixed_t dy)
+ uint32_t time,
+ struct weston_pointer_motion_event *event)
{
struct weston_compositor *ec = seat->compositor;
struct weston_pointer *pointer = seat->pointer;
weston_compositor_wake(ec);
- pointer->grab->interface->motion(pointer->grab, time, pointer->x + dx, pointer->y + dy);
+ pointer->grab->interface->motion(pointer->grab, time, event);
}
static void
@@ -1004,9 +1035,17 @@ notify_motion_absolute(struct weston_seat *seat,
{
struct weston_compositor *ec = seat->compositor;
struct weston_pointer *pointer = seat->pointer;
+ struct weston_pointer_motion_event event = { 0 };
weston_compositor_wake(ec);
- pointer->grab->interface->motion(pointer->grab, time, x, y);
+
+ event = (struct weston_pointer_motion_event) {
+ .mask = WESTON_POINTER_MOTION_ABS,
+ .x = x,
+ .y = y,
+ };
+
+ pointer->grab->interface->motion(pointer->grab, time, &event);
}
WL_EXPORT void
@@ -1377,7 +1416,7 @@ notify_pointer_focus(struct weston_seat *seat, struct weston_output *output,
wl_fixed_t x, wl_fixed_t y)
{
if (output) {
- weston_pointer_move(seat->pointer, x, y);
+ weston_pointer_move_to(seat->pointer, x, y);
} else {
/* FIXME: We should call weston_pointer_set_focus(seat,
* NULL) here, but somehow that breaks re-entry... */
diff --git a/src/libinput-device.c b/src/libinput-device.c
index 0e3f46d..b815b43 100644
--- a/src/libinput-device.c
+++ b/src/libinput-device.c
@@ -73,14 +73,19 @@ handle_pointer_motion(struct libinput_device *libinput_device,
{
struct evdev_device *device =
libinput_device_get_user_data(libinput_device);
- wl_fixed_t dx, dy;
+ struct weston_pointer_motion_event event = { 0 };
+
+ event = (struct weston_pointer_motion_event) {
+ .mask = WESTON_POINTER_MOTION_REL,
+ .dx = wl_fixed_from_double(
+ libinput_event_pointer_get_dx(pointer_event)),
+ .dy = wl_fixed_from_double(
+ libinput_event_pointer_get_dy(pointer_event)),
+ };
- dx = wl_fixed_from_double(libinput_event_pointer_get_dx(pointer_event));
- dy = wl_fixed_from_double(libinput_event_pointer_get_dy(pointer_event));
notify_motion(device->seat,
libinput_event_pointer_get_time(pointer_event),
- dx,
- dy);
+ &event);
}
static void
diff --git a/tests/weston-test.c b/tests/weston-test.c
index f1e45c1..acfc042 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -144,10 +144,15 @@ move_pointer(struct wl_client *client, struct wl_resource *resource,
struct weston_test *test = wl_resource_get_user_data(resource);
struct weston_seat *seat = get_seat(test);
struct weston_pointer *pointer = seat->pointer;
+ struct weston_pointer_motion_event event = { 0 };
- notify_motion(seat, 100,
- wl_fixed_from_int(x) - pointer->x,
- wl_fixed_from_int(y) - pointer->y);
+ event = (struct weston_pointer_motion_event) {
+ .mask = WESTON_POINTER_MOTION_REL,
+ .dx = wl_fixed_from_int(x) - pointer->x,
+ .dy = wl_fixed_from_int(y) - pointer->y,
+ };
+
+ notify_motion(seat, 100, &event);
notify_pointer_position(test, resource);
}
--
1.8.5.1
More information about the wayland-devel
mailing list