diff --git a/include/sway/commands.h b/include/sway/commands.h index 365068ae..87a8c23a 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -106,9 +106,9 @@ sway_cmd cmd_floating_mod; sway_cmd cmd_floating_scroll; sway_cmd cmd_focus; sway_cmd cmd_focus_follows_mouse; +sway_cmd cmd_focus_wrapping; sway_cmd cmd_font; sway_cmd cmd_for_window; -sway_cmd cmd_force_focus_wrapping; sway_cmd cmd_fullscreen; sway_cmd cmd_gaps; sway_cmd cmd_hide_edge_borders; diff --git a/include/sway/config.h b/include/sway/config.h index 118981e3..de651ea4 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -285,6 +285,12 @@ struct ipc_policy { uint32_t features; }; +enum focus_wrapping_mode { + WRAP_NO, + WRAP_YES, + WRAP_FORCE +}; + /** * The configuration struct. The result of loading a config file. */ @@ -320,7 +326,7 @@ struct sway_config { // Flags bool focus_follows_mouse; bool mouse_warping; - bool force_focus_wrapping; + enum focus_wrapping_mode focus_wrapping; bool active; bool failed; bool reloading; diff --git a/sway/commands.c b/sway/commands.c index c3728afd..be16a4b4 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -106,6 +106,7 @@ static struct cmd_handler handlers[] = { { "exec", cmd_exec }, { "exec_always", cmd_exec_always }, { "focus_follows_mouse", cmd_focus_follows_mouse }, + { "focus_wrapping", cmd_focus_wrapping }, { "font", cmd_font }, { "for_window", cmd_for_window }, { "fullscreen", cmd_fullscreen }, diff --git a/sway/commands/focus_wrapping.c b/sway/commands/focus_wrapping.c new file mode 100644 index 00000000..0a9e0bf2 --- /dev/null +++ b/sway/commands/focus_wrapping.c @@ -0,0 +1,23 @@ +#include +#include "sway/commands.h" +#include "sway/config.h" + +struct cmd_results *cmd_focus_wrapping(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "focus_wrapping", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + if (strcasecmp(argv[0], "no") == 0) { + config->focus_wrapping = WRAP_NO; + } else if (strcasecmp(argv[0], "yes") == 0) { + config->focus_wrapping = WRAP_YES; + } else if (strcasecmp(argv[0], "force") == 0) { + config->focus_wrapping = WRAP_FORCE; + } else { + return cmd_results_new(CMD_INVALID, "focus_wrapping", + "Expected 'focus_wrapping yes|no|force'"); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/config.c b/sway/config.c index 34c8a280..cf05c236 100644 --- a/sway/config.c +++ b/sway/config.c @@ -184,6 +184,7 @@ static void config_defaults(struct sway_config *config) { // Flags config->focus_follows_mouse = true; config->mouse_warping = true; + config->focus_wrapping = WRAP_YES; config->reloading = false; config->active = false; config->failed = false; diff --git a/sway/meson.build b/sway/meson.build index 9c942e8e..76c312ba 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -38,6 +38,7 @@ sway_sources = files( 'commands/exec_always.c', 'commands/focus.c', 'commands/focus_follows_mouse.c', + 'commands/focus_wrapping.c', 'commands/font.c', 'commands/for_window.c', 'commands/fullscreen.c', diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 5d99c9d6..10990fc4 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -328,6 +328,15 @@ The default colors are: *focus\_follows\_mouse* yes|no If set to _yes_, moving your mouse over a window will focus that window. +*focus\_wrapping* yes|no|force + This option determines what to do when attempting to focus over the edge + of a container. If set to _no_, the focused container will retain focus, + if there are no other containers in the direction. If set to _yes_, focus + will be wrapped to the opposite edge of the container, if there are no + other containers in the direction. If set to _force_, focus will be wrapped + to the opposite edge of the container, even if there are other containers + in the direction. Default is _yes_. + *font* Sets font for use in title bars in Pango format. diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 624d5516..6d76ae0f 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -708,7 +708,10 @@ struct sway_container *container_get_in_direction( sway_output_from_wlr(wlr_adjacent); if (!adjacent || adjacent == container) { - return wrap_candidate; + if (!wrap_candidate) { + return NULL; + } + return seat_get_focus_inactive_view(seat, wrap_candidate); } struct sway_container *next = get_swayc_in_output_direction(adjacent, dir, seat); @@ -748,23 +751,25 @@ struct sway_container *container_get_in_direction( if (desired < 0 || desired >= parent->children->length) { can_move = false; int len = parent->children->length; - if (!wrap_candidate && len > 1) { + if (config->focus_wrapping != WRAP_NO && !wrap_candidate + && len > 1) { if (desired < 0) { wrap_candidate = parent->children->items[len-1]; } else { wrap_candidate = parent->children->items[0]; } - if (config->force_focus_wrapping) { - return wrap_candidate; + if (config->focus_wrapping == WRAP_FORCE) { + return seat_get_focus_inactive_view(seat, + wrap_candidate); } } } else { - struct sway_container *desired_con = parent->children->items[desired]; + struct sway_container *desired_con = + parent->children->items[desired]; wlr_log(L_DEBUG, "cont %d-%p dir %i sibling %d: %p", idx, container, dir, desired, desired_con); - struct sway_container *next = seat_get_focus_inactive_view(seat, desired_con); - return next; + return seat_get_focus_inactive_view(seat, desired_con); } } @@ -773,7 +778,10 @@ struct sway_container *container_get_in_direction( parent = parent->parent; if (!parent) { // wrapping is the last chance - return wrap_candidate; + if (!wrap_candidate) { + return NULL; + } + return seat_get_focus_inactive_view(seat, wrap_candidate); } } }