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

@ -313,6 +313,18 @@ void keyboard_pad_handler::mouseReleaseEvent(QMouseEvent* event)
event->ignore();
}
bool keyboard_pad_handler::get_mouse_lock_state()
{
if (m_target)
{
auto mouse_locked = m_target->property("mouse_locked");
if (mouse_locked.isValid())
return mouse_locked.toBool();
return false;
}
return false;
}
void keyboard_pad_handler::mouseMoveEvent(QMouseEvent* event)
{
static int movement_x = 0;
@ -320,7 +332,7 @@ void keyboard_pad_handler::mouseMoveEvent(QMouseEvent* event)
static int last_pos_x = 0;
static int last_pos_y = 0;
if (m_target && m_target->visibility() == QWindow::Visibility::FullScreen && m_target->isActive())
if (m_target && m_target->isActive() && get_mouse_lock_state())
{
// get the screen dimensions
const QSize screen = m_target->size();