Make pointer disablement when using hide_cursor optional

This commit is contained in:
iguanajuice 2024-08-30 13:38:37 -04:00
parent f5ce4a4413
commit f23a380ccb
5 changed files with 28 additions and 6 deletions

View File

@ -207,6 +207,12 @@ enum seat_config_hide_cursor_when_typing {
HIDE_WHEN_TYPING_DISABLE, 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 { enum seat_config_allow_constrain {
CONSTRAIN_DEFAULT, // the default is currently enabled CONSTRAIN_DEFAULT, // the default is currently enabled
CONSTRAIN_ENABLE, CONSTRAIN_ENABLE,
@ -243,6 +249,7 @@ struct seat_config {
list_t *attachments; // list of seat_attachment configs list_t *attachments; // list of seat_attachment configs
int hide_cursor_timeout; int hide_cursor_timeout;
enum seat_config_hide_cursor_when_typing hide_cursor_when_typing; 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_allow_constrain allow_constrain;
enum seat_config_shortcuts_inhibit shortcuts_inhibit; enum seat_config_shortcuts_inhibit shortcuts_inhibit;
enum seat_keyboard_grouping keyboard_grouping; enum seat_keyboard_grouping keyboard_grouping;

View File

@ -31,12 +31,16 @@ struct cmd_results *seat_cmd_hide_cursor(int argc, char **argv) {
} }
seat_config->hide_cursor_timeout = timeout; seat_config->hide_cursor_timeout = timeout;
} else { } else {
if (strcmp(argv[0], "when-typing") != 0) { 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) ? seat_config->hide_cursor_when_typing = parse_boolean(argv[1], true) ?
HIDE_WHEN_TYPING_ENABLE : HIDE_WHEN_TYPING_DISABLE; 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 <timeout>|when-typing|but-keep-active [enable|disable]'");
}
} }
return cmd_results_new(CMD_SUCCESS, NULL); return cmd_results_new(CMD_SUCCESS, NULL);

View File

@ -29,6 +29,7 @@ struct seat_config *new_seat_config(const char* name) {
} }
seat->hide_cursor_timeout = -1; seat->hide_cursor_timeout = -1;
seat->hide_cursor_when_typing = HIDE_WHEN_TYPING_DEFAULT; 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->allow_constrain = CONSTRAIN_DEFAULT;
seat->shortcuts_inhibit = SHORTCUTS_INHIBIT_DEFAULT; seat->shortcuts_inhibit = SHORTCUTS_INHIBIT_DEFAULT;
seat->keyboard_grouping = KEYBOARD_GROUP_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; 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) { if (source->allow_constrain != CONSTRAIN_DEFAULT) {
dest->allow_constrain = source->allow_constrain; dest->allow_constrain = source->allow_constrain;
} }

View File

@ -183,7 +183,10 @@ void cursor_update_image(struct sway_cursor *cursor,
static void cursor_hide(struct sway_cursor *cursor) { static void cursor_hide(struct sway_cursor *cursor) {
wlr_cursor_unset_image(cursor->cursor); wlr_cursor_unset_image(cursor->cursor);
cursor->hidden = true; cursor->hidden = true;
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); wlr_seat_pointer_notify_clear_focus(cursor->seat->wlr_seat);
}
} }
static int hide_notify(void *data) { static int hide_notify(void *data) {

View File

@ -258,7 +258,7 @@ correct seat.
Set this seat as the fallback seat. A fallback seat will attach any device 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). not explicitly attached to another seat (similar to a "default" seat).
*seat* <name> hide_cursor <timeout>|when-typing [enable|disable] *seat* <name> hide_cursor <timeout>|when-typing|but-keep-active [enable|disable]
Hides the cursor image after the specified event occurred. Hides the cursor image after the specified event occurred.
If _timeout_ is specified, then the cursor will be hidden after _timeout_ 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 certain types of software (Gimp, Blender etc) that rely on simultaneous
input from mouse and keyboard. 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* <name> idle_inhibit <sources...> *seat* <name> idle_inhibit <sources...>
Sets the set of input event sources which can prevent the seat from 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 becoming idle, as a space separated list of source names. Valid names are