Merge pull request #2740 from RedSoxFan/gap-borders

Handle gap borders
master
Ryan Dwyer 6 years ago committed by GitHub
commit 183a4b0d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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;

@ -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 {

@ -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 },

@ -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);
}

@ -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);
}

@ -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);

@ -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',

@ -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.

@ -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;
}

Loading…
Cancel
Save