This commit is contained in:
AnimeGIF 2025-04-27 17:36:33 +01:00 committed by GitHub
commit b99e890c8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 604 additions and 8 deletions

View file

@ -343,6 +343,15 @@ void CemuConfig::Load(XMLConfigParser& parser)
dsu_client.host = dsuc.get_attribute("host", dsu_client.host); dsu_client.host = dsuc.get_attribute("host", dsu_client.host);
dsu_client.port = dsuc.get_attribute("port", dsu_client.port); dsu_client.port = dsuc.get_attribute("port", dsu_client.port);
// hotkeys
auto xml_hotkeys = parser.get("Hotkeys");
hotkeys.modifiers = xml_hotkeys.get("modifiers", sHotkeyCfg{});
hotkeys.exitFullscreen = xml_hotkeys.get("ExitFullscreen", sHotkeyCfg{uKeyboardHotkey{WXK_ESCAPE}});
hotkeys.toggleFullscreen = xml_hotkeys.get("ToggleFullscreen", sHotkeyCfg{uKeyboardHotkey{WXK_F11}});
hotkeys.toggleFullscreenAlt = xml_hotkeys.get("ToggleFullscreenAlt", sHotkeyCfg{uKeyboardHotkey{WXK_CONTROL_M, true}}); // ALT+ENTER
hotkeys.takeScreenshot = xml_hotkeys.get("TakeScreenshot", sHotkeyCfg{uKeyboardHotkey{WXK_F12}});
hotkeys.toggleFastForward = xml_hotkeys.get("ToggleFastForward", sHotkeyCfg{});
// emulatedusbdevices // emulatedusbdevices
auto usbdevices = parser.get("EmulatedUsbDevices"); auto usbdevices = parser.get("EmulatedUsbDevices");
emulated_usb_devices.emulate_skylander_portal = usbdevices.get("EmulateSkylanderPortal", emulated_usb_devices.emulate_skylander_portal); emulated_usb_devices.emulate_skylander_portal = usbdevices.get("EmulateSkylanderPortal", emulated_usb_devices.emulate_skylander_portal);
@ -544,6 +553,15 @@ void CemuConfig::Save(XMLConfigParser& parser)
dsuc.set_attribute("host", dsu_client.host); dsuc.set_attribute("host", dsu_client.host);
dsuc.set_attribute("port", dsu_client.port); dsuc.set_attribute("port", dsu_client.port);
// hotkeys
auto xml_hotkeys = config.set("Hotkeys");
xml_hotkeys.set("modifiers", hotkeys.modifiers);
xml_hotkeys.set("ExitFullscreen", hotkeys.exitFullscreen);
xml_hotkeys.set("ToggleFullscreen", hotkeys.toggleFullscreen);
xml_hotkeys.set("ToggleFullscreenAlt", hotkeys.toggleFullscreenAlt);
xml_hotkeys.set("TakeScreenshot", hotkeys.takeScreenshot);
xml_hotkeys.set("ToggleFastForward", hotkeys.toggleFastForward);
// emulated usb devices // emulated usb devices
auto usbdevices = config.set("EmulatedUsbDevices"); auto usbdevices = config.set("EmulatedUsbDevices");
usbdevices.set("EmulateSkylanderPortal", emulated_usb_devices.emulate_skylander_portal.GetValue()); usbdevices.set("EmulateSkylanderPortal", emulated_usb_devices.emulate_skylander_portal.GetValue());

View file

@ -191,6 +191,47 @@ enum class CrashDump
ENABLE_ENUM_ITERATORS(CrashDump, CrashDump::Disabled, CrashDump::Enabled); ENABLE_ENUM_ITERATORS(CrashDump, CrashDump::Disabled, CrashDump::Enabled);
#endif #endif
typedef union
{
struct
{
uint16 key : 13; // enough bits for all keycodes
uint16 alt : 1;
uint16 ctrl : 1;
uint16 shift : 1;
};
uint16 raw;
} uKeyboardHotkey;
typedef sint16 ControllerHotkey_t;
struct sHotkeyCfg
{
uKeyboardHotkey keyboard{WXK_NONE};
ControllerHotkey_t controller{-1}; // -1 = disabled
/* for defaults */
sHotkeyCfg(const uKeyboardHotkey& keyboard = {WXK_NONE}, const ControllerHotkey_t& controller = {-1}) :
keyboard(keyboard), controller(controller) {};
/* for reading from xml */
sHotkeyCfg(const char* xml_values)
{
std::istringstream iss(xml_values);
iss >> keyboard.raw >> controller;
}
};
template <>
struct fmt::formatter<sHotkeyCfg> : formatter<string_view>
{
template <typename FormatContext>
auto format(const sHotkeyCfg c, FormatContext &ctx) const {
std::string xml_values = fmt::format("{} {}", c.keyboard.raw, c.controller);
return formatter<string_view>::format(xml_values, ctx);
}
};
template <> template <>
struct fmt::formatter<PrecompiledShaderOption> : formatter<string_view> { struct fmt::formatter<PrecompiledShaderOption> : formatter<string_view> {
template <typename FormatContext> template <typename FormatContext>
@ -499,6 +540,17 @@ struct CemuConfig
ConfigValue<uint16> port{ 26760 }; ConfigValue<uint16> port{ 26760 };
}dsu_client{}; }dsu_client{};
// hotkeys
struct
{
sHotkeyCfg modifiers;
sHotkeyCfg toggleFullscreen;
sHotkeyCfg toggleFullscreenAlt;
sHotkeyCfg exitFullscreen;
sHotkeyCfg takeScreenshot;
sHotkeyCfg toggleFastForward;
} hotkeys{};
// debug // debug
ConfigValueBounds<CrashDump> crash_dump{ CrashDump::Disabled }; ConfigValueBounds<CrashDump> crash_dump{ CrashDump::Disabled };
ConfigValue<uint16> gdb_port{ 1337 }; ConfigValue<uint16> gdb_port{ 1337 };

View file

