Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/server/internal/desktop/xevent/xevent.go

82 lines
1.8 KiB
Go
Raw Normal View History

2022-09-16 09:55:30 +12:00
package xevent
/*
#cgo LDFLAGS: -lX11 -lXfixes
#include "xevent.h"
*/
import "C"
import (
"unsafe"
2023-01-22 11:43:04 +13:00
"m1k1o/neko/internal/types"
2022-09-16 09:55:30 +12:00
)
2023-01-22 11:43:04 +13:00
var CursorChangedChannel chan uint64
var ClipboardUpdatedChannel chan bool
var FileChooserDialogClosedChannel chan bool
var FileChooserDialogOpenedChannel chan bool
var EventErrorChannel chan types.DesktopErrorMessage
2022-09-16 09:55:30 +12:00
func init() {
2023-01-22 11:43:04 +13:00
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
}
}()
2022-09-16 09:55:30 +12: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) {
2023-01-22 11:43:04 +13:00
CursorChangedChannel <- uint64(event.cursor_serial)
2022-09-16 09:55:30 +12:00
}
//export goXEventClipboardUpdated
func goXEventClipboardUpdated() {
2023-01-22 11:43:04 +13:00
ClipboardUpdatedChannel <- true
2022-09-16 09:55:30 +12:00
}
//export goXEventConfigureNotify
func goXEventConfigureNotify(display *C.Display, window C.Window, name *C.char, role *C.char) {
2022-11-21 02:12:08 +13:00
2022-09-16 09:55:30 +12:00
}
//export goXEventUnmapNotify
func goXEventUnmapNotify(window C.Window) {
}
//export goXEventError
func goXEventError(event *C.XErrorEvent, message *C.char) {
2023-01-22 11:43:04 +13:00
EventErrorChannel <- types.DesktopErrorMessage{ uint8(event.error_code), C.GoString(message), uint8(event.request_code), uint8(event.minor_code) }
2022-09-16 09:55:30 +12:00
}
//export goXEventActive
func goXEventActive() C.int {
return C.int(1)
}