mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
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()
This commit is contained in:
parent
85c775c3b1
commit
2f5a44d34d
5 changed files with 46 additions and 36 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
42
src/ssd.c
42
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;
|
||||
|
|
|
|||
21
src/theme.c
21
src/theme.c
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue