From: Johan Malm Date: Thu, 15 Apr 2021 19:13:49 +0000 (+0100) Subject: theme: move title_height to theme struct X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=2f5a44d34d02c016457c37f29568c08d8919ce27;p=proto%2Flabwc.git theme: move title_height to theme struct title_height is a derived variable which needs both config and theme variables (font height and title padding). The code is tidier calling post_processing() for this from theme_init() --- diff --git a/include/config/rcxml.h b/include/config/rcxml.h index 69beac98..b682a1c3 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -14,7 +14,6 @@ struct rcxml { char *font_name_activewindow; int font_size_activewindow; struct wl_list keybinds; - int title_height; /* not set in rc.xml, but derived from font, etc */ }; extern struct rcxml rc; diff --git a/include/theme.h b/include/theme.h index 318c5815..b172cfb9 100644 --- a/include/theme.h +++ b/include/theme.h @@ -12,6 +12,7 @@ struct theme { int border_width; + int padding_height; float window_active_border_color[4]; float window_inactive_border_color[4]; @@ -34,6 +35,9 @@ struct theme { struct wlr_texture *xbm_close_inactive_unpressed; struct wlr_texture *xbm_maximize_inactive_unpressed; struct wlr_texture *xbm_iconify_inactive_unpressed; + + /* not set in rc.xml or themerc, but derived from font and padding_height */ + int title_height; }; /** diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 71a442a4..5271317a 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -12,7 +12,6 @@ #include #include "common/dir.h" -#include "common/font.h" #include "common/log.h" #include "common/nodename.h" #include "common/string-helpers.h" @@ -236,15 +235,6 @@ bind(const char *binding, const char *action, const char *command) } } -static void -set_title_height(void) -{ - char buf[256]; - snprintf(buf, sizeof(buf), "%s %d", rc.font_name_activewindow, - rc.font_size_activewindow); - rc.title_height = font_height(buf); -} - static void post_processing(void) { @@ -261,10 +251,6 @@ post_processing(void) if (!rc.font_name_activewindow) { rc.font_name_activewindow = strdup("sans"); } - set_title_height(); - if (rc.corner_radius >= rc.title_height) { - rc.corner_radius = rc.title_height - 1; - } } static void diff --git a/src/ssd.c b/src/ssd.c index f3c59da6..5691784c 100644 --- a/src/ssd.c +++ b/src/ssd.c @@ -18,7 +18,7 @@ ssd_thickness(struct view *view) { struct theme *theme = view->server->theme; struct border border = { - .top = rc.title_height + theme->border_width, + .top = theme->title_height + theme->border_width, .bottom = theme->border_width, .left = theme->border_width, .right = theme->border_width, @@ -44,37 +44,37 @@ ssd_box(struct view *view, enum ssd_part_type type) { struct theme *theme = view->server->theme; struct wlr_box box = { 0 }; - int corner_square = rc.title_height + theme->border_width; + int corner_square = theme->title_height + theme->border_width; assert(view); switch (type) { case LAB_SSD_BUTTON_CLOSE: - box.x = view->x + view->w - rc.title_height; - box.y = view->y - rc.title_height; - box.width = rc.title_height; - box.height = rc.title_height; + box.x = view->x + view->w - theme->title_height; + box.y = view->y - theme->title_height; + box.width = theme->title_height; + box.height = theme->title_height; break; case LAB_SSD_BUTTON_MAXIMIZE: - box.x = view->x + view->w - rc.title_height * 2; - box.y = view->y - rc.title_height; - box.width = rc.title_height; - box.height = rc.title_height; + box.x = view->x + view->w - theme->title_height * 2; + box.y = view->y - theme->title_height; + box.width = theme->title_height; + box.height = theme->title_height; break; case LAB_SSD_BUTTON_ICONIFY: - box.x = view->x + view->w - rc.title_height * 3; - box.y = view->y - rc.title_height; - box.width = rc.title_height; - box.height = rc.title_height; + box.x = view->x + view->w - theme->title_height * 3; + box.y = view->y - theme->title_height; + box.width = theme->title_height; + box.height = theme->title_height; break; case LAB_SSD_PART_TITLE: - box.x = view->x + rc.title_height; - box.y = view->y - rc.title_height; - box.width = view->w - 2 * rc.title_height; - box.height = rc.title_height; + box.x = view->x + theme->title_height; + box.y = view->y - theme->title_height; + box.width = view->w - 2 * theme->title_height; + box.height = theme->title_height; break; case LAB_SSD_PART_TOP: - box.x = view->x + rc.title_height; + box.x = view->x + theme->title_height; box.y = view->y - corner_square; - box.width = view->w - 2 * rc.title_height; + box.width = view->w - 2 * theme->title_height; box.height = theme->border_width; break; case LAB_SSD_PART_RIGHT: @@ -102,7 +102,7 @@ ssd_box(struct view *view, enum ssd_part_type type) box.height = corner_square; break; case LAB_SSD_PART_CORNER_TOP_RIGHT: - box.x = view->x + view->w - rc.title_height; + box.x = view->x + view->w - theme->title_height; box.y = view->y - corner_square; box.width = corner_square; box.height = corner_square; diff --git a/src/theme.c b/src/theme.c index e7722035..eaf36cc0 100644 --- a/src/theme.c +++ b/src/theme.c @@ -7,9 +7,11 @@ #include #include "common/dir.h" +#include "common/font.h" #include "common/log.h" #include "common/string-helpers.h" #include "common/zfree.h" +#include "config/rcxml.h" #include "theme.h" #include "xbm/xbm.h" @@ -64,6 +66,7 @@ parse_hexstr(const char *hex, float *rgba) void theme_builtin(struct theme *theme) { theme->border_width = 1; + theme->padding_height = 3; parse_hexstr("#dddad6", theme->window_active_border_color); parse_hexstr("#f6f5f4", theme->window_inactive_border_color); @@ -99,6 +102,9 @@ static void entry(struct theme *theme, const char *key, const char *value) if (match(key, "border.width")) { theme->border_width = atoi(value); } + if (match(key, "padding.height")) { + theme->padding_height = atoi(value); + } if (match(key, "window.active.border.color")) { parse_hexstr(value, theme->window_active_border_color); @@ -188,12 +194,27 @@ theme_read(struct theme *theme, const char *theme_name) fclose(stream); } +static void +post_processing(struct theme *theme) +{ + char buf[256]; + snprintf(buf, sizeof(buf), "%s %d", rc.font_name_activewindow, + rc.font_size_activewindow); + theme->title_height = font_height(buf) + 2 * theme->padding_height; + + if (rc.corner_radius >= theme->title_height) { + theme->title_height = rc.corner_radius + 1; + } + +} + void theme_init(struct theme *theme, struct wlr_renderer *renderer, const char *theme_name) { theme_read(theme, theme_name); xbm_load(theme, renderer); + post_processing(theme); } void