From 9d2e7b7e64db1a63d19998159d3a8818f02826b3 Mon Sep 17 00:00:00 2001 From: Connor E <38229097+c-edw@users.noreply.github.com> Date: Tue, 6 Nov 2018 17:15:47 +0000 Subject: [PATCH] Add focus_follows_mouse_mode. --- include/sway/config.h | 8 +++++++- sway/commands/focus_follows_mouse.c | 9 +++++++-- sway/config.c | 2 +- sway/input/cursor.c | 8 +++++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index 852d55767..0912bc73b 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -327,6 +327,12 @@ struct ipc_policy { uint32_t features; }; +enum focus_follows_mouse_mode { + FOLLOWS_NO, + FOLLOWS_YES, + FOLLOWS_ALWAYS +}; + enum focus_wrapping_mode { WRAP_NO, WRAP_YES, @@ -378,7 +384,7 @@ struct sway_config { enum sway_popup_during_fullscreen popup_during_fullscreen; // Flags - bool focus_follows_mouse; + enum focus_follows_mouse_mode focus_follows_mouse; enum mouse_warping_mode mouse_warping; enum focus_wrapping_mode focus_wrapping; bool active; diff --git a/sway/commands/focus_follows_mouse.c b/sway/commands/focus_follows_mouse.c index 0b0e334ce..fbfea5056 100644 --- a/sway/commands/focus_follows_mouse.c +++ b/sway/commands/focus_follows_mouse.c @@ -8,7 +8,12 @@ struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) { if ((error = checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1))) { return error; } - config->focus_follows_mouse = - parse_boolean(argv[0], config->focus_follows_mouse); + if(strcmp(argv[0], "no") == 0) { + config->focus_follows_mouse = FOLLOWS_NO; + } else if(strcmp(argv[0], "yes") == 0) { + config->focus_follows_mouse = FOLLOWS_YES; + } else if(strcmp(argv[0], "always") == 0) { + config->focus_follows_mouse = FOLLOWS_ALWAYS; + } return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/config.c b/sway/config.c index 7ef3ef382..64653024d 100644 --- a/sway/config.c +++ b/sway/config.c @@ -220,7 +220,7 @@ static void config_defaults(struct sway_config *config) { config->floating_minimum_height = 50; // Flags - config->focus_follows_mouse = true; + config->focus_follows_mouse = FOLLOWS_YES; config->mouse_warping = WARP_OUTPUT; config->focus_wrapping = WRAP_YES; config->validating = false; diff --git a/sway/input/cursor.c b/sway/input/cursor.c index c539df40b..0f67a7b19 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -637,7 +637,8 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, cursor->previous.y = cursor->cursor->y; cursor->previous.node = node; - if (node && config->focus_follows_mouse) { + if (node && (config->focus_follows_mouse == FOLLOWS_YES || + config->focus_follows_mouse == FOLLOWS_ALWAYS)) { struct sway_node *focus = seat_get_focus(seat); if (focus && node->type == N_WORKSPACE) { // Only follow the mouse if it would move to a new output @@ -652,9 +653,10 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, // - cursor is over a new view, i.e. entered a new window; and // - the new view is visible, i.e. not hidden in a stack or tab; and // - the seat does not have a keyboard grab - if (!wlr_seat_keyboard_has_grab(cursor->seat->wlr_seat) && + if ((!wlr_seat_keyboard_has_grab(cursor->seat->wlr_seat) && node != prev_node && - view_is_visible(node->sway_container->view)) { + view_is_visible(node->sway_container->view)) || + config->focus_follows_mouse == FOLLOWS_ALWAYS) { seat_set_focus(seat, node); } else { struct sway_node *next_focus =