aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui/MainWindow.cpp
diff options
context:
space:
mode:
authorKenneth Chew <kenneth.c0@protonmail.com>2022-04-08 16:21:52 -0400
committerKenneth Chew <kenneth.c0@protonmail.com>2022-04-08 16:21:52 -0400
commitab82358dcb327a1a8ee19e102ce79c260e4f1241 (patch)
treeead9209473db959f6c0ab661508f9fd6aede803b /launcher/ui/MainWindow.cpp
parent75fddd0052e67c52a9bfe1041be0709aa60b1a14 (diff)
downloadPrismLauncher-ab82358dcb327a1a8ee19e102ce79c260e4f1241.tar.gz
PrismLauncher-ab82358dcb327a1a8ee19e102ce79c260e4f1241.tar.bz2
PrismLauncher-ab82358dcb327a1a8ee19e102ce79c260e4f1241.zip
Show and hide the menu bar with the 'alt' key
Only applicable for systems without a native menu bar (i.e. almost anything that is not macOS or Ubuntu Unity). On these systems, the menu bar appears on top of the window, which does not look good next to the tool bar already up there. When the menu bar is hidden, the keyboard shortcuts set by the menu bar are disabled. They should always work, so this also adds a workaround for that.
Diffstat (limited to 'launcher/ui/MainWindow.cpp')
-rw-r--r--launcher/ui/MainWindow.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp
index 45c19ca4..b98cd8b7 100644
--- a/launcher/ui/MainWindow.cpp
+++ b/launcher/ui/MainWindow.cpp
@@ -527,6 +527,7 @@ public:
MainWindow->setMenuBar(menuBar);
}
+ // If a keyboard shortcut is changed here, it must be changed below in keyPressEvent as well
void createMenuActions(MainWindow *MainWindow)
{
newAct = new QAction(tr("&New Instance..."), MainWindow);
@@ -1096,6 +1097,64 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
retranslateUi();
}
+// macOS always has a native menu bar, so these fixes are not applicable
+// Other systems may or may not have a native menu bar (most do not - it seems like only Ubuntu Unity does)
+#ifdef Q_OS_MAC
+void MainWindow::keyReleaseEvent(QKeyEvent *event)
+{
+ if(event->key()==Qt::Key_Alt)
+ ui->menuBar->setVisible(!ui->menuBar->isVisible());
+}
+
+// FIXME: This is a hack because keyboard shortcuts do nothing while menu bar is hidden on systems without native menu bar
+// If a keyboard shortcut is changed above in `createMenuActions`, it must be changed here as well
+void MainWindow::keyPressEvent(QKeyEvent *event)
+{
+ if(ui->menuBar->isVisible() || ui->menuBar->isNativeMenuBar())
+ return; // let the menu bar handle the keyboard shortcuts
+
+ if(event->modifiers().testFlag(Qt::ControlModifier))
+ {
+ switch(event->key())
+ {
+ case Qt::Key_N:
+ on_actionAddInstance_triggered();
+ return;
+ case Qt::Key_O:
+ if(event->modifiers().testFlag(Qt::ShiftModifier))
+ on_actionLaunchInstanceOffline_triggered();
+ else
+ on_actionLaunchInstance_triggered();
+ return;
+ case Qt::Key_I:
+ on_actionEditInstance_triggered();
+ return;
+ case Qt::Key_G:
+ on_actionChangeInstGroup_triggered();
+ return;
+ case Qt::Key_M:
+ on_actionViewSelectedMCFolder_triggered();
+ return;
+ case Qt::Key_E:
+ on_actionExportInstance_triggered();
+ return;
+ case Qt::Key_Delete:
+ on_actionDeleteInstance_triggered();
+ return;
+ case Qt::Key_D:
+ on_actionCopyInstance_triggered();
+ return;
+ case Qt::Key_W:
+ close();
+ return;
+ // Text editing shortcuts are handled by the OS, so they do not need to be implemented here again
+ default:
+ return;
+ }
+ }
+}
+#endif
+
void MainWindow::retranslateUi()
{
auto accounts = APPLICATION->accounts();