aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dwyer <RyanDwyer@users.noreply.github.com>2018-10-02 11:37:33 +1000
committerGitHub <noreply@github.com>2018-10-02 11:37:33 +1000
commit183a4b0d6bbd17199d7071bfe5b76feb87838c18 (patch)
treea19bcbc62ff5d4ddcb822914a4f3516c7766406a
parentb542c5413efdbbe0bbf3be0196fe566b8c6bb07f (diff)
parentbb25194844599bb653a78633c9c09c0c0ff225ee (diff)
Merge pull request #2740 from RedSoxFan/gap-borders
Handle gap borders
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/config.h4
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/hide_edge_borders.c16
-rw-r--r--sway/commands/smart_borders.c25
-rw-r--r--sway/config.c1
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway.5.scd8
-rw-r--r--sway/tree/view.c31
9 files changed, 68 insertions, 20 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index afa65340..64f707f4 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -160,6 +160,7 @@ sway_cmd cmd_scratchpad;
sway_cmd cmd_seamless_mouse;
sway_cmd cmd_set;
sway_cmd cmd_show_marks;
+sway_cmd cmd_smart_borders;
sway_cmd cmd_smart_gaps;
sway_cmd cmd_split;
sway_cmd cmd_splith;
diff --git a/include/sway/config.h b/include/sway/config.h
index eab48aed..98a18b76 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -253,7 +253,8 @@ enum edge_border_types {
E_VERTICAL, /**< hide vertical edge borders */
E_HORIZONTAL, /**< hide horizontal edge borders */
E_BOTH, /**< hide vertical and horizontal edge borders */
- E_SMART /**< hide both if precisely one window is present in workspace */
+ E_SMART, /**< hide both if precisely one window is present in workspace */
+ E_SMART_NO_GAPS, /**< hide both if one window and gaps to edge is zero */
};
enum command_context {
@@ -383,6 +384,7 @@ struct sway_config {
int border_thickness;
int floating_border_thickness;
enum edge_border_types hide_edge_borders;
+ enum edge_border_types saved_edge_borders;
// border colors
struct {
diff --git a/sway/commands.c b/sway/commands.c
index 03cfebd7..72db8ab9 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -110,6 +110,7 @@ static struct cmd_handler handlers[] = {
{ "seat", cmd_seat },
{ "set", cmd_set },
{ "show_marks", cmd_show_marks },
+ { "smart_borders", cmd_smart_borders },
{ "smart_gaps", cmd_smart_gaps },
{ "tiling_drag", cmd_tiling_drag },
{ "workspace", cmd_workspace },
diff --git a/sway/commands/hide_edge_borders.c b/sway/commands/hide_edge_borders.c
index 0a5c7f28..ea261fb1 100644
--- a/sway/commands/hide_edge_borders.c
+++ b/sway/commands/hide_edge_borders.c
@@ -1,15 +1,8 @@
#include "sway/commands.h"
#include "sway/config.h"
-#include "sway/tree/container.h"
-#include "sway/tree/root.h"
+#include "sway/tree/arrange.h"
#include "sway/tree/view.h"
-static void _configure_view(struct sway_container *con, void *data) {
- if (con->view) {
- view_autoconfigure(con->view);
- }
-}
-
struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "hide_edge_borders", EXPECTED_EQUAL_TO, 1))) {
@@ -26,13 +19,16 @@ struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) {
config->hide_edge_borders = E_BOTH;
} else if (strcmp(argv[0], "smart") == 0) {
config->hide_edge_borders = E_SMART;
+ } else if (strcmp(argv[0], "smart_no_gaps") == 0) {
+ config->hide_edge_borders = E_SMART_NO_GAPS;
} else {
return cmd_results_new(CMD_INVALID, "hide_edge_borders",
"Expected 'hide_edge_borders "
- "<none|vertical|horizontal|both|smart>'");
+ "<none|vertical|horizontal|both|smart|smart_no_gaps>'");
}
+ config->saved_edge_borders = config->hide_edge_borders;
- root_for_each_container(_configure_view, NULL);
+ arrange_root();
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/smart_borders.c b/sway/commands/smart_borders.c
new file mode 100644
index 00000000..fcb4040e
--- /dev/null
+++ b/sway/commands/smart_borders.c
@@ -0,0 +1,25 @@
+#include "sway/commands.h"
+#include "sway/config.h"
+#include "sway/tree/arrange.h"
+#include "sway/tree/view.h"
+#include "util.h"
+
+struct cmd_results *cmd_smart_borders(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "smart_borders", EXPECTED_EQUAL_TO, 1))) {
+ return error;
+ }
+
+ enum edge_border_types saved = config->hide_edge_borders;
+ if (strcmp(argv[0], "no_gaps") == 0) {
+ config->hide_edge_borders = E_SMART_NO_GAPS;
+ } else {
+ config->hide_edge_borders = parse_boolean(argv[0], true) ?
+ E_SMART : config->saved_edge_borders;
+ }
+ config->saved_edge_borders = saved;
+
+ arrange_root();
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/config.c b/sway/config.c
index 1e08559d..048b57de 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -249,6 +249,7 @@ static void config_defaults(struct sway_config *config) {
config->border_thickness = 2;
config->floating_border_thickness = 2;
config->hide_edge_borders = E_NONE;
+ config->saved_edge_borders = E_NONE;
// border colors
set_color(config->border_colors.focused.border, 0x4C7899);
diff --git a/sway/meson.build b/sway/meson.build
index 6eb9a9d7..ec6546a2 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -78,6 +78,7 @@ sway_sources = files(
'commands/seat/fallback.c',
'commands/set.c',
'commands/show_marks.c',
+ 'commands/smart_borders.c',
'commands/smart_gaps.c',
'commands/split.c',
'commands/sticky.c',
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index aa5b38ab..3202d517 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -431,7 +431,7 @@ The default colors are:
Changes the _inner_ or _outer_ gaps for either _all_ workspaces or the
_current_ workspace.
-*hide\_edge\_borders* none|vertical|horizontal|both|smart
+*hide\_edge\_borders* none|vertical|horizontal|both|smart|smart\_no\_gaps
Hides window borders adjacent to the screen edges. Default is _none_.
*input* <input\_device> <input-subcommands...>
@@ -456,6 +456,12 @@ The default colors are:
*kill*
Kills (closes) the currently focused container and all of its children.
+*smart\_borders* on|no\_gaps|off
+ If smart\_borders are _on_, borders will only be enabled if the workspace
+ only has one visible child (identical to _hide\_edge\_borders_ smart). If
+ smart\_borders is set to _no\_gaps_, borders will only be enabled if the
+ workspace only has one visible child and gaps greater than zero.
+
*smart\_gaps* on|off
If smart\_gaps are _on_ gaps will only be enabled if a workspace has more
than one child.
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 3b271159..ca5e6ab0 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -179,6 +179,17 @@ bool view_is_only_visible(struct sway_view *view) {
return only_view;
}
+static bool gaps_to_edge(struct sway_view *view) {
+ struct sway_container *con = view->container;
+ while (con) {
+ if (con->current_gaps > 0) {
+ return true;
+ }
+ con = con->parent;
+ }
+ return view->container->workspace->current_gaps > 0;
+}
+
void view_autoconfigure(struct sway_view *view) {
if (!view->container->workspace) {
// Hidden in the scratchpad
@@ -196,23 +207,27 @@ void view_autoconfigure(struct sway_view *view) {
struct sway_workspace *ws = view->container->workspace;
struct sway_container *con = view->container;
- bool other_views = config->hide_edge_borders == E_SMART ?
- !view_is_only_visible(view) : false;
+
+ bool smart = config->hide_edge_borders == E_SMART ||
+ config->hide_edge_borders == E_SMART_NO_GAPS;
+ bool other_views = smart && !view_is_only_visible(view);
+ bool no_gaps = config->hide_edge_borders != E_SMART_NO_GAPS
+ || !gaps_to_edge(view);
view->border_top = view->border_bottom = true;
view->border_left = view->border_right = true;
if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_VERTICAL
- || (config->hide_edge_borders == E_SMART && !other_views)) {
- view->border_left = con->x != ws->x;
- int right_x = con->x + con->width;
+ || (smart && !other_views && no_gaps)) {
+ view->border_left = con->x - con->current_gaps != ws->x;
+ int right_x = con->x + con->width + con->current_gaps;
view->border_right = right_x != ws->x + ws->width;
}
if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_HORIZONTAL
- || (config->hide_edge_borders == E_SMART && !other_views)) {
- view->border_top = con->y != ws->y;
- int bottom_y = con->y + con->height;
+ || (smart && !other_views && no_gaps)) {
+ view->border_top = con->y - con->current_gaps != ws->y;
+ int bottom_y = con->y + con->height + con->current_gaps;
view->border_bottom = bottom_y != ws->y + ws->height;
}