diff --git a/config/config.go b/config/config.go index 7cf4239..733c48b 100644 --- a/config/config.go +++ b/config/config.go @@ -4,18 +4,25 @@ import ( "fmt" "io" "io/ioutil" - "launchpad.net/goyaml" "os" "os/exec" "strings" + + "launchpad.net/goyaml" ) type Config struct { - SuspendCmd, LockCmd string + SuspendCmd, LockCmd string + NoXSuspendCmd, NoXLockCmd string } func (c *Config) Suspend() (err error) { - args := strings.Split(c.SuspendCmd, " ") + var args []string + if len(os.Getenv("DISPLAY")) > 0 { + args = strings.Split(c.SuspendCmd, " ") + } else { + args = strings.Split(c.NoXSuspendCmd, " ") + } cmd := exec.Command(args[0], args[1:]...) stdout, err := cmd.StdoutPipe() if err != nil { @@ -34,7 +41,12 @@ func (c *Config) Suspend() (err error) { } func (c *Config) Lock() (err error) { - args := strings.Split(c.LockCmd, " ") + var args []string + if len(os.Getenv("DISPLAY")) > 0 { + args = strings.Split(c.LockCmd, " ") + } else { + args = strings.Split(c.NoXLockCmd, " ") + } cmd := exec.Command(args[0], args[1:]...) stdout, err := cmd.StdoutPipe() if err != nil { diff --git a/lockout/main.go b/lockout/main.go index ce7cdb0..b1f5d7f 100644 --- a/lockout/main.go +++ b/lockout/main.go @@ -2,8 +2,9 @@ package main import ( "fmt" - "github.com/vbatts/go-lockout/config" "os" + + "github.com/vbatts/go-lockout/config" ) func main() { @@ -40,5 +41,7 @@ Please configure this file to look something like suspendcmd: sudo /usr/sbin/pm-suspend lockcmd: xscreensaver-command -lock + noxsuspendcmd: sudo /usr/sbin/pm-suspend + noxlockcmd: clear ` )