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

View File

@ -21,24 +21,22 @@ type DesktopManagerCtx struct {
cleanup *time.Ticker
shutdown chan bool
emmiter events.EventEmmiter
display string
config *config.Desktop
}
func New(display string, config *config.Desktop) *DesktopManagerCtx {
func New(config *config.Desktop) *DesktopManagerCtx {
return &DesktopManagerCtx{
logger: log.With().Str("module", "desktop").Logger(),
cleanup: time.NewTicker(1 * time.Second),
shutdown: make(chan bool),
emmiter: events.New(),
display: display,
config: config,
}
}
func (manager *DesktopManagerCtx) Start() {
if err := xorg.DisplayOpen(manager.display); err != nil {
manager.logger.Warn().Err(err).Msg("unable to open dispaly")
if xorg.DisplayOpen(manager.config.Display) {
manager.logger.Panic().Str("display", manager.config.Display).Msg("unable to open display")
}
xorg.GetScreenConfigurations()
@ -51,7 +49,7 @@ func (manager *DesktopManagerCtx) Start() {
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
go manager.CloseFileChooserDialog()

View File

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

View File

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