2017-08-16 14:50:43 +02:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2017-11-12 15:55:28 +01:00
|
|
|
#include <time.h>
|
2017-08-16 14:50:43 +02:00
|
|
|
#include <wayland-server.h>
|
|
|
|
#include <wlr/types/wlr_seat.h>
|
2017-09-20 13:32:28 +02:00
|
|
|
#include <wlr/types/wlr_input_device.h>
|
2017-08-16 14:50:43 +02:00
|
|
|
#include <wlr/util/log.h>
|
2017-10-12 17:41:11 +02:00
|
|
|
#include <wlr/types/wlr_data_device.h>
|
2017-12-23 00:03:15 +01:00
|
|
|
#include <wlr/types/wlr_primary_selection.h>
|
2017-08-16 14:50:43 +02:00
|
|
|
|
2017-08-17 12:55:59 +02:00
|
|
|
static void resource_destroy(struct wl_client *client,
|
|
|
|
struct wl_resource *resource) {
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
|
|
|
|
2017-10-03 21:13:29 +02:00
|
|
|
static void pointer_send_frame(struct wl_resource *resource) {
|
|
|
|
if (wl_resource_get_version(resource) >=
|
|
|
|
WL_POINTER_FRAME_SINCE_VERSION) {
|
|
|
|
wl_pointer_send_frame(resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 14:50:43 +02:00
|
|
|
static void wl_pointer_set_cursor(struct wl_client *client,
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wl_resource *pointer_resource, uint32_t serial,
|
2017-10-05 13:11:51 +02:00
|
|
|
struct wl_resource *surface_resource,
|
|
|
|
int32_t hotspot_x, int32_t hotspot_y) {
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *seat_client =
|
|
|
|
wl_resource_get_user_data(pointer_resource);
|
2017-10-07 10:55:17 +02:00
|
|
|
struct wlr_surface *surface = NULL;
|
|
|
|
if (surface_resource != NULL) {
|
|
|
|
surface = wl_resource_get_user_data(surface_resource);
|
2017-10-08 23:24:57 +02:00
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
if (wlr_surface_set_role(surface, "wl_pointer-cursor", surface_resource,
|
2017-10-08 23:24:57 +02:00
|
|
|
WL_POINTER_ERROR_ROLE) < 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-07 10:55:17 +02:00
|
|
|
}
|
2017-10-05 13:11:51 +02:00
|
|
|
|
|
|
|
struct wlr_seat_pointer_request_set_cursor_event *event =
|
|
|
|
calloc(1, sizeof(struct wlr_seat_pointer_request_set_cursor_event));
|
|
|
|
if (event == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-30 13:37:54 +01:00
|
|
|
event->seat_client = seat_client;
|
2017-10-05 13:11:51 +02:00
|
|
|
event->surface = surface;
|
2017-11-01 18:15:37 +01:00
|
|
|
event->serial = serial;
|
2017-10-05 13:11:51 +02:00
|
|
|
event->hotspot_x = hotspot_x;
|
|
|
|
event->hotspot_y = hotspot_y;
|
|
|
|
|
2017-10-30 13:44:39 +01:00
|
|
|
wl_signal_emit(&seat_client->seat->events.request_set_cursor, event);
|
2017-10-05 13:11:51 +02:00
|
|
|
|
|
|
|
free(event);
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
|
|
|
|
2017-08-17 12:55:59 +02:00
|
|
|
static const struct wl_pointer_interface wl_pointer_impl = {
|
|
|
|
.set_cursor = wl_pointer_set_cursor,
|
2017-12-16 13:53:39 +01:00
|
|
|
.release = resource_destroy,
|
2017-08-17 12:55:59 +02:00
|
|
|
};
|
|
|
|
|
2017-08-16 14:50:43 +02:00
|
|
|
static void wl_pointer_destroy(struct wl_resource *resource) {
|
2017-12-16 13:53:39 +01:00
|
|
|
wl_list_remove(wl_resource_get_link(resource));
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wl_seat_get_pointer(struct wl_client *client,
|
2017-11-02 23:14:24 +01:00
|
|
|
struct wl_resource *seat_resource, uint32_t id) {
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *seat_client =
|
2017-11-02 23:14:24 +01:00
|
|
|
wl_resource_get_user_data(seat_resource);
|
2017-10-30 13:44:39 +01:00
|
|
|
if (!(seat_client->seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) {
|
2017-08-16 14:50:43 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-12-16 13:53:39 +01:00
|
|
|
|
|
|
|
struct wl_resource *resource = wl_resource_create(client,
|
|
|
|
&wl_pointer_interface, wl_resource_get_version(seat_resource), id);
|
|
|
|
if (resource == NULL) {
|
2017-11-02 23:14:24 +01:00
|
|
|
wl_resource_post_no_memory(seat_resource);
|
|
|
|
return;
|
|
|
|
}
|
2017-12-16 13:53:39 +01:00
|
|
|
wl_resource_set_implementation(resource, &wl_pointer_impl, seat_client,
|
|
|
|
&wl_pointer_destroy);
|
|
|
|
wl_list_insert(&seat_client->pointers, wl_resource_get_link(resource));
|
2017-08-17 12:55:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_keyboard_interface wl_keyboard_impl = {
|
2017-12-16 13:53:39 +01:00
|
|
|
.release = resource_destroy,
|
2017-08-17 12:55:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void wl_keyboard_destroy(struct wl_resource *resource) {
|
2017-12-16 13:53:39 +01:00
|
|
|
wl_list_remove(wl_resource_get_link(resource));
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
static void seat_client_send_keymap(struct wlr_seat_client *client,
|
2017-10-23 14:59:55 +02:00
|
|
|
struct wlr_keyboard *keyboard) {
|
2017-12-16 13:53:39 +01:00
|
|
|
if (!keyboard) {
|
2017-10-23 14:59:55 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-12-16 13:53:39 +01:00
|
|
|
|
2017-10-23 14:59:55 +02:00
|
|
|
// TODO: We should probably lift all of the keys set by the other
|
|
|
|
// keyboard
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &client->keyboards) {
|
|
|
|
wl_keyboard_send_keymap(resource,
|
|
|
|
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keyboard->keymap_fd,
|
|
|
|
keyboard->keymap_size);
|
|
|
|
}
|
2017-12-08 17:03:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void seat_client_send_repeat_info(struct wlr_seat_client *client,
|
|
|
|
struct wlr_keyboard *keyboard) {
|
2017-12-16 13:53:39 +01:00
|
|
|
if (!keyboard) {
|
2017-12-08 17:03:05 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-10-23 14:59:55 +02:00
|
|
|
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &client->keyboards) {
|
|
|
|
if (wl_resource_get_version(resource) >=
|
|
|
|
WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) {
|
|
|
|
wl_keyboard_send_repeat_info(resource,
|
|
|
|
keyboard->repeat_info.rate, keyboard->repeat_info.delay);
|
|
|
|
}
|
2017-10-23 14:59:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-16 14:50:43 +02:00
|
|
|
static void wl_seat_get_keyboard(struct wl_client *client,
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wl_resource *seat_resource, uint32_t id) {
|
|
|
|
struct wlr_seat_client *seat_client =
|
|
|
|
wl_resource_get_user_data(seat_resource);
|
2017-10-30 13:44:39 +01:00
|
|
|
if (!(seat_client->seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)) {
|
2017-08-17 12:55:59 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-12-16 13:53:39 +01:00
|
|
|
|
|
|
|
struct wl_resource *resource = wl_resource_create(client,
|
|
|
|
&wl_keyboard_interface, wl_resource_get_version(seat_resource), id);
|
|
|
|
if (resource == NULL) {
|
2017-11-02 23:14:24 +01:00
|
|
|
wl_resource_post_no_memory(seat_resource);
|
|
|
|
return;
|
|
|
|
}
|
2017-12-16 13:53:39 +01:00
|
|
|
wl_resource_set_implementation(resource, &wl_keyboard_impl, seat_client,
|
|
|
|
&wl_keyboard_destroy);
|
|
|
|
wl_list_insert(&seat_client->keyboards, wl_resource_get_link(resource));
|
2017-10-23 14:59:55 +02:00
|
|
|
|
2017-12-08 17:03:05 +01:00
|
|
|
struct wlr_keyboard *keyboard = seat_client->seat->keyboard_state.keyboard;
|
|
|
|
seat_client_send_keymap(seat_client, keyboard);
|
|
|
|
seat_client_send_repeat_info(seat_client, keyboard);
|
2017-10-23 14:59:55 +02:00
|
|
|
|
|
|
|
// TODO possibly handle the case where this keyboard needs an enter
|
|
|
|
// right away
|
2017-08-17 12:55:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_touch_interface wl_touch_impl = {
|
2017-12-16 13:53:39 +01:00
|
|
|
.release = resource_destroy,
|
2017-08-17 12:55:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void wl_touch_destroy(struct wl_resource *resource) {
|
2017-12-16 13:53:39 +01:00
|
|
|
wl_list_remove(wl_resource_get_link(resource));
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wl_seat_get_touch(struct wl_client *client,
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wl_resource *seat_resource, uint32_t id) {
|
|
|
|
struct wlr_seat_client *seat_client =
|
|
|
|
wl_resource_get_user_data(seat_resource);
|
2017-10-30 13:44:39 +01:00
|
|
|
if (!(seat_client->seat->capabilities & WL_SEAT_CAPABILITY_TOUCH)) {
|
2017-08-17 12:55:59 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-12-16 13:53:39 +01:00
|
|
|
|
|
|
|
struct wl_resource *resource = wl_resource_create(client,
|
|
|
|
&wl_touch_interface, wl_resource_get_version(seat_resource), id);
|
|
|
|
if (resource == NULL) {
|
2017-11-02 23:14:24 +01:00
|
|
|
wl_resource_post_no_memory(seat_resource);
|
|
|
|
return;
|
|
|
|
}
|
2017-12-16 13:53:39 +01:00
|
|
|
wl_resource_set_implementation(resource, &wl_touch_impl, seat_client,
|
|
|
|
&wl_touch_destroy);
|
|
|
|
wl_list_insert(&seat_client->touches, wl_resource_get_link(resource));
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
|
|
|
|
2017-12-16 13:53:39 +01:00
|
|
|
static void wlr_seat_client_resource_destroy(struct wl_resource *seat_resource) {
|
|
|
|
struct wlr_seat_client *client = wl_resource_get_user_data(seat_resource);
|
2017-11-19 17:10:27 +01:00
|
|
|
wl_signal_emit(&client->events.destroy, client);
|
2017-10-16 15:14:16 +02:00
|
|
|
|
2017-10-30 13:44:39 +01:00
|
|
|
if (client == client->seat->pointer_state.focused_client) {
|
|
|
|
client->seat->pointer_state.focused_client = NULL;
|
2017-09-20 13:32:28 +02:00
|
|
|
}
|
2017-10-30 13:44:39 +01:00
|
|
|
if (client == client->seat->keyboard_state.focused_client) {
|
|
|
|
client->seat->keyboard_state.focused_client = NULL;
|
2017-09-22 22:07:00 +02:00
|
|
|
}
|
2017-09-20 13:32:28 +02:00
|
|
|
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource, *tmp;
|
|
|
|
wl_resource_for_each_safe(resource, tmp, &client->pointers) {
|
|
|
|
wl_resource_destroy(resource);
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
2017-12-16 13:53:39 +01:00
|
|
|
wl_resource_for_each_safe(resource, tmp, &client->keyboards) {
|
|
|
|
wl_resource_destroy(resource);
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
2017-12-16 13:53:39 +01:00
|
|
|
wl_resource_for_each_safe(resource, tmp, &client->touches) {
|
|
|
|
wl_resource_destroy(resource);
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
2017-12-16 14:22:59 +01:00
|
|
|
wl_resource_for_each_safe(resource, tmp, &client->data_devices) {
|
|
|
|
wl_resource_destroy(resource);
|
2017-08-18 19:12:31 +02:00
|
|
|
}
|
2017-12-22 22:22:29 +01:00
|
|
|
wl_resource_for_each_safe(resource, tmp, &client->primary_selection_devices) {
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
}
|
2017-12-16 14:22:59 +01:00
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
wl_list_remove(&client->link);
|
|
|
|
free(client);
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct wl_seat_interface wl_seat_impl = {
|
|
|
|
.get_pointer = wl_seat_get_pointer,
|
|
|
|
.get_keyboard = wl_seat_get_keyboard,
|
|
|
|
.get_touch = wl_seat_get_touch,
|
2017-12-16 13:53:39 +01:00
|
|
|
.release = resource_destroy,
|
2017-08-16 14:50:43 +02:00
|
|
|
};
|
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
static void wl_seat_bind(struct wl_client *client, void *_wlr_seat,
|
2017-08-16 14:50:43 +02:00
|
|
|
uint32_t version, uint32_t id) {
|
|
|
|
struct wlr_seat *wlr_seat = _wlr_seat;
|
2017-10-30 13:37:54 +01:00
|
|
|
assert(client && wlr_seat);
|
|
|
|
|
|
|
|
struct wlr_seat_client *seat_client =
|
|
|
|
calloc(1, sizeof(struct wlr_seat_client));
|
2017-10-31 11:58:39 +01:00
|
|
|
if (seat_client == NULL) {
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
return;
|
|
|
|
}
|
2017-10-30 13:37:54 +01:00
|
|
|
seat_client->wl_resource =
|
|
|
|
wl_resource_create(client, &wl_seat_interface, version, id);
|
2017-11-02 23:14:24 +01:00
|
|
|
if (seat_client->wl_resource == NULL) {
|
|
|
|
free(seat_client);
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
return;
|
|
|
|
}
|
2017-10-30 13:37:54 +01:00
|
|
|
seat_client->client = client;
|
2017-10-30 13:44:39 +01:00
|
|
|
seat_client->seat = wlr_seat;
|
2017-12-16 13:53:39 +01:00
|
|
|
wl_list_init(&seat_client->pointers);
|
|
|
|
wl_list_init(&seat_client->keyboards);
|
|
|
|
wl_list_init(&seat_client->touches);
|
2017-12-16 14:22:59 +01:00
|
|
|
wl_list_init(&seat_client->data_devices);
|
2017-12-22 22:22:29 +01:00
|
|
|
wl_list_init(&seat_client->primary_selection_devices);
|
2017-10-30 13:37:54 +01:00
|
|
|
wl_resource_set_implementation(seat_client->wl_resource, &wl_seat_impl,
|
|
|
|
seat_client, wlr_seat_client_resource_destroy);
|
|
|
|
wl_list_insert(&wlr_seat->clients, &seat_client->link);
|
2017-10-03 21:13:29 +02:00
|
|
|
if (version >= WL_SEAT_NAME_SINCE_VERSION) {
|
2017-10-30 13:37:54 +01:00
|
|
|
wl_seat_send_name(seat_client->wl_resource, wlr_seat->name);
|
2017-10-03 21:13:29 +02:00
|
|
|
}
|
2017-10-30 13:37:54 +01:00
|
|
|
wl_seat_send_capabilities(seat_client->wl_resource, wlr_seat->capabilities);
|
2017-11-19 17:10:27 +01:00
|
|
|
wl_signal_init(&seat_client->events.destroy);
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
|
|
|
|
2017-10-05 19:28:26 +02:00
|
|
|
static void default_pointer_enter(struct wlr_seat_pointer_grab *grab,
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wlr_surface *surface, double sx, double sy) {
|
2017-10-05 19:28:26 +02:00
|
|
|
wlr_seat_pointer_enter(grab->seat, surface, sx, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void default_pointer_motion(struct wlr_seat_pointer_grab *grab,
|
|
|
|
uint32_t time, double sx, double sy) {
|
|
|
|
wlr_seat_pointer_send_motion(grab->seat, time, sx, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t default_pointer_button(struct wlr_seat_pointer_grab *grab,
|
|
|
|
uint32_t time, uint32_t button, uint32_t state) {
|
|
|
|
return wlr_seat_pointer_send_button(grab->seat, time, button, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void default_pointer_axis(struct wlr_seat_pointer_grab *grab,
|
|
|
|
uint32_t time, enum wlr_axis_orientation orientation, double value) {
|
|
|
|
wlr_seat_pointer_send_axis(grab->seat, time, orientation, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void default_pointer_cancel(struct wlr_seat_pointer_grab *grab) {
|
|
|
|
// cannot be cancelled
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wlr_pointer_grab_interface default_pointer_grab_impl = {
|
|
|
|
.enter = default_pointer_enter,
|
|
|
|
.motion = default_pointer_motion,
|
|
|
|
.button = default_pointer_button,
|
|
|
|
.axis = default_pointer_axis,
|
|
|
|
.cancel = default_pointer_cancel,
|
|
|
|
};
|
|
|
|
|
2017-10-07 17:02:11 +02:00
|
|
|
static void default_keyboard_enter(struct wlr_seat_keyboard_grab *grab,
|
|
|
|
struct wlr_surface *surface) {
|
|
|
|
wlr_seat_keyboard_enter(grab->seat, surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void default_keyboard_key(struct wlr_seat_keyboard_grab *grab,
|
|
|
|
uint32_t time, uint32_t key, uint32_t state) {
|
|
|
|
wlr_seat_keyboard_send_key(grab->seat, time, key, state);
|
|
|
|
}
|
|
|
|
|
2017-11-08 19:02:56 +01:00
|
|
|
static void default_keyboard_modifiers(struct wlr_seat_keyboard_grab *grab) {
|
|
|
|
wlr_seat_keyboard_send_modifiers(grab->seat);
|
2017-10-07 17:02:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void default_keyboard_cancel(struct wlr_seat_keyboard_grab *grab) {
|
|
|
|
// cannot be cancelled
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wlr_keyboard_grab_interface default_keyboard_grab_impl = {
|
|
|
|
.enter = default_keyboard_enter,
|
|
|
|
.key = default_keyboard_key,
|
|
|
|
.modifiers = default_keyboard_modifiers,
|
|
|
|
.cancel = default_keyboard_cancel,
|
|
|
|
};
|
|
|
|
|
2017-11-16 23:34:38 +01:00
|
|
|
static uint32_t default_touch_down(struct wlr_seat_touch_grab *grab, uint32_t time,
|
2017-11-14 01:16:34 +01:00
|
|
|
struct wlr_touch_point *point) {
|
2017-11-16 23:34:38 +01:00
|
|
|
return wlr_seat_touch_send_down(grab->seat, point->surface, time,
|
|
|
|
point->touch_id, point->sx, point->sy);
|
2017-11-12 23:04:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void default_touch_up(struct wlr_seat_touch_grab *grab, uint32_t time,
|
2017-11-14 01:16:34 +01:00
|
|
|
struct wlr_touch_point *point) {
|
|
|
|
wlr_seat_touch_send_up(grab->seat, time, point->touch_id);
|
2017-11-12 23:04:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void default_touch_motion(struct wlr_seat_touch_grab *grab,
|
2017-11-14 01:16:34 +01:00
|
|
|
uint32_t time, struct wlr_touch_point *point) {
|
2017-11-14 14:51:37 +01:00
|
|
|
if (!point->focus_surface || point->focus_surface == point->surface) {
|
|
|
|
wlr_seat_touch_send_motion(grab->seat, time, point->touch_id, point->sx,
|
|
|
|
point->sy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void default_touch_enter(struct wlr_seat_touch_grab *grab,
|
|
|
|
uint32_t time, struct wlr_touch_point *point) {
|
|
|
|
// not handled by default
|
2017-11-12 23:04:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void default_touch_cancel(struct wlr_seat_touch_grab *grab) {
|
|
|
|
// cannot be cancelled
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wlr_touch_grab_interface default_touch_grab_impl = {
|
|
|
|
.down = default_touch_down,
|
|
|
|
.up = default_touch_up,
|
|
|
|
.motion = default_touch_motion,
|
2017-11-14 14:51:37 +01:00
|
|
|
.enter = default_touch_enter,
|
2017-11-12 23:04:56 +01:00
|
|
|
.cancel = default_touch_cancel,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-29 22:51:33 +01:00
|
|
|
void wlr_seat_destroy(struct wlr_seat *seat) {
|
|
|
|
if (!seat) {
|
2017-12-07 01:02:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-29 22:51:33 +01:00
|
|
|
wl_signal_emit(&seat->events.destroy, seat);
|
|
|
|
|
|
|
|
wl_list_remove(&seat->display_destroy.link);
|
2017-12-29 17:55:03 +01:00
|
|
|
|
2017-12-30 09:58:04 +01:00
|
|
|
if (seat->selection_data_source) {
|
|
|
|
seat->selection_data_source->cancel(seat->selection_data_source);
|
|
|
|
seat->selection_data_source = NULL;
|
2017-12-29 22:51:33 +01:00
|
|
|
wl_list_remove(&seat->selection_data_source_destroy.link);
|
|
|
|
}
|
|
|
|
if (seat->primary_selection_source) {
|
|
|
|
seat->primary_selection_source->cancel(seat->primary_selection_source);
|
|
|
|
seat->primary_selection_source = NULL;
|
|
|
|
wl_list_remove(&seat->primary_selection_source_destroy.link);
|
|
|
|
}
|
2017-12-07 01:02:07 +01:00
|
|
|
|
|
|
|
struct wlr_seat_client *client, *tmp;
|
2017-12-29 22:51:33 +01:00
|
|
|
wl_list_for_each_safe(client, tmp, &seat->clients, link) {
|
2017-12-07 01:02:07 +01:00
|
|
|
// will destroy other resources as well
|
|
|
|
wl_resource_destroy(client->wl_resource);
|
|
|
|
}
|
|
|
|
|
2017-12-29 22:51:33 +01:00
|
|
|
wl_global_destroy(seat->wl_global);
|
|
|
|
free(seat->pointer_state.default_grab);
|
|
|
|
free(seat->keyboard_state.default_grab);
|
|
|
|
free(seat->touch_state.default_grab);
|
|
|
|
free(seat->name);
|
|
|
|
free(seat);
|
2017-12-07 01:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_seat *seat =
|
|
|
|
wl_container_of(listener, seat, display_destroy);
|
|
|
|
wlr_seat_destroy(seat);
|
|
|
|
}
|
|
|
|
|
2017-08-16 14:50:43 +02:00
|
|
|
struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
|
|
|
|
struct wlr_seat *wlr_seat = calloc(1, sizeof(struct wlr_seat));
|
|
|
|
if (!wlr_seat) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-09-20 13:32:28 +02:00
|
|
|
|
2017-11-12 23:04:56 +01:00
|
|
|
// pointer state
|
2017-10-30 13:44:39 +01:00
|
|
|
wlr_seat->pointer_state.seat = wlr_seat;
|
2017-09-25 14:47:00 +02:00
|
|
|
wl_list_init(&wlr_seat->pointer_state.surface_destroy.link);
|
|
|
|
wl_list_init(&wlr_seat->pointer_state.resource_destroy.link);
|
2017-09-22 22:07:00 +02:00
|
|
|
|
2017-10-07 17:02:11 +02:00
|
|
|
struct wlr_seat_pointer_grab *pointer_grab =
|
2017-10-05 19:28:26 +02:00
|
|
|
calloc(1, sizeof(struct wlr_seat_pointer_grab));
|
2017-10-07 17:02:11 +02:00
|
|
|
if (!pointer_grab) {
|
|
|
|
free(wlr_seat);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
pointer_grab->interface = &default_pointer_grab_impl;
|
|
|
|
pointer_grab->seat = wlr_seat;
|
|
|
|
wlr_seat->pointer_state.default_grab = pointer_grab;
|
|
|
|
wlr_seat->pointer_state.grab = pointer_grab;
|
|
|
|
|
2017-11-12 23:04:56 +01:00
|
|
|
// keyboard state
|
2017-10-07 17:02:11 +02:00
|
|
|
struct wlr_seat_keyboard_grab *keyboard_grab =
|
|
|
|
calloc(1, sizeof(struct wlr_seat_keyboard_grab));
|
|
|
|
if (!keyboard_grab) {
|
|
|
|
free(pointer_grab);
|
2017-10-05 19:28:26 +02:00
|
|
|
free(wlr_seat);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-10-07 17:02:11 +02:00
|
|
|
keyboard_grab->interface = &default_keyboard_grab_impl;
|
|
|
|
keyboard_grab->seat = wlr_seat;
|
|
|
|
wlr_seat->keyboard_state.default_grab = keyboard_grab;
|
|
|
|
wlr_seat->keyboard_state.grab = keyboard_grab;
|
2017-10-05 19:28:26 +02:00
|
|
|
|
2017-10-30 13:44:39 +01:00
|
|
|
wlr_seat->keyboard_state.seat = wlr_seat;
|
2017-09-25 14:47:00 +02:00
|
|
|
wl_list_init(&wlr_seat->keyboard_state.resource_destroy.link);
|
2017-09-22 22:07:00 +02:00
|
|
|
wl_list_init(
|
2017-09-25 14:47:00 +02:00
|
|
|
&wlr_seat->keyboard_state.surface_destroy.link);
|
2017-09-20 13:32:28 +02:00
|
|
|
|
2017-11-12 17:43:50 +01:00
|
|
|
// touch state
|
2017-11-12 23:04:56 +01:00
|
|
|
struct wlr_seat_touch_grab *touch_grab =
|
|
|
|
calloc(1, sizeof(struct wlr_seat_touch_grab));
|
|
|
|
if (!touch_grab) {
|
|
|
|
free(pointer_grab);
|
|
|
|
free(keyboard_grab);
|
|
|
|
free(wlr_seat);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
touch_grab->interface = &default_touch_grab_impl;
|
2017-11-13 21:41:48 +01:00
|
|
|
touch_grab->seat = wlr_seat;
|
2017-11-12 23:04:56 +01:00
|
|
|
wlr_seat->touch_state.default_grab = touch_grab;
|
|
|
|
wlr_seat->touch_state.grab = touch_grab;
|
|
|
|
|
2017-11-12 17:43:50 +01:00
|
|
|
wlr_seat->touch_state.seat = wlr_seat;
|
|
|
|
wl_list_init(&wlr_seat->touch_state.touch_points);
|
|
|
|
|
2017-08-16 14:50:43 +02:00
|
|
|
struct wl_global *wl_global = wl_global_create(display,
|
2017-08-17 12:55:59 +02:00
|
|
|
&wl_seat_interface, 6, wlr_seat, wl_seat_bind);
|
2017-08-16 14:50:43 +02:00
|
|
|
if (!wl_global) {
|
|
|
|
free(wlr_seat);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
wlr_seat->wl_global = wl_global;
|
2017-09-20 13:32:28 +02:00
|
|
|
wlr_seat->display = display;
|
2017-08-16 14:50:43 +02:00
|
|
|
wlr_seat->name = strdup(name);
|
2017-10-30 13:37:54 +01:00
|
|
|
wl_list_init(&wlr_seat->clients);
|
2017-11-19 15:33:55 +01:00
|
|
|
wl_list_init(&wlr_seat->drag_icons);
|
2017-09-20 13:32:28 +02:00
|
|
|
|
2017-10-05 13:11:51 +02:00
|
|
|
wl_signal_init(&wlr_seat->events.request_set_cursor);
|
2017-10-16 11:07:09 +02:00
|
|
|
wl_signal_init(&wlr_seat->events.selection);
|
2017-12-22 22:22:29 +01:00
|
|
|
wl_signal_init(&wlr_seat->events.primary_selection);
|
2017-09-20 13:32:28 +02:00
|
|
|
|
2017-10-06 13:32:59 +02:00
|
|
|
wl_signal_init(&wlr_seat->events.pointer_grab_begin);
|
|
|
|
wl_signal_init(&wlr_seat->events.pointer_grab_end);
|
|
|
|
|
2017-10-07 17:02:11 +02:00
|
|
|
wl_signal_init(&wlr_seat->events.keyboard_grab_begin);
|
|
|
|
wl_signal_init(&wlr_seat->events.keyboard_grab_end);
|
|
|
|
|
2017-11-12 23:34:32 +01:00
|
|
|
wl_signal_init(&wlr_seat->events.touch_grab_begin);
|
|
|
|
wl_signal_init(&wlr_seat->events.touch_grab_end);
|
|
|
|
|
2017-12-29 17:55:03 +01:00
|
|
|
wl_signal_init(&wlr_seat->events.destroy);
|
|
|
|
|
2017-12-07 01:02:07 +01:00
|
|
|
wlr_seat->display_destroy.notify = handle_display_destroy;
|
|
|
|
wl_display_add_destroy_listener(display, &wlr_seat->display_destroy);
|
2017-08-18 19:58:36 +02:00
|
|
|
|
2017-12-07 01:02:07 +01:00
|
|
|
return wlr_seat;
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *wlr_seat_client_for_wl_client(struct wlr_seat *wlr_seat,
|
|
|
|
struct wl_client *wl_client) {
|
2017-08-16 14:50:43 +02:00
|
|
|
assert(wlr_seat);
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *seat_client;
|
|
|
|
wl_list_for_each(seat_client, &wlr_seat->clients, link) {
|
|
|
|
if (seat_client->client == wl_client) {
|
|
|
|
return seat_client;
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_set_capabilities(struct wlr_seat *wlr_seat,
|
|
|
|
uint32_t capabilities) {
|
|
|
|
wlr_seat->capabilities = capabilities;
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *client;
|
|
|
|
wl_list_for_each(client, &wlr_seat->clients, link) {
|
|
|
|
wl_seat_send_capabilities(client->wl_resource, capabilities);
|
2017-08-17 12:55:59 +02:00
|
|
|
}
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_set_name(struct wlr_seat *wlr_seat, const char *name) {
|
|
|
|
free(wlr_seat->name);
|
|
|
|
wlr_seat->name = strdup(name);
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *client;
|
|
|
|
wl_list_for_each(client, &wlr_seat->clients, link) {
|
|
|
|
wl_seat_send_name(client->wl_resource, name);
|
2017-08-17 12:55:59 +02:00
|
|
|
}
|
2017-08-16 14:50:43 +02:00
|
|
|
}
|
2017-09-20 13:32:28 +02:00
|
|
|
|
|
|
|
bool wlr_seat_pointer_surface_has_focus(struct wlr_seat *wlr_seat,
|
|
|
|
struct wlr_surface *surface) {
|
|
|
|
return surface == wlr_seat->pointer_state.focused_surface;
|
|
|
|
}
|
|
|
|
|
2017-09-25 14:47:00 +02:00
|
|
|
static void pointer_surface_destroy_notify(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_seat_pointer_state *state = wl_container_of(
|
|
|
|
listener, state, surface_destroy);
|
2017-10-05 21:02:18 +02:00
|
|
|
wl_list_remove(&state->surface_destroy.link);
|
|
|
|
wl_list_init(&state->surface_destroy.link);
|
2017-10-30 13:44:39 +01:00
|
|
|
wlr_seat_pointer_clear_focus(state->seat);
|
2017-09-20 13:32:28 +02:00
|
|
|
}
|
|
|
|
|
2017-09-25 14:47:00 +02:00
|
|
|
static void pointer_resource_destroy_notify(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_seat_pointer_state *state = wl_container_of(
|
|
|
|
listener, state, resource_destroy);
|
2017-10-05 21:02:18 +02:00
|
|
|
wl_list_remove(&state->resource_destroy.link);
|
|
|
|
wl_list_init(&state->resource_destroy.link);
|
2017-10-30 13:44:39 +01:00
|
|
|
wlr_seat_pointer_clear_focus(state->seat);
|
2017-09-20 13:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_pointer_enter(struct wlr_seat *wlr_seat,
|
2017-09-21 17:38:04 +02:00
|
|
|
struct wlr_surface *surface, double sx, double sy) {
|
2017-09-20 13:32:28 +02:00
|
|
|
assert(wlr_seat);
|
|
|
|
|
|
|
|
if (wlr_seat->pointer_state.focused_surface == surface) {
|
|
|
|
// this surface already got an enter notify
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *client = NULL;
|
2017-09-20 13:32:28 +02:00
|
|
|
if (surface) {
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wl_client *wl_client = wl_resource_get_client(surface->resource);
|
|
|
|
client = wlr_seat_client_for_wl_client(wlr_seat, wl_client);
|
2017-09-20 13:32:28 +02:00
|
|
|
}
|
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *focused_client =
|
|
|
|
wlr_seat->pointer_state.focused_client;
|
2017-09-20 13:32:28 +02:00
|
|
|
struct wlr_surface *focused_surface =
|
|
|
|
wlr_seat->pointer_state.focused_surface;
|
|
|
|
|
|
|
|
// leave the previously entered surface
|
2017-12-16 13:53:39 +01:00
|
|
|
if (focused_client != NULL && focused_surface != NULL) {
|
2017-09-20 13:32:28 +02:00
|
|
|
uint32_t serial = wl_display_next_serial(wlr_seat->display);
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &focused_client->pointers) {
|
|
|
|
wl_pointer_send_leave(resource, serial, focused_surface->resource);
|
|
|
|
pointer_send_frame(resource);
|
|
|
|
}
|
2017-09-20 13:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// enter the current surface
|
2017-12-16 17:17:07 +01:00
|
|
|
if (client != NULL && surface != NULL) {
|
2017-09-20 13:32:28 +02:00
|
|
|
uint32_t serial = wl_display_next_serial(wlr_seat->display);
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &client->pointers) {
|
|
|
|
wl_pointer_send_enter(resource, serial, surface->resource,
|
|
|
|
wl_fixed_from_double(sx), wl_fixed_from_double(sy));
|
|
|
|
pointer_send_frame(resource);
|
|
|
|
}
|
2017-09-20 13:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// reinitialize the focus destroy events
|
2017-09-25 14:47:00 +02:00
|
|
|
wl_list_remove(&wlr_seat->pointer_state.surface_destroy.link);
|
|
|
|
wl_list_init(&wlr_seat->pointer_state.surface_destroy.link);
|
|
|
|
wl_list_remove(&wlr_seat->pointer_state.resource_destroy.link);
|
|
|
|
wl_list_init(&wlr_seat->pointer_state.resource_destroy.link);
|
2017-12-16 17:17:07 +01:00
|
|
|
if (surface != NULL) {
|
2017-10-08 19:12:28 +02:00
|
|
|
wl_signal_add(&surface->events.destroy,
|
2017-09-25 14:47:00 +02:00
|
|
|
&wlr_seat->pointer_state.surface_destroy);
|
2017-09-20 13:32:28 +02:00
|
|
|
wl_resource_add_destroy_listener(surface->resource,
|
2017-09-25 14:47:00 +02:00
|
|
|
&wlr_seat->pointer_state.resource_destroy);
|
|
|
|
wlr_seat->pointer_state.resource_destroy.notify =
|
|
|
|
pointer_resource_destroy_notify;
|
|
|
|
wlr_seat->pointer_state.surface_destroy.notify =
|
|
|
|
pointer_surface_destroy_notify;
|
2017-09-20 13:32:28 +02:00
|
|
|
}
|
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
wlr_seat->pointer_state.focused_client = client;
|
2017-09-20 13:32:28 +02:00
|
|
|
wlr_seat->pointer_state.focused_surface = surface;
|
|
|
|
|
|
|
|
// TODO: send focus change event
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_pointer_clear_focus(struct wlr_seat *wlr_seat) {
|
|
|
|
wlr_seat_pointer_enter(wlr_seat, NULL, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time,
|
2017-09-21 17:38:04 +02:00
|
|
|
double sx, double sy) {
|
2017-12-16 17:17:07 +01:00
|
|
|
struct wlr_seat_client *client = wlr_seat->pointer_state.focused_client;
|
|
|
|
if (client == NULL) {
|
2017-09-20 13:32:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
2017-12-16 17:17:07 +01:00
|
|
|
wl_resource_for_each(resource, &client->pointers) {
|
2017-12-16 13:53:39 +01:00
|
|
|
wl_pointer_send_motion(resource, time, wl_fixed_from_double(sx),
|
|
|
|
wl_fixed_from_double(sy));
|
|
|
|
pointer_send_frame(resource);
|
|
|
|
}
|
2017-09-20 13:32:28 +02:00
|
|
|
}
|
|
|
|
|
2017-09-22 17:11:11 +02:00
|
|
|
uint32_t wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time,
|
2017-09-22 00:30:04 +02:00
|
|
|
uint32_t button, uint32_t state) {
|
2017-12-16 17:17:07 +01:00
|
|
|
struct wlr_seat_client *client = wlr_seat->pointer_state.focused_client;
|
|
|
|
if (client == NULL) {
|
2017-09-22 17:11:11 +02:00
|
|
|
return 0;
|
2017-09-20 13:32:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t serial = wl_display_next_serial(wlr_seat->display);
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
2017-12-16 17:17:07 +01:00
|
|
|
wl_resource_for_each(resource, &client->pointers) {
|
2017-12-16 13:53:39 +01:00
|
|
|
wl_pointer_send_button(resource, serial, time, button, state);
|
|
|
|
pointer_send_frame(resource);
|
|
|
|
}
|
2017-09-22 17:11:11 +02:00
|
|
|
return serial;
|
2017-09-20 13:32:28 +02:00
|
|
|
}
|
2017-09-22 16:30:09 +02:00
|
|
|
|
|
|
|
void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
|
|
|
|
enum wlr_axis_orientation orientation, double value) {
|
2017-12-16 17:17:07 +01:00
|
|
|
struct wlr_seat_client *client = wlr_seat->pointer_state.focused_client;
|
|
|
|
if (client == NULL) {
|
2017-09-22 16:30:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
2017-12-16 17:17:07 +01:00
|
|
|
wl_resource_for_each(resource, &client->pointers) {
|
2017-12-16 13:53:39 +01:00
|
|
|
if (value) {
|
|
|
|
wl_pointer_send_axis(resource, time, orientation,
|
|
|
|
wl_fixed_from_double(value));
|
|
|
|
} else if (wl_resource_get_version(resource) >=
|
|
|
|
WL_POINTER_AXIS_STOP_SINCE_VERSION) {
|
|
|
|
wl_pointer_send_axis_stop(resource, time, orientation);
|
|
|
|
}
|
|
|
|
pointer_send_frame(resource);
|
2017-09-22 16:30:09 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-24 20:12:56 +02:00
|
|
|
|
2017-10-05 19:28:26 +02:00
|
|
|
void wlr_seat_pointer_start_grab(struct wlr_seat *wlr_seat,
|
|
|
|
struct wlr_seat_pointer_grab *grab) {
|
2017-11-13 21:41:48 +01:00
|
|
|
assert(wlr_seat);
|
2017-10-05 19:28:26 +02:00
|
|
|
grab->seat = wlr_seat;
|
2017-11-13 21:41:48 +01:00
|
|
|
assert(grab->seat);
|
2017-10-05 19:28:26 +02:00
|
|
|
wlr_seat->pointer_state.grab = grab;
|
2017-10-06 13:32:59 +02:00
|
|
|
|
|
|
|
wl_signal_emit(&wlr_seat->events.pointer_grab_begin, grab);
|
2017-10-05 19:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_pointer_end_grab(struct wlr_seat *wlr_seat) {
|
2017-10-06 13:32:59 +02:00
|
|
|
struct wlr_seat_pointer_grab *grab = wlr_seat->pointer_state.grab;
|
2017-10-09 12:16:51 +02:00
|
|
|
if (grab != wlr_seat->pointer_state.default_grab) {
|
|
|
|
wlr_seat->pointer_state.grab = wlr_seat->pointer_state.default_grab;
|
2017-10-12 19:33:42 +02:00
|
|
|
wl_signal_emit(&wlr_seat->events.pointer_grab_end, grab);
|
2017-11-01 13:05:02 +01:00
|
|
|
if (grab->interface->cancel) {
|
|
|
|
grab->interface->cancel(grab);
|
|
|
|
}
|
2017-10-09 12:16:51 +02:00
|
|
|
}
|
2017-10-05 19:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_pointer_notify_enter(struct wlr_seat *wlr_seat,
|
|
|
|
struct wlr_surface *surface, double sx, double sy) {
|
|
|
|
struct wlr_seat_pointer_grab *grab = wlr_seat->pointer_state.grab;
|
|
|
|
grab->interface->enter(grab, surface, sx, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_pointer_notify_motion(struct wlr_seat *wlr_seat, uint32_t time,
|
|
|
|
double sx, double sy) {
|
2017-11-12 15:55:28 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &wlr_seat->last_event);
|
2017-10-05 19:28:26 +02:00
|
|
|
struct wlr_seat_pointer_grab *grab = wlr_seat->pointer_state.grab;
|
|
|
|
grab->interface->motion(grab, time, sx, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t wlr_seat_pointer_notify_button(struct wlr_seat *wlr_seat,
|
|
|
|
uint32_t time, uint32_t button, uint32_t state) {
|
2017-11-12 15:55:28 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &wlr_seat->last_event);
|
2017-10-16 12:31:53 +02:00
|
|
|
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
|
|
|
if (wlr_seat->pointer_state.button_count == 0) {
|
|
|
|
wlr_seat->pointer_state.grab_button = button;
|
|
|
|
wlr_seat->pointer_state.grab_time = time;
|
|
|
|
}
|
|
|
|
wlr_seat->pointer_state.button_count++;
|
|
|
|
} else {
|
|
|
|
wlr_seat->pointer_state.button_count--;
|
|
|
|
}
|
|
|
|
|
2017-10-05 19:28:26 +02:00
|
|
|
struct wlr_seat_pointer_grab *grab = wlr_seat->pointer_state.grab;
|
2017-10-16 12:31:53 +02:00
|
|
|
uint32_t serial = grab->interface->button(grab, time, button, state);
|
|
|
|
|
2017-11-16 23:34:38 +01:00
|
|
|
if (serial && wlr_seat->pointer_state.button_count == 1) {
|
2017-10-16 12:31:53 +02:00
|
|
|
wlr_seat->pointer_state.grab_serial = serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
return serial;
|
2017-10-05 19:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_pointer_notify_axis(struct wlr_seat *wlr_seat, uint32_t time,
|
|
|
|
enum wlr_axis_orientation orientation, double value) {
|
2017-11-12 15:55:28 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &wlr_seat->last_event);
|
2017-10-05 19:28:26 +02:00
|
|
|
struct wlr_seat_pointer_grab *grab = wlr_seat->pointer_state.grab;
|
|
|
|
grab->interface->axis(grab, time, orientation, value);
|
|
|
|
}
|
|
|
|
|
2017-11-15 12:43:30 +01:00
|
|
|
bool wlr_seat_pointer_has_grab(struct wlr_seat *seat) {
|
|
|
|
return seat->pointer_state.grab->interface != &default_pointer_grab_impl;
|
|
|
|
}
|
|
|
|
|
2017-10-07 17:02:11 +02:00
|
|
|
void wlr_seat_keyboard_send_key(struct wlr_seat *wlr_seat, uint32_t time,
|
|
|
|
uint32_t key, uint32_t state) {
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *client = wlr_seat->keyboard_state.focused_client;
|
2017-12-16 13:53:39 +01:00
|
|
|
if (!client) {
|
2017-10-07 17:02:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t serial = wl_display_next_serial(wlr_seat->display);
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &client->keyboards) {
|
|
|
|
wl_keyboard_send_key(resource, serial, time, key, state);
|
|
|
|
}
|
2017-10-07 17:02:11 +02:00
|
|
|
}
|
|
|
|
|
2017-10-23 14:59:55 +02:00
|
|
|
static void handle_keyboard_keymap(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_seat_keyboard_state *state =
|
|
|
|
wl_container_of(listener, state, keyboard_keymap);
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *client;
|
2017-12-18 15:59:59 +01:00
|
|
|
struct wlr_keyboard *keyboard = data;
|
|
|
|
if (keyboard == state->keyboard) {
|
|
|
|
wl_list_for_each(client, &state->seat->clients, link) {
|
|
|
|
seat_client_send_keymap(client, state->keyboard);
|
|
|
|
}
|
2017-09-24 20:12:56 +02:00
|
|
|
}
|
2017-10-23 14:59:55 +02:00
|
|
|
}
|
2017-10-03 14:03:26 +02:00
|
|
|
|
2017-12-08 17:03:05 +01:00
|
|
|
static void handle_keyboard_repeat_info(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_seat_keyboard_state *state =
|
|
|
|
wl_container_of(listener, state, keyboard_repeat_info);
|
|
|
|
struct wlr_seat_client *client;
|
|
|
|
wl_list_for_each(client, &state->seat->clients, link) {
|
|
|
|
seat_client_send_repeat_info(client, state->keyboard);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 14:59:55 +02:00
|
|
|
static void handle_keyboard_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_seat_keyboard_state *state =
|
|
|
|
wl_container_of(listener, state, keyboard_destroy);
|
|
|
|
state->keyboard = NULL;
|
2017-10-03 14:03:26 +02:00
|
|
|
}
|
|
|
|
|
2017-10-23 14:59:55 +02:00
|
|
|
void wlr_seat_set_keyboard(struct wlr_seat *seat,
|
|
|
|
struct wlr_input_device *device) {
|
2017-10-24 13:24:48 +02:00
|
|
|
// TODO call this on device key event before the event reaches the
|
|
|
|
// compositor and set a pending keyboard and then send the new keyboard
|
|
|
|
// state on the next keyboard notify event.
|
2017-12-18 15:59:59 +01:00
|
|
|
struct wlr_keyboard *keyboard = (device ? device->keyboard : NULL);
|
|
|
|
if (seat->keyboard_state.keyboard == keyboard) {
|
2017-10-03 14:03:26 +02:00
|
|
|
return;
|
2017-09-24 20:12:56 +02:00
|
|
|
}
|
|
|
|
|
2017-10-23 14:59:55 +02:00
|
|
|
if (seat->keyboard_state.keyboard) {
|
|
|
|
wl_list_remove(&seat->keyboard_state.keyboard_destroy.link);
|
|
|
|
wl_list_remove(&seat->keyboard_state.keyboard_keymap.link);
|
2017-12-08 17:03:05 +01:00
|
|
|
wl_list_remove(&seat->keyboard_state.keyboard_repeat_info.link);
|
2017-10-23 14:59:55 +02:00
|
|
|
seat->keyboard_state.keyboard = NULL;
|
|
|
|
}
|
2017-10-03 14:03:26 +02:00
|
|
|
|
2017-12-18 15:59:59 +01:00
|
|
|
if (keyboard) {
|
2017-10-23 14:59:55 +02:00
|
|
|
assert(device->type == WLR_INPUT_DEVICE_KEYBOARD);
|
2017-12-08 17:03:05 +01:00
|
|
|
|
2017-10-23 14:59:55 +02:00
|
|
|
wl_signal_add(&device->events.destroy,
|
|
|
|
&seat->keyboard_state.keyboard_destroy);
|
|
|
|
seat->keyboard_state.keyboard_destroy.notify = handle_keyboard_destroy;
|
|
|
|
wl_signal_add(&device->keyboard->events.keymap,
|
|
|
|
&seat->keyboard_state.keyboard_keymap);
|
|
|
|
seat->keyboard_state.keyboard_keymap.notify = handle_keyboard_keymap;
|
2017-12-08 17:03:05 +01:00
|
|
|
wl_signal_add(&device->keyboard->events.repeat_info,
|
|
|
|
&seat->keyboard_state.keyboard_repeat_info);
|
|
|
|
seat->keyboard_state.keyboard_repeat_info.notify =
|
|
|
|
handle_keyboard_repeat_info;
|
2017-10-07 17:02:11 +02:00
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *client;
|
|
|
|
wl_list_for_each(client, &seat->clients, link) {
|
|
|
|
seat_client_send_keymap(client, device->keyboard);
|
2017-12-08 17:03:05 +01:00
|
|
|
seat_client_send_repeat_info(client, device->keyboard);
|
2017-09-24 20:12:56 +02:00
|
|
|
}
|
2017-10-23 14:59:55 +02:00
|
|
|
|
2017-09-24 20:12:56 +02:00
|
|
|
}
|
2017-12-18 15:59:59 +01:00
|
|
|
|
|
|
|
seat->keyboard_state.keyboard = keyboard;
|
2018-01-05 22:20:46 +01:00
|
|
|
wlr_seat_keyboard_send_modifiers(seat);
|
2017-09-24 20:12:56 +02:00
|
|
|
}
|
2017-09-25 14:29:35 +02:00
|
|
|
|
2017-10-07 17:02:11 +02:00
|
|
|
void wlr_seat_keyboard_start_grab(struct wlr_seat *wlr_seat,
|
|
|
|
struct wlr_seat_keyboard_grab *grab) {
|
|
|
|
grab->seat = wlr_seat;
|
|
|
|
wlr_seat->keyboard_state.grab = grab;
|
|
|
|
|
|
|
|
wl_signal_emit(&wlr_seat->events.keyboard_grab_begin, grab);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_keyboard_end_grab(struct wlr_seat *wlr_seat) {
|
|
|
|
struct wlr_seat_keyboard_grab *grab = wlr_seat->keyboard_state.grab;
|
|
|
|
|
2017-10-16 13:29:18 +02:00
|
|
|
if (grab != wlr_seat->keyboard_state.default_grab) {
|
|
|
|
wlr_seat->keyboard_state.grab = wlr_seat->keyboard_state.default_grab;
|
|
|
|
wl_signal_emit(&wlr_seat->events.keyboard_grab_end, grab);
|
2017-11-01 13:05:02 +01:00
|
|
|
if (grab->interface->cancel) {
|
|
|
|
grab->interface->cancel(grab);
|
|
|
|
}
|
2017-10-16 13:29:18 +02:00
|
|
|
}
|
2017-10-07 17:02:11 +02:00
|
|
|
}
|
|
|
|
|
2017-09-25 14:29:35 +02:00
|
|
|
static void keyboard_surface_destroy_notify(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_seat_keyboard_state *state = wl_container_of(
|
|
|
|
listener, state, surface_destroy);
|
2017-10-05 21:02:18 +02:00
|
|
|
wl_list_remove(&state->surface_destroy.link);
|
|
|
|
wl_list_init(&state->surface_destroy.link);
|
2017-10-30 13:44:39 +01:00
|
|
|
wlr_seat_keyboard_clear_focus(state->seat);
|
2017-09-22 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2017-09-25 14:29:35 +02:00
|
|
|
static void keyboard_resource_destroy_notify(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_seat_keyboard_state *state = wl_container_of(
|
|
|
|
listener, state, resource_destroy);
|
2017-10-05 21:02:18 +02:00
|
|
|
wl_list_remove(&state->resource_destroy.link);
|
|
|
|
wl_list_init(&state->resource_destroy.link);
|
2017-10-30 13:44:39 +01:00
|
|
|
wlr_seat_keyboard_clear_focus(state->seat);
|
2017-09-22 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2017-11-08 19:02:56 +01:00
|
|
|
void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat) {
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *client = seat->keyboard_state.focused_client;
|
2017-12-16 13:53:39 +01:00
|
|
|
if (client == NULL) {
|
2017-10-07 17:02:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-08 19:02:56 +01:00
|
|
|
struct wlr_keyboard *keyboard = seat->keyboard_state.keyboard;
|
2017-12-16 13:53:39 +01:00
|
|
|
if (keyboard == NULL) {
|
2017-11-08 19:02:56 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-10-07 17:02:11 +02:00
|
|
|
|
2017-11-08 19:02:56 +01:00
|
|
|
uint32_t serial = wl_display_next_serial(seat->display);
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &client->keyboards) {
|
|
|
|
wl_keyboard_send_modifiers(resource, serial,
|
|
|
|
keyboard->modifiers.depressed, keyboard->modifiers.latched,
|
|
|
|
keyboard->modifiers.locked, keyboard->modifiers.group);
|
|
|
|
}
|
2017-10-07 17:02:11 +02:00
|
|
|
}
|
|
|
|
|
2017-11-08 19:02:56 +01:00
|
|
|
void wlr_seat_keyboard_enter(struct wlr_seat *seat,
|
2017-09-25 14:29:35 +02:00
|
|
|
struct wlr_surface *surface) {
|
2017-11-08 19:02:56 +01:00
|
|
|
if (seat->keyboard_state.focused_surface == surface) {
|
2017-09-22 22:07:00 +02:00
|
|
|
// this surface already got an enter notify
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *client = NULL;
|
2017-09-22 22:07:00 +02:00
|
|
|
|
|
|
|
if (surface) {
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wl_client *wl_client = wl_resource_get_client(surface->resource);
|
2017-11-08 19:02:56 +01:00
|
|
|
client = wlr_seat_client_for_wl_client(seat, wl_client);
|
2017-09-22 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
struct wlr_seat_client *focused_client =
|
2017-11-08 19:02:56 +01:00
|
|
|
seat->keyboard_state.focused_client;
|
2017-09-22 22:07:00 +02:00
|
|
|
struct wlr_surface *focused_surface =
|
2017-11-08 19:02:56 +01:00
|
|
|
seat->keyboard_state.focused_surface;
|
2017-09-22 22:07:00 +02:00
|
|
|
|
|
|
|
// leave the previously entered surface
|
2017-12-16 13:53:39 +01:00
|
|
|
if (focused_client != NULL && focused_surface != NULL) {
|
2017-11-08 19:02:56 +01:00
|
|
|
uint32_t serial = wl_display_next_serial(seat->display);
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &focused_client->keyboards) {
|
|
|
|
wl_keyboard_send_leave(resource, serial, focused_surface->resource);
|
|
|
|
}
|
2017-09-22 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// enter the current surface
|
2017-12-16 13:53:39 +01:00
|
|
|
if (client != NULL && seat->keyboard_state.keyboard != NULL) {
|
2017-11-08 19:02:56 +01:00
|
|
|
struct wlr_keyboard *keyboard = seat->keyboard_state.keyboard;
|
2017-11-05 17:09:00 +01:00
|
|
|
|
2017-09-25 14:29:35 +02:00
|
|
|
struct wl_array keys;
|
|
|
|
wl_array_init(&keys);
|
2017-12-28 00:58:43 +01:00
|
|
|
for (size_t i = 0; i < keyboard->num_keycodes; ++i) {
|
|
|
|
uint32_t *p = wl_array_add(&keys, sizeof(uint32_t));
|
2017-12-28 09:44:35 +01:00
|
|
|
if (!p) {
|
|
|
|
wlr_log(L_ERROR, "Cannot allocate memory, skipping keycode: %d\n",
|
|
|
|
keyboard->keycodes[i]);
|
|
|
|
continue;
|
|
|
|
}
|
2017-12-28 00:58:43 +01:00
|
|
|
*p = keyboard->keycodes[i];
|
2017-11-05 17:09:00 +01:00
|
|
|
}
|
2017-11-08 19:02:56 +01:00
|
|
|
uint32_t serial = wl_display_next_serial(seat->display);
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &client->keyboards) {
|
|
|
|
wl_keyboard_send_enter(resource, serial, surface->resource, &keys);
|
|
|
|
}
|
2017-11-05 17:09:00 +01:00
|
|
|
wl_array_release(&keys);
|
|
|
|
|
2017-10-30 13:37:54 +01:00
|
|
|
wlr_seat_client_send_selection(client);
|
2017-12-23 00:03:15 +01:00
|
|
|
wlr_seat_client_send_primary_selection(client);
|
2017-09-22 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// reinitialize the focus destroy events
|
2017-11-08 19:02:56 +01:00
|
|
|
wl_list_remove(&seat->keyboard_state.surface_destroy.link);
|
|
|
|
wl_list_init(&seat->keyboard_state.surface_destroy.link);
|
|
|
|
wl_list_remove(&seat->keyboard_state.resource_destroy.link);
|
|
|
|
wl_list_init(&seat->keyboard_state.resource_destroy.link);
|
2017-09-22 22:07:00 +02:00
|
|
|
if (surface) {
|
2017-10-08 19:12:28 +02:00
|
|
|
wl_signal_add(&surface->events.destroy,
|
2017-11-08 19:02:56 +01:00
|
|
|
&seat->keyboard_state.surface_destroy);
|
2017-09-22 22:07:00 +02:00
|
|
|
wl_resource_add_destroy_listener(surface->resource,
|
2017-11-08 19:02:56 +01:00
|
|
|
&seat->keyboard_state.resource_destroy);
|
|
|
|
seat->keyboard_state.resource_destroy.notify =
|
2017-09-25 14:29:35 +02:00
|
|
|
keyboard_resource_destroy_notify;
|
2017-11-08 19:02:56 +01:00
|
|
|
seat->keyboard_state.surface_destroy.notify =
|
2017-09-25 14:29:35 +02:00
|
|
|
keyboard_surface_destroy_notify;
|
2017-09-22 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2017-11-08 19:02:56 +01:00
|
|
|
seat->keyboard_state.focused_client = client;
|
|
|
|
seat->keyboard_state.focused_surface = surface;
|
2017-12-10 08:06:43 +01:00
|
|
|
|
2017-12-16 13:53:39 +01:00
|
|
|
if (client != NULL && seat->keyboard_state.keyboard != NULL) {
|
2017-12-10 08:06:43 +01:00
|
|
|
// tell new client about any modifier change last,
|
|
|
|
// as it targets seat->keyboard_state.focused_client
|
|
|
|
wlr_seat_keyboard_send_modifiers(seat);
|
|
|
|
}
|
2017-09-22 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2017-11-08 19:02:56 +01:00
|
|
|
void wlr_seat_keyboard_notify_enter(struct wlr_seat *seat, struct
|
2017-10-07 17:02:11 +02:00
|
|
|
wlr_surface *surface) {
|
2017-11-08 19:02:56 +01:00
|
|
|
struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab;
|
2017-10-07 17:02:11 +02:00
|
|
|
grab->interface->enter(grab, surface);
|
|
|
|
}
|
|
|
|
|
2017-11-08 19:02:56 +01:00
|
|
|
void wlr_seat_keyboard_clear_focus(struct wlr_seat *seat) {
|
2017-09-23 20:40:56 +02:00
|
|
|
struct wl_array keys;
|
|
|
|
wl_array_init(&keys);
|
2017-11-08 19:02:56 +01:00
|
|
|
wlr_seat_keyboard_enter(seat, NULL);
|
2017-09-23 19:21:57 +02:00
|
|
|
}
|
2017-10-23 14:59:55 +02:00
|
|
|
|
2017-11-15 12:43:30 +01:00
|
|
|
bool wlr_seat_keyboard_has_grab(struct wlr_seat *seat) {
|
|
|
|
return seat->keyboard_state.grab->interface != &default_keyboard_grab_impl;
|
|
|
|
}
|
|
|
|
|
2017-11-08 19:02:56 +01:00
|
|
|
void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat) {
|
2017-11-12 15:55:28 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &seat->last_event);
|
2017-10-23 14:59:55 +02:00
|
|
|
struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab;
|
2017-11-08 19:02:56 +01:00
|
|
|
grab->interface->modifiers(grab);
|
2017-10-23 14:59:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_keyboard_notify_key(struct wlr_seat *seat, uint32_t time,
|
|
|
|
uint32_t key, uint32_t state) {
|
2017-11-12 15:55:28 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &seat->last_event);
|
2017-10-23 14:59:55 +02:00
|
|
|
struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab;
|
|
|
|
grab->interface->key(grab, time, key, state);
|
|
|
|
}
|
2017-11-12 17:43:50 +01:00
|
|
|
|
2017-11-12 23:34:32 +01:00
|
|
|
void wlr_seat_touch_start_grab(struct wlr_seat *wlr_seat,
|
|
|
|
struct wlr_seat_touch_grab *grab) {
|
|
|
|
grab->seat = wlr_seat;
|
|
|
|
wlr_seat->touch_state.grab = grab;
|
|
|
|
|
|
|
|
wl_signal_emit(&wlr_seat->events.touch_grab_begin, grab);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_touch_end_grab(struct wlr_seat *wlr_seat) {
|
|
|
|
struct wlr_seat_touch_grab *grab = wlr_seat->touch_state.grab;
|
|
|
|
|
|
|
|
if (grab != wlr_seat->touch_state.default_grab) {
|
|
|
|
wlr_seat->touch_state.grab = wlr_seat->touch_state.default_grab;
|
|
|
|
wl_signal_emit(&wlr_seat->events.touch_grab_end, grab);
|
|
|
|
if (grab->interface->cancel) {
|
|
|
|
grab->interface->cancel(grab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 23:20:55 +01:00
|
|
|
static void touch_point_clear_focus(struct wlr_touch_point *point) {
|
|
|
|
if (point->focus_surface) {
|
|
|
|
wl_list_remove(&point->focus_surface_destroy.link);
|
|
|
|
point->focus_client = NULL;
|
|
|
|
point->focus_surface = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:43:50 +01:00
|
|
|
static void touch_point_destroy(struct wlr_touch_point *point) {
|
2017-11-14 01:16:34 +01:00
|
|
|
wl_signal_emit(&point->events.destroy, point);
|
2017-11-16 23:20:55 +01:00
|
|
|
|
|
|
|
touch_point_clear_focus(point);
|
2017-11-12 17:43:50 +01:00
|
|
|
wl_list_remove(&point->surface_destroy.link);
|
|
|
|
wl_list_remove(&point->resource_destroy.link);
|
|
|
|
wl_list_remove(&point->link);
|
|
|
|
free(point);
|
|
|
|
}
|
|
|
|
static void handle_touch_point_resource_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_touch_point *point =
|
|
|
|
wl_container_of(listener, point, resource_destroy);
|
|
|
|
touch_point_destroy(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_touch_point_surface_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_touch_point *point =
|
|
|
|
wl_container_of(listener, point, surface_destroy);
|
|
|
|
touch_point_destroy(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct wlr_touch_point *touch_point_create(
|
|
|
|
struct wlr_seat *seat, int32_t touch_id,
|
|
|
|
struct wlr_surface *surface, double sx, double sy) {
|
|
|
|
struct wl_client *wl_client = wl_resource_get_client(surface->resource);
|
|
|
|
struct wlr_seat_client *client = wlr_seat_client_for_wl_client(seat, wl_client);
|
|
|
|
|
2017-12-16 13:53:39 +01:00
|
|
|
if (client == NULL || wl_list_empty(&client->touches)) {
|
2017-11-12 17:43:50 +01:00
|
|
|
// touch points are not valid without a connected client with touch
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_touch_point *point = calloc(1, sizeof(struct wlr_touch_point));
|
|
|
|
if (!point) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->touch_id = touch_id;
|
|
|
|
point->surface = surface;
|
|
|
|
point->client = client;
|
|
|
|
|
|
|
|
point->sx = sx;
|
|
|
|
point->sy = sy;
|
|
|
|
|
2017-11-14 01:16:34 +01:00
|
|
|
wl_signal_init(&point->events.destroy);
|
|
|
|
|
2017-11-12 17:43:50 +01:00
|
|
|
wl_signal_add(&surface->events.destroy, &point->surface_destroy);
|
|
|
|
point->surface_destroy.notify = handle_touch_point_surface_destroy;
|
|
|
|
wl_resource_add_destroy_listener(surface->resource,
|
|
|
|
&point->resource_destroy);
|
|
|
|
point->resource_destroy.notify = handle_touch_point_resource_destroy;
|
|
|
|
|
|
|
|
wl_list_insert(&seat->touch_state.touch_points, &point->link);
|
|
|
|
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_touch_point *wlr_seat_touch_get_point(
|
|
|
|
struct wlr_seat *seat, int32_t touch_id) {
|
|
|
|
struct wlr_touch_point *point = NULL;
|
|
|
|
wl_list_for_each(point, &seat->touch_state.touch_points, link) {
|
|
|
|
if (point->touch_id == touch_id) {
|
|
|
|
return point;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-16 23:34:38 +01:00
|
|
|
uint32_t wlr_seat_touch_notify_down(struct wlr_seat *seat,
|
2017-11-12 17:43:50 +01:00
|
|
|
struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx,
|
|
|
|
double sy) {
|
2017-11-13 21:41:48 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &seat->last_event);
|
2017-11-12 23:04:56 +01:00
|
|
|
struct wlr_seat_touch_grab *grab = seat->touch_state.grab;
|
2017-11-13 21:41:48 +01:00
|
|
|
struct wlr_touch_point *point =
|
|
|
|
touch_point_create(seat, touch_id, surface, sx, sy);
|
|
|
|
if (!point) {
|
|
|
|
wlr_log(L_ERROR, "could not create touch point");
|
2017-11-16 23:34:38 +01:00
|
|
|
return 0;
|
2017-11-13 21:41:48 +01:00
|
|
|
}
|
|
|
|
|
2017-11-16 23:34:38 +01:00
|
|
|
uint32_t serial = grab->interface->down(grab, time, point);
|
2017-11-14 01:16:34 +01:00
|
|
|
|
2017-11-16 23:34:38 +01:00
|
|
|
if (serial && wlr_seat_touch_num_points(seat) == 1) {
|
|
|
|
seat->touch_state.grab_serial = serial;
|
2017-11-13 21:41:48 +01:00
|
|
|
seat->touch_state.grab_id = touch_id;
|
2017-11-13 14:22:04 +01:00
|
|
|
}
|
2017-11-16 23:34:38 +01:00
|
|
|
|
|
|
|
return serial;
|
2017-11-12 23:04:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time,
|
|
|
|
int32_t touch_id) {
|
2017-11-13 21:41:48 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &seat->last_event);
|
2017-11-12 23:04:56 +01:00
|
|
|
struct wlr_seat_touch_grab *grab = seat->touch_state.grab;
|
2017-11-13 21:41:48 +01:00
|
|
|
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
|
|
|
|
if (!point) {
|
|
|
|
wlr_log(L_ERROR, "got touch up for unknown touch point");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-14 01:16:34 +01:00
|
|
|
grab->interface->up(grab, time, point);
|
|
|
|
|
2017-11-13 21:41:48 +01:00
|
|
|
touch_point_destroy(point);
|
2017-11-12 23:04:56 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 14:51:37 +01:00
|
|
|
void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time,
|
|
|
|
int32_t touch_id, double sx, double sy) {
|
2017-11-13 21:41:48 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &seat->last_event);
|
2017-11-12 23:04:56 +01:00
|
|
|
struct wlr_seat_touch_grab *grab = seat->touch_state.grab;
|
2017-11-13 21:41:48 +01:00
|
|
|
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
|
|
|
|
if (!point) {
|
|
|
|
wlr_log(L_ERROR, "got touch motion for unknown touch point");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
point->sx = sx;
|
|
|
|
point->sy = sy;
|
|
|
|
|
2017-11-14 01:16:34 +01:00
|
|
|
grab->interface->motion(grab, time, point);
|
2017-11-12 23:04:56 +01:00
|
|
|
}
|
|
|
|
|
2017-11-14 14:51:37 +01:00
|
|
|
static void handle_point_focus_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_touch_point *point =
|
|
|
|
wl_container_of(listener, point, focus_surface_destroy);
|
|
|
|
touch_point_clear_focus(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void touch_point_set_focus(struct wlr_touch_point *point,
|
|
|
|
struct wlr_surface *surface, double sx, double sy) {
|
|
|
|
if (point->focus_surface == surface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
touch_point_clear_focus(point);
|
|
|
|
|
|
|
|
if (surface && surface->resource) {
|
|
|
|
struct wlr_seat_client *client =
|
|
|
|
wlr_seat_client_for_wl_client(point->client->seat,
|
|
|
|
wl_resource_get_client(surface->resource));
|
|
|
|
|
2017-12-16 13:53:39 +01:00
|
|
|
if (client && !wl_list_empty(&client->touches)) {
|
2017-11-14 14:51:37 +01:00
|
|
|
wl_signal_add(&surface->events.destroy, &point->focus_surface_destroy);
|
|
|
|
point->focus_surface_destroy.notify = handle_point_focus_destroy;
|
|
|
|
point->focus_surface = surface;
|
|
|
|
point->focus_client = client;
|
|
|
|
point->sx = sx;
|
|
|
|
point->sy = sy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_touch_point_focus(struct wlr_seat *seat,
|
|
|
|
struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx,
|
|
|
|
double sy) {
|
|
|
|
assert(surface);
|
|
|
|
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
|
|
|
|
if (!point) {
|
|
|
|
wlr_log(L_ERROR, "got touch point focus for unknown touch point");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct wlr_surface *focus = point->focus_surface;
|
|
|
|
touch_point_set_focus(point, surface, sx, sy);
|
|
|
|
|
|
|
|
if (focus != point->focus_surface) {
|
|
|
|
struct wlr_seat_touch_grab *grab = seat->touch_state.grab;
|
|
|
|
grab->interface->enter(grab, time, point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_seat_touch_point_clear_focus(struct wlr_seat *seat, uint32_t time,
|
|
|
|
int32_t touch_id) {
|
|
|
|
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
|
|
|
|
if (!point) {
|
|
|
|
wlr_log(L_ERROR, "got touch point focus for unknown touch point");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-16 23:20:55 +01:00
|
|
|
touch_point_clear_focus(point);
|
2017-11-14 14:51:37 +01:00
|
|
|
}
|
|
|
|
|
2017-11-16 23:34:38 +01:00
|
|
|
uint32_t wlr_seat_touch_send_down(struct wlr_seat *seat,
|
2017-11-12 23:04:56 +01:00
|
|
|
struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx,
|
|
|
|
double sy) {
|
2017-11-13 21:41:48 +01:00
|
|
|
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
|
2017-11-12 17:43:50 +01:00
|
|
|
if (!point) {
|
2017-11-13 21:41:48 +01:00
|
|
|
wlr_log(L_ERROR, "got touch down for unknown touch point");
|
2017-11-16 23:34:38 +01:00
|
|
|
return 0;
|
2017-11-12 17:43:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t serial = wl_display_next_serial(seat->display);
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &point->client->touches) {
|
|
|
|
wl_touch_send_down(resource, serial, time, surface->resource,
|
|
|
|
touch_id, wl_fixed_from_double(sx), wl_fixed_from_double(sy));
|
|
|
|
wl_touch_send_frame(resource);
|
|
|
|
}
|
2017-11-16 23:34:38 +01:00
|
|
|
|
|
|
|
return serial;
|
2017-11-12 17:43:50 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 23:04:56 +01:00
|
|
|
void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time, int32_t touch_id) {
|
2017-11-12 17:43:50 +01:00
|
|
|
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
|
|
|
|
if (!point) {
|
2017-11-12 23:04:56 +01:00
|
|
|
wlr_log(L_ERROR, "got touch up for unknown touch point");
|
2017-11-12 17:43:50 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t serial = wl_display_next_serial(seat->display);
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &point->client->touches) {
|
|
|
|
wl_touch_send_up(resource, serial, time, touch_id);
|
|
|
|
wl_touch_send_frame(resource);
|
|
|
|
}
|
2017-11-12 17:43:50 +01:00
|
|
|
}
|
|
|
|
|
2017-11-12 23:04:56 +01:00
|
|
|
void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, int32_t touch_id,
|
2017-11-12 17:43:50 +01:00
|
|
|
double sx, double sy) {
|
|
|
|
struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id);
|
|
|
|
if (!point) {
|
2017-11-12 23:04:56 +01:00
|
|
|
wlr_log(L_ERROR, "got touch motion for unknown touch point");
|
2017-11-12 17:43:50 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-16 13:53:39 +01:00
|
|
|
struct wl_resource *resource;
|
|
|
|
wl_resource_for_each(resource, &point->client->touches) {
|
|
|
|
wl_touch_send_motion(resource, time, touch_id, wl_fixed_from_double(sx),
|
|
|
|
wl_fixed_from_double(sy));
|
|
|
|
wl_touch_send_frame(resource);
|
|
|
|
}
|
2017-11-12 17:43:50 +01:00
|
|
|
}
|
2017-11-15 12:43:30 +01:00
|
|
|
|
2017-11-15 14:34:35 +01:00
|
|
|
int wlr_seat_touch_num_points(struct wlr_seat *seat) {
|
|
|
|
return wl_list_length(&seat->touch_state.touch_points);
|
|
|
|
}
|
|
|
|
|
2017-11-15 12:43:30 +01:00
|
|
|
bool wlr_seat_touch_has_grab(struct wlr_seat *seat) {
|
|
|
|
return seat->touch_state.grab->interface != &default_touch_grab_impl;
|
|
|
|
}
|
2017-12-27 14:04:01 +01:00
|
|
|
|
|
|
|
bool wlr_seat_validate_grab_serial(struct wlr_seat *seat, uint32_t serial) {
|
|
|
|
return serial == seat->pointer_state.grab_serial ||
|
|
|
|
serial == seat->touch_state.grab_serial;
|
|
|
|
}
|