2021-01-11 03:55:29 +13:00
|
|
|
package xevent
|
|
|
|
|
|
|
|
/*
|
2021-06-29 04:10:48 +12:00
|
|
|
#cgo 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-11 03:55:29 +13:00
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/kataras/go-events"
|
|
|
|
)
|
|
|
|
|
2021-03-01 05:22:55 +13:00
|
|
|
var Emmiter events.EventEmmiter
|
2023-04-23 03:06:35 +12:00
|
|
|
var Unminimize bool = false
|
2023-11-24 22:39:09 +13:00
|
|
|
var FileChooserDialog bool = false
|
|
|
|
var fileChooserDialogWindow uint32 = 0
|
2021-01-11 03:55:29 +13:00
|
|
|
|
|
|
|
func init() {
|
2021-03-01 05:22:55 +13:00
|
|
|
Emmiter = events.New()
|
2021-01-11 03:55:29 +13:00
|
|
|
}
|
|
|
|
|
2024-03-28 09:38:33 +13:00
|
|
|
func SetupErrorHandler() {
|
|
|
|
C.XSetupErrorHandler()
|
|
|
|
}
|
|
|
|
|
2021-01-11 03:55:29 +13:00
|
|
|
func EventLoop(display string) {
|
|
|
|
displayUnsafe := C.CString(display)
|
|
|
|
defer C.free(unsafe.Pointer(displayUnsafe))
|
|
|
|
|
|
|
|
C.XEventLoop(displayUnsafe)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export goXEventCursorChanged
|
|
|
|
func goXEventCursorChanged(event C.XFixesCursorNotifyEvent) {
|
2021-03-01 05:22:55 +13:00
|
|
|
Emmiter.Emit("cursor-changed", uint64(event.cursor_serial))
|
2021-01-11 03:55:29 +13:00
|
|
|
}
|
|
|
|
|
2021-01-12 03:30:53 +13:00
|
|
|
//export goXEventClipboardUpdated
|
|
|
|
func goXEventClipboardUpdated() {
|
2021-03-01 05:22:55 +13:00
|
|
|
Emmiter.Emit("clipboard-updated")
|
2021-01-12 03:30:53 +13:00
|
|
|
}
|
|
|
|
|
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) {
|
2023-11-24 22:39:09 +13:00
|
|
|
if C.GoString(role) != "GtkFileChooserDialog" || !FileChooserDialog {
|
2021-02-01 03:01:46 +13:00
|
|
|
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)
|
|
|
|
|
2023-11-24 22:39:09 +13:00
|
|
|
if fileChooserDialogWindow == 0 {
|
|
|
|
fileChooserDialogWindow = uint32(window)
|
2021-03-01 05:22:55 +13:00
|
|
|
Emmiter.Emit("file-chooser-dialog-opened")
|
2021-01-21 11:47:49 +13:00
|
|
|
}
|
2021-01-19 09:40:57 +13:00
|
|
|
}
|
|
|
|
|
2021-01-20 09:01:31 +13:00
|
|
|
//export goXEventUnmapNotify
|
|
|
|
func goXEventUnmapNotify(window C.Window) {
|
2023-11-24 22:39:09 +13:00
|
|
|
if uint32(window) != fileChooserDialogWindow || !FileChooserDialog {
|
2021-01-20 09:01:31 +13:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-24 22:39:09 +13:00
|
|
|
fileChooserDialogWindow = 0
|
2021-03-01 05:22:55 +13:00
|
|
|
Emmiter.Emit("file-chooser-dialog-closed")
|
2021-01-12 12:09:43 +13:00
|
|
|
}
|
|
|
|
|
2023-04-23 03:06:35 +12:00
|
|
|
//export goXEventWMChangeState
|
|
|
|
func goXEventWMChangeState(display *C.Display, window C.Window, window_state C.ulong) {
|
|
|
|
// if we just realized that window is minimized and we want it to be unminimized
|
|
|
|
if window_state != C.NormalState && Unminimize {
|
|
|
|
// we want to unmap and map the window to force it to redraw
|
|
|
|
C.XUnmapWindow(display, window)
|
|
|
|
C.XMapWindow(display, window)
|
|
|
|
C.XFlush(display)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-11 03:55:29 +13:00
|
|
|
//export goXEventError
|
|
|
|
func goXEventError(event *C.XErrorEvent, message *C.char) {
|
2021-03-01 05:22:55 +13:00
|
|
|
Emmiter.Emit("event-error", uint8(event.error_code), C.GoString(message), uint8(event.request_code), uint8(event.minor_code))
|
2021-01-11 03:55:29 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//export goXEventActive
|
|
|
|
func goXEventActive() C.int {
|
|
|
|
return C.int(1)
|
|
|
|
}
|