From 481accca2adb59ef1302d5434643846a2b0f7557 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sun, 18 Nov 2018 19:50:24 +0300 Subject: [PATCH] add an option to manage when keyboard layout is changed This patch adds an option, but the actual functional for it to control being added in next one. To keep keyboard layout per window add in sway config: seat * keep_keyboard_layout per_window To keep keyboard layout globally either do not add anything (it's the default), or to explicitly enable it use the following: seat * keep_keyboard_layout global Signed-off-by: Konstantin Kharlamov --- include/sway/commands.h | 1 + include/sway/config.h | 7 ++++++ sway/commands/seat.c | 1 + sway/commands/seat/keep_keyboard_layout.c | 29 +++++++++++++++++++++++ sway/meson.build | 1 + sway/sway-input.5.scd | 3 +++ 6 files changed, 42 insertions(+) create mode 100644 sway/commands/seat/keep_keyboard_layout.c diff --git a/include/sway/commands.h b/include/sway/commands.h index c4903788c..d1fb42fae 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -277,6 +277,7 @@ sway_cmd seat_cmd_attach; sway_cmd seat_cmd_cursor; sway_cmd seat_cmd_fallback; sway_cmd seat_cmd_hide_cursor; +sway_cmd seat_cmd_keep_keyboard_layout; sway_cmd seat_cmd_pointer_constraint; sway_cmd cmd_ipc_cmd; diff --git a/include/sway/config.h b/include/sway/config.h index b94a35f3f..e4a4823d5 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -41,6 +41,12 @@ enum binding_flags { BINDING_CODE=32, // keyboard only; convert keysyms into keycodes }; +enum sway_keep_keyboard_layout { + KEYBOARD_LAYOUT_UNDEFINED = 0, + KEYBOARD_LAYOUT_GLOBAL, + KEYBOARD_LAYOUT_PER_WINDOW +}; + /** * A key binding and an associated command. */ @@ -165,6 +171,7 @@ struct seat_config { list_t *attachments; // list of seat_attachment configs int hide_cursor_timeout; enum seat_config_allow_constrain allow_constrain; + enum sway_keep_keyboard_layout keep_keyboard_layout; }; enum config_dpms { diff --git a/sway/commands/seat.c b/sway/commands/seat.c index aa36ba955..9570a74aa 100644 --- a/sway/commands/seat.c +++ b/sway/commands/seat.c @@ -12,6 +12,7 @@ static struct cmd_handler seat_handlers[] = { { "cursor", seat_cmd_cursor }, { "fallback", seat_cmd_fallback }, { "hide_cursor", seat_cmd_hide_cursor }, + { "keep_keyboard_layout", seat_cmd_keep_keyboard_layout }, { "pointer_constraint", seat_cmd_pointer_constraint }, }; diff --git a/sway/commands/seat/keep_keyboard_layout.c b/sway/commands/seat/keep_keyboard_layout.c new file mode 100644 index 000000000..3788205ed --- /dev/null +++ b/sway/commands/seat/keep_keyboard_layout.c @@ -0,0 +1,29 @@ +#include "log.h" +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/input/input-manager.h" + +struct cmd_results *seat_cmd_keep_keyboard_layout(int argc, char **argv) { + const char *STR_LAYOUT_GLOBAL = "global", + *STR_LAYOUT_PER_WINDOW = "per_window"; + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "keep_keyboard_layout", EXPECTED_EQUAL_TO, 1))) { + return error; + } + if (!config->handler_context.seat_config) { + return cmd_results_new(CMD_FAILURE, "No seat defined"); + } + + if (!strcmp(argv[0], STR_LAYOUT_GLOBAL)) { + config->handler_context.seat_config->keep_keyboard_layout + = KEYBOARD_LAYOUT_GLOBAL; + return cmd_results_new(CMD_SUCCESS, NULL, NULL); + } else if (!strcmp(argv[0], STR_LAYOUT_PER_WINDOW)) { + config->handler_context.seat_config->keep_keyboard_layout + = KEYBOARD_LAYOUT_PER_WINDOW; + return cmd_results_new(CMD_SUCCESS, NULL, NULL); + } else { + return cmd_results_new(CMD_FAILURE, "keep_keyboard_layout", + "Expected 'keep_keyboard_layout global|per_window"); + } +} diff --git a/sway/meson.build b/sway/meson.build index 05cece7a4..5bd0a204d 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -88,6 +88,7 @@ sway_sources = files( 'commands/seat/cursor.c', 'commands/seat/fallback.c', 'commands/seat/hide_cursor.c', + 'commands/seat/keep_keyboard_layout.c', 'commands/seat/pointer_constraint.c', 'commands/set.c', 'commands/show_marks.c', diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index efd3d1afc..e032b8ecf 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd @@ -201,6 +201,9 @@ correct seat. disables hiding the cursor. The minimal timeout is 100 and any value less than that (aside from 0), will be increased to 100. +*seat* keep_keyboard_layout global|per_window + Controls whether to keep keyboard layout per window. Default is _global_. + *seat* pointer_constraint enable|disable|escape Enables or disables the ability for clients to capture the cursor (enabled by default) for the seat. This is primarily useful for video games. The