]> git.mdlowis.com Git - proto/labwc.git/commitdiff
theme: support border.width
authorJohan Malm <jgm323@gmail.com>
Sat, 27 Mar 2021 21:09:45 +0000 (21:09 +0000)
committerJohan Malm <jgm323@gmail.com>
Sat, 27 Mar 2021 21:09:45 +0000 (21:09 +0000)
docs/labwc-theme.5.scd
include/theme.h
src/ssd.c
src/theme.c

index 864d6929c29aee0b53bd16d25bd12b79e0d94a3c..e16a93b0d8d4da6b2f27d0ea0ae4b4a35dfdf7f9 100644 (file)
@@ -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
 
index f175682ec3f71fecb4d8975b457621f92f7b034a..f2321db9841ae9becb9eb9587dbd48ac110d4a36 100644 (file)
@@ -11,6 +11,8 @@
 #include <wlr/render/wlr_renderer.h>
 
 struct theme {
+       int border_width;
+
        float window_active_title_bg_color[4];
        float window_active_handle_bg_color[4];
 
index afeacd355f5f8e3e6068dfb66cf58f22716013a3..bb59ad1dbfd4e6e79876655880910c1f9ca72ee8 100644 (file)
--- a/src/ssd.c
+++ b/src/ssd.c
 #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,
index f07afbd1ff80bd5fae3e82160f295b2ac3b8c493..49621d7a99adac701d08f5e1ff6afdcef21e6ada 100644 (file)
@@ -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);