@@ -21,11 +21,11 @@
2121
2222#include "globalshortcutregistry.h"
2323
24−static qulonglong s_windowId = 0;
25−
2624GlobalShortcutRegistry::GlobalShortcutRegistry(QObject *parent)
2725 : QObject(parent)
2826{
27+ connect(qGuiApp, &QGuiApplication::focusWindowChanged, this, &GlobalShortcutRegistry::setupFilterOnWindow);
28+ setupFilterOnWindow(qGuiApp->focusWindow());
2929}
3030
3131GlobalShortcutList GlobalShortcutRegistry::shortcuts() const
@@ -90,7 +90,7 @@ bool GlobalShortcutRegistry::eventFilter(QObject *obj, QEvent *event)
9090 if (m_shortcuts.contains(seq)) {
9191 const auto shortcuts = m_shortcuts.value(seq);
9292 Q_FOREACH(const auto &shortcut, shortcuts) {
93− if (shortcut) {
93+ if (shortcut && shortcut->window() == obj) {
9494 qApp->sendEvent(shortcut, &eCopy);
9595 }
9696 }
@@ -102,24 +102,15 @@ bool GlobalShortcutRegistry::eventFilter(QObject *obj, QEvent *event)
102102 return QObject::eventFilter(obj, event);
103103}
104104
105−void GlobalShortcutRegistry::setupFilterOnWindow(qulonglong wid)
105+void GlobalShortcutRegistry::setupFilterOnWindow(QWindow* window)
106106{
107− if (wid == s_windowId) {
108− return;
109− }
110−
111107 if (m_filteredWindow) {
112108 m_filteredWindow->removeEventFilter(this);
113109 m_filteredWindow.clear();
114− s_windowId = 0;
115110 }
116111
117− Q_FOREACH(QWindow *window, qApp->allWindows()) {
118− if (window && window->winId() == wid) {
119− m_filteredWindow = window;
120− window->installEventFilter(this);
121− s_windowId = wid;
122− break;
123− }
112+ if (window) {
113+ m_filteredWindow = window;
114+ window->installEventFilter(this);
124115 }
125116}