summaryrefslogtreecommitdiff
path: root/common/modules/mango/scripts.nix
blob: b3de75d160049d828f4ff7d06eed0ae1f4f09245 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ pkgs, ... }:
let
  # CHANGED: writeShellScript -> writeShellScriptBin
  volume-control = pkgs.writeShellScriptBin "volume-control" ''
    TAG="audio-volume"

    function get_vol {
      ${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{print int($2 * 100)}'
    }

    case $1 in
      up)   ${pkgs.wireplumber}/bin/wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+ ;;
      down) ${pkgs.wireplumber}/bin/wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- ;;
      mute) ${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle ;;
    esac

    vol=$(get_vol)
    is_muted=$(${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_AUDIO_SINK@ | grep "MUTED")

    if [ -n "$is_muted" ]; then
      ${pkgs.dunst}/bin/dunstify -a "Volume" -u low \
        -h string:x-canonical-private-synchronous:$TAG \
        "Volume: Muted"
    else
      ${pkgs.dunst}/bin/dunstify -a "Volume" -u low \
        -h string:x-canonical-private-synchronous:$TAG \
        -h int:value:"$vol" \
        "Volume: $vol%"
    fi
  '';

  # CHANGED: writeShellScript -> writeShellScriptBin
  brightness-control = pkgs.writeShellScriptBin "brightness-control" ''
    TAG="screen-brightness"

    case $1 in
      up)   ${pkgs.brightnessctl}/bin/brightnessctl set +5% ;;
      down) ${pkgs.brightnessctl}/bin/brightnessctl set 5%- ;;
    esac

    # Get current percentage
    current=$(${pkgs.brightnessctl}/bin/brightnessctl info | grep -oP '\(\K[0-9]+(?=%\))')

    ${pkgs.dunst}/bin/dunstify -a "Brightness" -u low \
      -h string:x-canonical-private-synchronous:$TAG \
      -h int:value:"$current" \
      "Brightness: $current%"
  '';

  # CHANGED: writeShellScript -> writeShellScriptBin
  mic-control = pkgs.writeShellScriptBin "mic-control" ''
    TAG="audio-mic"

    case $1 in
      toggle) ${pkgs.wireplumber}/bin/wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle ;;
    esac

    is_muted=$(${pkgs.wireplumber}/bin/wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | grep "MUTED")

    if [ -n "$is_muted" ]; then
        ${pkgs.dunst}/bin/dunstify -a "Microphone" -u low \
          -h string:x-canonical-private-synchronous:$TAG \
          "Microphone: Muted"
    else
        ${pkgs.dunst}/bin/dunstify -a "Microphone" -u low \
          -h string:x-canonical-private-synchronous:$TAG \
          "Microphone: On"
    fi
  '';
in
{
  home.packages = [
    volume-control
    brightness-control
    mic-control
  ];
}