mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
remove go-events
This commit is contained in:
committed by
Miroslav Šedivý
parent
cfc6bd417f
commit
5690a849e2
@ -9,7 +9,6 @@ import (
|
||||
"m1k1o/neko/internal/desktop/xevent"
|
||||
"m1k1o/neko/internal/desktop/xorg"
|
||||
|
||||
"github.com/kataras/go-events"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
@ -17,18 +16,20 @@ import (
|
||||
var mu = sync.Mutex{}
|
||||
|
||||
type DesktopManagerCtx struct {
|
||||
logger zerolog.Logger
|
||||
wg sync.WaitGroup
|
||||
shutdown chan struct{}
|
||||
emmiter events.EventEmmiter
|
||||
config *config.Desktop
|
||||
logger zerolog.Logger
|
||||
wg sync.WaitGroup
|
||||
shutdown chan struct{}
|
||||
beforeScreenSizeChangeChannel chan bool
|
||||
afterScreenSizeChangeChannel chan int16
|
||||
config *config.Desktop
|
||||
}
|
||||
|
||||
func New(config *config.Desktop) *DesktopManagerCtx {
|
||||
return &DesktopManagerCtx{
|
||||
logger: log.With().Str("module", "desktop").Logger(),
|
||||
shutdown: make(chan struct{}),
|
||||
emmiter: events.New(),
|
||||
beforeScreenSizeChangeChannel: make (chan bool),
|
||||
afterScreenSizeChangeChannel: make (chan int16),
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
@ -47,14 +48,17 @@ func (manager *DesktopManagerCtx) Start() {
|
||||
|
||||
go xevent.EventLoop(manager.config.Display)
|
||||
|
||||
manager.OnEventError(func(error_code uint8, message string, request_code uint8, minor_code uint8) {
|
||||
manager.logger.Warn().
|
||||
Uint8("error_code", error_code).
|
||||
Str("message", message).
|
||||
Uint8("request_code", request_code).
|
||||
Uint8("minor_code", minor_code).
|
||||
go func() {
|
||||
for {
|
||||
desktopErrorMessage := <- xevent.EventErrorChannel
|
||||
manager.logger.Warn().
|
||||
Uint8("error_code", desktopErrorMessage.Error_code).
|
||||
Str("message", desktopErrorMessage.Message).
|
||||
Uint8("request_code", desktopErrorMessage.Request_code).
|
||||
Uint8("minor_code", desktopErrorMessage.Minor_code).
|
||||
Msg("X event error occurred")
|
||||
})
|
||||
}
|
||||
}()
|
||||
|
||||
manager.wg.Add(1)
|
||||
|
||||
@ -75,16 +79,12 @@ func (manager *DesktopManagerCtx) Start() {
|
||||
}()
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) OnBeforeScreenSizeChange(listener func()) {
|
||||
manager.emmiter.On("before_screen_size_change", func(payload ...any) {
|
||||
listener()
|
||||
})
|
||||
func (manager *DesktopManagerCtx) GetBeforeScreenSizeChangeChannel() (chan bool) {
|
||||
return manager.beforeScreenSizeChangeChannel
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) OnAfterScreenSizeChange(listener func()) {
|
||||
manager.emmiter.On("after_screen_size_change", func(payload ...any) {
|
||||
listener()
|
||||
})
|
||||
func (manager *DesktopManagerCtx) GetAfterScreenSizeChangeChannel() (chan int16) {
|
||||
return manager.afterScreenSizeChangeChannel
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) Shutdown() error {
|
||||
|
@ -1,33 +1,26 @@
|
||||
package desktop
|
||||
|
||||
import "m1k1o/neko/internal/desktop/xevent"
|
||||
import (
|
||||
"m1k1o/neko/internal/desktop/xevent"
|
||||
"m1k1o/neko/internal/types"
|
||||
)
|
||||
|
||||
func (manager *DesktopManagerCtx) OnCursorChanged(listener func(serial uint64)) {
|
||||
xevent.Emmiter.On("cursor-changed", func(payload ...any) {
|
||||
listener(payload[0].(uint64))
|
||||
})
|
||||
func (manager *DesktopManagerCtx) GetCursorChangedChannel() (chan uint64) {
|
||||
return xevent.CursorChangedChannel
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) OnClipboardUpdated(listener func()) {
|
||||
xevent.Emmiter.On("clipboard-updated", func(payload ...any) {
|
||||
listener()
|
||||
})
|
||||
func (manager *DesktopManagerCtx) GetClipboardUpdatedChannel() (chan bool) {
|
||||
return xevent.ClipboardUpdatedChannel
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) OnFileChooserDialogOpened(listener func()) {
|
||||
xevent.Emmiter.On("file-chooser-dialog-opened", func(payload ...any) {
|
||||
listener()
|
||||
})
|
||||
func (manager *DesktopManagerCtx) GetFileChooserDialogOpenedChannel() (chan bool) {
|
||||
return xevent.FileChooserDialogOpenedChannel
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) OnFileChooserDialogClosed(listener func()) {
|
||||
xevent.Emmiter.On("file-chooser-dialog-closed", func(payload ...any) {
|
||||
listener()
|
||||
})
|
||||
func (manager *DesktopManagerCtx) GetFileChooserDialogClosedChannel() (chan bool) {
|
||||
return xevent.FileChooserDialogClosedChannel
|
||||
}
|
||||
|
||||
func (manager *DesktopManagerCtx) OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) {
|
||||
xevent.Emmiter.On("event-error", func(payload ...any) {
|
||||
listener(payload[0].(uint8), payload[1].(string), payload[2].(uint8), payload[3].(uint8))
|
||||
})
|
||||
func (manager *DesktopManagerCtx) GetEventErrorChannel() (chan types.DesktopErrorMessage) {
|
||||
return xevent.EventErrorChannel
|
||||
}
|
||||
|
@ -9,14 +9,38 @@ import "C"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/kataras/go-events"
|
||||
"m1k1o/neko/internal/types"
|
||||
)
|
||||
|
||||
var Emmiter events.EventEmmiter
|
||||
var CursorChangedChannel chan uint64
|
||||
var ClipboardUpdatedChannel chan bool
|
||||
var FileChooserDialogClosedChannel chan bool
|
||||
var FileChooserDialogOpenedChannel chan bool
|
||||
var EventErrorChannel chan types.DesktopErrorMessage
|
||||
|
||||
func init() {
|
||||
Emmiter = events.New()
|
||||
CursorChangedChannel = make(chan uint64)
|
||||
ClipboardUpdatedChannel = make(chan bool)
|
||||
FileChooserDialogClosedChannel = make(chan bool)
|
||||
FileChooserDialogOpenedChannel = make(chan bool)
|
||||
EventErrorChannel = make(chan types.DesktopErrorMessage)
|
||||
|
||||
// Dummy goroutines since there is no consumer for the channel otherwise
|
||||
go func() {
|
||||
for {
|
||||
_ = <-CursorChangedChannel
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
for {
|
||||
_ = <-FileChooserDialogClosedChannel
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
for {
|
||||
_ = <-FileChooserDialogOpenedChannel
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func EventLoop(display string) {
|
||||
@ -28,12 +52,12 @@ func EventLoop(display string) {
|
||||
|
||||
//export goXEventCursorChanged
|
||||
func goXEventCursorChanged(event C.XFixesCursorNotifyEvent) {
|
||||
Emmiter.Emit("cursor-changed", uint64(event.cursor_serial))
|
||||
CursorChangedChannel <- uint64(event.cursor_serial)
|
||||
}
|
||||
|
||||
//export goXEventClipboardUpdated
|
||||
func goXEventClipboardUpdated() {
|
||||
Emmiter.Emit("clipboard-updated")
|
||||
ClipboardUpdatedChannel <- true
|
||||
}
|
||||
|
||||
//export goXEventConfigureNotify
|
||||
@ -48,7 +72,7 @@ func goXEventUnmapNotify(window C.Window) {
|
||||
|
||||
//export goXEventError
|
||||
func goXEventError(event *C.XErrorEvent, message *C.char) {
|
||||
Emmiter.Emit("event-error", uint8(event.error_code), C.GoString(message), uint8(event.request_code), uint8(event.minor_code))
|
||||
EventErrorChannel <- types.DesktopErrorMessage{ uint8(event.error_code), C.GoString(message), uint8(event.request_code), uint8(event.minor_code) }
|
||||
}
|
||||
|
||||
//export goXEventActive
|
||||
|
@ -72,10 +72,10 @@ 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")
|
||||
manager.GetBeforeScreenSizeChangeChannel() <- true
|
||||
|
||||
defer func() {
|
||||
manager.emmiter.Emit("after_screen_size_change")
|
||||
manager.GetAfterScreenSizeChangeChannel() <- size.Rate
|
||||
mu.Unlock()
|
||||
}()
|
||||
|
||||
|
Reference in New Issue
Block a user