theme: support border.width

This commit is contained in:
Johan Malm 2021-03-27 21:09:45 +00:00
parent fdfb12b2ce
commit b3a73a9fdc
4 changed files with 29 additions and 20 deletions

View file

@ -29,6 +29,10 @@ A theme consists of a themerc file and optionally some xbm icons.
# THEME ELEMENTS # THEME ELEMENTS
*border.width*
Line width (integer) of border border drawn around window frames.
Default is 1.
*window.active.title.bg.color* *window.active.title.bg.color*
Background for the focussed window's titlebar Background for the focussed window's titlebar

View file

@ -11,6 +11,8 @@
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
struct theme { struct theme {
int border_width;
float window_active_title_bg_color[4]; float window_active_title_bg_color[4];
float window_active_handle_bg_color[4]; float window_active_handle_bg_color[4];

View file

@ -13,16 +13,15 @@
#include "theme.h" #include "theme.h"
#include "ssd.h" #include "ssd.h"
#define BORDER_WIDTH (2)
struct border struct border
ssd_thickness(struct view *view) ssd_thickness(struct view *view)
{ {
struct theme *theme = view->server->theme;
struct border border = { struct border border = {
.top = rc.title_height + BORDER_WIDTH, .top = rc.title_height + theme->border_width,
.bottom = BORDER_WIDTH, .bottom = theme->border_width,
.left = BORDER_WIDTH, .left = theme->border_width,
.right = BORDER_WIDTH, .right = theme->border_width,
}; };
return border; return border;
} }
@ -43,8 +42,9 @@ ssd_max_extents(struct view *view)
struct wlr_box struct wlr_box
ssd_box(struct view *view, enum ssd_part_type type) ssd_box(struct view *view, enum ssd_part_type type)
{ {
struct theme *theme = view->server->theme;
struct wlr_box box = { 0 }; struct wlr_box box = { 0 };
int corner_square = rc.title_height + BORDER_WIDTH; int corner_square = rc.title_height + theme->border_width;
assert(view); assert(view);
switch (type) { switch (type) {
case LAB_SSD_BUTTON_CLOSE: 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.x = view->x + rc.title_height;
box.y = view->y - corner_square; box.y = view->y - corner_square;
box.width = view->w - 2 * rc.title_height; box.width = view->w - 2 * rc.title_height;
box.height = BORDER_WIDTH; box.height = theme->border_width;
break; break;
case LAB_SSD_PART_RIGHT: case LAB_SSD_PART_RIGHT:
box.x = view->x + view->w; box.x = view->x + view->w;
box.y = view->y; box.y = view->y;
box.width = BORDER_WIDTH; box.width = theme->border_width;
box.height = view->h; box.height = view->h;
break; break;
case LAB_SSD_PART_BOTTOM: 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.y = view->y + view->h;
box.width = view->w + 2 * BORDER_WIDTH; box.width = view->w + 2 * theme->border_width;
box.height = +BORDER_WIDTH; box.height = +theme->border_width;
break; break;
case LAB_SSD_PART_LEFT: case LAB_SSD_PART_LEFT:
box.x = view->x - BORDER_WIDTH; box.x = view->x - theme->border_width;
box.y = view->y; box.y = view->y;
box.width = BORDER_WIDTH; box.width = theme->border_width;
box.height = view->h; box.height = view->h;
break; break;
case LAB_SSD_PART_CORNER_TOP_LEFT: 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.y = view->y - corner_square;
box.width = corner_square; box.width = corner_square;
box.height = corner_square; box.height = corner_square;
@ -203,12 +203,12 @@ rounded_rect(struct wlr_renderer *renderer, struct rounded_corner_ctx *ctx)
/* border */ /* border */
cairo_set_line_cap(cairo, CAIRO_LINE_CAP_ROUND); cairo_set_line_cap(cairo, CAIRO_LINE_CAP_ROUND);
set_source(cairo, ctx->border_color); set_source(cairo, ctx->border_color);
cairo_set_line_width(cairo, BORDER_WIDTH); cairo_set_line_width(cairo, ctx->line_width);
double half_line_width = BORDER_WIDTH / 2.0; double half_line_width = ctx->line_width / 2.0;
switch (ctx->corner) { switch (ctx->corner) {
case LAB_CORNER_TOP_LEFT: case LAB_CORNER_TOP_LEFT:
cairo_move_to(cairo, half_line_width, h); 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_arc(cairo, r, r, r - half_line_width, 180 * deg, 270 * deg);
cairo_line_to(cairo, w, half_line_width); cairo_line_to(cairo, w, half_line_width);
break; break;
@ -273,7 +273,7 @@ ssd_create(struct view *view)
struct rounded_corner_ctx ctx = { struct rounded_corner_ctx ctx = {
.box = &part->box, .box = &part->box,
.radius = 7.0, /* TODO: get from config */ .radius = 7.0, /* TODO: get from config */
.line_width = 1.0, .line_width = theme->border_width,
.fill_color = theme->window_active_title_bg_color, .fill_color = theme->window_active_title_bg_color,
.border_color = theme->window_active_handle_bg_color, .border_color = theme->window_active_handle_bg_color,
.corner = LAB_CORNER_TOP_LEFT, .corner = LAB_CORNER_TOP_LEFT,

View file

@ -63,6 +63,7 @@ parse_hexstr(const char *hex, float *rgba)
*/ */
void theme_builtin(struct theme *theme) void theme_builtin(struct theme *theme)
{ {
theme->border_width = 1;
parse_hexstr("#589bda", theme->window_active_title_bg_color); parse_hexstr("#589bda", theme->window_active_title_bg_color);
parse_hexstr("#3c7cb7", theme->window_active_handle_bg_color); parse_hexstr("#3c7cb7", theme->window_active_handle_bg_color);
parse_hexstr("#efece6", theme->window_inactive_title_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) { if (!key || !value) {
return; 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); parse_hexstr(value, theme->window_active_title_bg_color);
} else if (match(key, "window.active.handle.bg.color")) { } else if (match(key, "window.active.handle.bg.color")) {
parse_hexstr(value, theme->window_active_handle_bg_color); parse_hexstr(value, theme->window_active_handle_bg_color);