mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 18:10:37 +02:00
Stop QMenuBar to steal keyboard focus when pressing Alt key in Linux.
This commit is contained in:
parent
f7f9dfd26e
commit
801be7edee
3 changed files with 39 additions and 0 deletions
|
@ -803,6 +803,7 @@ bool Application::event(QEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::keyPressEvent(QKeyEvent* event) {
|
void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
|
qDebug("Application::keyPressEvent(%x)", event->key());
|
||||||
|
|
||||||
_keysPressed.insert(event->key());
|
_keysPressed.insert(event->key());
|
||||||
|
|
||||||
|
@ -1053,6 +1054,7 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::keyReleaseEvent(QKeyEvent* event) {
|
void Application::keyReleaseEvent(QKeyEvent* event) {
|
||||||
|
qDebug("Application::keyReleaseEvent(%x)", event->key());
|
||||||
|
|
||||||
_keysPressed.remove(event->key());
|
_keysPressed.remove(event->key());
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,11 @@ GLCanvas::GLCanvas() : QGLWidget(QGLFormat(QGL::NoDepthBuffer)),
|
||||||
_throttleRendering(false),
|
_throttleRendering(false),
|
||||||
_idleRenderInterval(MSECS_PER_FRAME_WHEN_THROTTLED)
|
_idleRenderInterval(MSECS_PER_FRAME_WHEN_THROTTLED)
|
||||||
{
|
{
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
// Cause GLCanvas::eventFilter to be called.
|
||||||
|
// It wouldn't hurt to do this on Mac and PC too; but apparently it's only needed on linux.
|
||||||
|
qApp->installEventFilter(this);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GLCanvas::isThrottleRendering() const {
|
bool GLCanvas::isThrottleRendering() const {
|
||||||
|
@ -162,3 +167,34 @@ void GLCanvas::dragEnterEvent(QDragEnterEvent* event) {
|
||||||
void GLCanvas::dropEvent(QDropEvent* event) {
|
void GLCanvas::dropEvent(QDropEvent* event) {
|
||||||
Application::getInstance()->dropEvent(event);
|
Application::getInstance()->dropEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pressing Alt (and Meta) key alone activates the menubar because its style inherits the
|
||||||
|
// SHMenuBarAltKeyNavigation from QWindowsStyle. This makes it impossible for a scripts to
|
||||||
|
// receive keyPress events for the Alt (and Meta) key in a reliable manner.
|
||||||
|
//
|
||||||
|
// This filter catches events before QMenuBar can steal the keyboard focus.
|
||||||
|
// The idea was borrowed from
|
||||||
|
// http://www.archivum.info/qt-interest@trolltech.com/2006-09/00053/Re-(Qt4)-Alt-key-focus-QMenuBar-(solved).html
|
||||||
|
|
||||||
|
bool GLCanvas::eventFilter(QObject*, QEvent* event) {
|
||||||
|
switch (event->type()) {
|
||||||
|
case QEvent::KeyPress:
|
||||||
|
case QEvent::KeyRelease:
|
||||||
|
case QEvent::ShortcutOverride:
|
||||||
|
{
|
||||||
|
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
||||||
|
if (keyEvent->key() == Qt::Key_Alt || keyEvent->key() == Qt::Key_Meta) {
|
||||||
|
if (event->type() == QEvent::KeyPress)
|
||||||
|
keyPressEvent(keyEvent);
|
||||||
|
else if (event->type() == QEvent::KeyRelease)
|
||||||
|
keyReleaseEvent(keyEvent);
|
||||||
|
else
|
||||||
|
QGLWidget::event(event);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ protected:
|
||||||
private slots:
|
private slots:
|
||||||
void activeChanged(Qt::ApplicationState state);
|
void activeChanged(Qt::ApplicationState state);
|
||||||
void throttleRender();
|
void throttleRender();
|
||||||
|
bool eventFilter(QObject*, QEvent* event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_GLCanvas_h
|
#endif // hifi_GLCanvas_h
|
||||||
|
|
Loading…
Reference in a new issue