desktop display from env.

This commit is contained in:
Miroslav Šedivý 2021-03-11 17:44:49 +01:00
parent 0ac2109275
commit d24cea3535
4 changed files with 13 additions and 14 deletions

View File

@ -1,6 +1,7 @@
package config package config
import ( import (
"os"
"regexp" "regexp"
"strconv" "strconv"
@ -9,6 +10,8 @@ import (
) )
type Desktop struct { type Desktop struct {
Display string
ScreenWidth int ScreenWidth int
ScreenHeight int ScreenHeight int
ScreenRate int16 ScreenRate int16
@ -24,6 +27,9 @@ func (Desktop) Init(cmd *cobra.Command) error {
} }
func (s *Desktop) Set() { func (s *Desktop) Set() {
// Display is provided by env variable
s.Display = os.Getenv("DISPLAY")
s.ScreenWidth = 1280 s.ScreenWidth = 1280
s.ScreenHeight = 720 s.ScreenHeight = 720
s.ScreenRate = 30 s.ScreenRate = 30

View File

@ -21,24 +21,22 @@ type DesktopManagerCtx struct {
cleanup *time.Ticker cleanup *time.Ticker
shutdown chan bool shutdown chan bool
emmiter events.EventEmmiter emmiter events.EventEmmiter
display string
config *config.Desktop config *config.Desktop
} }
func New(display string, config *config.Desktop) *DesktopManagerCtx { func New(config *config.Desktop) *DesktopManagerCtx {
return &DesktopManagerCtx{ return &DesktopManagerCtx{
logger: log.With().Str("module", "desktop").Logger(), logger: log.With().Str("module", "desktop").Logger(),
cleanup: time.NewTicker(1 * time.Second), cleanup: time.NewTicker(1 * time.Second),
shutdown: make(chan bool), shutdown: make(chan bool),
emmiter: events.New(), emmiter: events.New(),
display: display,
config: config, config: config,
} }
} }
func (manager *DesktopManagerCtx) Start() { func (manager *DesktopManagerCtx) Start() {
if err := xorg.DisplayOpen(manager.display); err != nil { if xorg.DisplayOpen(manager.config.Display) {
manager.logger.Warn().Err(err).Msg("unable to open dispaly") manager.logger.Panic().Str("display", manager.config.Display).Msg("unable to open display")
} }
xorg.GetScreenConfigurations() xorg.GetScreenConfigurations()
@ -51,7 +49,7 @@ func (manager *DesktopManagerCtx) Start() {
manager.logger.Warn().Err(err).Msg("unable to set initial screen size") manager.logger.Warn().Err(err).Msg("unable to set initial screen size")
} }
go xevent.EventLoop(manager.display) go xevent.EventLoop(manager.config.Display)
// In case it was opened // In case it was opened
go manager.CloseFileChooserDialog() go manager.CloseFileChooserDialog()

View File

@ -39,19 +39,15 @@ func GetScreenConfigurations() {
C.XGetScreenConfigurations() C.XGetScreenConfigurations()
} }
func DisplayOpen(display string) error { func DisplayOpen(display string) bool {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
displayUnsafe := C.CString(display) displayUnsafe := C.CString(display)
defer C.free(unsafe.Pointer(displayUnsafe)) defer C.free(unsafe.Pointer(displayUnsafe))
err := C.XDisplayOpen(displayUnsafe) ok := C.XDisplayOpen(displayUnsafe)
if int(err) == 1 { return int(ok) == 1
return fmt.Errorf("Could not open display %s.", display)
}
return nil
} }
func DisplayClose() { func DisplayClose() {

View File

@ -137,7 +137,6 @@ func (neko *Neko) Start() {
} }
neko.desktopManager = desktop.New( neko.desktopManager = desktop.New(
neko.Configs.Capture.Display,
neko.Configs.Desktop, neko.Configs.Desktop,
) )
neko.desktopManager.Start() neko.desktopManager.Start()