mirror of
https://github.com/labwc/labwc.git
synced 2025-11-03 09:01:51 -05:00
Un-global theme variable
This commit is contained in:
parent
9af7bd744f
commit
1b263e1f67
10 changed files with 64 additions and 57 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
20
src/output.c
20
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue