Qt: Fix relative mode for PSMouse

This commit is contained in:
Connor McLaughlin 2022-08-10 16:32:55 +10:00
parent ddbe28830e
commit 795ddee79c
7 changed files with 45 additions and 70 deletions

View File

@ -1211,13 +1211,12 @@ bool System::BootSystem(SystemBootParameters parameters)
} }
// Good to go. // Good to go.
Host::OnSystemStarted();
UpdateSoftwareCursor();
g_spu.GetOutputStream()->SetPaused(false);
// Initial state must be set before loading state.
s_state = s_state =
(g_settings.start_paused || parameters.override_start_paused.value_or(false)) ? State::Paused : State::Running; (g_settings.start_paused || parameters.override_start_paused.value_or(false)) ? State::Paused : State::Running;
UpdateSoftwareCursor();
g_spu.GetOutputStream()->SetPaused(false);
Host::OnSystemStarted();
if (s_state == State::Paused) if (s_state == State::Paused)
Host::OnSystemPaused(); Host::OnSystemPaused();
else else

View File

@ -101,17 +101,15 @@ std::optional<WindowInfo> DisplayWidget::getWindowInfo()
return wi; return wi;
} }
void DisplayWidget::updateRelativeMode(bool master_enable) void DisplayWidget::updateRelativeMode(bool enabled)
{ {
bool relative_mode = master_enable/* && InputManager::HasPointerAxisBinds()*/;
#ifdef _WIN32 #ifdef _WIN32
// prefer ClipCursor() over warping movement when we're using raw input // prefer ClipCursor() over warping movement when we're using raw input
bool clip_cursor = relative_mode && InputManager::IsUsingRawInput(); bool clip_cursor = enabled && InputManager::IsUsingRawInput();
if (m_relative_mouse_enabled == relative_mode && m_clip_mouse_enabled == clip_cursor) if (m_relative_mouse_enabled == enabled && m_clip_mouse_enabled == clip_cursor)
return; return;
Log_InfoPrintf("updateRelativeMode(): relative=%s, clip=%s", relative_mode ? "yes" : "no", Log_InfoPrintf("updateRelativeMode(): relative=%s, clip=%s", enabled ? "yes" : "no",
clip_cursor ? "yes" : "no"); clip_cursor ? "yes" : "no");
if (!clip_cursor && m_clip_mouse_enabled) if (!clip_cursor && m_clip_mouse_enabled)
@ -120,13 +118,13 @@ void DisplayWidget::updateRelativeMode(bool master_enable)
ClipCursor(nullptr); ClipCursor(nullptr);
} }
#else #else
if (m_relative_mouse_enabled == relative_mode) if (m_relative_mouse_enabled == enabled)
return; return;
Log_InfoPrintf("updateRelativeMode(): relative=%s", relative_mode ? "yes" : "no"); Log_InfoPrintf("updateRelativeMode(): relative=%s", enabled ? "yes" : "no");
#endif #endif
if (relative_mode) if (enabled)
{ {
#ifdef _WIN32 #ifdef _WIN32
m_relative_mouse_enabled = !clip_cursor; m_relative_mouse_enabled = !clip_cursor;
@ -146,26 +144,21 @@ void DisplayWidget::updateRelativeMode(bool master_enable)
} }
} }
void DisplayWidget::updateCursor(bool master_enable) void DisplayWidget::updateCursor(bool hidden)
{ {
#ifdef _WIN32 if (m_cursor_hidden == hidden)
const bool hide = master_enable && (m_should_hide_cursor || m_relative_mouse_enabled || m_clip_mouse_enabled);
#else
const bool hide = master_enable && (m_should_hide_cursor || m_relative_mouse_enabled);
#endif
if (m_cursor_hidden == hide)
return; return;
m_cursor_hidden = hide; m_cursor_hidden = hidden;
if (hide) if (hidden)
{ {
Log_DevPrintf("updateCursor(): Cursor is now hidden");
setCursor(Qt::BlankCursor); setCursor(Qt::BlankCursor);
Log_WarningPrint("set blank cursor");
} }
else else
{ {
Log_DevPrintf("updateCursor(): Cursor is now shown");
unsetCursor(); unsetCursor();
Log_WarningPrint("clear blank cursor");
} }
} }

