Add Turbo (Hold) Hotkey to desktop.

Requred expanding the GApplicationFilter class to contain a set of sequences to filter, a helper method to filter custom sequences, and some new signals and slots. The GApplicationFilter is now a local variable of citra_qt so that sequences can be added by the InitializeHotkeys function.
This commit is contained in:
David Griswold 2026-03-31 16:26:39 +03:00
parent be3125105a
commit 0c5d2ba557
4 changed files with 73 additions and 15 deletions

View File

@ -902,6 +902,27 @@ void GMainWindow::InitializeHotkeys() {
const auto fullscreen_hotkey = hotkey_registry.GetKeySequence(main_window, fullscreen);
add_secondary_window_hotkey(action_secondary_fullscreen, fullscreen_hotkey,
SLOT(ToggleSecondaryFullscreen()));
// add Toggle(Hold) to the event filter to be caught manually and processed in the two below
// methods
filter->sequences_to_catch.emplace(
hotkey_registry.GetKeySequence(main_window, QStringLiteral("Turbo Mode (Hold)")));
}
void GMainWindow::OnSequencePressed(QKeySequence seq) {
auto turbo_sequence = hotkey_registry.GetKeySequence(QStringLiteral("Main Window"),
QStringLiteral("Turbo Mode (Hold)"));
if (seq == turbo_sequence) {
SetTurboEnabled(true);
}
}
void GMainWindow::OnSequenceReleased(QKeySequence seq) {
auto turbo_sequence = hotkey_registry.GetKeySequence(QStringLiteral("Main Window"),
QStringLiteral("Turbo Mode (Hold)"));
if (seq == turbo_sequence) {
SetTurboEnabled(false);
}
}
void GMainWindow::SetDefaultUIGeometry() {
@ -975,19 +996,49 @@ void GMainWindow::OnAppFocusStateChanged(Qt::ApplicationState state) {
}
}
// helper method to check if a keyevent matches a key sequence.
bool matchesKeyEvent(const QKeyEvent* event, const QKeySequence& seq) {
if (seq.isEmpty())
return false;
int seqKey = seq[0];
int eventKey = (event->key() | event->modifiers());
return eventKey == seqKey;
}
bool GApplicationEventFilter::eventFilter(QObject* object, QEvent* event) {
if (event->type() == QEvent::FileOpen) {
emit FileOpen(static_cast<QFileOpenEvent*>(event));
return true;
}
if (event->type() == QEvent::ShortcutOverride || event->type() == QEvent::KeyPress) {
QKeyEvent* key = static_cast<QKeyEvent*>(event);
for (auto seq : sequences_to_catch) {
if (matchesKeyEvent(key, seq)) {
emit SequencePressCaught(seq);
return true;
}
}
} else if (event->type() == QEvent::KeyRelease) {
QKeyEvent* key = static_cast<QKeyEvent*>(event);
for (auto seq : sequences_to_catch) {
if (matchesKeyEvent(key, seq)) {
emit SequenceReleaseCaught(seq);
return true;
}
}
}
return false;
}
void GMainWindow::ConnectAppEvents() {
const auto filter = new GApplicationEventFilter();
QGuiApplication::instance()->installEventFilter(filter);
connect(filter, &GApplicationEventFilter::FileOpen, this, &GMainWindow::OnFileOpen);
connect(filter, &GApplicationEventFilter::SequencePressCaught, this,
&GMainWindow::OnSequencePressed);
connect(filter, &GApplicationEventFilter::SequenceReleaseCaught, this,
&GMainWindow::OnSequenceReleased);
}
void GMainWindow::ConnectWidgetEvents() {

View File

@ -94,6 +94,21 @@ enum class MediaType : u32;
int LaunchQtFrontend(int argc, char* argv[]);
class GApplicationEventFilter : public QObject {
Q_OBJECT
public:
std::set<QKeySequence> sequences_to_catch{};
signals:
void FileOpen(const QFileOpenEvent* event);
void SequencePressCaught(QKeySequence seq);
void SequenceReleaseCaught(QKeySequence seq);
protected:
bool eventFilter(QObject* object, QEvent* event) override;
};
class GMainWindow : public QMainWindow {
Q_OBJECT
@ -117,7 +132,8 @@ public:
void AcceptDropEvent(QDropEvent* event);
void OnFileOpen(const QFileOpenEvent* event);
void OnSequencePressed(QKeySequence seq);
void OnSequenceReleased(QKeySequence seq);
void UninstallTitles(
const std::vector<std::tuple<Service::FS::MediaType, u64, QString>>& titles);
@ -339,7 +355,7 @@ private:
std::unique_ptr<Ui::MainWindow> ui;
Core::System& system;
Core::Movie& movie;
GApplicationEventFilter* filter = new GApplicationEventFilter();
GRenderWindow* render_window;
GRenderWindow* secondary_window;
@ -464,15 +480,5 @@ protected:
void showEvent(QShowEvent* event) override;
};
class GApplicationEventFilter : public QObject {
Q_OBJECT
signals:
void FileOpen(const QFileOpenEvent* event);
protected:
bool eventFilter(QObject* object, QEvent* event) override;
};
Q_DECLARE_METATYPE(std::size_t);
Q_DECLARE_METATYPE(Service::AM::InstallStatus);

View File

@ -57,7 +57,7 @@ const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> QtConfi
// This must be in alphabetical order according to action name as it must have the same order as
// UISetting::values.shortcuts, which is alphabetically ordered.
// clang-format off
const std::array<UISettings::Shortcut, 38> QtConfig::default_hotkeys {{
const std::array<UISettings::Shortcut, 39> QtConfig::default_hotkeys {{
{QStringLiteral("Advance Frame"), QStringLiteral("Main Window"), {QStringLiteral(""), Qt::ApplicationShortcut}},
{QStringLiteral("Audio Mute/Unmute"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+M"), Qt::WindowShortcut}},
{QStringLiteral("Audio Volume Down"), QStringLiteral("Main Window"), {QStringLiteral(""), Qt::WindowShortcut}},
@ -96,6 +96,7 @@ const std::array<UISettings::Shortcut, 38> QtConfig::default_hotkeys {{
{QStringLiteral("Toggle Status Bar"), QStringLiteral("Main Window"), {QStringLiteral("Ctrl+S"), Qt::WindowShortcut}},
{QStringLiteral("Toggle Texture Dumping"), QStringLiteral("Main Window"), {QStringLiteral(""), Qt::ApplicationShortcut}},
{QStringLiteral("Toggle Turbo Mode"), QStringLiteral("Main Window"), {QStringLiteral(""), Qt::ApplicationShortcut}},
{QStringLiteral("Turbo Mode (Hold)"), QStringLiteral("Main Window"), {QStringLiteral(""), Qt::ApplicationShortcut}},
}};
// clang-format on

View File

@ -26,7 +26,7 @@ public:
static const std::array<int, Settings::NativeButton::NumButtons> default_buttons;
static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> default_analogs;
static const std::array<UISettings::Shortcut, 38> default_hotkeys;
static const std::array<UISettings::Shortcut, 39> default_hotkeys;
private:
void Initialize(const std::string& config_name);