Un-global theme variable

This commit is contained in:
Johan Malm 2021-02-21 21:54:40 +00:00
parent 9af7bd744f
commit 1b263e1f67
10 changed files with 64 additions and 57 deletions

View file

@ -117,6 +117,7 @@ struct server {
/* Set when in cycle (alt-tab) mode */ /* Set when in cycle (alt-tab) mode */
struct view *cycle_view; struct view *cycle_view;
struct theme *theme;
struct menu *rootmenu; struct menu *rootmenu;
}; };

View file

@ -33,8 +33,6 @@ struct theme {
struct wlr_texture *xbm_iconify_inactive_unpressed; struct wlr_texture *xbm_iconify_inactive_unpressed;
}; };
extern struct theme theme;
/** /**
* parse_hexstr - parse #rrggbb * parse_hexstr - parse #rrggbb
* @hex: hex string to be parsed * @hex: hex string to be parsed
@ -43,17 +41,20 @@ extern struct theme theme;
void parse_hexstr(const char *hex, float *rgba); 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 <theme-dir>/<theme-name>/openbox-3/themerc * @theme_name: theme-name in <theme-dir>/<theme-name>/openbox-3/themerc
* Note <theme-dir> is obtained in theme-dir.c * Note <theme-dir> 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 * theme_builin - apply built-in theme similar to Clearlooks
* Note: Only used if no theme can be found. Default values for individual * 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. * 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 */ #endif /* __LABWC_THEME_H */

View file

@ -8,6 +8,6 @@
/** /**
* xbm_load - load theme xbm files into global theme struct * 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 */ #endif /* __LABWC_XBM_H */

View file

@ -76,7 +76,8 @@ main(int argc, char *argv[])
server_init(&server); server_init(&server);
server_start(&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 }; struct menu rootmenu = { 0 };
menu_init_rootmenu(&server, &rootmenu); menu_init_rootmenu(&server, &rootmenu);

View file

@ -76,13 +76,14 @@ menuitem_create(struct server *server, struct menu *menu, const char *text)
if (!menuitem) { if (!menuitem) {
return NULL; return NULL;
} }
struct theme *theme = server->theme;
menuitem->geo_box.width = MENUWIDTH; menuitem->geo_box.width = MENUWIDTH;
menuitem->geo_box.height = MENUHEIGHT; menuitem->geo_box.height = MENUHEIGHT;
menuitem->active_texture = texture_create(server, &menuitem->geo_box, menuitem->active_texture = texture_create(server, &menuitem->geo_box,
text, theme.menu_items_active_bg_color, text, theme->menu_items_active_bg_color,
theme.menu_items_active_text_color); theme->menu_items_active_text_color);
menuitem->inactive_texture = texture_create(server, &menuitem->geo_box, 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); wl_list_insert(&menu->menuitems, &menuitem->link);
return menuitem; return menuitem;
} }

View file

@ -443,8 +443,10 @@ render_deco(struct view *view, struct output *output,
return; return;
} }
struct theme *theme = view->server->theme;
/* render border */ /* render border */
float *color = theme.window_active_handle_bg_color; float *color = theme->window_active_handle_bg_color;
enum deco_part border[4] = { enum deco_part border[4] = {
LAB_DECO_PART_TOP, LAB_DECO_PART_TOP,
LAB_DECO_PART_RIGHT, LAB_DECO_PART_RIGHT,
@ -459,9 +461,9 @@ render_deco(struct view *view, struct output *output,
/* render title */ /* render title */
struct wlr_seat *seat = view->server->seat.seat; struct wlr_seat *seat = view->server->seat.seat;
if (view->surface == seat->keyboard_state.focused_surface) { if (view->surface == seat->keyboard_state.focused_surface) {
color = theme.window_active_title_bg_color; color = theme->window_active_title_bg_color;
} else { } 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); struct wlr_box box = deco_box(view, LAB_DECO_PART_TITLE);
render_rect(output, output_damage, &box, color); 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) { if (view->surface == seat->keyboard_state.focused_surface) {
box = deco_box(view, LAB_DECO_BUTTON_CLOSE); box = deco_box(view, LAB_DECO_BUTTON_CLOSE);
render_icon(output, output_damage, &box, render_icon(output, output_damage, &box,
theme.xbm_close_active_unpressed); theme->xbm_close_active_unpressed);
box = deco_box(view, LAB_DECO_BUTTON_MAXIMIZE); box = deco_box(view, LAB_DECO_BUTTON_MAXIMIZE);
render_icon(output, output_damage, &box, render_icon(output, output_damage, &box,
theme.xbm_maximize_active_unpressed); theme->xbm_maximize_active_unpressed);
box = deco_box(view, LAB_DECO_BUTTON_ICONIFY); box = deco_box(view, LAB_DECO_BUTTON_ICONIFY);
render_icon(output, output_damage, &box, render_icon(output, output_damage, &box,
theme.xbm_iconify_active_unpressed); theme->xbm_iconify_active_unpressed);
} else { } else {
box = deco_box(view, LAB_DECO_BUTTON_CLOSE); box = deco_box(view, LAB_DECO_BUTTON_CLOSE);
render_icon(output, output_damage, &box, render_icon(output, output_damage, &box,
theme.xbm_close_inactive_unpressed); theme->xbm_close_inactive_unpressed);
box = deco_box(view, LAB_DECO_BUTTON_MAXIMIZE); box = deco_box(view, LAB_DECO_BUTTON_MAXIMIZE);
render_icon(output, output_damage, &box, render_icon(output, output_damage, &box,
theme.xbm_maximize_inactive_unpressed); theme->xbm_maximize_inactive_unpressed);
box = deco_box(view, LAB_DECO_BUTTON_ICONIFY); box = deco_box(view, LAB_DECO_BUTTON_ICONIFY);
render_icon(output, output_damage, &box, render_icon(output, output_damage, &box,
theme.xbm_iconify_inactive_unpressed); theme->xbm_iconify_inactive_unpressed);
} }
} }

View file

@ -27,7 +27,7 @@ reload_config_and_theme(void)
/* TODO: use rc.config_path */ /* TODO: use rc.config_path */
rcxml_finish(); rcxml_finish();
rcxml_read(NULL); 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); menu_reconfigure(g_server, g_server->rootmenu);
damage_all_outputs(g_server); damage_all_outputs(g_server);
} }

View file

@ -11,15 +11,15 @@
#include "theme/theme.h" #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("#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);
parse_hexstr("#ffffff", theme.window_active_button_unpressed_image_color); parse_hexstr("#ffffff", theme->window_active_button_unpressed_image_color);
parse_hexstr("#000000", theme.window_inactive_button_unpressed_image_color); parse_hexstr("#000000", theme->window_inactive_button_unpressed_image_color);
parse_hexstr("#fcfbfa", theme.menu_items_bg_color); parse_hexstr("#fcfbfa", theme->menu_items_bg_color);
parse_hexstr("#000000", theme.menu_items_text_color); parse_hexstr("#000000", theme->menu_items_text_color);
parse_hexstr("#4a90d9", theme.menu_items_active_bg_color); parse_hexstr("#4a90d9", theme->menu_items_active_bg_color);
parse_hexstr("#ffffff", theme.menu_items_active_text_color); parse_hexstr("#ffffff", theme->menu_items_active_text_color);
} }

View file

@ -49,29 +49,29 @@ match(const gchar *pattern, const gchar *string)
return (bool)g_pattern_match_simple(pattern, 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) { if (!key || !value) {
return; return;
} }
if (match(key, "window.active.title.bg.color")) { 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);
} else if (match(key, "window.inactive.title.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")) { } 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")) { } 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")) { } 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")) { } 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")) { } 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")) { } 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 static void
process_line(char *line) process_line(struct theme *theme, char *line)
{ {
if (line[0] == '\0' || line[0] == '#') { if (line[0] == '\0' || line[0] == '#') {
return; return;
} }
char *key = NULL, *value = NULL; char *key = NULL, *value = NULL;
parse_config_line(line, &key, &value); parse_config_line(line, &key, &value);
entry(key, value); entry(theme, key, value);
} }
static void static void
theme_read(const char *theme_name) theme_read(struct theme *theme, const char *theme_name)
{ {
FILE *stream = NULL; FILE *stream = NULL;
char *line = NULL; char *line = NULL;
@ -113,7 +113,7 @@ theme_read(const char *theme_name)
} }
if (!stream) { if (!stream) {
info("cannot find theme (%s), using built-in", theme_name); info("cannot find theme (%s), using built-in", theme_name);
theme_builtin(); theme_builtin(theme);
return; return;
} }
info("read themerc (%s)", themerc); info("read themerc (%s)", themerc);
@ -122,15 +122,16 @@ theme_read(const char *theme_name)
if (p) { if (p) {
*p = '\0'; *p = '\0';
} }
process_line(line); process_line(theme, line);
} }
free(line); free(line);
fclose(stream); fclose(stream);
} }
void 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); theme_read(theme, theme_name);
xbm_load(renderer); xbm_load(theme, renderer);
} }

View file

@ -78,21 +78,21 @@ out:
} }
void 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); parse_set_color(theme->window_active_button_unpressed_image_color);
load_button(r, "close.xbm", &theme.xbm_close_active_unpressed, load_button(r, "close.xbm", &theme->xbm_close_active_unpressed,
close_button_normal); 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); 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); iconify_button_normal);
parse_set_color(theme.window_inactive_button_unpressed_image_color); parse_set_color(theme->window_inactive_button_unpressed_image_color);
load_button(r, "close.xbm", &theme.xbm_close_inactive_unpressed, load_button(r, "close.xbm", &theme->xbm_close_inactive_unpressed,
close_button_normal); 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); 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); iconify_button_normal);
} }