greenhouse

kore

my public infrastructure monorepo

git clone [email protected]:kore.git

kore / home / features / wayland / dwl.nix57 lines · 1844B · raw

1{ config, pkgs, ... }:
2
3let
4  screenshot = pkgs.writeShellApplication {
5    name = "screenshot";
6    runtimeInputs = with pkgs; [ grim slurp wl-clipboard coreutils ];
7    text = ''
8      case "''${1:-area}" in
9        area) grim -g "$(slurp)" - | wl-copy -t image/png ;;
10        output) grim -g "$(slurp -o)" - | wl-copy -t image/png ;;
11        save)
12          dir="${config.xdg.userDirs.pictures}/screenshots"
13          mkdir -p "$dir"
14          grim -g "$(slurp)" "$dir/$(date +%Y-%m-%d_%H-%M-%S).png"
15          ;;
16        *) echo "usage: screenshot [area|output|save]" >&2; exit 1 ;;
17      esac
18    '';
19  };
20
21  volume = pkgs.writeShellApplication {
22    name = "volume";
23    runtimeInputs = with pkgs; [ wireplumber libnotify gawk coreutils ];
24    text = ''
25      sink=@DEFAULT_AUDIO_SINK@
26      source=@DEFAULT_AUDIO_SOURCE@
27
28      case "''${1:-}" in
29        up) wpctl set-volume -l 1.0 "$sink" 5%+ ;;
30        down) wpctl set-volume "$sink" 5%- ;;
31        mute) wpctl set-mute "$sink" toggle ;;
32        mic) wpctl set-mute "$source" toggle ;;
33        *) echo "usage: volume [up|down|mute|mic]" >&2; exit 1 ;;
34      esac
35
36      if [ "$1" = mic ]; then
37        target=$source
38      else
39        target=$sink
40      fi
41      state="$(wpctl get-volume "$target")"
42      pct="$(awk '{ printf "%d", $2 * 100 + 0.5 }' <<< "$state")"
43
44      if [ "$1" = mic ]; then
45        case "$state" in *MUTED*) title="mic muted" ;; *) title="mic on" ;; esac
46      else
47        case "$state" in *MUTED*) title="muted" ;; *) title="volume $pct" ;; esac
48      fi
49
50      idfile="''${XDG_RUNTIME_DIR:-/tmp}/volume-notify-id"
51      id="$(cat "$idfile" 2>/dev/null || echo 0)"
52      notify-send -p -r "$id" -c volume -h "int:value:$pct" "$title" > "$idfile"
53    '';
54  };
55in {
56  home.packages = with pkgs; [ wmenu wl-clipboard xdg-utils playerctl screenshot volume ];
57}