aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Chew <kenneth.c0@protonmail.com>2022-04-16 02:07:29 -0400
committerKenneth Chew <kenneth.c0@protonmail.com>2022-04-16 02:07:29 -0400
commite59d3a339fcba0d17fd70df5690d358d1da315ac (patch)
tree421685cb66ad636af38b6751072dfe27a08d999a
parent1049507b3fe1b103e3089bb1178cac3bc92ff964 (diff)
downloadPrismLauncher-e59d3a339fcba0d17fd70df5690d358d1da315ac.tar.gz
PrismLauncher-e59d3a339fcba0d17fd70df5690d358d1da315ac.tar.bz2
PrismLauncher-e59d3a339fcba0d17fd70df5690d358d1da315ac.zip
Close the current window instead of the main window from the menu bar
Systems with native menu bars show the same menu bar for all child windows. As a result, you cannot assume that the menu bar's parent (the `MainWindow`) will be the window in focus.
-rw-r--r--launcher/Application.cpp7
-rw-r--r--launcher/Application.h1
-rw-r--r--launcher/ui/MainWindow.cpp3
3 files changed, 9 insertions, 2 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp
index 25ac93e6..01b62971 100644
--- a/launcher/Application.cpp
+++ b/launcher/Application.cpp
@@ -80,6 +80,7 @@
#include <QStringList>
#include <QDebug>
#include <QStyleFactory>
+#include <QWindow>
#include "InstanceList.h"
@@ -1267,6 +1268,12 @@ bool Application::kill(InstancePtr instance)
return true;
}
+void Application::closeCurrentWindow()
+{
+ if (focusWindow())
+ focusWindow()->close();
+}
+
void Application::addRunningInstance()
{
m_runningInstances ++;
diff --git a/launcher/Application.h b/launcher/Application.h
index 54d9ba5f..172321c0 100644
--- a/launcher/Application.h
+++ b/launcher/Application.h
@@ -189,6 +189,7 @@ public slots:
MinecraftAccountPtr accountToUse = nullptr
);
bool kill(InstancePtr instance);
+ void closeCurrentWindow();
private slots:
void on_windowClose();
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp
index 90af763a..1c694484 100644
--- a/launcher/ui/MainWindow.cpp
+++ b/launcher/ui/MainWindow.cpp
@@ -615,8 +615,7 @@ public:
closeAct = new QAction(tr("Close &Window"), MainWindow);
closeAct->setShortcut(QKeySequence::Close);
closeAct->setStatusTip(tr("Close the current window"));
- // FIXME: currently this always closes the main window, even if it is not currently the window in focus
- connect(closeAct, &QAction::triggered, MainWindow, &MainWindow::close);
+ connect(closeAct, &QAction::triggered, APPLICATION, &Application::closeCurrentWindow);
undoAct = new QAction(tr("&Undo"), MainWindow);
undoAct->setShortcuts(QKeySequence::Undo);