Merge pull request #359 from acrisci/refactor/seat-handle-to-client

Rename wlr_seat_handle to wlr_seat_client
This commit is contained in:
Drew DeVault 2017-10-30 09:19:38 -04:00 committed by GitHub
commit 2e7cfd21e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 254 additions and 244 deletions

View file

@ -28,7 +28,7 @@ struct wlr_data_offer {
struct wlr_data_source {
struct wl_resource *resource;
struct wlr_data_offer *offer;
struct wlr_seat_handle *seat;
struct wlr_seat_client *seat_client;
struct wl_array mime_types;
bool accepted;
@ -54,8 +54,8 @@ struct wlr_drag {
struct wlr_seat_pointer_grab pointer_grab;
struct wlr_seat_keyboard_grab keyboard_grab;
struct wlr_seat_handle *handle;
struct wlr_seat_handle *focus_handle;
struct wlr_seat_client *seat_client;
struct wlr_seat_client *focus_client;
struct wlr_surface *icon;
struct wlr_surface *focus;
@ -63,7 +63,7 @@ struct wlr_drag {
struct wl_listener icon_destroy;
struct wl_listener source_destroy;
struct wl_listener handle_unbound;
struct wl_listener seat_client_unbound;
};
/**
@ -73,15 +73,13 @@ struct wlr_data_device_manager *wlr_data_device_manager_create(
struct wl_display *display);
/**
* Creates a new wl_data_offer if there is a wl_data_source currently set as the
* seat selection and sends it to the client for this handle, followed by the
* wl_data_device.selection() event.
* If there is no current selection, the wl_data_device.selection() event will
* carry a NULL wl_data_offer.
* If the client does not have a wl_data_device for the seat nothing * will be
* done.
* Creates a new wl_data_offer if there is a wl_data_source currently set as
* the seat selection and sends it to the seat client, followed by the
* wl_data_device.selection() event. If there is no current selection, the
* wl_data_device.selection() event will carry a NULL wl_data_offer. If the
* client does not have a wl_data_device for the seat nothing * will be done.
*/
void wlr_seat_handle_send_selection(struct wlr_seat_handle *handle);
void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client);
void wlr_seat_set_selection(struct wlr_seat *seat,
struct wlr_data_source *source, uint32_t serial);

View file

@ -11,9 +11,10 @@
* to issue input events to that client. The lifetime of these objects is
* managed by wlr_seat; some may be NULL.
*/
struct wlr_seat_handle {
struct wlr_seat_client {
struct wl_resource *wl_resource;
struct wlr_seat *wlr_seat;
struct wl_client *client;
struct wlr_seat *seat;
struct wl_resource *pointer;
struct wl_resource *keyboard;
@ -40,7 +41,8 @@ struct wlr_pointer_grab_interface {
struct wlr_seat_keyboard_grab;
struct wlr_keyboard_grab_interface {
void (*enter)(struct wlr_seat_keyboard_grab *grab, struct wlr_surface *surface);
void (*enter)(struct wlr_seat_keyboard_grab *grab,
struct wlr_surface *surface);
void (*key)(struct wlr_seat_keyboard_grab *grab, uint32_t time,
uint32_t key, uint32_t state);
void (*modifiers)(struct wlr_seat_keyboard_grab *grab,
@ -70,8 +72,8 @@ struct wlr_seat_pointer_grab {
};
struct wlr_seat_pointer_state {
struct wlr_seat *wlr_seat;
struct wlr_seat_handle *focused_handle;
struct wlr_seat *seat;
struct wlr_seat_client *focused_client;
struct wlr_surface *focused_surface;
struct wlr_seat_pointer_grab *grab;
@ -87,10 +89,10 @@ struct wlr_seat_pointer_state {
};
struct wlr_seat_keyboard_state {
struct wlr_seat *wlr_seat;
struct wlr_seat *seat;
struct wlr_keyboard *keyboard;
struct wlr_seat_handle *focused_handle;
struct wlr_seat_client *focused_client;
struct wlr_surface *focused_surface;
struct wl_listener keyboard_destroy;
@ -106,7 +108,7 @@ struct wlr_seat_keyboard_state {
struct wlr_seat {
struct wl_global *wl_global;
struct wl_display *display;
struct wl_list handles;
struct wl_list clients;
char *name;
uint32_t capabilities;
@ -138,8 +140,7 @@ struct wlr_seat {
};
struct wlr_seat_pointer_request_set_cursor_event {
struct wl_client *client;
struct wlr_seat_handle *seat_handle;
struct wlr_seat_client *seat_client;
struct wlr_surface *surface;
int32_t hotspot_x, hotspot_y;
};
@ -153,11 +154,11 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name);
*/
void wlr_seat_destroy(struct wlr_seat *wlr_seat);
/**
* Gets a wlr_seat_handle for the specified client, or returns NULL if no
* handle is bound for that client.
* Gets a wlr_seat_client for the specified client, or returns NULL if no
* client is bound for that client.
*/
struct wlr_seat_handle *wlr_seat_handle_for_client(struct wlr_seat *wlr_seat,
struct wl_client *client);
struct wlr_seat_client *wlr_seat_client_for_wl_client(struct wlr_seat *wlr_seat,
struct wl_client *wl_client);
/**
* Updates the capabilities available on this seat.
* Will automatically send them to all clients.
@ -231,9 +232,9 @@ void wlr_seat_pointer_start_grab(struct wlr_seat *wlr_seat,
void wlr_seat_pointer_end_grab(struct wlr_seat *wlr_seat);
/**
* Notify the seat of a pointer enter event to the given surface and request it to be the
* focused surface for the pointer. Pass surface-local coordinates where the
* enter occurred.
* Notify the seat of a pointer enter event to the given surface and request it
* to be the focused surface for the pointer. Pass surface-local coordinates
* where the enter occurred.
*/
void wlr_seat_pointer_notify_enter(struct wlr_seat *wlr_seat,
struct wlr_surface *surface, double sx, double sy);

View file

@ -475,12 +475,12 @@ static void handle_request_set_cursor(struct wl_listener *listener,
struct wlr_seat_pointer_request_set_cursor_event *event = data;
struct wlr_surface *focused_surface =
event->seat_handle->wlr_seat->pointer_state.focused_surface;
event->seat_client->seat->pointer_state.focused_surface;
bool ok = focused_surface != NULL && focused_surface->resource != NULL;
if (ok) {
struct wl_client *focused_client =
wl_resource_get_client(focused_surface->resource);
ok = event->client == focused_client;
ok = event->seat_client->client == focused_client;
}
if (!ok || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
wlr_log(L_DEBUG, "Denying request to set cursor from unfocused client");
@ -489,7 +489,7 @@ static void handle_request_set_cursor(struct wl_listener *listener,
wlr_log(L_DEBUG, "Setting client cursor");
cursor_set_surface(input, event->surface, event->hotspot_x, event->hotspot_y);
input->cursor_client = event->client;
input->cursor_client = event->seat_client->client;
}
void cursor_initialize(struct roots_input *input) {

View file

@ -38,7 +38,7 @@ static uint32_t data_offer_choose_action(struct wlr_data_offer *offer) {
return WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE;
}
if (offer->source->seat &&
if (offer->source->seat_client &&
offer->source->compositor_action & available_actions) {
return offer->source->compositor_action;
}
@ -263,31 +263,31 @@ static struct wlr_data_offer *wlr_data_source_send_offer(
}
void wlr_seat_handle_send_selection(struct wlr_seat_handle *handle) {
if (!handle->data_device) {
void wlr_seat_client_send_selection(struct wlr_seat_client *seat_client) {
if (!seat_client->data_device) {
return;
}
if (handle->wlr_seat->selection_source) {
if (seat_client->seat->selection_source) {
struct wlr_data_offer *offer =
wlr_data_source_send_offer(handle->wlr_seat->selection_source,
handle->data_device);
wl_data_device_send_selection(handle->data_device, offer->resource);
wlr_data_source_send_offer(seat_client->seat->selection_source,
seat_client->data_device);
wl_data_device_send_selection(seat_client->data_device, offer->resource);
} else {
wl_data_device_send_selection(handle->data_device, NULL);
wl_data_device_send_selection(seat_client->data_device, NULL);
}
}
static void seat_handle_selection_data_source_destroy(
static void seat_client_selection_data_source_destroy(
struct wl_listener *listener, void *data) {
struct wlr_seat *seat =
wl_container_of(listener, seat, selection_data_source_destroy);
if (seat->keyboard_state.focused_handle &&
if (seat->keyboard_state.focused_client &&
seat->keyboard_state.focused_surface &&
seat->keyboard_state.focused_handle->data_device) {
seat->keyboard_state.focused_client->data_device) {
wl_data_device_send_selection(
seat->keyboard_state.focused_handle->data_device, NULL);
seat->keyboard_state.focused_client->data_device, NULL);
}
seat->selection_source = NULL;
@ -311,35 +311,36 @@ void wlr_seat_set_selection(struct wlr_seat *seat,
seat->selection_source = source;
seat->selection_serial = serial;
struct wlr_seat_handle *focused_handle =
seat->keyboard_state.focused_handle;
struct wlr_seat_client *focused_client =
seat->keyboard_state.focused_client;
if (focused_handle) {
wlr_seat_handle_send_selection(focused_handle);
if (focused_client) {
wlr_seat_client_send_selection(focused_client);
}
wl_signal_emit(&seat->events.selection, seat);
if (source) {
seat->selection_data_source_destroy.notify =
seat_handle_selection_data_source_destroy;
seat_client_selection_data_source_destroy;
wl_signal_add(&source->events.destroy,
&seat->selection_data_source_destroy);
}
}
static void data_device_set_selection(struct wl_client *client,
struct wl_resource *seat_resource, struct wl_resource *source_resource,
struct wl_resource *dd_resource, struct wl_resource *source_resource,
uint32_t serial) {
if (!source_resource) {
return;
}
struct wlr_data_source *source = wl_resource_get_user_data(source_resource);
struct wlr_seat_handle *handle = wl_resource_get_user_data(seat_resource);
struct wlr_seat_client *seat_client =
wl_resource_get_user_data(dd_resource);
// TODO: store serial and check against incoming serial here
wlr_seat_set_selection(handle->wlr_seat, source, serial);
wlr_seat_set_selection(seat_client->seat, source, serial);
}
static void data_device_release(struct wl_client *client,
@ -347,13 +348,14 @@ static void data_device_release(struct wl_client *client,
wl_resource_destroy(resource);
}
static void drag_handle_seat_unbound(struct wl_listener *listener, void *data) {
struct wlr_drag *drag = wl_container_of(listener, drag, handle_unbound);
struct wlr_seat_handle *unbound_handle = data;
static void drag_client_seat_unbound(struct wl_listener *listener, void *data) {
struct wlr_drag *drag =
wl_container_of(listener, drag, seat_client_unbound);
struct wlr_seat_client *unbound_client = data;
if (drag->focus_handle == unbound_handle) {
drag->focus_handle = NULL;
wl_list_remove(&drag->handle_unbound.link);
if (drag->focus_client == unbound_client) {
drag->focus_client = NULL;
wl_list_remove(&drag->seat_client_unbound.link);
}
}
@ -363,10 +365,10 @@ static void wlr_drag_set_focus(struct wlr_drag *drag,
return;
}
if (drag->focus_handle && drag->focus_handle->data_device) {
wl_list_remove(&drag->handle_unbound.link);
wl_data_device_send_leave(drag->focus_handle->data_device);
drag->focus_handle = NULL;
if (drag->focus_client && drag->focus_client->data_device) {
wl_list_remove(&drag->seat_client_unbound.link);
wl_data_device_send_leave(drag->focus_client->data_device);
drag->focus_client = NULL;
drag->focus = NULL;
}
@ -376,7 +378,7 @@ static void wlr_drag_set_focus(struct wlr_drag *drag,
if (!drag->source &&
wl_resource_get_client(surface->resource) !=
wl_resource_get_client(drag->handle->wl_resource)) {
wl_resource_get_client(drag->seat_client->wl_resource)) {
return;
}
@ -387,11 +389,11 @@ static void wlr_drag_set_focus(struct wlr_drag *drag,
drag->source->offer = NULL;
}
struct wlr_seat_handle *focus_handle =
wlr_seat_handle_for_client(drag->handle->wlr_seat,
struct wlr_seat_client *focus_client =
wlr_seat_client_for_wl_client(drag->seat_client->seat,
wl_resource_get_client(surface->resource));
if (!focus_handle || !focus_handle->data_device) {
if (!focus_client || !focus_client->data_device) {
return;
}
@ -399,7 +401,7 @@ static void wlr_drag_set_focus(struct wlr_drag *drag,
if (drag->source) {
drag->source->accepted = false;
struct wlr_data_offer *offer =
wlr_data_source_send_offer(drag->source, focus_handle->data_device);
wlr_data_source_send_offer(drag->source, focus_client->data_device);
if (offer == NULL) {
return;
}
@ -415,17 +417,18 @@ static void wlr_drag_set_focus(struct wlr_drag *drag,
offer_resource = offer->resource;
}
uint32_t serial = wl_display_next_serial(drag->handle->wlr_seat->display);
uint32_t serial =
wl_display_next_serial(drag->seat_client->seat->display);
wl_data_device_send_enter(focus_handle->data_device, serial,
wl_data_device_send_enter(focus_client->data_device, serial,
surface->resource, wl_fixed_from_double(sx),
wl_fixed_from_double(sy), offer_resource);
drag->focus = surface;
drag->focus_handle = focus_handle;
drag->handle_unbound.notify = drag_handle_seat_unbound;
wl_signal_add(&focus_handle->wlr_seat->events.client_unbound,
&drag->handle_unbound);
drag->focus_client = focus_client;
drag->seat_client_unbound.notify = drag_client_seat_unbound;
wl_signal_add(&focus_client->seat->events.client_unbound,
&drag->seat_client_unbound);
}
static void wlr_drag_end(struct wlr_drag *drag) {
@ -452,8 +455,8 @@ static void pointer_drag_enter(struct wlr_seat_pointer_grab *grab,
static void pointer_drag_motion(struct wlr_seat_pointer_grab *grab,
uint32_t time, double sx, double sy) {
struct wlr_drag *drag = grab->data;
if (drag->focus && drag->focus_handle && drag->focus_handle->data_device) {
wl_data_device_send_motion(drag->focus_handle->data_device, time,
if (drag->focus && drag->focus_client && drag->focus_client->data_device) {
wl_data_device_send_motion(drag->focus_client->data_device, time,
wl_fixed_from_double(sx), wl_fixed_from_double(sy));
}
}
@ -465,10 +468,10 @@ static uint32_t pointer_drag_button(struct wlr_seat_pointer_grab *grab,
if (drag->source &&
grab->seat->pointer_state.grab_button == button &&
state == WL_POINTER_BUTTON_STATE_RELEASED) {
if (drag->focus_handle && drag->focus_handle->data_device &&
if (drag->focus_client && drag->focus_client->data_device &&
drag->source->current_dnd_action &&
drag->source->accepted) {
wl_data_device_send_drop(drag->focus_handle->data_device);
wl_data_device_send_drop(drag->focus_client->data_device);
if (wl_resource_get_version(drag->source->resource) >=
WL_DATA_SOURCE_DND_DROP_PERFORMED_SINCE_VERSION) {
wl_data_source_send_dnd_drop_performed(
@ -551,14 +554,14 @@ static void drag_handle_drag_source_destroy(struct wl_listener *listener,
wlr_drag_end(drag);
}
static bool seat_handle_start_drag(struct wlr_seat_handle *handle,
static bool seat_client_start_drag(struct wlr_seat_client *client,
struct wlr_data_source *source, struct wlr_surface *icon) {
struct wlr_drag *drag = calloc(1, sizeof(struct wlr_drag));
if (drag == NULL) {
return false;
}
struct wlr_seat *seat = handle->wlr_seat;
struct wlr_seat *seat = client->seat;
if (icon) {
drag->icon = icon;
@ -573,7 +576,7 @@ static bool seat_handle_start_drag(struct wlr_seat_handle *handle,
drag->source = source;
}
drag->handle = handle;
drag->seat_client = client;
drag->pointer_grab.data = drag;
drag->pointer_grab.interface = &wlr_data_device_pointer_drag_interface;
@ -591,12 +594,12 @@ static bool seat_handle_start_drag(struct wlr_seat_handle *handle,
}
static void data_device_start_drag(struct wl_client *client,
struct wl_resource *handle_resource,
struct wl_resource *device_resource,
struct wl_resource *source_resource,
struct wl_resource *origin_resource, struct wl_resource *icon_resource,
uint32_t serial) {
struct wlr_seat_handle *handle = wl_resource_get_user_data(handle_resource);
struct wlr_seat *seat = handle->wlr_seat;
struct wlr_seat_client *seat_client = wl_resource_get_user_data(device_resource);
struct wlr_seat *seat = seat_client->seat;
struct wlr_surface *origin = wl_resource_get_user_data(origin_resource);
struct wlr_data_source *source = NULL;
struct wlr_surface *icon = NULL;
@ -619,17 +622,17 @@ static void data_device_start_drag(struct wl_client *client,
}
if (icon) {
if (wlr_surface_set_role(icon, "wl_data_device-icon",
handle_resource, WL_DATA_DEVICE_ERROR_ROLE) < 0) {
icon_resource, WL_DATA_DEVICE_ERROR_ROLE) < 0) {
return;
}
}
// TODO touch grab
if (!seat_handle_start_drag(handle, source, icon)) {
wl_resource_post_no_memory(handle_resource);
if (!seat_client_start_drag(seat_client, source, icon)) {
wl_resource_post_no_memory(device_resource);
} else {
source->seat = handle;
source->seat_client = seat_client;
}
}
@ -642,7 +645,7 @@ static const struct wl_data_device_interface data_device_impl = {
void data_device_manager_get_data_device(struct wl_client *client,
struct wl_resource *manager_resource, uint32_t id,
struct wl_resource *seat_resource) {
struct wlr_seat_handle *handle = wl_resource_get_user_data(seat_resource);
struct wlr_seat_client *seat_client = wl_resource_get_user_data(seat_resource);
struct wl_resource *resource =
wl_resource_create(client,
@ -653,16 +656,16 @@ void data_device_manager_get_data_device(struct wl_client *client,
return;
}
if (handle->data_device != NULL) {
if (seat_client->data_device != NULL) {
// XXX this is probably a protocol violation, but it simplfies our code
// and it's stupid to create several data devices for the same seat.
wl_resource_destroy(handle->data_device);
wl_resource_destroy(seat_client->data_device);
}
handle->data_device = resource;
seat_client->data_device = resource;
wl_resource_set_implementation(resource, &data_device_impl,
handle, NULL);
seat_client, NULL);
}
static void data_source_resource_destroy(struct wl_resource *resource) {
@ -705,7 +708,7 @@ static void data_source_set_actions(struct wl_client *client,
return;
}
if (source->seat) {
if (source->seat_client) {
wl_resource_post_error(source->resource,
WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK,
"invalid action change after "

View file

@ -21,15 +21,16 @@ static void pointer_send_frame(struct wl_resource *resource) {
}
static void wl_pointer_set_cursor(struct wl_client *client,
struct wl_resource *resource, uint32_t serial,
struct wl_resource *pointer_resource, uint32_t serial,
struct wl_resource *surface_resource,
int32_t hotspot_x, int32_t hotspot_y) {
struct wlr_seat_handle *handle = wl_resource_get_user_data(resource);
struct wlr_seat_client *seat_client =
wl_resource_get_user_data(pointer_resource);
struct wlr_surface *surface = NULL;
if (surface_resource != NULL) {
surface = wl_resource_get_user_data(surface_resource);
if (wlr_surface_set_role(surface, "wl_pointer-cursor", resource,
if (wlr_surface_set_role(surface, "wl_pointer-cursor", surface_resource,
WL_POINTER_ERROR_ROLE) < 0) {
return;
}
@ -40,13 +41,12 @@ static void wl_pointer_set_cursor(struct wl_client *client,
if (event == NULL) {
return;
}
event->client = client;
event->seat_handle = handle;
event->seat_client = seat_client;
event->surface = surface;
event->hotspot_x = hotspot_x;
event->hotspot_y = hotspot_y;
wl_signal_emit(&handle->wlr_seat->events.request_set_cursor, event);
wl_signal_emit(&seat_client->seat->events.request_set_cursor, event);
free(event);
}
@ -57,28 +57,29 @@ static const struct wl_pointer_interface wl_pointer_impl = {
};
static void wl_pointer_destroy(struct wl_resource *resource) {
struct wlr_seat_handle *handle = wl_resource_get_user_data(resource);
if (handle->pointer) {
handle->pointer = NULL;
struct wlr_seat_client *client = wl_resource_get_user_data(resource);
if (client->pointer) {
client->pointer = NULL;
}
}
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_POINTER)) {
struct wl_resource *pointer_resource, uint32_t id) {
struct wlr_seat_client *seat_client =
wl_resource_get_user_data(pointer_resource);
if (!(seat_client->seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) {
return;
}
if (handle->pointer) {
if (seat_client->pointer) {
// 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->pointer);
wl_resource_destroy(seat_client->pointer);
}
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, &wl_pointer_destroy);
seat_client->pointer = wl_resource_create(client, &wl_pointer_interface,
wl_resource_get_version(pointer_resource), id);
wl_resource_set_implementation(seat_client->pointer, &wl_pointer_impl,
seat_client, &wl_pointer_destroy);
}
static const struct wl_keyboard_interface wl_keyboard_impl = {
@ -86,47 +87,49 @@ static const struct wl_keyboard_interface wl_keyboard_impl = {
};
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;
struct wlr_seat_client *client = wl_resource_get_user_data(resource);
if (client->keyboard) {
client->keyboard = NULL;
}
}
static void seat_handle_send_keymap(struct wlr_seat_handle *handle,
static void seat_client_send_keymap(struct wlr_seat_client *client,
struct wlr_keyboard *keyboard) {
if (!keyboard || !handle->keyboard) {
if (!keyboard || !client->keyboard) {
return;
}
// TODO: We should probably lift all of the keys set by the other
// keyboard
wl_keyboard_send_keymap(handle->keyboard,
wl_keyboard_send_keymap(client->keyboard,
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keyboard->keymap_fd,
keyboard->keymap_size);
if (wl_resource_get_version(handle->keyboard) >=
if (wl_resource_get_version(client->keyboard) >=
WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) {
wl_keyboard_send_repeat_info(handle->keyboard, 25, 600);
wl_keyboard_send_repeat_info(client->keyboard, 25, 600);
}
}
static void wl_seat_get_keyboard(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)) {
struct wl_resource *seat_resource, uint32_t id) {
struct wlr_seat_client *seat_client =
wl_resource_get_user_data(seat_resource);
if (!(seat_client->seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)) {
return;
}
if (handle->keyboard) {
if (seat_client->keyboard) {
// TODO: this is probably a protocol violation but it simplifies our
// code and it'd be stupid for clients to create several keyboards for
// the same seat
wl_resource_destroy(handle->keyboard);
wl_resource_destroy(seat_client->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);
seat_client->keyboard = wl_resource_create(client, &wl_keyboard_interface,
wl_resource_get_version(seat_resource), id);
wl_resource_set_implementation(seat_client->keyboard, &wl_keyboard_impl,
seat_client, &wl_keyboard_destroy);
seat_handle_send_keymap(handle, handle->wlr_seat->keyboard_state.keyboard);
seat_client_send_keymap(seat_client,
seat_client->seat->keyboard_state.keyboard);
// TODO possibly handle the case where this keyboard needs an enter
// right away
@ -137,55 +140,56 @@ static const struct wl_touch_interface wl_touch_impl = {
};
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;
struct wlr_seat_client *client = wl_resource_get_user_data(resource);
if (client->touch) {
client->touch = NULL;
}
}
static void wl_seat_get_touch(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_TOUCH)) {
struct wl_resource *seat_resource, uint32_t id) {
struct wlr_seat_client *seat_client =
wl_resource_get_user_data(seat_resource);
if (!(seat_client->seat->capabilities & WL_SEAT_CAPABILITY_TOUCH)) {
return;
}
if (handle->touch) {
if (seat_client->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);
wl_resource_destroy(seat_client->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);
seat_client->touch = wl_resource_create(client, &wl_touch_interface,
wl_resource_get_version(seat_resource), id);
wl_resource_set_implementation(seat_client->touch, &wl_touch_impl,
seat_client, &wl_touch_destroy);
}
static void wlr_seat_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_seat_handle *handle = wl_resource_get_user_data(resource);
wl_signal_emit(&handle->wlr_seat->events.client_unbound, handle);
static void wlr_seat_client_resource_destroy(struct wl_resource *resource) {
struct wlr_seat_client *client = wl_resource_get_user_data(resource);
wl_signal_emit(&client->seat->events.client_unbound, client);
if (handle == handle->wlr_seat->pointer_state.focused_handle) {
handle->wlr_seat->pointer_state.focused_handle = NULL;
if (client == client->seat->pointer_state.focused_client) {
client->seat->pointer_state.focused_client = NULL;
}
if (handle == handle->wlr_seat->keyboard_state.focused_handle) {
handle->wlr_seat->keyboard_state.focused_handle = NULL;
if (client == client->seat->keyboard_state.focused_client) {
client->seat->keyboard_state.focused_client = NULL;
}
if (handle->pointer) {
wl_resource_destroy(handle->pointer);
if (client->pointer) {
wl_resource_destroy(client->pointer);
}
if (handle->keyboard) {
wl_resource_destroy(handle->keyboard);
if (client->keyboard) {
wl_resource_destroy(client->keyboard);
}
if (handle->touch) {
wl_resource_destroy(handle->touch);
if (client->touch) {
wl_resource_destroy(client->touch);
}
if (handle->data_device) {
wl_resource_destroy(handle->data_device);
if (client->data_device) {
wl_resource_destroy(client->data_device);
}
wl_list_remove(&handle->link);
free(handle);
wl_list_remove(&client->link);
free(client);
}
struct wl_seat_interface wl_seat_impl = {
@ -195,23 +199,25 @@ struct wl_seat_interface wl_seat_impl = {
.release = resource_destroy
};
static void wl_seat_bind(struct wl_client *wl_client, void *_wlr_seat,
static void wl_seat_bind(struct wl_client *client, void *_wlr_seat,
uint32_t version, uint32_t id) {
struct wlr_seat *wlr_seat = _wlr_seat;
assert(wl_client && wlr_seat);
assert(client && wlr_seat);
struct wlr_seat_handle *handle = calloc(1, sizeof(struct wlr_seat_handle));
handle->wl_resource = wl_resource_create(
wl_client, &wl_seat_interface, version, id);
handle->wlr_seat = wlr_seat;
wl_resource_set_implementation(handle->wl_resource, &wl_seat_impl,
handle, wlr_seat_handle_resource_destroy);
wl_list_insert(&wlr_seat->handles, &handle->link);
struct wlr_seat_client *seat_client =
calloc(1, sizeof(struct wlr_seat_client));
seat_client->wl_resource =
wl_resource_create(client, &wl_seat_interface, version, id);
seat_client->client = client;
seat_client->seat = wlr_seat;
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);
if (version >= WL_SEAT_NAME_SINCE_VERSION) {
wl_seat_send_name(handle->wl_resource, wlr_seat->name);
wl_seat_send_name(seat_client->wl_resource, wlr_seat->name);
}
wl_seat_send_capabilities(handle->wl_resource, wlr_seat->capabilities);
wl_signal_emit(&wlr_seat->events.client_bound, handle);
wl_seat_send_capabilities(seat_client->wl_resource, wlr_seat->capabilities);
wl_signal_emit(&wlr_seat->events.client_bound, seat_client);
}
static void default_pointer_enter(struct wlr_seat_pointer_grab *grab,
@ -280,7 +286,7 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
return NULL;
}
wlr_seat->pointer_state.wlr_seat = wlr_seat;
wlr_seat->pointer_state.seat = wlr_seat;
wl_list_init(&wlr_seat->pointer_state.surface_destroy.link);
wl_list_init(&wlr_seat->pointer_state.resource_destroy.link);
@ -307,7 +313,7 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
wlr_seat->keyboard_state.default_grab = keyboard_grab;
wlr_seat->keyboard_state.grab = keyboard_grab;
wlr_seat->keyboard_state.wlr_seat = wlr_seat;
wlr_seat->keyboard_state.seat = wlr_seat;
wl_list_init(&wlr_seat->keyboard_state.resource_destroy.link);
wl_list_init(
&wlr_seat->keyboard_state.surface_destroy.link);
@ -321,7 +327,7 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
wlr_seat->wl_global = wl_global;
wlr_seat->display = display;
wlr_seat->name = strdup(name);
wl_list_init(&wlr_seat->handles);
wl_list_init(&wlr_seat->clients);
wl_signal_init(&wlr_seat->events.client_bound);
wl_signal_init(&wlr_seat->events.client_unbound);
@ -343,10 +349,10 @@ void wlr_seat_destroy(struct wlr_seat *wlr_seat) {
return;
}
struct wlr_seat_handle *handle, *tmp;
wl_list_for_each_safe(handle, tmp, &wlr_seat->handles, link) {
struct wlr_seat_client *client, *tmp;
wl_list_for_each_safe(client, tmp, &wlr_seat->clients, link) {
// will destroy other resources as well
wl_resource_destroy(handle->wl_resource);
wl_resource_destroy(client->wl_resource);
}
wl_global_destroy(wlr_seat->wl_global);
@ -357,13 +363,13 @@ void wlr_seat_destroy(struct wlr_seat *wlr_seat) {
free(wlr_seat);
}
struct wlr_seat_handle *wlr_seat_handle_for_client(struct wlr_seat *wlr_seat,
struct wl_client *client) {
struct wlr_seat_client *wlr_seat_client_for_wl_client(struct wlr_seat *wlr_seat,
struct wl_client *wl_client) {
assert(wlr_seat);
struct wlr_seat_handle *handle;
wl_list_for_each(handle, &wlr_seat->handles, link) {
if (wl_resource_get_client(handle->wl_resource) == client) {
return handle;
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;
}
}
return NULL;
@ -372,18 +378,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) {
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);
struct wlr_seat_client *client;
wl_list_for_each(client, &wlr_seat->clients, link) {
wl_seat_send_capabilities(client->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);
struct wlr_seat_client *client;
wl_list_for_each(client, &wlr_seat->clients, link) {
wl_seat_send_name(client->wl_resource, name);
}
}
@ -399,7 +405,7 @@ static void pointer_surface_destroy_notify(struct wl_listener *listener,
wl_list_remove(&state->surface_destroy.link);
wl_list_init(&state->surface_destroy.link);
state->focused_surface = NULL;
wlr_seat_pointer_clear_focus(state->wlr_seat);
wlr_seat_pointer_clear_focus(state->seat);
}
static void pointer_resource_destroy_notify(struct wl_listener *listener,
@ -409,12 +415,12 @@ static void pointer_resource_destroy_notify(struct wl_listener *listener,
wl_list_remove(&state->resource_destroy.link);
wl_list_init(&state->resource_destroy.link);
state->focused_surface = NULL;
wlr_seat_pointer_clear_focus(state->wlr_seat);
wlr_seat_pointer_clear_focus(state->seat);
}
static bool wlr_seat_pointer_has_focus_resource(struct wlr_seat *wlr_seat) {
return wlr_seat->pointer_state.focused_handle &&
wlr_seat->pointer_state.focused_handle->pointer;
return wlr_seat->pointer_state.focused_client &&
wlr_seat->pointer_state.focused_client->pointer;
}
void wlr_seat_pointer_enter(struct wlr_seat *wlr_seat,
@ -426,32 +432,32 @@ void wlr_seat_pointer_enter(struct wlr_seat *wlr_seat,
return;
}
struct wlr_seat_handle *handle = NULL;
struct wlr_seat_client *client = NULL;
if (surface) {
struct wl_client *client = wl_resource_get_client(surface->resource);
handle = wlr_seat_handle_for_client(wlr_seat, client);
struct wl_client *wl_client = wl_resource_get_client(surface->resource);
client = wlr_seat_client_for_wl_client(wlr_seat, wl_client);
}
struct wlr_seat_handle *focused_handle =
wlr_seat->pointer_state.focused_handle;
struct wlr_seat_client *focused_client =
wlr_seat->pointer_state.focused_client;
struct wlr_surface *focused_surface =
wlr_seat->pointer_state.focused_surface;
// leave the previously entered surface
if (focused_handle && focused_handle->pointer && focused_surface) {
if (focused_client && focused_client->pointer && focused_surface) {
uint32_t serial = wl_display_next_serial(wlr_seat->display);
wl_pointer_send_leave(focused_handle->pointer, serial,
wl_pointer_send_leave(focused_client->pointer, serial,
focused_surface->resource);
pointer_send_frame(focused_handle->pointer);
pointer_send_frame(focused_client->pointer);
}
// enter the current surface
if (handle && handle->pointer) {
if (client && client->pointer) {
uint32_t serial = wl_display_next_serial(wlr_seat->display);
wl_pointer_send_enter(handle->pointer, serial, surface->resource,
wl_pointer_send_enter(client->pointer, serial, surface->resource,
wl_fixed_from_double(sx), wl_fixed_from_double(sy));
pointer_send_frame(handle->pointer);
pointer_send_frame(client->pointer);
}
// reinitialize the focus destroy events
@ -470,7 +476,7 @@ void wlr_seat_pointer_enter(struct wlr_seat *wlr_seat,
pointer_surface_destroy_notify;
}
wlr_seat->pointer_state.focused_handle = handle;
wlr_seat->pointer_state.focused_client = client;
wlr_seat->pointer_state.focused_surface = surface;
// TODO: send focus change event
@ -486,9 +492,9 @@ void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time,
return;
}
wl_pointer_send_motion(wlr_seat->pointer_state.focused_handle->pointer,
wl_pointer_send_motion(wlr_seat->pointer_state.focused_client->pointer,
time, wl_fixed_from_double(sx), wl_fixed_from_double(sy));
pointer_send_frame(wlr_seat->pointer_state.focused_handle->pointer);
pointer_send_frame(wlr_seat->pointer_state.focused_client->pointer);
}
uint32_t wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time,
@ -498,9 +504,9 @@ uint32_t wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time,
}
uint32_t serial = wl_display_next_serial(wlr_seat->display);
wl_pointer_send_button(wlr_seat->pointer_state.focused_handle->pointer,
wl_pointer_send_button(wlr_seat->pointer_state.focused_client->pointer,
serial, time, button, state);
pointer_send_frame(wlr_seat->pointer_state.focused_handle->pointer);
pointer_send_frame(wlr_seat->pointer_state.focused_client->pointer);
return serial;
}
@ -511,7 +517,7 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time,
}
struct wl_resource *pointer =
wlr_seat->pointer_state.focused_handle->pointer;
wlr_seat->pointer_state.focused_client->pointer;
if (value) {
wl_pointer_send_axis(pointer, time, orientation,
@ -582,22 +588,22 @@ void wlr_seat_pointer_notify_axis(struct wlr_seat *wlr_seat, uint32_t time,
void wlr_seat_keyboard_send_key(struct wlr_seat *wlr_seat, uint32_t time,
uint32_t key, uint32_t state) {
struct wlr_seat_handle *handle = wlr_seat->keyboard_state.focused_handle;
if (!handle || !handle->keyboard) {
struct wlr_seat_client *client = wlr_seat->keyboard_state.focused_client;
if (!client || !client->keyboard) {
return;
}
uint32_t serial = wl_display_next_serial(wlr_seat->display);
wl_keyboard_send_key(handle->keyboard, serial,
wl_keyboard_send_key(client->keyboard, serial,
time, key, state);
}
static void handle_keyboard_keymap(struct wl_listener *listener, void *data) {
struct wlr_seat_keyboard_state *state =
wl_container_of(listener, state, keyboard_keymap);
struct wlr_seat_handle *handle;
wl_list_for_each(handle, &state->wlr_seat->handles, link) {
seat_handle_send_keymap(handle, state->keyboard);
struct wlr_seat_client *client;
wl_list_for_each(client, &state->seat->clients, link) {
seat_client_send_keymap(client, state->keyboard);
}
}
@ -632,9 +638,9 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat,
&seat->keyboard_state.keyboard_keymap);
seat->keyboard_state.keyboard_keymap.notify = handle_keyboard_keymap;
struct wlr_seat_handle *handle;
wl_list_for_each(handle, &seat->handles, link) {
seat_handle_send_keymap(handle, device->keyboard);
struct wlr_seat_client *client;
wl_list_for_each(client, &seat->clients, link) {
seat_client_send_keymap(client, device->keyboard);
}
seat->keyboard_state.keyboard = device->keyboard;
@ -665,7 +671,7 @@ static void keyboard_surface_destroy_notify(struct wl_listener *listener,
wl_list_remove(&state->surface_destroy.link);
wl_list_init(&state->surface_destroy.link);
state->focused_surface = NULL;
wlr_seat_keyboard_clear_focus(state->wlr_seat);
wlr_seat_keyboard_clear_focus(state->seat);
}
static void keyboard_resource_destroy_notify(struct wl_listener *listener,
@ -675,20 +681,20 @@ static void keyboard_resource_destroy_notify(struct wl_listener *listener,
wl_list_remove(&state->resource_destroy.link);
wl_list_init(&state->resource_destroy.link);
state->focused_surface = NULL;
wlr_seat_keyboard_clear_focus(state->wlr_seat);
wlr_seat_keyboard_clear_focus(state->seat);
}
void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat,
uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked,
uint32_t group) {
struct wlr_seat_handle *handle = seat->keyboard_state.focused_handle;
if (!handle || !handle->keyboard) {
struct wlr_seat_client *client = seat->keyboard_state.focused_client;
if (!client || !client->keyboard) {
return;
}
uint32_t serial = wl_display_next_serial(seat->display);
wl_keyboard_send_modifiers(handle->keyboard, serial,
wl_keyboard_send_modifiers(client->keyboard, serial,
mods_depressed, mods_latched,
mods_locked, group);
}
@ -700,35 +706,35 @@ void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat,
return;
}
struct wlr_seat_handle *handle = NULL;
struct wlr_seat_client *client = NULL;
if (surface) {
struct wl_client *client = wl_resource_get_client(surface->resource);
handle = wlr_seat_handle_for_client(wlr_seat, client);
struct wl_client *wl_client = wl_resource_get_client(surface->resource);
client = wlr_seat_client_for_wl_client(wlr_seat, wl_client);
}
struct wlr_seat_handle *focused_handle =
wlr_seat->keyboard_state.focused_handle;
struct wlr_seat_client *focused_client =
wlr_seat->keyboard_state.focused_client;
struct wlr_surface *focused_surface =
wlr_seat->keyboard_state.focused_surface;
// leave the previously entered surface
if (focused_handle && focused_handle->keyboard && focused_surface) {
if (focused_client && focused_client->keyboard && focused_surface) {
uint32_t serial = wl_display_next_serial(wlr_seat->display);
wl_keyboard_send_leave(focused_handle->keyboard, serial,
wl_keyboard_send_leave(focused_client->keyboard, serial,
focused_surface->resource);
}
// enter the current surface
if (handle && handle->keyboard) {
if (client && client->keyboard) {
// TODO: read the currently pressed keys out of the active keyboard and
// put them in this array
struct wl_array keys;
wl_array_init(&keys);
uint32_t serial = wl_display_next_serial(wlr_seat->display);
wl_keyboard_send_enter(handle->keyboard, serial,
wl_keyboard_send_enter(client->keyboard, serial,
surface->resource, &keys);
wlr_seat_handle_send_selection(handle);
wlr_seat_client_send_selection(client);
}
// reinitialize the focus destroy events
@ -747,7 +753,7 @@ void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat,
keyboard_surface_destroy_notify;
}
wlr_seat->keyboard_state.focused_handle = handle;
wlr_seat->keyboard_state.focused_client = client;
wlr_seat->keyboard_state.focused_surface = surface;
}

View file

@ -315,12 +315,12 @@ static void shell_surface_protocol_set_popup(struct wl_client *client,
uint32_t serial, struct wl_resource *parent_resource, int32_t x,
int32_t y, enum wl_shell_surface_transient flags) {
struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource);
struct wlr_seat_handle *seat_handle =
struct wlr_seat_client *seat_client =
wl_resource_get_user_data(seat_resource);
struct wlr_surface *parent =
wl_resource_get_user_data(parent_resource);
struct wlr_wl_shell_popup_grab *grab =
shell_popup_grab_from_seat(surface->shell, seat_handle->wlr_seat);
shell_popup_grab_from_seat(surface->shell, seat_client->seat);
if (!grab) {
wl_client_post_no_memory(client);
return;
@ -335,7 +335,7 @@ static void shell_surface_protocol_set_popup(struct wl_client *client,
shell_surface_popup_set_parent(surface, wl_parent);
grab->client = surface->client;
surface->popup_mapped = true;
wlr_seat_pointer_start_grab(seat_handle->wlr_seat, &grab->pointer_grab);
wlr_seat_pointer_start_grab(seat_client->seat, &grab->pointer_grab);
return;
}
@ -356,7 +356,7 @@ static void shell_surface_protocol_set_popup(struct wl_client *client,
wl_client_post_no_memory(client);
return;
}
popup_state->seat = seat_handle->wlr_seat;
popup_state->seat = seat_client->seat;
popup_state->serial = serial;
shell_surface_set_state(surface, WLR_WL_SHELL_SURFACE_STATE_POPUP,
@ -366,7 +366,7 @@ static void shell_surface_protocol_set_popup(struct wl_client *client,
grab->client = surface->client;
wl_list_insert(&grab->popups, &surface->grab_link);
surface->popup_mapped = true;
wlr_seat_pointer_start_grab(seat_handle->wlr_seat, &grab->pointer_grab);
wlr_seat_pointer_start_grab(seat_client->seat, &grab->pointer_grab);
}
static void shell_surface_protocol_set_maximized(struct wl_client *client,

View file

@ -357,7 +357,7 @@ static void xdg_popup_protocol_grab(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *seat_resource,
uint32_t serial) {
struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource);
struct wlr_seat_handle *handle = wl_resource_get_user_data(seat_resource);
struct wlr_seat_client *seat_client = wl_resource_get_user_data(seat_resource);
if (surface->popup_state->committed) {
wl_resource_post_error(surface->popup_state->resource,
@ -368,7 +368,7 @@ static void xdg_popup_protocol_grab(struct wl_client *client,
struct wlr_xdg_popup_grab_v6 *popup_grab =
xdg_shell_popup_grab_from_seat(surface->client->shell,
handle->wlr_seat);
seat_client->seat);
struct wlr_xdg_surface_v6 *topmost = xdg_popup_grab_get_topmost(popup_grab);
bool parent_is_toplevel =
@ -383,12 +383,14 @@ static void xdg_popup_protocol_grab(struct wl_client *client,
}
popup_grab->client = surface->client->client;
surface->popup_state->seat = handle->wlr_seat;
surface->popup_state->seat = seat_client->seat;
wl_list_insert(&popup_grab->popups, &surface->popup_state->grab_link);
wlr_seat_pointer_start_grab(handle->wlr_seat, &popup_grab->pointer_grab);
wlr_seat_keyboard_start_grab(handle->wlr_seat, &popup_grab->keyboard_grab);
wlr_seat_pointer_start_grab(seat_client->seat,
&popup_grab->pointer_grab);
wlr_seat_keyboard_start_grab(seat_client->seat,
&popup_grab->keyboard_grab);
}
static const struct zxdg_popup_v6_interface zxdg_popup_v6_implementation = {