Qt: Add hotkey to toggle mouse lock

This commit is contained in:
Alexei Doell
2026-02-24 11:55:09 -05:00
committed by Ty
parent dadf043e8c
commit b7d2b1a26c
10 changed files with 55 additions and 0 deletions
+4
View File
@@ -212,6 +212,10 @@ void Host::SetMouseMode(bool relative_mode, bool hide_cursor)
{
}
void Host::SetMouseLock(bool state)
{
}
std::optional<WindowInfo> Host::AcquireRenderWindow(bool recreate_window)
{
return GSRunner::GetPlatformWindowInfo();
+25
View File
@@ -440,6 +440,7 @@ void MainWindow::connectVMThreadSignals(EmuThread* thread)
connect(thread, &EmuThread::onReleaseRenderWindowRequested, this, &MainWindow::releaseRenderWindow, Qt::BlockingQueuedConnection);
connect(thread, &EmuThread::onResizeRenderWindowRequested, this, &MainWindow::displayResizeRequested);
connect(thread, &EmuThread::onMouseModeRequested, this, &MainWindow::mouseModeRequested);
connect(thread, &EmuThread::onMouseLockRequested, this, &MainWindow::mouseLockRequested);
connect(thread, &EmuThread::onFullscreenUIStateChange, this, &MainWindow::onFullscreenUIStateChange);
connect(thread, &EmuThread::onVMStarting, this, &MainWindow::onVMStarting);
connect(thread, &EmuThread::onVMStarted, this, &MainWindow::onVMStarted);
@@ -2664,6 +2665,30 @@ void MainWindow::mouseModeRequested(bool relative_mode, bool hide_cursor)
updateDisplayWidgetCursor();
}
void MainWindow::mouseLockRequested(bool state)
{
#ifdef __linux__ // Mouse locking is only supported on X11
const bool mouse_lock_supported = QGuiApplication::platformName().toLower() == "xcb";
if (!mouse_lock_supported)
return;
#endif
Host::SetBaseBoolSettingValue("EmuCore", "EnableMouseLock", state);
Host::CommitBaseSettingChanges();
if (state) {
setupMouseMoveHandler();
} else {
Common::DetachMousePositionCb();
}
if (m_settings_window)
{
InterfaceSettingsWidget* interface_settings = m_settings_window->getInterfaceSettingsWidget();
interface_settings->updateMouseLockCheckbox(state ? Qt::Checked : Qt::Unchecked);
}
}
void MainWindow::releaseRenderWindow()
{
// Now we can safely destroy the display window.
+1
View File
@@ -138,6 +138,7 @@ private Q_SLOTS:
std::optional<WindowInfo> acquireRenderWindow(bool recreate_window, bool fullscreen, bool render_to_main, bool surfaceless);
void displayResizeRequested(qint32 width, qint32 height);
void mouseModeRequested(bool relative_mode, bool hide_cursor);
void mouseLockRequested(bool state);
void releaseRenderWindow();
void setupMouseMoveHandler();
void onGameListRefreshComplete();
+5
View File
@@ -1737,6 +1737,11 @@ void Host::SetMouseMode(bool relative_mode, bool hide_cursor)
emit g_emu_thread->onMouseModeRequested(relative_mode, hide_cursor);
}
void Host::SetMouseLock(bool state)
{
emit g_emu_thread->onMouseLockRequested(state);
}
void QtHost::LockVMWithDialog()
{
s_vm_locked_with_dialog++;
+1
View File
@@ -119,6 +119,7 @@ Q_SIGNALS:
void onResizeRenderWindowRequested(qint32 width, qint32 height);
void onReleaseRenderWindowRequested();
void onMouseModeRequested(bool relative_mode, bool hide_cursor);
void onMouseLockRequested(bool state);
void onFullscreenUIStateChange(bool running);
/// Called when the VM is starting initialization, but has not been completed yet.
@@ -250,6 +250,12 @@ void InterfaceSettingsWidget::updatePromptOnStateLoadSaveFailureCheckbox(Qt::Che
m_ui.promptOnStateLoadSaveFailure->setCheckState(state);
}
void InterfaceSettingsWidget::updateMouseLockCheckbox(Qt::CheckState state)
{
QSignalBlocker blocker(m_ui.mouseLock);
m_ui.mouseLock->setCheckState(state);
}
void InterfaceSettingsWidget::onRenderToSeparateWindowChanged()
{
m_ui.hideMainWindow->setEnabled(m_ui.renderToSeparateWindow->isChecked());
@@ -16,6 +16,7 @@ public:
~InterfaceSettingsWidget();
void updatePromptOnStateLoadSaveFailureCheckbox(Qt::CheckState state);
void updateMouseLockCheckbox(Qt::CheckState state);
Q_SIGNALS:
void themeChanged();
+5
View File
@@ -340,4 +340,9 @@ DEFINE_HOTKEY("DecreaseVolume", TRANSLATE_NOOP("Hotkeys", "Audio"), TRANSLATE_NO
if (!pressed && VMManager::HasValidVM())
HotkeyAdjustVolume(-5);
})
DEFINE_HOTKEY("ToggleMouseLock", TRANSLATE_NOOP("Hotkeys", "System"), TRANSLATE_NOOP("Hotkeys", "Toggle Mouse Lock"),
[](s32 pressed) {
if (!pressed)
Host::SetMouseLock(!Host::GetBoolSettingValue("EmuCore", "EnableMouseLock"));
})
END_HOTKEY_LIST()
+3
View File
@@ -323,4 +323,7 @@ namespace Host
/// Enables relative mouse mode in the host, and/or hides the cursor.
void SetMouseMode(bool relative_mode, bool hide_cursor);
/// Changes the mouse lock setting
void SetMouseLock(bool state);
} // namespace Host
+4
View File
@@ -90,6 +90,10 @@ void Host::SetMouseMode(bool relative_mode, bool hide_cursor)
{
}
void Host::SetMouseLock(bool state)
{
}
std::optional<WindowInfo> Host::AcquireRenderWindow(bool recreate_window)
{
return std::nullopt;