Qt: Fix relative mode for PSMouse
This commit is contained in:
parent
ddbe28830e
commit
795ddee79c
|
@ -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
|
||||
|
|
|
@ -101,17 +101,15 @@ std::optional<WindowInfo> 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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<WindowInfo> 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<u32> m_keys_pressed_with_modifiers;
|
||||
|
|
|
@ -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<u32>(fullscreen), static_cast<u32>(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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
||||
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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue