From 22c33d4fb42f1dce5e860ef285aa6bf75da8e866 Mon Sep 17 00:00:00 2001 From: Bevan Weiss Date: Sat, 29 Aug 2020 19:59:30 +1000 Subject: [PATCH] Added settings and logic for auto-hide of mouse cursor. In line with the Show Cursor in Fullscreen settings, these settings are only updated when the render window is first launched, and not during the game. This could be revised (along with the Fullscreen Cursor) if it's more desired. --- rpcs3/rpcs3qt/gs_frame.cpp | 30 ++++++++++++++++++++++ rpcs3/rpcs3qt/gs_frame.h | 5 ++++ rpcs3/rpcs3qt/gui_settings.h | 2 ++ rpcs3/rpcs3qt/settings_dialog.cpp | 13 ++++++++++ rpcs3/rpcs3qt/settings_dialog.ui | 41 ++++++++++++++++++++++++++++++- rpcs3/rpcs3qt/tooltips.h | 1 + 6 files changed, 91 insertions(+), 1 deletion(-) diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index abf8336656..d4c9376687 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -8,6 +8,7 @@ #include "Emu/Cell/Modules/cellScreenshot.h" #include +#include #include #include #include @@ -46,6 +47,8 @@ gs_frame::gs_frame(const QRect& geometry, const QIcon& appIcon, const std::share m_disable_mouse = gui_settings->GetValue(gui::gs_disableMouse).toBool(); m_disable_kb_hotkeys = gui_settings->GetValue(gui::gs_disableKbHotkeys).toBool(); m_show_mouse_in_fullscreen = gui_settings->GetValue(gui::gs_showMouseFs).toBool(); + m_hide_mouse_after_idletime = gui_settings->GetValue(gui::gs_hideMouseIdle).toBool(); + m_hide_mouse_idletime = gui_settings->GetValue(gui::gs_hideMouseIdleTime).toUInt(); m_window_title = qstr(Emu.GetFormattedTitle(0)); @@ -70,6 +73,14 @@ gs_frame::gs_frame(const QRect& geometry, const QIcon& appIcon, const std::share // Change cursor when in fullscreen. connect(this, &QWindow::visibilityChanged, this, &gs_frame::HandleCursor); + // Configure the mouse hide on idle timer + connect(&m_mousehide_timer, SIGNAL(timeout()), this, SLOT(MouseHideTimeout())); + m_mousehide_timer.setSingleShot(true); + if (m_hide_mouse_after_idletime) + { + m_mousehide_timer.start(m_hide_mouse_idletime); // we start the idle timer + } + #ifdef _WIN32 m_tb_button = new QWinTaskbarButton(); m_tb_progress = m_tb_button->progress(); @@ -462,10 +473,24 @@ void gs_frame::HandleCursor(QWindow::Visibility visibility) if (visibility == QWindow::Visibility::FullScreen && !m_show_mouse_in_fullscreen) { setCursor(Qt::BlankCursor); + m_mousehide_timer.stop(); } else { setCursor(Qt::ArrowCursor); + if (m_hide_mouse_after_idletime) + { + m_mousehide_timer.start(m_hide_mouse_idletime); + } + } +} + +void gs_frame::MouseHideTimeout() +{ + // our idle timeout occured, so we blank the cursor + if (m_hide_mouse_after_idletime) + { + setCursor(Qt::BlankCursor); } } @@ -502,6 +527,11 @@ bool gs_frame::event(QEvent* ev) } close(); } + if (ev->type() == QEvent::MouseMove) + { + // this will make the cursor visible again if it was hidden by the mouse idle timeout + gs_frame::HandleCursor(visibility()); + } return QWindow::event(ev); } diff --git a/rpcs3/rpcs3qt/gs_frame.h b/rpcs3/rpcs3qt/gs_frame.h index becd0b8a5b..71df75ae5c 100644 --- a/rpcs3/rpcs3qt/gs_frame.h +++ b/rpcs3/rpcs3qt/gs_frame.h @@ -5,6 +5,7 @@ #include #include +#include #ifdef _WIN32 #include @@ -29,12 +30,15 @@ private: #endif std::shared_ptr m_gui_settings; + QTimer m_mousehide_timer; u64 m_frames = 0; QString m_window_title; bool m_disable_mouse = false; bool m_disable_kb_hotkeys = false; bool m_show_mouse_in_fullscreen = false; + bool m_hide_mouse_after_idletime = false; + u32 m_hide_mouse_idletime = 2000; // 2000 milliseconds) public: gs_frame(const QRect& geometry, const QIcon& appIcon, const std::shared_ptr& gui_settings); @@ -75,4 +79,5 @@ protected: private Q_SLOTS: void HandleCursor(QWindow::Visibility visibility); + void MouseHideTimeout(); }; diff --git a/rpcs3/rpcs3qt/gui_settings.h b/rpcs3/rpcs3qt/gui_settings.h index 5d6a2c3735..621cb31ce6 100644 --- a/rpcs3/rpcs3qt/gui_settings.h +++ b/rpcs3/rpcs3qt/gui_settings.h @@ -195,6 +195,8 @@ namespace gui const gui_save gs_resize = gui_save(gs_frame, "resize", false); const gui_save gs_width = gui_save(gs_frame, "width", 1280); const gui_save gs_height = gui_save(gs_frame, "height", 720); + const gui_save gs_hideMouseIdle = gui_save(gs_frame, "hideMouseOnIdle", false); + const gui_save gs_hideMouseIdleTime = gui_save(gs_frame, "hideMouseOnIdleTime", 2000); const gui_save tr_icon_color = gui_save(trophy, "icon_color", gl_icon_color); const gui_save tr_icon_height = gui_save(trophy, "icon_height", 75); diff --git a/rpcs3/rpcs3qt/settings_dialog.cpp b/rpcs3/rpcs3qt/settings_dialog.cpp index 391db37736..1cf5701a9e 100644 --- a/rpcs3/rpcs3qt/settings_dialog.cpp +++ b/rpcs3/rpcs3qt/settings_dialog.cpp @@ -1268,6 +1268,19 @@ settings_dialog::settings_dialog(std::shared_ptr gui_settings, std m_gui_settings->SetValue(gui::gs_showMouseFs, val); }); + ui->gs_hideMouseOnIdle->setChecked(m_gui_settings->GetValue(gui::gs_hideMouseIdle).toBool()); + connect(ui->gs_hideMouseOnIdle, &QCheckBox::clicked, [this](bool val) + { + m_gui_settings->SetValue(gui::gs_hideMouseIdle, val); + ui->gs_hideMouseOnIdleTime->setEnabled(val); + }); + ui->gs_hideMouseOnIdleTime->setEnabled(m_gui_settings->GetValue(gui::gs_hideMouseIdle).toBool()); + ui->gs_hideMouseOnIdleTime->setValue(m_gui_settings->GetValue(gui::gs_hideMouseIdleTime).toUInt()); + connect(ui->gs_hideMouseOnIdleTime, &QSpinBox::editingFinished, [=, this]() + { + m_gui_settings->SetValue(gui::gs_hideMouseIdleTime, ui->gs_hideMouseOnIdleTime->value()); + }); + const bool enable_buttons = m_gui_settings->GetValue(gui::gs_resize).toBool(); ui->gs_resizeOnBoot->setChecked(enable_buttons); ui->gs_width->setEnabled(enable_buttons); diff --git a/rpcs3/rpcs3qt/settings_dialog.ui b/rpcs3/rpcs3qt/settings_dialog.ui index 534f63dadd..3d41ea712c 100644 --- a/rpcs3/rpcs3qt/settings_dialog.ui +++ b/rpcs3/rpcs3qt/settings_dialog.ui @@ -2345,10 +2345,49 @@ - Show mouse cursor in Fullscreen + Show mouse cursor in Fullscreen + + + + + + Hide mouse cursor if idle + + + + + + + true + + + QAbstractSpinBox::CorrectToNearestValue + + + false + + + mS + + + 200 + + + 99999 + + + QAbstractSpinBox::DefaultStepType + + + 2000 + + + + + diff --git a/rpcs3/rpcs3qt/tooltips.h b/rpcs3/rpcs3qt/tooltips.h index c894b9acd2..b8cdc620b5 100644 --- a/rpcs3/rpcs3qt/tooltips.h +++ b/rpcs3/rpcs3qt/tooltips.h @@ -109,6 +109,7 @@ public: const QString disable_kb_hotkeys = tr("Disables keyboard hotkeys such as Ctrl-S, Ctrl-E, Ctrl-R, Ctrl-P while the game screen is active.\nCheck this if you want to play with mouse and keyboard."); const QString max_llvm_threads = tr("Limits the maximum number of threads used for the initial PPU and SPU module compilation.\nLower this in order to increase performance of other open applications.\nThe default uses all available threads."); const QString show_mouse_in_fullscreen = tr("Shows the mouse cursor when the fullscreen mode is active.\nCurrently this may not work every time."); + const QString hide_mouse_on_idle = tr("Hides the mouse cursor if no mouse movement is detected for the configured time."); const QString show_shader_compilation_hint = tr("Shows 'Compiling shaders' hint using the native overlay."); const QString use_native_interface = tr("Enables use of native HUD within the game window that can interact with game controllers.\nWhen disabled, regular Qt dialogs are used instead.\nCurrently, the on-screen keyboard only supports the English key layout.");