2021-01-11 03:55:29 +13:00
|
|
|
package xevent
|
|
|
|
|
|
|
|
/*
|
2021-01-12 03:57:14 +13:00
|
|
|
#cgo linux LDFLAGS: -lX11 -lXfixes
|
2021-01-11 03:55:29 +13:00
|
|
|
|
|
|
|
#include "xevent.h"
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
2021-02-15 02:40:17 +13:00
|
|
|
"strings"
|
2021-01-20 09:01:31 +13:00
|
|
|
"time"
|
2021-01-11 03:55:29 +13:00
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/kataras/go-events"
|
|
|
|
)
|
|
|
|
|
|
|
|
var emmiter events.EventEmmiter
|
2021-01-20 09:01:31 +13:00
|
|
|
var file_chooser_dialog_window uint32 = 0
|
2021-01-11 03:55:29 +13:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
emmiter = events.New()
|
|
|
|
}
|
|
|
|
|
|
|
|
func EventLoop(display string) {
|
|
|
|
displayUnsafe := C.CString(display)
|
|
|
|
defer C.free(unsafe.Pointer(displayUnsafe))
|
|
|
|
|
|
|
|
C.XEventLoop(displayUnsafe)
|
|
|
|
}
|
|
|
|
|
|
|
|
func OnCursorChanged(listener func(serial uint64)) {
|
|
|
|
emmiter.On("cursor-changed", func(payload ...interface{}) {
|
|
|
|
listener(payload[0].(uint64))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-12 03:30:53 +13:00
|
|
|
func OnClipboardUpdated(listener func()) {
|
|
|
|
emmiter.On("clipboard-updated", func(payload ...interface{}) {
|
|
|
|
listener()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-20 09:01:31 +13:00
|
|
|
func OnFileChooserDialogOpened(listener func()) {
|
|
|
|
emmiter.On("file-chooser-dialog-opened", func(payload ...interface{}) {
|
|
|
|
listener()
|
2021-01-12 12:09:43 +13:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-20 09:01:31 +13:00
|
|
|
func OnFileChooserDialogClosed(listener func()) {
|
|
|
|
emmiter.On("file-chooser-dialog-closed", func(payload ...interface{}) {
|
|
|
|
listener()
|
2021-01-19 09:40:57 +13:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-11 03:55:29 +13:00
|
|
|
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
|
|
|
|
func goXEventCursorChanged(event C.XFixesCursorNotifyEvent) {
|
|
|
|
emmiter.Emit("cursor-changed", uint64(event.cursor_serial))
|
|
|
|
}
|
|
|
|
|
2021-01-12 03:30:53 +13:00
|
|
|
//export goXEventClipboardUpdated
|
|
|
|
func goXEventClipboardUpdated() {
|
|
|
|
emmiter.Emit("clipboard-updated")
|
|
|
|
}
|
|
|
|
|
2021-01-20 09:01:31 +13:00
|
|
|
//export goXEventConfigureNotify
|
2021-02-01 03:01:46 +13:00
|
|
|
func goXEventConfigureNotify(display *C.Display, window C.Window, name *C.char, role *C.char) {
|
|
|
|
if C.GoString(role) != "GtkFileChooserDialog" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Refactor. Right now processing of this dialog relies on identifying
|
|
|
|
// via its name. When that changes to role, this condition should be removed.
|
|
|
|
if !strings.HasPrefix(C.GoString(name), "Open File") {
|
2021-01-20 09:01:31 +13:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
C.XFileChooserHide(display, window)
|
|
|
|
|
|
|
|
// Because first dialog is not put properly to background
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
C.XFileChooserHide(display, window)
|
2021-01-21 11:47:49 +13:00
|
|
|
|
|
|
|
if file_chooser_dialog_window == 0 {
|
|
|
|
file_chooser_dialog_window = uint32(window)
|
|
|
|
emmiter.Emit("file-chooser-dialog-opened")
|
|
|
|
}
|
2021-01-19 09:40:57 +13:00
|
|
|
}
|
|
|
|
|
2021-01-20 09:01:31 +13:00
|
|
|
//export goXEventUnmapNotify
|
|
|
|
func goXEventUnmapNotify(window C.Window) {
|
|
|
|
if uint32(window) != file_chooser_dialog_window {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-21 11:47:49 +13:00
|
|
|
file_chooser_dialog_window = 0
|
2021-01-20 09:01:31 +13:00
|
|
|
emmiter.Emit("file-chooser-dialog-closed")
|
2021-01-12 12:09:43 +13:00
|
|
|
}
|
|
|
|
|
2021-01-11 03:55:29 +13:00
|
|
|
//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))
|
|
|
|
}
|
|
|
|
|
|
|
|
//export goXEventActive
|
|
|
|
func goXEventActive() C.int {
|
|
|
|
return C.int(1)
|
|
|
|
}
|