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