on xenial help sign in
Fixed shortcuts parented to non QuickItems
e1ba4b7Nick Dedekind
plugins/GlobalShortcut/globalshortcutregistry.cpp+19−2
@@ -21,6 +21,20 @@
21
21
22#include "globalshortcutregistry.h"
22#include "globalshortcutregistry.h"
23
23
24+namespace {
25+QWindow* windowForShortcut(GlobalShortcut *sc) {
26+ QObject* parent= sc;
27+ while(parent) {
28+ if (auto item = qobject_cast<QQuickItem*>(parent)) {
29+ auto window = item->window();
30+ if (window) return window;
31+ }
32+ parent = parent->parent();
33+ }
34+ return nullptr;
35+}
36+} // namespace
37+
24GlobalShortcutRegistry::GlobalShortcutRegistry(QObject *parent)
38GlobalShortcutRegistry::GlobalShortcutRegistry(QObject *parent)
25 : QObject(parent)
39 : QObject(parent)
26{
40{
@@ -90,8 +104,11 @@ bool GlobalShortcutRegistry::eventFilter(QObject *obj, QEvent *event)
90 if (m_shortcuts.contains(seq)) {
104 if (m_shortcuts.contains(seq)) {
91 const auto shortcuts = m_shortcuts.value(seq);
105 const auto shortcuts = m_shortcuts.value(seq);
92 Q_FOREACH(const auto &shortcut, shortcuts) {
106 Q_FOREACH(const auto &shortcut, shortcuts) {
93− if (shortcut && shortcut->window() == obj) {
107+ if (shortcut) {
108+ auto window = windowForShortcut(shortcut);
109+ if (!window || window == obj) { // accept shortcut if it's not attached to a window or it's window is active.
94− qApp->sendEvent(shortcut, &eCopy);
110+ qApp->sendEvent(shortcut, &eCopy);
111+ }
95 }
112 }
96 }
113 }
97 }
114 }