GUI: Mouse Hide and Lock Keyboard Shortcut

This should address the second point of #4502.

A few notes:
1. it changes the current behaviour of the 'Fullscreen cursor'.  Currently it defaults to be captive.  This changes it so that it defaults to NOT being captive, but can be made captive with the CTRL+L key combination.
2. There are situations when in windowed mode it's possible to escape the captivity (it's like a minigame if you will).  This requires the mouse movement to exceed the bounds of the window in a single event scan.  It will just show up as a temporary visibility of the cursor when outside of the window bounds.  It's not too difficult to 'fix', but might not be a likely enough scenario to warrant either.
3. There currently isn't an ability to change what this keyboard combo maps to, but it's inline with a collection of other similar keyboard mappings.  I think adding such a more generic keyboard mapping system (not for just keypad items, but system items.. e.g. so that Emulator stop could be mapped to something other than CTRL+S etc) is a bit out-of-scope of this particular PR.
This commit is contained in:
Bevan Weiss 2020-08-30 15:12:36 +10:00 committed by Megamouse
parent a86a3d2fee
commit ca3ee019cc
6 changed files with 60 additions and 4 deletions

View file

@ -76,6 +76,11 @@ gs_frame::gs_frame(const QRect& geometry, const QIcon& appIcon, const std::share
connect(&m_mousehide_timer, &QTimer::timeout, this, &gs_frame::MouseHideTimeout);
m_mousehide_timer.setSingleShot(true);
// We default the mouse lock to being off
m_mouse_hide_and_lock = false;
// and we 'publish' this to the property values of this window
setProperty("mouse_locked", m_mouse_hide_and_lock);
#ifdef _WIN32
m_tb_button = new QWinTaskbarButton();
m_tb_progress = m_tb_button->progress();
@ -135,6 +140,11 @@ void gs_frame::keyPressEvent(QKeyEvent *keyEvent)
screenshot.success("Made forced mark %d in log", ++count);
return;
}
else if (keyEvent->modifiers() == Qt::ControlModifier)
{
toggle_mouselock();
return;
}
break;
case Qt::Key_Return:
if (keyEvent->modifiers() == Qt::AltModifier)
@ -209,6 +219,17 @@ void gs_frame::toggle_fullscreen()
});
}
void gs_frame::toggle_mouselock()
{
// first we toggle the value
m_mouse_hide_and_lock = !m_mouse_hide_and_lock;
// and then we publish it to the window properties
setProperty("mouse_locked", m_mouse_hide_and_lock);
HandleCursor(this->visibility());
}
void gs_frame::close()
{
Emu.Stop();
@ -465,14 +486,18 @@ void gs_frame::mouseDoubleClickEvent(QMouseEvent* ev)
void gs_frame::HandleCursor(QWindow::Visibility visibility)
{
if (visibility == QWindow::Visibility::FullScreen && !m_show_mouse_in_fullscreen)
if (m_mouse_hide_and_lock || (visibility == QWindow::Visibility::FullScreen && !m_show_mouse_in_fullscreen))
{
setCursor(Qt::BlankCursor);
m_mousehide_timer.stop();
}
else
{
setCursor(Qt::ArrowCursor);
if (!m_mouse_hide_and_lock)
{
setCursor(Qt::ArrowCursor);
}
if (m_hide_mouse_after_idletime)
{
m_mousehide_timer.start(m_hide_mouse_idletime);