From 151ae38a568a518458e57ac0c72d6b15172f0462 Mon Sep 17 00:00:00 2001 From: spycrab Date: Tue, 6 Jun 2017 13:49:49 +0200 Subject: Qt: Implement hotkeys (+ configuration) --- Source/Core/DolphinQt2/MainWindow.cpp | 54 ++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'Source/Core/DolphinQt2/MainWindow.cpp') diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index a8049826f2..a487e37b2a 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -24,9 +24,13 @@ #include "DolphinQt2/AboutDialog.h" #include "DolphinQt2/Config/ControllersWindow.h" + +#include "DolphinQt2/Config/Mapping/MappingWindow.h" #include "DolphinQt2/Config/SettingsWindow.h" #include "DolphinQt2/Host.h" +#include "DolphinQt2/HotkeyScheduler.h" #include "DolphinQt2/MainWindow.h" +#include "DolphinQt2/QtUtils/FocusEventFilter.h" #include "DolphinQt2/Resources.h" #include "DolphinQt2/Settings.h" @@ -64,16 +68,32 @@ void MainWindow::InitControllers() Pad::Initialize(); Keyboard::Initialize(); Wiimote::Initialize(Wiimote::InitializeMode::DO_NOT_WAIT_FOR_WIIMOTES); - HotkeyManagerEmu::Initialize(); + m_hotkey_scheduler = new HotkeyScheduler(); + m_hotkey_scheduler->Start(); + + ConnectHotkeys(); } void MainWindow::ShutdownControllers() { + m_hotkey_scheduler->Stop(); + g_controller_interface.Shutdown(); Pad::Shutdown(); Keyboard::Shutdown(); Wiimote::Shutdown(); HotkeyManagerEmu::Shutdown(); + + m_hotkey_scheduler->deleteLater(); +} + +static void InstallHotkeyFilter(QDialog* dialog) +{ + auto* filter = new FocusEventFilter(); + dialog->installEventFilter(filter); + + filter->connect(filter, &FocusEventFilter::focusOutEvent, [] { HotkeyManagerEmu::Enable(true); }); + filter->connect(filter, &FocusEventFilter::focusInEvent, [] { HotkeyManagerEmu::Enable(false); }); } void MainWindow::CreateComponents() @@ -85,6 +105,11 @@ void MainWindow::CreateComponents() m_stack = new QStackedWidget(this); m_controllers_window = new ControllersWindow(this); m_settings_window = new SettingsWindow(this); + m_hotkey_window = new MappingWindow(this, 0); + + InstallHotkeyFilter(m_hotkey_window); + InstallHotkeyFilter(m_controllers_window); + InstallHotkeyFilter(m_settings_window); } void MainWindow::ConnectMenuBar() @@ -113,6 +138,9 @@ void MainWindow::ConnectMenuBar() connect(m_menu_bar, &MenuBar::StateSaveOldest, this, &MainWindow::StateSaveOldest); connect(m_menu_bar, &MenuBar::SetStateSlot, this, &MainWindow::SetStateSlot); + // Options + connect(m_menu_bar, &MenuBar::ConfigureHotkeys, this, &MainWindow::ShowHotkeyDialog); + // View connect(m_menu_bar, &MenuBar::ShowTable, m_game_list, &GameList::SetTableView); connect(m_menu_bar, &MenuBar::ShowList, m_game_list, &GameList::SetListView); @@ -130,6 +158,22 @@ void MainWindow::ConnectMenuBar() [=]() { m_controllers_window->OnEmulationStateChanged(false); }); } +void MainWindow::ConnectHotkeys() +{ + connect(m_hotkey_scheduler, &HotkeyScheduler::ExitHotkey, this, &MainWindow::close); + connect(m_hotkey_scheduler, &HotkeyScheduler::PauseHotkey, this, &MainWindow::Pause); + connect(m_hotkey_scheduler, &HotkeyScheduler::StopHotkey, this, &MainWindow::Stop); + connect(m_hotkey_scheduler, &HotkeyScheduler::ScreenShotHotkey, this, &MainWindow::ScreenShot); + connect(m_hotkey_scheduler, &HotkeyScheduler::FullScreenHotkey, this, &MainWindow::FullScreen); + + connect(m_hotkey_scheduler, &HotkeyScheduler::StateLoadSlotHotkey, this, + &MainWindow::StateLoadSlot); + connect(m_hotkey_scheduler, &HotkeyScheduler::StateSaveSlotHotkey, this, + &MainWindow::StateSaveSlot); + connect(m_hotkey_scheduler, &HotkeyScheduler::SetStateSlotHotkey, this, + &MainWindow::SetStateSlot); +} + void MainWindow::ConnectToolBar() { addToolBar(m_tool_bar); @@ -364,6 +408,14 @@ void MainWindow::ShowAboutDialog() about->show(); } +void MainWindow::ShowHotkeyDialog() +{ + m_hotkey_window->ChangeMappingType(MappingWindow::Type::MAPPING_HOTKEYS); + m_hotkey_window->show(); + m_hotkey_window->raise(); + m_hotkey_window->activateWindow(); +} + void MainWindow::StateLoad() { QString path = QFileDialog::getOpenFileName(this, tr("Select a File"), QDir::currentPath(), -- cgit v1.2.3 From 22992ae41e8f979149f5a1ec895519397fce490a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 27 May 2017 15:43:40 +0200 Subject: Boot: Clean up the boot code * Move out boot parameters to a separate struct, which is not part of SConfig/ConfigManager because there is no reason for it to be there. * Move out file name parsing and constructing the appropriate params from paths to a separate function that does that, and only that. * For every different boot type we support, add a proper struct with only the required parameters, with descriptive names and use std::variant to only store what we need. * Clean up the bHLE_BS2 stuff which made no sense sometimes. Now instead of using bHLE_BS2 for two different things, both for storing the user config setting and as a runtime boot parameter, we simply replace the Disc boot params with BootParameters::IPL. * Const correctness so it's clear what can or cannot update the config. * Drop unused parameters and unneeded checks. * Make a few checks a lot more concise. (Looking at you, extension checks for disc images.) * Remove a mildly terrible workaround where we needed to pass an empty string in order to boot the GC IPL without any game inserted. (Not required anymore thanks to std::variant and std::optional.) The motivation for this are multiple: cleaning up and being able to add support for booting an installed NAND title. Without this change, it'd be pretty much impossible to implement that. Also, using std::visit with std::variant makes the compiler do additional type checks: now we're guaranteed that the boot code will handle all boot types and no invalid boot type will be possible. --- Source/Core/DolphinQt2/MainWindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Source/Core/DolphinQt2/MainWindow.cpp') diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index a8049826f2..0c8b14ef8c 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -9,6 +9,7 @@ #include "Common/Common.h" +#include "Core/Boot/Boot.h" #include "Core/BootManager.h" #include "Core/ConfigManager.h" #include "Core/Core.h" @@ -287,7 +288,7 @@ void MainWindow::StartGame(const QString& path) return; } // Boot up, show an error if it fails to load the game. - if (!BootManager::BootCore(path.toStdString(), SConfig::BOOT_DEFAULT)) + if (!BootManager::BootCore(BootParameters::GenerateFromFile(path.toStdString()))) { QMessageBox::critical(this, tr("Error"), tr("Failed to init core"), QMessageBox::Ok); return; -- cgit v1.2.3