Merge pull request #1894 from Trial97/maximize

Fixed the maximized option on the newer Minecraft versions
This commit is contained in:
Alexandru Ionut Tripon
2024-10-28 22:30:09 +02:00
committed by GitHub
7 changed files with 63 additions and 12 deletions

View File

@@ -411,3 +411,8 @@ void BaseInstance::updateRuntimeContext()
{
// NOOP
}
bool BaseInstance::isLegacy()
{
return traits().contains("legacyLaunch") || traits().contains("alphaLaunch");
}

View File

@@ -269,6 +269,8 @@ class BaseInstance : public QObject, public std::enable_shared_from_this<BaseIns
bool removeLinkedInstanceId(const QString& id);
bool isLinkedToInstanceId(const QString& id) const;
bool isLegacy();
protected:
void changeStatus(Status newStatus);

View File

@@ -91,6 +91,9 @@
#include "tools/BaseProfiler.h"
#include <QActionGroup>
#include <QMainWindow>
#include <QScreen>
#include <QWindow>
#ifdef Q_OS_LINUX
#include "MangoHud.h"
@@ -530,7 +533,7 @@ QStringList MinecraftInstance::javaArguments()
QString MinecraftInstance::getLauncher()
{
// use legacy launcher if the traits are set
if (traits().contains("legacyLaunch") || traits().contains("alphaLaunch"))
if (isLegacy())
return "legacy";
return "standard";
@@ -752,11 +755,34 @@ QString MinecraftInstance::createLaunchScript(AuthSessionPtr session, MinecraftT
// window size, title and state, legacy
{
QString windowParams;
if (settings()->get("LaunchMaximized").toBool())
windowParams = "maximized";
else
if (settings()->get("LaunchMaximized").toBool()) {
// FIXME doesn't support maximisation
if (!isLegacy()) {
auto screen = QGuiApplication::primaryScreen();
auto screenGeometry = screen->availableSize();
// small hack to get the widow decorations
for (auto w : QApplication::topLevelWidgets()) {
auto mainWindow = qobject_cast<QMainWindow*>(w);
if (mainWindow) {
auto m = mainWindow->windowHandle()->frameMargins();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
screenGeometry = screenGeometry.shrunkBy(m);
#else
screenGeometry = { screenGeometry.width() - m.left() - m.right(), screenGeometry.height() - m.top() - m.bottom() };
#endif
break;
}
}
windowParams = QString("%1x%2").arg(screenGeometry.width()).arg(screenGeometry.height());
} else {
windowParams = "maximized";
}
} else {
windowParams =
QString("%1x%2").arg(settings()->get("MinecraftWinWidth").toInt()).arg(settings()->get("MinecraftWinHeight").toInt());
}
launchScript += "windowTitle " + windowTitle() + "\n";
launchScript += "windowParams " + windowParams + "\n";
}

View File

@@ -55,6 +55,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="maximizedWarning">
<property name="toolTip">
<string>On newer versions the game only supports resolution. In order to simulate the maximized behaviour the current implementation approximates the maximum display size.</string>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; color:#f5c211;&quot;&gt;Warning&lt;/span&gt;&lt;span style=&quot; color:#f5c211;&quot;&gt;: On the newer Minecraft versions the start maximized option is not fully supported.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayoutWindowSize">
<item row="1" column="0">

View File

@@ -323,6 +323,7 @@ void InstanceSettingsPage::loadSettings()
// Window Size
ui->windowSizeGroupBox->setChecked(m_settings->get("OverrideWindow").toBool());
ui->maximizedCheckBox->setChecked(m_settings->get("LaunchMaximized").toBool());
ui->maximizedWarning->setVisible(m_settings->get("LaunchMaximized").toBool() && !m_instance->isLegacy());
ui->windowWidthSpinBox->setValue(m_settings->get("MinecraftWinWidth").toInt());
ui->windowHeightSpinBox->setValue(m_settings->get("MinecraftWinHeight").toInt());

View File

@@ -36,7 +36,7 @@
<item>
<widget class="QTabWidget" name="settingsTabs">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="minecraftPage">
<attribute name="title">
@@ -285,6 +285,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="maximizedWarning">
<property name="toolTip">
<string>The base game only supports resolution. In order to simulate the maximized behaviour the current implementation approximates the maximum display size..</string>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600; color:#f5c211;&quot;&gt;Warning&lt;/span&gt;&lt;span style=&quot; color:#f5c211;&quot;&gt;: The maximized option may not be fully supported for the current minecraft version.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayoutWindowSize">
<item row="1" column="0">

View File

@@ -76,13 +76,10 @@ public final class StandardLauncher extends AbstractLauncher {
@Override
public void launch() throws Throwable {
// window size, title and state
// FIXME doesn't support maximisation
if (!maximize) {
gameArgs.add("--width");
gameArgs.add(Integer.toString(width));
gameArgs.add("--height");
gameArgs.add(Integer.toString(height));
}
gameArgs.add("--width");
gameArgs.add(Integer.toString(width));
gameArgs.add("--height");
gameArgs.add(Integer.toString(height));
if (serverAddress != null) {
if (quickPlayMultiplayerSupported) {