mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
xevent: OnWindowCreated.
This commit is contained in:
parent
94a9c7c10a
commit
49c3b6d4fe
@ -12,6 +12,10 @@ func (manager *DesktopManagerCtx) OnClipboardUpdated(listener func()) {
|
||||
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)) {
|
||||
xevent.OnEventError(listener)
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ void XEventLoop(char *name) {
|
||||
XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0);
|
||||
XFixesSelectSelectionInput(display, root, XA_CLIPBOARD, XFixesSetSelectionOwnerNotifyMask);
|
||||
XFixesSelectCursorInput(display, root, XFixesDisplayCursorNotifyMask);
|
||||
XSelectInput(display, root, SubstructureNotifyMask);
|
||||
|
||||
XSync(display, 0);
|
||||
XSetErrorHandler(XEventError);
|
||||
@ -52,6 +53,22 @@ void XEventLoop(char *name) {
|
||||
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);
|
||||
|
@ -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)) {
|
||||
emmiter.On("event-error", func(payload ...interface{}) {
|
||||
listener(payload[0].(uint8), payload[1].(string), payload[2].(uint8), payload[3].(uint8))
|
||||
@ -54,6 +60,11 @@ func goXEventClipboardUpdated() {
|
||||
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
|
||||
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))
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/Xfixes.h>
|
||||
@ -7,6 +8,7 @@
|
||||
|
||||
extern void goXEventCursorChanged(XFixesCursorNotifyEvent event);
|
||||
extern void goXEventClipboardUpdated();
|
||||
extern void goXEventWindowCreated(XCreateWindowEvent event, char *name, char *role);
|
||||
extern void goXEventError(XErrorEvent *event, char *message);
|
||||
extern int goXEventActive();
|
||||
|
||||
|
@ -45,6 +45,7 @@ type DesktopManager interface {
|
||||
// xevent
|
||||
OnCursorChanged(listener func(serial uint64))
|
||||
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))
|
||||
|
||||
// clipboard
|
||||
|
@ -133,6 +133,15 @@ func (ws *WebSocketManagerCtx) Start() {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user