mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
xevent DRY, expose emitter.
This commit is contained in:
parent
09625ecca5
commit
9d60468aea
@ -5,21 +5,31 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnCursorChanged(listener func(serial uint64)) {
|
func (manager *DesktopManagerCtx) OnCursorChanged(listener func(serial uint64)) {
|
||||||
xevent.OnCursorChanged(listener)
|
xevent.Emmiter.On("cursor-changed", func(payload ...interface{}) {
|
||||||
|
listener(payload[0].(uint64))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnClipboardUpdated(listener func()) {
|
func (manager *DesktopManagerCtx) OnClipboardUpdated(listener func()) {
|
||||||
xevent.OnClipboardUpdated(listener)
|
xevent.Emmiter.On("clipboard-updated", func(payload ...interface{}) {
|
||||||
|
listener()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnFileChooserDialogOpened(listener func()) {
|
func (manager *DesktopManagerCtx) OnFileChooserDialogOpened(listener func()) {
|
||||||
xevent.OnFileChooserDialogOpened(listener)
|
xevent.Emmiter.On("file-chooser-dialog-opened", func(payload ...interface{}) {
|
||||||
|
listener()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnFileChooserDialogClosed(listener func()) {
|
func (manager *DesktopManagerCtx) OnFileChooserDialogClosed(listener func()) {
|
||||||
xevent.OnFileChooserDialogClosed(listener)
|
xevent.Emmiter.On("file-chooser-dialog-closed", func(payload ...interface{}) {
|
||||||
|
listener()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) {
|
func (manager *DesktopManagerCtx) OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) {
|
||||||
xevent.OnEventError(listener)
|
xevent.Emmiter.On("event-error", func(payload ...interface{}) {
|
||||||
|
listener(payload[0].(uint8), payload[1].(string), payload[2].(uint8), payload[3].(uint8))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,11 @@ import (
|
|||||||
"github.com/kataras/go-events"
|
"github.com/kataras/go-events"
|
||||||
)
|
)
|
||||||
|
|
||||||
var emmiter events.EventEmmiter
|
var Emmiter events.EventEmmiter
|
||||||
var file_chooser_dialog_window uint32 = 0
|
var file_chooser_dialog_window uint32 = 0
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
emmiter = events.New()
|
Emmiter = events.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
func EventLoop(display string) {
|
func EventLoop(display string) {
|
||||||
@ -29,44 +29,14 @@ func EventLoop(display string) {
|
|||||||
C.XEventLoop(displayUnsafe)
|
C.XEventLoop(displayUnsafe)
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnCursorChanged(listener func(serial uint64)) {
|
|
||||||
emmiter.On("cursor-changed", func(payload ...interface{}) {
|
|
||||||
listener(payload[0].(uint64))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func OnClipboardUpdated(listener func()) {
|
|
||||||
emmiter.On("clipboard-updated", func(payload ...interface{}) {
|
|
||||||
listener()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func OnFileChooserDialogOpened(listener func()) {
|
|
||||||
emmiter.On("file-chooser-dialog-opened", func(payload ...interface{}) {
|
|
||||||
listener()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func OnFileChooserDialogClosed(listener func()) {
|
|
||||||
emmiter.On("file-chooser-dialog-closed", func(payload ...interface{}) {
|
|
||||||
listener()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) {
|
|
||||||
emmiter.On("event-error", func(payload ...interface{}) {
|
|
||||||
listener(payload[0].(uint8), payload[1].(string), payload[2].(uint8), payload[3].(uint8))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
//export goXEventCursorChanged
|
//export goXEventCursorChanged
|
||||||
func goXEventCursorChanged(event C.XFixesCursorNotifyEvent) {
|
func goXEventCursorChanged(event C.XFixesCursorNotifyEvent) {
|
||||||
emmiter.Emit("cursor-changed", uint64(event.cursor_serial))
|
Emmiter.Emit("cursor-changed", uint64(event.cursor_serial))
|
||||||
}
|
}
|
||||||
|
|
||||||
//export goXEventClipboardUpdated
|
//export goXEventClipboardUpdated
|
||||||
func goXEventClipboardUpdated() {
|
func goXEventClipboardUpdated() {
|
||||||
emmiter.Emit("clipboard-updated")
|
Emmiter.Emit("clipboard-updated")
|
||||||
}
|
}
|
||||||
|
|
||||||
//export goXEventConfigureNotify
|
//export goXEventConfigureNotify
|
||||||
@ -89,7 +59,7 @@ func goXEventConfigureNotify(display *C.Display, window C.Window, name *C.char,
|
|||||||
|
|
||||||
if file_chooser_dialog_window == 0 {
|
if file_chooser_dialog_window == 0 {
|
||||||
file_chooser_dialog_window = uint32(window)
|
file_chooser_dialog_window = uint32(window)
|
||||||
emmiter.Emit("file-chooser-dialog-opened")
|
Emmiter.Emit("file-chooser-dialog-opened")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,12 +70,12 @@ func goXEventUnmapNotify(window C.Window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
file_chooser_dialog_window = 0
|
file_chooser_dialog_window = 0
|
||||||
emmiter.Emit("file-chooser-dialog-closed")
|
Emmiter.Emit("file-chooser-dialog-closed")
|
||||||
}
|
}
|
||||||
|
|
||||||
//export goXEventError
|
//export goXEventError
|
||||||
func goXEventError(event *C.XErrorEvent, message *C.char) {
|
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))
|
Emmiter.Emit("event-error", uint8(event.error_code), C.GoString(message), uint8(event.request_code), uint8(event.minor_code))
|
||||||
}
|
}
|
||||||
|
|
||||||
//export goXEventActive
|
//export goXEventActive
|
||||||
|
Loading…
Reference in New Issue
Block a user