From 88a4d2fb49bc37794a14b7d86b90d515f472d372 Mon Sep 17 00:00:00 2001 From: Palo Kisa Date: Wed, 27 Apr 2022 08:32:54 +0200 Subject: [PATCH] dialog: Listen to KwindowSystem signals only when shown Most of the time the runner window is not shown and we don't need to be notified about all the focus/desktop changes. --- dialog.cpp | 25 ++++++++++++++++++++++--- dialog.h | 2 ++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/dialog.cpp b/dialog.cpp index 5667817..0b9a0e9 100644 --- a/dialog.cpp +++ b/dialog.cpp @@ -133,8 +133,6 @@ Dialog::Dialog(QWidget *parent) : connect(mGlobalShortcut, &GlobalKeyShortcut::Action::activated, this, &Dialog::showHide); connect(mGlobalShortcut, &GlobalKeyShortcut::Action::shortcutChanged, this, &Dialog::shortcutChanged); - connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &Dialog::onActiveWindowChanged); - connect(KWindowSystem::self(), &KWindowSystem::currentDesktopChanged, this, &Dialog::onCurrentDesktopChanged); resize(mSettings->value(QL1S("dialog/width"), 400).toInt(), size().height()); @@ -197,6 +195,28 @@ void Dialog::moveEvent(QMoveEvent *event) } +/************************************************ + + ************************************************/ +void Dialog::showEvent(QShowEvent *event) +{ + connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &Dialog::onActiveWindowChanged); + connect(KWindowSystem::self(), &KWindowSystem::currentDesktopChanged, this, &Dialog::onCurrentDesktopChanged); + return QDialog::showEvent(event); +} + + +/************************************************ + + ************************************************/ +void Dialog::hideEvent(QHideEvent *event) +{ + QDialog::hideEvent(event); + disconnect(KWindowSystem::self(), &KWindowSystem::currentDesktopChanged, this, &Dialog::onCurrentDesktopChanged); + disconnect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &Dialog::onActiveWindowChanged); +} + + /************************************************ ************************************************/ @@ -397,7 +417,6 @@ void Dialog::applySettings() mCommandItemModel->showHistoryFirst(mSettings->value(QL1S("dialog/history_first"), true).toBool()); ui->commandList->setShownCount(mSettings->value(QL1S("dialog/list_shown_items"), 4).toInt()); - realign(); mSettings->sync(); } diff --git a/dialog.h b/dialog.h index a71dd3d..8b7b36f 100644 --- a/dialog.h +++ b/dialog.h @@ -65,6 +65,8 @@ class Dialog : public QDialog void closeEvent(QCloseEvent *event); void resizeEvent(QResizeEvent *event); void moveEvent(QMoveEvent *event); + void showEvent(QShowEvent *event); + void hideEvent(QHideEvent *event); bool eventFilter(QObject *object, QEvent *event); bool editKeyPressEvent(QKeyEvent *event); bool listKeyPressEvent(QKeyEvent *event);