]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Un-global theme variable
authorJohan Malm <jgm323@gmail.com>
Sun, 21 Feb 2021 21:54:40 +0000 (21:54 +0000)
committerJohan Malm <jgm323@gmail.com>
Sun, 21 Feb 2021 21:54:40 +0000 (21:54 +0000)
include/labwc.h
include/theme/theme.h
include/xbm/xbm.h
src/main.c
src/menu/menu.c
src/output.c
src/server.c
src/theme/theme-builtin.c
src/theme/theme.c
src/xbm/xbm.c

index 4829e0bce4ef066f9ee8f7b0dee90739e5d90f49..26754a21ec94ba07bd534e17dd1f936f24e8460e 100644 (file)
@@ -117,6 +117,7 @@ struct server {
        /* Set when in cycle (alt-tab) mode */
        struct view *cycle_view;
 
+       struct theme *theme;
        struct menu *rootmenu;
 };
 
index 86e59ee4d1d96aabadb3f2fa0ab28a131f9b0ab1..09d6955bc93eb948240b23b92c66c2f74cf3495d 100644 (file)
@@ -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 <theme-dir>/<theme-name>/openbox-3/themerc
  * 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
  * 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 */
index 1ddb6212593a04d5a8ccf6570bde5874fd6700e9..b63248716f107bcc1b47183549573d27f698dd4d 100644 (file)
@@ -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 */
index f0661edcb31babb1014d675e7cea37ec95a8eac9..606759412682f9fbec6fb653adde9c5972ea3f42 100644 (file)
@@ -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);
index 094dd55f9627b3d1e8059172b5bea516c1764b20..207dce106d7ee06c52f72eab8eceb13623ec0718 100644 (file)
@@ -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;
 }
index d1f8e36ca751c60fcd9e16ed50f4c5f905c32d06..142400189477b5e6a4205cb23bb0583d66564a3d 100644 (file)
@@ -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);
        }
 }
 
index bc046f13aa4934e5cd1943b5869fb7d36ae386cc..83df7ff877e59822598070d0f27d717cd92aaf2b 100644 (file)
@@ -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);
 }
index a5dd0ddfdd16a1f048cb7c85cb81598a685cd7ed..aa79ce6c073ba257561bb516ad541965834eaad8 100644 (file)
 
 #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);
 }
index f6b50355d2e42692877bd954d49391b02f0067b8..05f837f40863da320e3fa97e640a0e48e818523b 100644 (file)
@@ -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);
 }
index e8835e2737cf4afa7592d292836fda1aaea354f2..44c74753e442b657d7fb5a795a341e9d8af308ce 100644 (file)
@@ -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);
 }