|
|
|
@ -6,6 +6,11 @@
|
|
|
|
|
#include <wlr/types/wlr_seat.h>
|
|
|
|
|
#include <wlr/util/log.h>
|
|
|
|
|
|
|
|
|
|
static void resource_destroy(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource) {
|
|
|
|
|
wl_resource_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void wl_pointer_set_cursor(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource,
|
|
|
|
|
uint32_t serial,
|
|
|
|
@ -15,29 +20,22 @@ static void wl_pointer_set_cursor(struct wl_client *client,
|
|
|
|
|
wlr_log(L_DEBUG, "TODO: wl_pointer_set_cursor");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct wl_pointer_interface wl_pointer_impl = {
|
|
|
|
|
.set_cursor = wl_pointer_set_cursor,
|
|
|
|
|
.release = resource_destroy
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void wl_pointer_destroy(struct wl_resource *resource) {
|
|
|
|
|
struct wlr_seat_handle *handle = wl_resource_get_user_data(resource);
|
|
|
|
|
if (handle->pointer) {
|
|
|
|
|
wl_resource_destroy(handle->pointer);
|
|
|
|
|
handle->pointer = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void wl_pointer_release(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource) {
|
|
|
|
|
wl_pointer_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wl_pointer_interface wl_pointer_impl = {
|
|
|
|
|
.set_cursor = wl_pointer_set_cursor,
|
|
|
|
|
.release = wl_pointer_release
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void wl_seat_get_pointer(struct wl_client *client,
|
|
|
|
|
struct wl_resource *_handle, uint32_t id) {
|
|
|
|
|
struct wlr_seat_handle *handle = wl_resource_get_user_data(_handle);
|
|
|
|
|
if (!(handle->wlr_seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)) {
|
|
|
|
|
// TODO: Show error?
|
|
|
|
|
if (!(handle->wlr_seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (handle->pointer) {
|
|
|
|
@ -46,19 +44,69 @@ static void wl_seat_get_pointer(struct wl_client *client,
|
|
|
|
|
// the same seat
|
|
|
|
|
wl_resource_destroy(handle->pointer);
|
|
|
|
|
}
|
|
|
|
|
handle->pointer = wl_resource_create(client, &wl_pointer_interface, 5, id);
|
|
|
|
|
handle->pointer = wl_resource_create(client, &wl_pointer_interface,
|
|
|
|
|
wl_resource_get_version(_handle), id);
|
|
|
|
|
wl_resource_set_implementation(handle->pointer, &wl_pointer_impl,
|
|
|
|
|
handle, NULL);
|
|
|
|
|
handle, &wl_pointer_destroy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct wl_keyboard_interface wl_keyboard_impl = {
|
|
|
|
|
.release = resource_destroy
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void wl_keyboard_destroy(struct wl_resource *resource) {
|
|
|
|
|
struct wlr_seat_handle *handle = wl_resource_get_user_data(resource);
|
|
|
|
|
if (handle->keyboard) {
|
|
|
|
|
handle->keyboard = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void wl_seat_get_keyboard(struct wl_client *client,
|
|
|
|
|
struct wl_resource *_handle, uint32_t id) {
|
|
|
|
|
wlr_log(L_DEBUG, "TODO: wl_seat_get_keyboard");
|
|
|
|
|
struct wlr_seat_handle *handle = wl_resource_get_user_data(_handle);
|
|
|
|
|
if (!(handle->wlr_seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (handle->keyboard) {
|
|
|
|
|
// TODO: this is probably a protocol violation but it simplifies our
|
|
|
|
|
// code and it'd be stupid for clients to create several pointers for
|
|
|
|
|
// the same seat
|
|
|
|
|
wl_resource_destroy(handle->keyboard);
|
|
|
|
|
}
|
|
|
|
|
handle->keyboard = wl_resource_create(client, &wl_keyboard_interface,
|
|
|
|
|
wl_resource_get_version(_handle), id);
|
|
|
|
|
wl_resource_set_implementation(handle->keyboard, &wl_keyboard_impl,
|
|
|
|
|
handle, &wl_keyboard_destroy);
|
|
|
|
|
wl_signal_emit(&handle->wlr_seat->events.keyboard_bound, handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct wl_touch_interface wl_touch_impl = {
|
|
|
|
|
.release = resource_destroy
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void wl_touch_destroy(struct wl_resource *resource) {
|
|
|
|
|
struct wlr_seat_handle *handle = wl_resource_get_user_data(resource);
|
|
|
|
|
if (handle->touch) {
|
|
|
|
|
handle->touch = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void wl_seat_get_touch(struct wl_client *client,
|
|
|
|
|
struct wl_resource *_handle, uint32_t id) {
|
|
|
|
|
wlr_log(L_DEBUG, "TODO: wl_seat_get_touch");
|
|
|
|
|
struct wlr_seat_handle *handle = wl_resource_get_user_data(_handle);
|
|
|
|
|
if (!(handle->wlr_seat->capabilities & WL_SEAT_CAPABILITY_TOUCH)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (handle->touch) {
|
|
|
|
|
// TODO: this is probably a protocol violation but it simplifies our
|
|
|
|
|
// code and it'd be stupid for clients to create several pointers for
|
|
|
|
|
// the same seat
|
|
|
|
|
wl_resource_destroy(handle->touch);
|
|
|
|
|
}
|
|
|
|
|
handle->touch = wl_resource_create(client, &wl_touch_interface,
|
|
|
|
|
wl_resource_get_version(_handle), id);
|
|
|
|
|
wl_resource_set_implementation(handle->touch, &wl_touch_impl,
|
|
|
|
|
handle, &wl_touch_destroy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void wl_seat_destroy(struct wl_resource *resource) {
|
|
|
|
@ -67,33 +115,28 @@ static void wl_seat_destroy(struct wl_resource *resource) {
|
|
|
|
|
wl_resource_destroy(handle->pointer);
|
|
|
|
|
}
|
|
|
|
|
if (handle->keyboard) {
|
|
|
|
|
wl_resource_destroy(handle->pointer);
|
|
|
|
|
wl_resource_destroy(handle->keyboard);
|
|
|
|
|
}
|
|
|
|
|
if (handle->touch) {
|
|
|
|
|
wl_resource_destroy(handle->pointer);
|
|
|
|
|
wl_resource_destroy(handle->touch);
|
|
|
|
|
}
|
|
|
|
|
wl_signal_emit(&handle->wlr_seat->events.client_unbound, handle);
|
|
|
|
|
wl_list_remove(&handle->link);
|
|
|
|
|
free(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void wl_seat_release(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource) {
|
|
|
|
|
wl_seat_destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
.release = wl_seat_release
|
|
|
|
|
.release = resource_destroy
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void wl_seat_bind(struct wl_client *wl_client, void *_wlr_seat,
|
|
|
|
|
uint32_t version, uint32_t id) {
|
|
|
|
|
struct wlr_seat *wlr_seat = _wlr_seat;
|
|
|
|
|
assert(wl_client && wlr_seat);
|
|
|
|
|
if (version > 5) {
|
|
|
|
|
if (version > 6) {
|
|
|
|
|
wlr_log(L_ERROR, "Client requested unsupported wl_seat version, disconnecting");
|
|
|
|
|
wl_client_destroy(wl_client);
|
|
|
|
|
return;
|
|
|
|
@ -115,7 +158,7 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
struct wl_global *wl_global = wl_global_create(display,
|
|
|
|
|
&wl_seat_interface, 5, wlr_seat, wl_seat_bind);
|
|
|
|
|
&wl_seat_interface, 6, wlr_seat, wl_seat_bind);
|
|
|
|
|
if (!wl_global) {
|
|
|
|
|
free(wlr_seat);
|
|
|
|
|
return NULL;
|
|
|
|
@ -125,11 +168,18 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
|
|
|
|
|
wl_list_init(&wlr_seat->handles);
|
|
|
|
|
wl_signal_init(&wlr_seat->events.client_bound);
|
|
|
|
|
wl_signal_init(&wlr_seat->events.client_unbound);
|
|
|
|
|
wl_signal_init(&wlr_seat->events.keyboard_bound);
|
|
|
|
|
return wlr_seat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wlr_seat_destroy(struct wlr_seat *wlr_seat) {
|
|
|
|
|
// TODO
|
|
|
|
|
if (!wlr_seat) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_global_destroy(wlr_seat->wl_global);
|
|
|
|
|
free(wlr_seat->name);
|
|
|
|
|
free(wlr_seat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_seat_handle *wlr_seat_handle_for_client(struct wlr_seat *wlr_seat,
|
|
|
|
@ -146,11 +196,18 @@ struct wlr_seat_handle *wlr_seat_handle_for_client(struct wlr_seat *wlr_seat,
|
|
|
|
|
|
|
|
|
|
void wlr_seat_set_capabilities(struct wlr_seat *wlr_seat,
|
|
|
|
|
uint32_t capabilities) {
|
|
|
|
|
// TODO: If e.g. pointer was removed, destroy all client pointer resources
|
|
|
|
|
wlr_seat->capabilities = capabilities;
|
|
|
|
|
struct wlr_seat_handle *handle;
|
|
|
|
|
wl_list_for_each(handle, &wlr_seat->handles, link) {
|
|
|
|
|
wl_seat_send_capabilities(handle->wl_resource, capabilities);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wlr_seat_set_name(struct wlr_seat *wlr_seat, const char *name) {
|
|
|
|
|
free(wlr_seat->name);
|
|
|
|
|
wlr_seat->name = strdup(name);
|
|
|
|
|
struct wlr_seat_handle *handle;
|
|
|
|
|
wl_list_for_each(handle, &wlr_seat->handles, link) {
|
|
|
|
|
wl_seat_send_name(handle->wl_resource, name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|