Skip to content

Commit 83aa006

Browse files
committed
feat: add custom native library path settings
Signed-off-by: Sefa Eyeoglu <[email protected]>
1 parent ff67fd1 commit 83aa006

12 files changed

+196
-18
lines changed

CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ set(Launcher_SUBREDDIT_URL "https://prismlauncher.org/reddit" CACHE STRING "URL
216216
set(Launcher_FORCE_BUNDLED_LIBS OFF CACHE BOOL "Prevent using system libraries, if they are available as submodules")
217217
set(Launcher_QT_VERSION_MAJOR "6" CACHE STRING "Major Qt version to build against")
218218

219+
# Native libraries
220+
if(UNIX AND APPLE)
221+
set(Launcher_GLFW_LIBRARY_NAME "libglfw.dylib" CACHE STRING "Name of native glfw library")
222+
set(Launcher_OPENAL_LIBRARY_NAME "libopenal.dylib" CACHE STRING "Name of native glfw library")
223+
elseif(UNIX)
224+
set(Launcher_GLFW_LIBRARY_NAME "libglfw.so" CACHE STRING "Name of native glfw library")
225+
set(Launcher_OPENAL_LIBRARY_NAME "libopenal.so" CACHE STRING "Name of native glfw library")
226+
elseif(WIN32)
227+
set(Launcher_GLFW_LIBRARY_NAME "glfw.dll" CACHE STRING "Name of native glfw library")
228+
set(Launcher_OPENAL_LIBRARY_NAME "OpenAL.dll" CACHE STRING "Name of native glfw library")
229+
endif()
230+
219231
# API Keys
220232
# NOTE: These API keys are here for convenience. If you rebrand this software or intend to break the terms of service
221233
# of these platforms, please change these API keys beforehand.

buildconfig/BuildConfig.cpp.in

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ Config::Config()
110110
FLAME_API_KEY = "@Launcher_CURSEFORGE_API_KEY@";
111111
META_URL = "@Launcher_META_URL@";
112112

113+
GLFW_LIBRARY_NAME = "@Launcher_GLFW_LIBRARY_NAME@";
114+
OPENAL_LIBRARY_NAME = "@Launcher_OPENAL_LIBRARY_NAME@";
115+
113116
BUG_TRACKER_URL = "@Launcher_BUG_TRACKER_URL@";
114117
TRANSLATIONS_URL = "@Launcher_TRANSLATIONS_URL@";
115118
MATRIX_URL = "@Launcher_MATRIX_URL@";

buildconfig/BuildConfig.h

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ class Config {
134134
*/
135135
QString META_URL;
136136

137+
QString GLFW_LIBRARY_NAME;
138+
QString OPENAL_LIBRARY_NAME;
139+
137140
QString BUG_TRACKER_URL;
138141
QString TRANSLATIONS_URL;
139142
QString MATRIX_URL;

launcher/Application.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,9 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
582582

583583
// Native library workarounds
584584
m_settings->registerSetting("UseNativeOpenAL", false);
585+
m_settings->registerSetting("CustomOpenALPath", "");
585586
m_settings->registerSetting("UseNativeGLFW", false);
587+
m_settings->registerSetting("CustomGLFWPath", "");
586588

587589
// Peformance related options
588590
m_settings->registerSetting("EnableFeralGamemode", false);
@@ -842,6 +844,8 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
842844

843845
updateCapabilities();
844846

847+
detectLibraries();
848+
845849
if (createSetupWizard()) {
846850
return;
847851
}
@@ -1412,6 +1416,15 @@ void Application::updateCapabilities()
14121416
#endif
14131417
}
14141418

1419+
void Application::detectLibraries()
1420+
{
1421+
#ifdef Q_OS_LINUX
1422+
m_detectedGLFWPath = MangoHud::findLibrary(BuildConfig.GLFW_LIBRARY_NAME);
1423+
m_detectedOpenALPath = MangoHud::findLibrary(BuildConfig.OPENAL_LIBRARY_NAME);
1424+
qDebug() << m_detectedGLFWPath << m_detectedOpenALPath;
1425+
#endif
1426+
}
1427+
14151428
QString Application::getJarPath(QString jarFile)
14161429
{
14171430
QStringList potentialPaths = {

launcher/Application.h

+4
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class Application : public QApplication {
142142

143143
void updateCapabilities();
144144

145+
void detectLibraries();
146+
145147
/*!
146148
* Finds and returns the full path to a jar file.
147149
* Returns a null-string if it could not be found.
@@ -275,6 +277,8 @@ class Application : public QApplication {
275277
SetupWizard* m_setupWizard = nullptr;
276278

277279
public:
280+
QString m_detectedGLFWPath;
281+
QString m_detectedOpenALPath;
278282
QString m_instanceIdToLaunch;
279283
QString m_serverToJoin;
280284
QString m_profileToUse;

launcher/minecraft/MinecraftInstance.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ void MinecraftInstance::loadSpecificSettings()
166166
// Native library workarounds
167167
auto nativeLibraryWorkaroundsOverride = m_settings->registerSetting("OverrideNativeWorkarounds", false);
168168
m_settings->registerOverride(global_settings->getSetting("UseNativeOpenAL"), nativeLibraryWorkaroundsOverride);
169+
m_settings->registerOverride(global_settings->getSetting("CustomOpenALPath"), nativeLibraryWorkaroundsOverride);
169170
m_settings->registerOverride(global_settings->getSetting("UseNativeGLFW"), nativeLibraryWorkaroundsOverride);
171+
m_settings->registerOverride(global_settings->getSetting("CustomGLFWPath"), nativeLibraryWorkaroundsOverride);
170172

171173
// Peformance related options
172174
auto performanceOverride = m_settings->registerSetting("OverridePerformance", false);
@@ -390,22 +392,28 @@ QStringList MinecraftInstance::extraArguments()
390392
list.append("-Dloader.disable_beacon=true");
391393
}
392394

393-
#ifdef Q_OS_LINUX
394395
{
395396
QString openALPath;
396397
QString glfwPath;
397398

398-
if (settings()->get("UseNativeOpenAL").toBool())
399-
openALPath = MangoHud::findLibrary("libopenal.so");
400-
if (settings()->get("UseNativeGLFW").toBool())
401-
glfwPath = MangoHud::findLibrary("libglfw.so");
399+
if (settings()->get("UseNativeOpenAL").toBool()) {
400+
auto customPath = settings()->get("CustomOpenALPath").toString();
401+
openALPath = APPLICATION->m_detectedOpenALPath;
402+
if (!customPath.isEmpty())
403+
openALPath = customPath;
404+
}
405+
if (settings()->get("UseNativeGLFW").toBool()) {
406+
auto customPath = settings()->get("CustomGLFWPath").toString();
407+
glfwPath = APPLICATION->m_detectedGLFWPath;
408+
if (!customPath.isEmpty())
409+
glfwPath = customPath;
410+
}
402411

403412
if (!openALPath.isEmpty())
404413
list.append("-Dorg.lwjgl.openal.libname=" + openALPath);
405414
if (!glfwPath.isEmpty())
406415
list.append("-Dorg.lwjgl.glfw.libname=" + glfwPath);
407416
}
408-
#endif
409417

410418
return list;
411419
}

launcher/ui/pages/global/MinecraftPage.cpp

+33-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*/
3636

3737
#include "MinecraftPage.h"
38+
#include "BuildConfig.h"
3839
#include "ui_MinecraftPage.h"
3940

4041
#include <QDir>
@@ -44,9 +45,15 @@
4445
#include "Application.h"
4546
#include "settings/SettingsObject.h"
4647

48+
#ifdef Q_OS_LINUX
49+
#include "MangoHud.h"
50+
#endif
51+
4752
MinecraftPage::MinecraftPage(QWidget* parent) : QWidget(parent), ui(new Ui::MinecraftPage)
4853
{
4954
ui->setupUi(this);
55+
connect(ui->useNativeGLFWCheck, &QAbstractButton::toggled, this, &MinecraftPage::onUseNativeGLFWChanged);
56+
connect(ui->useNativeOpenALCheck, &QAbstractButton::toggled, this, &MinecraftPage::onUseNativeOpenALChanged);
5057
loadSettings();
5158
updateCheckboxStuff();
5259
}
@@ -74,6 +81,16 @@ void MinecraftPage::on_maximizedCheckBox_clicked(bool checked)
7481
updateCheckboxStuff();
7582
}
7683

84+
void MinecraftPage::onUseNativeGLFWChanged(bool checked)
85+
{
86+
ui->lineEditGLFWPath->setEnabled(checked);
87+
}
88+
89+
void MinecraftPage::onUseNativeOpenALChanged(bool checked)
90+
{
91+
ui->lineEditOpenALPath->setEnabled(checked);
92+
}
93+
7794
void MinecraftPage::applySettings()
7895
{
7996
auto s = APPLICATION->settings();
@@ -84,8 +101,10 @@ void MinecraftPage::applySettings()
84101
s->set("MinecraftWinHeight", ui->windowHeightSpinBox->value());
85102

86103
// Native library workarounds
87-
s->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked());
88104
s->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked());
105+
s->set("CustomGLFWPath", ui->lineEditGLFWPath->text());
106+
s->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked());
107+
s->set("CustomOpenALPath", ui->lineEditOpenALPath->text());
89108

90109
// Peformance related options
91110
s->set("EnableFeralGamemode", ui->enableFeralGamemodeCheck->isChecked());
@@ -114,8 +133,20 @@ void MinecraftPage::loadSettings()
114133
ui->windowWidthSpinBox->setValue(s->get("MinecraftWinWidth").toInt());
115134
ui->windowHeightSpinBox->setValue(s->get("MinecraftWinHeight").toInt());
116135

117-
ui->useNativeOpenALCheck->setChecked(s->get("UseNativeOpenAL").toBool());
118136
ui->useNativeGLFWCheck->setChecked(s->get("UseNativeGLFW").toBool());
137+
ui->lineEditGLFWPath->setText(s->get("CustomGLFWPath").toString());
138+
ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.GLFW_LIBRARY_NAME));
139+
#ifdef Q_OS_LINUX
140+
if (!APPLICATION->m_detectedGLFWPath.isEmpty())
141+
ui->lineEditGLFWPath->setPlaceholderText(tr("Auto detected path: %1").arg(APPLICATION->m_detectedGLFWPath));
142+
#endif
143+
ui->useNativeOpenALCheck->setChecked(s->get("UseNativeOpenAL").toBool());
144+
ui->lineEditOpenALPath->setText(s->get("CustomOpenALPath").toString());
145+
ui->lineEditOpenALPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.OPENAL_LIBRARY_NAME));
146+
#ifdef Q_OS_LINUX
147+
if (!APPLICATION->m_detectedOpenALPath.isEmpty())
148+
ui->lineEditOpenALPath->setPlaceholderText(tr("Auto detected path: %1").arg(APPLICATION->m_detectedOpenALPath));
149+
#endif
119150