View File

@ -15,16 +15,14 @@ public:
QPaintEngine* paintEngine() const override; QPaintEngine* paintEngine() const override;
ALWAYS_INLINE void setShouldHideCursor(bool hide) { m_should_hide_cursor = hide; }
int scaledWindowWidth() const; int scaledWindowWidth() const;
int scaledWindowHeight() const; int scaledWindowHeight() const;
qreal devicePixelRatioFromScreen() const; qreal devicePixelRatioFromScreen() const;
std::optional<WindowInfo> getWindowInfo(); std::optional<WindowInfo> getWindowInfo();
void updateRelativeMode(bool master_enable); void updateRelativeMode(bool enabled);
void updateCursor(bool master_enable); void updateCursor(bool hidden);
Q_SIGNALS: Q_SIGNALS:
void windowResizedEvent(int width, int height, float scale); void windowResizedEvent(int width, int height, float scale);
@ -46,7 +44,6 @@ private:
#ifdef _WIN32 #ifdef _WIN32
bool m_clip_mouse_enabled = false; bool m_clip_mouse_enabled = false;
#endif #endif
bool m_should_hide_cursor = false;
bool m_cursor_hidden = false; bool m_cursor_hidden = false;
std::vector<u32> m_keys_pressed_with_modifiers; std::vector<u32> m_keys_pressed_with_modifiers;

View File

