From cf92852bb3a4fb5a99830bf6ca21f8da3f853740 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Fri, 19 Apr 2019 12:36:54 +0200 Subject: [PATCH] Dont install event filter unless its registered --- src/globalshortcuts/globalshortcut.cpp | 2 ++ .../globalshortcutbackend-system.cpp | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/globalshortcuts/globalshortcut.cpp b/src/globalshortcuts/globalshortcut.cpp index 838232496..24f7bb641 100644 --- a/src/globalshortcuts/globalshortcut.cpp +++ b/src/globalshortcuts/globalshortcut.cpp @@ -62,6 +62,7 @@ GlobalShortcut::GlobalShortcut(QKeySequence shortcut, GlobalShortcutBackend *bac } GlobalShortcut::~GlobalShortcut() { + if (this == initialized_) { QAbstractEventDispatcher::instance()->removeNativeEventFilter(this); initialized_ = nullptr; @@ -69,6 +70,7 @@ GlobalShortcut::~GlobalShortcut() { else { unsetShortcut(); } + } bool GlobalShortcut::setShortcut(const QKeySequence &shortcut) { diff --git a/src/globalshortcuts/globalshortcutbackend-system.cpp b/src/globalshortcuts/globalshortcutbackend-system.cpp index 4727f9b70..c72ff9444 100644 --- a/src/globalshortcuts/globalshortcutbackend-system.cpp +++ b/src/globalshortcuts/globalshortcutbackend-system.cpp @@ -32,15 +32,16 @@ #include "globalshortcutbackend.h" #include "globalshortcut.h" -GlobalShortcutBackendSystem::GlobalShortcutBackendSystem(GlobalShortcuts *parent) : GlobalShortcutBackend(parent), - gshortcut_init_(new GlobalShortcut(this)) {} +GlobalShortcutBackendSystem::GlobalShortcutBackendSystem(GlobalShortcuts *parent) : GlobalShortcutBackend(parent), gshortcut_init_(nullptr) {} -GlobalShortcutBackendSystem::~GlobalShortcutBackendSystem(){} +GlobalShortcutBackendSystem::~GlobalShortcutBackendSystem() { DoUnregister(); } bool GlobalShortcutBackendSystem::DoRegister() { qLog(Debug) << "Registering"; + if (!gshortcut_init_) gshortcut_init_ = new GlobalShortcut(this); + for (const GlobalShortcuts::Shortcut &shortcut : manager_->shortcuts().values()) { AddShortcut(shortcut.action); } @@ -63,8 +64,14 @@ bool GlobalShortcutBackendSystem::AddShortcut(QAction *action) { void GlobalShortcutBackendSystem::DoUnregister() { qLog(Debug) << "Unregistering"; + qDeleteAll(shortcuts_); shortcuts_.clear(); + if (gshortcut_init_) { + delete gshortcut_init_; + gshortcut_init_ = nullptr; + } + }