From bd80261fc2d7b95aca16850b2b63f9c84e8ca0e7 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Fri, 29 Dec 2023 13:12:56 +0100 Subject: [PATCH] add --title flag to hide_edge_borders, fix #7409 --- include/sway/config.h | 1 + sway/commands/hide_edge_borders.c | 6 ++++++ sway/config.c | 1 + sway/desktop/render.c | 11 +++++++---- sway/sway.5.scd | 5 +++-- sway/tree/view.c | 15 +++++++++++---- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index f9da19675c..7ddf164070 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -556,6 +556,7 @@ struct sway_config { enum edge_border_types hide_edge_borders; enum edge_border_smart_types hide_edge_borders_smart; bool hide_lone_tab; + bool hide_lone_title; // border colors struct { diff --git a/sway/commands/hide_edge_borders.c b/sway/commands/hide_edge_borders.c index 43bd6dc86e..93713248fa 100644 --- a/sway/commands/hide_edge_borders.c +++ b/sway/commands/hide_edge_borders.c @@ -13,10 +13,15 @@ struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { } bool hide_lone_tab = false; + bool hide_lone_title = false; if (strcmp(*argv, "--i3") == 0) { hide_lone_tab = true; ++argv; --argc; + } else if (strcmp(*argv, "--title") == 0) { + hide_lone_title = true; + ++argv; + --argc; } if (!argc) { @@ -41,6 +46,7 @@ struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { return cmd_results_new(CMD_INVALID, "%s", expected_syntax); } config->hide_lone_tab = hide_lone_tab; + config->hide_lone_title = hide_lone_title; arrange_root(); diff --git a/sway/config.c b/sway/config.c index 4b51dc73f6..e7ba323e11 100644 --- a/sway/config.c +++ b/sway/config.c @@ -298,6 +298,7 @@ static void config_defaults(struct sway_config *config) { config->hide_edge_borders = E_NONE; config->hide_edge_borders_smart = ESMART_OFF; config->hide_lone_tab = false; + config->hide_lone_title = false; config->has_focused_tab_title = false; diff --git a/sway/desktop/render.c b/sway/desktop/render.c index c9a306cfea..2e75760604 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -689,7 +689,8 @@ static void render_container(struct render_context *ctx, * they'll apply their own borders to their children. */ static void render_containers_linear(struct render_context *ctx, struct parent_data *parent) { - for (int i = 0; i < parent->children->length; ++i) { + int children_length = parent->children->length; + for (int i = 0; i < children_length; ++i) { struct sway_container *child = parent->children->items[i]; if (child->view) { @@ -718,9 +719,11 @@ static void render_containers_linear(struct render_context *ctx, struct parent_d } if (state->border == B_NORMAL) { - render_titlebar(ctx, child, floor(state->x), - floor(state->y), state->width, colors, - title_texture, marks_texture); + if(!config->hide_lone_title || children_length > 1) { + render_titlebar(ctx, child, floor(state->x), + floor(state->y), state->width, colors, + title_texture, marks_texture); + } } else if (state->border == B_PIXEL) { render_top_border(ctx, child, colors); } diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 7e58b5286b..5254759eae 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -741,10 +741,11 @@ The default colors are: This affects new workspaces only, and is used when the workspace doesn't have its own gaps settings (see: workspace gaps ...). -*hide_edge_borders* [--i3] none|vertical|horizontal|both|smart|smart_no_gaps +*hide_edge_borders* [--i3 | --title] none|vertical|horizontal|both|smart|smart_no_gaps Hides window borders adjacent to the screen edges. Default is _none_. The _--i3_ option enables i3-compatible behavior to hide the title bar on - tabbed and stacked containers with one child. The _smart_|_smart_no_gaps_ + tabbed and stacked containers with one child. The --title option hide + the title bar on containers with one child. The _smart_|_smart_no_gaps_ options are equivalent to setting _smart_borders_ smart|no_gaps and _hide_edge_borders_ none. diff --git a/sway/tree/view.c b/sway/tree/view.c index 00dc47215f..7074b2bbf6 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -300,7 +300,7 @@ void view_autoconfigure(struct sway_view *view) { // bar, and disable any top border because we'll always have the title bar. list_t *siblings = container_get_siblings(con); bool show_titlebar = (siblings && siblings->length > 1) - || !config->hide_lone_tab; + || !(config->hide_lone_tab || config->hide_lone_title); if (show_titlebar) { enum sway_container_layout layout = container_parent_layout(con); if (layout == L_TABBED) { @@ -343,9 +343,16 @@ void view_autoconfigure(struct sway_view *view) { y = con->pending.y + y_offset; height = con->pending.height - y_offset - con->pending.border_thickness * con->pending.border_bottom; - } else { - y = con->pending.y + container_titlebar_height(); - height = con->pending.height - container_titlebar_height() + } else { + list_t *siblings = container_get_siblings(con); + int titlebar_height; + if ((siblings && siblings->length > 1) || !config->hide_lone_title) { + titlebar_height = container_titlebar_height(); + } else { + titlebar_height = con->pending.border_thickness * con->pending.border_top + y_offset; + } + y = con->pending.y + titlebar_height; + height = con->pending.height - titlebar_height - con->pending.border_thickness * con->pending.border_bottom; } break;