diff --git a/rpcs3/Input/keyboard_pad_handler.cpp b/rpcs3/Input/keyboard_pad_handler.cpp index 926c355f38..7bb6f80b92 100644 --- a/rpcs3/Input/keyboard_pad_handler.cpp +++ b/rpcs3/Input/keyboard_pad_handler.cpp @@ -435,34 +435,7 @@ void keyboard_pad_handler::processKeyEvent(QKeyEvent* event, bool pressed) } }; - // We need to ignore keys when using rpcs3 keyboard shortcuts - // NOTE: needs to be updated with gs_frame::keyPressEvent - switch (event->key()) - { - case Qt::Key_Escape: - case Qt::Key_F11: - case Qt::Key_F12: - break; - case Qt::Key_L: - if (event->modifiers() != Qt::AltModifier && event->modifiers() != Qt::ControlModifier) - handle_key(); - break; - case Qt::Key_Return: - if (event->modifiers() != Qt::AltModifier) - handle_key(); - break; - case Qt::Key_P: - case Qt::Key_S: - case Qt::Key_R: - case Qt::Key_E: - case Qt::Key_0: - if (event->modifiers() != Qt::ControlModifier) - handle_key(); - break; - default: - handle_key(); - break; - } + handle_key(); event->ignore(); } diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index b21703d2ec..ccfb3327cf 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -123,9 +123,8 @@ gs_frame::gs_frame(QScreen* screen, const QRect& geometry, const QIcon& appIcon, create(); } - // TODO: enable in Qt6 - //m_shortcut_handler = new shortcut_handler(gui::shortcuts::shortcut_handler_id::game_window, this, m_gui_settings); - //connect(m_shortcut_handler, &shortcut_handler::shortcut_activated, this, &gs_frame::handle_shortcut); + m_shortcut_handler = new shortcut_handler(gui::shortcuts::shortcut_handler_id::game_window, this, m_gui_settings); + connect(m_shortcut_handler, &shortcut_handler::shortcut_activated, this, &gs_frame::handle_shortcut); // Change cursor when in fullscreen. connect(this, &QWindow::visibilityChanged, this, [this](QWindow::Visibility visibility) @@ -178,6 +177,14 @@ void gs_frame::load_gui_settings() m_hide_mouse_idletime = m_gui_settings->GetValue(gui::gs_hideMouseIdleTime).toUInt(); } +void gs_frame::update_shortcuts() +{ + if (m_shortcut_handler) + { + m_shortcut_handler->update(); + } +} + void gs_frame::paintEvent(QPaintEvent *event) { Q_UNUSED(event) @@ -226,94 +233,6 @@ void gs_frame::showEvent(QShowEvent *event) QWindow::showEvent(event); } -// TODO: remove when shortcuts are properly hooked up (also check keyboard_pad_handler::processKeyEvent) -void gs_frame::keyPressEvent(QKeyEvent *keyEvent) -{ - if (keyEvent->isAutoRepeat()) - { - keyEvent->ignore(); - return; - } - - // NOTE: needs to be updated with keyboard_pad_handler::processKeyEvent - - switch (keyEvent->key()) - { - case Qt::Key_L: - { - if (keyEvent->modifiers() == Qt::AltModifier) - { - handle_shortcut(gui::shortcuts::shortcut::gw_log_mark, {}); - break; - } - else if (keyEvent->modifiers() == Qt::ControlModifier) - { - handle_shortcut(gui::shortcuts::shortcut::gw_mouse_lock, {}); - break; - } - break; - } - case Qt::Key_Return: - { - if (keyEvent->modifiers() == Qt::AltModifier) - handle_shortcut(gui::shortcuts::shortcut::gw_toggle_fullscreen, {}); - break; - } - case Qt::Key_Escape: - { - handle_shortcut(gui::shortcuts::shortcut::gw_exit_fullscreen, {}); - break; - } - case Qt::Key_P: - { - if (keyEvent->modifiers() == Qt::ControlModifier) - handle_shortcut(gui::shortcuts::shortcut::gw_pause_play, {}); - break; - } - case Qt::Key_S: - { - if (keyEvent->modifiers() == Qt::ControlModifier) - handle_shortcut(gui::shortcuts::shortcut::gw_savestate, {}); - break; - } - case Qt::Key_R: - { - if (keyEvent->modifiers() == Qt::ControlModifier) - handle_shortcut(gui::shortcuts::shortcut::gw_restart, {}); - break; - } - case Qt::Key_C: - { - if (keyEvent->modifiers() == Qt::AltModifier) - handle_shortcut(gui::shortcuts::shortcut::gw_rsx_capture, {}); - break; - } - case Qt::Key_F10: - { - if (keyEvent->modifiers() == Qt::ControlModifier) - handle_shortcut(gui::shortcuts::shortcut::gw_frame_limit, {}); - break; - } - case Qt::Key_F11: - { - if (keyEvent->modifiers() == Qt::ControlModifier) - handle_shortcut(gui::shortcuts::shortcut::gw_toggle_mouse_and_keyboard, {}); - else - handle_shortcut(gui::shortcuts::shortcut::gw_toggle_recording, {}); - break; - } - case Qt::Key_F12: - { - handle_shortcut(gui::shortcuts::shortcut::gw_screenshot, {}); - break; - } - default: - { - break; - } - } -} - void gs_frame::handle_shortcut(gui::shortcuts::shortcut shortcut_key, const QKeySequence& key_sequence) { gui_log.notice("Game window registered shortcut: %s (%s)", shortcut_key, key_sequence.toString()); diff --git a/rpcs3/rpcs3qt/gs_frame.h b/rpcs3/rpcs3qt/gs_frame.h index 95d358105e..97a777360c 100644 --- a/rpcs3/rpcs3qt/gs_frame.h +++ b/rpcs3/rpcs3qt/gs_frame.h @@ -24,6 +24,8 @@ private: // taskbar progress std::unique_ptr m_progress_indicator; + shortcut_handler* m_shortcut_handler = nullptr; + QRect m_initial_geometry; std::shared_ptr m_gui_settings; @@ -55,6 +57,8 @@ public: void delete_context(draw_context_t context) override; void toggle_fullscreen() override; + void update_shortcuts(); + // taskbar progress void progress_reset(bool reset_limit = false); void progress_set_value(int value); @@ -75,8 +79,6 @@ protected: void paintEvent(QPaintEvent *event) override; void showEvent(QShowEvent *event) override; - void keyPressEvent(QKeyEvent *keyEvent) override; - void close() override; bool shown() override; diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index 0b1cce3e37..54742e2404 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -309,6 +309,7 @@ void gui_application::InitializeConnects() connect(m_main_window, &main_window::RequestLanguageChange, this, &gui_application::LoadLanguage); connect(m_main_window, &main_window::RequestGlobalStylesheetChange, this, &gui_application::OnChangeStyleSheetRequest); connect(m_main_window, &main_window::NotifyEmuSettingsChange, this, [this](){ OnEmuSettingsChange(); }); + connect(m_main_window, &main_window::NotifyShortcutHandlers, this, &gui_application::OnShortcutChange); connect(this, &gui_application::OnEmulatorRun, m_main_window, &main_window::OnEmuRun); connect(this, &gui_application::OnEmulatorStop, m_main_window, &main_window::OnEmuStop); @@ -1031,6 +1032,14 @@ void gui_application::OnChangeStyleSheetRequest() } } +void gui_application::OnShortcutChange() +{ + if (m_game_window) + { + static_cast(m_game_window)->update_shortcuts(); + } +} + /** * Using connects avoids timers being unable to be used in a non-qt thread. So, even if this looks stupid to just call func, it's succinct. */ diff --git a/rpcs3/rpcs3qt/gui_application.h b/rpcs3/rpcs3qt/gui_application.h index 87b86d9bc3..d37836e04a 100644 --- a/rpcs3/rpcs3qt/gui_application.h +++ b/rpcs3/rpcs3qt/gui_application.h @@ -121,6 +121,7 @@ private: private Q_SLOTS: void OnChangeStyleSheetRequest(); + void OnShortcutChange(); void OnAppStateChanged(Qt::ApplicationState state); Q_SIGNALS: diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index e18a5efacf..e13603e72f 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -2762,7 +2762,11 @@ void main_window::CreateConnects() connect(ui->confShortcutsAct, &QAction::triggered, [this]() { shortcut_dialog dlg(m_gui_settings, this); - connect(&dlg, &shortcut_dialog::saved, m_shortcut_handler, &shortcut_handler::update); + connect(&dlg, &shortcut_dialog::saved, this, [this]() + { + m_shortcut_handler->update(); + NotifyShortcutHandlers(); + }); dlg.exec(); }); diff --git a/rpcs3/rpcs3qt/main_window.h b/rpcs3/rpcs3qt/main_window.h index 7bad86b653..de6ad8ab0d 100644 --- a/rpcs3/rpcs3qt/main_window.h +++ b/rpcs3/rpcs3qt/main_window.h @@ -98,6 +98,7 @@ Q_SIGNALS: void RequestDialogRepaint(); void NotifyEmuSettingsChange(); void NotifyWindowCloseEvent(bool closed); + void NotifyShortcutHandlers(); public Q_SLOTS: void OnEmuStop(); diff --git a/rpcs3/rpcs3qt/shortcut_dialog.ui b/rpcs3/rpcs3qt/shortcut_dialog.ui index 84b2672722..efafa998a2 100644 --- a/rpcs3/rpcs3qt/shortcut_dialog.ui +++ b/rpcs3/rpcs3qt/shortcut_dialog.ui @@ -43,9 +43,6 @@ - - false - Game Window Shortcuts diff --git a/rpcs3/rpcs3qt/shortcut_handler.cpp b/rpcs3/rpcs3qt/shortcut_handler.cpp index 91f67df3e4..8ebefaa899 100644 --- a/rpcs3/rpcs3qt/shortcut_handler.cpp +++ b/rpcs3/rpcs3qt/shortcut_handler.cpp @@ -4,7 +4,7 @@ LOG_CHANNEL(shortcut_log, "Shortcuts"); -shortcut_handler::shortcut_handler(gui::shortcuts::shortcut_handler_id handler_id, QWidget* parent, const std::shared_ptr& gui_settings) +shortcut_handler::shortcut_handler(gui::shortcuts::shortcut_handler_id handler_id, QObject* parent, const std::shared_ptr& gui_settings) : QObject(parent), m_handler_id(handler_id), m_gui_settings(gui_settings) { // Initialize shortcuts diff --git a/rpcs3/rpcs3qt/shortcut_handler.h b/rpcs3/rpcs3qt/shortcut_handler.h index c0f6597dce..3f667a832d 100644 --- a/rpcs3/rpcs3qt/shortcut_handler.h +++ b/rpcs3/rpcs3qt/shortcut_handler.h @@ -13,7 +13,7 @@ class shortcut_handler : public QObject Q_OBJECT public: - shortcut_handler(gui::shortcuts::shortcut_handler_id handler_id, QWidget* parent, const std::shared_ptr& gui_settings); + shortcut_handler(gui::shortcuts::shortcut_handler_id handler_id, QObject* parent, const std::shared_ptr& gui_settings); Q_SIGNALS: void shortcut_activated(gui::shortcuts::shortcut shortcut_key, const QKeySequence& key_sequence); diff --git a/rpcs3/rpcs3qt/shortcut_settings.cpp b/rpcs3/rpcs3qt/shortcut_settings.cpp index 5a6c9e3b16..d7ed07eafd 100644 --- a/rpcs3/rpcs3qt/shortcut_settings.cpp +++ b/rpcs3/rpcs3qt/shortcut_settings.cpp @@ -78,6 +78,9 @@ gui_save shortcut_settings::get_shortcut_gui_save(const QString& shortcut_name) QKeySequence shortcut_settings::get_key_sequence(const shortcut_info& entry, const std::shared_ptr& gui_settings) { + if (!gui_settings) + return {}; + const QString saved_value = gui_settings->GetValue(get_shortcut_gui_save(entry.name)).toString(); QKeySequence key_sequence = QKeySequence::fromString(saved_value);