|
|
@ -205,6 +205,34 @@ static const struct wlr_pointer_grab_interface default_pointer_grab_impl = {
|
|
|
|
.cancel = default_pointer_cancel,
|
|
|
|
.cancel = default_pointer_cancel,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void default_keyboard_modifiers(struct wlr_seat_keyboard_grab *grab,
|
|
|
|
|
|
|
|
uint32_t mods_depressed, uint32_t mods_latched,
|
|
|
|
|
|
|
|
uint32_t mods_locked, uint32_t group) {
|
|
|
|
|
|
|
|
wlr_seat_keyboard_send_modifiers(grab->seat, mods_depressed,
|
|
|
|
|
|
|
|
mods_latched, mods_locked, group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
|
|
|
|
struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
|
|
|
|
struct wlr_seat *wlr_seat = calloc(1, sizeof(struct wlr_seat));
|
|
|
|
struct wlr_seat *wlr_seat = calloc(1, sizeof(struct wlr_seat));
|
|
|
|
if (!wlr_seat) {
|
|
|
|
if (!wlr_seat) {
|
|
|
@ -215,16 +243,28 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
|
|
|
|
wl_list_init(&wlr_seat->pointer_state.surface_destroy.link);
|
|
|
|
wl_list_init(&wlr_seat->pointer_state.surface_destroy.link);
|
|
|
|
wl_list_init(&wlr_seat->pointer_state.resource_destroy.link);
|
|
|
|
wl_list_init(&wlr_seat->pointer_state.resource_destroy.link);
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_seat_pointer_grab *default_grab =
|
|
|
|
struct wlr_seat_pointer_grab *pointer_grab =
|
|
|
|
calloc(1, sizeof(struct wlr_seat_pointer_grab));
|
|
|
|
calloc(1, sizeof(struct wlr_seat_pointer_grab));
|
|
|
|
if (!default_grab) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_seat_keyboard_grab *keyboard_grab =
|
|
|
|
|
|
|
|
calloc(1, sizeof(struct wlr_seat_keyboard_grab));
|
|
|
|
|
|
|
|
if (!keyboard_grab) {
|
|
|
|
|
|
|
|
free(pointer_grab);
|
|
|
|
free(wlr_seat);
|
|
|
|
free(wlr_seat);
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default_grab->interface = &default_pointer_grab_impl;
|
|
|
|
keyboard_grab->interface = &default_keyboard_grab_impl;
|
|
|
|
default_grab->seat = wlr_seat;
|
|
|
|
keyboard_grab->seat = wlr_seat;
|
|
|
|
wlr_seat->pointer_state.default_grab = default_grab;
|
|
|
|
wlr_seat->keyboard_state.default_grab = keyboard_grab;
|
|
|
|
wlr_seat->pointer_state.grab = default_grab;
|
|
|
|
wlr_seat->keyboard_state.grab = keyboard_grab;
|
|
|
|
|
|
|
|
|
|
|
|
wlr_seat->keyboard_state.wlr_seat = wlr_seat;
|
|
|
|
wlr_seat->keyboard_state.wlr_seat = wlr_seat;
|
|
|
|
wl_list_init(&wlr_seat->keyboard_state.resource_destroy.link);
|
|
|
|
wl_list_init(&wlr_seat->keyboard_state.resource_destroy.link);
|
|
|
@ -249,6 +289,9 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
|
|
|
|
wl_signal_init(&wlr_seat->events.pointer_grab_begin);
|
|
|
|
wl_signal_init(&wlr_seat->events.pointer_grab_begin);
|
|
|
|
wl_signal_init(&wlr_seat->events.pointer_grab_end);
|
|
|
|
wl_signal_init(&wlr_seat->events.pointer_grab_end);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wl_signal_init(&wlr_seat->events.keyboard_grab_begin);
|
|
|
|
|
|
|
|
wl_signal_init(&wlr_seat->events.keyboard_grab_end);
|
|
|
|
|
|
|
|
|
|
|
|
return wlr_seat;
|
|
|
|
return wlr_seat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -265,6 +308,7 @@ void wlr_seat_destroy(struct wlr_seat *wlr_seat) {
|
|
|
|
|
|
|
|
|
|
|
|
wl_global_destroy(wlr_seat->wl_global);
|
|
|
|
wl_global_destroy(wlr_seat->wl_global);
|
|
|
|
free(wlr_seat->pointer_state.default_grab);
|
|
|
|
free(wlr_seat->pointer_state.default_grab);
|
|
|
|
|
|
|
|
free(wlr_seat->keyboard_state.default_grab);
|
|
|
|
free(wlr_seat->data_device);
|
|
|
|
free(wlr_seat->data_device);
|
|
|
|
free(wlr_seat->name);
|
|
|
|
free(wlr_seat->name);
|
|
|
|
free(wlr_seat);
|
|
|
|
free(wlr_seat);
|
|
|
@ -495,6 +539,18 @@ static void keyboard_switch_seat_keyboard(struct wlr_seat_handle *handle,
|
|
|
|
handle->seat_keyboard = seat_kb;
|
|
|
|
handle->seat_keyboard = seat_kb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t serial = wl_display_next_serial(wlr_seat->display);
|
|
|
|
|
|
|
|
wl_keyboard_send_key(handle->keyboard, serial,
|
|
|
|
|
|
|
|
time, key, state);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void keyboard_key_notify(struct wl_listener *listener, void *data) {
|
|
|
|
static void keyboard_key_notify(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_seat_keyboard *seat_kb = wl_container_of(listener, seat_kb, key);
|
|
|
|
struct wlr_seat_keyboard *seat_kb = wl_container_of(listener, seat_kb, key);
|
|
|
|
struct wlr_seat *seat = seat_kb->seat;
|
|
|
|
struct wlr_seat *seat = seat_kb->seat;
|
|
|
@ -508,9 +564,9 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_event_keyboard_key *event = data;
|
|
|
|
struct wlr_event_keyboard_key *event = data;
|
|
|
|
enum wlr_key_state key_state = event->state;
|
|
|
|
enum wlr_key_state key_state = event->state;
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t key_serial = wl_display_next_serial(seat->display);
|
|
|
|
struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab;
|
|
|
|
wl_keyboard_send_key(handle->keyboard, key_serial,
|
|
|
|
grab->interface->key(grab, (uint32_t)(event->time_usec / 1000),
|
|
|
|
(uint32_t)event->time_usec, event->keycode, key_state);
|
|
|
|
event->keycode, key_state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void keyboard_modifiers_notify(struct wl_listener *listener,
|
|
|
|
static void keyboard_modifiers_notify(struct wl_listener *listener,
|
|
|
@ -527,8 +583,9 @@ static void keyboard_modifiers_notify(struct wl_listener *listener,
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_keyboard *keyboard = seat_kb->keyboard;
|
|
|
|
struct wlr_keyboard *keyboard = seat_kb->keyboard;
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t modifiers_serial = wl_display_next_serial(seat->display);
|
|
|
|
struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab;
|
|
|
|
wl_keyboard_send_modifiers(handle->keyboard, modifiers_serial,
|
|
|
|
|
|
|
|
|
|
|
|
grab->interface->modifiers(grab,
|
|
|
|
keyboard->modifiers.depressed, keyboard->modifiers.latched,
|
|
|
|
keyboard->modifiers.depressed, keyboard->modifiers.latched,
|
|
|
|
keyboard->modifiers.locked, keyboard->modifiers.group);
|
|
|
|
keyboard->modifiers.locked, keyboard->modifiers.group);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -584,6 +641,21 @@ void wlr_seat_detach_keyboard(struct wlr_seat *seat, struct wlr_keyboard *kb) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
wlr_seat->keyboard_state.grab = wlr_seat->keyboard_state.default_grab;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wl_signal_emit(&wlr_seat->events.keyboard_grab_end, grab);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void keyboard_surface_destroy_notify(struct wl_listener *listener,
|
|
|
|
static void keyboard_surface_destroy_notify(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
void *data) {
|
|
|
|
struct wlr_seat_keyboard_state *state = wl_container_of(
|
|
|
|
struct wlr_seat_keyboard_state *state = wl_container_of(
|
|
|
@ -604,6 +676,21 @@ static void keyboard_resource_destroy_notify(struct wl_listener *listener,
|
|
|
|
wlr_seat_keyboard_clear_focus(state->wlr_seat);
|
|
|
|
wlr_seat_keyboard_clear_focus(state->wlr_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) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t serial = wl_display_next_serial(seat->display);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wl_keyboard_send_modifiers(handle->keyboard, serial,
|
|
|
|
|
|
|
|
mods_depressed, mods_latched,
|
|
|
|
|
|
|
|
mods_locked, group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat,
|
|
|
|
void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat,
|
|
|
|
struct wlr_surface *surface) {
|
|
|
|
struct wlr_surface *surface) {
|
|
|
|
if (wlr_seat->keyboard_state.focused_surface == surface) {
|
|
|
|
if (wlr_seat->keyboard_state.focused_surface == surface) {
|
|
|
@ -660,6 +747,12 @@ void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat,
|
|
|
|
wlr_seat->keyboard_state.focused_surface = surface;
|
|
|
|
wlr_seat->keyboard_state.focused_surface = surface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_seat_keyboard_notify_enter(struct wlr_seat *wlr_seat, struct
|
|
|
|
|
|
|
|
wlr_surface *surface) {
|
|
|
|
|
|
|
|
struct wlr_seat_keyboard_grab *grab = wlr_seat->keyboard_state.grab;
|
|
|
|
|
|
|
|
grab->interface->enter(grab, surface);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_seat_keyboard_clear_focus(struct wlr_seat *wlr_seat) {
|
|
|
|
void wlr_seat_keyboard_clear_focus(struct wlr_seat *wlr_seat) {
|
|
|
|
struct wl_array keys;
|
|
|
|
struct wl_array keys;
|
|
|
|
wl_array_init(&keys);
|
|
|
|
wl_array_init(&keys);
|
|
|
|