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() {
if (this == initialized_) {
QAbstractEventDispatcher::instance()->removeNativeEventFilter(this);
initialized_ = nullptr;
@ -69,6 +70,7 @@ GlobalShortcut::~GlobalShortcut() {
else {
unsetShortcut();
}
}
bool GlobalShortcut::setShortcut(const QKeySequence &shortcut) {

View File

@ -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;
}
}