Refactor screensaver package into display and lockscreen

This commit is contained in:
2020-08-18 13:15:45 +02:00
parent 97884bfb64
commit 8bba5b30a4
4 changed files with 78 additions and 67 deletions

26
lockscreen/lockscreen.go Normal file
View File

@ -0,0 +1,26 @@
package lockscreen
import (
"os/exec"
"strings"
)
// IsActive checks whether the screen is locked (checks if the screensaver is active)
func 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
}