@ -142,12 +142,6 @@ bool MainWindow::confirmMessage(const QString& title, const QString& message)
return (QMessageBox::question(this, title, message) == QMessageBox::Yes); return (QMessageBox::question(this, title, message) == QMessageBox::Yes);
} }
bool MainWindow::shouldHideCursor() const
{
return m_mouse_cursor_hidden ||
(isRenderingFullscreen() && Host::GetBoolSettingValue("Main", "HideCursorInFullscreen", true));
}
bool MainWindow::createDisplay(bool fullscreen, bool render_to_main) bool MainWindow::createDisplay(bool fullscreen, bool render_to_main)
{ {
Log_DevPrintf("createDisplay(%u, %u)", static_cast<u32>(fullscreen), static_cast<u32>(render_to_main)); Log_DevPrintf("createDisplay(%u, %u)", static_cast<u32>(fullscreen), static_cast<u32>(render_to_main));
@ -183,16 +177,13 @@ bool MainWindow::createDisplay(bool fullscreen, bool render_to_main)
updateWindowTitle(); updateWindowTitle();
updateWindowState(); updateWindowState();
m_display_widget->setFocus();
m_ui.actionStartFullscreenUI->setEnabled(false); m_ui.actionStartFullscreenUI->setEnabled(false);
m_ui.actionStartFullscreenUI2->setEnabled(false); m_ui.actionStartFullscreenUI2->setEnabled(false);
m_ui.actionViewSystemDisplay->setEnabled(true); m_ui.actionViewSystemDisplay->setEnabled(true);
m_ui.actionFullscreen->setEnabled(true); m_ui.actionFullscreen->setEnabled(true);
updateDisplayWidgetCursor();
m_display_widget->setFocus(); m_display_widget->setFocus();
m_display_widget->setShouldHideCursor(shouldHideMouseCursor());
m_display_widget->updateRelativeMode(s_system_valid && !s_system_paused);
m_display_widget->updateCursor(s_system_valid && !s_system_paused);
g_host_display->DoneRenderContextCurrent(); g_host_display->DoneRenderContextCurrent();
return true; return true;
@ -238,10 +229,8 @@ bool MainWindow::updateDisplay(bool fullscreen, bool render_to_main, bool surfac
container->showNormal(); container->showNormal();
} }
updateDisplayWidgetCursor();
m_display_widget->setFocus(); m_display_widget->setFocus();
m_display_widget->setShouldHideCursor(shouldHideMouseCursor());
m_display_widget->updateRelativeMode(s_system_valid && !s_system_paused);
m_display_widget->updateCursor(s_system_valid && !s_system_paused);
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
return true; return true;
@ -278,11 +267,8 @@ bool MainWindow::updateDisplay(bool fullscreen, bool render_to_main, bool surfac
updateWindowTitle(); updateWindowTitle();
updateWindowState(); updateWindowState();
updateDisplayWidgetCursor();
m_display_widget->setFocus(); m_display_widget->setFocus();
m_display_widget->setShouldHideCursor(shouldHideMouseCursor());
m_display_widget->updateRelativeMode(m_relative_mouse_mode && s_system_valid && !s_system_paused);
m_display_widget->updateCursor(s_system_valid && !s_system_paused);
QSignalBlocker blocker(m_ui.actionFullscreen); QSignalBlocker blocker(m_ui.actionFullscreen);
m_ui.actionFullscreen->setChecked(fullscreen); m_ui.actionFullscreen->setChecked(fullscreen);
@ -460,6 +446,12 @@ void MainWindow::destroyDisplayWidget(bool show_game_list)
} }
} }
void MainWindow::updateDisplayWidgetCursor()
{
m_display_widget->updateRelativeMode(s_system_valid && !s_system_paused && m_relative_mouse_mode);
m_display_widget->updateCursor(s_system_valid && !s_system_paused && shouldHideMouseCursor());
}
void MainWindow::focusDisplayWidget() void MainWindow::focusDisplayWidget()
{ {
if (!m_display_widget || centralWidget() != m_display_widget) if (!m_display_widget || centralWidget() != m_display_widget)
@ -481,19 +473,9 @@ QWidget* MainWindow::getDisplayContainer() const
void MainWindow::onMouseModeRequested(bool relative_mode, bool hide_cursor) void MainWindow::onMouseModeRequested(bool relative_mode, bool hide_cursor)
{ {
m_relative_mouse_mode = relative_mode; m_relative_mouse_mode = relative_mode;
m_mouse_cursor_hidden = hide_cursor; m_hide_mouse_cursor = hide_cursor;
if (m_display_widget) if (m_display_widget)
{ updateDisplayWidgetCursor();
m_display_widget->setShouldHideCursor(shouldHideCursor());
const bool update = s_system_valid && !s_system_paused;
m_display_widget->updateCursor(update);
if (update)
m_display_widget->updateRelativeMode(m_relative_mouse_mode);
}
} }
void MainWindow::onSystemStarting() void MainWindow::onSystemStarting()
@ -525,10 +507,7 @@ void MainWindow::onSystemPaused()
updateStatusBarWidgetVisibility(); updateStatusBarWidgetVisibility();
m_ui.statusBar->showMessage(tr("Paused")); m_ui.statusBar->showMessage(tr("Paused"));
if (m_display_widget) if (m_display_widget)
{ updateDisplayWidgetCursor();
m_display_widget->updateRelativeMode(false);
m_display_widget->updateCursor(false);
}
} }
void MainWindow::onSystemResumed() void MainWindow::onSystemResumed()
@ -545,8 +524,7 @@ void MainWindow::onSystemResumed()
updateStatusBarWidgetVisibility(); updateStatusBarWidgetVisibility();
if (m_display_widget) if (m_display_widget)
{ {
m_display_widget->updateRelativeMode(m_relative_mouse_mode); updateDisplayWidgetCursor();
m_display_widget->updateCursor(true);
m_display_widget->setFocus(); m_display_widget->setFocus();
} }
} }
@ -1729,7 +1707,8 @@ bool MainWindow::isRenderingToMain() const
bool MainWindow::shouldHideMouseCursor() const bool MainWindow::shouldHideMouseCursor() const
{ {
return isRenderingFullscreen() && Host::GetBoolSettingValue("Main", "HideCursorInFullscreen", false); return m_hide_mouse_cursor ||
(isRenderingFullscreen() && Host::GetBoolSettingValue("Main", "HideCursorInFullscreen", false));
} }
bool MainWindow::shouldHideMainWindow() const bool MainWindow::shouldHideMainWindow() const

