summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2016-03-20 07:45:51 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2016-03-20 07:45:51 -0400
commit599d6ab65174263cbacb730e674bf20c024c909a (patch)
treecce18134cdc904d0d3ba720e245dcf96274f564b
parentMerge pull request #523 from mikkeloscar/slack-key-handler (diff)
parentImplement 'smart_gaps' feature from i3-gaps (diff)
downloadsway-599d6ab65174263cbacb730e674bf20c024c909a.tar.gz
sway-599d6ab65174263cbacb730e674bf20c024c909a.tar.zst
sway-599d6ab65174263cbacb730e674bf20c024c909a.zip
Merge pull request #524 from mikkeloscar/smart-gaps
Implement 'smart_gaps' feature from i3-gaps
-rw-r--r--include/config.h1
-rw-r--r--sway/commands.c19
-rw-r--r--sway/config.c1
-rw-r--r--sway/container.c2
-rw-r--r--sway/layout.c2
-rw-r--r--sway/sway.5.txt4
6 files changed, 27 insertions, 2 deletions
diff --git a/include/config.h b/include/config.h
index d77872ee..9356140d 100644
--- a/include/config.h
+++ b/include/config.h
@@ -181,6 +181,7 @@ struct sway_config {
181 bool seamless_mouse; 181 bool seamless_mouse;
182 182
183 bool edge_gaps; 183 bool edge_gaps;
184 bool smart_gaps;
184 int gaps_inner; 185 int gaps_inner;
185 int gaps_outer; 186 int gaps_outer;
186}; 187};
diff --git a/sway/commands.c b/sway/commands.c
index e03eef24..4da411c4 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -68,6 +68,7 @@ static sway_cmd cmd_reload;
68static sway_cmd cmd_resize; 68static sway_cmd cmd_resize;
69static sway_cmd cmd_scratchpad; 69static sway_cmd cmd_scratchpad;
70static sway_cmd cmd_set; 70static sway_cmd cmd_set;
71static sway_cmd cmd_smart_gaps;
71static sway_cmd cmd_split; 72static sway_cmd cmd_split;
72static sway_cmd cmd_splith; 73static sway_cmd cmd_splith;
73static sway_cmd cmd_splitt; 74static sway_cmd cmd_splitt;
@@ -1480,6 +1481,23 @@ static struct cmd_results *cmd_gaps(int argc, char **argv) {
1480 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 1481 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
1481} 1482}
1482 1483
1484static struct cmd_results *cmd_smart_gaps(int argc, char **argv) {
1485 struct cmd_results *error = NULL;
1486 if ((error = checkarg(argc, "smart_gaps", EXPECTED_EQUAL_TO, 1))) {
1487 return error;
1488 }
1489
1490 if (strcasecmp(argv[0], "on") == 0) {
1491 config->smart_gaps = true;
1492 } else if (strcasecmp(argv[0], "off") == 0) {
1493 config->smart_gaps = false;
1494 } else {
1495 return cmd_results_new(CMD_INVALID, "smart_gaps", "Expected 'smart_gaps <on|off>'");
1496 }
1497
1498 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
1499}
1500
1483static struct cmd_results *cmd_kill(int argc, char **argv) { 1501static struct cmd_results *cmd_kill(int argc, char **argv) {
1484 if (config->reading) return cmd_results_new(CMD_FAILURE, "kill", "Can't be used in config file."); 1502 if (config->reading) return cmd_results_new(CMD_FAILURE, "kill", "Can't be used in config file.");
1485 if (!config->active) return cmd_results_new(CMD_FAILURE, "kill", "Can only be used when sway is running."); 1503 if (!config->active) return cmd_results_new(CMD_FAILURE, "kill", "Can only be used when sway is running.");
@@ -2048,6 +2066,7 @@ static struct cmd_handler handlers[] = {
2048 { "scratchpad", cmd_scratchpad }, 2066 { "scratchpad", cmd_scratchpad },
2049 { "seamless_mouse", cmd_seamless_mouse }, 2067 { "seamless_mouse", cmd_seamless_mouse },
2050 { "set", cmd_set }, 2068 { "set", cmd_set },
2069 { "smart_gaps", cmd_smart_gaps },
2051 { "split", cmd_split }, 2070 { "split", cmd_split },
2052 { "splith", cmd_splith }, 2071 { "splith", cmd_splith },
2053 { "splitt", cmd_splitt }, 2072 { "splitt", cmd_splitt },
diff --git a/sway/config.c b/sway/config.c
index 296e164c..ebf7546d 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -170,6 +170,7 @@ static void config_defaults(struct sway_config *config) {
170 config->reading = false; 170 config->reading = false;
171 171
172 config->edge_gaps = true; 172 config->edge_gaps = true;
173 config->smart_gaps = false;
173 config->gaps_inner = 0; 174 config->gaps_inner = 0;
174 config->gaps_outer = 0; 175 config->gaps_outer = 0;
175 176
diff --git a/sway/container.c b/sway/container.c
index e4c20bc9..9330a3de 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -675,7 +675,7 @@ int swayc_gap(swayc_t *container) {
675 return container->gaps >= 0 ? container->gaps : config->gaps_inner; 675 return container->gaps >= 0 ? container->gaps : config->gaps_inner;
676 } else if (container->type == C_WORKSPACE) { 676 } else if (container->type == C_WORKSPACE) {
677 int base = container->gaps >= 0 ? container->gaps : config->gaps_outer; 677 int base = container->gaps >= 0 ? container->gaps : config->gaps_outer;
678 if (config->edge_gaps) { 678 if (config->edge_gaps && !(config->smart_gaps && container->children->length == 1)) {
679 // the inner gap is created via a margin around each window which 679 // the inner gap is created via a margin around each window which
680 // is half the gap size, so the workspace also needs half a gap 680 // is half the gap size, so the workspace also needs half a gap
681 // size to make the outermost gap the same size (excluding the 681 // size to make the outermost gap the same size (excluding the
diff --git a/sway/layout.c b/sway/layout.c
index e9998bc8..d9c4598f 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -406,7 +406,7 @@ void update_geometry(swayc_t *container) {
406 if (op->focused == ws) { 406 if (op->focused == ws) {
407 wlc_view_bring_to_front(container->handle); 407 wlc_view_bring_to_front(container->handle);
408 } 408 }
409 } else if (!config->edge_gaps && gap > 0) { 409 } else if ((!config->edge_gaps && gap > 0) || (config->smart_gaps && ws->children->length == 1)) {
410 // Remove gap against the workspace edges. Because a pixel is not 410 // Remove gap against the workspace edges. Because a pixel is not
411 // divisable, depending on gap size and the number of siblings our view 411 // divisable, depending on gap size and the number of siblings our view
412 // might be at the workspace edge without being exactly so (thus test 412 // might be at the workspace edge without being exactly so (thus test
diff --git a/sway/sway.5.txt b/sway/sway.5.txt
index 7a87bb44..e73beb81 100644
--- a/sway/sway.5.txt
+++ b/sway/sway.5.txt
@@ -154,6 +154,10 @@ or triggered at runtime.
154 workspace (or current workspace), and _current_ changes gaps for the current 154 workspace (or current workspace), and _current_ changes gaps for the current
155 view or workspace. 155 view or workspace.
156 156
157**smart_gaps** <on|off>::
158 If smart_gaps are _on_ then gaps will only be enabled if a workspace has more
159 than one child container.
160
157**mode** <mode_name>:: 161**mode** <mode_name>::
158 Switches to the given mode_name. the default mode is simply _default_. To 162 Switches to the given mode_name. the default mode is simply _default_. To
159 create a new mode in config append _{_ to this command, the following lines 163 create a new mode in config append _{_ to this command, the following lines