2020-08-18 11:15:45 +00:00
|
|
|
package lockscreen
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-08-20 14:57:57 +00:00
|
|
|
// XDG uses qdbus to monitor the freedesktop screensaver status
|
|
|
|
type XDG struct {}
|
|
|
|
|
2020-08-18 11:15:45 +00:00
|
|
|
// IsActive checks whether the screen is locked (checks if the screensaver is active)
|
2020-08-20 14:57:57 +00:00
|
|
|
func (XDG) IsActive() (bool, error) {
|
2020-08-18 11:15:45 +00:00
|
|
|
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
|
|
|
|
}
|