From c63e3533f4fa3888635980be24d391f9cbfe893d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 11 Apr 2014 08:06:26 +0200 Subject: [PATCH] Get Toplevel::resourceName() and ::resourceClass() from NETWinInfo It's provided by the NETWinInfo, no need to keep an own implementation. To keep compatibility with existing KWin code using the window class or resource it's always converted to lower. In addition a notify signal Toplevel::windowClassChanged is added and emitted from the event handler whenever the WM2WindowClass property is set. REVIEW: 117496 --- events.cpp | 6 ++++++ manage.cpp | 1 + toplevel.cpp | 14 +++----------- toplevel.h | 9 +++++++-- unmanaged.cpp | 5 ++++- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/events.cpp b/events.cpp index 43ef8176e8..013ee52456 100644 --- a/events.cpp +++ b/events.cpp @@ -523,6 +523,9 @@ bool Client::windowEvent(xcb_generic_event_t *e) if (dirtyProperties2.testFlag(NET::WM2WindowRole)) { emit windowRoleChanged(); } + if (dirtyProperties2.testFlag(NET::WM2WindowClass)) { + getResourceClass(); + } } const uint8_t eventType = e->response_type & ~0x80; @@ -1508,6 +1511,9 @@ bool Unmanaged::windowEvent(xcb_generic_event_t *e) if (dirtyProperties2.testFlag(NET::WM2WindowRole)) { emit windowRoleChanged(); } + if (dirtyProperties2.testFlag(NET::WM2WindowClass)) { + getResourceClass(); + } const uint8_t eventType = e->response_type & ~0x80; switch (eventType) { case XCB_UNMAP_NOTIFY: diff --git a/manage.cpp b/manage.cpp index 393b826549..b903e48793 100644 --- a/manage.cpp +++ b/manage.cpp @@ -91,6 +91,7 @@ bool Client::manage(xcb_window_t w, bool isMapped) NET::WMPid | NET::WMIconName; const NET::Properties2 properties2 = + NET::WM2WindowClass | NET::WM2WindowRole | NET::WM2UserTime | NET::WM2StartupId | diff --git a/toplevel.cpp b/toplevel.cpp index 4cda621adc..a945757a87 100644 --- a/toplevel.cpp +++ b/toplevel.cpp @@ -224,17 +224,9 @@ Window Toplevel::wmClientLeader() const void Toplevel::getResourceClass() { - XClassHint classHint; - if (XGetClassHint(display(), window(), &classHint)) { - // Qt3.2 and older had this all lowercase, Qt3.3 capitalized resource class. - // Force lowercase, so that workarounds listing resource classes still work. - resource_name = QByteArray(classHint.res_name).toLower(); - resource_class = QByteArray(classHint.res_class).toLower(); - XFree(classHint.res_name); - XFree(classHint.res_class); - } else { - resource_name = resource_class = QByteArray(); - } + resource_name = QByteArray(info->windowClassName()).toLower(); + resource_class = QByteArray(info->windowClassClass()).toLower(); + emit windowClassChanged(); } double Toplevel::opacity() const diff --git a/toplevel.h b/toplevel.h index 20257f88d0..8fe138975b 100644 --- a/toplevel.h +++ b/toplevel.h @@ -73,8 +73,8 @@ class Toplevel Q_PROPERTY(QRect rect READ rect) Q_PROPERTY(QPoint clientPos READ clientPos) Q_PROPERTY(QSize clientSize READ clientSize) - Q_PROPERTY(QByteArray resourceName READ resourceName) - Q_PROPERTY(QByteArray resourceClass READ resourceClass) + Q_PROPERTY(QByteArray resourceName READ resourceName NOTIFY windowClassChanged) + Q_PROPERTY(QByteArray resourceClass READ resourceClass NOTIFY windowClassChanged) Q_PROPERTY(QByteArray windowRole READ windowRole NOTIFY windowRoleChanged) /** * Returns whether the window is a desktop background window (the one with wallpaper). @@ -372,6 +372,11 @@ Q_SIGNALS: * @since 5.0 **/ void windowRoleChanged(); + /** + * Emitted whenever the window class name or resource name of the window changes. + * @since 5.0 + **/ + void windowClassChanged(); protected Q_SLOTS: /** diff --git a/unmanaged.cpp b/unmanaged.cpp index e0e757914f..db5ab7c5bf 100644 --- a/unmanaged.cpp +++ b/unmanaged.cpp @@ -65,7 +65,10 @@ bool Unmanaged::track(Window w) vis = attr.visual; bit_depth = attr.depth; info = new NETWinInfo(connection(), w, rootWindow(), - NET::WMWindowType | NET::WMPid, NET::WM2Opacity | NET::WM2WindowRole); + NET::WMWindowType | NET::WMPid, + NET::WM2Opacity | + NET::WM2WindowRole | + NET::WM2WindowClass); getResourceClass(); getWmClientLeader(); getWmClientMachine();