Refactor screensaver package into display and lockscreen
This commit is contained in:
26
lockscreen/lockscreen.go
Normal file
26
lockscreen/lockscreen.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user