From e82e4de37f5c6fe184da62f228329a37517ccd55 Mon Sep 17 00:00:00 2001 From: Will McKinnon Date: Wed, 30 Nov 2022 20:22:39 -0500 Subject: [PATCH] fix: titlebars on containers with smart_gaps on and a large corner_radius now render as expected --- sway/commands/corner_radius.c | 12 +++++++++++- sway/commands/titlebar_padding.c | 25 +++++++++++++++++++++++-- sway/desktop/render.c | 8 ++------ sway/tree/container.c | 4 +--- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/sway/commands/corner_radius.c b/sway/commands/corner_radius.c index ce1eff88..ab216f6e 100644 --- a/sway/commands/corner_radius.c +++ b/sway/commands/corner_radius.c @@ -1,6 +1,7 @@ #include #include "sway/commands.h" #include "sway/config.h" +#include "sway/tree/container.h" #include "log.h" struct cmd_results *cmd_corner_radius(int argc, char **argv) { @@ -17,7 +18,16 @@ struct cmd_results *cmd_corner_radius(int argc, char **argv) { config->corner_radius = value; - // TODO: rerender windows (see opacity cmd) + /* + titlebar padding depends on corner_radius to + ensure that titlebars are rendered nicely + */ + if (value > config->titlebar_h_padding) { + config->titlebar_h_padding = value; + } + if (value > (int)container_titlebar_height()) { + config->titlebar_v_padding = (value - config->font_height) / 2; + } return cmd_results_new(CMD_SUCCESS, NULL); } diff --git a/sway/commands/titlebar_padding.c b/sway/commands/titlebar_padding.c index 29ce59ff..affb6b50 100644 --- a/sway/commands/titlebar_padding.c +++ b/sway/commands/titlebar_padding.c @@ -2,6 +2,7 @@ #include "sway/commands.h" #include "sway/config.h" #include "sway/output.h" +#include "sway/swaynag.h" #include "sway/tree/arrange.h" #include "log.h" @@ -27,8 +28,28 @@ struct cmd_results *cmd_titlebar_padding(int argc, char **argv) { } } - config->titlebar_v_padding = v_value; - config->titlebar_h_padding = h_value; + /* + titlebar padding depends on corner_radius to + ensure that titlebars are rendered nicely + */ + if (v_value > (config->corner_radius - config->font_height) / 2) { + config->titlebar_v_padding = v_value; + } else { + config_add_swaynag_warning( + "titlebar_v_padding (%d) is too small for the current corner radius (%d)", + v_value, config->corner_radius + ); + return cmd_results_new(CMD_FAILURE, NULL); + } + if (h_value > config->corner_radius) { + config->titlebar_h_padding = h_value; + } else { + config_add_swaynag_warning( + "titlebar_h_padding (%d) is too small for the current corner radius (%d)", + h_value, config->corner_radius + ); + return cmd_results_new(CMD_FAILURE, NULL); + } for (int i = 0; i < root->outputs->length; ++i) { struct sway_output *output = root->outputs->items[i]; diff --git a/sway/desktop/render.c b/sway/desktop/render.c index bc9093d9..3ee719b6 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -563,14 +563,10 @@ static void render_titlebar(struct sway_output *output, double output_x = output->lx; double output_y = output->ly; int titlebar_border_thickness = config->titlebar_border_thickness; + int titlebar_h_padding = config->titlebar_h_padding; + int titlebar_v_padding = config->titlebar_v_padding; enum alignment title_align = config->title_align; - // titlebar padding should account for corner radius - int titlebar_h_padding = corner_radius > config->titlebar_h_padding ? - corner_radius : config->titlebar_h_padding; - float titlebar_v_padding = corner_radius == (int)container_titlebar_height() ? - (container_titlebar_height() - config->font_height) / 2.0 : config->titlebar_v_padding; - // Single pixel bar above title memcpy(&color, colors->border, sizeof(float) * 4); premultiply_alpha(color, alpha); diff --git a/sway/tree/container.c b/sway/tree/container.c index 684304c8..73bb865c 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -676,9 +676,7 @@ void container_update_representation(struct sway_container *con) { } size_t container_titlebar_height(void) { - int config_titlebar_height = config->font_height + config->titlebar_v_padding * 2; - return config->corner_radius > config_titlebar_height ? - config->corner_radius : config_titlebar_height; + return config->font_height + config->titlebar_v_padding * 2; } void floating_calculate_constraints(int *min_width, int *max_width,