From f23a380ccb51c78906fc0e5ce954679ec28ed4a5 Mon Sep 17 00:00:00 2001 From: iguanajuice Date: Fri, 30 Aug 2024 13:38:37 -0400 Subject: [PATCH] Make pointer disablement when using hide_cursor optional --- include/sway/config.h | 7 +++++++ sway/commands/seat/hide_cursor.c | 12 ++++++++---- sway/config/seat.c | 5 +++++ sway/input/cursor.c | 5 ++++- sway/sway-input.5.scd | 5 ++++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index d9f561571..c659dc92a 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -207,6 +207,12 @@ enum seat_config_hide_cursor_when_typing { HIDE_WHEN_TYPING_DISABLE, }; +enum seat_config_hide_cursor_but_keep_active { + HIDE_CURSOR_BUT_KEEP_ACTIVE_DEFAULT, // the default is currently disabled + HIDE_CURSOR_BUT_KEEP_ACTIVE_ENABLE, + HIDE_CURSOR_BUT_KEEP_ACTIVE_DISABLE, +}; + enum seat_config_allow_constrain { CONSTRAIN_DEFAULT, // the default is currently enabled CONSTRAIN_ENABLE, @@ -243,6 +249,7 @@ struct seat_config { list_t *attachments; // list of seat_attachment configs int hide_cursor_timeout; enum seat_config_hide_cursor_when_typing hide_cursor_when_typing; + enum seat_config_hide_cursor_but_keep_active hide_cursor_but_keep_active; enum seat_config_allow_constrain allow_constrain; enum seat_config_shortcuts_inhibit shortcuts_inhibit; enum seat_keyboard_grouping keyboard_grouping; diff --git a/sway/commands/seat/hide_cursor.c b/sway/commands/seat/hide_cursor.c index 2ad74e7bf..b804a442e 100644 --- a/sway/commands/seat/hide_cursor.c +++ b/sway/commands/seat/hide_cursor.c @@ -31,12 +31,16 @@ struct cmd_results *seat_cmd_hide_cursor(int argc, char **argv) { } seat_config->hide_cursor_timeout = timeout; } else { - if (strcmp(argv[0], "when-typing") != 0) { + if (strcmp(argv[0], "when-typing") == 0) { + seat_config->hide_cursor_when_typing = parse_boolean(argv[1], true) ? + HIDE_WHEN_TYPING_ENABLE : HIDE_WHEN_TYPING_DISABLE; + } else if (strcmp(argv[0], "but-keep-active") == 0) { + seat_config->hide_cursor_but_keep_active = parse_boolean(argv[1], true) ? + HIDE_CURSOR_BUT_KEEP_ACTIVE_ENABLE : HIDE_CURSOR_BUT_KEEP_ACTIVE_DISABLE; + } else { return cmd_results_new(CMD_INVALID, - "Expected 'hide_cursor |when-typing [enable|disable]'"); + "Expected 'hide_cursor |when-typing|but-keep-active [enable|disable]'"); } - seat_config->hide_cursor_when_typing = parse_boolean(argv[1], true) ? - HIDE_WHEN_TYPING_ENABLE : HIDE_WHEN_TYPING_DISABLE; } return cmd_results_new(CMD_SUCCESS, NULL); diff --git a/sway/config/seat.c b/sway/config/seat.c index f2326189e..1c1c40df2 100644 --- a/sway/config/seat.c +++ b/sway/config/seat.c @@ -29,6 +29,7 @@ struct seat_config *new_seat_config(const char* name) { } seat->hide_cursor_timeout = -1; seat->hide_cursor_when_typing = HIDE_WHEN_TYPING_DEFAULT; + seat->hide_cursor_but_keep_active = HIDE_CURSOR_BUT_KEEP_ACTIVE_DEFAULT; seat->allow_constrain = CONSTRAIN_DEFAULT; seat->shortcuts_inhibit = SHORTCUTS_INHIBIT_DEFAULT; seat->keyboard_grouping = KEYBOARD_GROUP_DEFAULT; @@ -154,6 +155,10 @@ void merge_seat_config(struct seat_config *dest, struct seat_config *source) { dest->hide_cursor_when_typing = source->hide_cursor_when_typing; } + if (source->hide_cursor_but_keep_active != HIDE_CURSOR_BUT_KEEP_ACTIVE_DEFAULT) { + dest->hide_cursor_but_keep_active = source->hide_cursor_but_keep_active; + } + if (source->allow_constrain != CONSTRAIN_DEFAULT) { dest->allow_constrain = source->allow_constrain; } diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 025995a4a..b25679550 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -183,7 +183,10 @@ void cursor_update_image(struct sway_cursor *cursor, static void cursor_hide(struct sway_cursor *cursor) { wlr_cursor_unset_image(cursor->cursor); cursor->hidden = true; - wlr_seat_pointer_notify_clear_focus(cursor->seat->wlr_seat); + if (cursor->seat->config->hide_cursor_but_keep_active + != HIDE_CURSOR_BUT_KEEP_ACTIVE_ENABLE) { + wlr_seat_pointer_notify_clear_focus(cursor->seat->wlr_seat); + } } static int hide_notify(void *data) { diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index fbef2a321..5ae7e66b3 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd @@ -258,7 +258,7 @@ correct seat. Set this seat as the fallback seat. A fallback seat will attach any device not explicitly attached to another seat (similar to a "default" seat). -*seat* hide_cursor |when-typing [enable|disable] +*seat* hide_cursor |when-typing|but-keep-active [enable|disable] Hides the cursor image after the specified event occurred. If _timeout_ is specified, then the cursor will be hidden after _timeout_ @@ -273,6 +273,9 @@ correct seat. certain types of software (Gimp, Blender etc) that rely on simultaneous input from mouse and keyboard. + If _but-keep-active_ is enabled, then the cursor will remain active when + hidden. This solves the issues with _when-typing_ as mentioned above. + *seat* idle_inhibit Sets the set of input event sources which can prevent the seat from becoming idle, as a space separated list of source names. Valid names are