add OnWindowConfigured.

This commit is contained in:
Miroslav Šedivý 2021-01-18 21:40:57 +01:00
parent bd062d3949
commit 54760551f7
5 changed files with 44 additions and 14 deletions

View File

@ -16,6 +16,10 @@ func (manager *DesktopManagerCtx) OnWindowCreated(listener func(window uint32, n
xevent.OnWindowCreated(listener) xevent.OnWindowCreated(listener)
} }
func (manager *DesktopManagerCtx) OnWindowConfigured(listener func(window uint32, name string, role string)) {
xevent.OnWindowConfigured(listener)
}
func (manager *DesktopManagerCtx) OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) { func (manager *DesktopManagerCtx) OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) {
xevent.OnEventError(listener) xevent.OnEventError(listener)
} }

View File

@ -23,8 +23,8 @@ void XEventLoop(char *name) {
return; return;
} }
Atom XA_CLIPBOARD; Atom WM_WINDOW_ROLE = XInternAtom(display, "WM_WINDOW_ROLE", 1);
XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0); Atom XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0);
XFixesSelectSelectionInput(display, root, XA_CLIPBOARD, XFixesSetSelectionOwnerNotifyMask); XFixesSelectSelectionInput(display, root, XA_CLIPBOARD, XFixesSetSelectionOwnerNotifyMask);
XFixesSelectCursorInput(display, root, XFixesDisplayCursorNotifyMask); XFixesSelectCursorInput(display, root, XFixesDisplayCursorNotifyMask);
XSelectInput(display, root, SubstructureNotifyMask); XSelectInput(display, root, SubstructureNotifyMask);
@ -54,18 +54,32 @@ void XEventLoop(char *name) {
} }
} }
// XFixesSelectionNotifyEvent // CreateNotify
if (event.type == CreateNotify) { if (event.type == CreateNotify) {
Window window = event.xcreatewindow.window;
char *name; char *name;
XFetchName(display, event.xcreatewindow.window, &name); XFetchName(display, window, &name);
char *role; XTextProperty role;
XTextProperty text_data; XGetTextProperty(display, window, &role, WM_WINDOW_ROLE);
Atom atom = XInternAtom(display, "WM_WINDOW_ROLE", True);
int status = XGetTextProperty(display, event.xcreatewindow.window, &text_data, atom);
role = (char *)text_data.value;
goXEventWindowCreated(event.xcreatewindow, name, role); goXEventWindowCreated(window, name, role.value);
XFree(name);
continue;
}
// ConfigureNotify
if (event.type == ConfigureNotify) {
Window window = event.xconfigure.window;
char *name;
XFetchName(display, window, &name);
XTextProperty role;
XGetTextProperty(display, window, &role, WM_WINDOW_ROLE);
goXEventWindowConfigured(window, name, role.value);
XFree(name); XFree(name);
continue; continue;
} }

View File

@ -44,6 +44,12 @@ func OnWindowCreated(listener func(window uint32, name string, role string)) {
}) })
} }
func OnWindowConfigured(listener func(window uint32, name string, role string)) {
emmiter.On("window-configured", func(payload ...interface{}) {
listener(payload[0].(uint32), payload[1].(string), payload[2].(string))
})
}
func OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) { func OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) {
emmiter.On("event-error", func(payload ...interface{}) { emmiter.On("event-error", func(payload ...interface{}) {
listener(payload[0].(uint8), payload[1].(string), payload[2].(uint8), payload[3].(uint8)) listener(payload[0].(uint8), payload[1].(string), payload[2].(uint8), payload[3].(uint8))
@ -61,8 +67,13 @@ func goXEventClipboardUpdated() {
} }
//export goXEventWindowCreated //export goXEventWindowCreated
func goXEventWindowCreated(event C.XCreateWindowEvent, name *C.char, role *C.char) { func goXEventWindowCreated(window C.Window, name *C.char, role *C.char) {
emmiter.Emit("window-created", uint32(event.window), C.GoString(name), C.GoString(role)) emmiter.Emit("window-created", uint32(window), C.GoString(name), C.GoString(role))
}
//export goXEventWindowConfigured
func goXEventWindowConfigured(window C.Window, name *C.char, role *C.char) {
emmiter.Emit("window-configured", uint32(window), C.GoString(name), C.GoString(role))
} }
//export goXEventError //export goXEventError

View File

@ -8,10 +8,10 @@
extern void goXEventCursorChanged(XFixesCursorNotifyEvent event); extern void goXEventCursorChanged(XFixesCursorNotifyEvent event);
extern void goXEventClipboardUpdated(); extern void goXEventClipboardUpdated();
extern void goXEventWindowCreated(XCreateWindowEvent event, char *name, char *role); extern void goXEventWindowCreated(Window window, char *name, char *role);
extern void goXEventWindowConfigured(Window window, char *name, char *role);
extern void goXEventError(XErrorEvent *event, char *message); extern void goXEventError(XErrorEvent *event, char *message);
extern int goXEventActive(); extern int goXEventActive();
static int XEventError(Display *display, XErrorEvent *event); static int XEventError(Display *display, XErrorEvent *event);
void XEventLoop(char *display); void XEventLoop(char *display);

View File

@ -58,6 +58,7 @@ type DesktopManager interface {
OnCursorChanged(listener func(serial uint64)) OnCursorChanged(listener func(serial uint64))
OnClipboardUpdated(listener func()) OnClipboardUpdated(listener func())
OnWindowCreated(listener func(window uint32, name string, role string)) OnWindowCreated(listener func(window uint32, name string, role string))
OnWindowConfigured(listener func(window uint32, name string, role string))
OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8)) OnEventError(listener func(error_code uint8, message string, request_code uint8, minor_code uint8))
// clipboard // clipboard