]> git.mdlowis.com Git - proto/labwc.git/commitdiff
theme: move title_height to theme struct
authorJohan Malm <jgm323@gmail.com>
Thu, 15 Apr 2021 19:13:49 +0000 (20:13 +0100)
committerJohan Malm <jgm323@gmail.com>
Thu, 15 Apr 2021 19:13:49 +0000 (20:13 +0100)
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()

include/config/rcxml.h
include/theme.h
src/config/rcxml.c
src/ssd.c
src/theme.c

index 69beac98064ff9c68ec136be6b776cc9732f9cbf..b682a1c300737b1e503bf464ca0460217db890a7 100644 (file)
@@ -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;
index 318c5815568ad173d0812e34d3d6b32674d405d5..b172cfb97d99bd70a96276c2d28993d08d924e93 100644 (file)
@@ -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;
 };
 
 /**
index 71a442a448d543621fd00e97a948ccae476b3f1d..5271317aa3981c34e46ea5806920bc8660a0ad64 100644 (file)
@@ -12,7 +12,6 @@
 #include <wayland-server-core.h>
 
 #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
index f3c59da66b8ff50e7f5cb70377655952b49f456b..5691784cffc3adfb8744094eb5a5896fb6f9f21f 100644 (file)
--- 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;
index e77220353bf7ad4c8671f63b0334f7537b85b12a..eaf36cc0cabd0ffd102911dce934a52575985f37 100644 (file)
@@ -7,9 +7,11 @@
 #include <string.h>
 
 #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