Dont install event filter unless its registered

This commit is contained in:
Jonas Kvinge
2019-04-19 12:36:54 +02:00
parent 844c4a28f4
commit cf92852bb3
2 changed files with 12 additions and 3 deletions

View File

@@ -62,6 +62,7 @@ GlobalShortcut::GlobalShortcut(QKeySequence shortcut, GlobalShortcutBackend *bac
} }
GlobalShortcut::~GlobalShortcut() { GlobalShortcut::~GlobalShortcut() {
if (this == initialized_) { if (this == initialized_) {
QAbstractEventDispatcher::instance()->removeNativeEventFilter(this); QAbstractEventDispatcher::instance()->removeNativeEventFilter(this);
initialized_ = nullptr; initialized_ = nullptr;
@@ -69,6 +70,7 @@ GlobalShortcut::~GlobalShortcut() {
else { else {
unsetShortcut(); unsetShortcut();
} }
} }
bool GlobalShortcut::setShortcut(const QKeySequence &shortcut) { bool GlobalShortcut::setShortcut(const QKeySequence &shortcut) {

View File

@@ -32,15 +32,16 @@
#include "globalshortcutbackend.h" #include "globalshortcutbackend.h"
#include "globalshortcut.h" #include "globalshortcut.h"
GlobalShortcutBackendSystem::GlobalShortcutBackendSystem(GlobalShortcuts *parent) : GlobalShortcutBackend(parent), GlobalShortcutBackendSystem::GlobalShortcutBackendSystem(GlobalShortcuts *parent) : GlobalShortcutBackend(parent), gshortcut_init_(nullptr) {}
gshortcut_init_(new GlobalShortcut(this)) {}
GlobalShortcutBackendSystem::~GlobalShortcutBackendSystem(){} GlobalShortcutBackendSystem::~GlobalShortcutBackendSystem() { DoUnregister(); }
bool GlobalShortcutBackendSystem::DoRegister() { bool GlobalShortcutBackendSystem::DoRegister() {
qLog(Debug) << "Registering"; qLog(Debug) << "Registering";
if (!gshortcut_init_) gshortcut_init_ = new GlobalShortcut(this);
for (const GlobalShortcuts::Shortcut &shortcut : manager_->shortcuts().values()) { for (const GlobalShortcuts::Shortcut &shortcut : manager_->shortcuts().values()) {
AddShortcut(shortcut.action); AddShortcut(shortcut.action);
} }
@@ -63,8 +64,14 @@ bool GlobalShortcutBackendSystem::AddShortcut(QAction *action) {
void GlobalShortcutBackendSystem::DoUnregister() { void GlobalShortcutBackendSystem::DoUnregister() {
qLog(Debug) << "Unregistering"; qLog(Debug) << "Unregistering";
qDeleteAll(shortcuts_); qDeleteAll(shortcuts_);
shortcuts_.clear(); shortcuts_.clear();
if (gshortcut_init_) {
delete gshortcut_init_;
gshortcut_init_ = nullptr;
}
} }