From 1b263e1f67f7f73d4e1820dba760a2b126c71068 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Sun, 21 Feb 2021 21:54:40 +0000 Subject: [PATCH] Un-global theme variable --- include/labwc.h | 1 + include/theme/theme.h | 11 ++++++----- include/xbm/xbm.h | 2 +- src/main.c | 3 ++- src/menu/menu.c | 7 ++++--- src/output.c | 20 +++++++++++--------- src/server.c | 2 +- src/theme/theme-builtin.c | 20 ++++++++++---------- src/theme/theme.c | 37 +++++++++++++++++++------------------ src/xbm/xbm.c | 18 +++++++++--------- 10 files changed, 64 insertions(+), 57 deletions(-) diff --git a/include/labwc.h b/include/labwc.h index 4829e0bc..26754a21 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -117,6 +117,7 @@ struct server { /* Set when in cycle (alt-tab) mode */ struct view *cycle_view; + struct theme *theme; struct menu *rootmenu; }; diff --git a/include/theme/theme.h b/include/theme/theme.h index 86e59ee4..09d6955b 100644 --- a/include/theme/theme.h +++ b/include/theme/theme.h @@ -33,8 +33,6 @@ struct theme { struct wlr_texture *xbm_iconify_inactive_unpressed; }; -extern struct theme theme; - /** * parse_hexstr - parse #rrggbb * @hex: hex string to be parsed @@ -43,17 +41,20 @@ extern struct theme theme; void parse_hexstr(const char *hex, float *rgba); /** - * theme_init - read theme incl. buttons into global theme struct + * theme_init - read openbox theme and generate button textures + * @theme: global theme struct + * @renderer: wlr_renderer for creating button textures * @theme_name: theme-name in //openbox-3/themerc * Note is obtained in theme-dir.c */ -void theme_init(struct wlr_renderer *renderer, const char *theme_name); +void theme_init(struct theme *theme, struct wlr_renderer *renderer, + const char *theme_name); /** * theme_builin - apply built-in theme similar to Clearlooks * Note: Only used if no theme can be found. Default values for individual * theme options are as per openbox spec and are typically black/white. */ -void theme_builtin(void); +void theme_builtin(struct theme *theme); #endif /* __LABWC_THEME_H */ diff --git a/include/xbm/xbm.h b/include/xbm/xbm.h index 1ddb6212..b6324871 100644 --- a/include/xbm/xbm.h +++ b/include/xbm/xbm.h @@ -8,6 +8,6 @@ /** * xbm_load - load theme xbm files into global theme struct */ -void xbm_load(struct wlr_renderer *renderer); +void xbm_load(struct theme *theme, struct wlr_renderer *renderer); #endif /* __LABWC_XBM_H */ diff --git a/src/main.c b/src/main.c index f0661edc..60675941 100644 --- a/src/main.c +++ b/src/main.c @@ -76,7 +76,8 @@ main(int argc, char *argv[]) server_init(&server); server_start(&server); - theme_init(server.renderer, rc.theme_name); + theme_init(&theme, server.renderer, rc.theme_name); + server.theme = &theme; struct menu rootmenu = { 0 }; menu_init_rootmenu(&server, &rootmenu); diff --git a/src/menu/menu.c b/src/menu/menu.c index 094dd55f..207dce10 100644 --- a/src/menu/menu.c +++ b/src/menu/menu.c @@ -76,13 +76,14 @@ menuitem_create(struct server *server, struct menu *menu, const char *text) if (!menuitem) { return NULL; } + struct theme *theme = server->theme; menuitem->geo_box.width = MENUWIDTH; menuitem->geo_box.height = MENUHEIGHT; menuitem->active_texture = texture_create(server, &menuitem->geo_box, - text, theme.menu_items_active_bg_color, - theme.menu_items_active_text_color); + text, theme->menu_items_active_bg_color, + theme->menu_items_active_text_color); menuitem->inactive_texture = texture_create(server, &menuitem->geo_box, - text, theme.menu_items_bg_color, theme.menu_items_text_color); + text, theme->menu_items_bg_color, theme->menu_items_text_color); wl_list_insert(&menu->menuitems, &menuitem->link); return menuitem; } diff --git a/src/output.c b/src/output.c index d1f8e36c..14240018 100644 --- a/src/output.c +++ b/src/output.c @@ -443,8 +443,10 @@ render_deco(struct view *view, struct output *output, return; } + struct theme *theme = view->server->theme; + /* render border */ - float *color = theme.window_active_handle_bg_color; + float *color = theme->window_active_handle_bg_color; enum deco_part border[4] = { LAB_DECO_PART_TOP, LAB_DECO_PART_RIGHT, @@ -459,9 +461,9 @@ render_deco(struct view *view, struct output *output, /* render title */ struct wlr_seat *seat = view->server->seat.seat; if (view->surface == seat->keyboard_state.focused_surface) { - color = theme.window_active_title_bg_color; + color = theme->window_active_title_bg_color; } else { - color = theme.window_inactive_title_bg_color; + color = theme->window_inactive_title_bg_color; } struct wlr_box box = deco_box(view, LAB_DECO_PART_TITLE); render_rect(output, output_damage, &box, color); @@ -480,23 +482,23 @@ render_deco(struct view *view, struct output *output, if (view->surface == seat->keyboard_state.focused_surface) { box = deco_box(view, LAB_DECO_BUTTON_CLOSE); render_icon(output, output_damage, &box, - theme.xbm_close_active_unpressed); + theme->xbm_close_active_unpressed); box = deco_box(view, LAB_DECO_BUTTON_MAXIMIZE); render_icon(output, output_damage, &box, - theme.xbm_maximize_active_unpressed); + theme->xbm_maximize_active_unpressed); box = deco_box(view, LAB_DECO_BUTTON_ICONIFY); render_icon(output, output_damage, &box, - theme.xbm_iconify_active_unpressed); + theme->xbm_iconify_active_unpressed); } else { box = deco_box(view, LAB_DECO_BUTTON_CLOSE); render_icon(output, output_damage, &box, - theme.xbm_close_inactive_unpressed); + theme->xbm_close_inactive_unpressed); box = deco_box(view, LAB_DECO_BUTTON_MAXIMIZE); render_icon(output, output_damage, &box, - theme.xbm_maximize_inactive_unpressed); + theme->xbm_maximize_inactive_unpressed); box = deco_box(view, LAB_DECO_BUTTON_ICONIFY); render_icon(output, output_damage, &box, - theme.xbm_iconify_inactive_unpressed); + theme->xbm_iconify_inactive_unpressed); } } diff --git a/src/server.c b/src/server.c index bc046f13..83df7ff8 100644 --- a/src/server.c +++ b/src/server.c @@ -27,7 +27,7 @@ reload_config_and_theme(void) /* TODO: use rc.config_path */ rcxml_finish(); rcxml_read(NULL); - theme_init(g_server->renderer, rc.theme_name); + theme_init(g_server->theme, g_server->renderer, rc.theme_name); menu_reconfigure(g_server, g_server->rootmenu); damage_all_outputs(g_server); } diff --git a/src/theme/theme-builtin.c b/src/theme/theme-builtin.c index a5dd0ddf..aa79ce6c 100644 --- a/src/theme/theme-builtin.c +++ b/src/theme/theme-builtin.c @@ -11,15 +11,15 @@ #include "theme/theme.h" -void theme_builtin(void) +void theme_builtin(struct theme *theme) { - 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); - parse_hexstr("#ffffff", theme.window_active_button_unpressed_image_color); - parse_hexstr("#000000", theme.window_inactive_button_unpressed_image_color); - parse_hexstr("#fcfbfa", theme.menu_items_bg_color); - parse_hexstr("#000000", theme.menu_items_text_color); - parse_hexstr("#4a90d9", theme.menu_items_active_bg_color); - parse_hexstr("#ffffff", theme.menu_items_active_text_color); + 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); + parse_hexstr("#ffffff", theme->window_active_button_unpressed_image_color); + parse_hexstr("#000000", theme->window_inactive_button_unpressed_image_color); + parse_hexstr("#fcfbfa", theme->menu_items_bg_color); + parse_hexstr("#000000", theme->menu_items_text_color); + parse_hexstr("#4a90d9", theme->menu_items_active_bg_color); + parse_hexstr("#ffffff", theme->menu_items_active_text_color); } diff --git a/src/theme/theme.c b/src/theme/theme.c index f6b50355..05f837f4 100644 --- a/src/theme/theme.c +++ b/src/theme/theme.c @@ -49,29 +49,29 @@ match(const gchar *pattern, const gchar *string) return (bool)g_pattern_match_simple(pattern, string); } -static void entry(const char *key, const char *value) +static void entry(struct theme *theme, const char *key, const char *value) { if (!key || !value) { return; } 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")) { - parse_hexstr(value, theme.window_active_handle_bg_color); + parse_hexstr(value, theme->window_active_handle_bg_color); } else if (match(key, "window.inactive.title.bg.color")) { - parse_hexstr(value, theme.window_inactive_title_bg_color); + parse_hexstr(value, theme->window_inactive_title_bg_color); } else if (match(key, "window.active.button.unpressed.image.color")) { - parse_hexstr(value, theme.window_active_button_unpressed_image_color); + parse_hexstr(value, theme->window_active_button_unpressed_image_color); } else if (match(key, "window.inactive.button.unpressed.image.color")) { - parse_hexstr(value, theme.window_inactive_button_unpressed_image_color); + parse_hexstr(value, theme->window_inactive_button_unpressed_image_color); } else if (match(key, "menu.items.bg.color")) { - parse_hexstr(value, theme.menu_items_bg_color); + parse_hexstr(value, theme->menu_items_bg_color); } else if (match(key, "menu.items.text.color")) { - parse_hexstr(value, theme.menu_items_text_color); + parse_hexstr(value, theme->menu_items_text_color); } else if (match(key, "menu.items.active.bg.color")) { - parse_hexstr(value, theme.menu_items_active_bg_color); + parse_hexstr(value, theme->menu_items_active_bg_color); } else if (match(key, "menu.items.active.text.color")) { - parse_hexstr(value, theme.menu_items_active_text_color); + parse_hexstr(value, theme->menu_items_active_text_color); } } @@ -88,18 +88,18 @@ parse_config_line(char *line, char **key, char **value) } static void -process_line(char *line) +process_line(struct theme *theme, char *line) { if (line[0] == '\0' || line[0] == '#') { return; } char *key = NULL, *value = NULL; parse_config_line(line, &key, &value); - entry(key, value); + entry(theme, key, value); } static void -theme_read(const char *theme_name) +theme_read(struct theme *theme, const char *theme_name) { FILE *stream = NULL; char *line = NULL; @@ -113,7 +113,7 @@ theme_read(const char *theme_name) } if (!stream) { info("cannot find theme (%s), using built-in", theme_name); - theme_builtin(); + theme_builtin(theme); return; } info("read themerc (%s)", themerc); @@ -122,15 +122,16 @@ theme_read(const char *theme_name) if (p) { *p = '\0'; } - process_line(line); + process_line(theme, line); } free(line); fclose(stream); } void -theme_init(struct wlr_renderer *renderer, const char *theme_name) +theme_init(struct theme *theme, struct wlr_renderer *renderer, + const char *theme_name) { - theme_read(theme_name); - xbm_load(renderer); + theme_read(theme, theme_name); + xbm_load(theme, renderer); } diff --git a/src/xbm/xbm.c b/src/xbm/xbm.c index e8835e27..44c74753 100644 --- a/src/xbm/xbm.c +++ b/src/xbm/xbm.c @@ -78,21 +78,21 @@ out: } void -xbm_load(struct wlr_renderer *r) +xbm_load(struct theme *theme, struct wlr_renderer *r) { - parse_set_color(theme.window_active_button_unpressed_image_color); - load_button(r, "close.xbm", &theme.xbm_close_active_unpressed, + parse_set_color(theme->window_active_button_unpressed_image_color); + load_button(r, "close.xbm", &theme->xbm_close_active_unpressed, close_button_normal); - load_button(r, "max.xbm", &theme.xbm_maximize_active_unpressed, + load_button(r, "max.xbm", &theme->xbm_maximize_active_unpressed, max_button_normal); - load_button(r, "iconify.xbm", &theme.xbm_iconify_active_unpressed, + load_button(r, "iconify.xbm", &theme->xbm_iconify_active_unpressed, iconify_button_normal); - parse_set_color(theme.window_inactive_button_unpressed_image_color); - load_button(r, "close.xbm", &theme.xbm_close_inactive_unpressed, + parse_set_color(theme->window_inactive_button_unpressed_image_color); + load_button(r, "close.xbm", &theme->xbm_close_inactive_unpressed, close_button_normal); - load_button(r, "max.xbm", &theme.xbm_maximize_inactive_unpressed, + load_button(r, "max.xbm", &theme->xbm_maximize_inactive_unpressed, max_button_normal); - load_button(r, "iconify.xbm", &theme.xbm_iconify_inactive_unpressed, + load_button(r, "iconify.xbm", &theme->xbm_iconify_inactive_unpressed, iconify_button_normal); }