diff options
author | Tamir Zahavi-Brunner <tamir.z3@gmail.com> | 2020-09-07 01:44:13 +0300 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-10-30 09:59:54 +0100 |
commit | 96578aa91e9856bfb3e2d26fb7a625ff7c9b79e3 (patch) | |
tree | ac763cde133816f3bd8218eccbc352416ce88a5f /sway/commands | |
parent | 4799cb09606ba8b3cc3969c24637b3c6c9eac485 (diff) |
hide_cursor: Add an option to hide when typing
Add an option for the `hide_cursor` command to hide the cursor when
typing, i.e. whenever a key is pressed.
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/seat/hide_cursor.c | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/sway/commands/seat/hide_cursor.c b/sway/commands/seat/hide_cursor.c index 3bfce697..e09b82d9 100644 --- a/sway/commands/seat/hide_cursor.c +++ b/sway/commands/seat/hide_cursor.c @@ -3,26 +3,48 @@ #include "sway/commands.h" #include "sway/config.h" #include "sway/input/seat.h" +#include "sway/input/cursor.h" +#include "sway/server.h" #include "stringop.h" +#include "util.h" struct cmd_results *seat_cmd_hide_cursor(int argc, char **argv) { struct cmd_results *error = NULL; - if ((error = checkarg(argc, "hide_cursor", EXPECTED_EQUAL_TO, 1))) { + if ((error = checkarg(argc, "hide_cursor", EXPECTED_AT_LEAST, 1))) { return error; } - if (!config->handler_context.seat_config) { + if ((error = checkarg(argc, "hide_cursor", EXPECTED_AT_MOST, 2))) { + return error; + } + struct seat_config *seat_config = config->handler_context.seat_config; + if (!seat_config) { return cmd_results_new(CMD_FAILURE, "No seat defined"); } - char *end; - int timeout = strtol(argv[0], &end, 10); - if (*end) { - return cmd_results_new(CMD_INVALID, "Expected an integer timeout"); - } - if (timeout < 100 && timeout != 0) { - timeout = 100; + if (argc == 1) { + char *end; + int timeout = strtol(argv[0], &end, 10); + if (*end) { + return cmd_results_new(CMD_INVALID, "Expected an integer timeout"); + } + if (timeout < 100 && timeout != 0) { + timeout = 100; + } + seat_config->hide_cursor_timeout = timeout; + } else { + if (strcmp(argv[0], "when-typing") != 0) { + return cmd_results_new(CMD_INVALID, + "Expected 'hide_cursor <timeout>|when-typing [enable|disable]'"); + } + seat_config->hide_cursor_when_typing = parse_boolean(argv[1], true) ? + HIDE_WHEN_TYPING_ENABLE : HIDE_WHEN_TYPING_DISABLE; + + // Invalidate all the caches for this config + struct sway_seat *seat = NULL; + wl_list_for_each(seat, &server.input->seats, link) { + seat->cursor->hide_when_typing = HIDE_WHEN_TYPING_DEFAULT; + } } - config->handler_context.seat_config->hide_cursor_timeout = timeout; return cmd_results_new(CMD_SUCCESS, NULL); } |