This commit is contained in:
dmitry-erin 2024-04-22 05:11:55 +01:00 committed by GitHub
commit d298311a32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 207 additions and 102 deletions

View file

@ -37,7 +37,9 @@
#include "theme.h"
#include "buffer.h"
#include "ssd.h"
#include "view.h"
#include "labwc.h"
#include "window-rules.h"
struct button {
const char *name;
const char *alt_name;
@ -396,8 +398,8 @@ hex_to_dec(char c)
* @hex: hex string to be parsed
* @rgba: pointer to float[4] for return value
*/
static void
parse_hexstr(const char *hex, float *rgba)
void
theme_parse_hexstr(const char *hex, float *rgba)
{
if (!hex || hex[0] != '#' || strlen(hex) < 7) {
return;
@ -471,39 +473,39 @@ theme_builtin(struct theme *theme)
theme->menu_overlap_x = 0;
theme->menu_overlap_y = 0;
parse_hexstr("#e1dedb", theme->window_active_border_color);
parse_hexstr("#f6f5f4", theme->window_inactive_border_color);
theme_parse_hexstr("#e1dedb", theme->window_active_border_color);
theme_parse_hexstr("#f6f5f4", theme->window_inactive_border_color);
parse_hexstr("#ff0000", theme->window_toggled_keybinds_color);
theme_parse_hexstr("#ff0000", theme->window_toggled_keybinds_color);
parse_hexstr("#e1dedb", theme->window_active_title_bg_color);
parse_hexstr("#f6f5f4", theme->window_inactive_title_bg_color);
theme_parse_hexstr("#e1dedb", theme->window_active_title_bg_color);
theme_parse_hexstr("#f6f5f4", theme->window_inactive_title_bg_color);
parse_hexstr("#000000", theme->window_active_label_text_color);
parse_hexstr("#000000", theme->window_inactive_label_text_color);
theme_parse_hexstr("#000000", theme->window_active_label_text_color);
theme_parse_hexstr("#000000", theme->window_inactive_label_text_color);
theme->window_label_text_justify = parse_justification("Center");
parse_hexstr("#000000",
theme_parse_hexstr("#000000",
theme->window_active_button_menu_unpressed_image_color);
parse_hexstr("#000000",
theme_parse_hexstr("#000000",
theme->window_active_button_iconify_unpressed_image_color);
parse_hexstr("#000000",
theme_parse_hexstr("#000000",
theme->window_active_button_max_unpressed_image_color);
parse_hexstr("#000000",
theme_parse_hexstr("#000000",
theme->window_active_button_close_unpressed_image_color);
parse_hexstr("#000000",
theme_parse_hexstr("#000000",
theme->window_inactive_button_menu_unpressed_image_color);
parse_hexstr("#000000",
theme_parse_hexstr("#000000",
theme->window_inactive_button_iconify_unpressed_image_color);
parse_hexstr("#000000",
theme_parse_hexstr("#000000",
theme->window_inactive_button_max_unpressed_image_color);
parse_hexstr("#000000",
theme_parse_hexstr("#000000",
theme->window_inactive_button_close_unpressed_image_color);
parse_hexstr("#fcfbfa", theme->menu_items_bg_color);
parse_hexstr("#000000", theme->menu_items_text_color);
parse_hexstr("#e1dedb", theme->menu_items_active_bg_color);
parse_hexstr("#000000", theme->menu_items_active_text_color);
theme_parse_hexstr("#fcfbfa", theme->menu_items_bg_color);
theme_parse_hexstr("#000000", theme->menu_items_text_color);
theme_parse_hexstr("#e1dedb", theme->menu_items_active_bg_color);
theme_parse_hexstr("#000000", theme->menu_items_active_text_color);
theme->menu_item_padding_x = 7;
theme->menu_item_padding_y = 4;
@ -514,7 +516,7 @@ theme_builtin(struct theme *theme)
theme->menu_separator_line_thickness = 1;
theme->menu_separator_padding_width = 6;
theme->menu_separator_padding_height = 3;
parse_hexstr("#888888", theme->menu_separator_color);
theme_parse_hexstr("#888888", theme->menu_separator_color);
theme->osd_window_switcher_width = 600;
theme->osd_window_switcher_width_is_percent = false;
@ -589,33 +591,33 @@ entry(struct theme *theme, const char *key, const char *value)
}
if (match_glob(key, "window.active.border.color")) {
parse_hexstr(value, theme->window_active_border_color);
theme_parse_hexstr(value, theme->window_active_border_color);
}
if (match_glob(key, "window.inactive.border.color")) {
parse_hexstr(value, theme->window_inactive_border_color);
theme_parse_hexstr(value, theme->window_inactive_border_color);
}
/* border.color is obsolete, but handled for backward compatibility */
if (match_glob(key, "border.color")) {
parse_hexstr(value, theme->window_active_border_color);
parse_hexstr(value, theme->window_inactive_border_color);
theme_parse_hexstr(value, theme->window_active_border_color);
theme_parse_hexstr(value, theme->window_inactive_border_color);
}
if (match_glob(key, "window.active.indicator.toggled-keybind.color")) {
parse_hexstr(value, theme->window_toggled_keybinds_color);
theme_parse_hexstr(value, theme->window_toggled_keybinds_color);
}
if (match_glob(key, "window.active.title.bg.color")) {
parse_hexstr(value, theme->window_active_title_bg_color);
theme_parse_hexstr(value, theme->window_active_title_bg_color);
}
if (match_glob(key, "window.inactive.title.bg.color")) {
parse_hexstr(value, theme->window_inactive_title_bg_color);
theme_parse_hexstr(value, theme->window_inactive_title_bg_color);
}
if (match_glob(key, "window.active.label.text.color")) {
parse_hexstr(value, theme->window_active_label_text_color);
theme_parse_hexstr(value, theme->window_active_label_text_color);
}
if (match_glob(key, "window.inactive.label.text.color")) {
parse_hexstr(value, theme->window_inactive_label_text_color);
theme_parse_hexstr(value, theme->window_inactive_label_text_color);
}
if (match_glob(key, "window.label.text.justify")) {
theme->window_label_text_justify = parse_justification(value);
@ -623,57 +625,57 @@ entry(struct theme *theme, const char *key, const char *value)
/* universal button */
if (match_glob(key, "window.active.button.unpressed.image.color")) {
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_active_button_menu_unpressed_image_color);
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_active_button_iconify_unpressed_image_color);
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_active_button_max_unpressed_image_color);
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_active_button_close_unpressed_image_color);
}
if (match_glob(key, "window.inactive.button.unpressed.image.color")) {
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_inactive_button_menu_unpressed_image_color);
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_inactive_button_iconify_unpressed_image_color);
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_inactive_button_max_unpressed_image_color);
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_inactive_button_close_unpressed_image_color);
}
/* individual buttons */
if (match_glob(key, "window.active.button.menu.unpressed.image.color")) {
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_active_button_menu_unpressed_image_color);
}
if (match_glob(key, "window.active.button.iconify.unpressed.image.color")) {
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_active_button_iconify_unpressed_image_color);
}
if (match_glob(key, "window.active.button.max.unpressed.image.color")) {
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_active_button_max_unpressed_image_color);
}
if (match_glob(key, "window.active.button.close.unpressed.image.color")) {
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_active_button_close_unpressed_image_color);
}
if (match_glob(key, "window.inactive.button.menu.unpressed.image.color")) {
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_inactive_button_menu_unpressed_image_color);
}
if (match_glob(key, "window.inactive.button.iconify.unpressed.image.color")) {
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_inactive_button_iconify_unpressed_image_color);
}
if (match_glob(key, "window.inactive.button.max.unpressed.image.color")) {
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_inactive_button_max_unpressed_image_color);
}
if (match_glob(key, "window.inactive.button.close.unpressed.image.color")) {
parse_hexstr(value,
theme_parse_hexstr(value,
theme->window_inactive_button_close_unpressed_image_color);
}
@ -685,16 +687,16 @@ entry(struct theme *theme, const char *key, const char *value)
}
if (match_glob(key, "menu.items.bg.color")) {
parse_hexstr(value, theme->menu_items_bg_color);
theme_parse_hexstr(value, theme->menu_items_bg_color);
}
if (match_glob(key, "menu.items.text.color")) {
parse_hexstr(value, theme->menu_items_text_color);
theme_parse_hexstr(value, theme->menu_items_text_color);
}
if (match_glob(key, "menu.items.active.bg.color")) {
parse_hexstr(value, theme->menu_items_active_bg_color);
theme_parse_hexstr(value, theme->menu_items_active_bg_color);
}
if (match_glob(key, "menu.items.active.text.color")) {
parse_hexstr(value, theme->menu_items_active_text_color);
theme_parse_hexstr(value, theme->menu_items_active_text_color);
}
if (match_glob(key, "menu.separator.width")) {
@ -707,17 +709,17 @@ entry(struct theme *theme, const char *key, const char *value)
theme->menu_separator_padding_height = atoi(value);
}
if (match_glob(key, "menu.separator.color")) {
parse_hexstr(value, theme->menu_separator_color);
theme_parse_hexstr(value, theme->menu_separator_color);
}
if (match_glob(key, "osd.bg.color")) {
parse_hexstr(value, theme->osd_bg_color);
theme_parse_hexstr(value, theme->osd_bg_color);
}
if (match_glob(key, "osd.border.width")) {
theme->osd_border_width = atoi(value);
}
if (match_glob(key, "osd.border.color")) {
parse_hexstr(value, theme->osd_border_color);
theme_parse_hexstr(value, theme->osd_border_color);
}
if (match_glob(key, "osd.window-switcher.width")) {
if (strrchr(value, '%')) {
@ -752,7 +754,7 @@ entry(struct theme *theme, const char *key, const char *value)
theme->osd_workspace_switcher_boxes_height = atoi(value);
}
if (match_glob(key, "osd.label.text.color")) {
parse_hexstr(value, theme->osd_label_text_color);
theme_parse_hexstr(value, theme->osd_label_text_color);
}
if (match_glob(key, "snapping.preview.region.fill")) {
theme->snapping_preview_region_fill = parse_bool(value, true);
@ -1164,3 +1166,40 @@ theme_finish(struct theme *theme)
zdrop(&theme->corner_top_right_active_normal);
zdrop(&theme->corner_top_right_inactive_normal);
}
struct theme
get_theme_for_view(struct view *view)
{
float *custom_color = window_rules_get_custom_border_color(view);
if (!custom_color) {
return *view->server->theme;
}
struct theme theme = { 0 };
/* The same code as in theme_init*(), but with introducing custom color*/
theme_builtin(&theme);
struct wl_list paths;
paths_theme_create(&paths, rc.theme_name, "themerc");
theme_read(&theme, &paths);
paths_destroy(&paths);
paths_config_create(&paths, "themerc-override");
theme_read(&theme, &paths);
paths_destroy(&paths);
memcpy(theme.window_active_border_color, custom_color, sizeof(float)*4);
memcpy(theme.window_inactive_border_color, custom_color, sizeof(float)*4);
memcpy(theme.window_active_title_bg_color, custom_color, sizeof(float)*4);
memcpy(theme.window_inactive_title_bg_color, custom_color, sizeof(float)*4);
memcpy(theme.osd_bg_color, custom_color, sizeof(float)*4);
memcpy(theme.osd_border_color, custom_color, sizeof(float)*4);
memcpy(theme.window_toggled_keybinds_color, custom_color, sizeof(float)*4);
post_processing(&theme);
create_corners(&theme);
load_buttons(&theme);
return theme;
}