diff options
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/seat.c | 1 | ||||
-rw-r--r-- | sway/commands/seat/hide_cursor.c (renamed from sway/commands/hide_cursor.c) | 14 | ||||
-rw-r--r-- | sway/config.c | 2 | ||||
-rw-r--r-- | sway/config/seat.c | 5 | ||||
-rw-r--r-- | sway/input/cursor.c | 22 | ||||
-rw-r--r-- | sway/input/seat.c | 14 | ||||
-rw-r--r-- | sway/meson.build | 2 | ||||
-rw-r--r-- | sway/sway-input.5.scd | 6 | ||||
-rw-r--r-- | sway/sway.5.scd | 6 |
10 files changed, 47 insertions, 26 deletions
diff --git a/sway/commands.c b/sway/commands.c index 51bfe13a..927434bc 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -71,7 +71,6 @@ static struct cmd_handler handlers[] = { { "force_focus_wrapping", cmd_force_focus_wrapping }, { "fullscreen", cmd_fullscreen }, { "gaps", cmd_gaps }, - { "hide_cursor", cmd_hide_cursor }, { "hide_edge_borders", cmd_hide_edge_borders }, { "include", cmd_include }, { "input", cmd_input }, diff --git a/sway/commands/seat.c b/sway/commands/seat.c index 56acd204..3e7ffed9 100644 --- a/sway/commands/seat.c +++ b/sway/commands/seat.c @@ -10,6 +10,7 @@ static struct cmd_handler seat_handlers[] = { { "attach", seat_cmd_attach }, { "cursor", seat_cmd_cursor }, { "fallback", seat_cmd_fallback }, + { "hide_cursor", seat_cmd_hide_cursor }, }; struct cmd_results *cmd_seat(int argc, char **argv) { diff --git a/sway/commands/hide_cursor.c b/sway/commands/seat/hide_cursor.c index 3778fcff..343573b5 100644 --- a/sway/commands/hide_cursor.c +++ b/sway/commands/seat/hide_cursor.c @@ -2,15 +2,17 @@ #include <string.h> #include "sway/commands.h" #include "sway/config.h" -#include "sway/input/cursor.h" #include "sway/input/seat.h" #include "stringop.h" -struct cmd_results *cmd_hide_cursor(int argc, char **argv) { +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))) { return error; } + if (!config->handler_context.seat_config) { + return cmd_results_new(CMD_FAILURE, "hide_cursor", "No seat defined"); + } char *end; int timeout = strtol(argv[0], &end, 10); @@ -21,13 +23,7 @@ struct cmd_results *cmd_hide_cursor(int argc, char **argv) { if (timeout < 100 && timeout != 0) { timeout = 100; } - config->hide_cursor_timeout = timeout; - - struct sway_seat *seat; - wl_list_for_each(seat, &server.input->seats, link) { - wl_event_source_timer_update(seat->cursor->hide_source, - config->hide_cursor_timeout); - } + config->handler_context.seat_config->hide_cursor_timeout = timeout; return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/config.c b/sway/config.c index 303774b4..bb7f796d 100644 --- a/sway/config.c +++ b/sway/config.c @@ -257,8 +257,6 @@ static void config_defaults(struct sway_config *config) { config->hide_edge_borders = E_NONE; config->saved_edge_borders = E_NONE; - config->hide_cursor_timeout = 0; - // border colors set_color(config->border_colors.focused.border, 0x4C7899); set_color(config->border_colors.focused.background, 0x285577); diff --git a/sway/config/seat.c b/sway/config/seat.c index c248990a..d7316c68 100644 --- a/sway/config/seat.c +++ b/sway/config/seat.c @@ -25,6 +25,7 @@ struct seat_config *new_seat_config(const char* name) { free(seat); return NULL; } + seat->hide_cursor_timeout = -1; return seat; } @@ -137,6 +138,10 @@ void merge_seat_config(struct seat_config *dest, struct seat_config *source) { } } } + + if (source->hide_cursor_timeout != -1) { + dest->hide_cursor_timeout = source->hide_cursor_timeout; + } } struct seat_config *copy_seat_config(struct seat_config *seat) { diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 22c5b075..f8302ddf 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -597,9 +597,17 @@ static int hide_notify(void *data) { return 1; } -static void handle_activity(struct sway_cursor *cursor) { - wl_event_source_timer_update(cursor->hide_source, - config->hide_cursor_timeout); +void cursor_handle_activity(struct sway_cursor *cursor) { + struct seat_config *sc = seat_get_config(cursor->seat); + if (!sc) { + sc = seat_get_config_by_name("*"); + } + int timeout = sc ? sc->hide_cursor_timeout : 0; + if (timeout < 0) { + timeout = 0; + } + wl_event_source_timer_update(cursor->hide_source, timeout); + wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); if (cursor->hidden) { cursor->hidden = false; @@ -709,7 +717,7 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) { wlr_cursor_move(cursor->cursor, event->device, event->delta_x, event->delta_y); cursor_send_pointer_motion(cursor, event->time_msec); - handle_activity(cursor); + cursor_handle_activity(cursor); transaction_commit_dirty(); } @@ -720,7 +728,7 @@ static void handle_cursor_motion_absolute( struct wlr_event_pointer_motion_absolute *event = data; wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); cursor_send_pointer_motion(cursor, event->time_msec); - handle_activity(cursor); + cursor_handle_activity(cursor); transaction_commit_dirty(); } @@ -1009,7 +1017,7 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { struct wlr_event_pointer_button *event = data; dispatch_cursor_button(cursor, event->device, event->time_msec, event->button, event->state); - handle_activity(cursor); + cursor_handle_activity(cursor); transaction_commit_dirty(); } @@ -1119,7 +1127,7 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, axis); struct wlr_event_pointer_axis *event = data; dispatch_cursor_axis(cursor, event); - handle_activity(cursor); + cursor_handle_activity(cursor); transaction_commit_dirty(); } diff --git a/sway/input/seat.c b/sway/input/seat.c index e0f0db1d..fa82c9ce 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -995,6 +995,8 @@ void seat_apply_config(struct sway_seat *seat, wl_list_for_each(seat_device, &seat->devices, link) { seat_configure_device(seat, seat_device->input_device); } + + cursor_handle_activity(seat->cursor); } struct seat_config *seat_get_config(struct sway_seat *seat) { @@ -1009,6 +1011,18 @@ struct seat_config *seat_get_config(struct sway_seat *seat) { return NULL; } +struct seat_config *seat_get_config_by_name(const char *name) { + struct seat_config *seat_config = NULL; + for (int i = 0; i < config->seat_configs->length; ++i ) { + seat_config = config->seat_configs->items[i]; + if (strcmp(name, seat_config->name) == 0) { + return seat_config; + } + } + + return NULL; +} + void seat_begin_down(struct sway_seat *seat, struct sway_container *con, uint32_t button, double sx, double sy) { seat->operation = OP_DOWN; diff --git a/sway/meson.build b/sway/meson.build index 48ce6b45..6d446acb 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -56,7 +56,6 @@ sway_sources = files( 'commands/force_focus_wrapping.c', 'commands/fullscreen.c', 'commands/gaps.c', - 'commands/hide_cursor.c', 'commands/hide_edge_borders.c', 'commands/kill.c', 'commands/mark.c', @@ -79,6 +78,7 @@ sway_sources = files( 'commands/seat/attach.c', 'commands/seat/cursor.c', 'commands/seat/fallback.c', + 'commands/seat/hide_cursor.c', 'commands/set.c', 'commands/show_marks.c', 'commands/smart_borders.c', diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index 45994644..820194a9 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd @@ -145,6 +145,12 @@ in their own "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* <name> hide\_cursor <timeout> + Hides the cursor image after the specified _timeout_ (in milliseconds) + has elapsed with no activity on that cursor. A timeout of 0 (default) + disables hiding the cursor. The minimal timeout is 100 and any value less + than that (aside from 0), will be increased to 100. + # SEE ALSO *sway*(5) *sway-output*(5) diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 2befcfac..e6abef56 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -477,12 +477,6 @@ The default colors are: This affects new workspaces only, and is used when the workspace doesn't have its own gaps settings (see: workspace <ws> gaps ...). -*hide\_cursor* <timeout> - Hides the cursor image after the specified _timeout_ (in milliseconds) - has elapsed with no activity on that cursor. A timeout of 0 (default) - disables hiding the cursor. The minimal timeout is 100 and any value less - than that (aside from 0), will be increased to 100. - *hide\_edge\_borders* none|vertical|horizontal|both|smart|smart\_no\_gaps Hides window borders adjacent to the screen edges. Default is _none_. |