adding a setting for when not running X

This commit is contained in:
Vincent Batts 2014-10-09 08:55:20 -04:00
parent 0353abbd93
commit 8dccc692e8
2 changed files with 20 additions and 5 deletions

View file

@ -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 {