From ae0e454fc2c5d1da0d954dd53fd64fa0007a97af Mon Sep 17 00:00:00 2001 From: Bevan Weiss Date: Mon, 31 Aug 2020 00:09:38 +1000 Subject: [PATCH] Use dynamic_cast to convert QWindow m_target to gs_frame Used to access get_mouse_lock_state rather than going through the QWindow property tables. Modify mouse hide and lock to default OFF when entering Windowed mode, and to default ON when entering Fullscreen unless 'show cursor in fullscreen' is configured --- rpcs3/Input/basic_mouse_handler.cpp | 9 ++------- rpcs3/Input/basic_mouse_handler.h | 1 + rpcs3/Input/keyboard_pad_handler.cpp | 10 +++------- rpcs3/rpcs3qt/gs_frame.cpp | 25 ++++++++++++++----------- rpcs3/rpcs3qt/gs_frame.h | 2 ++ 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/rpcs3/Input/basic_mouse_handler.cpp b/rpcs3/Input/basic_mouse_handler.cpp index b1b8f54563..4d1464601a 100644 --- a/rpcs3/Input/basic_mouse_handler.cpp +++ b/rpcs3/Input/basic_mouse_handler.cpp @@ -91,13 +91,8 @@ void basic_mouse_handler::MouseScroll(QWheelEvent* event) bool basic_mouse_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; - } + if (auto game_frame = dynamic_cast(m_target)) + return game_frame->get_mouse_lock_state(); return false; } diff --git a/rpcs3/Input/basic_mouse_handler.h b/rpcs3/Input/basic_mouse_handler.h index 06cea8ab24..791875148e 100644 --- a/rpcs3/Input/basic_mouse_handler.h +++ b/rpcs3/Input/basic_mouse_handler.h @@ -2,6 +2,7 @@ #include "stdafx.h" #include "Emu/Io/MouseHandler.h" +#include "rpcs3qt/gs_frame.h" #include #include diff --git a/rpcs3/Input/keyboard_pad_handler.cpp b/rpcs3/Input/keyboard_pad_handler.cpp index 3601828f4c..3022fa39ae 100644 --- a/rpcs3/Input/keyboard_pad_handler.cpp +++ b/rpcs3/Input/keyboard_pad_handler.cpp @@ -2,6 +2,7 @@ #include "pad_thread.h" #include "Emu/Io/pad_config.h" #include "Input/product_info.h" +#include "rpcs3qt/gs_frame.h" #include @@ -315,13 +316,8 @@ void keyboard_pad_handler::mouseReleaseEvent(QMouseEvent* event) 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; - } + if (auto game_frame = dynamic_cast(m_target)) + return game_frame->get_mouse_lock_state(); return false; } diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index 39b91dbad9..370c4b9d27 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -78,8 +78,6 @@ gs_frame::gs_frame(const QRect& geometry, const QIcon& appIcon, const std::share // 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(); @@ -211,10 +209,15 @@ void gs_frame::toggle_fullscreen() if (visibility() == FullScreen) { setVisibility(Windowed); + // in windowed mode we default to not hiding / locking the mouse + m_mouse_hide_and_lock = false; } else { setVisibility(FullScreen); + // in fullscreen (unless we want to show mouse) then we default to hiding and locking + if (!m_show_mouse_in_fullscreen) + m_mouse_hide_and_lock = true; } }); } @@ -224,12 +227,15 @@ 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); - + // and update the cursor HandleCursor(this->visibility()); } +bool gs_frame::get_mouse_lock_state() +{ + return m_mouse_hide_and_lock; +} + void gs_frame::close() { Emu.Stop(); @@ -484,19 +490,16 @@ void gs_frame::mouseDoubleClickEvent(QMouseEvent* ev) } } -void gs_frame::HandleCursor(QWindow::Visibility visibility) +void gs_frame::HandleCursor(QWindow::Visibility /*visibility*/) { - if (m_mouse_hide_and_lock || (visibility == QWindow::Visibility::FullScreen && !m_show_mouse_in_fullscreen)) + if (m_mouse_hide_and_lock) { setCursor(Qt::BlankCursor); m_mousehide_timer.stop(); } else { - if (!m_mouse_hide_and_lock) - { - setCursor(Qt::ArrowCursor); - } + setCursor(Qt::ArrowCursor); if (m_hide_mouse_after_idletime) { diff --git a/rpcs3/rpcs3qt/gs_frame.h b/rpcs3/rpcs3qt/gs_frame.h index fd743627a2..f2e02c7a29 100644 --- a/rpcs3/rpcs3qt/gs_frame.h +++ b/rpcs3/rpcs3qt/gs_frame.h @@ -55,6 +55,8 @@ public: void progress_increment(int delta); void progress_set_limit(int limit); + bool get_mouse_lock_state(); + void take_screenshot(const std::vector sshot_data, const u32 sshot_width, const u32 sshot_height, bool is_bgra) override; protected: