Skip to content
This repository has been archived by the owner on Dec 17, 2017. It is now read-only.

Commit

Permalink
appswitcher: close window when there is no key pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
pvanek committed Feb 16, 2011
1 parent 89bc008 commit 0dd97b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
32 changes: 14 additions & 18 deletions razorqt-appswitcher/src/appswitcher.cpp
Expand Up @@ -67,7 +67,7 @@ void RazorAppSwitcher::AppSwitcher::handleApps()
}
// rest at the end
merge += l;

// setup new windows
foreach (Window w, merge)
{
Expand All @@ -88,7 +88,7 @@ void RazorAppSwitcher::AppSwitcher::handleApps()
}

selectNextItem();

// Warning: show() has to be called *after* setting focus. Dunno why
// but it works now.
if (!isVisible())
Expand Down Expand Up @@ -142,26 +142,22 @@ void RazorAppSwitcher::AppSwitcher::keyPressEvent(QKeyEvent * e)
break;
}
};
//
// TODO/FIXME: dunno why it does not work...
// // Let's assume that switch shortcut is always something like "alt+tab".
// // So at least one of ctrl. alt, or meta key *has* to be pressed.
// // If there is not any - apply focused window and close.
// qDebug() << e->modifiers() << Qt::ControlModifier << Qt::AltModifier << Qt::MetaModifier;
// if (e->modifiers() & (Qt::ControlModifier || Qt::AltModifier || Qt::MetaModifier))
// {
// qDebug() << "RazorAppSwitcher::AppSwitcher::keyPressEvent no 'meta' key pressed. Closing.";
// activateXWindow();
// }

QWidget::keyPressEvent(e);
}

//void RazorAppSwitcher::AppSwitcher::keyReleaseEvent(QKeyEvent * e)
//{
// qDebug() << "AppSwitcher::keyReleaseEvent" << e << e->key() << e->modifiers();;
// QWidget::keyReleaseEvent(e);
//}
void RazorAppSwitcher::AppSwitcher::keyReleaseEvent(QKeyEvent * e)
{
qDebug() << "AppSwitcher::keyReleaseEvent" << e << e->modifiers();
// close window if there is no modifier pressed.
// Here I assume that the key shortcis is always with ctrl or alt
if (e->modifiers() == 0)
{
activateXWindow();
close();
}
QWidget::keyReleaseEvent(e);
}

bool RazorAppSwitcher::AppSwitcher::eventFilter(QObject * o, QEvent * e)
{
Expand Down
3 changes: 2 additions & 1 deletion razorqt-appswitcher/src/appswitcher.h
Expand Up @@ -81,7 +81,8 @@ class AppSwitcher : public QWidget, public Ui::AppSwitcher

//! Handle Escape (close()) or Enter (activate window) keys
void keyPressEvent(QKeyEvent * e);
//void keyReleaseEvent(QKeyEvent * e);
//! Handle window closing when user releases ctrl or alt
void keyReleaseEvent(QKeyEvent * e);

/*! Filter events to close the window when it gets QEvent::WindowDeactivate.
It makes sense to close window when user activates another app.
Expand Down

0 comments on commit 0dd97b6

Please sign in to comment.