yuzu: create linux group in general settings

- Create files dedicated to starting and stopping gamemode functions
  - Use them in yuzu and yuzu_cmd modules
This commit is contained in:
flodavid 2023-11-03 15:41:16 +01:00
parent dfa56765d6
commit 40644d43f7
16 changed files with 177 additions and 81 deletions

View File

@ -189,8 +189,7 @@ if (ANDROID)
endif() endif()
endif() endif()
# Gamemode if (UNIX)
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
add_subdirectory(gamemode) add_subdirectory(gamemode)
target_include_directories(gamemode PUBLIC gamemode/include) target_include_directories(gamemode PUBLIC gamemode/include)
endif() endif()

View File

@ -4,4 +4,8 @@
project(gamemode) project(gamemode)
add_library(gamemode include/gamemode_client.h) add_library(gamemode include/gamemode_client.h)
target_link_libraries(gamemode PRIVATE common)
target_include_directories(gamemode PUBLIC include)
set_target_properties(gamemode PROPERTIES LINKER_LANGUAGE C) set_target_properties(gamemode PROPERTIES LINKER_LANGUAGE C)

View File

@ -174,6 +174,15 @@ if(ANDROID)
) )
endif() endif()
if (UNIX)
target_sources(common PRIVATE
linux/gamemode.cpp
linux/gamemode.h
)
target_link_libraries(common PRIVATE gamemode)
endif()
if(ARCHITECTURE_x86_64) if(ARCHITECTURE_x86_64)
target_sources(common target_sources(common
PRIVATE PRIVATE

View File

@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <gamemode_client.h>
#include "common/linux/gamemode.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

View File

@ -0,0 +1,24 @@
// 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

View File

@ -219,6 +219,8 @@ const char* TranslateCategory(Category category) {
return "Services"; return "Services";
case Category::Paths: case Category::Paths:
return "Paths"; return "Paths";
case Category::Linux:
return "Linux";
case Category::MaxEnum: case Category::MaxEnum:
break; break;
} }

View File

@ -178,8 +178,6 @@ struct Values {
true, true,
&use_speed_limit}; &use_speed_limit};
Setting<bool> enable_gamemode{linkage, false, "enable_gamemode", Category::Core};
// Cpu // Cpu
SwitchableSetting<CpuAccuracy, true> cpu_accuracy{linkage, CpuAccuracy::Auto, SwitchableSetting<CpuAccuracy, true> cpu_accuracy{linkage, CpuAccuracy::Auto,
CpuAccuracy::Auto, CpuAccuracy::Paranoid, CpuAccuracy::Auto, CpuAccuracy::Paranoid,
@ -429,6 +427,9 @@ struct Values {
true, true,
true}; true};
// Linux
SwitchableSetting<bool> enable_gamemode{linkage, true, "enable_gamemode", Category::Linux};
// Controls // Controls
InputSetting<std::array<PlayerInput, 10>> players; InputSetting<std::array<PlayerInput, 10>> players;

View File

@ -41,6 +41,7 @@ enum class Category : u32 {
Multiplayer, Multiplayer,
Services, Services,
Paths, Paths,
Linux,
MaxEnum, MaxEnum,
}; };

View File

