diff --git a/src/core/system.cpp b/src/core/system.cpp index 0b86258af..a5beaaf65 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1211,13 +1211,12 @@ bool System::BootSystem(SystemBootParameters parameters) } // Good to go. - Host::OnSystemStarted(); - UpdateSoftwareCursor(); - g_spu.GetOutputStream()->SetPaused(false); - - // Initial state must be set before loading state. s_state = (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) Host::OnSystemPaused(); else diff --git a/src/duckstation-qt/displaywidget.cpp b/src/duckstation-qt/displaywidget.cpp index 7feb177fe..9d9c1bc74 100644 --- a/src/duckstation-qt/displaywidget.cpp +++ b/src/duckstation-qt/displaywidget.cpp @@ -101,17 +101,15 @@ std::optional DisplayWidget::getWindowInfo() return wi; } -void DisplayWidget::updateRelativeMode(bool master_enable) +void DisplayWidget::updateRelativeMode(bool enabled) { - bool relative_mode = master_enable/* && InputManager::HasPointerAxisBinds()*/; - #ifdef _WIN32 // prefer ClipCursor() over warping movement when we're using raw input - bool clip_cursor = relative_mode && InputManager::IsUsingRawInput(); - if (m_relative_mouse_enabled == relative_mode && m_clip_mouse_enabled == clip_cursor) + bool clip_cursor = enabled && InputManager::IsUsingRawInput(); + if (m_relative_mouse_enabled == enabled && m_clip_mouse_enabled == clip_cursor) 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"); if (!clip_cursor && m_clip_mouse_enabled) @@ -120,13 +118,13 @@ void DisplayWidget::updateRelativeMode(bool master_enable) ClipCursor(nullptr); } #else - if (m_relative_mouse_enabled == relative_mode) + if (m_relative_mouse_enabled == enabled) return; - Log_InfoPrintf("updateRelativeMode(): relative=%s", relative_mode ? "yes" : "no"); + Log_InfoPrintf("updateRelativeMode(): relative=%s", enabled ? "yes" : "no"); #endif - if (relative_mode) + if (enabled) { #ifdef _WIN32 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 - 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) + if (m_cursor_hidden == hidden) return; - m_cursor_hidden = hide; - if (hide) + m_cursor_hidden = hidden; + if (hidden) { + Log_DevPrintf("updateCursor(): Cursor is now hidden"); setCursor(Qt::BlankCursor); - Log_WarningPrint("set blank cursor"); } else { + Log_DevPrintf("updateCursor(): Cursor is now shown"); unsetCursor(); - Log_WarningPrint("clear blank cursor"); } } diff --git a/src/duckstation-qt/displaywidget.h b/src/duckstation-qt/displaywidget.h index 85103fdda..ed7522b01 100644 --- a/src/duckstation-qt/displaywidget.h +++ b/src/duckstation-qt/displaywidget.h @@ -15,16 +15,14 @@ public: QPaintEngine* paintEngine() const override; - ALWAYS_INLINE void setShouldHideCursor(bool hide) { m_should_hide_cursor = hide; } - int scaledWindowWidth() const; int scaledWindowHeight() const; qreal devicePixelRatioFromScreen() const; std::optional getWindowInfo(); - void updateRelativeMode(bool master_enable); - void updateCursor(bool master_enable); + void updateRelativeMode(bool enabled); + void updateCursor(bool hidden); Q_SIGNALS: void windowResizedEvent(int width, int height, float scale); @@ -46,7 +44,6 @@ private: #ifdef _WIN32 bool m_clip_mouse_enabled = false; #endif - bool m_should_hide_cursor = false; bool m_cursor_hidden = false; std::vector m_keys_pressed_with_modifiers; diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index bb17d120a..bda4f2f5c 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -142,12 +142,6 @@ bool MainWindow::confirmMessage(const QString& title, const QString& message) 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) { Log_DevPrintf("createDisplay(%u, %u)", static_cast(fullscreen), static_cast(render_to_main)); @@ -183,16 +177,13 @@ bool MainWindow::createDisplay(bool fullscreen, bool render_to_main) updateWindowTitle(); updateWindowState(); - m_display_widget->setFocus(); m_ui.actionStartFullscreenUI->setEnabled(false); m_ui.actionStartFullscreenUI2->setEnabled(false); m_ui.actionViewSystemDisplay->setEnabled(true); m_ui.actionFullscreen->setEnabled(true); + updateDisplayWidgetCursor(); 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(); return true; @@ -238,10 +229,8 @@ bool MainWindow::updateDisplay(bool fullscreen, bool render_to_main, bool surfac container->showNormal(); } + updateDisplayWidgetCursor(); 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); return true; @@ -278,11 +267,8 @@ bool MainWindow::updateDisplay(bool fullscreen, bool render_to_main, bool surfac updateWindowTitle(); updateWindowState(); - + updateDisplayWidgetCursor(); 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); 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() { 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) { m_relative_mouse_mode = relative_mode; - m_mouse_cursor_hidden = hide_cursor; - + m_hide_mouse_cursor = hide_cursor; if (m_display_widget) - { - 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); - } + updateDisplayWidgetCursor(); } void MainWindow::onSystemStarting() @@ -525,10 +507,7 @@ void MainWindow::onSystemPaused() updateStatusBarWidgetVisibility(); m_ui.statusBar->showMessage(tr("Paused")); if (m_display_widget) - { - m_display_widget->updateRelativeMode(false); - m_display_widget->updateCursor(false); - } + updateDisplayWidgetCursor(); } void MainWindow::onSystemResumed() @@ -545,8 +524,7 @@ void MainWindow::onSystemResumed() updateStatusBarWidgetVisibility(); if (m_display_widget) { - m_display_widget->updateRelativeMode(m_relative_mouse_mode); - m_display_widget->updateCursor(true); + updateDisplayWidgetCursor(); m_display_widget->setFocus(); } } @@ -1729,7 +1707,8 @@ bool MainWindow::isRenderingToMain() 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 diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index d28d4e04f..463132be0 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -199,8 +199,8 @@ private: void restoreDisplayWindowGeometryFromConfig(); void createDisplayWidget(bool fullscreen, bool render_to_main, bool is_exclusive_fullscreen); void destroyDisplayWidget(bool show_game_list); + void updateDisplayWidgetCursor(); void setDisplayFullscreen(const std::string& fullscreen_mode); - bool shouldHideCursor() const; SettingsDialog* getSettingsDialog(); void doSettings(const char* category = nullptr); @@ -261,7 +261,7 @@ private: bool m_was_paused_by_focus_loss = false; bool m_open_debugger_on_start = 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_save_states_invalidated = false; diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 8ca07e41f..c8a3b94ea 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -671,6 +671,7 @@ void EmuThread::onDisplayWindowMouseMoveEvent(bool relative, float x, float y) g_host_display->SetMousePosition(static_cast(x), static_cast(y)); InputManager::UpdatePointerAbsolutePosition(0, x, y); + ImGuiManager::UpdateMousePosition(x, y); } else { @@ -678,6 +679,14 @@ void EmuThread::onDisplayWindowMouseMoveEvent(bool relative, float x, float y) InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::X, x); if (y != 0.0f) InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::Y, y); + + if (g_host_display) + { + const float abs_x = static_cast(g_host_display->GetMousePositionX()) + x; + const float abs_y = static_cast(g_host_display->GetMousePositionY()) + y; + g_host_display->SetMousePosition(static_cast(abs_x), static_cast(abs_y)); + ImGuiManager::UpdateMousePosition(abs_x, abs_y); + } } } diff --git a/src/frontend-common/input_manager.cpp b/src/frontend-common/input_manager.cpp index 7b83f14e1..d4f6dcaea 100644 --- a/src/frontend-common/input_manager.cpp +++ b/src/frontend-common/input_manager.cpp @@ -857,8 +857,6 @@ void InputManager::UpdatePointerAbsolutePosition(u32 index, float x, float y) UpdatePointerRelativeDelta(index, InputPointerAxis::X, dx); if (dy != 0.0f) UpdatePointerRelativeDelta(index, InputPointerAxis::Y, dy); - - ImGuiManager::UpdateMousePosition(x, y); } void InputManager::UpdatePointerRelativeDelta(u32 index, InputPointerAxis axis, float d, bool raw_input)