From 4d88c957905e7f6b2c8188d218ca22b3e6986fe4 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Thu, 27 Dec 2018 00:32:15 -0500 Subject: [PATCH] hide_cursor: change to a seat subcommand This makes hide_cursor a seat subcommand, which allows for seat specific timeouts. --- include/sway/commands.h | 4 ++-- include/sway/config.h | 3 +-- include/sway/input/cursor.h | 2 ++ include/sway/input/seat.h | 2 ++ sway/commands.c | 1 - sway/commands/seat.c | 1 + sway/commands/{ => seat}/hide_cursor.c | 14 +++++--------- sway/config.c | 2 -- sway/config/seat.c | 5 +++++ sway/input/cursor.c | 22 +++++++++++++++------- sway/input/seat.c | 14 ++++++++++++++ sway/meson.build | 2 +- sway/sway-input.5.scd | 6 ++++++ sway/sway.5.scd | 6 ------ 14 files changed, 54 insertions(+), 30 deletions(-) rename sway/commands/{ => seat}/hide_cursor.c (64%) diff --git a/include/sway/commands.h b/include/sway/commands.h index 89e18c66..7bee2538 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -133,7 +133,6 @@ sway_cmd cmd_force_display_urgency_hint; sway_cmd cmd_force_focus_wrapping; sway_cmd cmd_fullscreen; sway_cmd cmd_gaps; -sway_cmd cmd_hide_cursor; sway_cmd cmd_hide_edge_borders; sway_cmd cmd_include; sway_cmd cmd_input; @@ -260,8 +259,9 @@ sway_cmd output_cmd_scale; sway_cmd output_cmd_transform; sway_cmd seat_cmd_attach; -sway_cmd seat_cmd_fallback; sway_cmd seat_cmd_cursor; +sway_cmd seat_cmd_fallback; +sway_cmd seat_cmd_hide_cursor; sway_cmd cmd_ipc_cmd; sway_cmd cmd_ipc_events; diff --git a/include/sway/config.h b/include/sway/config.h index 6610f009..86473e17 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -140,6 +140,7 @@ struct seat_config { char *name; int fallback; // -1 means not set list_t *attachments; // list of seat_attachment configs + int hide_cursor_timeout; }; enum config_dpms { @@ -436,8 +437,6 @@ struct sway_config { enum edge_border_types hide_edge_borders; enum edge_border_types saved_edge_borders; - int hide_cursor_timeout; - // border colors struct { struct border_colors focused; diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 21a26f68..78489e21 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -60,6 +60,8 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat); */ void cursor_rebase(struct sway_cursor *cursor); +void cursor_handle_activity(struct sway_cursor *cursor); + /** * Like cursor_rebase, but also allows focus to change when the cursor enters a * new container. diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index bef2af77..d665c86e 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -174,6 +174,8 @@ void seat_apply_config(struct sway_seat *seat, struct seat_config *seat_config); struct seat_config *seat_get_config(struct sway_seat *seat); +struct seat_config *seat_get_config_by_name(const char *name); + bool seat_is_input_allowed(struct sway_seat *seat, struct wlr_surface *surface); void drag_icon_update_position(struct sway_drag_icon *icon); 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 similarity index 64% rename from sway/commands/hide_cursor.c rename to 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 #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* hide\_cursor + 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 gaps ...). -*hide\_cursor* - 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_.