aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-05-27 23:20:21 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-05-27 23:20:21 -0400
commit46da1dc32bd6c101964d32bb698e8187fb9ee91e (patch)
treee713b194254bf6d43214a394459c1b94e64bbacb
parentMerge pull request #2050 from smlx/focus-fix (diff)
downloadsway-46da1dc32bd6c101964d32bb698e8187fb9ee91e.tar.gz
sway-46da1dc32bd6c101964d32bb698e8187fb9ee91e.tar.zst
sway-46da1dc32bd6c101964d32bb698e8187fb9ee91e.zip
Implement focus_wrapping
-rw-r--r--include/sway/commands.h2
-rw-r--r--include/sway/config.h8
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/focus_wrapping.c23
-rw-r--r--sway/config.c1
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway.5.scd9
-rw-r--r--sway/tree/layout.c24
8 files changed, 59 insertions, 10 deletions
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;
106sway_cmd cmd_floating_scroll; 106sway_cmd cmd_floating_scroll;
107sway_cmd cmd_focus; 107sway_cmd cmd_focus;
108sway_cmd cmd_focus_follows_mouse; 108sway_cmd cmd_focus_follows_mouse;
109sway_cmd cmd_focus_wrapping;
109sway_cmd cmd_font; 110sway_cmd cmd_font;
110sway_cmd cmd_for_window; 111sway_cmd cmd_for_window;
111sway_cmd cmd_force_focus_wrapping;
112sway_cmd cmd_fullscreen; 112sway_cmd cmd_fullscreen;
113sway_cmd cmd_gaps; 113sway_cmd cmd_gaps;
114sway_cmd cmd_hide_edge_borders; 114sway_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 {
285 uint32_t features; 285 uint32_t features;
286}; 286};
287 287
288enum focus_wrapping_mode {
289 WRAP_NO,
290 WRAP_YES,
291 WRAP_FORCE
292};
293
288/** 294/**
289 * The configuration struct. The result of loading a config file. 295 * The configuration struct. The result of loading a config file.
290 */ 296 */
@@ -320,7 +326,7 @@ struct sway_config {
320 // Flags 326 // Flags
321 bool focus_follows_mouse; 327 bool focus_follows_mouse;
322 bool mouse_warping; 328 bool mouse_warping;
323 bool force_focus_wrapping; 329 enum focus_wrapping_mode focus_wrapping;
324 bool active; 330 bool active;
325 bool failed; 331 bool failed;
326 bool reloading; 332 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[] = {
106 { "exec", cmd_exec }, 106 { "exec", cmd_exec },
107 { "exec_always", cmd_exec_always }, 107 { "exec_always", cmd_exec_always },
108 { "focus_follows_mouse", cmd_focus_follows_mouse }, 108 { "focus_follows_mouse", cmd_focus_follows_mouse },
109 { "focus_wrapping", cmd_focus_wrapping },
109 { "font", cmd_font }, 110 { "font", cmd_font },
110 { "for_window", cmd_for_window }, 111 { "for_window", cmd_for_window },
111 { "fullscreen", cmd_fullscreen }, 112 { "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 @@
1#include <strings.h>
2#include "sway/commands.h"
3#include "sway/config.h"
4
5struct cmd_results *cmd_focus_wrapping(int argc, char **argv) {
6 struct cmd_results *error = NULL;
7 if ((error = checkarg(argc, "focus_wrapping", EXPECTED_EQUAL_TO, 1))) {
8 return error;
9 }
10
11 if (strcasecmp(argv[0], "no") == 0) {
12 config->focus_wrapping = WRAP_NO;
13 } else if (strcasecmp(argv[0], "yes") == 0) {
14 config->focus_wrapping = WRAP_YES;
15 } else if (strcasecmp(argv[0], "force") == 0) {
16 config->focus_wrapping = WRAP_FORCE;
17 } else {
18 return cmd_results_new(CMD_INVALID, "focus_wrapping",
19 "Expected 'focus_wrapping yes|no|force'");
20 }
21
22 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
23}
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) {
184 // Flags 184 // Flags
185 config->focus_follows_mouse = true; 185 config->focus_follows_mouse = true;
186 config->mouse_warping = true; 186 config->mouse_warping = true;
187 config->focus_wrapping = WRAP_YES;
187 config->reloading = false; 188 config->reloading = false;
188 config->active = false; 189 config->active = false;
189 config->failed = false; 190 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(
38 'commands/exec_always.c', 38 'commands/exec_always.c',
39 'commands/focus.c', 39 'commands/focus.c',
40 'commands/focus_follows_mouse.c', 40 'commands/focus_follows_mouse.c',
41 'commands/focus_wrapping.c',
41 'commands/font.c', 42 'commands/font.c',
42 'commands/for_window.c', 43 'commands/for_window.c',
43 'commands/fullscreen.c', 44 '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:
328*focus\_follows\_mouse* yes|no 328*focus\_follows\_mouse* yes|no
329 If set to _yes_, moving your mouse over a window will focus that window. 329 If set to _yes_, moving your mouse over a window will focus that window.
330 330
331*focus\_wrapping* yes|no|force
332 This option determines what to do when attempting to focus over the edge
333 of a container. If set to _no_, the focused container will retain focus,
334 if there are no other containers in the direction. If set to _yes_, focus
335 will be wrapped to the opposite edge of the container, if there are no
336 other containers in the direction. If set to _force_, focus will be wrapped
337 to the opposite edge of the container, even if there are other containers
338 in the direction. Default is _yes_.
339
331*font* <font> 340*font* <font>
332 Sets font for use in title bars in Pango format. 341 Sets font for use in title bars in Pango format.
333 342
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(
708 sway_output_from_wlr(wlr_adjacent); 708 sway_output_from_wlr(wlr_adjacent);
709 709
710 if (!adjacent || adjacent == container) { 710 if (!adjacent || adjacent == container) {
711 return wrap_candidate; 711 if (!wrap_candidate) {
712 return NULL;
713 }
714 return seat_get_focus_inactive_view(seat, wrap_candidate);
712 } 715 }
713 struct sway_container *next = 716 struct sway_container *next =
714 get_swayc_in_output_direction(adjacent, dir, seat); 717 get_swayc_in_output_direction(adjacent, dir, seat);
@@ -748,23 +751,25 @@ struct sway_container *container_get_in_direction(
748 if (desired < 0 || desired >= parent->children->length) { 751 if (desired < 0 || desired >= parent->children->length) {
749 can_move = false; 752 can_move = false;
750 int len = parent->children->length; 753 int len = parent->children->length;
751 if (!wrap_candidate && len > 1) { 754 if (config->focus_wrapping != WRAP_NO && !wrap_candidate
755 && len > 1) {
752 if (desired < 0) { 756 if (desired < 0) {
753 wrap_candidate = parent->children->items[len-1]; 757 wrap_candidate = parent->children->items[len-1];
754 } else { 758 } else {
755 wrap_candidate = parent->children->items[0]; 759 wrap_candidate = parent->children->items[0];
756 } 760 }
757 if (config->force_focus_wrapping) { 761 if (config->focus_wrapping == WRAP_FORCE) {
758 return wrap_candidate; 762 return seat_get_focus_inactive_view(seat,
763 wrap_candidate);
759 } 764 }
760 } 765 }
761 } else { 766 } else {
762 struct sway_container *desired_con = parent->children->items[desired]; 767 struct sway_container *desired_con =
768 parent->children->items[desired];
763 wlr_log(L_DEBUG, 769 wlr_log(L_DEBUG,
764 "cont %d-%p dir %i sibling %d: %p", idx, 770 "cont %d-%p dir %i sibling %d: %p", idx,
765 container, dir, desired, desired_con); 771 container, dir, desired, desired_con);
766 struct sway_container *next = seat_get_focus_inactive_view(seat, desired_con); 772 return seat_get_focus_inactive_view(seat, desired_con);
767 return next;
768 } 773 }
769 } 774 }
770 775
@@ -773,7 +778,10 @@ struct sway_container *container_get_in_direction(
773 parent = parent->parent; 778 parent = parent->parent;
774 if (!parent) { 779 if (!parent) {
775 // wrapping is the last chance 780 // wrapping is the last chance
776 return wrap_candidate; 781 if (!wrap_candidate) {
782 return NULL;
783 }
784 return seat_get_focus_inactive_view(seat, wrap_candidate);
777 } 785 }
778 } 786 }
779 } 787 }