relative_pointer: implementation and code fixes

In particular, modified public creator and destructor function names,
added a display destroy listener, safely extract user data from
resources, send correct time (in usecs) in rootston, etc.
This commit is contained in:
random human 2018-10-04 00:43:35 +05:30 committed by Alex Maese
parent 42ffa413fb
commit 68137dca3f
7 changed files with 96 additions and 53 deletions

View File

@ -22,12 +22,6 @@
/** /**
* A global interface used for getting the relative pointer object for a given * A global interface used for getting the relative pointer object for a given
* pointer. * pointer.
*
* Signals:
* - destroy -> struct wlr_relative_pointer_manager_v1 *manager
* :: the manager was destroyed
* - new_relative_pointer -> struct wlr_relative_pointer_v1 *relative_pointer
* :: a new relative_pointer was created
*/ */
struct wlr_relative_pointer_manager_v1 { struct wlr_relative_pointer_manager_v1 {
@ -36,9 +30,15 @@ struct wlr_relative_pointer_manager_v1 {
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
/**
* returns struct wlr_relative_pointer_v1 *relative_pointer
* called when a new relative_pointer is successfully created
*/
struct wl_signal new_relative_pointer; struct wl_signal new_relative_pointer;
} events; } events;
struct wl_listener display_destroy_listener;
void *data; void *data;
}; };
@ -48,16 +48,12 @@ struct wlr_relative_pointer_manager_v1 {
* used for emitting relative pointer events. It shares the same focus as * 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 * wl_pointer objects of the same seat and will only emit events when it has
* focus. * focus.
*
* Signals:
* - destroy -> struct wlr_relative_pointer_v1 *relative_pointer
* :: the relative_pointer was destroyed
*/ */
struct wlr_relative_pointer_v1 { struct wlr_relative_pointer_v1 {
struct wl_client *client; struct wl_client *client;
struct wl_resource *resource; struct wl_resource *resource;
struct wl_pointer *pointer; struct wl_resource *pointer;
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
@ -66,10 +62,16 @@ struct wlr_relative_pointer_v1 {
void *data; void *data;
}; };
struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl_display *display); struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_manager_v1_create(
void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager); struct wl_display *display);
void wlr_relative_pointer_manager_v1_destroy(
struct wlr_relative_pointer_manager_v1 *relative_pointer_manager);
void wlr_relative_pointer_v1_send_relative_motion(struct wlr_relative_pointer_v1 *relative_pointer, void wlr_relative_pointer_v1_send_relative_motion(
uint64_t time, double dx, double dy, double dx_unaccel, double dy_unaccel); struct wlr_relative_pointer_v1 *relative_pointer, uint64_t time,
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);
#endif #endif

View File

@ -27,7 +27,7 @@ struct wlr_seat_client {
// lists of wl_resource // lists of wl_resource
struct wl_list resources; struct wl_list resources;
struct wl_list pointers; struct wl_list pointers;
struct wl_list relative_pointers; struct wl_list relative_pointers_v1;
struct wl_list keyboards; struct wl_list keyboards;
struct wl_list touches; struct wl_list touches;
struct wl_list data_devices; struct wl_list data_devices;

View File

@ -311,7 +311,7 @@ void roots_cursor_handle_motion(struct roots_cursor *cursor,
double dy = event->delta_y; double dy = event->delta_y;
wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, wlr_seat_pointer_notify_relative_motion(cursor->seat->seat,
(uint64_t)event->time_msec, dx, dy, dx, dy); (uint64_t)event->time_msec * 1000, dx, dy, dx, dy);
if (cursor->active_constraint) { if (cursor->active_constraint) {
struct roots_view *view = cursor->pointer_view->view; struct roots_view *view = cursor->pointer_view->view;
@ -355,7 +355,7 @@ void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor,
double dx = lx - cursor->cursor->x; double dx = lx - cursor->cursor->x;
double dy = ly - cursor->cursor->y; double dy = ly - cursor->cursor->y;
wlr_seat_pointer_notify_relative_motion(cursor->seat->seat, wlr_seat_pointer_notify_relative_motion(cursor->seat->seat,
(uint64_t)event->time_msec, dx, dy, dx, dy); (uint64_t)event->time_msec * 1000, dx, dy, dx, dy);
if (cursor->pointer_view) { if (cursor->pointer_view) {
struct roots_view *view = cursor->pointer_view->view; struct roots_view *view = cursor->pointer_view->view;

View File

@ -1082,7 +1082,7 @@ struct roots_desktop *desktop_create(struct roots_server *server,
desktop->foreign_toplevel_manager_v1 = desktop->foreign_toplevel_manager_v1 =
wlr_foreign_toplevel_manager_v1_create(server->wl_display); wlr_foreign_toplevel_manager_v1_create(server->wl_display);
desktop->relative_pointer_manager = desktop->relative_pointer_manager =
wlr_relative_pointer_v1_create(server->wl_display); wlr_relative_pointer_manager_v1_create(server->wl_display);
return desktop; return desktop;
} }

View File

@ -79,7 +79,7 @@ static void seat_client_handle_resource_destroy(
wl_resource_for_each_safe(resource, tmp, &client->pointers) { wl_resource_for_each_safe(resource, tmp, &client->pointers) {
wl_resource_destroy(resource); wl_resource_destroy(resource);
} }
wl_resource_for_each_safe(resource, tmp, &client->relative_pointers) { wl_resource_for_each_safe(resource, tmp, &client->relative_pointers_v1) {
wl_resource_destroy(resource); wl_resource_destroy(resource);
} }
wl_resource_for_each_safe(resource, tmp, &client->keyboards) { wl_resource_for_each_safe(resource, tmp, &client->keyboards) {
@ -134,7 +134,7 @@ static void seat_handle_bind(struct wl_client *client, void *_wlr_seat,
seat_client->seat = wlr_seat; seat_client->seat = wlr_seat;
wl_list_init(&seat_client->resources); wl_list_init(&seat_client->resources);
wl_list_init(&seat_client->pointers); wl_list_init(&seat_client->pointers);
wl_list_init(&seat_client->relative_pointers); wl_list_init(&seat_client->relative_pointers_v1);
wl_list_init(&seat_client->keyboards); wl_list_init(&seat_client->keyboards);
wl_list_init(&seat_client->touches); wl_list_init(&seat_client->touches);
wl_list_init(&seat_client->data_devices); wl_list_init(&seat_client->data_devices);

View File

@ -314,16 +314,16 @@ void wlr_seat_pointer_notify_relative_motion(struct wlr_seat *wlr_seat,
} }
struct wl_resource *resource; struct wl_resource *resource;
wl_resource_for_each(resource, &client->relative_pointers) { wl_resource_for_each(resource, &client->relative_pointers_v1) {
struct wlr_relative_pointer_v1 *relative_pointer = struct wlr_relative_pointer_v1 *relative_pointer =
wl_resource_get_user_data(resource); wlr_relative_pointer_v1_from_resource(resource);
if (relative_pointer == NULL) { if (relative_pointer == NULL) {
continue; continue;
} }
wlr_relative_pointer_v1_send_relative_motion(relative_pointer, time, wlr_relative_pointer_v1_send_relative_motion(relative_pointer, time,
dx, dy, dx_unaccel, dy_unaccel); dx, dy, dx_unaccel, dy_unaccel);
pointer_send_frame((struct wl_resource *) relative_pointer->pointer); pointer_send_frame(relative_pointer->pointer);
} }
} }

View File

@ -9,12 +9,57 @@
#include "wayland-server.h" #include "wayland-server.h"
#include "relative-pointer-unstable-v1-protocol.h" #include "relative-pointer-unstable-v1-protocol.h"
#define RELATIVE_POINTER_MANAGER_VERSION 1
static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_manager_v1_impl; static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_manager_v1_impl;
static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl; static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl;
/** /**
* Callback functions * helper functions
*/
struct wlr_relative_pointer_v1 *relative_pointer_from_resource(struct wl_resource *resource) {
assert(wl_resource_instance_of(resource, &zwp_relative_pointer_v1_interface,
&relative_pointer_v1_impl));
return wl_resource_get_user_data(resource);
}
static struct wlr_relative_pointer_manager_v1 *relative_pointer_manager_from_resource(struct wl_resource *resource) {
assert(wl_resource_instance_of(resource, &zwp_relative_pointer_manager_v1_interface,
&relative_pointer_manager_v1_impl));
return wl_resource_get_user_data(resource);
}
/**
* relative_pointer handler functions
*/
static void relative_pointer_v1_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_relative_pointer_v1 *relative_pointer =
relative_pointer_from_resource(resource);
wlr_signal_emit_safe(&relative_pointer->events.destroy, relative_pointer);
wl_list_remove(wl_resource_get_link(resource));
free(relative_pointer);
}
static void relative_pointer_v1_handle_destroy(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_relative_pointer_v1 *relative_pointer =
relative_pointer_from_resource(resource);
wlr_log(WLR_DEBUG, "relative_pointer_v1 %p released by client %p",
relative_pointer, client);
wl_resource_destroy(resource);
}
/**
* relative_pointer_manager handler functions
*/ */
static void relative_pointer_manager_v1_handle_resource_destroy(struct wl_resource *resource) { static void relative_pointer_manager_v1_handle_resource_destroy(struct wl_resource *resource) {
@ -22,14 +67,6 @@ static void relative_pointer_manager_v1_handle_resource_destroy(struct wl_resour
} }
static void relative_pointer_v1_handle_resource_destroy(struct wl_resource *resource) {
wl_list_remove(wl_resource_get_link(resource));
struct wlr_relative_pointer_v1 *relative_pointer = wl_resource_get_user_data(resource);
free(relative_pointer);
}
static void relative_pointer_manager_v1_handle_destroy(struct wl_client *client, static void relative_pointer_manager_v1_handle_destroy(struct wl_client *client,
struct wl_resource *resource) { struct wl_resource *resource) {
wl_resource_destroy(resource); wl_resource_destroy(resource);
@ -62,18 +99,18 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl
relative_pointer->client = client; relative_pointer->client = client;
relative_pointer->resource = relative_pointer_resource; relative_pointer->resource = relative_pointer_resource;
relative_pointer->pointer = (struct wl_pointer *) pointer; relative_pointer->pointer = pointer;
wl_signal_init(&relative_pointer->events.destroy); wl_signal_init(&relative_pointer->events.destroy);
wl_list_insert(&seat_client->relative_pointers, wl_list_insert(&seat_client->relative_pointers_v1,
wl_resource_get_link(relative_pointer_resource)); wl_resource_get_link(relative_pointer_resource));
wl_resource_set_implementation(relative_pointer_resource, &relative_pointer_v1_impl, wl_resource_set_implementation(relative_pointer_resource, &relative_pointer_v1_impl,
relative_pointer, relative_pointer_v1_handle_resource_destroy); relative_pointer, relative_pointer_v1_handle_resource_destroy);
struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = struct wlr_relative_pointer_manager_v1 *relative_pointer_manager =
wl_resource_get_user_data(resource); relative_pointer_manager_from_resource(resource);
wlr_signal_emit_safe(&relative_pointer_manager->events.new_relative_pointer, wlr_signal_emit_safe(&relative_pointer_manager->events.new_relative_pointer,
relative_pointer); relative_pointer);
@ -82,17 +119,6 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl
} }
static void relative_pointer_v1_handle_destroy(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_relative_pointer_v1 *relative_pointer =
wl_resource_get_user_data(resource);
wlr_log(WLR_DEBUG, "relative_pointer_v1 %p released by client %p",
relative_pointer, client);
wl_resource_destroy(resource);
}
static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void *data, static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = data; struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = data;
@ -114,6 +140,12 @@ static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void *
wl_client); wl_client);
} }
static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_relative_pointer_manager_v1 *relative_pointer_manager =
wl_container_of(listener, relative_pointer_manager, display_destroy_listener);
wlr_relative_pointer_manager_v1_destroy(relative_pointer_manager);
}
/** /**
* Implementations * Implementations
@ -134,7 +166,7 @@ static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl =
* Public functions * Public functions
*/ */
struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl_display *display) { struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_manager_v1_create(struct wl_display *display) {
struct wlr_relative_pointer_manager_v1 *relative_pointer_manager = struct wlr_relative_pointer_manager_v1 *relative_pointer_manager =
calloc(1, sizeof(struct wlr_relative_pointer_manager_v1)); calloc(1, sizeof(struct wlr_relative_pointer_manager_v1));
@ -144,11 +176,8 @@ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl
wl_list_init(&relative_pointer_manager->resources); wl_list_init(&relative_pointer_manager->resources);
wl_signal_init(&relative_pointer_manager->events.destroy);
wl_signal_init(&relative_pointer_manager->events.new_relative_pointer);
relative_pointer_manager->global = wl_global_create(display, relative_pointer_manager->global = wl_global_create(display,
&zwp_relative_pointer_manager_v1_interface, 1, &zwp_relative_pointer_manager_v1_interface, RELATIVE_POINTER_MANAGER_VERSION,
relative_pointer_manager, relative_pointer_manager_v1_bind); relative_pointer_manager, relative_pointer_manager_v1_bind);
if (relative_pointer_manager->global == NULL) { if (relative_pointer_manager->global == NULL) {
@ -156,18 +185,25 @@ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl
return NULL; return NULL;
} }
wl_signal_init(&relative_pointer_manager->events.destroy);
wl_signal_init(&relative_pointer_manager->events.new_relative_pointer);
relative_pointer_manager->display_destroy_listener.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &relative_pointer_manager->display_destroy_listener);
wlr_log(WLR_DEBUG, "relative_pointer_v1 manager created"); wlr_log(WLR_DEBUG, "relative_pointer_v1 manager created");
return relative_pointer_manager; return relative_pointer_manager;
} }
void wlr_relative_pointer_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager) { void wlr_relative_pointer_manager_v1_destroy(struct wlr_relative_pointer_manager_v1 *relative_pointer_manager) {
if (relative_pointer_manager == NULL) { if (relative_pointer_manager == NULL) {
return; return;
} }
wlr_signal_emit_safe(&relative_pointer_manager->events.destroy, relative_pointer_manager); wlr_signal_emit_safe(&relative_pointer_manager->events.destroy, relative_pointer_manager);
wl_list_remove(&relative_pointer_manager->display_destroy_listener.link);
struct wl_resource *resource; struct wl_resource *resource;
struct wl_resource *tmp_resource; struct wl_resource *tmp_resource;
@ -190,3 +226,8 @@ void wlr_relative_pointer_v1_send_relative_motion(struct wlr_relative_pointer_v1
wl_fixed_from_double(dx), wl_fixed_from_double(dy), wl_fixed_from_double(dx), wl_fixed_from_double(dy),
wl_fixed_from_double(dx_unaccel), wl_fixed_from_double(dy_unaccel)); wl_fixed_from_double(dx_unaccel), wl_fixed_from_double(dy_unaccel));
} }
struct wlr_relative_pointer_v1 *wlr_relative_pointer_v1_from_resource(struct wl_resource *resource) {
return relative_pointer_from_resource(resource);
}