From e3f36b74c59028a38fee62ccdc98eeb7704a80c6 Mon Sep 17 00:00:00 2001 From: spycrab Date: Thu, 2 Aug 2018 12:55:30 +0200 Subject: [PATCH] Hotkeys: Add "Toggle USB Keyboard" hotkey --- Source/Core/Core/HotkeyManager.cpp | 5 +++-- Source/Core/Core/HotkeyManager.h | 1 + Source/Core/DolphinQt/HotkeyScheduler.cpp | 6 ++++++ Source/Core/DolphinQt/Settings.cpp | 14 ++++++++++++++ Source/Core/DolphinQt/Settings.h | 4 ++++ Source/Core/DolphinQt/Settings/WiiPane.cpp | 8 +++++--- 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/HotkeyManager.cpp b/Source/Core/Core/HotkeyManager.cpp index 5905ea0ad1..d8d6be0672 100644 --- a/Source/Core/Core/HotkeyManager.cpp +++ b/Source/Core/Core/HotkeyManager.cpp @@ -20,7 +20,7 @@ #include "InputCommon/GCPadStatus.h" // clang-format off -constexpr std::array s_hotkey_labels{{ +constexpr std::array s_hotkey_labels{{ _trans("Open"), _trans("Change Disc"), _trans("Eject Disc"), @@ -68,6 +68,7 @@ constexpr std::array s_hotkey_labels{{ _trans("Connect Wii Remote 3"), _trans("Connect Wii Remote 4"), _trans("Connect Balance Board"), + _trans("Toggle USB Keyboard"), _trans("Next Profile for Wii Remote 1"), _trans("Previous Profile for Wii Remote 1"), @@ -271,7 +272,7 @@ constexpr std::array s_groups_info = { {_trans("Stepping"), HK_STEP, HK_SKIP}, {_trans("Program Counter"), HK_SHOW_PC, HK_SET_PC}, {_trans("Breakpoint"), HK_BP_TOGGLE, HK_MBP_ADD}, - {_trans("Wii"), HK_TRIGGER_SYNC_BUTTON, HK_BALANCEBOARD_CONNECT}, + {_trans("Wii"), HK_TRIGGER_SYNC_BUTTON, HK_TOGGLE_USB_KEYBOARD}, {_trans("Controller Profile"), HK_NEXT_WIIMOTE_PROFILE_1, HK_PREV_GAME_WIIMOTE_PROFILE_4}, {_trans("Graphics Toggles"), HK_TOGGLE_CROP, HK_TOGGLE_TEXTURES}, {_trans("Internal Resolution"), HK_INCREASE_IR, HK_DECREASE_IR}, diff --git a/Source/Core/Core/HotkeyManager.h b/Source/Core/Core/HotkeyManager.h index 7b72478a4d..24ffe4eb58 100644 --- a/Source/Core/Core/HotkeyManager.h +++ b/Source/Core/Core/HotkeyManager.h @@ -66,6 +66,7 @@ enum Hotkey HK_WIIMOTE3_CONNECT, HK_WIIMOTE4_CONNECT, HK_BALANCEBOARD_CONNECT, + HK_TOGGLE_USB_KEYBOARD, HK_NEXT_WIIMOTE_PROFILE_1, HK_PREV_WIIMOTE_PROFILE_1, diff --git a/Source/Core/DolphinQt/HotkeyScheduler.cpp b/Source/Core/DolphinQt/HotkeyScheduler.cpp index cb882d5e01..ce0a23bce4 100644 --- a/Source/Core/DolphinQt/HotkeyScheduler.cpp +++ b/Source/Core/DolphinQt/HotkeyScheduler.cpp @@ -238,6 +238,12 @@ void HotkeyScheduler::Run() if (wiimote_id > -1) emit ConnectWiiRemote(wiimote_id); + + if (IsHotkey(HK_TOGGLE_USB_KEYBOARD)) + { + Settings::Instance().SetUSBKeyboardConnected( + !Settings::Instance().IsUSBKeyboardConnected()); + } } if (IsHotkey(HK_PREV_WIIMOTE_PROFILE_1)) diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp index cc821e0b96..5a10d71c08 100644 --- a/Source/Core/DolphinQt/Settings.cpp +++ b/Source/Core/DolphinQt/Settings.cpp @@ -520,3 +520,17 @@ void Settings::SetBatchModeEnabled(bool batch) { m_batch = batch; } + +bool Settings::IsUSBKeyboardConnected() const +{ + return SConfig::GetInstance().m_WiiKeyboard; +} + +void Settings::SetUSBKeyboardConnected(bool connected) +{ + if (IsUSBKeyboardConnected() != connected) + { + SConfig::GetInstance().m_WiiKeyboard = connected; + emit USBKeyboardConnectionChanged(connected); + } +} diff --git a/Source/Core/DolphinQt/Settings.h b/Source/Core/DolphinQt/Settings.h index d71c92e375..b80d877e1c 100644 --- a/Source/Core/DolphinQt/Settings.h +++ b/Source/Core/DolphinQt/Settings.h @@ -87,6 +87,9 @@ public: bool IsBatchModeEnabled() const; void SetBatchModeEnabled(bool batch); + bool IsUSBKeyboardConnected() const; + void SetUSBKeyboardConnected(bool connected); + // Graphics void SetHideCursor(bool hide_cursor); bool GetHideCursor() const; @@ -169,6 +172,7 @@ signals: void AutoUpdateTrackChanged(const QString& mode); void AnalyticsToggled(bool enabled); void DevicesChanged(); + void USBKeyboardConnectionChanged(bool connected); private: bool m_batch = false; diff --git a/Source/Core/DolphinQt/Settings/WiiPane.cpp b/Source/Core/DolphinQt/Settings/WiiPane.cpp index 2a0932e4c2..aadce435cb 100644 --- a/Source/Core/DolphinQt/Settings/WiiPane.cpp +++ b/Source/Core/DolphinQt/Settings/WiiPane.cpp @@ -24,6 +24,7 @@ #include "Core/Core.h" #include "Core/IOS/IOS.h" +#include "DolphinQt/Settings.h" #include "DolphinQt/Settings/USBDeviceAddToWhitelistDialog.h" #include "UICommon/USBUtils.h" @@ -73,6 +74,8 @@ void WiiPane::ConnectLayout() connect(m_pal60_mode_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig); connect(m_sd_card_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig); connect(m_connect_keyboard_checkbox, &QCheckBox::toggled, this, &WiiPane::OnSaveConfig); + connect(&Settings::Instance(), &Settings::USBKeyboardConnectionChanged, + m_connect_keyboard_checkbox, &QCheckBox::setChecked); // Whitelisted USB Passthrough Devices connect(m_whitelist_usb_list, &QListWidget::itemClicked, this, &WiiPane::ValidateSelectionState); @@ -190,7 +193,6 @@ void WiiPane::OnEmulationStateChanged(bool running) m_screensaver_checkbox->setEnabled(!running); m_pal60_mode_checkbox->setEnabled(!running); m_sd_card_checkbox->setEnabled(!running); - m_connect_keyboard_checkbox->setEnabled(!running); m_system_language_choice->setEnabled(!running); m_aspect_ratio_choice->setEnabled(!running); m_wiimote_motor->setEnabled(!running); @@ -203,7 +205,7 @@ void WiiPane::LoadConfig() { m_screensaver_checkbox->setChecked(Config::Get(Config::SYSCONF_SCREENSAVER)); m_pal60_mode_checkbox->setChecked(Config::Get(Config::SYSCONF_PAL60)); - m_connect_keyboard_checkbox->setChecked(SConfig::GetInstance().m_WiiKeyboard); + m_connect_keyboard_checkbox->setChecked(Settings::Instance().IsUSBKeyboardConnected()); m_sd_card_checkbox->setChecked(SConfig::GetInstance().m_WiiSDCard); m_aspect_ratio_choice->setCurrentIndex(Config::Get(Config::SYSCONF_WIDESCREEN)); m_system_language_choice->setCurrentIndex(Config::Get(Config::SYSCONF_LANGUAGE)); @@ -221,7 +223,7 @@ void WiiPane::OnSaveConfig() { Config::SetBase(Config::SYSCONF_SCREENSAVER, m_screensaver_checkbox->isChecked()); Config::SetBase(Config::SYSCONF_PAL60, m_pal60_mode_checkbox->isChecked()); - SConfig::GetInstance().m_WiiKeyboard = m_connect_keyboard_checkbox->isChecked(); + Settings::Instance().SetUSBKeyboardConnected(m_connect_keyboard_checkbox->isChecked()); SConfig::GetInstance().m_WiiSDCard = m_sd_card_checkbox->isChecked(); Config::SetBase(Config::SYSCONF_SENSOR_BAR_POSITION, TranslateSensorBarPosition(m_wiimote_ir_sensor_position->currentIndex()));