kde-lockscreen-suspend-display/lockscreen/lockscreen.go

29 lines
578 B
Go

package lockscreen
import (
"os/exec"
"strings"
)
// XDG uses qdbus to monitor the freedesktop screensaver status
type XDG struct {}
// IsActive checks whether the screen is locked (checks if the screensaver is active)
func (XDG) IsActive() (bool, error) {
cmd := exec.Command("qdbus",
"org.kde.screensaver",
"/ScreenSaver",
"org.freedesktop.ScreenSaver.GetActive",
)
outputBytes, err := cmd.CombinedOutput()
if err != nil {
return false, err
}
output := string(outputBytes)
if strings.HasPrefix(output, "true") {
return true, nil
}
return false, nil
}