Skip to content

shouya/wake-guard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WakeGuard

WakeGuard is a DBus based service to inhibit idle/sleep for X11 desktop users. I wrote this program because I need a status bar widget that allows me:

  • to quickly adjust inhibition time
  • to select the mode between preventing screen dim and preventing system suspend
  • see the up-to-date remaining time in the status bar

And to my knowledge, there is no such program available.

Main features

  • inhibit idle (i.e. X screensaver)
  • inhibit sleep (i.e. systemd suspend)
  • increase/decrease duration of inhibition
  • set duration of inhibition
  • set inhibition type to idle or sleep
  • monitor for up-to-date remaining inhibition time
  • monitoring and control through dbus interface
  • asynchronous, efficient, light on system resources

Implementation details

  • prevent idle by resetting x screensaver timeout (i.e. xset s reset)
  • prevent sleep through logind API (i.e. systemd-inhibit)

Installation

cargo build --release
cp target/release/wakeguard ~/.local/bin

Usage

Here’s a sample eww widget just for reference:

(deflisten wake-guard :initial
  '{"active":false,"mode":null,"remaining_seconds":null,"message":""}'
  `wake-guard monitor`)

(defwidget wake-guard-toggle []
  (tooltip
   (wake-guard-toggle-tooltip)
   (eventbox
    :cursor "hand"
    :onclick { wake-guard.mode=="null" ? "wake-guard msg -m idle +15m" :
               wake-guard.mode=="sleep" ? "wake-guard msg -m idle +0s" :
               wake-guard.mode=="idle" ? "wake-guard msg -m sleep +0s" : "" }
    :onmiddleclick "(notify-send 'Display off in 2 secs'; sleep 2; xset dpms force off) &"
    :onrightclick "(notify-send 'Suspending in 2 secs'; sleep 2; systemctl suspend) &"
    :onscroll "test {} = up && wake-guard msg +15m || wake-guard msg -15m"
    :class { wake-guard.active ? "toggle-enabled" : "toggle-disabled" }
    (box :space-evenly false
         (box :visible {wake-guard.mode=="null"}
              (icon :text "󰒲"))
         (box :visible {wake-guard.mode=="sleep"}
              (icon :text "󰒳"))
         (box :visible {wake-guard.mode=="idle"}
              (icon :text "󰈉"))
         (label :visible {wake-guard.mode!="null"} :text "${wake-guard.mode}")
         (label :visible {wake-guard.message!=""} :text "/${wake-guard.message}")))))

(defwidget wake-guard-toggle-tooltip []
  (box
   :orientation "v"
   :space-evenly false
   (label :xalign 0 :text "Left-click: toggle mode")
   (label :xalign 0 :text "Middle-click: screen-off")
   (label :xalign 0 :text "Right-click: suspend")
   (label :xalign 0 :text "Scroll: adjust duration")))

You must start the dbus service with wake-guard daemon before using the widget. I recommend starting it in your X session startup script or systemd user service. An example systemd user service is provided in the repository.

Run wake-guard --help for detailed usage information.

Releases

No releases published

Packages

No packages published

Languages