From 54760551f723f2a3898a0f4395faa28eafbfd116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 18 Jan 2021 21:40:57 +0100 Subject: [PATCH] add OnWindowConfigured. --- internal/desktop/xevent.go | 4 ++++ internal/desktop/xevent/xevent.c | 34 ++++++++++++++++++++++--------- internal/desktop/xevent/xevent.go | 15 ++++++++++++-- internal/desktop/xevent/xevent.h | 4 ++-- internal/types/desktop.go | 1 + 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/internal/desktop/xevent.go b/internal/desktop/xevent.go index f59f2025..6f605fb1 100644 --- a/internal/desktop/xevent.go +++ b/internal/desktop/xevent.go @@ -16,6 +16,10 @@ func (manager *DesktopManagerCtx) OnWindowCreated(listener func(window uint32, n 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)) { xevent.OnEventError(listener) } diff --git a/internal/desktop/xevent/xevent.c b/internal/desktop/xevent/xevent.c index f7d9e870..36aaa40e 100644 --- a/internal/desktop/xevent/xevent.c +++ b/internal/desktop/xevent/xevent.c @@ -23,8 +23,8 @@ void XEventLoop(char *name) { return; } - Atom XA_CLIPBOARD; - XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0); + Atom WM_WINDOW_ROLE = XInternAtom(display, "WM_WINDOW_ROLE", 1); + Atom XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0); XFixesSelectSelectionInput(display, root, XA_CLIPBOARD, XFixesSetSelectionOwnerNotifyMask); XFixesSelectCursorInput(display, root, XFixesDisplayCursorNotifyMask); XSelectInput(display, root, SubstructureNotifyMask); @@ -54,18 +54,32 @@ void XEventLoop(char *name) { } } - // XFixesSelectionNotifyEvent + // CreateNotify if (event.type == CreateNotify) { + Window window = event.xcreatewindow.window; + char *name; - XFetchName(display, event.xcreatewindow.window, &name); + XFetchName(display, 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; + XTextProperty role; + XGetTextProperty(display, window, &role, WM_WINDOW_ROLE); - 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); continue; } diff --git a/internal/desktop/xevent/xevent.go b/internal/desktop/xevent/xevent.go index 467baa14..d6b32548 100644 --- a/internal/desktop/xevent/xevent.go +++ b/internal/desktop/xevent/xevent.go @@ -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)) { emmiter.On("event-error", func(payload ...interface{}) { listener(payload[0].(uint8), payload[1].(string), payload[2].(uint8), payload[3].(uint8)) @@ -61,8 +67,13 @@ func goXEventClipboardUpdated() { } //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)) +func goXEventWindowCreated(window C.Window, name *C.char, role *C.char) { + 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 diff --git a/internal/desktop/xevent/xevent.h b/internal/desktop/xevent/xevent.h index 24ee7160..9314fc70 100644 --- a/internal/desktop/xevent/xevent.h +++ b/internal/desktop/xevent/xevent.h @@ -8,10 +8,10 @@ extern void goXEventCursorChanged(XFixesCursorNotifyEvent event); 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 int goXEventActive(); static int XEventError(Display *display, XErrorEvent *event); void XEventLoop(char *display); - diff --git a/internal/types/desktop.go b/internal/types/desktop.go index 50333d20..9ec70e8b 100644 --- a/internal/types/desktop.go +++ b/internal/types/desktop.go @@ -58,6 +58,7 @@ type DesktopManager interface { OnCursorChanged(listener func(serial uint64)) OnClipboardUpdated(listener func()) 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)) // clipboard