relative-pointer-v1: move pointer iteration in wlroots

This makes sure we always send events to the right client.
This commit is contained in:
emersion 2019-01-04 16:14:06 +01:00
parent aebd74243f
commit f71cf15aad
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
3 changed files with 40 additions and 53 deletions

View File

@ -11,19 +11,16 @@
#include <wayland-server.h>
/**
* This protocol specifies a set of interfaces used for making clients able to
* receive relative pointer events not obstructed by barriers (such as the
* monitor edge or pointer constraints).
*/
/**
* A global interface used for getting the relative pointer object for a given
* pointer.
*/
struct wlr_relative_pointer_manager_v1 {
struct wl_global *global;
struct wl_list resources; // wl_resource_get_link()
@ -31,7 +28,7 @@ struct wlr_relative_pointer_manager_v1 {
struct {
struct wl_signal destroy;
struct wl_signal new_relative_pointer; //wlr_relative_pointer_v1
struct wl_signal new_relative_pointer; // wlr_relative_pointer_v1
} events;
struct wl_listener display_destroy_listener;
@ -39,17 +36,15 @@ struct wlr_relative_pointer_manager_v1 {
void *data;
};
/**
* A wp_relative_pointer object is an extension to the wl_pointer interface
* used for emitting relative pointer events. It shares the same focus as
* wl_pointer objects of the same seat and will only emit events when it has
* focus.
*/
struct wlr_relative_pointer_v1 {
struct wl_resource *resource;
struct wl_resource *pointer;
struct wl_resource *pointer_resource;
struct wlr_seat *seat;
struct wl_list link; // wlr_relative_pointer_manager_v1::relative_pointers
@ -66,14 +61,15 @@ struct wlr_relative_pointer_v1 {
struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_manager_v1_create(
struct wl_display *display);
void wlr_relative_pointer_manager_v1_destroy(
struct wlr_relative_pointer_manager_v1 *relative_pointer_manager);
struct wlr_relative_pointer_manager_v1 *manager);
/**
* Send a relative motion event to the seat with the same wl_pointer as relative_pointer
*/
void wlr_relative_pointer_v1_send_relative_motion(
struct wlr_relative_pointer_v1 *relative_pointer, uint64_t time_msec,
double dx, double dy, double dx_unaccel, double dy_unaccel);
void wlr_relative_pointer_manager_v1_send_relative_motion(
struct wlr_relative_pointer_manager_v1 *manager, struct wlr_seat *seat,
uint64_t time_msec, double dx, double dy,
double dx_unaccel, double dy_unaccel);
struct wlr_relative_pointer_v1 *wlr_relative_pointer_v1_from_resource(
struct wl_resource *resource);

View File

@ -35,7 +35,8 @@ void roots_cursor_destroy(struct roots_cursor *cursor) {
// TODO
}
static void seat_view_deco_motion(struct roots_seat_view *view, double deco_sx, double deco_sy) {
static void seat_view_deco_motion(struct roots_seat_view *view,
double deco_sx, double deco_sy) {
struct roots_cursor *cursor = view->seat->cursor;
double sx = deco_sx;
@ -305,40 +306,18 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
}
}
static void notify_relative_motion(struct roots_seat *seat, uint64_t time_msec,
double dx, double dy, double dx_unaccel, double dy_unaccel) {
struct wlr_relative_pointer_manager_v1 *relative_pointer_manager =
seat->input->server->desktop->relative_pointer_manager;
struct wlr_seat_client *client = seat->seat->pointer_state.focused_client;
if (client == NULL) {
return;
}
struct wlr_relative_pointer_v1 *pointer;
wl_list_for_each(pointer, &relative_pointer_manager->relative_pointers, link) {
struct wlr_seat_client *relative_pointer_client =
wlr_seat_client_from_pointer_resource(pointer->pointer);
if (seat->seat == pointer->seat &&
client == relative_pointer_client) {
wlr_relative_pointer_v1_send_relative_motion(pointer,
time_msec, dx, dy, dx_unaccel, dy_unaccel);
}
}
}
void roots_cursor_handle_motion(struct roots_cursor *cursor,
struct wlr_event_pointer_motion *event) {
double dx = event->delta_x;
double dy = event->delta_y;
double unaccel_dx = event->unaccel_dx;
double unaccel_dy = event->unaccel_dy;
double dx_unaccel = event->unaccel_dx;
double dy_unaccel = event->unaccel_dy;
notify_relative_motion(cursor->seat,
(uint64_t)event->time_msec * 1000, dx, dy, unaccel_dx, unaccel_dy);
wlr_relative_pointer_manager_v1_send_relative_motion(
cursor->seat->input->server->desktop->relative_pointer_manager,
cursor->seat->seat, (uint64_t)event->time_msec * 1000, dx, dy,
dx_unaccel, dy_unaccel);
if (cursor->active_constraint) {
struct roots_view *view = cursor->pointer_view->view;
@ -381,9 +360,9 @@ void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor,
double dx = lx - cursor->cursor->x;
double dy = ly - cursor->cursor->y;
notify_relative_motion(cursor->seat,
(uint64_t)event->time_msec * 1000, dx, dy, dx, dy);
wlr_relative_pointer_manager_v1_send_relative_motion(
cursor->seat->input->server->desktop->relative_pointer_manager,
cursor->seat->seat, (uint64_t)event->time_msec * 1000, dx, dy, dx, dy);
if (cursor->pointer_view) {
struct roots_view *view = cursor->pointer_view->view;

View File

@ -122,7 +122,7 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl
relative_pointer->resource = relative_pointer_resource;
relative_pointer->seat = seat_client->seat;
relative_pointer->pointer = pointer;
relative_pointer->pointer_resource = pointer;
wl_signal_init(&relative_pointer->events.destroy);
@ -139,7 +139,7 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl
&relative_pointer->seat_destroy);
relative_pointer->seat_destroy.notify = relative_pointer_handle_seat_destroy;
wl_resource_add_destroy_listener(relative_pointer->pointer,
wl_resource_add_destroy_listener(relative_pointer->pointer_resource,
&relative_pointer->pointer_destroy);
relative_pointer->pointer_destroy.notify = relative_pointer_handle_pointer_destroy;
@ -246,18 +246,30 @@ void wlr_relative_pointer_manager_v1_destroy(struct wlr_relative_pointer_manager
wl_global_destroy(manager->global);
free(manager);
wlr_log(WLR_DEBUG, "relative_pointer_v1 manager destroyed");
}
void wlr_relative_pointer_v1_send_relative_motion(struct wlr_relative_pointer_v1 *relative_pointer,
void wlr_relative_pointer_manager_v1_send_relative_motion(
struct wlr_relative_pointer_manager_v1 *manager, struct wlr_seat *seat,
uint64_t time_msec, double dx, double dy,
double dx_unaccel, double dy_unaccel) {
zwp_relative_pointer_v1_send_relative_motion(relative_pointer->resource,
(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));
struct wlr_seat_client *focused = seat->pointer_state.focused_client;
if (focused == NULL) {
return;
}
wl_pointer_send_frame(relative_pointer->pointer);
struct wlr_relative_pointer_v1 *pointer;
wl_list_for_each(pointer, &manager->relative_pointers, link) {
struct wlr_seat_client *seat_client =
wlr_seat_client_from_pointer_resource(pointer->pointer_resource);
if (seat != pointer->seat || focused != seat_client) {
continue;
}
zwp_relative_pointer_v1_send_relative_motion(pointer->resource,
(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));
wl_pointer_send_frame(pointer->pointer_resource);
}
}