@ -7,6 +7,9 @@
#include <string> #include <string>
#include <mutex> #include <mutex>
template <typename T>
concept HasConstCharConstructor = requires { T(std::declval<const char*>()); };
class XMLConfigParser class XMLConfigParser
{ {
public: public:
@ -43,7 +46,7 @@ public:
return element->Int64Text(default_value); return element->Int64Text(default_value);
else if constexpr (std::is_same_v<T, uint64>) // doesnt support real uint64... else if constexpr (std::is_same_v<T, uint64>) // doesnt support real uint64...
return (uint64)element->Int64Text((sint64)default_value); return (uint64)element->Int64Text((sint64)default_value);
else if constexpr (std::is_same_v<T, const char*> || std::is_same_v<T, std::string>) else if constexpr (std::is_same_v<T, const char*> || std::is_same_v<T, std::string> || HasConstCharConstructor<T>)
{ {
const char* text = element->GetText(); const char* text = element->GetText();
return text ? text : default_value; return text ? text : default_value;

View file

@ -71,6 +71,8 @@ add_library(CemuGui
helpers/wxLogEvent.h helpers/wxLogEvent.h
helpers/wxWayland.cpp helpers/wxWayland.cpp
helpers/wxWayland.h helpers/wxWayland.h
input/HotkeySettings.cpp
input/HotkeySettings.h
input/InputAPIAddWindow.cpp input/InputAPIAddWindow.cpp
input/InputAPIAddWindow.h input/InputAPIAddWindow.h
input/InputSettings2.cpp input/InputSettings2.cpp

View file

@ -11,6 +11,7 @@
#include "input/InputManager.h" #include "input/InputManager.h"
#include "gui/helpers/wxHelpers.h" #include "gui/helpers/wxHelpers.h"
#include "Cemu/ncrypto/ncrypto.h" #include "Cemu/ncrypto/ncrypto.h"
#include "gui/input/HotkeySettings.h"
#if BOOST_OS_LINUX && HAS_WAYLAND #if BOOST_OS_LINUX && HAS_WAYLAND
#include "gui/helpers/wxWayland.h" #include "gui/helpers/wxWayland.h"
@ -331,6 +332,8 @@ bool CemuApp::OnInit()
std::unique_lock lock(g_mutex); std::unique_lock lock(g_mutex);
g_window_info.app_active = true; g_window_info.app_active = true;
HotkeySettings::Init(m_mainFrame);
SetTopWindow(m_mainFrame); SetTopWindow(m_mainFrame);
m_mainFrame->Show(); m_mainFrame->Show();

View file

@ -40,6 +40,7 @@
#include "gui/helpers/wxHelpers.h" #include "gui/helpers/wxHelpers.h"
#include "Cafe/HW/Latte/Renderer/Vulkan/VsyncDriver.h" #include "Cafe/HW/Latte/Renderer/Vulkan/VsyncDriver.h"
#include "gui/input/InputSettings2.h" #include "gui/input/InputSettings2.h"
#include "gui/input/HotkeySettings.h"
#include "input/InputManager.h" #include "input/InputManager.h"
#if BOOST_OS_WINDOWS #if BOOST_OS_WINDOWS
@ -91,6 +92,7 @@ enum
MAINFRAME_MENU_ID_OPTIONS_GENERAL2, MAINFRAME_MENU_ID_OPTIONS_GENERAL2,
MAINFRAME_MENU_ID_OPTIONS_AUDIO, MAINFRAME_MENU_ID_OPTIONS_AUDIO,
MAINFRAME_MENU_ID_OPTIONS_INPUT, MAINFRAME_MENU_ID_OPTIONS_INPUT,
MAINFRAME_MENU_ID_OPTIONS_HOTKEY,
// options -> account // options -> account
MAINFRAME_MENU_ID_OPTIONS_ACCOUNT_1 = 20350, MAINFRAME_MENU_ID_OPTIONS_ACCOUNT_1 = 20350,
MAINFRAME_MENU_ID_OPTIONS_ACCOUNT_12 = 20350 + 11, MAINFRAME_MENU_ID_OPTIONS_ACCOUNT_12 = 20350 + 11,
@ -187,6 +189,7 @@ EVT_MENU(MAINFRAME_MENU_ID_OPTIONS_GENERAL, MainWindow::OnOptionsInput)
EVT_MENU(MAINFRAME_MENU_ID_OPTIONS_GENERAL2, MainWindow::OnOptionsInput) EVT_MENU(MAINFRAME_MENU_ID_OPTIONS_GENERAL2, MainWindow::OnOptionsInput)
EVT_MENU(MAINFRAME_MENU_ID_OPTIONS_AUDIO, MainWindow::OnOptionsInput) EVT_MENU(MAINFRAME_MENU_ID_OPTIONS_AUDIO, MainWindow::OnOptionsInput)
EVT_MENU(MAINFRAME_MENU_ID_OPTIONS_INPUT, MainWindow::OnOptionsInput) EVT_MENU(MAINFRAME_MENU_ID_OPTIONS_INPUT, MainWindow::OnOptionsInput)
EVT_MENU(MAINFRAME_MENU_ID_OPTIONS_HOTKEY, MainWindow::OnOptionsInput)
// tools menu // tools menu
EVT_MENU(MAINFRAME_MENU_ID_TOOLS_MEMORY_SEARCHER, MainWindow::OnToolsInput) EVT_MENU(MAINFRAME_MENU_ID_TOOLS_MEMORY_SEARCHER, MainWindow::OnToolsInput)
EVT_MENU(MAINFRAME_MENU_ID_TOOLS_TITLE_MANAGER, MainWindow::OnToolsInput) EVT_MENU(MAINFRAME_MENU_ID_TOOLS_TITLE_MANAGER, MainWindow::OnToolsInput)
@ -924,6 +927,12 @@ void MainWindow::OnOptionsInput(wxCommandEvent& event)
break; break;
} }
case MAINFRAME_MENU_ID_OPTIONS_HOTKEY:
{
auto* frame = new HotkeySettings(this);
frame->Show();
break;
}
} }
} }
@ -1437,13 +1446,15 @@ void MainWindow::OnKeyUp(wxKeyEvent& event)
if (swkbd_hasKeyboardInputHook()) if (swkbd_hasKeyboardInputHook())
return; return;
const auto code = event.GetKeyCode(); uKeyboardHotkey hotkey{};
if (code == WXK_ESCAPE) hotkey.key = event.GetKeyCode();
SetFullScreen(false); hotkey.alt = event.AltDown();
else if (code == WXK_RETURN && event.AltDown() || code == WXK_F11) hotkey.ctrl = event.ControlDown();
SetFullScreen(!IsFullScreen()); hotkey.shift = event.ShiftDown();
else if (code == WXK_F12) const auto& hotkey_map = HotkeySettings::s_keyboardHotkeyToFuncMap;
g_window_info.has_screenshot_request = true; // async screenshot request const auto it = hotkey_map.find(hotkey.raw);
if (it != hotkey_map.end())
it->second();
} }
void MainWindow::OnKeyDown(wxKeyEvent& event) void MainWindow::OnKeyDown(wxKeyEvent& event)
@ -2159,6 +2170,7 @@ void MainWindow::RecreateMenu()
optionsMenu->AppendSeparator(); optionsMenu->AppendSeparator();
optionsMenu->Append(MAINFRAME_MENU_ID_OPTIONS_GENERAL2, _("&General settings")); optionsMenu->Append(MAINFRAME_MENU_ID_OPTIONS_GENERAL2, _("&General settings"));
optionsMenu->Append(MAINFRAME_MENU_ID_OPTIONS_INPUT, _("&Input settings")); optionsMenu->Append(MAINFRAME_MENU_ID_OPTIONS_INPUT, _("&Input settings"));
optionsMenu->Append(MAINFRAME_MENU_ID_OPTIONS_HOTKEY, _("&Hotkey settings"));
optionsMenu->AppendSeparator(); optionsMenu->AppendSeparator();
optionsMenu->AppendSubMenu(m_optionsAccountMenu, _("&Active account")); optionsMenu->AppendSubMenu(m_optionsAccountMenu, _("&Active account"));

View file

@ -0,0 +1,363 @@
#include "gui/input/HotkeySettings.h"
#include <config/ActiveSettings.h>
#include <gui/guiWrapper.h>
#include "input/InputManager.h"
#include "HotkeySettings.h"
#if BOOST_OS_LINUX || BOOST_OS_MACOS
#include "resource/embedded/resources.h"
#endif
extern WindowInfo g_window_info;
const std::unordered_map<sHotkeyCfg*, std::function<void(void)>> HotkeySettings::s_cfgHotkeyToFuncMap{
{&s_cfgHotkeys.toggleFullscreen, [](void) { s_mainWindow->ShowFullScreen(!s_mainWindow->IsFullScreen()); }},
{&s_cfgHotkeys.toggleFullscreenAlt, [](void) { s_mainWindow->ShowFullScreen(!s_mainWindow->IsFullScreen()); }},
{&s_cfgHotkeys.exitFullscreen, [](void) { s_mainWindow->ShowFullScreen(false); }},
{&s_cfgHotkeys.takeScreenshot, [](void) { g_window_info.has_screenshot_request = true; }},
{&s_cfgHotkeys.toggleFastForward, [](void) { ActiveSettings::SetTimerShiftFactor((ActiveSettings::GetTimerShiftFactor() < 3) ? 3 : 1); }},
};
struct HotkeyEntry
{
enum class InputButtonType : wxWindowID {
Keyboard,
Controller,
};
std::unique_ptr<wxStaticText> name;
std::unique_ptr<wxButton> keyInput;
std::unique_ptr<wxButton> controllerInput;
sHotkeyCfg& hotkey;
HotkeyEntry(wxStaticText* name, wxButton* keyInput, wxButton* controllerInput, sHotkeyCfg& hotkey)
: name(name), keyInput(keyInput), controllerInput(controllerInput), hotkey(hotkey)
{
keyInput->SetClientData(&hotkey);
keyInput->SetId(static_cast<wxWindowID>(InputButtonType::Keyboard));
controllerInput->SetClientData(&hotkey);
controllerInput->SetId(static_cast<wxWindowID>(InputButtonType::Controller));
}
};
HotkeySettings::HotkeySettings(wxWindow* parent)
: wxFrame(parent, wxID_ANY, "Hotkey Settings")
{
SetIcon(wxICON(X_HOTKEY_SETTINGS));
m_sizer = new wxFlexGridSizer(0, 3, 10, 10);
m_sizer->AddGrowableCol(1);
m_sizer->AddGrowableCol(2);
m_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE);
m_panel->SetSizer(m_sizer);
Center();
SetActiveController();
CreateColumnHeaders();
/* global modifier */
CreateHotkeyRow("Hotkey modifier", s_cfgHotkeys.modifiers);
m_hotkeys.at(0).keyInput->Hide();
/* hotkeys */
CreateHotkeyRow("Toggle fullscreen", s_cfgHotkeys.toggleFullscreen);
CreateHotkeyRow("Take screenshot", s_cfgHotkeys.takeScreenshot);
CreateHotkeyRow("Toggle fast-forward", s_cfgHotkeys.toggleFastForward);
m_controllerTimer = new wxTimer(this);
Bind(wxEVT_TIMER, &HotkeySettings::OnControllerTimer, this);
m_sizer->SetSizeHints(this);
}
HotkeySettings::~HotkeySettings()
{
m_controllerTimer->Stop();
if (m_needToSave)
{
g_config.Save();
}
}
void HotkeySettings::Init(wxFrame* mainWindowFrame)
{
s_keyboardHotkeyToFuncMap.reserve(s_cfgHotkeyToFuncMap.size());
for (const auto& [cfgHotkey, func] : s_cfgHotkeyToFuncMap)
{
auto keyboardHotkey = cfgHotkey->keyboard.raw;
if (keyboardHotkey > 0)
{
s_keyboardHotkeyToFuncMap[keyboardHotkey] = func;
}
auto controllerHotkey = cfgHotkey->controller;
if (controllerHotkey > 0)
{
s_controllerHotkeyToFuncMap[controllerHotkey] = func;
}
}
s_mainWindow = mainWindowFrame;
}
void HotkeySettings::CreateColumnHeaders(void)
{
auto* emptySpace = new wxStaticText(m_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL);
auto* keyboard = new wxStaticText(m_panel, wxID_ANY, "Keyboard", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL);
auto* controller = new wxStaticText(m_panel, wxID_ANY, "Controller", wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER_HORIZONTAL);
keyboard->SetMinSize(m_minButtonSize);
controller->SetMinSize(m_minButtonSize);
auto flags = wxSizerFlags().Expand();
m_sizer->Add(emptySpace, flags);
m_sizer->Add(keyboard, flags);
m_sizer->Add(controller, flags);
}
void HotkeySettings::CreateHotkeyRow(const wxString& label, sHotkeyCfg& cfgHotkey)
{
auto* name = new wxStaticText(m_panel, wxID_ANY, label);
auto* keyInput = new wxButton(m_panel, wxID_ANY, To_wxString(cfgHotkey.keyboard), wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS | wxBU_EXACTFIT);
auto* controllerInput = new wxButton(m_panel, wxID_ANY, To_wxString(cfgHotkey.controller), wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS | wxBU_EXACTFIT);
/* for starting input */
keyInput->Bind(wxEVT_BUTTON, &HotkeySettings::OnKeyboardHotkeyInputLeftClick, this);
controllerInput->Bind(wxEVT_BUTTON, &HotkeySettings::OnControllerHotkeyInputLeftClick, this);
/* for cancelling and clearing input */
keyInput->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(HotkeySettings::OnHotkeyInputRightClick), NULL, this);
controllerInput->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(HotkeySettings::OnHotkeyInputRightClick), NULL, this);
keyInput->SetMinSize(m_minButtonSize);
controllerInput->SetMinSize(m_minButtonSize);
auto flags = wxSizerFlags().Expand();
m_sizer->Add(name, flags);
m_sizer->Add(keyInput, flags);
m_sizer->Add(controllerInput, flags);
m_hotkeys.emplace_back(name, keyInput, controllerInput, cfgHotkey);
}
void HotkeySettings::OnControllerTimer(wxTimerEvent& event)
{
if (m_activeController.expired())
{
m_controllerTimer->Stop();
return;
}
auto& controller = *m_activeController.lock();
auto buttons = controller.update_state().buttons;
if (!buttons.IsIdle())
{
for (const auto& newHotkey : buttons.GetButtonList())
{
m_controllerTimer->Stop();
auto* inputButton = static_cast<wxButton*>(m_controllerTimer->GetClientData());
auto& cfgHotkey = *static_cast<sHotkeyCfg*>(inputButton->GetClientData());
const auto oldHotkey = cfgHotkey.controller;
const bool is_modifier = (&cfgHotkey == &s_cfgHotkeys.modifiers);
/* ignore same hotkeys and block duplicate hotkeys */
if ((newHotkey != oldHotkey) && (is_modifier || (newHotkey != s_cfgHotkeys.modifiers.controller)) &&
(s_controllerHotkeyToFuncMap.find(newHotkey) == s_controllerHotkeyToFuncMap.end()))
{
m_needToSave |= true;
cfgHotkey.controller = newHotkey;
/* don't bind modifier to map */
if (!is_modifier) {
s_controllerHotkeyToFuncMap.erase(oldHotkey);
s_controllerHotkeyToFuncMap[newHotkey] = s_cfgHotkeyToFuncMap.at(&cfgHotkey);
}
}
FinalizeInput<ControllerHotkey_t>(inputButton);
return;
}
}
}
void HotkeySettings::OnKeyboardHotkeyInputLeftClick(wxCommandEvent& event)
{
auto* inputButton = static_cast<wxButton*>(event.GetEventObject());
if (m_activeInputButton)
{
/* ignore multiple clicks of the same button */
if (inputButton == m_activeInputButton) return;
RestoreInputButton(m_activeInputButton);
}
inputButton->Bind(wxEVT_KEY_UP, &HotkeySettings::OnKeyUp, this);
inputButton->SetLabelText('_');
m_activeInputButton = inputButton;
}
void HotkeySettings::OnControllerHotkeyInputLeftClick(wxCommandEvent& event)
{
auto* inputButton = static_cast<wxButton*>(event.GetEventObject());
if (m_activeInputButton)
{
/* ignore multiple clicks of the same button */
if (inputButton == m_activeInputButton) return;
RestoreInputButton(m_activeInputButton);
}
m_controllerTimer->Stop();
if (!SetActiveController())
{
return;
}
inputButton->SetLabelText('_');
m_controllerTimer->SetClientData(inputButton);
m_controllerTimer->Start(25);
m_activeInputButton = inputButton;
}
void HotkeySettings::OnHotkeyInputRightClick(wxMouseEvent& event)
{
if (m_activeInputButton)
{
RestoreInputButton(m_activeInputButton);
return;
}
auto* inputButton = static_cast<wxButton*>(event.GetEventObject());
auto& cfgHotkey = *static_cast<sHotkeyCfg*>(inputButton->GetClientData());
using InputButtonType = HotkeyEntry::InputButtonType;
switch (static_cast<InputButtonType>(inputButton->GetId()))
{
case InputButtonType::Keyboard: {
uKeyboardHotkey newHotkey{};
if (cfgHotkey.keyboard.raw != newHotkey.raw)
{
m_needToSave |= true;
s_keyboardHotkeyToFuncMap.erase(cfgHotkey.keyboard.raw);
cfgHotkey.keyboard = newHotkey;
FinalizeInput<uKeyboardHotkey>(inputButton);
}
} break;
case InputButtonType::Controller: {
ControllerHotkey_t newHotkey{ -1 };
if (cfgHotkey.controller != newHotkey)
{
m_needToSave |= true;
s_controllerHotkeyToFuncMap.erase(cfgHotkey.controller);
cfgHotkey.controller = newHotkey;
FinalizeInput<ControllerHotkey_t>(inputButton);
}
} break;
default: break;
}
}
bool HotkeySettings::SetActiveController(void)
{
auto emulatedController = InputManager::instance().get_controller(0);
if (emulatedController.use_count() <= 1)
{
return false;
}
const auto& controllers = emulatedController->get_controllers();
if (controllers.empty())
{
return false;
}
m_activeController = controllers.at(0);
return true;
}
void HotkeySettings::OnKeyUp(wxKeyEvent& event)
{
auto* inputButton = static_cast<wxButton*>(event.GetEventObject());
auto& cfgHotkey = *static_cast<sHotkeyCfg*>(inputButton->GetClientData());
if (auto keycode = event.GetKeyCode(); IsValidKeycodeUp(keycode))
{
auto oldHotkey = cfgHotkey.keyboard;
uKeyboardHotkey newHotkey{};
newHotkey.key = keycode;
newHotkey.alt = event.AltDown();
newHotkey.ctrl = event.ControlDown();
newHotkey.shift = event.ShiftDown();
if ((newHotkey.raw != oldHotkey.raw) &&
(s_keyboardHotkeyToFuncMap.find(newHotkey.raw) == s_keyboardHotkeyToFuncMap.end()))
{
m_needToSave |= true;
cfgHotkey.keyboard = newHotkey;
s_keyboardHotkeyToFuncMap.erase(oldHotkey.raw);
s_keyboardHotkeyToFuncMap[newHotkey.raw] = s_cfgHotkeyToFuncMap.at(&cfgHotkey);
}
}
FinalizeInput<uKeyboardHotkey>(inputButton);
}
template <typename T>
void HotkeySettings::FinalizeInput(wxButton* inputButton)
{
auto& cfgHotkey = *static_cast<sHotkeyCfg*>(inputButton->GetClientData());
if constexpr (std::is_same_v<T, uKeyboardHotkey>)
{
inputButton->Unbind(wxEVT_KEY_UP, &HotkeySettings::OnKeyUp, this);
inputButton->SetLabelText(To_wxString(cfgHotkey.keyboard));
} else if constexpr (std::is_same_v<T, ControllerHotkey_t>)
{
inputButton->SetLabelText(To_wxString(cfgHotkey.controller));
}
m_activeInputButton = nullptr;
}
void HotkeySettings::RestoreInputButton(wxButton* inputButton)
{
using InputButtonType = HotkeyEntry::InputButtonType;
switch (static_cast<InputButtonType>(inputButton->GetId()))
{
case InputButtonType::Keyboard: {
FinalizeInput<uKeyboardHotkey>(inputButton);
} break;
case InputButtonType::Controller: {
FinalizeInput<ControllerHotkey_t>(inputButton);
} break;
default: break;
}
}
bool HotkeySettings::IsValidKeycodeUp(int keycode)
{
switch (keycode)
{
case WXK_NONE:
case WXK_ESCAPE:
case WXK_ALT:
case WXK_CONTROL:
case WXK_SHIFT:
return false;
default:
return true;
}
}
wxString HotkeySettings::To_wxString(uKeyboardHotkey hotkey)
{
wxString ret{};
if (hotkey.raw)
{
if (hotkey.alt)
{
ret.append("ALT + ");
}
if (hotkey.ctrl)
{
ret.append("CTRL + ");
}
if (hotkey.shift)
{
ret.append("SHIFT + ");
}
ret.append(wxAcceleratorEntry(0, hotkey.key).ToString());
}
return ret;
}
wxString HotkeySettings::To_wxString(ControllerHotkey_t hotkey)
{
wxString ret{};
if ((hotkey != -1) && !m_activeController.expired())
{
ret = m_activeController.lock()->get_button_name(hotkey);
}
return ret;
}

