theme: support theme setting override

...by reading <config-dir>/themerc-override where <config-dir> 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.
This commit is contained in:
Johan Malm 2022-12-05 21:46:16 +00:00 committed by Johan Malm
parent d82d8117f7
commit af56b68041
7 changed files with 58 additions and 7 deletions

View file

@ -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 <data-dir>/share/themes/$theme_name/openbox-3/themerc */
theme_read(theme, theme_name);
/* Read <config-dir>/labwc/themerc-override */
theme_read_override(theme);
post_processing(theme);
create_corners(theme);
xbm_load(theme);