summaryrefslogtreecommitdiffstats
path: root/roles/hyprland/files/scripts/power.sh
blob: c2f566d6c70ee6b1f47a4cab8ae6605fdc0fb417 (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
#!/bin/bash

shutdown() {
  hyprshutdown -t "Shutting down..." --post-cmd "systemctl poweroff"
}

reboot() {
  hyprshutdown -t "Restarting..." --post-cmd "systemctl reboot"
}

hibernate() {
  systemctl suspend
}

lock_screen() {
  loginctl lock-session
}

interactive() {
  # Use the commented styling to get tofi fullscreen theme instead of
  # using the hpyrland windowrule workaround to get the dimming effect
  # --width 100% \
  # --height 120% \
  # --font-size 20 \
  # --anchor center \
  # --border-width 0 \
  # --outline-width 0 \
  # --padding-top 50% \
  # --padding-left 42% \
  # --result-spacing 10 \
  # --placeholder-text "" \
  # --prompt-text "Power:" \
  # --background-color "#000B"
  ACTION=$(printf ' Shutdown\n󰑙 Reboot\n󰤄 Suspend\n Lock Session' | tofi \
    --width 450 \
    --height 300 \
    --font-size 20 \
    --anchor center \
    --prompt-text "Power:" \
    --placeholder-text "" \
    --result-spacing 10
  )


  case "$ACTION" in
    *Shutdown*)
      shutdown
      ;;
    *Reboot*)
      reboot
      ;;
    *Suspend*)
      lock_screen
      hibernate
      ;;
    *Lock*)
      lock_screen
      ;;
  esac
}

case "$1" in
    "--shutdown")
        shutdown
        ;;
    "--reboot")
        reboot
        ;;
    "--hibernate")
        lock_screen
        hibernate
        ;;
    "--lock")
        lock_screen
        ;;
    *)
        interactive
        ;;
esac