View file

@ -0,0 +1,52 @@
#pragma once
#include <wx/wx.h>
#include "config/CemuConfig.h"
#include "input/api/Controller.h"
class HotkeyEntry;
class HotkeySettings : public wxFrame
{
public:
static void Init(wxFrame* mainWindowFrame);
inline static std::unordered_map<uint16, std::function<void(void)>> s_keyboardHotkeyToFuncMap{};
inline static std::unordered_map<uint16, std::function<void(void)>> s_controllerHotkeyToFuncMap{};
inline static auto& s_cfgHotkeys = GetConfig().hotkeys;
HotkeySettings(wxWindow* parent);
~HotkeySettings();
private:
inline static wxFrame* s_mainWindow = nullptr;
static const std::unordered_map<sHotkeyCfg*, std::function<void(void)>> s_cfgHotkeyToFuncMap;
wxPanel* m_panel;
wxFlexGridSizer* m_sizer;
wxButton* m_activeInputButton{ nullptr };
wxTimer* m_controllerTimer{ nullptr };
const wxSize m_minButtonSize{ 200, 30 };
std::vector<HotkeyEntry> m_hotkeys;
std::weak_ptr<ControllerBase> m_activeController{};
bool m_needToSave = false;
/* helpers */
void CreateColumnHeaders(void);
void CreateHotkeyRow(const wxString& label, sHotkeyCfg& cfgHotkey);
wxString To_wxString(uKeyboardHotkey hotkey);
wxString To_wxString(ControllerHotkey_t hotkey);
bool IsValidKeycodeUp(int keycode);
bool SetActiveController(void);
template<typename T>
void FinalizeInput(wxButton* inputButton);
void RestoreInputButton(wxButton* inputButton);
/* events */
void OnKeyboardHotkeyInputLeftClick(wxCommandEvent& event);
void OnControllerHotkeyInputLeftClick(wxCommandEvent& event);
void OnHotkeyInputRightClick(wxMouseEvent& event);
void OnKeyUp(wxKeyEvent& event);
void OnControllerTimer(wxTimerEvent& event);
};

