mirror of https://github.com/xSmurf/oz.git
parent
81cce725b4
commit
e9be258644
@ -0,0 +1,69 @@
|
||||
package xpra
|
||||
import (
|
||||
"github.com/subgraph/oz"
|
||||
"fmt"
|
||||
"os"
|
||||
"github.com/op/go-logging"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var xpraClientDefaultArgs = []string{
|
||||
"--title=@title@",
|
||||
"--compress=0",
|
||||
//"--delay-tray",
|
||||
//"--border=auto",
|
||||
"--no-keyboard-sync",
|
||||
}
|
||||
|
||||
func NewClient(config *oz.XServerConf, display uint64, cred *syscall.Credential, workdir string, hostname string, log *logging.Logger) *Xpra {
|
||||
x := new(Xpra)
|
||||
x.Config = config
|
||||
x.Display = display
|
||||
x.WorkDir = workdir
|
||||
x.xpraArgs = prepareClientArgs(config, display, workdir, log)
|
||||
x.Process = exec.Command("/usr/bin/xpra", x.xpraArgs...)
|
||||
x.Process.SysProcAttr = &syscall.SysProcAttr{
|
||||
Credential: cred,
|
||||
}
|
||||
x.Process.Env = append(os.Environ(),
|
||||
fmt.Sprintf("TMPDIR=%s", workdir),
|
||||
fmt.Sprintf("XPRA_SOCKET_HOSTNAME=%s", hostname),
|
||||
)
|
||||
return x
|
||||
}
|
||||
|
||||
func prepareClientArgs(config *oz.XServerConf, display uint64, workdir string, log *logging.Logger) []string {
|
||||
args := getDefaultArgs(config)
|
||||
args = append(args, xpraClientDefaultArgs...)
|
||||
if !config.EnableTray {
|
||||
args = append(args, "--no-tray")
|
||||
}
|
||||
if exists(config.TrayIcon, "Tray icon", log) {
|
||||
args = append(args, fmt.Sprintf("--tray-icon=%s", config.TrayIcon))
|
||||
}
|
||||
if exists(config.WindowIcon, "Window icon", log) {
|
||||
args = append(args, fmt.Sprintf("--window-icon=%s", config.WindowIcon))
|
||||
}
|
||||
args = append(args,
|
||||
fmt.Sprint("--socket-dir=%s", workdir),
|
||||
"attach",
|
||||
fmt.Sprintf(":%d", display),
|
||||
)
|
||||
return args
|
||||
}
|
||||
|
||||
func exists(path,label string, log *logging.Logger) bool {
|
||||
if path == "" {
|
||||
return false
|
||||
}
|
||||
if _,err := os.Stat(path); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
log.Notice("%s file missing at %s, ignored.", label, path)
|
||||
} else {
|
||||
log.Warning("Error reading file info for %s: %v", path, err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package xpra
|
||||
import (
|
||||
"github.com/subgraph/oz"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
var xpraServerDefaultArgs = []string{
|
||||
"--no-mdns",
|
||||
//"--pulseaudio",
|
||||
"--no-pulseaudio",
|
||||
"--input-method=SCIM",
|
||||
}
|
||||
|
||||
func NewServer(config *oz.XServerConf, display uint64, workdir string) *Xpra {
|
||||
x := new(Xpra)
|
||||
x.Config = config
|
||||
x.Display = display
|
||||
x.WorkDir = workdir
|
||||
x.xpraArgs = prepareServerArgs(config, display, workdir)
|
||||
x.Process = exec.Command("/usr/bin/xpra", x.xpraArgs...)
|
||||
x.Process.Env = append(os.Environ(), "TMPDIR="+workdir)
|
||||
|
||||
return x
|
||||
}
|
||||
|
||||
func prepareServerArgs(config *oz.XServerConf, display uint64, workdir string) []string {
|
||||
args := getDefaultArgs(config)
|
||||
args = append(args, xpraServerDefaultArgs...)
|
||||
args = append(args,
|
||||
fmt.Sprintf("--socket-dir=%s", workdir),
|
||||
"start",
|
||||
fmt.Sprintf(":%d", display),
|
||||
)
|
||||
return args
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
package xpra
|
||||
import (
|
||||
"os/exec"
|
||||
"github.com/subgraph/oz"
|
||||
)
|
||||
|
||||
type Xpra struct {
|
||||
// Server working directory where unix socket is created
|
||||
WorkDir string
|
||||
|
||||
Config *oz.XServerConf
|
||||
|
||||
// Running xpra process
|
||||
Process *exec.Cmd
|
||||
|
||||
// Display number
|
||||
Display uint64
|
||||
|
||||
// Arguments passed to xpra command
|
||||
xpraArgs []string
|
||||
|
||||
}
|
||||
|
||||
var xpraDefaultArgs = []string{
|
||||
"--no-daemon",
|
||||
"--mmap",
|
||||
"--no-sharing",
|
||||
"--bell",
|
||||
"--system-tray",
|
||||
"--xsettings",
|
||||
//"--no-xsettings",
|
||||
"--notifications",
|
||||
"--cursors",
|
||||
"--encoding=rgb",
|
||||
"--no-pulseaudio",
|
||||
}
|
||||
|
||||
func getDefaultArgs(config *oz.XServerConf) []string {
|
||||
args := []string{}
|
||||
args = append(args, xpraDefaultArgs...)
|
||||
if config.DisableClipboard {
|
||||
args = append(args, "--no-clipboard")
|
||||
} else {
|
||||
args = append(args, "--clipboard")
|
||||
}
|
||||
|
||||
if config.DisableAudio {
|
||||
args = append(args, "--no-microphone", "--no-speaker")
|
||||
} else {
|
||||
args = append(args, "--microphone", "--speaker")
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
Loading…
Reference in new issue