aboutsummaryrefslogtreecommitdiff
path: root/tw/services/files/sessionmenu
blob: 4f145d34c8c921be8d962b2e229e20ea9e0eee49 (about) (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
#!/usr/bin/env -S guile --no-auto-compile
!#
(use-modules (ice-9 format)
             (ice-9 match)
             (ice-9 ports))

(define wm
  (cond ((getenv "SWAYSOCK") 'sway)
        ((getenv "I3SOCK") 'i3)
        (else #f)))

(define (call-command/stderr . command)
  "Call COMMAND using `system*', but redirect all output to stderr."
  (with-output-to-port (current-error-port)
    (lambda () (apply system* command))))

(define (wm-msg . command)
  (apply call-command/stderr
         (match wm
           (sway "swaymsg")
           (i3 "i3-msg")
           (_ (error "No recognised window manager running")))
         command))

(match (command-line)
  ((_ "quit")
   (exit 0))
  ((_ "Reload WM configuration")
   (wm-msg "reload"))
  ((_ "Sleep")
   ;; Rely on swayidle to lock the screen before going to sleep.
   (call-command/stderr "loginctl" "suspend"))
  ((_ "Log out")
   (wm-msg "exit"))
  ((_ "Shutdown")
   (call-command/stderr "sudo" "-n" "/run/current-system/profile/sbin/shutdown"))
  ((_ "Reboot")
   (call-command/stderr "sudo" "-n" "/run/current-system/profile/sbin/reboot"))
  (_
   (format #t "\0~a\x1f~a~%~{~a\0icon\x1f~a~%~}"
           "prompt" "Session"
           `(,@(if wm
                   '("Reload WM configuration" "reload"
                     "Log out" "system-log-out")
                   '())
             "Sleep" "system-suspend"
             "Shutdown" "system-shutdown"
             "Reboot" "system-reboot"))))