View file

@ -1,4 +1,6 @@
#include "input/api/Controller.h" #include "input/api/Controller.h"
#include "config/CemuConfig.h"
#include "gui/input/HotkeySettings.h"
#include "gui/guiWrapper.h" #include "gui/guiWrapper.h"
@ -67,6 +69,22 @@ const ControllerState& ControllerBase::update_state()
#undef APPLY_AXIS_BUTTON #undef APPLY_AXIS_BUTTON
/* hotkey capturing */
const auto& hotkey_mod = HotkeySettings::s_cfgHotkeys.modifiers.controller;
if ((hotkey_mod >= 0) && result.buttons.GetButtonState(hotkey_mod)) {
const auto& hotkey_map = HotkeySettings::s_controllerHotkeyToFuncMap;
for (const auto& button_id : result.buttons.GetButtonList()) {
const auto it = hotkey_map.find(button_id);
if (it == hotkey_map.end())
continue;
/* only capture clicks */
if (m_last_state.buttons.GetButtonState(button_id))
break;
it->second();
break;
}
}
m_last_state = std::move(result); m_last_state = std::move(result);
return m_last_state; return m_last_state;
} }

View file

@ -37,6 +37,7 @@ X_SETTINGS ICON "resource\\icons8_automatic_26_x
X_GAME_PROFILE ICON "resource\\icons8-compose-filled-50.ico" X_GAME_PROFILE ICON "resource\\icons8-compose-filled-50.ico"
X_HOTKEY_SETTINGS ICON "resource\\icons8_hotkeys.ico"
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View file

