mirror of
https://github.com/swaywm/sway.git
synced 2024-11-09 18:03:14 +00:00
input/keyboard: refactor into sway_keyboard_set_layout
This commit is contained in:
parent
0386b2afcb
commit
4c3c060211
|
@ -961,16 +961,8 @@ cleanup:
|
|||
free(sway_group);
|
||||
}
|
||||
|
||||
void sway_keyboard_configure(struct sway_keyboard *keyboard) {
|
||||
struct input_config *input_config =
|
||||
input_device_get_config(keyboard->seat_device->input_device);
|
||||
|
||||
if (!sway_assert(!wlr_keyboard_group_from_wlr_keyboard(keyboard->wlr),
|
||||
"sway_keyboard_configure should not be called with a "
|
||||
"keyboard group's keyboard")) {
|
||||
return;
|
||||
}
|
||||
|
||||
static void sway_keyboard_set_layout(struct sway_keyboard *keyboard,
|
||||
struct input_config *input_config) {
|
||||
struct xkb_keymap *keymap = sway_keyboard_compile_keymap(input_config, NULL);
|
||||
if (!keymap) {
|
||||
sway_log(SWAY_ERROR, "Failed to compile keymap. Attempting defaults");
|
||||
|
@ -986,31 +978,13 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
|
|||
!wlr_keyboard_keymaps_match(keyboard->keymap, keymap) : true;
|
||||
bool effective_layout_changed = keyboard->effective_layout != 0;
|
||||
|
||||
int repeat_rate = 25;
|
||||
if (input_config && input_config->repeat_rate != INT_MIN) {
|
||||
repeat_rate = input_config->repeat_rate;
|
||||
}
|
||||
int repeat_delay = 600;
|
||||
if (input_config && input_config->repeat_delay != INT_MIN) {
|
||||
repeat_delay = input_config->repeat_delay;
|
||||
}
|
||||
|
||||
bool repeat_info_changed = keyboard->repeat_rate != repeat_rate ||
|
||||
keyboard->repeat_delay != repeat_delay;
|
||||
|
||||
if (keymap_changed || repeat_info_changed || config->reloading) {
|
||||
if (keymap_changed || config->reloading) {
|
||||
xkb_keymap_unref(keyboard->keymap);
|
||||
keyboard->keymap = keymap;
|
||||
keyboard->effective_layout = 0;
|
||||
keyboard->repeat_rate = repeat_rate;
|
||||
keyboard->repeat_delay = repeat_delay;
|
||||
|
||||
sway_keyboard_group_remove_invalid(keyboard);
|
||||
|
||||
wlr_keyboard_set_keymap(keyboard->wlr, keyboard->keymap);
|
||||
wlr_keyboard_set_repeat_info(keyboard->wlr,
|
||||
keyboard->repeat_rate, keyboard->repeat_delay);
|
||||
|
||||
if (!keyboard->wlr->group) {
|
||||
sway_keyboard_group_add(keyboard);
|
||||
}
|
||||
|
@ -1061,6 +1035,47 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
|
|||
wlr_seat_set_keyboard(seat, keyboard->wlr);
|
||||
}
|
||||
|
||||
if (keymap_changed) {
|
||||
ipc_event_input("xkb_keymap",
|
||||
keyboard->seat_device->input_device);
|
||||
} else if (effective_layout_changed) {
|
||||
ipc_event_input("xkb_layout",
|
||||
keyboard->seat_device->input_device);
|
||||
}
|
||||
}
|
||||
|
||||
void sway_keyboard_configure(struct sway_keyboard *keyboard) {
|
||||
struct input_config *input_config =
|
||||
input_device_get_config(keyboard->seat_device->input_device);
|
||||
|
||||
if (!sway_assert(!wlr_keyboard_group_from_wlr_keyboard(keyboard->wlr),
|
||||
"sway_keyboard_configure should not be called with a "
|
||||
"keyboard group's keyboard")) {
|
||||
return;
|
||||
}
|
||||
|
||||
int repeat_rate = 25;
|
||||
if (input_config && input_config->repeat_rate != INT_MIN) {
|
||||
repeat_rate = input_config->repeat_rate;
|
||||
}
|
||||
int repeat_delay = 600;
|
||||
if (input_config && input_config->repeat_delay != INT_MIN) {
|
||||
repeat_delay = input_config->repeat_delay;
|
||||
}
|
||||
|
||||
bool repeat_info_changed = keyboard->repeat_rate != repeat_rate ||
|
||||
keyboard->repeat_delay != repeat_delay;
|
||||
|
||||
if (repeat_info_changed || config->reloading) {
|
||||
keyboard->repeat_rate = repeat_rate;
|
||||
keyboard->repeat_delay = repeat_delay;
|
||||
|
||||
wlr_keyboard_set_repeat_info(keyboard->wlr,
|
||||
keyboard->repeat_rate, keyboard->repeat_delay);
|
||||
}
|
||||
|
||||
sway_keyboard_set_layout(keyboard, input_config);
|
||||
|
||||
wl_list_remove(&keyboard->keyboard_key.link);
|
||||
wl_signal_add(&keyboard->wlr->events.key, &keyboard->keyboard_key);
|
||||
keyboard->keyboard_key.notify = handle_keyboard_key;
|
||||
|
@ -1070,13 +1085,6 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
|
|||
&keyboard->keyboard_modifiers);
|
||||
keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers;
|
||||
|
||||
if (keymap_changed) {
|
||||
ipc_event_input("xkb_keymap",
|
||||
keyboard->seat_device->input_device);
|
||||
} else if (effective_layout_changed) {
|
||||
ipc_event_input("xkb_layout",
|
||||
keyboard->seat_device->input_device);
|
||||
}
|
||||
}
|
||||
|
||||
void sway_keyboard_destroy(struct sway_keyboard *keyboard) {
|
||||
|
|
Loading…
Reference in a new issue