Skip to content

Commit

Permalink
main.cpp: make sure menu bar doesn't steal focus sometimes
Browse files Browse the repository at this point in the history
When XDG_CURRENT_DESKTOP ≠ kde, perssing and immediately releasing Alt
key makes focus get stuck in menu. Fix this by overriding QProxyStyle.

This does not influence menu accelerators (e.g. Alt+f to access "File" in
menu), which continue working according to user settings.

Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
  • Loading branch information
Hi-Angel committed Aug 6, 2019
1 parent ac9ccc9 commit 5fdedf7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <qplatformdefs.h>
#include <QApplication>
#include <QCommandLineParser>
#include <QProxyStyle>
#include <QStandardPaths>
#include <QDir>

Expand Down Expand Up @@ -63,6 +64,21 @@ void deleteQApplication()
}
}

// This override resolves following problem: since some qt version if
// XDG_CURRENT_DESKTOP ≠ kde, then pressing and immediately releasing Alt key makes
// focus get stuck in QMenu.
// Upstream report: https://bugreports.qt.io/browse/QTBUG-77355
class MenuStyle : public QProxyStyle {
public:
int styleHint(const StyleHint stylehint,
const QStyleOption *opt,
const QWidget *widget,
QStyleHintReturn *returnData) const override {
return (stylehint == QStyle::SH_MenuBar_AltKeyNavigation)
? 0 : QProxyStyle::styleHint(stylehint, opt, widget, returnData);
}
};

// ***
// Entry point into the Konsole terminal application.
// ***
Expand All @@ -88,6 +104,7 @@ extern "C" int Q_DECL_EXPORT kdemain(int argc, char *argv[])
#endif

auto app = new QApplication(argc, argv);
app->setStyle(new MenuStyle());

#if defined(Q_OS_LINUX) && (QT_VERSION < QT_VERSION_CHECK(5, 11, 2))
if (qtUseGLibOld.isNull()) {
Expand Down

1 comment on commit 5fdedf7

@kurthindenburg
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I committed this - thanks

Please sign in to comment.