Skip to content

Commit

Permalink
mainmenu: Fix close menu by "weird" shortcut
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
palinek committed Oct 30, 2015
1 parent 52d2f72 commit acc90ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
24 changes: 4 additions & 20 deletions plugin-mainmenu/lxqtmainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });
}
}

Expand All @@ -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);

}
}


/************************************************
************************************************/
Expand Down Expand Up @@ -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<QKeyEvent*>(event);
if(mShortcutSeq == QKeySequence(keyEvent->modifiers() + keyEvent->key()))
if (keyEvent->modifiers() & ~Qt::ShiftModifier)
{
mHideTimer.start();
mMenu->hide(); // close the app menu
return true;
}
Expand Down
2 changes: 0 additions & 2 deletions plugin-mainmenu/lxqtmainmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class LXQtMainMenu : public QObject, public ILXQtPanelPlugin

QTimer mDelayedPopup;
QTimer mHideTimer;
QKeySequence mShortcutSeq;
QString mMenuFile;

protected slots:
Expand All @@ -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
Expand Down

0 comments on commit acc90ef

Please sign in to comment.