Merge pull request 'fix(hotkey): unlock framerate hotkey during gameplay' (#84) from fix/ctrl+u into main

Reviewed-on: https://git.citron-emu.org/Citron/Emulator/pulls/84
This commit is contained in:
Zephyron
2026-01-03 05:24:44 +00:00
3 changed files with 30 additions and 5 deletions

View File

@@ -602,6 +602,10 @@ int GRenderWindow::QtModifierToSwitchModifier(Qt::KeyboardModifiers qt_modifiers
}
void GRenderWindow::keyPressEvent(QKeyEvent* event) {
if (!first_frame) {
event->ignore();
return;
}
if (event->isAutoRepeat()) {
return; // Ignore auto-repeated key presses
}
@@ -621,6 +625,12 @@ void GRenderWindow::keyPressEvent(QKeyEvent* event) {
return; // Stop processing
}
if (key_sequence == hotkey_registry.GetKeySequence(main_window_id, "Toggle Framerate Limit")) {
emit UnlockFramerateHotkeyPressed(); // Signal the main window
event->accept(); // Consume the event
return; // Stop processing
}
// --- If not a critical hotkey, pass to game as normal ---
const auto modifier = QtModifierToSwitchModifier(event->modifiers());
const auto key = QtKeyToSwitchKey(static_cast<Qt::Key>(event->key()));
@@ -630,6 +640,10 @@ void GRenderWindow::keyPressEvent(QKeyEvent* event) {
}
void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
if (!first_frame) {
event->ignore();
return;
}
/**
* This feature can be enhanced with the following functions, but they do not provide
* cross-platform behavior.

View File

@@ -232,6 +232,7 @@ signals:
void TasPlaybackStateChanged();
void PanningToggleHotkeyPressed();
void FullscreenExitHotkeyPressed();
void UnlockFramerateHotkeyPressed();
private slots:
void HideMouseCursor();

View File

@@ -1104,6 +1104,8 @@ void GMainWindow::InitializeWidgets() {
if (emulation_running) {
render_window->show();
render_window->setFocus();
// The only safe time to enable screenshots:
ui->action_Capture_Screenshot->setEnabled(true);
}
});
@@ -1473,9 +1475,6 @@ void GMainWindow::InitializeHotkeys() {
connect_shortcut(QStringLiteral("Audio Mute/Unmute"), &GMainWindow::OnMute);
connect_shortcut(QStringLiteral("Audio Volume Down"), &GMainWindow::OnDecreaseVolume);
connect_shortcut(QStringLiteral("Audio Volume Up"), &GMainWindow::OnIncreaseVolume);
connect_shortcut(QStringLiteral("Toggle Framerate Limit"), [] {
Settings::values.use_speed_limit.SetValue(!Settings::values.use_speed_limit.GetValue());
});
connect_shortcut(QStringLiteral("Toggle Renderdoc Capture"), [this] {
if (Settings::values.enable_renderdoc_hotkey) {
system->GetRenderdocAPI().ToggleCapture();
@@ -1614,6 +1613,12 @@ void GMainWindow::ConnectWidgetEvents() {
connect(this, &GMainWindow::EmulationStopping, render_window,
&GRenderWindow::OnEmulationStopping);
connect(render_window, &GRenderWindow::UnlockFramerateHotkeyPressed, this, [this] {
if (system->IsPoweredOn()) {
Settings::values.use_speed_limit.SetValue(!Settings::values.use_speed_limit.GetValue());
}
});
// Software Keyboard Applet
connect(this, &GMainWindow::EmulationStarting, this, &GMainWindow::SoftwareKeyboardExit);
connect(this, &GMainWindow::EmulationStopping, this, &GMainWindow::SoftwareKeyboardExit);
@@ -2059,6 +2064,8 @@ void GMainWindow::BootGame(const QString& filename, Service::AM::FrontendAppletP
return;
}
current_title_id = title_id; // Store ID safely
if (type == StartGameType::Normal) {
// Load per game settings if it is a normal boot
const auto file_path =
@@ -5297,15 +5304,17 @@ void GMainWindow::OnOpenControllerMenu() {
}
void GMainWindow::OnCaptureScreenshot() {
if (emu_thread == nullptr || !emu_thread->IsRunning()) {
if (emu_thread == nullptr || !emu_thread->IsRunning() || !render_window->IsLoadingComplete()) {
return;
}
const u64 title_id = system->GetApplicationProcessProgramID();
const u64 title_id = current_title_id;
const auto screenshot_path =
QString::fromStdString(Common::FS::GetCitronPathString(Common::FS::CitronPath::ScreenshotsDir));
const auto date =
QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz"));
QString filename = QStringLiteral("%1/%2_%3.png")
.arg(screenshot_path)
.arg(title_id, 16, 16, QLatin1Char{'0'})
@@ -5326,6 +5335,7 @@ void GMainWindow::OnCaptureScreenshot() {
}
}
#endif
render_window->CaptureScreenshot(filename);
}