yuzu: integrate gamemode support on linux

This commit is contained in:
xcfrg 2023-07-16 18:45:33 -04:00 committed by flodavid
parent 5a182f4e7c
commit dfa56765d6
11 changed files with 481 additions and 1 deletions

View file

@ -178,6 +178,8 @@ struct Values {
true,
&use_speed_limit};
Setting<bool> enable_gamemode{linkage, false, "enable_gamemode", Category::Core};
// Cpu
SwitchableSetting<CpuAccuracy, true> cpu_accuracy{linkage, CpuAccuracy::Auto,
CpuAccuracy::Auto, CpuAccuracy::Paranoid,

View file

@ -386,7 +386,7 @@ if (NOT WIN32)
target_include_directories(yuzu PRIVATE ${Qt${QT_MAJOR_VERSION}Gui_PRIVATE_INCLUDE_DIRS})
endif()
if (UNIX AND NOT APPLE)
target_link_libraries(yuzu PRIVATE Qt${QT_MAJOR_VERSION}::DBus)
target_link_libraries(yuzu PRIVATE Qt${QT_MAJOR_VERSION}::DBus gamemode)
endif()
target_compile_definitions(yuzu PRIVATE

View file

@ -29,6 +29,9 @@ ConfigureGeneral::ConfigureGeneral(const Core::System& system_,
if (!Settings::IsConfiguringGlobal()) {
ui->button_reset_defaults->setVisible(false);
}
#ifndef __linux__
ui->enable_gamemode->setVisible(false);
#endif
}
ConfigureGeneral::~ConfigureGeneral() = default;

View file

@ -175,6 +175,7 @@ std::unique_ptr<TranslationMap> InitializeTranslations(QWidget* parent) {
INSERT(UISettings, hide_mouse, tr("Hide mouse on inactivity"), QStringLiteral());
INSERT(UISettings, controller_applet_disabled, tr("Disable controller applet"),
QStringLiteral());
INSERT(UISettings, enable_gamemode, tr("Enable Gamemode"), QStringLiteral());
// Ui Debugging

View file

@ -185,6 +185,10 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
#endif
#ifdef __linux__
#include <gamemode_client.h>
#endif
constexpr int default_mouse_hide_timeout = 2500;
constexpr int default_mouse_center_timeout = 10;
constexpr int default_input_update_timeout = 1;
@ -2126,6 +2130,16 @@ void GMainWindow::OnEmulationStopped() {
discord_rpc->Update();
#ifdef __linux__
if (UISettings::values.enable_gamemode) {
if (gamemode_request_end() < 0) {
LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Stopped gamemode");
}
}
#endif
// The emulation is stopped, so closing the window or not does not matter anymore
disconnect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame);
@ -3504,6 +3518,16 @@ void GMainWindow::OnStartGame() {
play_time_manager->Start();
discord_rpc->Update();
#ifdef __linux__
if (UISettings::values.enable_gamemode) {
if (gamemode_request_start() < 0) {
LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Started gamemode");
}
}
#endif
}
void GMainWindow::OnRestartGame() {
@ -3524,6 +3548,16 @@ void GMainWindow::OnPauseGame() {
play_time_manager->Stop();
UpdateMenuState();
AllowOSSleep();
#ifdef __linux__
if (UISettings::values.enable_gamemode) {
if (gamemode_request_end() < 0) {
LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Stopped gamemode");
}
}
#endif
}
void GMainWindow::OnPauseContinueGame() {
@ -5181,6 +5215,26 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) {
discord_rpc->Update();
}
void GMainWindow::SetGamemodeDisabled([[maybe_unused]] bool state) {
#ifdef __linux__
if (emulation_running) {
if (state) {
if (gamemode_request_end() < 0) {
LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Stopped gamemode");
}
} else {
if (gamemode_request_start() < 0) {
LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Started gamemode");
}
}
}
#endif
}
void GMainWindow::changeEvent(QEvent* event) {
#ifdef __unix__
// PaletteChange event appears to only reach so far into the GUI, explicitly asking to

View file

@ -140,6 +140,9 @@ struct Values {
Settings::Specialization::Default,
true,
true};
// Gamemode
Setting<bool> enable_gamemode{linkage, false, "enable_gamemode", Category::UiGeneral};
Setting<bool> disable_web_applet{linkage, true, "disable_web_applet", Category::Ui};
// Discord RPC

View file

@ -44,6 +44,7 @@ target_link_libraries(yuzu-cmd PRIVATE SDL2::SDL2 Vulkan::Headers)
if(UNIX AND NOT APPLE)
install(TARGETS yuzu-cmd)
target_link_libraries(yuzu-cmd PRIVATE gamemode)
endif()
if(WIN32)

View file

@ -63,6 +63,10 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
#endif
#ifdef __linux__
#include <gamemode_client.h>
#endif
static void PrintHelp(const char* argv0) {
std::cout << "Usage: " << argv0
<< " [options] <filename>\n"
@ -425,6 +429,16 @@ int main(int argc, char** argv) {
exit(0);
});
#ifdef __linux__
if (Settings::values.disable_gamemode) {
if (gamemode_request_start() < 0) {
LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Started gamemode");
}
}
#endif
void(system.Run());
if (system.DebuggerEnabled()) {
system.InitializeDebugger();
@ -436,6 +450,16 @@ int main(int argc, char** argv) {
void(system.Pause());
system.ShutdownMainProcess();
#ifdef __linux__
if (Settings::values.disable_gamemode) {
if (gamemode_request_end() < 0) {
LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Stopped gamemode");
}
}
#endif
detached_tasks.WaitForAllTasks();
return 0;
}