xevent to update clipboard.

This commit is contained in:
Miroslav Šedivý
2021-01-11 15:30:53 +01:00
parent 910f0af995
commit a2ca3727fe
6 changed files with 46 additions and 42 deletions

View File

@ -8,6 +8,10 @@ func (manager *DesktopManagerCtx) OnCursorChanged(listener func(serial uint64))
xevent.OnCursorChanged(listener)
}
func (manager *DesktopManagerCtx) OnClipboardUpdated(listener func()) {
xevent.OnClipboardUpdated(listener)
}
func (manager *DesktopManagerCtx) OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) {
xevent.OnEventError(listener)
}

View File

@ -23,7 +23,11 @@ void XEventLoop(char *name) {
return;
}
Atom XA_CLIPBOARD;
XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0);
XFixesSelectSelectionInput(display, root, XA_CLIPBOARD, XFixesSetSelectionOwnerNotifyMask);
XFixesSelectCursorInput(display, root, XFixesDisplayCursorNotifyMask);
XSync(display, 0);
XSetErrorHandler(XEventError);
@ -39,6 +43,15 @@ void XEventLoop(char *name) {
continue;
}
}
// XFixesSelectionNotifyEvent
if (event.type == xfixes_event_base + XFixesSelectionNotify) {
XFixesSelectionNotifyEvent notifyEvent = *((XFixesSelectionNotifyEvent *) &event);
if (notifyEvent.subtype == XFixesSetSelectionOwnerNotify && notifyEvent.selection == XA_CLIPBOARD) {
goXEventClipboardUpdated();
continue;
}
}
}
XCloseDisplay(display);

View File

@ -33,6 +33,12 @@ func OnCursorChanged(listener func(serial uint64)) {
})
}
func OnClipboardUpdated(listener func()) {
emmiter.On("clipboard-updated", 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))
@ -44,6 +50,11 @@ func goXEventCursorChanged(event C.XFixesCursorNotifyEvent) {
emmiter.Emit("cursor-changed", uint64(event.cursor_serial))
}
//export goXEventClipboardUpdated
func goXEventClipboardUpdated() {
emmiter.Emit("clipboard-updated")
}
//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))

View File

@ -1,5 +1,6 @@
#pragma once
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h>
#include <stdint.h>
@ -7,6 +8,7 @@
#include <string.h>
extern void goXEventCursorChanged(XFixesCursorNotifyEvent event);
extern void goXEventClipboardUpdated();
extern void goXEventError(XErrorEvent *event, char *message);
extern int goXEventActive();