home: wm: i3: move script generation out-of-line

This makes for a cleaner configuration file.
This commit is contained in:
Bruno BELANYI 2021-06-03 17:18:33 +02:00
parent a465955a28
commit 0cf077012d

View file

@ -25,6 +25,45 @@ let
addVimKeyBindings = bindings: bindings // (toVimKeyBindings bindings); addVimKeyBindings = bindings: bindings // (toVimKeyBindings bindings);
# Generate an attrset of movement bindings, using the mapper function # Generate an attrset of movement bindings, using the mapper function
genMovementBindings = f: addVimKeyBindings (lib.my.genAttrs' movementKeys f); genMovementBindings = f: addVimKeyBindings (lib.my.genAttrs' movementKeys f);
# Screen backlight management
changeBacklight =
let
brightnessctl = "${pkgs.brightnessctl}/bin/brightnessctl";
in
pkgs.writeScript "change-backlight" ''
#!/bin/sh
if [ "$1" = "up" ]; then
upDown="+$2%"
else
upDown="$2%-"
fi
newBrightness="$(${brightnessctl} -m set "$upDown" | cut -d, -f4)"
${pkgs.libnotify}/bin/notify-send -u low \
-h string:x-canonical-private-synchronous:change-backlight \
-h "int:value:''${newBrightness/\%/}" \
-- "Set brightness to $newBrightness"
'';
# Lock management
toggleXautolock =
let
systemctlUser = "${pkgs.systemd}/bin/systemctl --user";
notify-send = "${pkgs.libnotify}/bin/notify-send";
notify = "${notify-send} -u low"
+ " -h string:x-canonical-private-synchronous:xautolock-toggle";
in
pkgs.writeScript "toggle-xautolock" ''
#!/bin/sh
if ${systemctlUser} is-active xautolock-session.service; then
${systemctlUser} stop --user xautolock-session.service
${notify} "Disabled Xautolock"
else
${systemctlUser} start xautolock-session.service
${notify} "Enabled Xautolock"
fi
'';
in in
{ {
config = lib.mkIf isEnabled { config = lib.mkIf isEnabled {
@ -221,55 +260,21 @@ in
"XF86AudioNext" = "exec playerctl next"; "XF86AudioNext" = "exec playerctl next";
"XF86AudioPrev" = "exec playerctl previous"; "XF86AudioPrev" = "exec playerctl previous";
} }
(
let
brightnessctl = "${pkgs.brightnessctl}/bin/brightnessctl";
changeBacklight = pkgs.writeScript "change-backlight" ''
#!/bin/sh
if [ "$1" = "up" ]; then
upDown="+$2%"
else
upDown="$2%-"
fi
newBrightness="$(${brightnessctl} -m set "$upDown" | cut -d, -f4)"
${pkgs.libnotify}/bin/notify-send -u low \
-h string:x-canonical-private-synchronous:change-backlight \
-h "int:value:''${newBrightness/\%/}" \
-- "Set brightness to $newBrightness"
'';
in
{ {
# Screen management
"XF86Display" = "exec arandr"; "XF86Display" = "exec arandr";
"XF86MonBrightnessUp" = "exec ${changeBacklight} up 10"; "XF86MonBrightnessUp" = "exec ${changeBacklight} up 10";
"XF86MonBrightnessDown" = "exec ${changeBacklight} down 10"; "XF86MonBrightnessDown" = "exec ${changeBacklight} down 10";
"Control+XF86MonBrightnessUp" = "exec ${changeBacklight} up 1"; "Control+XF86MonBrightnessUp" = "exec ${changeBacklight} up 1";
"Control+XF86MonBrightnessDown" = "exec ${changeBacklight} down 1"; "Control+XF86MonBrightnessDown" = "exec ${changeBacklight} down 1";
} }
)
{ {
# Sub-modes # Sub-modes
"${modifier}+r" = "mode resize"; "${modifier}+r" = "mode resize";
"${modifier}+Shift+space" = "mode floating"; "${modifier}+Shift+space" = "mode floating";
} }
(lib.optionalAttrs config.my.home.wm.screen-lock.enable { (lib.optionalAttrs config.my.home.wm.screen-lock.enable {
"${modifier}+x" = "${modifier}+x" = "exec ${toggleXautolock}";
let
systemctlUser = "${pkgs.systemd}/bin/systemctl --user";
notify = "${pkgs.libnotify}/bin/notify-send -u low " +
"-h string:x-canonical-private-synchronous:xautolock-toggle";
toggleXautolock = pkgs.writeScript "toggle-xautolock" ''
#!/bin/sh
if ${systemctlUser} is-active xautolock-session.service; then
${systemctlUser} stop --user xautolock-session.service
${notify} "Disabled Xautolock"
else
${systemctlUser} start xautolock-session.service
${notify} "Enabled Xautolock"
fi
'';
in
"exec ${toggleXautolock}";
}) })
( (
let let