Implement seat subcommand hide_cursor_while_typing

This implements the following seat subcommand:
  `hide_cursor_while_typing <timeout>`

If timeout is set to a positive value (of at least 100), the cursor
will be hidden when typing and will not be unhidden until the timeout
has expired after the last key has been released.

This also changes the way cursor hiding/unhiding is managed to allow
for both `hide_cursor` and `hide_cursor_while_typing` to be used in
conjunction with each other for complex cursor hiding rules.
This commit is contained in:
Brian Ashworth 2019-03-25 01:37:44 -04:00
parent d9de5b8758
commit f1654af50f
11 changed files with 161 additions and 33 deletions

View file

@ -269,6 +269,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_hide_cursor_while_typing;
sway_cmd seat_cmd_pointer_constraint;
sway_cmd cmd_ipc_cmd;

View file

@ -161,7 +161,8 @@ struct seat_config {
char *name;
int fallback; // -1 means not set
list_t *attachments; // list of seat_attachment configs
int hide_cursor_timeout;
int hide_cursor_timeout; // idle timeout
int hide_cursor_typing_timeout;
enum seat_config_allow_constrain allow_constrain;
};

View file

@ -13,6 +13,12 @@
#define SWAY_SCROLL_LEFT KEY_MAX + 3
#define SWAY_SCROLL_RIGHT KEY_MAX + 4
enum sway_cursor_hidden_reason {
CURSOR_VISIBLE = 0,
CURSOR_HIDDEN_IDLE = 1,
CURSOR_HIDDEN_TYPING = 2,
};
struct sway_cursor {
struct sway_seat *seat;
struct wlr_cursor *cursor;
@ -49,8 +55,9 @@ struct sway_cursor {
struct wl_listener constraint_commit;
struct wl_event_source *hide_source;
bool hidden;
struct wl_event_source *hide_source; // idle
struct wl_event_source *hide_source_typing;
uint32_t hidden; // bitfield of enum sway_cursor_hidden_reason
size_t pressed_button_count;
};
@ -73,8 +80,18 @@ void cursor_rebase(struct sway_cursor *cursor);
void cursor_rebase_all(void);
void cursor_handle_activity(struct sway_cursor *cursor);
void cursor_unhide(struct sway_cursor *cursor);
int cursor_get_timeout(struct sway_cursor *cursor);
void cursor_hide(struct sway_cursor *cursor,
enum sway_cursor_hidden_reason reason);
// Removes the cursor hidden reason and if all reasons are removed, unhides the
// cursor. If CURSOR_VISIBLE is given as the reason, all reasons will be
// removed and the cursor will be unhidden.
void cursor_unhide(struct sway_cursor *cursor,
enum sway_cursor_hidden_reason reason);
int cursor_get_timeout(struct sway_cursor *cursor,
enum sway_cursor_hidden_reason reason);
void dispatch_cursor_button(struct sway_cursor *cursor,
struct wlr_input_device *device, uint32_t time_msec, uint32_t button,