120151
ui->enableFeralGamemodeCheck->setChecked(s->get("EnableFeralGamemode").toBool());
121152
ui->enableMangoHud->setChecked(s->get("EnableMangoHud").toBool());

launcher/ui/pages/global/MinecraftPage.h

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class MinecraftPage : public QWidget, public BasePage {
7070
private slots:
7171
void on_maximizedCheckBox_clicked(bool checked);
7272

73+
void onUseNativeGLFWChanged(bool checked);
74+
void onUseNativeOpenALChanged(bool checked);
75+
7376
private:
7477
Ui::MinecraftPage* ui;
7578
};

launcher/ui/pages/global/MinecraftPage.ui

+37-3
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,55 @@
214214
<property name="title">
215215
<string>Native library workarounds</string>
216216
</property>
217-
<layout class="QVBoxLayout" name="verticalLayout_11">
218-
<item>
217+
<layout class="QGridLayout" name="gridLayout">
218+
<item row="0" column="0">
219219
<widget class="QCheckBox" name="useNativeGLFWCheck">
220220
<property name="text">
221221
<string>Use system installation of &amp;GLFW</string>
222222
</property>
223223
</widget>
224224
</item>
225-
<item>
225+
<item row="1" column="0">
226+
<widget class="QLabel" name="labelGLFWPath">
227+
<property name="text">
228+
<string>&amp;GLFW library path</string>
229+
</property>
230+
<property name="buddy">
231+
<cstring>lineEditGLFWPath</cstring>
232+
</property>
233+
</widget>
234+
</item>
235+
<item row="2" column="0">
226236
<widget class="QCheckBox" name="useNativeOpenALCheck">
227237
<property name="text">
228238
<string>Use system installation of &amp;OpenAL</string>
229239
</property>
230240
</widget>
231241
</item>
242+
<item row="3" column="0">
243+
<widget class="QLabel" name="labelOpenALPath">
244+
<property name="text">
245+
<string>&amp;OpenAL library path</string>
246+
</property>
247+
<property name="buddy">
248+
<cstring>lineEditOpenALPath</cstring>
249+
</property>
250+
</widget>
251+
</item>
252+
<item row="1" column="1">
253+
<widget class="QLineEdit" name="lineEditGLFWPath">
254+
<property name="enabled">
255+
<bool>false</bool>
256+
</property>
257+
</widget>
258+
</item>
259+
<item row="3" column="1">
260+
<widget class="QLineEdit" name="lineEditOpenALPath">
261+
<property name="enabled">
262+
<bool>false</bool>
263+
</property>
264+
</widget>
265+
</item>
232266
</layout>
233267
</widget>
234268
</item>

