pointer: add a frame event

Frame events group logically connected pointer events. It makes sense to make
the backend responsible for sending frame events, since once the events are
split (ie. once the frame events are stripped) it's not easy to figure out
which events belongs to which frame again.

This is also how Weston handles frame events.

Fixes https://github.com/swaywm/wlroots/issues/1468
This commit is contained in:
emersion 2019-01-26 11:04:05 +01:00
parent 209210d307
commit 5de26ad8ed
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
14 changed files with 96 additions and 21 deletions

View file

@ -31,6 +31,10 @@ static void default_pointer_axis(struct wlr_seat_pointer_grab *grab,
value_discrete, source);
}
static void default_pointer_frame(struct wlr_seat_pointer_grab *grab) {
wlr_seat_pointer_send_frame(grab->seat);
}
static void default_pointer_cancel(struct wlr_seat_pointer_grab *grab) {
// cannot be cancelled
}
@ -40,6 +44,7 @@ const struct wlr_pointer_grab_interface default_pointer_grab_impl = {
.motion = default_pointer_motion,
.button = default_pointer_button,
.axis = default_pointer_axis,
.frame = default_pointer_frame,
.cancel = default_pointer_cancel,
};
@ -212,7 +217,6 @@ void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time,
wl_pointer_send_motion(resource, time, wl_fixed_from_double(sx),
wl_fixed_from_double(sy));
pointer_send_frame(resource);
}
}
@ -231,7 +235,6 @@ uint32_t wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time,
}
wl_pointer_send_button(resource, serial, time, button, state);
pointer_send_frame(resource);
}
return serial;
}
@ -267,6 +270,21 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
} else if (version >= WL_POINTER_AXIS_STOP_SINCE_VERSION) {
wl_pointer_send_axis_stop(resource, time, orientation);
}
}
}
void wlr_seat_pointer_send_frame(struct wlr_seat *wlr_seat) {
struct wlr_seat_client *client = wlr_seat->pointer_state.focused_client;
if (client == NULL) {
return;
}
struct wl_resource *resource;
wl_resource_for_each(resource, &client->pointers) {
if (wlr_seat_client_from_pointer_resource(resource) == NULL) {
continue;
}
pointer_send_frame(resource);
}
}
@ -336,6 +354,14 @@ void wlr_seat_pointer_notify_axis(struct wlr_seat *wlr_seat, uint32_t time,
source);
}
void wlr_seat_pointer_notify_frame(struct wlr_seat *wlr_seat) {
clock_gettime(CLOCK_MONOTONIC, &wlr_seat->last_event);
struct wlr_seat_pointer_grab *grab = wlr_seat->pointer_state.grab;
if (grab->interface->frame) {
grab->interface->frame(grab);
}
}
bool wlr_seat_pointer_has_grab(struct wlr_seat *seat) {
return seat->pointer_state.grab->interface != &default_pointer_grab_impl;
}

View file

@ -21,6 +21,7 @@ struct wlr_cursor_device {
struct wl_listener motion_absolute;
struct wl_listener button;
struct wl_listener axis;
struct wl_listener frame;
struct wl_listener touch_down;
struct wl_listener touch_up;
@ -81,6 +82,7 @@ struct wlr_cursor *wlr_cursor_create(void) {
wl_signal_init(&cur->events.motion_absolute);
wl_signal_init(&cur->events.button);
wl_signal_init(&cur->events.axis);
wl_signal_init(&cur->events.frame);
// touch signals
wl_signal_init(&cur->events.touch_up);
@ -133,6 +135,7 @@ static void cursor_device_destroy(struct wlr_cursor_device *c_device) {
wl_list_remove(&c_device->motion_absolute.link);
wl_list_remove(&c_device->button.link);
wl_list_remove(&c_device->axis.link);
wl_list_remove(&c_device->frame.link);
} else if (dev->type == WLR_INPUT_DEVICE_TOUCH) {
wl_list_remove(&c_device->touch_down.link);
wl_list_remove(&c_device->touch_up.link);
@ -415,6 +418,11 @@ static void handle_pointer_axis(struct wl_listener *listener, void *data) {
wlr_signal_emit_safe(&device->cursor->events.axis, event);
}
static void handle_pointer_frame(struct wl_listener *listener, void *data) {
struct wlr_cursor_device *device = wl_container_of(listener, device, frame);
wlr_signal_emit_safe(&device->cursor->events.frame, device->cursor);
}
static void handle_touch_up(struct wl_listener *listener, void *data) {
struct wlr_event_touch_up *event = data;
struct wlr_cursor_device *device;
@ -538,6 +546,9 @@ static struct wlr_cursor_device *cursor_device_create(
wl_signal_add(&device->pointer->events.axis, &c_device->axis);
c_device->axis.notify = handle_pointer_axis;
wl_signal_add(&device->pointer->events.frame, &c_device->frame);
c_device->frame.notify = handle_pointer_frame;
} else if (device->type == WLR_INPUT_DEVICE_TOUCH) {
wl_signal_add(&device->touch->events.motion, &c_device->touch_motion);
c_device->touch_motion.notify = handle_touch_motion;

View file

@ -11,6 +11,7 @@ void wlr_pointer_init(struct wlr_pointer *pointer,
wl_signal_init(&pointer->events.motion_absolute);
wl_signal_init(&pointer->events.button);
wl_signal_init(&pointer->events.axis);
wl_signal_init(&pointer->events.frame);
}
void wlr_pointer_destroy(struct wlr_pointer *pointer) {
@ -20,10 +21,6 @@ void wlr_pointer_destroy(struct wlr_pointer *pointer) {
if (pointer->impl && pointer->impl->destroy) {
pointer->impl->destroy(pointer);
} else {
wl_list_remove(&pointer->events.motion.listener_list);
wl_list_remove(&pointer->events.motion_absolute.listener_list);
wl_list_remove(&pointer->events.button.listener_list);
wl_list_remove(&pointer->events.axis.listener_list);
free(pointer);
}
}

View file

@ -271,9 +271,5 @@ void wlr_relative_pointer_manager_v1_send_relative_motion(
(uint32_t)(time_msec >> 32), (uint32_t)time_msec,
wl_fixed_from_double(dx), wl_fixed_from_double(dy),
wl_fixed_from_double(dx_unaccel), wl_fixed_from_double(dy_unaccel));
uint32_t version = wl_resource_get_version(pointer->resource);
if (version >= WL_POINTER_FRAME_SINCE_VERSION) {
wl_pointer_send_frame(pointer->pointer_resource);
}
}
}