Skip to content

Commit

Permalink
Mainmenu: Use xfitman to force focus when menu raised via shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmas committed Feb 2, 2013
1 parent 43a283e commit 4762b7b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
36 changes: 19 additions & 17 deletions razorqt-panel/plugin-mainmenu/razormainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <razorqt/powermanager.h>
#include <razorqt/screensaver.h>
#include <razorqxt/qxtglobalshortcut.h>
#include <razorqt/xfitman.h>

#include <qtxdg/xdgicon.h>
#include <qtxdg/xdgdesktopfile.h>
Expand Down Expand Up @@ -106,40 +107,41 @@ void RazorMainMenu::showMenu()
if (!mMenu)
return;

int x, y;
QPoint menuPos;

switch (panel()->position())
{
case RazorPanel::PositionTop:
x = mButton.mapToGlobal(QPoint(0, 0)).x();
y = panel()->mapToGlobal(QPoint(0, panel()->height())).y();
menuPos = QPoint(
mButton.mapToGlobal(QPoint(0, 0)).x(),
panel()->mapToGlobal(QPoint(0, panel()->height())).y());
break;

case RazorPanel::PositionBottom:
x = mButton.mapToGlobal(QPoint(0, 0)).x();
y = panel()->mapToGlobal(QPoint(0, 0)).y() - mMenu->sizeHint().height();
menuPos = QPoint(
mButton.mapToGlobal(QPoint(0, 0)).x(),
panel()->mapToGlobal(QPoint(0, 0)).y() - mMenu->sizeHint().height());
break;

case RazorPanel::PositionLeft:
x = panel()->mapToGlobal(QPoint(panel()->width(), 0)).x();
y = mButton.mapToGlobal(QPoint(0, 0)).y();
menuPos = QPoint(
panel()->mapToGlobal(QPoint(panel()->width(), 0)).x(),
mButton.mapToGlobal(QPoint(0, 0)).y());
break;

case RazorPanel::PositionRight:
x = panel()->mapToGlobal(QPoint(0, 0)).x() - mMenu->sizeHint().width();
y = mButton.mapToGlobal(QPoint(0, 0)).y();
menuPos = QPoint(
panel()->mapToGlobal(QPoint(0, 0)).x() - mMenu->sizeHint().width(),
mButton.mapToGlobal(QPoint(0, 0)).y());
break;

}

menuPos = QPoint(x, y);

activateWindow();
QTimer::singleShot(1, this, SLOT(afterMenuActivated()));
}

void RazorMainMenu::afterMenuActivated()
{
// Just using Qt`s activateWindow() won't work on some WMs like Kwin.
// There are two solutions:
// activate window with Qt call and then execute menu 1ms later using timer,
// or use native X11 API calls:
xfitMan().raiseWindow(this->effectiveWinId());
mMenu->exec(menuPos);
}

Expand Down
2 changes: 0 additions & 2 deletions razorqt-panel/plugin-mainmenu/razormainmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class RazorMainMenu : public RazorPanelPlugin
QLabel mMainMenuButton;
QString mLogDir;
QMenu* mMenu;
QPoint menuPos;
QxtGlobalShortcut *mShortcut;
MenuStyle mTopMenuStyle;
MenuStyle mMenuStyle;
Expand All @@ -74,7 +73,6 @@ protected slots:

private slots:
void showMenu();
void afterMenuActivated();
void showHideMenu();
};

Expand Down

0 comments on commit 4762b7b

Please sign in to comment.