launcher/ui/pages/instance/InstanceSettingsPage.cpp

+32-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ InstanceSettingsPage::InstanceSettingsPage(BaseInstance* inst, QWidget* parent)
6666
connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
6767
connect(ui->instanceAccountSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
6868
&InstanceSettingsPage::changeInstanceAccount);
69+
70+
connect(ui->useNativeGLFWCheck, &QAbstractButton::toggled, this, &InstanceSettingsPage::onUseNativeGLFWChanged);
71+
connect(ui->useNativeOpenALCheck, &QAbstractButton::toggled, this, &InstanceSettingsPage::onUseNativeOpenALChanged);
72+
6973
loadSettings();
7074

7175
updateThresholds();
@@ -198,11 +202,15 @@ void InstanceSettingsPage::applySettings()
198202
bool workarounds = ui->nativeWorkaroundsGroupBox->isChecked();
199203
m_settings->set("OverrideNativeWorkarounds", workarounds);
200204
if (workarounds) {
201-
m_settings->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked());
202205
m_settings->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked());
206+
m_settings->set("CustomGLFWPath", ui->lineEditGLFWPath->text());
207+
m_settings->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked());
208+
m_settings->set("CustomOpenALPath", ui->lineEditOpenALPath->text());
203209
} else {
204-
m_settings->reset("UseNativeOpenAL");
205210
m_settings->reset("UseNativeGLFW");
211+
m_settings->reset("CustomGLFWPath");
212+
m_settings->reset("UseNativeOpenAL");
213+
m_settings->reset("CustomOpenALPath");
206214
}
207215

