mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
desktop display from env.
This commit is contained in:
parent
0ac2109275
commit
d24cea3535
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user