]> git.mdlowis.com Git - proto/labwc.git/commitdiff
theme: support theme setting override
authorJohan Malm <jgm323@gmail.com>
Mon, 5 Dec 2022 21:46:16 +0000 (21:46 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 3 Jan 2023 21:21:21 +0000 (21:21 +0000)
...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.

README.md
docs/README
docs/labwc-config.5.scd
docs/labwc-theme.5.scd
docs/meson.build
docs/themerc
src/theme.c

index a2c06f25ea4e3124de64c52a185bad0d1c5131f4..5cb475f91da4bd7ee68d19f1df47a884fc2ceef6 100644 (file)
--- 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
index 954919a24a6d77cd1ec774bfb5d6e7eaa20b0a56..e2b393961f1e5336d341af59950de45344333878 100644 (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.
index c435d5fb1911a4f6a471d6373b9fe502884a6456..e00debe1a604f8391df83e3b43ce6ddc58f6cad8 100644 (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.
 
index ccf52c0478a2de3c4504901fc23d7a92850536b5..ffb23f998fcf4c01a31af95fcb2a8c08e9e37b01 100644 (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*
index 37c74a3f8e50617d3bff93b18983c4b40fdbdb3a..f118980fba19c7613af04f737ca2320e4ee3c43e 100644 (file)
@@ -30,6 +30,7 @@ install_data(
     'environment',
     'menu.xml',
     'README',
+    'themerc',
     'rc.xml',
     'rc.xml.all'
   ],
index 6b339519138753ab6c9f4cd5c494a0a19786f0a2..f72f848093239d4d5104dd1b21ad2ca54f3b9cf3 100644 (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
index f88f9221c4a9629b4a307f40a9d1bd8d4e5cb8ba..b98ffa907853c39d9b1f8ee9581dad5debe90289 100644 (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);