mirror of
https://github.com/swaywm/sway.git
synced 2026-04-25 06:46:24 -04:00
keyboard: simplify code for im grab handling
This commit is contained in:
parent
972c72bb0a
commit
93bcd6f59f
1 changed files with 56 additions and 50 deletions
|
|
@ -378,6 +378,21 @@ static void update_keyboard_state(struct sway_keyboard *keyboard,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get keyboard grab of the seat from sway_keyboard.
|
||||||
|
*
|
||||||
|
* Returns NULL if the keyboard is not grabbed by an input method.
|
||||||
|
*/
|
||||||
|
static struct wlr_input_method_keyboard_grab_v2 *keyboard_get_im_grab(
|
||||||
|
struct sway_keyboard *keyboard) {
|
||||||
|
struct wlr_input_method_v2 *input_method = keyboard->seat_device->
|
||||||
|
sway_seat->im_relay.input_method;
|
||||||
|
if (!input_method) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return input_method->keyboard_grab;
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_key_event(struct sway_keyboard *keyboard,
|
static void handle_key_event(struct sway_keyboard *keyboard,
|
||||||
struct wlr_event_keyboard_key *event) {
|
struct wlr_event_keyboard_key *event) {
|
||||||
struct sway_seat *seat = keyboard->seat_device->sway_seat;
|
struct sway_seat *seat = keyboard->seat_device->sway_seat;
|
||||||
|
|
@ -489,9 +504,7 @@ static void handle_key_event(struct sway_keyboard *keyboard,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!handled || event->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
if (!handled || event->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
||||||
if (seat->im_relay.input_method) {
|
struct wlr_input_method_keyboard_grab_v2 *kb_grab = keyboard_get_im_grab(keyboard);
|
||||||
struct wlr_input_method_keyboard_grab_v2 *kb_grab =
|
|
||||||
seat->im_relay.input_method->keyboard_grab;
|
|
||||||
struct wlr_virtual_keyboard_v1 *virtual_keyboard =
|
struct wlr_virtual_keyboard_v1 *virtual_keyboard =
|
||||||
wlr_input_device_get_virtual_keyboard(wlr_device);
|
wlr_input_device_get_virtual_keyboard(wlr_device);
|
||||||
|
|
||||||
|
|
@ -521,7 +534,6 @@ static void handle_key_event(struct sway_keyboard *keyboard,
|
||||||
event->time_msec, event->keycode, event->state);
|
event->time_msec, event->keycode, event->state);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bool pressed_sent = update_shortcut_state(
|
bool pressed_sent = update_shortcut_state(
|
||||||
&keyboard->state_pressed_sent, event->keycode, event->state,
|
&keyboard->state_pressed_sent, event->keycode, event->state,
|
||||||
|
|
@ -648,11 +660,7 @@ static void handle_modifier_event(struct sway_keyboard *keyboard) {
|
||||||
struct wlr_input_device *wlr_device =
|
struct wlr_input_device *wlr_device =
|
||||||
keyboard->seat_device->input_device->wlr_device;
|
keyboard->seat_device->input_device->wlr_device;
|
||||||
if (!wlr_device->keyboard->group) {
|
if (!wlr_device->keyboard->group) {
|
||||||
struct sway_seat *seat = keyboard->seat_device->sway_seat;
|
struct wlr_input_method_keyboard_grab_v2 *kb_grab = keyboard_get_im_grab(keyboard);
|
||||||
bool sent_to_kb_grab = false;
|
|
||||||
if (seat->im_relay.input_method) {
|
|
||||||
struct wlr_input_method_keyboard_grab_v2 *kb_grab =
|
|
||||||
seat->im_relay.input_method->keyboard_grab;
|
|
||||||
struct wlr_virtual_keyboard_v1 *virtual_keyboard =
|
struct wlr_virtual_keyboard_v1 *virtual_keyboard =
|
||||||
wlr_input_device_get_virtual_keyboard(wlr_device);
|
wlr_input_device_get_virtual_keyboard(wlr_device);
|
||||||
|
|
||||||
|
|
@ -665,12 +673,10 @@ static void handle_modifier_event(struct sway_keyboard *keyboard) {
|
||||||
wlr_device->keyboard);
|
wlr_device->keyboard);
|
||||||
wlr_input_method_keyboard_grab_v2_send_modifiers(kb_grab,
|
wlr_input_method_keyboard_grab_v2_send_modifiers(kb_grab,
|
||||||
&wlr_device->keyboard->modifiers);
|
&wlr_device->keyboard->modifiers);
|
||||||
sent_to_kb_grab = true;
|
} else {
|
||||||
}
|
struct wlr_seat *wlr_seat = keyboard->seat_device->sway_seat->wlr_seat;
|
||||||
}
|
wlr_seat_set_keyboard(wlr_seat, wlr_device);
|
||||||
if (!sent_to_kb_grab) {
|
wlr_seat_keyboard_notify_modifiers(wlr_seat,
|
||||||
wlr_seat_set_keyboard(seat->wlr_seat, wlr_device);
|
|
||||||
wlr_seat_keyboard_notify_modifiers(seat->wlr_seat,
|
|
||||||
&wlr_device->keyboard->modifiers);
|
&wlr_device->keyboard->modifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue