aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2016-10-07 08:40:18 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2016-10-12 21:42:42 -0400
commita92d427b3753af16758efb60c6bf4a44871620d6 (patch)
treeda8f823ce7038ca8a7f036819f0b339ae976cba6
parentMerge pull request #936 from thejan2009/pango-numeric-char-ref (diff)
downloadsway-a92d427b3753af16758efb60c6bf4a44871620d6.tar.gz
sway-a92d427b3753af16758efb60c6bf4a44871620d6.tar.zst
sway-a92d427b3753af16758efb60c6bf4a44871620d6.zip
Merge pull request #935 from thejan2009/wrap-focus-change
Wrap focus change
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/config.h1
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/force_focus_wrapping.c12
-rw-r--r--sway/layout.c35
5 files changed, 46 insertions, 4 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index f646c412..fe67c58c 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -106,6 +106,7 @@ sway_cmd cmd_focus;
106sway_cmd cmd_focus_follows_mouse; 106sway_cmd cmd_focus_follows_mouse;
107sway_cmd cmd_font; 107sway_cmd cmd_font;
108sway_cmd cmd_for_window; 108sway_cmd cmd_for_window;
109sway_cmd cmd_force_focus_wrapping;
109sway_cmd cmd_fullscreen; 110sway_cmd cmd_fullscreen;
110sway_cmd cmd_gaps; 111sway_cmd cmd_gaps;
111sway_cmd cmd_hide_edge_borders; 112sway_cmd cmd_hide_edge_borders;
diff --git a/include/sway/config.h b/include/sway/config.h
index 56deaf01..b29fe6c5 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -211,6 +211,7 @@ struct sway_config {
211 // Flags 211 // Flags
212 bool focus_follows_mouse; 212 bool focus_follows_mouse;
213 bool mouse_warping; 213 bool mouse_warping;
214 bool force_focus_wrapping;
214 bool active; 215 bool active;
215 bool failed; 216 bool failed;
216 bool reloading; 217 bool reloading;
diff --git a/sway/commands.c b/sway/commands.c
index 317122cd..d93f6591 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -171,6 +171,7 @@ static struct cmd_handler handlers[] = {
171 { "focus", cmd_focus }, 171 { "focus", cmd_focus },
172 { "focus_follows_mouse", cmd_focus_follows_mouse }, 172 { "focus_follows_mouse", cmd_focus_follows_mouse },
173 { "font", cmd_font }, 173 { "font", cmd_font },
174 { "force_focus_wrapping", cmd_force_focus_wrapping },
174 { "for_window", cmd_for_window }, 175 { "for_window", cmd_for_window },
175 { "fullscreen", cmd_fullscreen }, 176 { "fullscreen", cmd_fullscreen },
176 { "gaps", cmd_gaps }, 177 { "gaps", cmd_gaps },
diff --git a/sway/commands/force_focus_wrapping.c b/sway/commands/force_focus_wrapping.c
new file mode 100644
index 00000000..23019cd3
--- /dev/null
+++ b/sway/commands/force_focus_wrapping.c
@@ -0,0 +1,12 @@
1#include <string.h>
2#include "sway/commands.h"
3
4struct cmd_results *cmd_force_focus_wrapping(int argc, char **argv) {
5 struct cmd_results *error = NULL;
6 if ((error = checkarg(argc, "force_focus_wrapping", EXPECTED_EQUAL_TO, 1))) {
7 return error;
8 }
9
10 config->force_focus_wrapping = !strcasecmp(argv[0], "yes");
11 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
12}
diff --git a/sway/layout.c b/sway/layout.c
index 6012af66..3629df24 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -1084,13 +1084,17 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
1084 return container->fullscreen; 1084 return container->fullscreen;
1085 } 1085 }
1086 1086
1087 swayc_t *wrap_candidate = NULL;
1087 while (true) { 1088 while (true) {
1088 // Test if we can even make a difference here 1089 // Test if we can even make a difference here
1089 bool can_move = false; 1090 bool can_move = false;
1090 int diff = 0; 1091 int diff = 0;
1091 if (parent->type == C_ROOT) { 1092 if (parent->type == C_ROOT) {
1092 sway_log(L_DEBUG, "Moving between outputs");
1093 swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true); 1093 swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true);
1094 if (!output || output == container) {
1095 return wrap_candidate;
1096 }
1097 sway_log(L_DEBUG, "Moving between outputs");
1094 return get_swayc_in_output_direction(output, dir); 1098 return get_swayc_in_output_direction(output, dir);
1095 } else { 1099 } else {
1096 if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { 1100 if (dir == MOVE_LEFT || dir == MOVE_RIGHT) {
@@ -1108,8 +1112,31 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
1108 1112
1109 if (can_move) { 1113 if (can_move) {
1110 int desired = index_child(container) + diff; 1114 int desired = index_child(container) + diff;
1111 if (container->is_floating || desired < 0 || desired >= parent->children->length) { 1115 if (container->is_floating) {
1116 if (desired < 0) {
1117 wrap_candidate = parent->floating->items[parent->floating->length-1];
1118 } else if (desired >= parent->floating->length){
1119 wrap_candidate = parent->floating->items[0];
1120 } else {
1121 wrap_candidate = parent->floating->items[desired];
1122 }
1123 if (wrap_candidate) {
1124 wlc_view_bring_to_front(wrap_candidate->handle);
1125 }
1126 return wrap_candidate;
1127 } else if (desired < 0 || desired >= parent->children->length) {
1112 can_move = false; 1128 can_move = false;
1129 int len = parent->children->length;
1130 if (!wrap_candidate && len > 1) {
1131 if (desired < 0) {
1132 wrap_candidate = parent->children->items[len-1];
1133 } else {
1134 wrap_candidate = parent->children->items[0];
1135 }
1136 if (config->force_focus_wrapping) {
1137 return wrap_candidate;
1138 }
1139 }
1113 } else { 1140 } else {
1114 return parent->children->items[desired]; 1141 return parent->children->items[desired];
1115 } 1142 }
@@ -1118,8 +1145,8 @@ swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_directio
1118 container = parent; 1145 container = parent;
1119 parent = parent->parent; 1146 parent = parent->parent;
1120 if (!parent || container == limit) { 1147 if (!parent || container == limit) {
1121 // Nothing we can do 1148 // wrapping is the last chance
1122 return NULL; 1149 return wrap_candidate;
1123 } 1150 }
1124 } 1151 }
1125 } 1152 }