Skip to content

Commit

Permalink
xorg add events.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o committed Sep 17, 2022
1 parent 2e5d3f5 commit 72da075
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions server/internal/desktop/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ 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
}

func New(config *config.Desktop, broadcast types.BroadcastManager) *DesktopManagerCtx {
return &DesktopManagerCtx{
logger: log.With().Str("module", "desktop").Logger(),
shutdown: make(chan struct{}),
emmiter: events.New(),
config: config,
}
}
Expand Down Expand Up @@ -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")

Expand Down
8 changes: 8 additions & 0 deletions server/internal/desktop/xorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 2 additions & 0 deletions server/internal/types/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type KeyboardMap struct {
type DesktopManager interface {
Start()
Shutdown() error
OnBeforeScreenSizeChange(listener func())
OnAfterScreenSizeChange(listener func())

// clipboard
ReadClipboard() string
Expand Down

0 comments on commit 72da075

Please sign in to comment.