diff --git a/server/internal/desktop/manager.go b/server/internal/desktop/manager.go index bd310a7e..a1ad408e 100644 --- a/server/internal/desktop/manager.go +++ b/server/internal/desktop/manager.go @@ -10,14 +10,18 @@ import ( "m1k1o/neko/internal/desktop/xorg" "m1k1o/neko/internal/types" + "github.com/kataras/go-events" "github.com/rs/zerolog" "github.com/rs/zerolog/log" ) +var mu = sync.Mutex{} + type DesktopManagerCtx struct { logger zerolog.Logger wg sync.WaitGroup shutdown chan struct{} + emmiter events.EventEmmiter config *config.Desktop } @@ -25,6 +29,7 @@ func New(config *config.Desktop, broadcast types.BroadcastManager) *DesktopManag return &DesktopManagerCtx{ logger: log.With().Str("module", "desktop").Logger(), shutdown: make(chan struct{}), + emmiter: events.New(), config: config, } } @@ -71,6 +76,18 @@ func (manager *DesktopManagerCtx) Start() { }() } +func (manager *DesktopManagerCtx) OnBeforeScreenSizeChange(listener func()) { + manager.emmiter.On("before_screen_size_change", func(payload ...any) { + listener() + }) +} + +func (manager *DesktopManagerCtx) OnAfterScreenSizeChange(listener func()) { + manager.emmiter.On("after_screen_size_change", func(payload ...any) { + listener() + }) +} + func (manager *DesktopManagerCtx) Shutdown() error { manager.logger.Info().Msgf("desktop shutting down") diff --git a/server/internal/desktop/xorg.go b/server/internal/desktop/xorg.go index a0c8945a..2a2f4312 100644 --- a/server/internal/desktop/xorg.go +++ b/server/internal/desktop/xorg.go @@ -71,6 +71,14 @@ func (manager *DesktopManagerCtx) ScreenConfigurations() map[int]types.ScreenCon } func (manager *DesktopManagerCtx) SetScreenSize(size types.ScreenSize) error { + mu.Lock() + manager.emmiter.Emit("before_screen_size_change") + + defer func() { + manager.emmiter.Emit("after_screen_size_change") + mu.Unlock() + }() + return xorg.ChangeScreenSize(size.Width, size.Height, size.Rate) } diff --git a/server/internal/types/desktop.go b/server/internal/types/desktop.go index 4414bbae..39fe55c4 100644 --- a/server/internal/types/desktop.go +++ b/server/internal/types/desktop.go @@ -36,6 +36,8 @@ type KeyboardMap struct { type DesktopManager interface { Start() Shutdown() error + OnBeforeScreenSizeChange(listener func()) + OnAfterScreenSizeChange(listener func()) // clipboard ReadClipboard() string