xorg add events.

This commit is contained in:
Miroslav Šedivý 2022-09-17 11:08:17 +02:00
parent 2e5d3f5624
commit 72da075972
3 changed files with 27 additions and 0 deletions

View File

@ -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")

View File

@ -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)
}

View File

@ -36,6 +36,8 @@ type KeyboardMap struct {
type DesktopManager interface {
Start()
Shutdown() error
OnBeforeScreenSizeChange(listener func())
OnAfterScreenSizeChange(listener func())
// clipboard
ReadClipboard() string