From b3a73a9fdc971110a5f059ab0d90ed2d9d6f9d01 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Sat, 27 Mar 2021 21:09:45 +0000 Subject: [PATCH] theme: support border.width --- docs/labwc-theme.5.scd | 4 ++++ include/theme.h | 2 ++ src/ssd.c | 38 +++++++++++++++++++------------------- src/theme.c | 5 ++++- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/docs/labwc-theme.5.scd b/docs/labwc-theme.5.scd index 864d6929..e16a93b0 100644 --- a/docs/labwc-theme.5.scd +++ b/docs/labwc-theme.5.scd @@ -29,6 +29,10 @@ A theme consists of a themerc file and optionally some xbm icons. # THEME ELEMENTS +*border.width* + Line width (integer) of border border drawn around window frames. + Default is 1. + *window.active.title.bg.color* Background for the focussed window's titlebar diff --git a/include/theme.h b/include/theme.h index f175682e..f2321db9 100644 --- a/include/theme.h +++ b/include/theme.h @@ -11,6 +11,8 @@ #include struct theme { + int border_width; + float window_active_title_bg_color[4]; float window_active_handle_bg_color[4]; diff --git a/src/ssd.c b/src/ssd.c index afeacd35..bb59ad1d 100644 --- a/src/ssd.c +++ b/src/ssd.c @@ -13,16 +13,15 @@ #include "theme.h" #include "ssd.h" -#define BORDER_WIDTH (2) - struct border ssd_thickness(struct view *view) { + struct theme *theme = view->server->theme; struct border border = { - .top = rc.title_height + BORDER_WIDTH, - .bottom = BORDER_WIDTH, - .left = BORDER_WIDTH, - .right = BORDER_WIDTH, + .top = rc.title_height + theme->border_width, + .bottom = theme->border_width, + .left = theme->border_width, + .right = theme->border_width, }; return border; } @@ -43,8 +42,9 @@ ssd_max_extents(struct view *view) struct wlr_box 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 + BORDER_WIDTH; + int corner_square = rc.title_height + theme->border_width; assert(view); switch (type) { case LAB_SSD_BUTTON_CLOSE: @@ -75,28 +75,28 @@ ssd_box(struct view *view, enum ssd_part_type type) box.x = view->x + rc.title_height; box.y = view->y - corner_square; box.width = view->w - 2 * rc.title_height; - box.height = BORDER_WIDTH; + box.height = theme->border_width; break; case LAB_SSD_PART_RIGHT: box.x = view->x + view->w; box.y = view->y; - box.width = BORDER_WIDTH; + box.width = theme->border_width; box.height = view->h; break; case LAB_SSD_PART_BOTTOM: - box.x = view->x - BORDER_WIDTH; + box.x = view->x - theme->border_width; box.y = view->y + view->h; - box.width = view->w + 2 * BORDER_WIDTH; - box.height = +BORDER_WIDTH; + box.width = view->w + 2 * theme->border_width; + box.height = +theme->border_width; break; case LAB_SSD_PART_LEFT: - box.x = view->x - BORDER_WIDTH; + box.x = view->x - theme->border_width; box.y = view->y; - box.width = BORDER_WIDTH; + box.width = theme->border_width; box.height = view->h; break; case LAB_SSD_PART_CORNER_TOP_LEFT: - box.x = view->x - BORDER_WIDTH; + box.x = view->x - theme->border_width; box.y = view->y - corner_square; box.width = corner_square; box.height = corner_square; @@ -203,12 +203,12 @@ rounded_rect(struct wlr_renderer *renderer, struct rounded_corner_ctx *ctx) /* border */ cairo_set_line_cap(cairo, CAIRO_LINE_CAP_ROUND); set_source(cairo, ctx->border_color); - cairo_set_line_width(cairo, BORDER_WIDTH); - double half_line_width = BORDER_WIDTH / 2.0; + cairo_set_line_width(cairo, ctx->line_width); + double half_line_width = ctx->line_width / 2.0; switch (ctx->corner) { case LAB_CORNER_TOP_LEFT: cairo_move_to(cairo, half_line_width, h); - cairo_line_to(cairo, half_line_width, r + BORDER_WIDTH); + cairo_line_to(cairo, half_line_width, r + half_line_width); cairo_arc(cairo, r, r, r - half_line_width, 180 * deg, 270 * deg); cairo_line_to(cairo, w, half_line_width); break; @@ -273,7 +273,7 @@ ssd_create(struct view *view) struct rounded_corner_ctx ctx = { .box = &part->box, .radius = 7.0, /* TODO: get from config */ - .line_width = 1.0, + .line_width = theme->border_width, .fill_color = theme->window_active_title_bg_color, .border_color = theme->window_active_handle_bg_color, .corner = LAB_CORNER_TOP_LEFT, diff --git a/src/theme.c b/src/theme.c index f07afbd1..49621d7a 100644 --- a/src/theme.c +++ b/src/theme.c @@ -63,6 +63,7 @@ parse_hexstr(const char *hex, float *rgba) */ void theme_builtin(struct theme *theme) { + theme->border_width = 1; parse_hexstr("#589bda", theme->window_active_title_bg_color); parse_hexstr("#3c7cb7", theme->window_active_handle_bg_color); parse_hexstr("#efece6", theme->window_inactive_title_bg_color); @@ -85,7 +86,9 @@ static void entry(struct theme *theme, const char *key, const char *value) if (!key || !value) { return; } - if (match(key, "window.active.title.bg.color")) { + if (match(key, "border.width")) { + theme->border_width = atoi(value); + } else if (match(key, "window.active.title.bg.color")) { parse_hexstr(value, theme->window_active_title_bg_color); } else if (match(key, "window.active.handle.bg.color")) { parse_hexstr(value, theme->window_active_handle_bg_color); -- 2.52.0