summaryrefslogtreecommitdiffstats
path: root/roles/hyprland/files/scripts/sunset.sh
blob: 1659aaab9e4533556f9aa9c5c2ecaf924ebab453 (plain) (blame)
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
78
79
80
81
#!/bin/bash

# Default temperature values
TEMP_ON=4000
TEMP_OFF=6000

get_temp() {
    local temp="$(hyprctl hyprsunset temperature 2>/dev/null | grep -oE '[0-9]+')"
    echo "$temp"
}

get_status() {
    read -r temp <<< "$(get_temp)"
    local waybar_status=""
    if [[ "$temp" == "$TEMP_ON" ]]; then
        waybar_status=$(printf '{"alt": "on", "tooltip": "Nightshift On (temp: %s)"}' "$temp")
    else
        waybar_status=$(printf '{"alt": "off", "tooltip": "Nightshift Off (temp: %s)"}' "$temp")
    fi
    echo "${waybar_status}"
}

set_temp() {
    local temp=$1
    hyprctl hyprsunset temperature $temp 2>/dev/null 1>&2
    notify "" "" "$TEMP"
    pkill -x -SIGRTMIN+6 waybar
}

toggle_nightshift() {
    read -r temp <<< "$(get_temp)"
    if [[ "$temp" == "$TEMP_ON" ]]; then
        set_temp $TEMP_OFF
        temp=$TEMP_OFF
        class="off"
        icon=""
    else
        set_temp $TEMP_ON
        temp=$TEMP_ON
        class="on"
        icon=""
    fi
    notify "$class" "$icon" "$temp"
    pkill -x -SIGRTMIN+6 waybar
}

notify() {
    local class="$1"
    local icon="$2"
    local temp="$3"
    notify-send -e \
        -h string:x-canonical-private-synchronous:sunset \
        -u low \
        "Nightshift ${class}" \
        "${icon}   Temprature: ${temp}"
}

TEMP="${2:-$TEMP_ON}"
case "$1" in
    "--get")
        read -r temp <<< "$(get_temp)"
        echo "${temp}"
        ;;
    "--set")
        set_temp "$TEMP"
        ;;
    "--status")
        get_status
        ;;
    "--toggle")
        toggle_nightshift
        ;;
    *)
        echo -e "Usage:"
        echo -e "  --get          to get current screen temprature value"
        echo -e "  --set [arg]    to set current screen temprature to [arg]"
        echo -e "  --toggle       to toggle sunset/nightshift"
        echo -e " --staus         to get the (waybar) JSON staus"
        exit 0
        ;;
esac