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

79 lines
1.6 KiB
Go
Raw Permalink 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-29 10:08:36 +13:00
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
2023-01-30 05:51:39 +13:00
var ClipboardUpdatedChannel chan struct{}
2023-01-22 11:43:04 +13:00
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)
2023-01-30 05:51:39 +13:00
ClipboardUpdatedChannel = make(chan struct{})
2023-01-22 11:43:04 +13:00
EventErrorChannel = make(chan types.DesktopErrorMessage)
go func() {
for {
2023-01-30 05:51:39 +13:00
// TODO: Reserved for future use.
2023-01-29 10:08:36 +13:00
<-CursorChangedChannel
2023-01-22 11:43:04 +13:00
}
}()
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)
}
2023-01-30 05:51:39 +13:00
// TODO: Shutdown function.
//close(CursorChangedChannel)
//close(ClipboardUpdatedChannel)
//close(EventErrorChannel)
2022-09-16 09:55:30 +12:00
//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-30 05:51:39 +13:00
ClipboardUpdatedChannel <- struct{}{}
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-29 10:08:36 +13:00
EventErrorChannel <- types.DesktopErrorMessage{
Error_code: uint8(event.error_code),
Message: C.GoString(message),
Request_code: uint8(event.request_code),
Minor_code: uint8(event.minor_code),
}
2022-09-16 09:55:30 +12:00
}
//export goXEventActive
func goXEventActive() C.int {
return C.int(1)
}