From f55821a6daad638110a7eb5b6b824f9f06220b51 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Wed, 11 Aug 2021 00:52:34 +0300
Subject: [PATCH] SL-15791 CONTROL_ML_LBUTTON and CONTROL_LBUTTON were
 triggered simultaneously

---
 indra/newview/llviewerinput.cpp | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/indra/newview/llviewerinput.cpp b/indra/newview/llviewerinput.cpp
index 1ca7d8024ae..15cf0b05dbc 100644
--- a/indra/newview/llviewerinput.cpp
+++ b/indra/newview/llviewerinput.cpp
@@ -1550,11 +1550,16 @@ bool LLViewerInput::scanMouse(EMouseClickType click, EMouseState state) const
     MASK mask = gKeyboard->currentMask(TRUE);
     res = scanMouse(mMouseBindings[mode], mMouseBindings[mode].size(), click, mask, state);
 
-    // no user defined actions found or those actions can't handle the key/button, handle control if nessesary
-    // This will pass AGENT_CONTROL_LBUTTON_DOWN to server, no idea why it doesn't do mouselook variant _ML_
-    // but it was set this way forever (moved as is from LLTool::handleMouseDown) so lots of scripts probably
-    // rely on this.
-    if (!res && mLMouseDefaultHandling[mode] && agent_control_lbutton.canHandle(click, KEY_NONE, mask))
+    // No user defined actions found or those actions can't handle the key/button, handle control if nessesary
+    //
+    // Default handling for MODE_FIRST_PERSON is in LLToolCompGun::handleMouseDown, but only if
+    // leftButtonGrabbed()
+    //
+    // If not grabbed or not in mouse look, should pass AGENT_CONTROL_LBUTTON_DOWN to server
+    if (!res
+        && (mode != MODE_FIRST_PERSON || !gAgent.leftButtonGrabbed()) 
+        && mLMouseDefaultHandling[mode]
+        && agent_control_lbutton.canHandle(click, KEY_NONE, mask))
     {
         switch (state)
         {
-- 
GitLab