2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2021-07-16 17:07:00 +01:00
|
|
|
/*
|
|
|
|
|
* Theme engine for labwc
|
|
|
|
|
*
|
2023-08-04 22:30:16 +01:00
|
|
|
* Copyright (C) Johan Malm 2020-2023
|
2021-07-16 17:07:00 +01:00
|
|
|
*/
|
|
|
|
|
|
2020-06-11 21:20:43 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2023-08-21 21:26:08 +01:00
|
|
|
#include "config.h"
|
2021-07-16 17:07:00 +01:00
|
|
|
#include <cairo.h>
|
2020-09-28 20:41:41 +01:00
|
|
|
#include <ctype.h>
|
2021-07-16 17:07:00 +01:00
|
|
|
#include <drm_fourcc.h>
|
2020-09-28 20:41:41 +01:00
|
|
|
#include <glib.h>
|
2021-07-16 17:07:00 +01:00
|
|
|
#include <math.h>
|
2020-09-28 20:41:41 +01:00
|
|
|
#include <stdbool.h>
|
2020-06-11 21:20:43 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2021-07-16 17:07:00 +01:00
|
|
|
#include <wlr/util/box.h>
|
2021-07-22 21:30:17 +01:00
|
|
|
#include <wlr/util/log.h>
|
2021-10-17 19:12:06 +00:00
|
|
|
#include <strings.h>
|
2023-10-20 18:34:14 -04:00
|
|
|
#include "common/macros.h"
|
2020-08-10 17:24:17 +01:00
|
|
|
#include "common/dir.h"
|
2021-04-15 20:13:49 +01:00
|
|
|
#include "common/font.h"
|
2022-08-26 04:50:54 +02:00
|
|
|
#include "common/graphic-helpers.h"
|
2023-04-28 21:21:08 +01:00
|
|
|
#include "common/match.h"
|
2020-10-09 19:46:59 +01:00
|
|
|
#include "common/string-helpers.h"
|
2021-04-15 20:13:49 +01:00
|
|
|
#include "config/rcxml.h"
|
2023-08-10 15:57:20 +01:00
|
|
|
#include "button/button-png.h"
|
2023-08-21 21:26:08 +01:00
|
|
|
|
|
|
|
|
#if HAVE_RSVG
|
|
|
|
|
#include "button/button-svg.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-08-10 15:50:25 +01:00
|
|
|
#include "button/button-xbm.h"
|
2021-02-21 22:18:34 +00:00
|
|
|
#include "theme.h"
|
2022-02-17 01:46:32 +01:00
|
|
|
#include "buffer.h"
|
2022-02-21 03:18:38 +01:00
|
|
|
#include "ssd.h"
|
2020-06-11 21:20:43 +01:00
|
|
|
|
2023-08-04 22:30:16 +01:00
|
|
|
struct button {
|
|
|
|
|
const char *name;
|
2023-12-06 20:33:26 +00:00
|
|
|
const char *alt_name;
|
2023-08-04 22:30:16 +01:00
|
|
|
char fallback_button[6]; /* built-in 6x6 button */
|
|
|
|
|
struct {
|
|
|
|
|
struct lab_data_buffer **buffer;
|
|
|
|
|
float *rgba;
|
|
|
|
|
} active, inactive;
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-21 21:26:08 +01:00
|
|
|
static void
|
|
|
|
|
drop(struct lab_data_buffer **buffer)
|
|
|
|
|
{
|
|
|
|
|
if (*buffer) {
|
|
|
|
|
wlr_buffer_drop(&(*buffer)->base);
|
|
|
|
|
*buffer = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-09 19:37:35 +00:00
|
|
|
/*
|
|
|
|
|
* We use the following button filename schema: "BUTTON [TOGGLED] [STATE]"
|
|
|
|
|
* with the words separted by underscore, and the following meaning:
|
|
|
|
|
* - BUTTON can be one of 'max', 'iconify', 'close', 'menu'
|
|
|
|
|
* - TOGGLED is either 'toggled' or nothing
|
|
|
|
|
* - STATE is 'hover' or nothing. In future, 'pressed' may be supported too.
|
|
|
|
|
*
|
|
|
|
|
* We believe that this is how the vast majority of extant openbox themes out
|
|
|
|
|
* there are constructed and it is consistent with the openbox.org wiki. But
|
|
|
|
|
* please be aware that it is actually different to vanilla Openbox which uses:
|
|
|
|
|
* "BUTTON [STATE] [TOGGLED]" following an unfortunate commit in 2014 which
|
|
|
|
|
* broke themes and led to some distros patching Openbox:
|
|
|
|
|
* https://github.com/danakj/openbox/commit/35e92e4c2a45b28d5c2c9b44b64aeb4222098c94
|
|
|
|
|
*
|
|
|
|
|
* Arch Linux and Debian patch Openbox to keep the old syntax (the one we use).
|
|
|
|
|
* https://gitlab.archlinux.org/archlinux/packaging/packages/openbox/-/blob/main/debian-887908.patch?ref_type=heads
|
|
|
|
|
* This patch does the following:
|
|
|
|
|
* - reads "%s_toggled_pressed.xbm" and "%s_toggled_hover.xbm" instead of the
|
|
|
|
|
* 'hover_toggled' equivalents.
|
|
|
|
|
* - parses 'toggled.unpressed', toggled.pressed' and 'toggled.hover' instead
|
|
|
|
|
* of the other way around ('*.toggled') when processing themerc.
|
|
|
|
|
*
|
|
|
|
|
* For compatibility with distros which do not apply similar patches, we support
|
|
|
|
|
* the hover-before-toggle too, for example:
|
|
|
|
|
*
|
|
|
|
|
* .name = "max_toggled_hover",
|
|
|
|
|
* .alt_name = "max_hover_toggled",
|
|
|
|
|
*
|
|
|
|
|
* ...in the button array definition below.
|
|
|
|
|
*/
|
2023-08-04 22:30:16 +01:00
|
|
|
static void
|
|
|
|
|
load_buttons(struct theme *theme)
|
|
|
|
|
{
|
2023-12-09 19:20:54 +00:00
|
|
|
struct button buttons[] = { {
|
|
|
|
|
.name = "menu",
|
|
|
|
|
.fallback_button = { 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00 },
|
|
|
|
|
.active.buffer = &theme->button_menu_active_unpressed,
|
|
|
|
|
.active.rgba = theme->window_active_button_menu_unpressed_image_color,
|
|
|
|
|
.inactive.buffer = &theme->button_menu_inactive_unpressed,
|
|
|
|
|
.inactive.rgba = theme->window_inactive_button_menu_unpressed_image_color,
|
|
|
|
|
}, {
|
|
|
|
|
.name = "iconify",
|
|
|
|
|
.fallback_button = { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f },
|
|
|
|
|
.active.buffer = &theme->button_iconify_active_unpressed,
|
|
|
|
|
.active.rgba = theme->window_active_button_iconify_unpressed_image_color,
|
|
|
|
|
.inactive.buffer = &theme->button_iconify_inactive_unpressed,
|
|
|
|
|
.inactive.rgba = theme->window_inactive_button_iconify_unpressed_image_color,
|
|
|
|
|
}, {
|
|
|
|
|
.name = "max",
|
|
|
|
|
.fallback_button = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f },
|
|
|
|
|
.active.buffer = &theme->button_maximize_active_unpressed,
|
|
|
|
|
.active.rgba = theme->window_active_button_max_unpressed_image_color,
|
|
|
|
|
.inactive.buffer = &theme->button_maximize_inactive_unpressed,
|
|
|
|
|
.inactive.rgba = theme->window_inactive_button_max_unpressed_image_color,
|
|
|
|
|
}, {
|
|
|
|
|
.name = "max_toggled",
|
|
|
|
|
.fallback_button = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f },
|
|
|
|
|
.active.buffer = &theme->button_restore_active_unpressed,
|
|
|
|
|
.active.rgba = theme->window_active_button_max_unpressed_image_color,
|
|
|
|
|
.inactive.buffer = &theme->button_restore_inactive_unpressed,
|
|
|
|
|
.inactive.rgba = theme->window_inactive_button_max_unpressed_image_color,
|
|
|
|
|
}, {
|
|
|
|
|
.name = "close",
|
|
|
|
|
.fallback_button = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 },
|
|
|
|
|
.active.buffer = &theme->button_close_active_unpressed,
|
|
|
|
|
.active.rgba = theme->window_active_button_close_unpressed_image_color,
|
|
|
|
|
.inactive.buffer = &theme->button_close_inactive_unpressed,
|
|
|
|
|
.inactive.rgba = theme->window_inactive_button_close_unpressed_image_color,
|
|
|
|
|
}, {
|
|
|
|
|
.name = "menu_hover",
|
|
|
|
|
.fallback_button = { 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00 },
|
|
|
|
|
.active.buffer = &theme->button_menu_active_hover,
|
|
|
|
|
.active.rgba = theme->window_active_button_menu_unpressed_image_color,
|
|
|
|
|
.inactive.buffer = &theme->button_menu_inactive_hover,
|
|
|
|
|
.inactive.rgba = theme->window_inactive_button_menu_unpressed_image_color,
|
|
|
|
|
}, {
|
|
|
|
|
.name = "iconify_hover",
|
|
|
|
|
.fallback_button = { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f },
|
|
|
|
|
.active.buffer = &theme->button_iconify_active_hover,
|
|
|
|
|
.active.rgba = theme->window_active_button_iconify_unpressed_image_color,
|
|
|
|
|
.inactive.buffer = &theme->button_iconify_inactive_hover,
|
|
|
|
|
.inactive.rgba = theme->window_inactive_button_iconify_unpressed_image_color,
|
|
|
|
|
}, {
|
|
|
|
|
.name = "max_hover",
|
|
|
|
|
.fallback_button = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f },
|
|
|
|
|
.active.buffer = &theme->button_maximize_active_hover,
|
|
|
|
|
.active.rgba = theme->window_active_button_max_unpressed_image_color,
|
|
|
|
|
.inactive.buffer = &theme->button_maximize_inactive_hover,
|
|
|
|
|
.inactive.rgba = theme->window_inactive_button_max_unpressed_image_color,
|
|
|
|
|
}, {
|
2023-12-09 19:37:35 +00:00
|
|
|
.name = "max_toggled_hover",
|
|
|
|
|
.alt_name = "max_hover_toggled",
|
2023-12-09 19:20:54 +00:00
|
|
|
.fallback_button = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f },
|
|
|
|
|
.active.buffer = &theme->button_restore_active_hover,
|
|
|
|
|
.active.rgba = theme->window_active_button_max_unpressed_image_color,
|
|
|
|
|
.inactive.buffer = &theme->button_restore_inactive_hover,
|
|
|
|
|
.inactive.rgba = theme->window_inactive_button_max_unpressed_image_color,
|
|
|
|
|
}, {
|
|
|
|
|
.name = "close_hover",
|
|
|
|
|
.fallback_button = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 },
|
|
|
|
|
.active.buffer = &theme->button_close_active_hover,
|
|
|
|
|
.active.rgba = theme->window_active_button_close_unpressed_image_color,
|
|
|
|
|
.inactive.buffer = &theme->button_close_inactive_hover,
|
|
|
|
|
.inactive.rgba = theme->window_inactive_button_close_unpressed_image_color,
|
|
|
|
|
}, };
|
2023-08-04 22:30:16 +01:00
|
|
|
|
|
|
|
|
char filename[4096] = {0};
|
2023-12-06 20:33:26 +00:00
|
|
|
char alt_filename[4096] = {0};
|
2023-09-16 22:25:41 +01:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(buttons); ++i) {
|
2023-08-04 22:30:16 +01:00
|
|
|
struct button *b = &buttons[i];
|
2023-08-04 22:34:07 +01:00
|
|
|
|
2023-08-21 21:26:08 +01:00
|
|
|
drop(b->active.buffer);
|
|
|
|
|
drop(b->inactive.buffer);
|
|
|
|
|
|
2023-08-04 22:34:07 +01:00
|
|
|
/* Try png icon first */
|
|
|
|
|
snprintf(filename, sizeof(filename), "%s-active.png", b->name);
|
2023-09-16 22:36:31 +01:00
|
|
|
button_png_load(filename, b->active.buffer);
|
2023-08-04 22:34:07 +01:00
|
|
|
snprintf(filename, sizeof(filename), "%s-inactive.png", b->name);
|
2023-09-16 22:36:31 +01:00
|
|
|
button_png_load(filename, b->inactive.buffer);
|
2023-08-04 22:34:07 +01:00
|
|
|
|
2023-08-21 21:26:08 +01:00
|
|
|
#if HAVE_RSVG
|
|
|
|
|
/* Then try svg icon */
|
|
|
|
|
int size = theme->title_height - 2 * theme->padding_height;
|
|
|
|
|
if (!*b->active.buffer) {
|
|
|
|
|
snprintf(filename, sizeof(filename), "%s-active.svg", b->name);
|
|
|
|
|
button_svg_load(filename, b->active.buffer, size);
|
|
|
|
|
}
|
|
|
|
|
if (!*b->inactive.buffer) {
|
|
|
|
|
snprintf(filename, sizeof(filename), "%s-inactive.svg", b->name);
|
|
|
|
|
button_svg_load(filename, b->inactive.buffer, size);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* If there were no png/svg buttons, use xbm */
|
2023-08-04 22:30:16 +01:00
|
|
|
snprintf(filename, sizeof(filename), "%s.xbm", b->name);
|
2023-12-06 21:55:31 +00:00
|
|
|
alt_filename[0] = '\0';
|
2023-12-06 20:33:26 +00:00
|
|
|
if (b->alt_name) {
|
|
|
|
|
snprintf(alt_filename, sizeof(alt_filename), "%s.xbm", b->alt_name);
|
|
|
|
|
}
|
2023-08-04 22:34:07 +01:00
|
|
|
if (!*b->active.buffer) {
|
2023-12-06 20:33:26 +00:00
|
|
|
button_xbm_load(filename, alt_filename, b->active.buffer,
|
2023-08-04 22:34:07 +01:00
|
|
|
b->fallback_button, b->active.rgba);
|
|
|
|
|
}
|
|
|
|
|
if (!*b->inactive.buffer) {
|
2023-12-06 20:33:26 +00:00
|
|
|
button_xbm_load(filename, alt_filename, b->inactive.buffer,
|
2023-08-04 22:34:07 +01:00
|
|
|
b->fallback_button, b->inactive.rgba);
|
|
|
|
|
}
|
2023-08-04 22:30:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static int
|
|
|
|
|
hex_to_dec(char c)
|
2020-06-11 21:20:43 +01:00
|
|
|
{
|
2020-09-28 20:41:41 +01:00
|
|
|
if (c >= '0' && c <= '9') {
|
2020-06-11 21:20:43 +01:00
|
|
|
return c - '0';
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
|
|
|
|
if (c >= 'a' && c <= 'f') {
|
2020-06-11 21:20:43 +01:00
|
|
|
return c - 'a' + 10;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
|
|
|
|
if (c >= 'A' && c <= 'F') {
|
2020-06-11 21:20:43 +01:00
|
|
|
return c - 'A' + 10;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-11 21:20:43 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-21 22:13:18 +00:00
|
|
|
/**
|
|
|
|
|
* parse_hexstr - parse #rrggbb
|
|
|
|
|
* @hex: hex string to be parsed
|
|
|
|
|
* @rgba: pointer to float[4] for return value
|
|
|
|
|
*/
|
2021-07-20 21:27:41 +01:00
|
|
|
static void
|
2020-09-28 20:41:41 +01:00
|
|
|
parse_hexstr(const char *hex, float *rgba)
|
2020-06-11 21:20:43 +01:00
|
|
|
{
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!hex || hex[0] != '#' || strlen(hex) < 7) {
|
2020-06-11 21:20:43 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-11 21:20:43 +01:00
|
|
|
rgba[0] = (hex_to_dec(hex[1]) * 16 + hex_to_dec(hex[2])) / 255.0;
|
|
|
|
|
rgba[1] = (hex_to_dec(hex[3]) * 16 + hex_to_dec(hex[4])) / 255.0;
|
|
|
|
|
rgba[2] = (hex_to_dec(hex[5]) * 16 + hex_to_dec(hex[6])) / 255.0;
|
2020-09-28 20:41:41 +01:00
|
|
|
if (strlen(hex) > 7) {
|
2020-06-11 21:20:43 +01:00
|
|
|
rgba[3] = atoi(hex + 7) / 100.0;
|
2020-09-28 20:41:41 +01:00
|
|
|
} else {
|
2020-06-11 21:20:43 +01:00
|
|
|
rgba[3] = 1.0;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-11 21:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-17 19:12:06 +00:00
|
|
|
static enum lab_justification
|
|
|
|
|
parse_justification(const char *str)
|
|
|
|
|
{
|
|
|
|
|
if (!strcasecmp(str, "Center")) {
|
|
|
|
|
return LAB_JUSTIFY_CENTER;
|
|
|
|
|
} else if (!strcasecmp(str, "Right")) {
|
|
|
|
|
return LAB_JUSTIFY_RIGHT;
|
|
|
|
|
} else {
|
|
|
|
|
return LAB_JUSTIFY_LEFT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-21 22:13:18 +00:00
|
|
|
/*
|
|
|
|
|
* We generally use Openbox defaults, but if no theme file can be found it's
|
|
|
|
|
* better to populate the theme variables with some sane values as no-one
|
|
|
|
|
* wants to use openbox without a theme - it'll all just be black and white.
|
|
|
|
|
*
|
|
|
|
|
* Openbox doesn't actual start if it can't find a theme. As it's normally
|
|
|
|
|
* packaged with Clearlooks, this is not a problem, but for labwc I thought
|
|
|
|
|
* this was a bit hard-line. People might want to try labwc without having
|
|
|
|
|
* Openbox (and associated themes) installed.
|
|
|
|
|
*
|
2021-10-15 21:44:27 +01:00
|
|
|
* theme_builtin() applies a theme that is similar to vanilla GTK
|
2021-02-21 22:13:18 +00:00
|
|
|
*/
|
2021-07-20 21:27:41 +01:00
|
|
|
static void
|
|
|
|
|
theme_builtin(struct theme *theme)
|
2021-02-21 22:13:18 +00:00
|
|
|
{
|
2021-03-27 21:09:45 +00:00
|
|
|
theme->border_width = 1;
|
2021-04-15 20:13:49 +01:00
|
|
|
theme->padding_height = 3;
|
2023-10-02 12:44:30 -03:00
|
|
|
theme->title_height = INT_MIN;
|
2021-11-08 17:36:39 +00:00
|
|
|
theme->menu_overlap_x = 0;
|
|
|
|
|
theme->menu_overlap_y = 0;
|
2021-04-10 19:11:29 +01:00
|
|
|
|
2023-11-28 08:22:54 +02:00
|
|
|
parse_hexstr("#e1dedb", theme->window_active_border_color);
|
2021-04-10 19:30:39 +01:00
|
|
|
parse_hexstr("#f6f5f4", theme->window_inactive_border_color);
|
2021-04-10 19:11:29 +01:00
|
|
|
|
2023-03-05 10:35:56 +01:00
|
|
|
parse_hexstr("#ff0000", theme->window_toggled_keybinds_color);
|
|
|
|
|
|
2023-11-28 08:22:54 +02:00
|
|
|
parse_hexstr("#e1dedb", theme->window_active_title_bg_color);
|
2021-04-10 19:30:39 +01:00
|
|
|
parse_hexstr("#f6f5f4", theme->window_inactive_title_bg_color);
|
2021-04-10 19:11:29 +01:00
|
|
|
|
2021-10-15 21:35:41 +01:00
|
|
|
parse_hexstr("#000000", theme->window_active_label_text_color);
|
|
|
|
|
parse_hexstr("#000000", theme->window_inactive_label_text_color);
|
2022-04-22 17:54:20 +01:00
|
|
|
theme->window_label_text_justify = parse_justification("Center");
|
2021-10-15 21:35:41 +01:00
|
|
|
|
2022-01-26 02:54:03 +01:00
|
|
|
parse_hexstr("#000000",
|
|
|
|
|
theme->window_active_button_menu_unpressed_image_color);
|
2021-09-21 22:05:56 +01:00
|
|
|
parse_hexstr("#000000",
|
|
|
|
|
theme->window_active_button_iconify_unpressed_image_color);
|
|
|
|
|
parse_hexstr("#000000",
|
|
|
|
|
theme->window_active_button_max_unpressed_image_color);
|
|
|
|
|
parse_hexstr("#000000",
|
|
|
|
|
theme->window_active_button_close_unpressed_image_color);
|
2022-01-26 02:54:03 +01:00
|
|
|
parse_hexstr("#000000",
|
|
|
|
|
theme->window_inactive_button_menu_unpressed_image_color);
|
2021-09-21 22:05:56 +01:00
|
|
|
parse_hexstr("#000000",
|
|
|
|
|
theme->window_inactive_button_iconify_unpressed_image_color);
|
|
|
|
|
parse_hexstr("#000000",
|
|
|
|
|
theme->window_inactive_button_max_unpressed_image_color);
|
|
|
|
|
parse_hexstr("#000000",
|
|
|
|
|
theme->window_inactive_button_close_unpressed_image_color);
|
2021-04-10 19:11:29 +01:00
|
|
|
|
2021-02-21 22:13:18 +00:00
|
|
|
parse_hexstr("#fcfbfa", theme->menu_items_bg_color);
|
|
|
|
|
parse_hexstr("#000000", theme->menu_items_text_color);
|
2023-11-28 08:22:54 +02:00
|
|
|
parse_hexstr("#e1dedb", theme->menu_items_active_bg_color);
|
2021-04-10 19:30:39 +01:00
|
|
|
parse_hexstr("#000000", theme->menu_items_active_text_color);
|
2021-10-13 21:29:32 +01:00
|
|
|
|
2022-12-06 14:38:56 +01:00
|
|
|
theme->menu_item_padding_x = 7;
|
|
|
|
|
theme->menu_item_padding_y = 4;
|
|
|
|
|
|
2022-12-05 14:38:16 +01:00
|
|
|
theme->menu_min_width = 20;
|
|
|
|
|
theme->menu_max_width = 200;
|
|
|
|
|
|
2022-12-06 12:01:44 +01:00
|
|
|
theme->menu_separator_line_thickness = 1;
|
2022-06-22 21:07:25 +01:00
|
|
|
theme->menu_separator_padding_width = 6;
|
|
|
|
|
theme->menu_separator_padding_height = 3;
|
|
|
|
|
parse_hexstr("#888888", theme->menu_separator_color);
|
|
|
|
|
|
2023-04-24 21:31:28 +01:00
|
|
|
theme->osd_window_switcher_width = 600;
|
2023-07-01 14:56:13 +02:00
|
|
|
theme->osd_window_switcher_padding = 4;
|
2023-04-24 21:31:28 +01:00
|
|
|
theme->osd_window_switcher_item_padding_x = 10;
|
2023-07-01 14:56:13 +02:00
|
|
|
theme->osd_window_switcher_item_padding_y = 1;
|
|
|
|
|
theme->osd_window_switcher_item_active_border_width = 2;
|
2023-04-24 21:31:28 +01:00
|
|
|
|
2022-05-31 19:14:58 +02:00
|
|
|
/* inherit settings in post_processing() if not set elsewhere */
|
2021-10-15 21:44:27 +01:00
|
|
|
theme->osd_bg_color[0] = FLT_MIN;
|
2022-05-31 19:14:58 +02:00
|
|
|
theme->osd_border_width = INT_MIN;
|
|
|
|
|
theme->osd_border_color[0] = FLT_MIN;
|
2021-10-15 21:44:27 +01:00
|
|
|
theme->osd_label_text_color[0] = FLT_MIN;
|
2021-02-21 22:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-20 21:27:41 +01:00
|
|
|
static void
|
|
|
|
|
entry(struct theme *theme, const char *key, const char *value)
|
2020-06-11 21:20:43 +01:00
|
|
|
{
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!key || !value) {
|
2020-06-11 21:20:43 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2021-04-10 19:17:39 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Note that in order for the pattern match to apply to more than just
|
|
|
|
|
* the first instance, "else if" cannot be used throughout this function
|
|
|
|
|
*/
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "border.width")) {
|
2021-03-27 21:09:45 +00:00
|
|
|
theme->border_width = atoi(value);
|
2021-04-10 19:17:39 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "padding.height")) {
|
2021-04-15 20:13:49 +01:00
|
|
|
theme->padding_height = atoi(value);
|
|
|
|
|
}
|
2023-10-02 12:44:30 -03:00
|
|
|
if (match_glob(key, "titlebar.height")) {
|
|
|
|
|
theme->title_height = atoi(value);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.items.padding.x")) {
|
2022-12-06 14:38:56 +01:00
|
|
|
theme->menu_item_padding_x = atoi(value);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.items.padding.y")) {
|
2022-12-06 14:38:56 +01:00
|
|
|
theme->menu_item_padding_y = atoi(value);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.overlap.x")) {
|
2021-11-08 17:36:39 +00:00
|
|
|
theme->menu_overlap_x = atoi(value);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.overlap.y")) {
|
2021-11-08 17:36:39 +00:00
|
|
|
theme->menu_overlap_y = atoi(value);
|
|
|
|
|
}
|
2021-04-10 19:11:29 +01:00
|
|
|
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.active.border.color")) {
|
2021-04-10 19:11:29 +01:00
|
|
|
parse_hexstr(value, theme->window_active_border_color);
|
2021-04-10 19:17:39 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.inactive.border.color")) {
|
2021-04-10 19:11:29 +01:00
|
|
|
parse_hexstr(value, theme->window_inactive_border_color);
|
2021-04-10 19:17:39 +01:00
|
|
|
}
|
2021-09-24 21:26:31 +01:00
|
|
|
/* border.color is obsolete, but handled for backward compatibility */
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "border.color")) {
|
2021-09-24 21:26:31 +01:00
|
|
|
parse_hexstr(value, theme->window_active_border_color);
|
|
|
|
|
parse_hexstr(value, theme->window_inactive_border_color);
|
|
|
|
|
}
|
2021-04-10 19:11:29 +01:00
|
|
|
|
2023-03-05 10:35:56 +01:00
|
|
|
if (match_glob(key, "window.active.indicator.toggled-keybind.color")) {
|
|
|
|
|
parse_hexstr(value, theme->window_toggled_keybinds_color);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.active.title.bg.color")) {
|
2021-02-21 21:54:40 +00:00
|
|
|
parse_hexstr(value, theme->window_active_title_bg_color);
|
2021-04-10 19:17:39 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.inactive.title.bg.color")) {
|
2021-02-21 21:54:40 +00:00
|
|
|
parse_hexstr(value, theme->window_inactive_title_bg_color);
|
2021-04-10 19:17:39 +01:00
|
|
|
}
|
2021-04-10 19:11:29 +01:00
|
|
|
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.active.label.text.color")) {
|
2021-10-15 21:35:41 +01:00
|
|
|
parse_hexstr(value, theme->window_active_label_text_color);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.inactive.label.text.color")) {
|
2021-10-15 21:35:41 +01:00
|
|
|
parse_hexstr(value, theme->window_inactive_label_text_color);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.label.text.justify")) {
|
2021-10-17 19:12:06 +00:00
|
|
|
theme->window_label_text_justify = parse_justification(value);
|
|
|
|
|
}
|
2021-10-15 21:35:41 +01:00
|
|
|
|
2021-08-11 20:58:35 +01:00
|
|
|
/* universal button */
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.active.button.unpressed.image.color")) {
|
2022-01-26 02:54:03 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_active_button_menu_unpressed_image_color);
|
2021-09-21 22:05:56 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_active_button_iconify_unpressed_image_color);
|
|
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_active_button_max_unpressed_image_color);
|
|
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_active_button_close_unpressed_image_color);
|
2021-04-10 19:17:39 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.inactive.button.unpressed.image.color")) {
|
2022-01-26 02:54:03 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_inactive_button_menu_unpressed_image_color);
|
2021-09-21 22:05:56 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_inactive_button_iconify_unpressed_image_color);
|
|
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_inactive_button_max_unpressed_image_color);
|
|
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_inactive_button_close_unpressed_image_color);
|
2021-08-11 20:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* individual buttons */
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.active.button.menu.unpressed.image.color")) {
|
2022-12-23 18:18:05 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_active_button_menu_unpressed_image_color);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.active.button.iconify.unpressed.image.color")) {
|
2021-09-21 22:05:56 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_active_button_iconify_unpressed_image_color);
|
2021-08-11 20:58:35 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.active.button.max.unpressed.image.color")) {
|
2021-09-21 22:05:56 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_active_button_max_unpressed_image_color);
|
2021-08-11 20:58:35 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.active.button.close.unpressed.image.color")) {
|
2021-09-21 22:05:56 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_active_button_close_unpressed_image_color);
|
2021-08-11 20:58:35 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.inactive.button.menu.unpressed.image.color")) {
|
2022-12-23 18:18:05 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_inactive_button_menu_unpressed_image_color);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.inactive.button.iconify.unpressed.image.color")) {
|
2021-09-21 22:05:56 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_inactive_button_iconify_unpressed_image_color);
|
2021-08-11 20:58:35 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.inactive.button.max.unpressed.image.color")) {
|
2021-09-21 22:05:56 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_inactive_button_max_unpressed_image_color);
|
2021-08-11 20:58:35 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "window.inactive.button.close.unpressed.image.color")) {
|
2021-09-21 22:05:56 +01:00
|
|
|
parse_hexstr(value,
|
|
|
|
|
theme->window_inactive_button_close_unpressed_image_color);
|
2021-04-10 19:17:39 +01:00
|
|
|
}
|
2021-04-10 19:11:29 +01:00
|
|
|
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.width.min")) {
|
2022-12-05 14:38:16 +01:00
|
|
|
theme->menu_min_width = atoi(value);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.width.max")) {
|
2022-12-05 14:38:16 +01:00
|
|
|
theme->menu_max_width = atoi(value);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.items.bg.color")) {
|
2021-02-21 21:54:40 +00:00
|
|
|
parse_hexstr(value, theme->menu_items_bg_color);
|
2021-04-10 19:17:39 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.items.text.color")) {
|
2021-02-21 21:54:40 +00:00
|
|
|
parse_hexstr(value, theme->menu_items_text_color);
|
2021-04-10 19:17:39 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.items.active.bg.color")) {
|
2021-02-21 21:54:40 +00:00
|
|
|
parse_hexstr(value, theme->menu_items_active_bg_color);
|
2021-04-10 19:17:39 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.items.active.text.color")) {
|
2021-02-21 21:54:40 +00:00
|
|
|
parse_hexstr(value, theme->menu_items_active_text_color);
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2021-10-13 21:29:32 +01:00
|
|
|
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.separator.width")) {
|
2022-12-06 12:01:44 +01:00
|
|
|
theme->menu_separator_line_thickness = atoi(value);
|
2022-06-22 21:07:25 +01:00
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.separator.padding.width")) {
|
2022-06-22 21:07:25 +01:00
|
|
|
theme->menu_separator_padding_width = atoi(value);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.separator.padding.height")) {
|
2022-06-22 21:07:25 +01:00
|
|
|
theme->menu_separator_padding_height = atoi(value);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "menu.separator.color")) {
|
2022-06-22 21:07:25 +01:00
|
|
|
parse_hexstr(value, theme->menu_separator_color);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "osd.bg.color")) {
|
2021-10-13 21:29:32 +01:00
|
|
|
parse_hexstr(value, theme->osd_bg_color);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "osd.border.width")) {
|
2022-05-31 19:14:58 +02:00
|
|
|
theme->osd_border_width = atoi(value);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "osd.border.color")) {
|
2022-05-31 19:14:58 +02:00
|
|
|
parse_hexstr(value, theme->osd_border_color);
|
|
|
|
|
}
|
2023-04-24 21:31:28 +01:00
|
|
|
if (match_glob(key, "osd.window-switcher.width")) {
|
|
|
|
|
theme->osd_window_switcher_width = atoi(value);
|
|
|
|
|
}
|
2023-06-29 21:29:43 +01:00
|
|
|
if (match_glob(key, "osd.window-switcher.padding")) {
|
|
|
|
|
theme->osd_window_switcher_padding = atoi(value);
|
|
|
|
|
}
|
2023-04-24 21:31:28 +01:00
|
|
|
if (match_glob(key, "osd.window-switcher.item.padding.x")) {
|
|
|
|
|
theme->osd_window_switcher_item_padding_x = atoi(value);
|
|
|
|
|
}
|
|
|
|
|
if (match_glob(key, "osd.window-switcher.item.padding.y")) {
|
|
|
|
|
theme->osd_window_switcher_item_padding_y = atoi(value);
|
|
|
|
|
}
|
2023-07-01 14:56:13 +02:00
|
|
|
if (match_glob(key, "osd.window-switcher.item.active.border.width")) {
|
|
|
|
|
theme->osd_window_switcher_item_active_border_width = atoi(value);
|
|
|
|
|
}
|
2023-04-28 21:21:08 +01:00
|
|
|
if (match_glob(key, "osd.label.text.color")) {
|
2021-10-13 21:29:32 +01:00
|
|
|
parse_hexstr(value, theme->osd_label_text_color);
|
|
|
|
|
}
|
2020-06-11 21:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
parse_config_line(char *line, char **key, char **value)
|
2020-06-11 21:20:43 +01:00
|
|
|
{
|
|
|
|
|
char *p = strchr(line, ':');
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!p) {
|
2020-06-11 21:20:43 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-11 21:20:43 +01:00
|
|
|
*p = '\0';
|
2020-10-09 19:46:59 +01:00
|
|
|
*key = string_strip(line);
|
|
|
|
|
*value = string_strip(++p);
|
2020-06-11 21:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
2021-02-21 21:54:40 +00:00
|
|
|
process_line(struct theme *theme, char *line)
|
2020-06-11 21:20:43 +01:00
|
|
|
{
|
2020-09-28 20:41:41 +01:00
|
|
|
if (line[0] == '\0' || line[0] == '#') {
|
2020-06-11 21:20:43 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-11 21:20:43 +01:00
|
|
|
char *key = NULL, *value = NULL;
|
|
|
|
|
parse_config_line(line, &key, &value);
|
2021-02-21 21:54:40 +00:00
|
|
|
entry(theme, key, value);
|
2020-06-11 21:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-21 21:14:06 +00:00
|
|
|
static void
|
2021-02-21 21:54:40 +00:00
|
|
|
theme_read(struct theme *theme, const char *theme_name)
|
2020-06-11 21:20:43 +01:00
|
|
|
{
|
2020-09-14 18:17:36 +01:00
|
|
|
FILE *stream = NULL;
|
2020-06-11 21:20:43 +01:00
|
|
|
char *line = NULL;
|
|
|
|
|
size_t len = 0;
|
2020-07-20 19:53:03 +01:00
|
|
|
char themerc[4096];
|
2020-06-11 21:20:43 +01:00
|
|
|
|
2020-09-14 18:17:36 +01:00
|
|
|
if (strlen(theme_dir(theme_name))) {
|
|
|
|
|
snprintf(themerc, sizeof(themerc), "%s/themerc",
|
2023-01-31 11:43:45 +01:00
|
|
|
theme_dir(theme_name));
|
2020-09-14 18:17:36 +01:00
|
|
|
stream = fopen(themerc, "r");
|
|
|
|
|
}
|
2020-06-11 21:20:43 +01:00
|
|
|
if (!stream) {
|
2021-06-28 20:48:55 +01:00
|
|
|
if (theme_name) {
|
2021-07-22 21:30:17 +01:00
|
|
|
wlr_log(WLR_INFO, "cannot find theme %s", theme_name);
|
2021-06-28 20:48:55 +01:00
|
|
|
}
|
2020-06-11 21:20:43 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2021-07-22 21:30:17 +01:00
|
|
|
wlr_log(WLR_INFO, "read theme %s", themerc);
|
2020-06-18 20:39:55 +01:00
|
|
|
while (getline(&line, &len, stream) != -1) {
|
2020-06-11 21:20:43 +01:00
|
|
|
char *p = strrchr(line, '\n');
|
2020-09-28 20:41:41 +01:00
|
|
|
if (p) {
|
2020-06-11 21:20:43 +01:00
|
|
|
*p = '\0';
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2021-02-21 21:54:40 +00:00
|
|
|
process_line(theme, line);
|
2020-06-11 21:20:43 +01:00
|
|
|
}
|
|
|
|
|
free(line);
|
|
|
|
|
fclose(stream);
|
|
|
|
|
}
|
2021-02-21 21:14:06 +00:00
|
|
|
|
2022-12-05 21:46:16 +00:00
|
|
|
static void
|
|
|
|
|
theme_read_override(struct theme *theme)
|
|
|
|
|
{
|
|
|
|
|
char f[4096] = { 0 };
|
|
|
|
|
snprintf(f, sizeof(f), "%s/themerc-override", rc.config_dir);
|
|
|
|
|
|
|
|
|
|
FILE *stream = fopen(f, "r");
|
|
|
|
|
if (!stream) {
|
|
|
|
|
wlr_log(WLR_INFO, "no theme override '%s'", f);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wlr_log(WLR_INFO, "read theme-override %s", f);
|
|
|
|
|
char *line = NULL;
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
while (getline(&line, &len, stream) != -1) {
|
|
|
|
|
char *p = strrchr(line, '\n');
|
|
|
|
|
if (p) {
|
|
|
|
|
*p = '\0';
|
|
|
|
|
}
|
|
|
|
|
process_line(theme, line);
|
|
|
|
|
}
|
|
|
|
|
free(line);
|
|
|
|
|
fclose(stream);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-16 17:07:00 +01:00
|
|
|
struct rounded_corner_ctx {
|
|
|
|
|
struct wlr_box *box;
|
|
|
|
|
double radius;
|
|
|
|
|
double line_width;
|
|
|
|
|
float *fill_color;
|
|
|
|
|
float *border_color;
|
|
|
|
|
enum {
|
|
|
|
|
LAB_CORNER_UNKNOWN = 0,
|
|
|
|
|
LAB_CORNER_TOP_LEFT,
|
|
|
|
|
LAB_CORNER_TOP_RIGHT,
|
|
|
|
|
} corner;
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-17 01:46:32 +01:00
|
|
|
static struct lab_data_buffer *
|
|
|
|
|
rounded_rect(struct rounded_corner_ctx *ctx)
|
2021-07-16 17:07:00 +01:00
|
|
|
{
|
|
|
|
|
/* 1 degree in radians (=2π/360) */
|
|
|
|
|
double deg = 0.017453292519943295;
|
|
|
|
|
|
|
|
|
|
if (ctx->corner == LAB_CORNER_UNKNOWN) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double w = ctx->box->width;
|
|
|
|
|
double h = ctx->box->height;
|
|
|
|
|
double r = ctx->radius;
|
|
|
|
|
|
2022-02-17 01:46:32 +01:00
|
|
|
struct lab_data_buffer *buffer;
|
|
|
|
|
/* TODO: scale */
|
|
|
|
|
buffer = buffer_create_cairo(w, h, 1, true);
|
|
|
|
|
|
|
|
|
|
cairo_t *cairo = buffer->cairo;
|
|
|
|
|
cairo_surface_t *surf = cairo_get_target(cairo);
|
2021-07-16 17:07:00 +01:00
|
|
|
|
|
|
|
|
/* set transparent background */
|
|
|
|
|
cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
|
|
|
|
|
cairo_paint(cairo);
|
|
|
|
|
|
2023-07-15 21:50:40 +01:00
|
|
|
/*
|
|
|
|
|
* Create outline path and fill. Illustration of top-left corner buffer:
|
|
|
|
|
*
|
|
|
|
|
* _,,ooO"""""""""+
|
|
|
|
|
* ,oO"' ^ |
|
|
|
|
|
* ,o" | |
|
|
|
|
|
* o" |r |
|
|
|
|
|
* o' | |
|
|
|
|
|
* O r v |
|
|
|
|
|
* O<--------->+ |
|
|
|
|
|
* O |
|
|
|
|
|
* O |
|
|
|
|
|
* O |
|
|
|
|
|
* +--------------------+
|
|
|
|
|
*/
|
2021-07-16 17:07:00 +01:00
|
|
|
cairo_set_line_width(cairo, 0.0);
|
|
|
|
|
cairo_new_sub_path(cairo);
|
|
|
|
|
switch (ctx->corner) {
|
|
|
|
|
case LAB_CORNER_TOP_LEFT:
|
|
|
|
|
cairo_arc(cairo, r, r, r, 180 * deg, 270 * deg);
|
|
|
|
|
cairo_line_to(cairo, w, 0);
|
|
|
|
|
cairo_line_to(cairo, w, h);
|
|
|
|
|
cairo_line_to(cairo, 0, h);
|
|
|
|
|
break;
|
|
|
|
|
case LAB_CORNER_TOP_RIGHT:
|
|
|
|
|
cairo_arc(cairo, w - r, r, r, -90 * deg, 0 * deg);
|
|
|
|
|
cairo_line_to(cairo, w, h);
|
|
|
|
|
cairo_line_to(cairo, 0, h);
|
|
|
|
|
cairo_line_to(cairo, 0, 0);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2021-07-23 21:15:55 +01:00
|
|
|
wlr_log(WLR_ERROR, "unknown corner type");
|
2021-07-16 17:07:00 +01:00
|
|
|
}
|
|
|
|
|
cairo_close_path(cairo);
|
|
|
|
|
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
2022-08-26 04:50:54 +02:00
|
|
|
set_cairo_color(cairo, ctx->fill_color);
|
2021-07-16 17:07:00 +01:00
|
|
|
cairo_fill_preserve(cairo);
|
|
|
|
|
cairo_stroke(cairo);
|
|
|
|
|
|
2023-07-15 21:50:40 +01:00
|
|
|
/*
|
|
|
|
|
* Stroke horizontal and vertical borders, shown by Xs and Ys
|
|
|
|
|
* respectively in the figure below:
|
|
|
|
|
*
|
|
|
|
|
* _,,ooO"XXXXXXXXX
|
|
|
|
|
* ,oO"' |
|
|
|
|
|
* ,o" |
|
|
|
|
|
* o" |
|
|
|
|
|
* o' |
|
|
|
|
|
* O |
|
|
|
|
|
* Y |
|
|
|
|
|
* Y |
|
|
|
|
|
* Y |
|
|
|
|
|
* Y |
|
|
|
|
|
* Y--------------------+
|
|
|
|
|
*/
|
|
|
|
|
cairo_set_line_cap(cairo, CAIRO_LINE_CAP_BUTT);
|
2022-08-26 04:50:54 +02:00
|
|
|
set_cairo_color(cairo, ctx->border_color);
|
2021-07-16 17:07:00 +01:00
|
|
|
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);
|
2023-07-15 21:50:40 +01:00
|
|
|
cairo_line_to(cairo, half_line_width, r);
|
|
|
|
|
cairo_move_to(cairo, r, half_line_width);
|
2021-07-16 17:07:00 +01:00
|
|
|
cairo_line_to(cairo, w, half_line_width);
|
|
|
|
|
break;
|
|
|
|
|
case LAB_CORNER_TOP_RIGHT:
|
|
|
|
|
cairo_move_to(cairo, 0, half_line_width);
|
|
|
|
|
cairo_line_to(cairo, w - r, half_line_width);
|
2023-07-15 21:50:40 +01:00
|
|
|
cairo_move_to(cairo, w - half_line_width, r);
|
2021-07-16 17:07:00 +01:00
|
|
|
cairo_line_to(cairo, w - half_line_width, h);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2021-07-23 21:15:55 +01:00
|
|
|
wlr_log(WLR_ERROR, "unknown corner type");
|
2021-07-16 17:07:00 +01:00
|
|
|
}
|
|
|
|
|
cairo_stroke(cairo);
|
2023-07-15 21:50:40 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If radius==0 the borders stroked above go right up to (and including)
|
|
|
|
|
* the corners, so there is not need to do any more.
|
|
|
|
|
*/
|
|
|
|
|
if (!r) {
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Stroke the arc section of the border of the corner piece.
|
|
|
|
|
*
|
|
|
|
|
* Note: This figure is drawn at a more zoomed in scale compared with
|
|
|
|
|
* those above.
|
|
|
|
|
*
|
|
|
|
|
* ,,ooooO"" ^
|
|
|
|
|
* ,ooo""' | |
|
|
|
|
|
* ,oOO" | | line-thickness
|
|
|
|
|
* ,OO" | |
|
|
|
|
|
* ,OO" _,,ooO"" v
|
|
|
|
|
* ,O" ,oO"'
|
|
|
|
|
* ,O' ,o"
|
|
|
|
|
* ,O' o"
|
|
|
|
|
* o' o'
|
|
|
|
|
* O O
|
|
|
|
|
* O---------O +
|
|
|
|
|
* <----------------->
|
|
|
|
|
* radius
|
|
|
|
|
*
|
|
|
|
|
* We handle the edge-case where line-thickness > radius by merely
|
|
|
|
|
* setting line-thickness = radius and in effect drawing a quadrant of a
|
|
|
|
|
* circle. In this case the X and Y borders butt up against the arc and
|
|
|
|
|
* overlap each other (as their line-thickessnes are greater than the
|
|
|
|
|
* linethickness of the arc). As a result, there is no inner rounded
|
|
|
|
|
* corners.
|
|
|
|
|
*
|
|
|
|
|
* So, in order to have inner rounded corners cornerRadius should be
|
|
|
|
|
* greater than border.width.
|
|
|
|
|
*
|
|
|
|
|
* Also, see diagrams in https://github.com/labwc/labwc/pull/990
|
|
|
|
|
*/
|
|
|
|
|
double line_width = MIN(ctx->line_width, r);
|
|
|
|
|
cairo_set_line_width(cairo, line_width);
|
|
|
|
|
half_line_width = line_width / 2.0;
|
|
|
|
|
switch (ctx->corner) {
|
|
|
|
|
case LAB_CORNER_TOP_LEFT:
|
|
|
|
|
cairo_move_to(cairo, half_line_width, r);
|
|
|
|
|
cairo_arc(cairo, r, r, r - half_line_width, 180 * deg, 270 * deg);
|
|
|
|
|
break;
|
|
|
|
|
case LAB_CORNER_TOP_RIGHT:
|
|
|
|
|
cairo_move_to(cairo, w - r, half_line_width);
|
|
|
|
|
cairo_arc(cairo, w - r, r, r - half_line_width, -90 * deg, 0 * deg);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
cairo_stroke(cairo);
|
|
|
|
|
|
|
|
|
|
out:
|
2021-07-16 17:07:00 +01:00
|
|
|
cairo_surface_flush(surf);
|
2022-02-17 01:46:32 +01:00
|
|
|
|
|
|
|
|
return buffer;
|
2021-07-16 17:07:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2022-02-17 01:46:32 +01:00
|
|
|
create_corners(struct theme *theme)
|
2021-07-16 17:07:00 +01:00
|
|
|
{
|
|
|
|
|
struct wlr_box box = {
|
|
|
|
|
.x = 0,
|
|
|
|
|
.y = 0,
|
2023-01-06 15:56:44 +01:00
|
|
|
.width = SSD_BUTTON_WIDTH + theme->border_width,
|
2022-03-09 08:52:33 +01:00
|
|
|
.height = theme->title_height + theme->border_width,
|
2021-07-16 17:07:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct rounded_corner_ctx ctx = {
|
|
|
|
|
.box = &box,
|
|
|
|
|
.radius = rc.corner_radius,
|
|
|
|
|
.line_width = theme->border_width,
|
|
|
|
|
.fill_color = theme->window_active_title_bg_color,
|
|
|
|
|
.border_color = theme->window_active_border_color,
|
|
|
|
|
.corner = LAB_CORNER_TOP_LEFT,
|
|
|
|
|
};
|
2022-02-17 01:46:32 +01:00
|
|
|
theme->corner_top_left_active_normal = rounded_rect(&ctx);
|
2021-07-16 17:07:00 +01:00
|
|
|
|
|
|
|
|
ctx.fill_color = theme->window_inactive_title_bg_color,
|
|
|
|
|
ctx.border_color = theme->window_inactive_border_color,
|
2022-02-17 01:46:32 +01:00
|
|
|
theme->corner_top_left_inactive_normal = rounded_rect(&ctx);
|
2021-07-16 17:07:00 +01:00
|
|
|
|
|
|
|
|
ctx.corner = LAB_CORNER_TOP_RIGHT;
|
|
|
|
|
ctx.fill_color = theme->window_active_title_bg_color,
|
|
|
|
|
ctx.border_color = theme->window_active_border_color,
|
2022-02-17 01:46:32 +01:00
|
|
|
theme->corner_top_right_active_normal = rounded_rect(&ctx);
|
2021-07-16 17:07:00 +01:00
|
|
|
|
|
|
|
|
ctx.fill_color = theme->window_inactive_title_bg_color,
|
|
|
|
|
ctx.border_color = theme->window_inactive_border_color,
|
2022-02-17 01:46:32 +01:00
|
|
|
theme->corner_top_right_inactive_normal = rounded_rect(&ctx);
|
2021-07-16 17:07:00 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-15 20:13:49 +01:00
|
|
|
static void
|
|
|
|
|
post_processing(struct theme *theme)
|
|
|
|
|
{
|
2023-12-07 09:28:27 +01:00
|
|
|
int h = MAX(font_height(&rc.font_activewindow), font_height(&rc.font_inactivewindow));
|
2023-10-02 12:44:30 -03:00
|
|
|
if (theme->title_height < h) {
|
|
|
|
|
theme->title_height = h + 2 * theme->padding_height;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 21:31:28 +01:00
|
|
|
theme->osd_window_switcher_item_height = font_height(&rc.font_osd)
|
2023-07-05 19:49:56 +01:00
|
|
|
+ 2 * theme->osd_window_switcher_item_padding_y
|
|
|
|
|
+ 2 * theme->osd_window_switcher_item_active_border_width;
|
2021-04-15 20:13:49 +01:00
|
|
|
|
|
|
|
|
if (rc.corner_radius >= theme->title_height) {
|
2023-07-15 21:53:50 +01:00
|
|
|
rc.corner_radius = theme->title_height - 1;
|
2021-04-15 20:13:49 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-05 14:38:16 +01:00
|
|
|
if (theme->menu_max_width < theme->menu_min_width) {
|
|
|
|
|
wlr_log(WLR_ERROR,
|
|
|
|
|
"Adjusting menu.width.max: .max (%d) lower than .min (%d)",
|
|
|
|
|
theme->menu_max_width, theme->menu_min_width);
|
|
|
|
|
theme->menu_max_width = theme->menu_min_width;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 19:14:58 +02:00
|
|
|
/* Inherit OSD settings if not set */
|
2021-10-15 21:44:27 +01:00
|
|
|
if (theme->osd_bg_color[0] == FLT_MIN) {
|
|
|
|
|
memcpy(theme->osd_bg_color,
|
|
|
|
|
theme->window_active_title_bg_color,
|
|
|
|
|
sizeof(theme->osd_bg_color));
|
|
|
|
|
}
|
2022-05-31 19:14:58 +02:00
|
|
|
if (theme->osd_border_width == INT_MIN) {
|
|
|
|
|
theme->osd_border_width = theme->border_width;
|
|
|
|
|
}
|
2021-10-15 21:44:27 +01:00
|
|
|
if (theme->osd_label_text_color[0] == FLT_MIN) {
|
|
|
|
|
memcpy(theme->osd_label_text_color,
|
|
|
|
|
theme->window_active_label_text_color,
|
|
|
|
|
sizeof(theme->osd_label_text_color));
|
|
|
|
|
}
|
2022-05-31 19:14:58 +02:00
|
|
|
if (theme->osd_border_color[0] == FLT_MIN) {
|
|
|
|
|
/*
|
|
|
|
|
* As per http://openbox.org/wiki/Help:Themes#osd.border.color
|
|
|
|
|
* we should fall back to window_active_border_color but
|
|
|
|
|
* that is usually the same as window_active_title_bg_color
|
|
|
|
|
* and thus the fallback for osd_bg_color. Which would mean
|
|
|
|
|
* they are both the same color and thus the border is invisible.
|
|
|
|
|
*
|
|
|
|
|
* Instead, we fall back to osd_label_text_color which in turn
|
|
|
|
|
* falls back to window_active_label_text_color.
|
|
|
|
|
*/
|
|
|
|
|
memcpy(theme->osd_border_color, theme->osd_label_text_color,
|
|
|
|
|
sizeof(theme->osd_border_color));
|
|
|
|
|
}
|
2021-04-15 20:13:49 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-21 21:14:06 +00:00
|
|
|
void
|
2022-02-17 01:46:32 +01:00
|
|
|
theme_init(struct theme *theme, const char *theme_name)
|
2021-02-21 21:14:06 +00:00
|
|
|
{
|
2021-07-20 21:27:41 +01:00
|
|
|
/*
|
|
|
|
|
* Set some default values. This is particularly important on
|
|
|
|
|
* reconfigure as not all themes set all options
|
|
|
|
|
*/
|
|
|
|
|
theme_builtin(theme);
|
|
|
|
|
|
2022-12-05 21:46:16 +00:00
|
|
|
/* Read <data-dir>/share/themes/$theme_name/openbox-3/themerc */
|
2021-02-21 21:54:40 +00:00
|
|
|
theme_read(theme, theme_name);
|
2022-12-05 21:46:16 +00:00
|
|
|
|
|
|
|
|
/* Read <config-dir>/labwc/themerc-override */
|
|
|
|
|
theme_read_override(theme);
|
|
|
|
|
|
2021-04-15 20:13:49 +01:00
|
|
|
post_processing(theme);
|
2022-02-17 01:46:32 +01:00
|
|
|
create_corners(theme);
|
2023-08-04 22:30:16 +01:00
|
|
|
load_buttons(theme);
|
2021-02-21 21:14:06 +00:00
|
|
|
}
|
2021-02-21 22:03:14 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
theme_finish(struct theme *theme)
|
|
|
|
|
{
|
2022-05-26 15:47:44 +02:00
|
|
|
wlr_buffer_drop(&theme->corner_top_left_active_normal->base);
|
|
|
|
|
wlr_buffer_drop(&theme->corner_top_left_inactive_normal->base);
|
|
|
|
|
wlr_buffer_drop(&theme->corner_top_right_active_normal->base);
|
|
|
|
|
wlr_buffer_drop(&theme->corner_top_right_inactive_normal->base);
|
|
|
|
|
theme->corner_top_left_active_normal = NULL;
|
|
|
|
|
theme->corner_top_left_inactive_normal = NULL;
|
|
|
|
|
theme->corner_top_right_active_normal = NULL;
|
|
|
|
|
theme->corner_top_right_inactive_normal = NULL;
|
2021-02-21 22:03:14 +00:00
|
|
|
}
|