View File

@ -199,8 +199,8 @@ private:
void restoreDisplayWindowGeometryFromConfig(); void restoreDisplayWindowGeometryFromConfig();
void createDisplayWidget(bool fullscreen, bool render_to_main, bool is_exclusive_fullscreen); void createDisplayWidget(bool fullscreen, bool render_to_main, bool is_exclusive_fullscreen);
void destroyDisplayWidget(bool show_game_list); void destroyDisplayWidget(bool show_game_list);
void updateDisplayWidgetCursor();
void setDisplayFullscreen(const std::string& fullscreen_mode); void setDisplayFullscreen(const std::string& fullscreen_mode);
bool shouldHideCursor() const;
SettingsDialog* getSettingsDialog(); SettingsDialog* getSettingsDialog();
void doSettings(const char* category = nullptr); void doSettings(const char* category = nullptr);
@ -261,7 +261,7 @@ private:
bool m_was_paused_by_focus_loss = false; bool m_was_paused_by_focus_loss = false;
bool m_open_debugger_on_start = false; bool m_open_debugger_on_start = false;
bool m_relative_mouse_mode = false; bool m_relative_mouse_mode = false;
bool m_mouse_cursor_hidden = false; bool m_hide_mouse_cursor = false;
bool m_display_created = false; bool m_display_created = false;
bool m_save_states_invalidated = false; bool m_save_states_invalidated = false;

View File

@ -671,6 +671,7 @@ void EmuThread::onDisplayWindowMouseMoveEvent(bool relative, float x, float y)
g_host_display->SetMousePosition(static_cast<s32>(x), static_cast<s32>(y)); g_host_display->SetMousePosition(static_cast<s32>(x), static_cast<s32>(y));
InputManager::UpdatePointerAbsolutePosition(0, x, y); InputManager::UpdatePointerAbsolutePosition(0, x, y);
ImGuiManager::UpdateMousePosition(x, y);
} }
else else
{ {
@ -678,6 +679,14 @@ void EmuThread::onDisplayWindowMouseMoveEvent(bool relative, float x, float y)
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::X, x); InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::X, x);
if (y != 0.0f) if (y != 0.0f)
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::Y, y); InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::Y, y);
if (g_host_display)
{
const float abs_x = static_cast<float>(g_host_display->GetMousePositionX()) + x;
const float abs_y = static_cast<float>(g_host_display->GetMousePositionY()) + y;
g_host_display->SetMousePosition(static_cast<s32>(abs_x), static_cast<s32>(abs_y));
ImGuiManager::UpdateMousePosition(abs_x, abs_y);
}
} }
} }

View File

@ -857,8 +857,6 @@ void InputManager::UpdatePointerAbsolutePosition(u32 index, float x, float y)
UpdatePointerRelativeDelta(index, InputPointerAxis::X, dx); UpdatePointerRelativeDelta(index, InputPointerAxis::X, dx);
if (dy != 0.0f) if (dy != 0.0f)
UpdatePointerRelativeDelta(index, InputPointerAxis::Y, dy); UpdatePointerRelativeDelta(index, InputPointerAxis::Y, dy);
ImGuiManager::UpdateMousePosition(x, y);
} }
void InputManager::UpdatePointerRelativeDelta(u32 index, InputPointerAxis axis, float d, bool raw_input) void InputManager::UpdatePointerRelativeDelta(u32 index, InputPointerAxis axis, float d, bool raw_input)