From 2f5eec3576a961ec1a21368166cab676e9db3043 Mon Sep 17 00:00:00 2001 From: Vitor K Date: Sat, 5 Dec 2020 18:12:17 -0300 Subject: [PATCH] Fixes to "hide mouse on inactivity" (#5476) The feature wasn't working when the "single window mode" was off. Changed the cursor setting to only affect the render_window and moved to a signal/slot model to show the mouse. --- src/citra_qt/bootmanager.cpp | 5 +++-- src/citra_qt/bootmanager.h | 3 +++ src/citra_qt/main.cpp | 28 +++++++++++++++------------- src/citra_qt/main.h | 2 ++ 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 97e956baa..18f7e8ea6 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -297,7 +297,7 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) { } else if (event->button() == Qt::RightButton) { InputCommon::GetMotionEmu()->BeginTilt(pos.x(), pos.y()); } - QWidget::mousePressEvent(event); + emit MouseActivity(); } void GRenderWindow::mouseMoveEvent(QMouseEvent* event) { @@ -308,7 +308,7 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) { const auto [x, y] = ScaleTouch(pos); this->TouchMoved(x, y); InputCommon::GetMotionEmu()->Tilt(pos.x(), pos.y()); - QWidget::mouseMoveEvent(event); + emit MouseActivity(); } void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) { @@ -319,6 +319,7 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) { this->TouchReleased(); else if (event->button() == Qt::RightButton) InputCommon::GetMotionEmu()->EndTilt(); + emit MouseActivity(); } void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) { diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h index ab9bd7197..3dec9751b 100644 --- a/src/citra_qt/bootmanager.h +++ b/src/citra_qt/bootmanager.h @@ -199,6 +199,9 @@ signals: */ void FirstFrameDisplayed(); + /// Emitted on mouse activity. Used to signal that the mouse should be shown if it's hidden + void MouseActivity(); + private: std::pair ScaleTouch(QPointF pos) const; void TouchBeginEvent(const QTouchEvent* event); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 0bca4de9d..a804bfb98 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -203,13 +203,9 @@ GMainWindow::GMainWindow() // Show one-time "callout" messages to the user ShowTelemetryCallout(); - // make sure menubar has the arrow cursor instead of inheriting from this - ui->menubar->setCursor(QCursor()); - statusBar()->setCursor(QCursor()); - mouse_hide_timer.setInterval(default_mouse_timeout); connect(&mouse_hide_timer, &QTimer::timeout, this, &GMainWindow::HideMouseCursor); - connect(ui->menubar, &QMenuBar::hovered, this, &GMainWindow::ShowMouseCursor); + connect(ui->menubar, &QMenuBar::hovered, this, &GMainWindow::OnMouseActivity); if (UISettings::values.check_for_update_on_start) { CheckForUpdates(); @@ -1026,6 +1022,8 @@ void GMainWindow::BootGame(const QString& filename) { emu_thread->start(); connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); + connect(render_window, &GRenderWindow::MouseActivity, this, &GMainWindow::OnMouseActivity); + // BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views // before the CPU continues connect(emu_thread.get(), &EmuThread::DebugModeEntered, registersWidget, @@ -1051,7 +1049,6 @@ void GMainWindow::BootGame(const QString& filename) { if (UISettings::values.hide_mouse) { mouse_hide_timer.start(); setMouseTracking(true); - ui->centralwidget->setMouseTracking(true); } // show and hide the render_window to create the context @@ -1153,7 +1150,6 @@ void GMainWindow::ShutdownGame() { game_list->setFilterFocus(); setMouseTracking(false); - ui->centralwidget->setMouseTracking(false); // Disable status bar updates status_bar_update_timer.stop(); @@ -1750,11 +1746,9 @@ void GMainWindow::OnConfigure() { config->Save(); if (UISettings::values.hide_mouse && emulation_running) { setMouseTracking(true); - ui->centralwidget->setMouseTracking(true); mouse_hide_timer.start(); } else { setMouseTracking(false); - ui->centralwidget->setMouseTracking(false); } } else { Settings::values.input_profiles = old_input_profiles; @@ -2089,22 +2083,30 @@ void GMainWindow::HideMouseCursor() { ShowMouseCursor(); return; } - setCursor(QCursor(Qt::BlankCursor)); + render_window->setCursor(QCursor(Qt::BlankCursor)); } void GMainWindow::ShowMouseCursor() { - unsetCursor(); + render_window->unsetCursor(); if (emu_thread != nullptr && UISettings::values.hide_mouse) { mouse_hide_timer.start(); } } -void GMainWindow::mouseMoveEvent(QMouseEvent* event) { +void GMainWindow::OnMouseActivity() { ShowMouseCursor(); } +void GMainWindow::mouseMoveEvent(QMouseEvent* event) { + OnMouseActivity(); +} + void GMainWindow::mousePressEvent(QMouseEvent* event) { - ShowMouseCursor(); + OnMouseActivity(); +} + +void GMainWindow::mouseReleaseEvent(QMouseEvent* event) { + OnMouseActivity(); } void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string details) { diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index fef8dee48..a570878b8 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h @@ -221,6 +221,7 @@ private slots: void OnCheckForUpdates(); void OnOpenUpdater(); void OnLanguageChanged(const QString& locale); + void OnMouseActivity(); private: bool ValidateMovie(const QString& path, u64 program_id = 0); @@ -313,6 +314,7 @@ protected: void dragMoveEvent(QDragMoveEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; void mousePressEvent(QMouseEvent* event) override; + void mouseReleaseEvent(QMouseEvent* event) override; }; Q_DECLARE_METATYPE(std::size_t);