mirror of
https://github.com/swaywm/sway.git
synced 2024-11-23 00:11:28 +00:00
Merge pull request #2060 from RedSoxFan/focus-wrapping
Implement focus_wrapping
This commit is contained in:
commit
1071785f56
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 },
|
||||
|
|
23
sway/commands/focus_wrapping.c
Normal file
23
sway/commands/focus_wrapping.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include <strings.h>
|
||||
#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);
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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* <font>
|
||||
Sets font for use in title bars in Pango format.
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue