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.
This commit is contained in:
Bevan Weiss 2020-08-29 19:59:30 +10:00 committed by Megamouse
parent e9cdb248a0
commit 22c33d4fb4
6 changed files with 91 additions and 1 deletions

View File

@ -8,6 +8,7 @@
#include "Emu/Cell/Modules/cellScreenshot.h"
#include <QCoreApplication>
#include <QTimer>
#include <QKeyEvent>
#include <QMessageBox>
#include <string>
@ -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);
}

View File

@ -5,6 +5,7 @@
#include <QWindow>
#include <QPaintEvent>
#include <QTimer>
#ifdef _WIN32
#include <QWinTaskbarProgress>
@ -29,12 +30,15 @@ private:
#endif
std::shared_ptr<gui_settings> 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>& gui_settings);
@ -75,4 +79,5 @@ protected:
private Q_SLOTS:
void HandleCursor(QWindow::Visibility visibility);
void MouseHideTimeout();
};

View File

@ -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);

View File

@ -1268,6 +1268,19 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> 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);

View File

@ -2345,10 +2345,49 @@
<item>
<widget class="QCheckBox" name="gs_showMouseInFullscreen">
<property name="text">
<string>Show mouse cursor in Fullscreen </string>
<string>Show mouse cursor in Fullscreen</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_hideMouseOnIdle" stretch="0,0">
<item>
<widget class="QCheckBox" name="gs_hideMouseOnIdle">
<property name="text">
<string>Hide mouse cursor if idle</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="gs_hideMouseOnIdleTime">
<property name="accelerated">
<bool>true</bool>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="suffix">
<string> mS</string>
</property>
<property name="minimum">
<number>200</number>
</property>
<property name="maximum">
<number>99999</number>
</property>
<property name="stepType">
<enum>QAbstractSpinBox::DefaultStepType</enum>
</property>
<property name="value">
<number>2000</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="gs_resizeOnBoot">
<property name="text">

View File

@ -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.");