adding scripts for sway

This commit is contained in:
James Patrick 2022-03-16 23:09:22 -04:00
parent 8be2695ed0
commit 5c0e62ba20
4 changed files with 115 additions and 30 deletions

View File

@ -0,0 +1,22 @@
{ pkgs, ... }:
let
in pkgs.writeShellScriptBin "brightness.sh" ''
#! ${pkgs.bash}/bin/bash
function notify {
val="$(light | cut -d '.' -f 1)"
str="$val $(seq -s "" "$(($val / 5 ))" | sed 's/[0-9]//g' )"
icon=/etc/profiles/per-user/james/share/icons/kora/actions/16/contrast.svg
echo "$str"
notify-send "$str" -h string:x-canonical-private-synchronous:brightness -i $icon -t 1500
}
case $1 in
up)
${pkgs.light}/bin/light -A 5 ; notify ;;
down)
${pkgs.light}/bin/light -U 5 ; notify ;;
*)
echo "invalid command"
;;
esac
''

View File

@ -0,0 +1,12 @@
{ pkgs, ... }:
let
in pkgs.writeShellScriptBin "sway-entry" ''
#! ${pkgs.bash}/bin/bash
# first import environment variables from the login manager
# function is currently deprecated. It should be rolled back in the future
systemctl --user import-environment
# then start the service
exec systemctl --user start sway.service
''

View File

@ -0,0 +1,45 @@
{ pkgs, ... }:
let
in pkgs.writeShellScriptBin "volume.sh" ''
#! ${pkgs.bash}/bin/bash
function get_volume {
amixer get Master | grep '%' | head -n 1 | cut -d '[' -f 2 | cut -d '%' -f 1
}
function is_mute {
amixer get Master | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
}
function notify {
vol=$(get_volume)
str="$vol $(seq -s "" "$(($vol / 5 ))" | sed 's/[0-9]//g' )"
if is_mute ; then
icon=/etc/profiles/per-user/james/share/icons/kora/actions/16/audio-volume-muted.svg
else
if (( "$vol" == "0" )) ; then
icon=/etc/profiles/per-user/james/share/icons/kora/actions/16/audio-volume-off.svg
elif (( "$vol" < "30" )) ; then
icon=/etc/profiles/per-user/james/share/icons/kora/actions/16/audio-volume-low.svg
elif (( "$vol" < "60" )) ; then
icon=/etc/profiles/per-user/james/share/icons/kora/actions/16/audio-volume-medium.svg
else
icon=/etc/profiles/per-user/james/share/icons/kora/actions/16/audio-volume-high.svg
fi
fi
echo "$str"
notify-send "$str" -h string:x-canonical-private-synchronous:volume -i $icon -t 1500
}
case $1 in
up)
pactl set-sink-volume @DEFAULT_SINK@ +5% ; notify ;;
down)
pactl set-sink-volume @DEFAULT_SINK@ -5% ; notify ;;
mute)
amixer set Master toggle > /dev/null ; notify ;;
*)
echo "invalid command"
;;
esac
$(is_mute) ; echo $?
''

View File

@ -7,6 +7,11 @@ let
"https://raw.githubusercontent.com/catppuccin/wallpapers/main/landscapes/evening-sky.png";
sha256 = "sha256-fYMzoY3un4qGOSR4DMqVUAFmGGil+wUze31rLLrjcAc=";
};
brightness-sh = pkgs.callPackage ./scripts/brightness.nix { inherit pkgs; };
sway-entry = pkgs.callPackage ./scripts/sway-entry.nix { inherit pkgs; };
volume-sh = pkgs.callPackage ./scripts/volume.nix { inherit pkgs; };
scripts = [ brightness-sh sway-entry volume-sh ];
in with lib; {
options = {
this.application.sway = {
@ -80,47 +85,48 @@ in with lib; {
outer = 2;
};
# And import and scripts as scene here would be good.
keybindings = mkOptionDefault {
XF86AudioMute = "exec ${volume-sh}/bin/volume.sh mute";
XF86AudioRaiseVolume = "exec ${volume-sh}/bin/volume.sh up";
XF86AudioLowerVolume = "exec ${volume-sh}/bin/volume.sh down";
XF86AudioPlay = "exec ${pkgs.playerctl}/bin/playerctl play";
XF86AudioPause = "exec ${pkgs.playerctl}/bin/playerctl pause";
XF86MonBrightnessUp = "exec ${brightness-sh}/bin/brightness.sh up";
XF86MonBrightnessDown =
"exec ${brightness-sh}/bin/brightness.sh down";
};
# https://github.com/gytis-ivaskevicius/nixfiles/blob/master/home-manager/i3-sway.nix
keybindings = mkOptionDefault { "Mod4+d" = ""; };
modifier = "Mod4";
output = { "eDP-1" = { bg = "${wallpaper} fill"; }; };
terminal = "${pkgs.kitty}/bin/kitty";
# https://rycee.gitlab.io/home-manager/options.html#opt-wayland.windowManager.sway.config.window.commands
window = { };
# window = { };
startup = [{ command = "${pkgs.autotiling}/bin/autotiling"; }];
};
};
home.packages = with pkgs; [
autotiling
dmenu
grim
imagemagick
slurp
gammastep
swayidle
swaylock
playerctl
wl-clipboard
wofi
(writeTextFile {
name = "sway-entry";
destination = "/bin/sway-entry";
executable = true;
text = ''
#! ${pkgs.bash}/bin/bash
# first import environment variables from the login manager
# function is currently deprecated. It should be rolled back in the future
systemctl --user import-environment
# then start the service
exec systemctl --user start sway.service
'';
})
];
home.packages = with pkgs;
[
autotiling
batsignal
dmenu
grim
imagemagick
slurp
gammastep
swayidle
swaylock
playerctl
wl-clipboard
wofi
] ++ scripts;
};
programs.light.enable = true;
programs.sway = {
enable = true;
wrapperFeatures.gtk = true;
};
systemd.user.targets.sway-session = {
description = "Sway compositor session";