From d343fea6264d0d061aa346c64085f09004aaf675 Mon Sep 17 00:00:00 2001 From: OfficialR3ido101 <39566484+OfficialR3ido101@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:52:53 +0000 Subject: [PATCH 1/4] Stop mouse capturing when in vr --- interface/src/Application.cpp | 1 + interface/src/Application.h | 4 ++++ interface/src/Application_UI.cpp | 8 ++++++++ interface/src/ui/PreferencesDialog.cpp | 10 ++++++++++ .../src/display-plugins/CompositorHelper.cpp | 8 ++++++++ .../src/display-plugins/CompositorHelper.h | 4 +++- 6 files changed, 34 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4449acd6ad..42bbb64567 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -225,6 +225,7 @@ Application::Application( _hmdTabletBecomesToolbarSetting("hmdTabletBecomesToolbar", DEFAULT_HMD_TABLET_BECOMES_TOOLBAR), _preferStylusOverLaserSetting("preferStylusOverLaser", DEFAULT_PREFER_STYLUS_OVER_LASER), _preferAvatarFingerOverStylusSetting("preferAvatarFingerOverStylus", DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS), + _defaultMouseLock("defaultMouseLock", DEFAULT_MOUSE_LOCK), _showGraphicsIconSetting("showGraphicsIcon", DEFAULT_SHOW_GRAPHICS_ICON), _constrainToolbarPosition("toolbar/constrainToolbarToCenterX", true), _awayStateWhenFocusLostInVREnabled("awayStateWhenFocusLostInVREnabled", DEFAULT_AWAY_STATE_WHEN_FOCUS_LOST_IN_VR_ENABLED), diff --git a/interface/src/Application.h b/interface/src/Application.h index 613ad3f1b8..f725be2e5c 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -188,6 +188,9 @@ public: void setPreferStylusOverLaser(bool value) { _preferStylusOverLaserSetting.set(value); } bool getPreferAvatarFingerOverStylus() { return _preferAvatarFingerOverStylusSetting.get(); } void setPreferAvatarFingerOverStylus(bool value) { _preferAvatarFingerOverStylusSetting.set(value); } + + void setMouseLock(bool value); + bool getMouseLock(); bool getShowGraphicsIcon() { return _showGraphicsIconSetting.get(); } void setShowGraphicsIcon(bool value); @@ -791,6 +794,7 @@ private: Setting::Handle _hmdTabletBecomesToolbarSetting; Setting::Handle _preferStylusOverLaserSetting; Setting::Handle _preferAvatarFingerOverStylusSetting; + Setting::Handle _defaultMouseLock; Setting::Handle _showGraphicsIconSetting; Setting::Handle _constrainToolbarPosition; Setting::Handle _awayStateWhenFocusLostInVREnabled; diff --git a/interface/src/Application_UI.cpp b/interface/src/Application_UI.cpp index 6d4dbcbef3..da7aa42a7b 100644 --- a/interface/src/Application_UI.cpp +++ b/interface/src/Application_UI.cpp @@ -269,6 +269,14 @@ void Application::setHmdTabletBecomesToolbarSetting(bool value) { updateSystemTabletMode(); } +void Application::setMouseLock(bool value) { + _defaultMouseLock.set(value); + getApplicationCompositor().setMouseLockComposit(value); +} +bool Application::getMouseLock() { + return _defaultMouseLock.get(); +} + void Application::setShowGraphicsIcon(bool value) { _showGraphicsIconSetting.set(value); DependencyManager::get()->sendLocalMessage("Overte-ShowGraphicsIconChanged", ""); diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 623aede2fa..a0cc26b89c 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -32,6 +32,8 @@ void setupPreferences() { auto preferences = DependencyManager::get(); auto myAvatar = DependencyManager::get()->getMyAvatar(); + + static const QString AVATAR_BASICS { "Avatar Basics" }; { auto getter = [myAvatar]()->QString { return myAvatar->getDisplayName(); }; @@ -142,6 +144,14 @@ void setupPreferences() { preferences->addPreference(new CheckPreference(UI_CATEGORY, "Constrain Toolbar Position to Horizontal Center", getter, setter)); } + //static const QString TEST{ "TEST SECTION" }; + { + auto getter = []() -> bool { return qApp->getMouseLock(); }; + auto setter = [](bool value) { qApp->setMouseLock(value); }; + auto preference = new CheckPreference(UI_CATEGORY, "3D mouse cursor in VR", getter, setter); + preferences->addPreference(preference); + } + { auto getter = []()->bool { return qApp->getAwayStateWhenFocusLostInVREnabled(); }; auto setter = [](bool value) { qApp->setAwayStateWhenFocusLostInVREnabled(value); }; diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp index c645c39eb4..1cdb112aa9 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp @@ -195,6 +195,10 @@ bool CompositorHelper::shouldCaptureMouse() const { if (!isHMD()) { return false; } + + if (!_mouseLockComposit) { + return false; + } if (!isWindowActive()) { @@ -216,6 +220,10 @@ void CompositorHelper::setAllowMouseCapture(bool capture) { } } +void CompositorHelper::setMouseLockComposit(bool capture) { + _mouseLockComposit = capture; +} + void CompositorHelper::handleLeaveEvent() { if (shouldCaptureMouse()) { diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.h b/libraries/display-plugins/src/display-plugins/CompositorHelper.h index 389d49929e..175bec15d0 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.h +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.h @@ -106,6 +106,7 @@ public: bool getAllowMouseCapture() const { return _allowMouseCapture; } void setAllowMouseCapture(bool capture); + void setMouseLockComposit(bool capture); /// if the reticle is pointing to a system overlay (a dialog box for example) then the function returns true otherwise false bool getReticleOverDesktop() const; @@ -168,7 +169,8 @@ private: bool _reticleOverQml { false }; - std::atomic _allowMouseCapture { true }; + std::atomic _allowMouseCapture{ true }; + std::atomic _mouseLockComposit{ false }; bool _fakeMouseEvent { false }; From 585df97a1936dd1be2920e5110ac56c2e19b8df6 Mon Sep 17 00:00:00 2001 From: OfficialR3ido101 <39566484+OfficialR3ido101@users.noreply.github.com> Date: Wed, 26 Feb 2025 19:20:33 +0000 Subject: [PATCH 2/4] removed useless commented out code and set the correct category for mouse locking in VR --- interface/src/Application.cpp | 1 + interface/src/ui/PreferencesDialog.cpp | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 42bbb64567..df1b16e7e3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -159,6 +159,7 @@ const bool DEFAULT_DESKTOP_TABLET_BECOMES_TOOLBAR = true; const bool DEFAULT_HMD_TABLET_BECOMES_TOOLBAR = false; const bool DEFAULT_PREFER_STYLUS_OVER_LASER = false; const bool DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS = false; +const bool DEFAULT_MOUSE_LOCK = false; const bool DEFAULT_SHOW_GRAPHICS_ICON = true; const bool DEFAULT_MINI_TABLET_ENABLED = false; const bool DEFAULT_AWAY_STATE_WHEN_FOCUS_LOST_IN_VR_ENABLED = true; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index a0cc26b89c..8a84636429 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -144,14 +144,6 @@ void setupPreferences() { preferences->addPreference(new CheckPreference(UI_CATEGORY, "Constrain Toolbar Position to Horizontal Center", getter, setter)); } - //static const QString TEST{ "TEST SECTION" }; - { - auto getter = []() -> bool { return qApp->getMouseLock(); }; - auto setter = [](bool value) { qApp->setMouseLock(value); }; - auto preference = new CheckPreference(UI_CATEGORY, "3D mouse cursor in VR", getter, setter); - preferences->addPreference(preference); - } - { auto getter = []()->bool { return qApp->getAwayStateWhenFocusLostInVREnabled(); }; auto setter = [](bool value) { qApp->setAwayStateWhenFocusLostInVREnabled(value); }; @@ -175,6 +167,13 @@ void setupPreferences() { preference->setMax(500); preferences->addPreference(preference); } + + { + auto getter = []() -> bool { return qApp->getMouseLock(); }; + auto setter = [](bool value) { qApp->setMouseLock(value); }; + auto preference = new CheckPreference(UI_CATEGORY, "3D mouse cursor in VR", getter, setter); + preferences->addPreference(preference); + } { static const QString RETICLE_ICON_NAME = { Cursor::Manager::getIconName(Cursor::Icon::RETICLE) }; From aced56d934ad470cefe51546466dc4d7272de4a9 Mon Sep 17 00:00:00 2001 From: OfficialR3ido101 Date: Sat, 5 Apr 2025 19:53:02 +0100 Subject: [PATCH 3/4] Fixed for review changed vars --- interface/src/Application.cpp | 4 ++-- interface/src/Application.h | 6 +++--- interface/src/Application_UI.cpp | 6 +++--- interface/src/ui/PreferencesDialog.cpp | 4 ++-- .../src/display-plugins/CompositorHelper.cpp | 8 ++++---- .../src/display-plugins/CompositorHelper.h | 6 +++--- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index df1b16e7e3..af1e3a5b44 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -159,7 +159,7 @@ const bool DEFAULT_DESKTOP_TABLET_BECOMES_TOOLBAR = true; const bool DEFAULT_HMD_TABLET_BECOMES_TOOLBAR = false; const bool DEFAULT_PREFER_STYLUS_OVER_LASER = false; const bool DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS = false; -const bool DEFAULT_MOUSE_LOCK = false; +const bool DEFAULT_MOUSE_CAPTURE_VR = false; const bool DEFAULT_SHOW_GRAPHICS_ICON = true; const bool DEFAULT_MINI_TABLET_ENABLED = false; const bool DEFAULT_AWAY_STATE_WHEN_FOCUS_LOST_IN_VR_ENABLED = true; @@ -226,7 +226,7 @@ Application::Application( _hmdTabletBecomesToolbarSetting("hmdTabletBecomesToolbar", DEFAULT_HMD_TABLET_BECOMES_TOOLBAR), _preferStylusOverLaserSetting("preferStylusOverLaser", DEFAULT_PREFER_STYLUS_OVER_LASER), _preferAvatarFingerOverStylusSetting("preferAvatarFingerOverStylus", DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS), - _defaultMouseLock("defaultMouseLock", DEFAULT_MOUSE_LOCK), + _defaultMouseCaptureVR("defaultMouseCaptureVR", DEFAULT_MOUSE_CAPTURE_VR), _showGraphicsIconSetting("showGraphicsIcon", DEFAULT_SHOW_GRAPHICS_ICON), _constrainToolbarPosition("toolbar/constrainToolbarToCenterX", true), _awayStateWhenFocusLostInVREnabled("awayStateWhenFocusLostInVREnabled", DEFAULT_AWAY_STATE_WHEN_FOCUS_LOST_IN_VR_ENABLED), diff --git a/interface/src/Application.h b/interface/src/Application.h index f725be2e5c..5b911b4b9f 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -189,8 +189,8 @@ public: bool getPreferAvatarFingerOverStylus() { return _preferAvatarFingerOverStylusSetting.get(); } void setPreferAvatarFingerOverStylus(bool value) { _preferAvatarFingerOverStylusSetting.set(value); } - void setMouseLock(bool value); - bool getMouseLock(); + void setMouseCaptureVR(bool value); + bool getMouseCaptureVR(); bool getShowGraphicsIcon() { return _showGraphicsIconSetting.get(); } void setShowGraphicsIcon(bool value); @@ -794,7 +794,7 @@ private: Setting::Handle _hmdTabletBecomesToolbarSetting; Setting::Handle _preferStylusOverLaserSetting; Setting::Handle _preferAvatarFingerOverStylusSetting; - Setting::Handle _defaultMouseLock; + Setting::Handle _defaultMouseCaptureVR; Setting::Handle _showGraphicsIconSetting; Setting::Handle _constrainToolbarPosition; Setting::Handle _awayStateWhenFocusLostInVREnabled; diff --git a/interface/src/Application_UI.cpp b/interface/src/Application_UI.cpp index da7aa42a7b..9601968d4e 100644 --- a/interface/src/Application_UI.cpp +++ b/interface/src/Application_UI.cpp @@ -269,11 +269,11 @@ void Application::setHmdTabletBecomesToolbarSetting(bool value) { updateSystemTabletMode(); } -void Application::setMouseLock(bool value) { +void Application::setMouseCaptureVR(bool value) { _defaultMouseLock.set(value); - getApplicationCompositor().setMouseLockComposit(value); + getApplicationCompositor().setMouseLockCompositVR(value); } -bool Application::getMouseLock() { +bool Application::getMouseCaptureVR() { return _defaultMouseLock.get(); } diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 8a84636429..cf7d02a8b4 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -169,8 +169,8 @@ void setupPreferences() { } { - auto getter = []() -> bool { return qApp->getMouseLock(); }; - auto setter = [](bool value) { qApp->setMouseLock(value); }; + auto getter = []() -> bool { return qApp->getMouseCaptureVR(); }; + auto setter = [](bool value) { qApp->setMouseCaptureVR(value); }; auto preference = new CheckPreference(UI_CATEGORY, "3D mouse cursor in VR", getter, setter); preferences->addPreference(preference); } diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp index 1cdb112aa9..39affa66a3 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp @@ -188,7 +188,7 @@ static bool isWindowActive() { } bool CompositorHelper::shouldCaptureMouse() const { - if (!_allowMouseCapture) { + if (!_allowMouseCaptureVR) { return false; } @@ -214,13 +214,13 @@ bool CompositorHelper::shouldCaptureMouse() const { } void CompositorHelper::setAllowMouseCapture(bool capture) { - if (capture != _allowMouseCapture) { - _allowMouseCapture = capture; + if (capture != _allowMouseCaptureVR) { + _allowMouseCaptureVR = capture; emit allowMouseCaptureChanged(); } } -void CompositorHelper::setMouseLockComposit(bool capture) { +void CompositorHelper::setMouseLockCompositVR(bool capture) { _mouseLockComposit = capture; } diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.h b/libraries/display-plugins/src/display-plugins/CompositorHelper.h index 175bec15d0..4d1dcda464 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.h +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.h @@ -104,9 +104,9 @@ public: bool shouldCaptureMouse() const; - bool getAllowMouseCapture() const { return _allowMouseCapture; } + bool getAllowMouseCapture() const { return _allowMouseCaptureVR; } void setAllowMouseCapture(bool capture); - void setMouseLockComposit(bool capture); + void setMouseLockCompositVR(bool capture); /// if the reticle is pointing to a system overlay (a dialog box for example) then the function returns true otherwise false bool getReticleOverDesktop() const; @@ -169,7 +169,7 @@ private: bool _reticleOverQml { false }; - std::atomic _allowMouseCapture{ true }; + std::atomic _allowMouseCaptureVR{ true }; std::atomic _mouseLockComposit{ false }; bool _fakeMouseEvent { false }; From a1bd83e8aab36316f110c36feac9086f7cd95cca Mon Sep 17 00:00:00 2001 From: Karol Suprynowicz Date: Sat, 5 Apr 2025 22:40:27 +0200 Subject: [PATCH 4/4] Change variable names --- interface/src/Application_UI.cpp | 6 +++--- .../src/display-plugins/CompositorHelper.cpp | 12 ++++++------ .../src/display-plugins/CompositorHelper.h | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/interface/src/Application_UI.cpp b/interface/src/Application_UI.cpp index 9601968d4e..ee40319e28 100644 --- a/interface/src/Application_UI.cpp +++ b/interface/src/Application_UI.cpp @@ -270,11 +270,11 @@ void Application::setHmdTabletBecomesToolbarSetting(bool value) { } void Application::setMouseCaptureVR(bool value) { - _defaultMouseLock.set(value); - getApplicationCompositor().setMouseLockCompositVR(value); + _defaultMouseCaptureVR.set(value); + getApplicationCompositor().setEnableMouseCaptureVR(value); } bool Application::getMouseCaptureVR() { - return _defaultMouseLock.get(); + return _defaultMouseCaptureVR.get(); } void Application::setShowGraphicsIcon(bool value) { diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp index 39affa66a3..ed16b5875c 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.cpp @@ -188,7 +188,7 @@ static bool isWindowActive() { } bool CompositorHelper::shouldCaptureMouse() const { - if (!_allowMouseCaptureVR) { + if (!_allowMouseCapture) { return false; } @@ -196,7 +196,7 @@ bool CompositorHelper::shouldCaptureMouse() const { return false; } - if (!_mouseLockComposit) { + if (!_enableMouseCaptureVR) { return false; } @@ -214,14 +214,14 @@ bool CompositorHelper::shouldCaptureMouse() const { } void CompositorHelper::setAllowMouseCapture(bool capture) { - if (capture != _allowMouseCaptureVR) { - _allowMouseCaptureVR = capture; + if (capture != _allowMouseCapture) { + _allowMouseCapture = capture; emit allowMouseCaptureChanged(); } } -void CompositorHelper::setMouseLockCompositVR(bool capture) { - _mouseLockComposit = capture; +void CompositorHelper::setEnableMouseCaptureVR(bool capture) { + _enableMouseCaptureVR = capture; } void CompositorHelper::handleLeaveEvent() { diff --git a/libraries/display-plugins/src/display-plugins/CompositorHelper.h b/libraries/display-plugins/src/display-plugins/CompositorHelper.h index 4d1dcda464..a952b80238 100644 --- a/libraries/display-plugins/src/display-plugins/CompositorHelper.h +++ b/libraries/display-plugins/src/display-plugins/CompositorHelper.h @@ -104,9 +104,9 @@ public: bool shouldCaptureMouse() const; - bool getAllowMouseCapture() const { return _allowMouseCaptureVR; } + bool getAllowMouseCapture() const { return _allowMouseCapture; } void setAllowMouseCapture(bool capture); - void setMouseLockCompositVR(bool capture); + void setEnableMouseCaptureVR(bool capture); /// if the reticle is pointing to a system overlay (a dialog box for example) then the function returns true otherwise false bool getReticleOverDesktop() const; @@ -169,8 +169,8 @@ private: bool _reticleOverQml { false }; - std::atomic _allowMouseCaptureVR{ true }; - std::atomic _mouseLockComposit{ false }; + std::atomic _allowMouseCapture{ true }; + std::atomic _enableMouseCaptureVR{ false }; bool _fakeMouseEvent { false };