summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar liamwhite2023-11-29 12:33:09 -0500
committerGravatar GitHub2023-11-29 12:33:09 -0500
commit337e37f91dcc7d5b6a0a5da3f3196aa0f8df4143 (patch)
tree70d10b1f7919e6ed6709acab3259c69b038add6c /src
parentMerge pull request #11902 from ameerj/ssbo-align (diff)
parentcmake: move gamemode target include into its file (diff)
downloadyuzu-337e37f91dcc7d5b6a0a5da3f3196aa0f8df4143.tar.gz
yuzu-337e37f91dcc7d5b6a0a5da3f3196aa0f8df4143.tar.xz
yuzu-337e37f91dcc7d5b6a0a5da3f3196aa0f8df4143.zip
Merge pull request #11946 from flodavid/gamemode
Enable (Feral Interactive) Gamemode on Linux
Diffstat (limited to '')
-rw-r--r--src/common/CMakeLists.txt9
-rw-r--r--src/common/linux/gamemode.cpp39
-rw-r--r--src/common/linux/gamemode.h24
-rw-r--r--src/common/settings.cpp2
-rw-r--r--src/common/settings.h3
-rw-r--r--src/common/settings_common.h1
-rw-r--r--src/yuzu/CMakeLists.txt2
-rw-r--r--src/yuzu/configuration/configure_general.cpp43
-rw-r--r--src/yuzu/configuration/configure_general.ui27
-rw-r--r--src/yuzu/configuration/configure_system.ui2
-rw-r--r--src/yuzu/configuration/shared_translation.cpp3
-rw-r--r--src/yuzu/main.cpp30
-rw-r--r--src/yuzu/main.h1
-rw-r--r--src/yuzu_cmd/yuzu.cpp12
14 files changed, 189 insertions, 9 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index e216eb3de..57cbb9d07 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -174,6 +174,15 @@ if(ANDROID)
174 ) 174 )
175endif() 175endif()
176 176
177if (UNIX)
178 target_sources(common PRIVATE
179 linux/gamemode.cpp
180 linux/gamemode.h
181 )
182
183 target_link_libraries(common PRIVATE gamemode)
184endif()
185
177if(ARCHITECTURE_x86_64) 186if(ARCHITECTURE_x86_64)
178 target_sources(common 187 target_sources(common
179 PRIVATE 188 PRIVATE
diff --git a/src/common/linux/gamemode.cpp b/src/common/linux/gamemode.cpp
new file mode 100644
index 000000000..8876d8dc4
--- /dev/null
+++ b/src/common/linux/gamemode.cpp
@@ -0,0 +1,39 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include <gamemode_client.h>
5
6#include "common/linux/gamemode.h"
7#include "common/settings.h"
8
9namespace Common::Linux {
10
11void StartGamemode() {
12 if (Settings::values.enable_gamemode) {
13 if (gamemode_request_start() < 0) {
14 LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string());
15 } else {
16 LOG_INFO(Frontend, "Started gamemode");
17 }
18 }
19}
20
21void StopGamemode() {
22 if (Settings::values.enable_gamemode) {
23 if (gamemode_request_end() < 0) {
24 LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
25 } else {
26 LOG_INFO(Frontend, "Stopped gamemode");
27 }
28 }
29}
30
31void SetGamemodeState(bool state) {
32 if (state) {
33 StartGamemode();
34 } else {
35 StopGamemode();
36 }
37}
38
39} // namespace Common::Linux
diff --git a/src/common/linux/gamemode.h b/src/common/linux/gamemode.h
new file mode 100644
index 000000000..b80646ae2
--- /dev/null
+++ b/src/common/linux/gamemode.h
@@ -0,0 +1,24 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6namespace Common::Linux {
7
8/**
9 * Start the (Feral Interactive) Linux gamemode if it is installed and it is activated
10 */
11void StartGamemode();
12
13/**
14 * Stop the (Feral Interactive) Linux gamemode if it is installed and it is activated
15 */
16void StopGamemode();
17
18/**
19 * Start or stop the (Feral Interactive) Linux gamemode if it is installed and it is activated
20 * @param state The new state the gamemode should have
21 */
22void SetGamemodeState(bool state);
23
24} // namespace Common::Linux
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index a10131eb2..3e829253f 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -219,6 +219,8 @@ const char* TranslateCategory(Category category) {
219 return "Services"; 219 return "Services";
220 case Category::Paths: 220 case Category::Paths:
221 return "Paths"; 221 return "Paths";
222 case Category::Linux:
223 return "Linux";
222 case Category::MaxEnum: 224 case Category::MaxEnum:
223 break; 225 break;
224 } 226 }
diff --git a/src/common/settings.h b/src/common/settings.h
index b929fd957..6425cd98f 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -429,6 +429,9 @@ struct Values {
429 true, 429 true,
430 true}; 430 true};
431 431
432 // Linux
433 SwitchableSetting<bool> enable_gamemode{linkage, true, "enable_gamemode", Category::Linux};
434
432 // Controls 435 // Controls
433 InputSetting<std::array<PlayerInput, 10>> players; 436 InputSetting<std::array<PlayerInput, 10>> players;
434 437
diff --git a/src/common/settings_common.h b/src/common/settings_common.h
index 7943223eb..344c04439 100644
--- a/src/common/settings_common.h
+++ b/src/common/settings_common.h
@@ -41,6 +41,7 @@ enum class Category : u32 {
41 Multiplayer, 41 Multiplayer,
42 Services, 42 Services,
43 Paths, 43 Paths,
44 Linux,
44 MaxEnum, 45 MaxEnum,
45}; 46};
46 47
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt
index 90278052a..f3ad2214b 100644
--- a/src/yuzu/CMakeLists.txt
+++ b/src/yuzu/CMakeLists.txt
@@ -386,7 +386,7 @@ if (NOT WIN32)
386 target_include_directories(yuzu PRIVATE ${Qt${QT_MAJOR_VERSION}Gui_PRIVATE_INCLUDE_DIRS}) 386 target_include_directories(yuzu PRIVATE ${Qt${QT_MAJOR_VERSION}Gui_PRIVATE_INCLUDE_DIRS})
387endif() 387endif()
388if (UNIX AND NOT APPLE) 388if (UNIX AND NOT APPLE)
389 target_link_libraries(yuzu PRIVATE Qt${QT_MAJOR_VERSION}::DBus) 389 target_link_libraries(yuzu PRIVATE Qt${QT_MAJOR_VERSION}::DBus gamemode)
390endif() 390endif()
391 391
392target_compile_definitions(yuzu PRIVATE 392target_compile_definitions(yuzu PRIVATE
diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp
index c727fadd1..701b895e7 100644
--- a/src/yuzu/configuration/configure_general.cpp
+++ b/src/yuzu/configuration/configure_general.cpp
@@ -36,12 +36,29 @@ ConfigureGeneral::~ConfigureGeneral() = default;
36void ConfigureGeneral::SetConfiguration() {} 36void ConfigureGeneral::SetConfiguration() {}
37 37
38void ConfigureGeneral::Setup(const ConfigurationShared::Builder& builder) { 38void ConfigureGeneral::Setup(const ConfigurationShared::Builder& builder) {
39 QLayout& layout = *ui->general_widget->layout(); 39 QLayout& general_layout = *ui->general_widget->layout();
40 QLayout& linux_layout = *ui->linux_widget->layout();
40 41
41 std::map<u32, QWidget*> hold{}; 42 std::map<u32, QWidget*> general_hold{};
43 std::map<u32, QWidget*> linux_hold{};
42 44
43 for (const auto setting : 45 std::vector<Settings::BasicSetting*> settings;
44 UISettings::values.linkage.by_category[Settings::Category::UiGeneral]) { 46
47 auto push = [&settings](auto& list) {
48 for (auto setting : list) {
49 settings.push_back(setting);
50 }
51 };
52
53 push(UISettings::values.linkage.by_category[Settings::Category::UiGeneral]);
54 push(Settings::values.linkage.by_category[Settings::Category::Linux]);
55
56 // Only show Linux group on Unix
57#ifndef __unix__
58 ui->LinuxGroupBox->setVisible(false);
59#endif
60
61 for (const auto setting : settings) {
45 auto* widget = builder.BuildWidget(setting, apply_funcs); 62 auto* widget = builder.BuildWidget(setting, apply_funcs);
46 63
47 if (widget == nullptr) { 64 if (widget == nullptr) {
@@ -52,11 +69,23 @@ void ConfigureGeneral::Setup(const ConfigurationShared::Builder& builder) {
52 continue; 69 continue;
53 } 70 }
54 71
55 hold.emplace(setting->Id(), widget); 72 switch (setting->GetCategory()) {
73 case Settings::Category::UiGeneral:
74 general_hold.emplace(setting->Id(), widget);
75 break;
76 case Settings::Category::Linux:
77 linux_hold.emplace(setting->Id(), widget);
78 break;
79 default:
80 widget->deleteLater();
81 }
56 } 82 }
57 83
58 for (const auto& [id, widget] : hold) { 84 for (const auto& [id, widget] : general_hold) {
59 layout.addWidget(widget); 85 general_layout.addWidget(widget);
86 }
87 for (const auto& [id, widget] : linux_hold) {
88 linux_layout.addWidget(widget);
60 } 89 }
61} 90}
62 91
diff --git a/src/yuzu/configuration/configure_general.ui b/src/yuzu/configuration/configure_general.ui
index a10e7d3a5..ef20891a3 100644
--- a/src/yuzu/configuration/configure_general.ui
+++ b/src/yuzu/configuration/configure_general.ui
@@ -47,6 +47,33 @@
47 </widget> 47 </widget>
48 </item> 48 </item>
49 <item> 49 <item>
50 <widget class="QGroupBox" name="LinuxGroupBox">
51 <property name="title">
52 <string>Linux</string>
53 </property>
54 <layout class="QVBoxLayout" name="LinuxVerticalLayout_1">
55 <item>
56 <widget class="QWidget" name="linux_widget" native="true">
57 <layout class="QVBoxLayout" name="LinuxVerticalLayout_2">
58 <property name="leftMargin">
59 <number>0</number>
60 </property>
61 <property name="topMargin">
62 <number>0</number>
63 </property>
64 <property name="rightMargin">
65 <number>0</number>
66 </property>
67 <property name="bottomMargin">
68 <number>0</number>
69 </property>
70 </layout>
71 </widget>
72 </item>
73 </layout>
74 </widget>
75 </item>
76 <item>
50 <spacer name="verticalSpacer"> 77 <spacer name="verticalSpacer">
51 <property name="orientation"> 78 <property name="orientation">
52 <enum>Qt::Vertical</enum> 79 <enum>Qt::Vertical</enum>
diff --git a/src/yuzu/configuration/configure_system.ui b/src/yuzu/configuration/configure_system.ui
index 2a735836e..04b771129 100644
--- a/src/yuzu/configuration/configure_system.ui
+++ b/src/yuzu/configuration/configure_system.ui
@@ -57,7 +57,7 @@
57 </widget> 57 </widget>
58 </item> 58 </item>
59 <item> 59 <item>
60 <widget class="QGroupBox" name="groupBox"> 60 <widget class="QGroupBox" name="coreGroup">
61 <property name="title"> 61 <property name="title">
62 <string>Core</string> 62 <string>Core</string>
63 </property> 63 </property>
diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp
index a7b5def32..ee0ca4aa7 100644
--- a/src/yuzu/configuration/shared_translation.cpp
+++ b/src/yuzu/configuration/shared_translation.cpp
@@ -176,6 +176,9 @@ std::unique_ptr<TranslationMap> InitializeTranslations(QWidget* parent) {
176 INSERT(UISettings, controller_applet_disabled, tr("Disable controller applet"), 176 INSERT(UISettings, controller_applet_disabled, tr("Disable controller applet"),
177 QStringLiteral()); 177 QStringLiteral());
178 178
179 // Linux
180 INSERT(Settings, enable_gamemode, tr("Enable Gamemode"), QStringLiteral());
181
179 // Ui Debugging 182 // Ui Debugging
180 183
181 // Ui Multiplayer 184 // Ui Multiplayer
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 31aabb78a..10c788290 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -17,6 +17,7 @@
17#ifdef __unix__ 17#ifdef __unix__
18#include <csignal> 18#include <csignal>
19#include <sys/socket.h> 19#include <sys/socket.h>
20#include "common/linux/gamemode.h"
20#endif 21#endif
21 22
22#include <boost/container/flat_set.hpp> 23#include <boost/container/flat_set.hpp>
@@ -319,6 +320,7 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk
319 provider{std::make_unique<FileSys::ManualContentProvider>()} { 320 provider{std::make_unique<FileSys::ManualContentProvider>()} {
320#ifdef __unix__ 321#ifdef __unix__
321 SetupSigInterrupts(); 322 SetupSigInterrupts();
323 SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue());
322#endif 324#endif
323 system->Initialize(); 325 system->Initialize();
324 326
@@ -2120,6 +2122,10 @@ void GMainWindow::OnEmulationStopped() {
2120 2122
2121 discord_rpc->Update(); 2123 discord_rpc->Update();
2122 2124
2125#ifdef __unix__
2126 Common::Linux::StopGamemode();
2127#endif
2128
2123 // The emulation is stopped, so closing the window or not does not matter anymore 2129 // The emulation is stopped, so closing the window or not does not matter anymore
2124 disconnect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); 2130 disconnect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame);
2125 2131
@@ -3502,6 +3508,10 @@ void GMainWindow::OnStartGame() {
3502 play_time_manager->Start(); 3508 play_time_manager->Start();
3503 3509
3504 discord_rpc->Update(); 3510 discord_rpc->Update();
3511
3512#ifdef __unix__
3513 Common::Linux::StartGamemode();
3514#endif
3505} 3515}
3506 3516
3507void GMainWindow::OnRestartGame() { 3517void GMainWindow::OnRestartGame() {
@@ -3522,6 +3532,10 @@ void GMainWindow::OnPauseGame() {
3522 play_time_manager->Stop(); 3532 play_time_manager->Stop();
3523 UpdateMenuState(); 3533 UpdateMenuState();
3524 AllowOSSleep(); 3534 AllowOSSleep();
3535
3536#ifdef __unix__
3537 Common::Linux::StopGamemode();
3538#endif
3525} 3539}
3526 3540
3527void GMainWindow::OnPauseContinueGame() { 3541void GMainWindow::OnPauseContinueGame() {
@@ -3803,6 +3817,9 @@ void GMainWindow::OnConfigure() {
3803 const auto old_theme = UISettings::values.theme; 3817 const auto old_theme = UISettings::values.theme;
3804 const bool old_discord_presence = UISettings::values.enable_discord_presence.GetValue(); 3818 const bool old_discord_presence = UISettings::values.enable_discord_presence.GetValue();
3805 const auto old_language_index = Settings::values.language_index.GetValue(); 3819 const auto old_language_index = Settings::values.language_index.GetValue();
3820#ifdef __unix__
3821 const bool old_gamemode = Settings::values.enable_gamemode.GetValue();
3822#endif
3806 3823
3807 Settings::SetConfiguringGlobal(true); 3824 Settings::SetConfiguringGlobal(true);
3808 ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), 3825 ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(),
@@ -3864,6 +3881,11 @@ void GMainWindow::OnConfigure() {
3864 if (UISettings::values.enable_discord_presence.GetValue() != old_discord_presence) { 3881 if (UISettings::values.enable_discord_presence.GetValue() != old_discord_presence) {
3865 SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); 3882 SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue());
3866 } 3883 }
3884#ifdef __unix__
3885 if (Settings::values.enable_gamemode.GetValue() != old_gamemode) {
3886 SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue());
3887 }
3888#endif
3867 3889
3868 if (!multiplayer_state->IsHostingPublicRoom()) { 3890 if (!multiplayer_state->IsHostingPublicRoom()) {
3869 multiplayer_state->UpdateCredentials(); 3891 multiplayer_state->UpdateCredentials();
@@ -5172,6 +5194,14 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) {
5172 discord_rpc->Update(); 5194 discord_rpc->Update();
5173} 5195}
5174 5196
5197#ifdef __unix__
5198void GMainWindow::SetGamemodeEnabled(bool state) {
5199 if (emulation_running) {
5200 Common::Linux::SetGamemodeState(state);
5201 }
5202}
5203#endif
5204
5175void GMainWindow::changeEvent(QEvent* event) { 5205void GMainWindow::changeEvent(QEvent* event) {
5176#ifdef __unix__ 5206#ifdef __unix__
5177 // PaletteChange event appears to only reach so far into the GUI, explicitly asking to 5207 // PaletteChange event appears to only reach so far into the GUI, explicitly asking to
diff --git a/src/yuzu/main.h b/src/yuzu/main.h
index 733d6291e..530e445f9 100644
--- a/src/yuzu/main.h
+++ b/src/yuzu/main.h
@@ -340,6 +340,7 @@ private:
340 void SetupSigInterrupts(); 340 void SetupSigInterrupts();
341 static void HandleSigInterrupt(int); 341 static void HandleSigInterrupt(int);
342 void OnSigInterruptNotifierActivated(); 342 void OnSigInterruptNotifierActivated();
343 void SetGamemodeEnabled(bool state);
343#endif 344#endif
344 345
345private slots: 346private slots:
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp
index 0416d5951..a81635fa4 100644
--- a/src/yuzu_cmd/yuzu.cpp
+++ b/src/yuzu_cmd/yuzu.cpp
@@ -63,6 +63,10 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
63} 63}
64#endif 64#endif
65 65
66#ifdef __unix__
67#include "common/linux/gamemode.h"
68#endif
69
66static void PrintHelp(const char* argv0) { 70static void PrintHelp(const char* argv0) {
67 std::cout << "Usage: " << argv0 71 std::cout << "Usage: " << argv0
68 << " [options] <filename>\n" 72 << " [options] <filename>\n"
@@ -425,6 +429,10 @@ int main(int argc, char** argv) {
425 exit(0); 429 exit(0);
426 }); 430 });
427 431
432#ifdef __unix__
433 Common::Linux::StartGamemode();
434#endif
435
428 void(system.Run()); 436 void(system.Run());
429 if (system.DebuggerEnabled()) { 437 if (system.DebuggerEnabled()) {
430 system.InitializeDebugger(); 438 system.InitializeDebugger();
@@ -436,6 +444,10 @@ int main(int argc, char** argv) {
436 void(system.Pause()); 444 void(system.Pause());
437 system.ShutdownMainProcess(); 445 system.ShutdownMainProcess();
438 446
447#ifdef __unix__
448 Common::Linux::StopGamemode();
449#endif
450
439 detached_tasks.WaitForAllTasks(); 451 detached_tasks.WaitForAllTasks();
440 return 0; 452 return 0;
441} 453}