From f9f7b96acd275afd96a82866c8194211b3945a18 Mon Sep 17 00:00:00 2001 From: lizzie Date: Fri, 29 Aug 2025 23:48:25 +0000 Subject: [PATCH 1/7] [gamemode] Make available on other platforms Signed-off-by: lizzie --- CMakeLists.txt | 2 +- externals/gamemode/gamemode_client.h | 28 +++++++++++++++- src/common/CMakeLists.txt | 8 ++--- src/common/gamemode.cpp | 50 ++++++++++++++++++++++++++++ src/common/gamemode.h | 17 ++++++++++ src/common/linux/gamemode.cpp | 40 ---------------------- src/common/linux/gamemode.h | 24 ------------- src/yuzu/main.cpp | 18 +++------- src/yuzu_cmd/yuzu.cpp | 16 ++------- 9 files changed, 105 insertions(+), 98 deletions(-) create mode 100644 src/common/gamemode.cpp create mode 100644 src/common/gamemode.h delete mode 100644 src/common/linux/gamemode.cpp delete mode 100644 src/common/linux/gamemode.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d11b58bf1f..367db95709 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -474,7 +474,7 @@ else() find_package(Catch2 3.0.1 REQUIRED) endif() - if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR ANDROID) + if (PLATFORM_LINUX OR ANDROID) find_package(gamemode 1.7 MODULE) endif() diff --git a/externals/gamemode/gamemode_client.h b/externals/gamemode/gamemode_client.h index b9f64fe460..bfbf61c0c2 100644 --- a/externals/gamemode/gamemode_client.h +++ b/externals/gamemode/gamemode_client.h @@ -1,6 +1,9 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + /* -Copyright (c) 2017-2019, Feral Interactive +Copyright (c) 2017-2025, Feral Interactive and the GameMode contributors All rights reserved. Redistribution and use in source and binary forms, with or without @@ -103,6 +106,7 @@ typedef int (*api_call_pid_return_int)(pid_t); static api_call_return_int REAL_internal_gamemode_request_start = NULL; static api_call_return_int REAL_internal_gamemode_request_end = NULL; static api_call_return_int REAL_internal_gamemode_query_status = NULL; +static api_call_return_int REAL_internal_gamemode_request_restart = NULL; static api_call_return_cstring REAL_internal_gamemode_error_string = NULL; static api_call_pid_return_int REAL_internal_gamemode_request_start_for = NULL; static api_call_pid_return_int REAL_internal_gamemode_request_end_for = NULL; @@ -166,6 +170,10 @@ __attribute__((always_inline)) static inline int internal_load_libgamemode(void) (void **)&REAL_internal_gamemode_query_status, sizeof(REAL_internal_gamemode_query_status), false }, + { "real_gamemode_request_restart", + (void **)&REAL_internal_gamemode_request_restart, + sizeof(REAL_internal_gamemode_request_restart), + false }, { "real_gamemode_error_string", (void **)&REAL_internal_gamemode_error_string, sizeof(REAL_internal_gamemode_error_string), @@ -319,6 +327,24 @@ __attribute__((always_inline)) static inline int gamemode_query_status(void) return REAL_internal_gamemode_query_status(); } +/* Redirect to the real libgamemode */ +__attribute__((always_inline)) static inline int gamemode_request_restart(void) +{ + /* Need to load gamemode */ + if (internal_load_libgamemode() < 0) { + return -1; + } + + if (REAL_internal_gamemode_request_restart == NULL) { + snprintf(internal_gamemode_client_error_string, + sizeof(internal_gamemode_client_error_string), + "gamemode_request_restart missing (older host?)"); + return -1; + } + + return REAL_internal_gamemode_request_restart(); +} + /* Redirect to the real libgamemode */ __attribute__((always_inline)) static inline int gamemode_request_start_for(pid_t pid) { diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 6173e29f45..fb19bf547d 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -69,6 +69,8 @@ add_library( fs/fs_util.h fs/path_util.cpp fs/path_util.h + gamemode.cpp + gamemode.h hash.h heap_tracker.cpp heap_tracker.h @@ -191,11 +193,7 @@ if(ANDROID) android/applets/software_keyboard.h) endif() -if(LINUX AND NOT APPLE) - target_sources(common PRIVATE linux/gamemode.cpp linux/gamemode.h) - - target_link_libraries(common PRIVATE gamemode::headers) -endif() +target_link_libraries(common PRIVATE gamemode::headers) if(ARCHITECTURE_x86_64) target_sources( diff --git a/src/common/gamemode.cpp b/src/common/gamemode.cpp new file mode 100644 index 0000000000..a3f0ba37ab --- /dev/null +++ b/src/common/gamemode.cpp @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +// While technically available on al *NIX platforms, Linux is only available +// as the primary target of libgamemode.so - so warnings are suppressed +#ifdef __unix__ +#include +#endif +#include "common/gamemode.h" +#include "common/logging/log.h" +#include "common/settings.h" + +namespace Common::FeralGamemode { + +void Start() noexcept { + if (Settings::values.enable_gamemode) { +#ifdef __unix__ + if (gamemode_request_start() < 0) { +#ifdef __linux__ + LOG_WARNING(Frontend, "{}", gamemode_error_string()); +#else + LOG_INFO(Frontend, "{}", gamemode_error_string()); +#endif + } else { + LOG_INFO(Frontend, "Done"); + } +#endif + } +} + +void Stop() noexcept { + if (Settings::values.enable_gamemode) { +#ifdef __unix__ + if (gamemode_request_end() < 0) { +#ifdef __linux__ + LOG_WARNING(Frontend, "{}", gamemode_error_string()); +#else + LOG_INFO(Frontend, "{}", gamemode_error_string()); +#endif + } else { + LOG_INFO(Frontend, "Done"); + } +#endif + } +} + +} // namespace Common::Linux diff --git a/src/common/gamemode.h b/src/common/gamemode.h new file mode 100644 index 0000000000..05b1936bb5 --- /dev/null +++ b/src/common/gamemode.h @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +namespace Common::FeralGamemode { + +/// @brief Start the gamemode client +void Start() noexcept; + +/// @brief Stop the gmemode client +void Stop() noexcept; + +} // namespace Common::FeralGamemode diff --git a/src/common/linux/gamemode.cpp b/src/common/linux/gamemode.cpp deleted file mode 100644 index 8d3e2934a6..0000000000 --- a/src/common/linux/gamemode.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include - -#include "common/linux/gamemode.h" -#include "common/logging/log.h" -#include "common/settings.h" - -namespace Common::Linux { - -void StartGamemode() { - if (Settings::values.enable_gamemode) { - if (gamemode_request_start() < 0) { - LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string()); - } else { - LOG_INFO(Frontend, "Started gamemode"); - } - } -} - -void StopGamemode() { - if (Settings::values.enable_gamemode) { - if (gamemode_request_end() < 0) { - LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string()); - } else { - LOG_INFO(Frontend, "Stopped gamemode"); - } - } -} - -void SetGamemodeState(bool state) { - if (state) { - StartGamemode(); - } else { - StopGamemode(); - } -} - -} // namespace Common::Linux diff --git a/src/common/linux/gamemode.h b/src/common/linux/gamemode.h deleted file mode 100644 index b80646ae27..0000000000 --- a/src/common/linux/gamemode.h +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -namespace Common::Linux { - -/** - * Start the (Feral Interactive) Linux gamemode if it is installed and it is activated - */ -void StartGamemode(); - -/** - * Stop the (Feral Interactive) Linux gamemode if it is installed and it is activated - */ -void StopGamemode(); - -/** - * Start or stop the (Feral Interactive) Linux gamemode if it is installed and it is activated - * @param state The new state the gamemode should have - */ -void SetGamemodeState(bool state); - -} // namespace Common::Linux diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 2c3c46114d..1b6c5941dd 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -21,9 +21,7 @@ #include #include #endif -#ifdef __linux__ -#include "common/linux/gamemode.h" -#endif +#include "common/gamemode.h" #include @@ -2388,9 +2386,7 @@ void GMainWindow::OnEmulationStopped() { discord_rpc->Update(); -#ifdef __linux__ - Common::Linux::StopGamemode(); -#endif + Common::FeralGamemode::Stop(); // The emulation is stopped, so closing the window or not does not matter anymore disconnect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); @@ -3573,10 +3569,7 @@ void GMainWindow::OnStartGame() { play_time_manager->Start(); discord_rpc->Update(); - -#ifdef __linux__ - Common::Linux::StartGamemode(); -#endif + Common::FeralGamemode::StartGamemode(); } void GMainWindow::OnRestartGame() { @@ -3597,10 +3590,7 @@ void GMainWindow::OnPauseGame() { play_time_manager->Stop(); UpdateMenuState(); AllowOSSleep(); - -#ifdef __linux__ - Common::Linux::StopGamemode(); -#endif + Common::FeralGamemode::Stop(); } void GMainWindow::OnPauseContinueGame() { diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 599582aba9..7400b48e47 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -63,10 +63,7 @@ __declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; } #endif - -#ifdef __linux__ -#include "common/linux/gamemode.h" -#endif +#include "common/gamemode.h" static void PrintHelp(const char* argv0) { std::cout << "Usage: " << argv0 @@ -435,10 +432,7 @@ int main(int argc, char** argv) { // Just exit right away. exit(0); }); - -#ifdef __linux__ - Common::Linux::StartGamemode(); -#endif + Common::FeralGamemode::StartGamemode(); void(system.Run()); if (system.DebuggerEnabled()) { @@ -450,11 +444,7 @@ int main(int argc, char** argv) { system.DetachDebugger(); void(system.Pause()); system.ShutdownMainProcess(); - -#ifdef __linux__ - Common::Linux::StopGamemode(); -#endif - + Common::FeralGamemode::Stop(); detached_tasks.WaitForAllTasks(); return 0; } From 667e3c1fb5b4b6dfc7a8f19bcb1ac61badb440c6 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 30 Aug 2025 00:04:36 +0000 Subject: [PATCH 2/7] [gamemode] make option available on all nixes Signed-off-by: lizzie --- src/yuzu/main.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 1b6c5941dd..c09697d3ed 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -424,10 +424,7 @@ GMainWindow::GMainWindow(bool has_broken_vulkan) #ifdef __unix__ SetupSigInterrupts(); #endif - -#ifdef __linux__ SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue()); -#endif UISettings::RestoreWindowState(config); @@ -3885,9 +3882,7 @@ void GMainWindow::OnConfigure() { const auto old_theme = UISettings::values.theme; const bool old_discord_presence = UISettings::values.enable_discord_presence.GetValue(); const auto old_language_index = Settings::values.language_index.GetValue(); -#ifdef __linux__ const bool old_gamemode = Settings::values.enable_gamemode.GetValue(); -#endif Settings::SetConfiguringGlobal(true); ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), @@ -3947,11 +3942,9 @@ void GMainWindow::OnConfigure() { if (UISettings::values.enable_discord_presence.GetValue() != old_discord_presence) { SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); } -#ifdef __linux__ if (Settings::values.enable_gamemode.GetValue() != old_gamemode) { SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue()); } -#endif if (!multiplayer_state->IsHostingPublicRoom()) { multiplayer_state->UpdateCredentials(); @@ -5560,13 +5553,15 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) { discord_rpc->Update(); } -#ifdef __linux__ void GMainWindow::SetGamemodeEnabled(bool state) { if (emulation_running) { - Common::Linux::SetGamemodeState(state); + if (state) { + Common::FeralGamemode::Start(); + } else { + Common::FeralGamemode::Stop(); + } } } -#endif void GMainWindow::changeEvent(QEvent* event) { #ifdef __unix__ @@ -5730,7 +5725,7 @@ int main(int argc, char* argv[]) { chdir(Common::FS::PathToUTF8String(bin_path).c_str()); #endif -#ifdef __linux__ +#ifdef __unix__ // Set the DISPLAY variable in order to open web browsers // TODO (lat9nq): Find a better solution for AppImages to start external applications if (QString::fromLocal8Bit(qgetenv("DISPLAY")).isEmpty()) { From 26db1fb807490104ba3759fae0188b2d7dd98a2f Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 30 Aug 2025 08:43:59 +0000 Subject: [PATCH 3/7] [gamemode] extra win/lin/macos fixes Signed-off-by: lizzie --- externals/CMakeLists.txt | 2 +- src/yuzu/main.cpp | 2 +- src/yuzu_cmd/yuzu.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index b209b48db9..f0c2394d16 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -179,7 +179,7 @@ if (ANDROID AND ARCHITECTURE_arm64) AddJsonPackage(libadrenotools) endif() -if (UNIX AND NOT APPLE AND NOT TARGET gamemode::headers) +if (NOT TARGET gamemode::headers) add_library(gamemode INTERFACE) target_include_directories(gamemode INTERFACE gamemode) add_library(gamemode::headers ALIAS gamemode) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index c09697d3ed..b07c68b622 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -3566,7 +3566,7 @@ void GMainWindow::OnStartGame() { play_time_manager->Start(); discord_rpc->Update(); - Common::FeralGamemode::StartGamemode(); + Common::FeralGamemode::Start(); } void GMainWindow::OnRestartGame() { diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 7400b48e47..62ca70850c 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -432,7 +432,7 @@ int main(int argc, char** argv) { // Just exit right away. exit(0); }); - Common::FeralGamemode::StartGamemode(); + Common::FeralGamemode::Start(); void(system.Run()); if (system.DebuggerEnabled()) { From 47b703067e51b6d418f561eae261529442d13f28 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 30 Aug 2025 15:17:30 +0200 Subject: [PATCH 4/7] [settings] fix unreachable code warning in fastmem bool (#347) Signed-off-by: lizzie Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/347 Reviewed-by: Shinmegumi Reviewed-by: CamilleLaVey Co-authored-by: lizzie Co-committed-by: lizzie --- src/common/settings.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 19140bce0d..d4f16f4853 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -163,8 +163,9 @@ bool IsFastmemEnabled() { } #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun__) return false; -#endif +#else return true; +#endif } static bool is_nce_enabled = false; From bae2a395e27f80d53017a60a7a5f986f2fb39d95 Mon Sep 17 00:00:00 2001 From: lizzie Date: Fri, 29 Aug 2025 23:48:25 +0000 Subject: [PATCH 5/7] [gamemode] Make available on other platforms Signed-off-by: lizzie --- CMakeLists.txt | 2 +- externals/gamemode/gamemode_client.h | 28 +++++++++++++++- src/common/CMakeLists.txt | 8 ++--- src/common/gamemode.cpp | 50 ++++++++++++++++++++++++++++ src/common/gamemode.h | 17 ++++++++++ src/common/linux/gamemode.cpp | 40 ---------------------- src/common/linux/gamemode.h | 24 ------------- src/yuzu/main.cpp | 18 +++------- src/yuzu_cmd/yuzu.cpp | 16 ++------- 9 files changed, 105 insertions(+), 98 deletions(-) create mode 100644 src/common/gamemode.cpp create mode 100644 src/common/gamemode.h delete mode 100644 src/common/linux/gamemode.cpp delete mode 100644 src/common/linux/gamemode.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d11b58bf1f..367db95709 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -474,7 +474,7 @@ else() find_package(Catch2 3.0.1 REQUIRED) endif() - if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR ANDROID) + if (PLATFORM_LINUX OR ANDROID) find_package(gamemode 1.7 MODULE) endif() diff --git a/externals/gamemode/gamemode_client.h b/externals/gamemode/gamemode_client.h index b9f64fe460..bfbf61c0c2 100644 --- a/externals/gamemode/gamemode_client.h +++ b/externals/gamemode/gamemode_client.h @@ -1,6 +1,9 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + /* -Copyright (c) 2017-2019, Feral Interactive +Copyright (c) 2017-2025, Feral Interactive and the GameMode contributors All rights reserved. Redistribution and use in source and binary forms, with or without @@ -103,6 +106,7 @@ typedef int (*api_call_pid_return_int)(pid_t); static api_call_return_int REAL_internal_gamemode_request_start = NULL; static api_call_return_int REAL_internal_gamemode_request_end = NULL; static api_call_return_int REAL_internal_gamemode_query_status = NULL; +static api_call_return_int REAL_internal_gamemode_request_restart = NULL; static api_call_return_cstring REAL_internal_gamemode_error_string = NULL; static api_call_pid_return_int REAL_internal_gamemode_request_start_for = NULL; static api_call_pid_return_int REAL_internal_gamemode_request_end_for = NULL; @@ -166,6 +170,10 @@ __attribute__((always_inline)) static inline int internal_load_libgamemode(void) (void **)&REAL_internal_gamemode_query_status, sizeof(REAL_internal_gamemode_query_status), false }, + { "real_gamemode_request_restart", + (void **)&REAL_internal_gamemode_request_restart, + sizeof(REAL_internal_gamemode_request_restart), + false }, { "real_gamemode_error_string", (void **)&REAL_internal_gamemode_error_string, sizeof(REAL_internal_gamemode_error_string), @@ -319,6 +327,24 @@ __attribute__((always_inline)) static inline int gamemode_query_status(void) return REAL_internal_gamemode_query_status(); } +/* Redirect to the real libgamemode */ +__attribute__((always_inline)) static inline int gamemode_request_restart(void) +{ + /* Need to load gamemode */ + if (internal_load_libgamemode() < 0) { + return -1; + } + + if (REAL_internal_gamemode_request_restart == NULL) { + snprintf(internal_gamemode_client_error_string, + sizeof(internal_gamemode_client_error_string), + "gamemode_request_restart missing (older host?)"); + return -1; + } + + return REAL_internal_gamemode_request_restart(); +} + /* Redirect to the real libgamemode */ __attribute__((always_inline)) static inline int gamemode_request_start_for(pid_t pid) { diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 6173e29f45..fb19bf547d 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -69,6 +69,8 @@ add_library( fs/fs_util.h fs/path_util.cpp fs/path_util.h + gamemode.cpp + gamemode.h hash.h heap_tracker.cpp heap_tracker.h @@ -191,11 +193,7 @@ if(ANDROID) android/applets/software_keyboard.h) endif() -if(LINUX AND NOT APPLE) - target_sources(common PRIVATE linux/gamemode.cpp linux/gamemode.h) - - target_link_libraries(common PRIVATE gamemode::headers) -endif() +target_link_libraries(common PRIVATE gamemode::headers) if(ARCHITECTURE_x86_64) target_sources( diff --git a/src/common/gamemode.cpp b/src/common/gamemode.cpp new file mode 100644 index 0000000000..a3f0ba37ab --- /dev/null +++ b/src/common/gamemode.cpp @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +// While technically available on al *NIX platforms, Linux is only available +// as the primary target of libgamemode.so - so warnings are suppressed +#ifdef __unix__ +#include +#endif +#include "common/gamemode.h" +#include "common/logging/log.h" +#include "common/settings.h" + +namespace Common::FeralGamemode { + +void Start() noexcept { + if (Settings::values.enable_gamemode) { +#ifdef __unix__ + if (gamemode_request_start() < 0) { +#ifdef __linux__ + LOG_WARNING(Frontend, "{}", gamemode_error_string()); +#else + LOG_INFO(Frontend, "{}", gamemode_error_string()); +#endif + } else { + LOG_INFO(Frontend, "Done"); + } +#endif + } +} + +void Stop() noexcept { + if (Settings::values.enable_gamemode) { +#ifdef __unix__ + if (gamemode_request_end() < 0) { +#ifdef __linux__ + LOG_WARNING(Frontend, "{}", gamemode_error_string()); +#else + LOG_INFO(Frontend, "{}", gamemode_error_string()); +#endif + } else { + LOG_INFO(Frontend, "Done"); + } +#endif + } +} + +} // namespace Common::Linux diff --git a/src/common/gamemode.h b/src/common/gamemode.h new file mode 100644 index 0000000000..05b1936bb5 --- /dev/null +++ b/src/common/gamemode.h @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +namespace Common::FeralGamemode { + +/// @brief Start the gamemode client +void Start() noexcept; + +/// @brief Stop the gmemode client +void Stop() noexcept; + +} // namespace Common::FeralGamemode diff --git a/src/common/linux/gamemode.cpp b/src/common/linux/gamemode.cpp deleted file mode 100644 index 8d3e2934a6..0000000000 --- a/src/common/linux/gamemode.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include - -#include "common/linux/gamemode.h" -#include "common/logging/log.h" -#include "common/settings.h" - -namespace Common::Linux { - -void StartGamemode() { - if (Settings::values.enable_gamemode) { - if (gamemode_request_start() < 0) { - LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string()); - } else { - LOG_INFO(Frontend, "Started gamemode"); - } - } -} - -void StopGamemode() { - if (Settings::values.enable_gamemode) { - if (gamemode_request_end() < 0) { - LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string()); - } else { - LOG_INFO(Frontend, "Stopped gamemode"); - } - } -} - -void SetGamemodeState(bool state) { - if (state) { - StartGamemode(); - } else { - StopGamemode(); - } -} - -} // namespace Common::Linux diff --git a/src/common/linux/gamemode.h b/src/common/linux/gamemode.h deleted file mode 100644 index b80646ae27..0000000000 --- a/src/common/linux/gamemode.h +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -namespace Common::Linux { - -/** - * Start the (Feral Interactive) Linux gamemode if it is installed and it is activated - */ -void StartGamemode(); - -/** - * Stop the (Feral Interactive) Linux gamemode if it is installed and it is activated - */ -void StopGamemode(); - -/** - * Start or stop the (Feral Interactive) Linux gamemode if it is installed and it is activated - * @param state The new state the gamemode should have - */ -void SetGamemodeState(bool state); - -} // namespace Common::Linux diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 2c3c46114d..1b6c5941dd 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -21,9 +21,7 @@ #include #include #endif -#ifdef __linux__ -#include "common/linux/gamemode.h" -#endif +#include "common/gamemode.h" #include @@ -2388,9 +2386,7 @@ void GMainWindow::OnEmulationStopped() { discord_rpc->Update(); -#ifdef __linux__ - Common::Linux::StopGamemode(); -#endif + Common::FeralGamemode::Stop(); // The emulation is stopped, so closing the window or not does not matter anymore disconnect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); @@ -3573,10 +3569,7 @@ void GMainWindow::OnStartGame() { play_time_manager->Start(); discord_rpc->Update(); - -#ifdef __linux__ - Common::Linux::StartGamemode(); -#endif + Common::FeralGamemode::StartGamemode(); } void GMainWindow::OnRestartGame() { @@ -3597,10 +3590,7 @@ void GMainWindow::OnPauseGame() { play_time_manager->Stop(); UpdateMenuState(); AllowOSSleep(); - -#ifdef __linux__ - Common::Linux::StopGamemode(); -#endif + Common::FeralGamemode::Stop(); } void GMainWindow::OnPauseContinueGame() { diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 599582aba9..7400b48e47 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -63,10 +63,7 @@ __declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; } #endif - -#ifdef __linux__ -#include "common/linux/gamemode.h" -#endif +#include "common/gamemode.h" static void PrintHelp(const char* argv0) { std::cout << "Usage: " << argv0 @@ -435,10 +432,7 @@ int main(int argc, char** argv) { // Just exit right away. exit(0); }); - -#ifdef __linux__ - Common::Linux::StartGamemode(); -#endif + Common::FeralGamemode::StartGamemode(); void(system.Run()); if (system.DebuggerEnabled()) { @@ -450,11 +444,7 @@ int main(int argc, char** argv) { system.DetachDebugger(); void(system.Pause()); system.ShutdownMainProcess(); - -#ifdef __linux__ - Common::Linux::StopGamemode(); -#endif - + Common::FeralGamemode::Stop(); detached_tasks.WaitForAllTasks(); return 0; } From 208645deff260a4305054c086f54eac8aca97573 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 30 Aug 2025 00:04:36 +0000 Subject: [PATCH 6/7] [gamemode] make option available on all nixes Signed-off-by: lizzie --- src/yuzu/main.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 1b6c5941dd..c09697d3ed 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -424,10 +424,7 @@ GMainWindow::GMainWindow(bool has_broken_vulkan) #ifdef __unix__ SetupSigInterrupts(); #endif - -#ifdef __linux__ SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue()); -#endif UISettings::RestoreWindowState(config); @@ -3885,9 +3882,7 @@ void GMainWindow::OnConfigure() { const auto old_theme = UISettings::values.theme; const bool old_discord_presence = UISettings::values.enable_discord_presence.GetValue(); const auto old_language_index = Settings::values.language_index.GetValue(); -#ifdef __linux__ const bool old_gamemode = Settings::values.enable_gamemode.GetValue(); -#endif Settings::SetConfiguringGlobal(true); ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), @@ -3947,11 +3942,9 @@ void GMainWindow::OnConfigure() { if (UISettings::values.enable_discord_presence.GetValue() != old_discord_presence) { SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); } -#ifdef __linux__ if (Settings::values.enable_gamemode.GetValue() != old_gamemode) { SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue()); } -#endif if (!multiplayer_state->IsHostingPublicRoom()) { multiplayer_state->UpdateCredentials(); @@ -5560,13 +5553,15 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) { discord_rpc->Update(); } -#ifdef __linux__ void GMainWindow::SetGamemodeEnabled(bool state) { if (emulation_running) { - Common::Linux::SetGamemodeState(state); + if (state) { + Common::FeralGamemode::Start(); + } else { + Common::FeralGamemode::Stop(); + } } } -#endif void GMainWindow::changeEvent(QEvent* event) { #ifdef __unix__ @@ -5730,7 +5725,7 @@ int main(int argc, char* argv[]) { chdir(Common::FS::PathToUTF8String(bin_path).c_str()); #endif -#ifdef __linux__ +#ifdef __unix__ // Set the DISPLAY variable in order to open web browsers // TODO (lat9nq): Find a better solution for AppImages to start external applications if (QString::fromLocal8Bit(qgetenv("DISPLAY")).isEmpty()) { From 012d0d48ae8c8f4e103bd1f7a1a2e833982a5931 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 30 Aug 2025 08:43:59 +0000 Subject: [PATCH 7/7] [gamemode] extra win/lin/macos fixes Signed-off-by: lizzie --- externals/CMakeLists.txt | 2 +- src/yuzu/main.cpp | 2 +- src/yuzu_cmd/yuzu.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index b209b48db9..f0c2394d16 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -179,7 +179,7 @@ if (ANDROID AND ARCHITECTURE_arm64) AddJsonPackage(libadrenotools) endif() -if (UNIX AND NOT APPLE AND NOT TARGET gamemode::headers) +if (NOT TARGET gamemode::headers) add_library(gamemode INTERFACE) target_include_directories(gamemode INTERFACE gamemode) add_library(gamemode::headers ALIAS gamemode) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index c09697d3ed..b07c68b622 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -3566,7 +3566,7 @@ void GMainWindow::OnStartGame() { play_time_manager->Start(); discord_rpc->Update(); - Common::FeralGamemode::StartGamemode(); + Common::FeralGamemode::Start(); } void GMainWindow::OnRestartGame() { diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 7400b48e47..62ca70850c 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -432,7 +432,7 @@ int main(int argc, char** argv) { // Just exit right away. exit(0); }); - Common::FeralGamemode::StartGamemode(); + Common::FeralGamemode::Start(); void(system.Run()); if (system.DebuggerEnabled()) {