From af56b68041200086cb21b20acf416bf0f24f5f9e Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Mon, 5 Dec 2022 21:46:16 +0000 Subject: [PATCH] theme: support theme setting override ...by reading /themerc-override where is normally $HOME/.config/labwc can be other locations as described in labwc-config(5) and can also be specified by the command line option -C. The reason for supporting theme override is to give users more fine- grained control of settings without making local copies and modifying themes. --- README.md | 14 ++++++++------ docs/README | 4 +++- docs/labwc-config.5.scd | 3 +++ docs/labwc-theme.5.scd | 5 +++++ docs/meson.build | 1 + docs/themerc | 7 +++++++ src/theme.c | 31 +++++++++++++++++++++++++++++++ 7 files changed, 58 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a2c06f25..5cb475f9 100644 --- a/README.md +++ b/README.md @@ -168,12 +168,13 @@ For a step-by-step initial configuration guide, see [getting-started] User config files are located at `${XDG_CONFIG_HOME:-$HOME/.config/labwc/}` with the following four files being used: -| file | man page -| ------------- | -------- -| [rc.xml] | [labwc-config(5)], [labwc-actions(5)] -| [menu.xml] | [labwc-menu(5)] -| [autostart] | [labwc(1)] -| [environment] | [labwc-config(5)] +| file | man page +| ------------------ | -------- +| [rc.xml] | [labwc-config(5)], [labwc-actions(5)] +| [menu.xml] | [labwc-menu(5)] +| [autostart] | [labwc(1)] +| [environment] | [labwc-config(5)] +| [themerc-override] | [labwc-theme(5)] The example [rc.xml] has been kept simple. For all options and default values, see [rc.xml.all] @@ -259,6 +260,7 @@ See [integration] for further details. [autostart]: docs/autostart [environment]: docs/environment [themerc]: docs/themerc +[themerc-override]: docs/themerc [labwc(1)]: https://labwc.github.io/labwc.1.html [labwc-config(5)]: https://labwc.github.io/labwc-config.5.html diff --git a/docs/README b/docs/README index 954919a2..e2b39396 100644 --- a/docs/README +++ b/docs/README @@ -3,5 +3,7 @@ Config layout for ~/.config/labwc/ - environment - menu.xml - rc.xml +- themerc-override + +See `man labwc-config and `man labwc-theme` for further details. -See man labwc-config for further details. diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index c435d5fb..e00debe1 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -18,6 +18,9 @@ searched for in the following order: - ${XDG_CONFIG_HOME:-$HOME/.config}/labwc - ${XDG_CONFIG_DIRS:-/etc/xdg}/labwc +The configuration directory location can be override with the -C command line +option. + All configuration and theme files except autostart are re-loaded on receiving signal SIGHUP. diff --git a/docs/labwc-theme.5.scd b/docs/labwc-theme.5.scd index ccf52c04..ffb23f99 100644 --- a/docs/labwc-theme.5.scd +++ b/docs/labwc-theme.5.scd @@ -20,6 +20,11 @@ the rc.xml configuration file (labwc-config(5)). A theme consists of a themerc file and optionally some xbm icons. +Theme settings specified in themerc can be overridden by creating a +'themerc-override' file in the configuration directory, which is normally +$HOME/.config/labwc/ but can be a few other locations as described in +labwc-config(5). + # DATA TYPES *color RGB values* diff --git a/docs/meson.build b/docs/meson.build index 37c74a3f..f118980f 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -30,6 +30,7 @@ install_data( 'environment', 'menu.xml', 'README', + 'themerc', 'rc.xml', 'rc.xml.all' ], diff --git a/docs/themerc b/docs/themerc index 6b339519..f72f8480 100644 --- a/docs/themerc +++ b/docs/themerc @@ -1,3 +1,10 @@ +# This file contains all themerc options with default values +# +# System-wide and local themes can be overridden by creating a copy of this +# file and renaming it to $HOME/.config/labwc/themerc-override. Be careful +# though - if you only want to override a small number of specific options, +# make sure all other lines are commented out or deleted. + # general border.width: 1 padding.height: 3 diff --git a/src/theme.c b/src/theme.c index f88f9221..b98ffa90 100644 --- a/src/theme.c +++ b/src/theme.c @@ -372,6 +372,32 @@ theme_read(struct theme *theme, const char *theme_name) fclose(stream); } +static void +theme_read_override(struct theme *theme) +{ + char f[4096] = { 0 }; + snprintf(f, sizeof(f), "%s/themerc-override", rc.config_dir); + + FILE *stream = fopen(f, "r"); + if (!stream) { + wlr_log(WLR_INFO, "no theme override '%s'", f); + return; + } + + wlr_log(WLR_INFO, "read theme-override %s", f); + char *line = NULL; + size_t len = 0; + while (getline(&line, &len, stream) != -1) { + char *p = strrchr(line, '\n'); + if (p) { + *p = '\0'; + } + process_line(theme, line); + } + free(line); + fclose(stream); +} + struct rounded_corner_ctx { struct wlr_box *box; double radius; @@ -552,7 +578,12 @@ theme_init(struct theme *theme, const char *theme_name) */ theme_builtin(theme); + /* Read /share/themes/$theme_name/openbox-3/themerc */ theme_read(theme, theme_name); + + /* Read /labwc/themerc-override */ + theme_read_override(theme); + post_processing(theme); create_corners(theme); xbm_load(theme); -- 2.52.0