208216
// Performance
@@ -312,7 +320,19 @@ void InstanceSettingsPage::loadSettings()
312320
// Workarounds
313321
ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool());
314322
ui->useNativeGLFWCheck->setChecked(m_settings->get("UseNativeGLFW").toBool());
323+
ui->lineEditGLFWPath->setText(m_settings->get("CustomGLFWPath").toString());
324+
#ifdef Q_OS_LINUX
325+
ui->lineEditGLFWPath->setPlaceholderText(APPLICATION->m_detectedGLFWPath);
326+
#else
327+
ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.GLFW_LIBRARY_NAME));
328+
#endif
315329
ui->useNativeOpenALCheck->setChecked(m_settings->get("UseNativeOpenAL").toBool());
330+
ui->lineEditOpenALPath->setText(m_settings->get("CustomOpenALPath").toString());
331+
#ifdef Q_OS_LINUX
332+
ui->lineEditOpenALPath->setPlaceholderText(APPLICATION->m_detectedOpenALPath);
333+
#else
334+
ui->lineEditGLFWPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.OPENAL_LIBRARY_NAME));
335+
#endif
316336

317337
// Performance
318338
ui->perfomanceGroupBox->setChecked(m_settings->get("OverridePerformance").toBool());
@@ -408,6 +428,16 @@ void InstanceSettingsPage::on_javaTestBtn_clicked()
408428
checker->run();
409429
}
410430

431+
void InstanceSettingsPage::onUseNativeGLFWChanged(bool checked)
432+
{
433+
ui->lineEditGLFWPath->setEnabled(checked);
434+
}
435+
436+
void InstanceSettingsPage::onUseNativeOpenALChanged(bool checked)
437+
{
438+
ui->lineEditOpenALPath->setEnabled(checked);
439+
}
440+
411441
void InstanceSettingsPage::updateAccountsMenu()
412442
{
413443
ui->instanceAccountSelector->clear();

launcher/ui/pages/instance/InstanceSettingsPage.h

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class InstanceSettingsPage : public QWidget, public BasePage {
7171
void on_javaBrowseBtn_clicked();
7272
void on_maxMemSpinBox_valueChanged(int i);
7373

74+
void onUseNativeGLFWChanged(bool checked);
75+
void onUseNativeOpenALChanged(bool checked);
76+
7477
void applySettings();
7578
void loadSettings();
7679

0 commit comments

Comments
 (0)