summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar xcfrg2023-07-16 18:45:33 -0400
committerGravatar flodavid2023-11-25 19:30:29 +0100
commitdfa56765d6d869a317ec46dcf3a8f4f35b146382 (patch)
tree827c46ada3f60e9bdef93c25a26319f00377d15f
parentMerge pull request #11889 from t895/ini-lib (diff)
downloadyuzu-dfa56765d6d869a317ec46dcf3a8f4f35b146382.tar.gz
yuzu-dfa56765d6d869a317ec46dcf3a8f4f35b146382.tar.xz
yuzu-dfa56765d6d869a317ec46dcf3a8f4f35b146382.zip
yuzu: integrate gamemode support on linux
Diffstat (limited to '')
-rw-r--r--externals/CMakeLists.txt6
-rw-r--r--externals/gamemode/CMakeLists.txt7
-rw-r--r--externals/gamemode/include/gamemode_client.h379
-rw-r--r--src/common/settings.h2
-rw-r--r--src/yuzu/CMakeLists.txt2
-rw-r--r--src/yuzu/configuration/configure_general.cpp3
-rw-r--r--src/yuzu/configuration/shared_translation.cpp1
-rw-r--r--src/yuzu/main.cpp54
-rw-r--r--src/yuzu/uisettings.h3
-rw-r--r--src/yuzu_cmd/CMakeLists.txt1
-rw-r--r--src/yuzu_cmd/yuzu.cpp24
11 files changed, 481 insertions, 1 deletions
diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt
index 515e3f2a4..36fc60e0e 100644
--- a/externals/CMakeLists.txt
+++ b/externals/CMakeLists.txt
@@ -189,6 +189,12 @@ if (ANDROID)
189 endif() 189 endif()
190endif() 190endif()
191 191
192# Gamemode
193if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
194 add_subdirectory(gamemode)
195 target_include_directories(gamemode PUBLIC gamemode/include)
196endif()
197
192# Breakpad 198# Breakpad
193# https://github.com/microsoft/vcpkg/blob/master/ports/breakpad/CMakeLists.txt 199# https://github.com/microsoft/vcpkg/blob/master/ports/breakpad/CMakeLists.txt
194if (YUZU_CRASH_DUMPS AND NOT TARGET libbreakpad_client) 200if (YUZU_CRASH_DUMPS AND NOT TARGET libbreakpad_client)
diff --git a/externals/gamemode/CMakeLists.txt b/externals/gamemode/CMakeLists.txt
new file mode 100644
index 000000000..3dddc6dbd
--- /dev/null
+++ b/externals/gamemode/CMakeLists.txt
@@ -0,0 +1,7 @@
1# SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2# SPDX-License-Identifier: GPL-3.0-or-later
3
4project(gamemode)
5
6add_library(gamemode include/gamemode_client.h)
7set_target_properties(gamemode PROPERTIES LINKER_LANGUAGE C)
diff --git a/externals/gamemode/include/gamemode_client.h b/externals/gamemode/include/gamemode_client.h
new file mode 100644
index 000000000..184812334
--- /dev/null
+++ b/externals/gamemode/include/gamemode_client.h
@@ -0,0 +1,379 @@
1// SPDX-FileCopyrightText: Copyright 2017-2019 Feral Interactive
2// SPDX-License-Identifier: BSD-3-Clause
3
4/*
5
6Copyright (c) 2017-2019, Feral Interactive
7All rights reserved.
8
9Redistribution and use in source and binary forms, with or without
10modification, are permitted provided that the following conditions are met:
11
12 * Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17 * Neither the name of Feral Interactive nor the names of its contributors
18 may be used to endorse or promote products derived from this software
19 without specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31POSSIBILITY OF SUCH DAMAGE.
32
33 */
34#ifndef CLIENT_GAMEMODE_H
35#define CLIENT_GAMEMODE_H
36/*
37 * GameMode supports the following client functions
38 * Requests are refcounted in the daemon
39 *
40 * int gamemode_request_start() - Request gamemode starts
41 * 0 if the request was sent successfully
42 * -1 if the request failed
43 *
44 * int gamemode_request_end() - Request gamemode ends
45 * 0 if the request was sent successfully
46 * -1 if the request failed
47 *
48 * GAMEMODE_AUTO can be defined to make the above two functions apply during static init and
49 * destruction, as appropriate. In this configuration, errors will be printed to stderr
50 *
51 * int gamemode_query_status() - Query the current status of gamemode
52 * 0 if gamemode is inactive
53 * 1 if gamemode is active
54 * 2 if gamemode is active and this client is registered
55 * -1 if the query failed
56 *
57 * int gamemode_request_start_for(pid_t pid) - Request gamemode starts for another process
58 * 0 if the request was sent successfully
59 * -1 if the request failed
60 * -2 if the request was rejected
61 *
62 * int gamemode_request_end_for(pid_t pid) - Request gamemode ends for another process
63 * 0 if the request was sent successfully
64 * -1 if the request failed
65 * -2 if the request was rejected
66 *
67 * int gamemode_query_status_for(pid_t pid) - Query status of gamemode for another process
68 * 0 if gamemode is inactive
69 * 1 if gamemode is active
70 * 2 if gamemode is active and this client is registered
71 * -1 if the query failed
72 *
73 * const char* gamemode_error_string() - Get an error string
74 * returns a string describing any of the above errors
75 *
76 * Note: All the above requests can be blocking - dbus requests can and will block while the daemon
77 * handles the request. It is not recommended to make these calls in performance critical code
78 */
79
80#include <stdbool.h>
81#include <stdio.h>
82
83#include <dlfcn.h>
84#include <string.h>
85
86#include <assert.h>
87
88#include <sys/types.h>
89
90static char internal_gamemode_client_error_string[512] = { 0 };
91
92/**
93 * Load libgamemode dynamically to dislodge us from most dependencies.
94 * This allows clients to link and/or use this regardless of runtime.
95 * See SDL2 for an example of the reasoning behind this in terms of
96 * dynamic versioning as well.
97 */
98static volatile int internal_libgamemode_loaded = 1;
99
100/* Typedefs for the functions to load */
101typedef int (*api_call_return_int)(void);
102typedef const char *(*api_call_return_cstring)(void);
103typedef int (*api_call_pid_return_int)(pid_t);
104
105/* Storage for functors */
106static api_call_return_int REAL_internal_gamemode_request_start = NULL;
107static api_call_return_int REAL_internal_gamemode_request_end = NULL;
108static api_call_return_int REAL_internal_gamemode_query_status = NULL;
109static api_call_return_cstring REAL_internal_gamemode_error_string = NULL;
110static api_call_pid_return_int REAL_internal_gamemode_request_start_for = NULL;
111static api_call_pid_return_int REAL_internal_gamemode_request_end_for = NULL;
112static api_call_pid_return_int REAL_internal_gamemode_query_status_for = NULL;
113
114/**
115 * Internal helper to perform the symbol binding safely.
116 *
117 * Returns 0 on success and -1 on failure
118 */
119__attribute__((always_inline)) static inline int internal_bind_libgamemode_symbol(
120 void *handle, const char *name, void **out_func, size_t func_size, bool required)
121{
122 void *symbol_lookup = NULL;
123 char *dl_error = NULL;
124
125 /* Safely look up the symbol */
126 symbol_lookup = dlsym(handle, name);
127 dl_error = dlerror();
128 if (required && (dl_error || !symbol_lookup)) {
129 snprintf(internal_gamemode_client_error_string,
130 sizeof(internal_gamemode_client_error_string),
131 "dlsym failed - %s",
132 dl_error);
133 return -1;
134 }
135
136 /* Have the symbol correctly, copy it to make it usable */
137 memcpy(out_func, &symbol_lookup, func_size);
138 return 0;
139}
140
141/**
142 * Loads libgamemode and needed functions
143 *
144 * Returns 0 on success and -1 on failure
145 */
146__attribute__((always_inline)) static inline int internal_load_libgamemode(void)
147{
148 /* We start at 1, 0 is a success and -1 is a fail */
149 if (internal_libgamemode_loaded != 1) {
150 return internal_libgamemode_loaded;
151 }
152
153 /* Anonymous struct type to define our bindings */
154 struct binding {
155 const char *name;
156 void **functor;
157 size_t func_size;
158 bool required;
159 } bindings[] = {
160 { "real_gamemode_request_start",
161 (void **)&REAL_internal_gamemode_request_start,
162 sizeof(REAL_internal_gamemode_request_start),
163 true },
164 { "real_gamemode_request_end",
165 (void **)&REAL_internal_gamemode_request_end,
166 sizeof(REAL_internal_gamemode_request_end),
167 true },
168 { "real_gamemode_query_status",
169 (void **)&REAL_internal_gamemode_query_status,
170 sizeof(REAL_internal_gamemode_query_status),
171 false },
172 { "real_gamemode_error_string",
173 (void **)&REAL_internal_gamemode_error_string,
174 sizeof(REAL_internal_gamemode_error_string),
175 true },
176 { "real_gamemode_request_start_for",
177 (void **)&REAL_internal_gamemode_request_start_for,
178 sizeof(REAL_internal_gamemode_request_start_for),
179 false },
180 { "real_gamemode_request_end_for",
181 (void **)&REAL_internal_gamemode_request_end_for,
182 sizeof(REAL_internal_gamemode_request_end_for),
183 false },
184 { "real_gamemode_query_status_for",
185 (void **)&REAL_internal_gamemode_query_status_for,
186 sizeof(REAL_internal_gamemode_query_status_for),
187 false },
188 };
189
190 void *libgamemode = NULL;
191
192 /* Try and load libgamemode */
193 libgamemode = dlopen("libgamemode.so.0", RTLD_NOW);
194 if (!libgamemode) {
195 /* Attempt to load unversioned library for compatibility with older
196 * versions (as of writing, there are no ABI changes between the two -
197 * this may need to change if ever ABI-breaking changes are made) */
198 libgamemode = dlopen("libgamemode.so", RTLD_NOW);
199 if (!libgamemode) {
200 snprintf(internal_gamemode_client_error_string,
201 sizeof(internal_gamemode_client_error_string),
202 "dlopen failed - %s",
203 dlerror());
204 internal_libgamemode_loaded = -1;
205 return -1;
206 }
207 }
208
209 /* Attempt to bind all symbols */
210 for (size_t i = 0; i < sizeof(bindings) / sizeof(bindings[0]); i++) {
211 struct binding *binder = &bindings[i];
212
213 if (internal_bind_libgamemode_symbol(libgamemode,
214 binder->name,
215 binder->functor,
216 binder->func_size,
217 binder->required)) {
218 internal_libgamemode_loaded = -1;
219 return -1;
220 };
221 }
222
223 /* Success */
224 internal_libgamemode_loaded = 0;
225 return 0;
226}
227
228/**
229 * Redirect to the real libgamemode
230 */
231__attribute__((always_inline)) static inline const char *gamemode_error_string(void)
232{
233 /* If we fail to load the system gamemode, or we have an error string already, return our error
234 * string instead of diverting to the system version */
235 if (internal_load_libgamemode() < 0 || internal_gamemode_client_error_string[0] != '\0') {
236 return internal_gamemode_client_error_string;
237 }
238
239 /* Assert for static analyser that the function is not NULL */
240 assert(REAL_internal_gamemode_error_string != NULL);
241
242 return REAL_internal_gamemode_error_string();
243}
244
245/**
246 * Redirect to the real libgamemode
247 * Allow automatically requesting game mode
248 * Also prints errors as they happen.
249 */
250#ifdef GAMEMODE_AUTO
251__attribute__((constructor))
252#else
253__attribute__((always_inline)) static inline
254#endif
255int gamemode_request_start(void)
256{
257 /* Need to load gamemode */
258 if (internal_load_libgamemode() < 0) {
259#ifdef GAMEMODE_AUTO
260 fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
261#endif
262 return -1;
263 }
264
265 /* Assert for static analyser that the function is not NULL */
266 assert(REAL_internal_gamemode_request_start != NULL);
267
268 if (REAL_internal_gamemode_request_start() < 0) {
269#ifdef GAMEMODE_AUTO
270 fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
271#endif
272 return -1;
273 }
274
275 return 0;
276}
277
278/* Redirect to the real libgamemode */
279#ifdef GAMEMODE_AUTO
280__attribute__((destructor))
281#else
282__attribute__((always_inline)) static inline
283#endif
284int gamemode_request_end(void)
285{
286 /* Need to load gamemode */
287 if (internal_load_libgamemode() < 0) {
288#ifdef GAMEMODE_AUTO
289 fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
290#endif
291 return -1;
292 }
293
294 /* Assert for static analyser that the function is not NULL */
295 assert(REAL_internal_gamemode_request_end != NULL);
296
297 if (REAL_internal_gamemode_request_end() < 0) {
298#ifdef GAMEMODE_AUTO
299 fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
300#endif
301 return -1;
302 }
303
304 return 0;
305}
306
307/* Redirect to the real libgamemode */
308__attribute__((always_inline)) static inline int gamemode_query_status(void)
309{
310 /* Need to load gamemode */
311 if (internal_load_libgamemode() < 0) {
312 return -1;
313 }
314
315 if (REAL_internal_gamemode_query_status == NULL) {
316 snprintf(internal_gamemode_client_error_string,
317 sizeof(internal_gamemode_client_error_string),
318 "gamemode_query_status missing (older host?)");
319 return -1;
320 }
321
322 return REAL_internal_gamemode_query_status();
323}
324
325/* Redirect to the real libgamemode */
326__attribute__((always_inline)) static inline int gamemode_request_start_for(pid_t pid)
327{
328 /* Need to load gamemode */
329 if (internal_load_libgamemode() < 0) {
330 return -1;
331 }
332
333 if (REAL_internal_gamemode_request_start_for == NULL) {
334 snprintf(internal_gamemode_client_error_string,
335 sizeof(internal_gamemode_client_error_string),
336 "gamemode_request_start_for missing (older host?)");
337 return -1;
338 }
339
340 return REAL_internal_gamemode_request_start_for(pid);
341}
342
343/* Redirect to the real libgamemode */
344__attribute__((always_inline)) static inline int gamemode_request_end_for(pid_t pid)
345{
346 /* Need to load gamemode */
347 if (internal_load_libgamemode() < 0) {
348 return -1;
349 }
350
351 if (REAL_internal_gamemode_request_end_for == NULL) {
352 snprintf(internal_gamemode_client_error_string,
353 sizeof(internal_gamemode_client_error_string),
354 "gamemode_request_end_for missing (older host?)");
355 return -1;
356 }
357
358 return REAL_internal_gamemode_request_end_for(pid);
359}
360
361/* Redirect to the real libgamemode */
362__attribute__((always_inline)) static inline int gamemode_query_status_for(pid_t pid)
363{
364 /* Need to load gamemode */
365 if (internal_load_libgamemode() < 0) {
366 return -1;
367 }
368
369 if (REAL_internal_gamemode_query_status_for == NULL) {
370 snprintf(internal_gamemode_client_error_string,
371 sizeof(internal_gamemode_client_error_string),
372 "gamemode_query_status_for missing (older host?)");
373 return -1;
374 }
375
376 return REAL_internal_gamemode_query_status_for(pid);
377}
378
379#endif // CLIENT_GAMEMODE_H
diff --git a/src/common/settings.h b/src/common/settings.h
index e75099b89..788020bde 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -178,6 +178,8 @@ struct Values {
178 true, 178 true,
179 &use_speed_limit}; 179 &use_speed_limit};
180 180
181 Setting<bool> enable_gamemode{linkage, false, "enable_gamemode", Category::Core};
182
181 // Cpu 183 // Cpu
182 SwitchableSetting<CpuAccuracy, true> cpu_accuracy{linkage, CpuAccuracy::Auto, 184 SwitchableSetting<CpuAccuracy, true> cpu_accuracy{linkage, CpuAccuracy::Auto,
183 CpuAccuracy::Auto, CpuAccuracy::Paranoid, 185 CpuAccuracy::Auto, CpuAccuracy::Paranoid,
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..ce7e17850 100644
--- a/src/yuzu/configuration/configure_general.cpp
+++ b/src/yuzu/configuration/configure_general.cpp
@@ -29,6 +29,9 @@ ConfigureGeneral::ConfigureGeneral(const Core::System& system_,
29 if (!Settings::IsConfiguringGlobal()) { 29 if (!Settings::IsConfiguringGlobal()) {
30 ui->button_reset_defaults->setVisible(false); 30 ui->button_reset_defaults->setVisible(false);
31 } 31 }
32#ifndef __linux__
33 ui->enable_gamemode->setVisible(false);
34#endif
32} 35}
33 36
34ConfigureGeneral::~ConfigureGeneral() = default; 37ConfigureGeneral::~ConfigureGeneral() = default;
diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp
index a7b5def32..903805e75 100644
--- a/src/yuzu/configuration/shared_translation.cpp
+++ b/src/yuzu/configuration/shared_translation.cpp
@@ -175,6 +175,7 @@ std::unique_ptr<TranslationMap> InitializeTranslations(QWidget* parent) {
175 INSERT(UISettings, hide_mouse, tr("Hide mouse on inactivity"), QStringLiteral()); 175 INSERT(UISettings, hide_mouse, tr("Hide mouse on inactivity"), QStringLiteral());
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 INSERT(UISettings, enable_gamemode, tr("Enable Gamemode"), QStringLiteral());
178 179
179 // Ui Debugging 180 // Ui Debugging
180 181
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index defe45198..cf61d4258 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -185,6 +185,10 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
185} 185}
186#endif 186#endif
187 187
188#ifdef __linux__
189#include <gamemode_client.h>
190#endif
191
188constexpr int default_mouse_hide_timeout = 2500; 192constexpr int default_mouse_hide_timeout = 2500;
189constexpr int default_mouse_center_timeout = 10; 193constexpr int default_mouse_center_timeout = 10;
190constexpr int default_input_update_timeout = 1; 194constexpr int default_input_update_timeout = 1;
@@ -2126,6 +2130,16 @@ void GMainWindow::OnEmulationStopped() {
2126 2130
2127 discord_rpc->Update(); 2131 discord_rpc->Update();
2128 2132
2133#ifdef __linux__
2134 if (UISettings::values.enable_gamemode) {
2135 if (gamemode_request_end() < 0) {
2136 LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
2137 } else {
2138 LOG_INFO(Frontend, "Stopped gamemode");
2139 }
2140 }
2141#endif
2142
2129 // The emulation is stopped, so closing the window or not does not matter anymore 2143 // The emulation is stopped, so closing the window or not does not matter anymore
2130 disconnect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); 2144 disconnect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame);
2131 2145
@@ -3504,6 +3518,16 @@ void GMainWindow::OnStartGame() {
3504 play_time_manager->Start(); 3518 play_time_manager->Start();
3505 3519
3506 discord_rpc->Update(); 3520 discord_rpc->Update();
3521
3522#ifdef __linux__
3523 if (UISettings::values.enable_gamemode) {
3524 if (gamemode_request_start() < 0) {
3525 LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string());
3526 } else {
3527 LOG_INFO(Frontend, "Started gamemode");
3528 }
3529 }
3530#endif
3507} 3531}
3508 3532
3509void GMainWindow::OnRestartGame() { 3533void GMainWindow::OnRestartGame() {
@@ -3524,6 +3548,16 @@ void GMainWindow::OnPauseGame() {
3524 play_time_manager->Stop(); 3548 play_time_manager->Stop();
3525 UpdateMenuState(); 3549 UpdateMenuState();
3526 AllowOSSleep(); 3550 AllowOSSleep();
3551
3552#ifdef __linux__
3553 if (UISettings::values.enable_gamemode) {
3554 if (gamemode_request_end() < 0) {
3555 LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
3556 } else {
3557 LOG_INFO(Frontend, "Stopped gamemode");
3558 }
3559 }
3560#endif
3527} 3561}
3528 3562
3529void GMainWindow::OnPauseContinueGame() { 3563void GMainWindow::OnPauseContinueGame() {
@@ -5181,6 +5215,26 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) {
5181 discord_rpc->Update(); 5215 discord_rpc->Update();
5182} 5216}
5183 5217
5218void GMainWindow::SetGamemodeDisabled([[maybe_unused]] bool state) {
5219#ifdef __linux__
5220 if (emulation_running) {
5221 if (state) {
5222 if (gamemode_request_end() < 0) {
5223 LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
5224 } else {
5225 LOG_INFO(Frontend, "Stopped gamemode");
5226 }
5227 } else {
5228 if (gamemode_request_start() < 0) {
5229 LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string());
5230 } else {
5231 LOG_INFO(Frontend, "Started gamemode");
5232 }
5233 }
5234 }
5235#endif
5236}
5237
5184void GMainWindow::changeEvent(QEvent* event) { 5238void GMainWindow::changeEvent(QEvent* event) {
5185#ifdef __unix__ 5239#ifdef __unix__
5186 // PaletteChange event appears to only reach so far into the GUI, explicitly asking to 5240 // PaletteChange event appears to only reach so far into the GUI, explicitly asking to
diff --git a/src/yuzu/uisettings.h b/src/yuzu/uisettings.h
index 549a39e1b..3e5ddc07a 100644
--- a/src/yuzu/uisettings.h
+++ b/src/yuzu/uisettings.h
@@ -140,6 +140,9 @@ struct Values {
140 Settings::Specialization::Default, 140 Settings::Specialization::Default,
141 true, 141 true,
142 true}; 142 true};
143 // Gamemode
144 Setting<bool> enable_gamemode{linkage, false, "enable_gamemode", Category::UiGeneral};
145
143 Setting<bool> disable_web_applet{linkage, true, "disable_web_applet", Category::Ui}; 146 Setting<bool> disable_web_applet{linkage, true, "disable_web_applet", Category::Ui};
144 147
145 // Discord RPC 148 // Discord RPC
diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt
index fbeba8813..002f3e841 100644
--- a/src/yuzu_cmd/CMakeLists.txt
+++ b/src/yuzu_cmd/CMakeLists.txt
@@ -44,6 +44,7 @@ target_link_libraries(yuzu-cmd PRIVATE SDL2::SDL2 Vulkan::Headers)
44 44
45if(UNIX AND NOT APPLE) 45if(UNIX AND NOT APPLE)
46 install(TARGETS yuzu-cmd) 46 install(TARGETS yuzu-cmd)
47 target_link_libraries(yuzu-cmd PRIVATE gamemode)
47endif() 48endif()
48 49
49if(WIN32) 50if(WIN32)
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp
index 0416d5951..1c3a1809b 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 __linux__
67#include <gamemode_client.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,16 @@ int main(int argc, char** argv) {
425 exit(0); 429 exit(0);
426 }); 430 });
427 431
432#ifdef __linux__
433 if (Settings::values.disable_gamemode) {
434 if (gamemode_request_start() < 0) {
435 LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string());
436 } else {
437 LOG_INFO(Frontend, "Started gamemode");
438 }
439 }
440#endif
441
428 void(system.Run()); 442 void(system.Run());
429 if (system.DebuggerEnabled()) { 443 if (system.DebuggerEnabled()) {
430 system.InitializeDebugger(); 444 system.InitializeDebugger();
@@ -436,6 +450,16 @@ int main(int argc, char** argv) {
436 void(system.Pause()); 450 void(system.Pause());
437 system.ShutdownMainProcess(); 451 system.ShutdownMainProcess();
438 452
453#ifdef __linux__
454 if (Settings::values.disable_gamemode) {
455 if (gamemode_request_end() < 0) {
456 LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
457 } else {
458 LOG_INFO(Frontend, "Stopped gamemode");
459 }
460 }
461#endif
462
439 detached_tasks.WaitForAllTasks(); 463 detached_tasks.WaitForAllTasks();
440 return 0; 464 return 0;
441} 465}