xevent: OnWindowCreated.

This commit is contained in:
Miroslav Šedivý 2021-01-12 00:09:43 +01:00
parent 94a9c7c10a
commit 49c3b6d4fe
6 changed files with 44 additions and 0 deletions

View File

@ -12,6 +12,10 @@ func (manager *DesktopManagerCtx) OnClipboardUpdated(listener func()) {
xevent.OnClipboardUpdated(listener) xevent.OnClipboardUpdated(listener)
} }
func (manager *DesktopManagerCtx) OnWindowCreated(listener func(window uint32, name string, role string)) {
xevent.OnWindowCreated(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

@ -27,6 +27,7 @@ void XEventLoop(char *name) {
XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0); 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);
XSync(display, 0); XSync(display, 0);
XSetErrorHandler(XEventError); XSetErrorHandler(XEventError);
@ -52,6 +53,22 @@ void XEventLoop(char *name) {
continue; continue;
} }
} }
// XFixesSelectionNotifyEvent
if (event.type == CreateNotify) {
char *name;
XFetchName(display, event.xcreatewindow.window, &name);
char *role;
XTextProperty text_data;
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);
XFree(name);
continue;
}
} }
XCloseDisplay(display); XCloseDisplay(display);

View File

@ -38,6 +38,12 @@ func OnClipboardUpdated(listener func()) {
}) })
} }
func OnWindowCreated(listener func(window uint32, name string, role string)) {
emmiter.On("window-created", 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))
@ -54,6 +60,11 @@ func goXEventClipboardUpdated() {
emmiter.Emit("clipboard-updated") emmiter.Emit("clipboard-updated")
} }
//export goXEventWindowCreated
func goXEventWindowCreated(event C.XCreateWindowEvent, name *C.char, role *C.char) {
emmiter.Emit("window-created", uint32(event.window), C.GoString(name), C.GoString(role))
}
//export goXEventError //export goXEventError
func goXEventError(event *C.XErrorEvent, message *C.char) { 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)) 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 #pragma once
#include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/extensions/Xfixes.h> #include <X11/extensions/Xfixes.h>
@ -7,6 +8,7 @@
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 goXEventError(XErrorEvent *event, char *message); extern void goXEventError(XErrorEvent *event, char *message);
extern int goXEventActive(); extern int goXEventActive();

View File

@ -45,6 +45,7 @@ type DesktopManager interface {
// xevent // xevent
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))
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

View File

@ -133,6 +133,15 @@ func (ws *WebSocketManagerCtx) Start() {
ws.logger.Warn().Err(err).Msg("could not sync clipboard") ws.logger.Warn().Err(err).Msg("could not sync clipboard")
} }
}) })
ws.desktop.OnWindowCreated(func(window uint32, name string, role string) {
// TODO: Implement.
ws.logger.Info().
Uint32("window", window).
Str("name", name).
Str("role", role).
Msg("created new window")
})
} }
func (ws *WebSocketManagerCtx) Shutdown() error { func (ws *WebSocketManagerCtx) Shutdown() error {