config: add include_one directive

Adds include_one <pattern1> <pattern2>, which loads all files
matching pattern1, then loads files from pattern2 only if their
basename was not already loaded from pattern1.

This allows user configs in ~/.config/sway/conf.d/ to shadow
distro-provided defaults in /etc/sway/conf.d/ by filename without
completely overriding the include path — a common pain point for
packagers on NixOS, Fedora, and similar distributions.

Edge cases handled:
- pattern1 matches nothing: all pattern2 files load normally
- Same basename in both: pattern1 file wins, pattern2 skipped
- Neither pattern matches: silently succeeds (matches include behavior)
This commit is contained in:
Abhijith Dayadi 2026-03-18 22:32:15 +00:00
parent 6d25b100a2
commit d5940c1cc8
7 changed files with 96 additions and 0 deletions

View file

@ -145,6 +145,7 @@ sway_cmd cmd_fullscreen;
sway_cmd cmd_gaps;
sway_cmd cmd_hide_edge_borders;
sway_cmd cmd_include;
sway_cmd cmd_include_one;
sway_cmd cmd_inhibit_idle;
sway_cmd cmd_input;
sway_cmd cmd_seat;

View file

@ -621,6 +621,14 @@ bool load_main_config(const char *path, bool is_active, bool validating);
void load_include_configs(const char *path, struct sway_config *config,
struct swaynag_instance *swaynag);
/**
* Loads included configs using basename-based shadowing.
* Files from pattern1 are always loaded. Files from pattern2 are loaded
* only if their basename was not already loaded from pattern1.
*/
void load_include_one_configs(const char *pattern1, const char *pattern2,
struct sway_config *config, struct swaynag_instance *swaynag);
/**
* Reads the config from the given FILE.
*/