swaywm / swaylock

Screen locker for Wayland
MIT License
853 stars 202 forks source link

Add include directive #355

Open d2718nis opened 7 months ago

d2718nis commented 7 months ago

Description

I wish there was an option to include parts of configuration files from other places. For example, it would be great to have an option to apply themes.

Example

This most likely should use the modified load_config from here

include=/home/user/.themes/swaylock/colors

Motivation

Right at the moment I have two (and a half) ways to install a theme from a third-party:

Some thoughts

  1. Should be able to expand ~ symbol as a user home directory

    config=~/.themes/swaylock/colors

    is expanded to

    config=/home/user/.themes/swaylock/colors
  2. The priority should work the same way it works right now: the value of the lowest (by line count) setting is applied Imagine a configuration file

    config=/tmp/colors
    color=#ffffff

The contents of the /tmp/colors are:

color=#000000

The color=#ffffff from the original config file should overwrite the color=#000000 line from the /tmp/colors file.

  1. Not sure if it should have a maximum include depth, but I do not see any reasons to have any restrictions on that

  2. Keep in mind the recursion: if two files are including each other, there should be a way to prevent that by either of:

    • Exit with an explicit error
    • Log a warning and ignore the include line of a file that was already parsed
  3. Could be also useful to expand environment variables, some of them are quite useful, for example $HOME or $XDG_CONFIG_HOME

Additional info

I thought about using the --config as a long-option like this:

config=/home/user/.themes/swaylock/colors

But the manual page specifically states that you can't do that with the --config option:

All flags aside from this one are valid options in the configuration file using the format long-option=value

Therefore it didn't work.

d2718nis commented 6 months ago

Just thought of another option: automatically include files based on directory structure, for example include all drop-in configuration files from $XDG_CONFIG_HOME/swaylock/config.d/*.conf and other default locations based on priority defined in the manual. In theory this would be much easier to implement