Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bspwm: re-add support for lists as config option values #2125

Merged
merged 1 commit into from
Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 additions & 29 deletions modules/services/window-managers/bspwm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,29 @@ let
builtins.replaceStrings upperChars (map (c: "_${c}") lowerChars);

formatMonitor = monitor: desktops:
"bspc monitor ${strings.escapeShellArg monitor} -d ${
strings.escapeShellArgs desktops
}";

formatSetting = n: v:
let
vStr = if isBool v then
boolToString v
else if isInt v || isFloat v then
toString v
else if isString v then
strings.escapeShellArg v
else
throw "unsupported setting type for ${n}";
in "bspc config ${strings.escapeShellArg n} ${vStr}";
"bspc monitor ${escapeShellArg monitor} -d ${escapeShellArgs desktops}";

formatValue = v:
if isList v then
concatMapStringsSep "," formatValue v
else if isBool v then
if v then "on" else "off"
else if isInt v || isFloat v then
toString v
else if isString v then
v
else
throw "unsupported type"; # should not happen

formatSetting = n: v: "bspc config ${escapeShellArgs [ n (formatValue v) ]}";

formatRule = target: directives:
let
formatDirective = n: v:
let
vStr = if isBool v then
if v then "on" else "off"
else if isInt v || isFloat v then
toString v
else if isString v then
v
else
throw "unsupported rule attribute type for ${n}";
in "${camelToSnake n}=${vStr}";

directivesStr = strings.escapeShellArgs (mapAttrsToList formatDirective
formatDirective = n: v: "${camelToSnake n}=${formatValue v}";

directivesStr = escapeShellArgs (mapAttrsToList formatDirective
(filterAttrs (n: v: v != null) directives));
in "bspc rule -a ${strings.escapeShellArg target} ${directivesStr}";
in "bspc rule -a ${escapeShellArg target} ${directivesStr}";

formatStartupProgram = s: "${s} &";

Expand Down
2 changes: 1 addition & 1 deletion modules/services/window-managers/bspwm/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ in {
settings = mkOption {
type = with types;
let primitive = either bool (either int (either float str));
in attrsOf primitive;
in attrsOf (either primitive (listOf primitive));
default = { };
description = "General settings given to <literal>bspc config</literal>.";
example = {
Expand Down
7 changes: 4 additions & 3 deletions tests/modules/services/window-managers/bspwm/bspwmrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
bspc monitor 'focused' -d 'desktop 1' 'd'\''esk top'

bspc config 'border_width' 2
bspc config 'border_width' '2'
bspc config 'external_rules_command' '/path/to/external rules command'
bspc config 'gapless_monocle' true
bspc config 'split_ratio' 0.520000
bspc config 'gapless_monocle' 'on'
bspc config 'ignore_ewmh_fullscreen' 'enter,exit'
bspc config 'split_ratio' '0.520000'

bspc rule -r '*'
bspc rule -a '*' 'center=off' 'desktop=d'\''esk top#next' 'split_dir=north' 'sticky=on'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ with lib;
split_ratio = 0.52;
gapless_monocle = true;
external_rules_command = "/path/to/external rules command";
ignore_ewmh_fullscreen = [ "enter" "exit" ];
};
rules."*" = {
sticky = true;
Expand Down