@ -29,9 +29,6 @@ ConfigureGeneral::ConfigureGeneral(const Core::System& system_,
if (!Settings::IsConfiguringGlobal()) { if (!Settings::IsConfiguringGlobal()) {
ui->button_reset_defaults->setVisible(false); ui->button_reset_defaults->setVisible(false);
} }
#ifndef __linux__
ui->enable_gamemode->setVisible(false);
#endif
} }
ConfigureGeneral::~ConfigureGeneral() = default; ConfigureGeneral::~ConfigureGeneral() = default;
@ -39,12 +36,29 @@ ConfigureGeneral::~ConfigureGeneral() = default;
void ConfigureGeneral::SetConfiguration() {} void ConfigureGeneral::SetConfiguration() {}
void ConfigureGeneral::Setup(const ConfigurationShared::Builder& builder) { void ConfigureGeneral::Setup(const ConfigurationShared::Builder& builder) {
QLayout& layout = *ui->general_widget->layout(); QLayout& general_layout = *ui->general_widget->layout();
QLayout& linux_layout = *ui->linux_widget->layout();
std::map<u32, QWidget*> hold{}; std::map<u32, QWidget*> general_hold{};
std::map<u32, QWidget*> linux_hold{};
for (const auto setting : std::vector<Settings::BasicSetting*> settings;
UISettings::values.linkage.by_category[Settings::Category::UiGeneral]) {
auto push = [&settings](auto& list) {
for (auto setting : list) {
settings.push_back(setting);
}
};
push(UISettings::values.linkage.by_category[Settings::Category::UiGeneral]);
push(Settings::values.linkage.by_category[Settings::Category::Linux]);
// Only show Linux group on Unix
#ifndef __unix__
ui->LinuxGroupBox->setVisible(false);
#endif
for (const auto setting : settings) {
auto* widget = builder.BuildWidget(setting, apply_funcs); auto* widget = builder.BuildWidget(setting, apply_funcs);
if (widget == nullptr) { if (widget == nullptr) {
@ -55,11 +69,23 @@ void ConfigureGeneral::Setup(const ConfigurationShared::Builder& builder) {
continue; continue;
} }
hold.emplace(setting->Id(), widget); switch (setting->GetCategory()) {
case Settings::Category::UiGeneral:
general_hold.emplace(setting->Id(), widget);
break;
case Settings::Category::Linux:
linux_hold.emplace(setting->Id(), widget);
break;
default:
widget->deleteLater();
}
} }
for (const auto& [id, widget] : hold) { for (const auto& [id, widget] : general_hold) {
layout.addWidget(widget); general_layout.addWidget(widget);
}
for (const auto& [id, widget] : linux_hold) {
linux_layout.addWidget(widget);
} }
} }

View File

@ -46,6 +46,33 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="LinuxGroupBox">
<property name="title">
<string>Linux</string>
</property>
<layout class="QVBoxLayout" name="LinuxVerticalLayout_1">
<item>
<widget class="QWidget" name="linux_widget" native="true">
<layout class="QVBoxLayout" name="LinuxVerticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">

View File

@ -57,7 +57,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="coreGroup">
<property name="title"> <property name="title">
<string>Core</string> <string>Core</string>
</property> </property>

View File

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

View File

@ -17,6 +17,7 @@
#ifdef __unix__ #ifdef __unix__
#include <csignal> #include <csignal>
#include <sys/socket.h> #include <sys/socket.h>
#include "common/linux/gamemode.h"
#endif #endif
#include <boost/container/flat_set.hpp> #include <boost/container/flat_set.hpp>
@ -185,10 +186,6 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
} }
#endif #endif
#ifdef __linux__
#include <gamemode_client.h>
#endif
constexpr int default_mouse_hide_timeout = 2500; constexpr int default_mouse_hide_timeout = 2500;
constexpr int default_mouse_center_timeout = 10; constexpr int default_mouse_center_timeout = 10;
constexpr int default_input_update_timeout = 1; constexpr int default_input_update_timeout = 1;
@ -323,6 +320,7 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk
provider{std::make_unique<FileSys::ManualContentProvider>()} { provider{std::make_unique<FileSys::ManualContentProvider>()} {
#ifdef __unix__ #ifdef __unix__
SetupSigInterrupts(); SetupSigInterrupts();
SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue());
#endif #endif
system->Initialize(); system->Initialize();
@ -2130,14 +2128,8 @@ void GMainWindow::OnEmulationStopped() {
discord_rpc->Update(); discord_rpc->Update();
#ifdef __linux__ #ifdef __unix__
if (UISettings::values.enable_gamemode) { Common::Linux::StopGamemode();
if (gamemode_request_end() < 0) {
LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Stopped gamemode");
}
}
#endif #endif
// The emulation is stopped, so closing the window or not does not matter anymore // The emulation is stopped, so closing the window or not does not matter anymore
@ -3519,14 +3511,8 @@ void GMainWindow::OnStartGame() {
discord_rpc->Update(); discord_rpc->Update();
#ifdef __linux__ #ifdef __unix__
if (UISettings::values.enable_gamemode) { Common::Linux::StartGamemode();
if (gamemode_request_start() < 0) {
LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Started gamemode");
}
}
#endif #endif
} }
@ -3549,14 +3535,8 @@ void GMainWindow::OnPauseGame() {
UpdateMenuState(); UpdateMenuState();
AllowOSSleep(); AllowOSSleep();
#ifdef __linux__ #ifdef __unix__
if (UISettings::values.enable_gamemode) { Common::Linux::StopGamemode();
if (gamemode_request_end() < 0) {
LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Stopped gamemode");
}
}
#endif #endif
} }
@ -3839,6 +3819,9 @@ void GMainWindow::OnConfigure() {
const auto old_theme = UISettings::values.theme; const auto old_theme = UISettings::values.theme;
const bool old_discord_presence = UISettings::values.enable_discord_presence.GetValue(); const bool old_discord_presence = UISettings::values.enable_discord_presence.GetValue();
const auto old_language_index = Settings::values.language_index.GetValue(); const auto old_language_index = Settings::values.language_index.GetValue();
#ifdef __unix__
const bool old_gamemode = Settings::values.enable_gamemode.GetValue();
#endif
Settings::SetConfiguringGlobal(true); Settings::SetConfiguringGlobal(true);
ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(),
@ -3900,6 +3883,11 @@ void GMainWindow::OnConfigure() {
if (UISettings::values.enable_discord_presence.GetValue() != old_discord_presence) { if (UISettings::values.enable_discord_presence.GetValue() != old_discord_presence) {
SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue());
} }
#ifdef __unix__
if (Settings::values.enable_gamemode.GetValue() != old_gamemode) {
SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue());
}
#endif
if (!multiplayer_state->IsHostingPublicRoom()) { if (!multiplayer_state->IsHostingPublicRoom()) {
multiplayer_state->UpdateCredentials(); multiplayer_state->UpdateCredentials();
@ -5215,25 +5203,13 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) {
discord_rpc->Update(); discord_rpc->Update();
} }
void GMainWindow::SetGamemodeDisabled([[maybe_unused]] bool state) { #ifdef __unix__
#ifdef __linux__ void GMainWindow::SetGamemodeEnabled(bool state) {
if (emulation_running) { if (emulation_running) {
if (state) { Common::Linux::SetGamemodeState(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
} }
#endif
void GMainWindow::changeEvent(QEvent* event) { void GMainWindow::changeEvent(QEvent* event) {
#ifdef __unix__ #ifdef __unix__

View File

@ -340,6 +340,7 @@ private:
void SetupSigInterrupts(); void SetupSigInterrupts();
static void HandleSigInterrupt(int); static void HandleSigInterrupt(int);
void OnSigInterruptNotifierActivated(); void OnSigInterruptNotifierActivated();
void SetGamemodeEnabled(bool state);
#endif #endif
private slots: private slots:

View File

@ -140,9 +140,6 @@ struct Values {
Settings::Specialization::Default, Settings::Specialization::Default,
true, true,
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}; Setting<bool> disable_web_applet{linkage, true, "disable_web_applet", Category::Ui};
// Discord RPC // Discord RPC

View File

@ -63,8 +63,8 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
} }
#endif #endif
#ifdef __linux__ #ifdef __unix__
#include <gamemode_client.h> #include "common/linux/gamemode.h"
#endif #endif
static void PrintHelp(const char* argv0) { static void PrintHelp(const char* argv0) {
@ -429,14 +429,8 @@ int main(int argc, char** argv) {
exit(0); exit(0);
}); });
#ifdef __linux__ #ifdef __unix__
if (Settings::values.disable_gamemode) { Common::Linux::StartGamemode();
if (gamemode_request_start() < 0) {
LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Started gamemode");
}
}
#endif #endif
void(system.Run()); void(system.Run());
@ -450,14 +444,8 @@ int main(int argc, char** argv) {
void(system.Pause()); void(system.Pause());
system.ShutdownMainProcess(); system.ShutdownMainProcess();
#ifdef __linux__ #ifdef __unix__
if (Settings::values.disable_gamemode) { Common::Linux::StopGamemode();
if (gamemode_request_end() < 0) {
LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
} else {
LOG_INFO(Frontend, "Stopped gamemode");
}
}
#endif #endif
detached_tasks.WaitForAllTasks(); detached_tasks.WaitForAllTasks();