greenhouse

kore

my public infrastructure monorepo

git clone [email protected]:kore.git

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