From acc90ef308a4e15a0ab72cb7a7403e41a9988b36 Mon Sep 17 00:00:00 2001 From: Palo Kisa Date: Tue, 27 Oct 2015 22:56:55 +0100 Subject: [PATCH] mainmenu: Fix close menu by "weird" shortcut Globalkeys uses not compatible string representation of shortcut (it's probably done by XKeysymToString) with QKeySequence. So we are not able to know if the shortcut sequence was pressed in event handling. We use a workaround and closing the menu after any "modifier" key pushed (this way also other QMenu objects behave) --- plugin-mainmenu/lxqtmainmenu.cpp | 24 ++++-------------------- plugin-mainmenu/lxqtmainmenu.h | 2 -- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/plugin-mainmenu/lxqtmainmenu.cpp b/plugin-mainmenu/lxqtmainmenu.cpp index 43d505152..9673a4ff1 100644 --- a/plugin-mainmenu/lxqtmainmenu.cpp +++ b/plugin-mainmenu/lxqtmainmenu.cpp @@ -89,11 +89,8 @@ LXQtMainMenu::LXQtMainMenu(const ILXQtPanelPluginStartupInfo &startupInfo): connect(mShortcut, &GlobalKeyShortcut::Action::registrationFinished, [this] { if (mShortcut->shortcut().isEmpty()) mShortcut->changeShortcut(DEFAULT_SHORTCUT); - else - mShortcutSeq = QKeySequence(mShortcut->shortcut()); }); - connect(mShortcut, SIGNAL(activated()), &mDelayedPopup, SLOT(start())); - connect(mShortcut, SIGNAL(shortcutChanged(QString,QString)), this, SLOT(shortcutChanged(QString,QString))); + connect(mShortcut, &GlobalKeyShortcut::Action::activated, [this] { if (!mHideTimer.isActive()) mDelayedPopup.start(); }); } } @@ -119,26 +116,12 @@ LXQtMainMenu::~LXQtMainMenu() ************************************************/ void LXQtMainMenu::showHideMenu() { - - if (mMenu && (mMenu->isVisible() || mHideTimer.isActive())) + if (mMenu && mMenu->isVisible()) mMenu->hide(); else showMenu(); } -/************************************************ - - ************************************************/ -void LXQtMainMenu::shortcutChanged(const QString &/*oldShortcut*/, const QString &newShortcut) -{ - if (!newShortcut.isEmpty()) - { - mShortcutSeq = QKeySequence(newShortcut); - - } -} - - /************************************************ ************************************************/ @@ -322,8 +305,9 @@ bool LXQtMainMenu::eventFilter(QObject *obj, QEvent *event) { // if our shortcut key is pressed while the menu is open, close the menu QKeyEvent* keyEvent = static_cast(event); - if(mShortcutSeq == QKeySequence(keyEvent->modifiers() + keyEvent->key())) + if (keyEvent->modifiers() & ~Qt::ShiftModifier) { + mHideTimer.start(); mMenu->hide(); // close the app menu return true; } diff --git a/plugin-mainmenu/lxqtmainmenu.h b/plugin-mainmenu/lxqtmainmenu.h index 31e6ea9da..117cd9f99 100644 --- a/plugin-mainmenu/lxqtmainmenu.h +++ b/plugin-mainmenu/lxqtmainmenu.h @@ -97,7 +97,6 @@ class LXQtMainMenu : public QObject, public ILXQtPanelPlugin QTimer mDelayedPopup; QTimer mHideTimer; - QKeySequence mShortcutSeq; QString mMenuFile; protected slots: @@ -108,7 +107,6 @@ protected slots: private slots: void showMenu(); void showHideMenu(); - void shortcutChanged(const QString &oldShortcut, const QString &newShortcut); }; class LXQtMainMenuPluginLibrary: public QObject, public ILXQtPanelPluginLibrary