@ -0,0 +1,70 @@
/* XPM */
const char *X_HOTKEY_SETTINGS_xpm[] = {
"64 64 2 1",
" c None",
". c #000000",
" ... ",
" .... ",
" .... ",
" .. .... ",
" .. ...... ",
" ... ...... ",
" ... ...... ",
" ... ....... ",
" .... ........ ... ",
" .... ......... ... ",
" .... ......... ... ",
" .... .......... .... ",
" .... ......... .... ",
" ..... ........... ..... ",
" ..... .......... ..... ",
" ........ ........... ...... ",
" ........ ... ....... ...... ",
" ........... ... ....... ...... ",
" ........... ..... ...... ....... ",
" ........... ..... ...... ........ ",
" ............. ...... ...... ......... ",
" ........ .... ...... .... ..... .... ",
" ........ .... ....... .... ...... .... ",
" ...... .... ...... ..... ....... ..... ",
" ...... ........... ............ .... ",
" ...... .......... .......... .... ",
" ..... .......... .......... .... ",
" ..... .......... ......... ..... ",
" ..... .......... ........ ..... ",
" ..... ........ ........ ...... ",
" ..... ..... ..... ..... ",
" ..... ..... .... ...... ",
" ..... ..... ",
" ... .... ",
" . ............................ .. ",
" ................................ ",
" ................................ ",
" .................................... ",
" .................................... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... .......... ",
" .......... .......... ",
" .......... .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .......... ........ .......... ",
" .................................... ",
" .................................... ",
" .................................... ",
" .................................... ",
" ................................ ",
" ................................ ",
" ............................. "
};

View file

@ -2,6 +2,7 @@
#include "M_WND_ICON128.xpm" #include "M_WND_ICON128.xpm"
#include "X_BOX.xpm" #include "X_BOX.xpm"
#include "X_SETTINGS.xpm" #include "X_SETTINGS.xpm"
#include "X_HOTKEY_SETTINGS.xpm"
#include "icons8-checkmark-yes-32.hpng" #include "icons8-checkmark-yes-32.hpng"
#include "icons8-error-32.hpng" #include "icons8-error-32.hpng"

View file

@ -2,6 +2,7 @@ extern const char* X_GAME_PROFILE_xpm[];
extern const char* M_WND_ICON128_xpm[]; extern const char* M_WND_ICON128_xpm[];
extern const char* X_BOX_xpm[]; extern const char* X_BOX_xpm[];
extern const char* X_SETTINGS_xpm[]; extern const char* X_SETTINGS_xpm[];
extern const char* X_HOTKEY_SETTINGS_xpm[];
extern unsigned char PNG_CHECK_YES_png[573]; extern unsigned char PNG_CHECK_YES_png[573];
extern unsigned char PNG_ERROR_png[472]; extern unsigned char PNG_ERROR_png[472];

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B