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

@ -169,11 +169,12 @@ 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)]
| [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

View file

@ -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.

View file

@ -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.

View file

@ -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*

View file

@ -30,6 +30,7 @@ install_data(
'environment',
'menu.xml',
'README',
'themerc',
'rc.xml',
'rc.xml.all'
],

View file

@ -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

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);