mirror of
https://github.com/swaywm/sway.git
synced 2024-11-23 00:11:28 +00:00
Handle border options for gaps
Fixes `hide_edge_borders smart` when gaps are in use. Implements `hide_edge_borders smart_no_gaps` and `smart_borders on|no_gaps|off`. Since `smart_borders on` is equivalent to `hide_edge_borders smart` and `smart_borders no_gaps` is equivalent to `hide_edge_borders smart_no_gaps`, I opted to just save the last value set for `hide_edge_borders` and restore that on `smart_borders off`. This simplifies the conditions for setting the border.
This commit is contained in:
parent
b542c5413e
commit
bb25194844
|
@ -160,6 +160,7 @@ sway_cmd cmd_scratchpad;
|
||||||
sway_cmd cmd_seamless_mouse;
|
sway_cmd cmd_seamless_mouse;
|
||||||
sway_cmd cmd_set;
|
sway_cmd cmd_set;
|
||||||
sway_cmd cmd_show_marks;
|
sway_cmd cmd_show_marks;
|
||||||
|
sway_cmd cmd_smart_borders;
|
||||||
sway_cmd cmd_smart_gaps;
|
sway_cmd cmd_smart_gaps;
|
||||||
sway_cmd cmd_split;
|
sway_cmd cmd_split;
|
||||||
sway_cmd cmd_splith;
|
sway_cmd cmd_splith;
|
||||||
|
|
|
@ -253,7 +253,8 @@ enum edge_border_types {
|
||||||
E_VERTICAL, /**< hide vertical edge borders */
|
E_VERTICAL, /**< hide vertical edge borders */
|
||||||
E_HORIZONTAL, /**< hide horizontal edge borders */
|
E_HORIZONTAL, /**< hide horizontal edge borders */
|
||||||
E_BOTH, /**< hide vertical and 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 {
|
enum command_context {
|
||||||
|
@ -383,6 +384,7 @@ struct sway_config {
|
||||||
int border_thickness;
|
int border_thickness;
|
||||||
int floating_border_thickness;
|
int floating_border_thickness;
|
||||||
enum edge_border_types hide_edge_borders;
|
enum edge_border_types hide_edge_borders;
|
||||||
|
enum edge_border_types saved_edge_borders;
|
||||||
|
|
||||||
// border colors
|
// border colors
|
||||||
struct {
|
struct {
|
||||||
|
|
|
@ -110,6 +110,7 @@ static struct cmd_handler handlers[] = {
|
||||||
{ "seat", cmd_seat },
|
{ "seat", cmd_seat },
|
||||||
{ "set", cmd_set },
|
{ "set", cmd_set },
|
||||||
{ "show_marks", cmd_show_marks },
|
{ "show_marks", cmd_show_marks },
|
||||||
|
{ "smart_borders", cmd_smart_borders },
|
||||||
{ "smart_gaps", cmd_smart_gaps },
|
{ "smart_gaps", cmd_smart_gaps },
|
||||||
{ "tiling_drag", cmd_tiling_drag },
|
{ "tiling_drag", cmd_tiling_drag },
|
||||||
{ "workspace", cmd_workspace },
|
{ "workspace", cmd_workspace },
|
||||||
|
|
|
@ -1,15 +1,8 @@
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
#include "sway/tree/container.h"
|
#include "sway/tree/arrange.h"
|
||||||
#include "sway/tree/root.h"
|
|
||||||
#include "sway/tree/view.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 *cmd_hide_edge_borders(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
if ((error = checkarg(argc, "hide_edge_borders", EXPECTED_EQUAL_TO, 1))) {
|
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;
|
config->hide_edge_borders = E_BOTH;
|
||||||
} else if (strcmp(argv[0], "smart") == 0) {
|
} else if (strcmp(argv[0], "smart") == 0) {
|
||||||
config->hide_edge_borders = E_SMART;
|
config->hide_edge_borders = E_SMART;
|
||||||
|
} else if (strcmp(argv[0], "smart_no_gaps") == 0) {
|
||||||
|
config->hide_edge_borders = E_SMART_NO_GAPS;
|
||||||
} else {
|
} else {
|
||||||
return cmd_results_new(CMD_INVALID, "hide_edge_borders",
|
return cmd_results_new(CMD_INVALID, "hide_edge_borders",
|
||||||
"Expected '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);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
25
sway/commands/smart_borders.c
Normal file
25
sway/commands/smart_borders.c
Normal file
|
@ -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->border_thickness = 2;
|
||||||
config->floating_border_thickness = 2;
|
config->floating_border_thickness = 2;
|
||||||
config->hide_edge_borders = E_NONE;
|
config->hide_edge_borders = E_NONE;
|
||||||
|
config->saved_edge_borders = E_NONE;
|
||||||
|
|
||||||
// border colors
|
// border colors
|
||||||
set_color(config->border_colors.focused.border, 0x4C7899);
|
set_color(config->border_colors.focused.border, 0x4C7899);
|
||||||
|
|
|
@ -78,6 +78,7 @@ sway_sources = files(
|
||||||
'commands/seat/fallback.c',
|
'commands/seat/fallback.c',
|
||||||
'commands/set.c',
|
'commands/set.c',
|
||||||
'commands/show_marks.c',
|
'commands/show_marks.c',
|
||||||
|
'commands/smart_borders.c',
|
||||||
'commands/smart_gaps.c',
|
'commands/smart_gaps.c',
|
||||||
'commands/split.c',
|
'commands/split.c',
|
||||||
'commands/sticky.c',
|
'commands/sticky.c',
|
||||||
|
|
|
@ -431,7 +431,7 @@ The default colors are:
|
||||||
Changes the _inner_ or _outer_ gaps for either _all_ workspaces or the
|
Changes the _inner_ or _outer_ gaps for either _all_ workspaces or the
|
||||||
_current_ workspace.
|
_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_.
|
Hides window borders adjacent to the screen edges. Default is _none_.
|
||||||
|
|
||||||
*input* <input\_device> <input-subcommands...>
|
*input* <input\_device> <input-subcommands...>
|
||||||
|
@ -456,6 +456,12 @@ The default colors are:
|
||||||
*kill*
|
*kill*
|
||||||
Kills (closes) the currently focused container and all of its children.
|
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
|
*smart\_gaps* on|off
|
||||||
If smart\_gaps are _on_ gaps will only be enabled if a workspace has more
|
If smart\_gaps are _on_ gaps will only be enabled if a workspace has more
|
||||||
than one child.
|
than one child.
|
||||||
|
|
|
@ -179,6 +179,17 @@ bool view_is_only_visible(struct sway_view *view) {
|
||||||
return only_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) {
|
void view_autoconfigure(struct sway_view *view) {
|
||||||
if (!view->container->workspace) {
|
if (!view->container->workspace) {
|
||||||
// Hidden in the scratchpad
|
// Hidden in the scratchpad
|
||||||
|
@ -196,23 +207,27 @@ void view_autoconfigure(struct sway_view *view) {
|
||||||
|
|
||||||
struct sway_workspace *ws = view->container->workspace;
|
struct sway_workspace *ws = view->container->workspace;
|
||||||
struct sway_container *con = view->container;
|
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_top = view->border_bottom = true;
|
||||||
view->border_left = view->border_right = true;
|
view->border_left = view->border_right = true;
|
||||||
if (config->hide_edge_borders == E_BOTH
|
if (config->hide_edge_borders == E_BOTH
|
||||||
|| config->hide_edge_borders == E_VERTICAL
|
|| config->hide_edge_borders == E_VERTICAL
|
||||||
|| (config->hide_edge_borders == E_SMART && !other_views)) {
|
|| (smart && !other_views && no_gaps)) {
|
||||||
view->border_left = con->x != ws->x;
|
view->border_left = con->x - con->current_gaps != ws->x;
|
||||||
int right_x = con->x + con->width;
|
int right_x = con->x + con->width + con->current_gaps;
|
||||||
view->border_right = right_x != ws->x + ws->width;
|
view->border_right = right_x != ws->x + ws->width;
|
||||||
}
|
}
|
||||||
if (config->hide_edge_borders == E_BOTH
|
if (config->hide_edge_borders == E_BOTH
|
||||||
|| config->hide_edge_borders == E_HORIZONTAL
|
|| config->hide_edge_borders == E_HORIZONTAL
|
||||||
|| (config->hide_edge_borders == E_SMART && !other_views)) {
|
|| (smart && !other_views && no_gaps)) {
|
||||||
view->border_top = con->y != ws->y;
|
view->border_top = con->y - con->current_gaps != ws->y;
|
||||||
int bottom_y = con->y + con->height;
|
int bottom_y = con->y + con->height + con->current_gaps;
|
||||||
view->border_bottom = bottom_y != ws->y + ws->height;
|
view->border_bottom = bottom_y != ws->y + ws->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue