From 725ae53bf59324f817f563ff053b837c10c52484 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 15 Jul 2021 17:30:21 +0300 Subject: SL-443 Keybindings: Restored default fails to save --- indra/newview/llkeyconflict.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'indra/newview/llkeyconflict.cpp') diff --git a/indra/newview/llkeyconflict.cpp b/indra/newview/llkeyconflict.cpp index b6107eeedf..d7a17b237e 100644 --- a/indra/newview/llkeyconflict.cpp +++ b/indra/newview/llkeyconflict.cpp @@ -730,13 +730,19 @@ void LLKeyConflictHandler::resetToDefault(const std::string &control_name, U32 i { return; } + LLKeyConflict &type_data = mControlsMap[control_name]; + if (!type_data.mAssignable) + { + return; + } LLKeyData data = getDefaultControl(control_name, index); - if (data != mControlsMap[control_name].getKeyData(index)) + if (data != type_data.getKeyData(index)) { // reset controls that might have been switched to our current control removeConflicts(data, mControlsMap[control_name].mConflictMask); mControlsMap[control_name].setKeyData(data, index); + mHasUnsavedChanges = true; } } -- cgit v1.2.3 From 0814ba33222fa86e73ca3e5351175ba4b7b545e8 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 15 Jul 2021 17:34:16 +0300 Subject: SL-443 Keybindings: Support reassigment of script interaction button --- indra/newview/llkeyconflict.cpp | 58 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-) (limited to 'indra/newview/llkeyconflict.cpp') diff --git a/indra/newview/llkeyconflict.cpp b/indra/newview/llkeyconflict.cpp index d7a17b237e..58a740e16a 100644 --- a/indra/newview/llkeyconflict.cpp +++ b/indra/newview/llkeyconflict.cpp @@ -868,7 +868,7 @@ void LLKeyConflictHandler::resetKeyboardBindings() void LLKeyConflictHandler::generatePlaceholders(ESourceMode load_mode) { - // These controls are meant to cause conflicts when user tries to assign same control somewhere else + // These placeholds are meant to cause conflict resolution when user tries to assign same control somewhere else // also this can be used to pre-record controls that should not conflict or to assign conflict groups/masks if (load_mode == MODE_FIRST_PERSON) @@ -928,25 +928,73 @@ void LLKeyConflictHandler::generatePlaceholders(ESourceMode load_mode) registerTemporaryControl("spin_around_ccw_sitting"); registerTemporaryControl("spin_around_cw_sitting"); } + + + // Special case, mouse clicks passed to scripts have 'lowest' piority + // thus do not conflict, everything else has a chance before them + // also in ML they have highest priority, but only when script-grabbed, + // thus do not conflict + // (see AGENT_CONTROL_ML_LBUTTON_DOWN and CONTROL_LBUTTON_DOWN_INDEX) + LLKeyConflict *type_data = &mControlsMap[script_mouse_handler_name]; + type_data->mAssignable = true; + type_data->mConflictMask = U32_MAX - CONFLICT_LMOUSE; } -bool LLKeyConflictHandler::removeConflicts(const LLKeyData &data, const U32 &conlict_mask) +bool LLKeyConflictHandler::removeConflicts(const LLKeyData &data, U32 conlict_mask) { if (conlict_mask == CONFLICT_NOTHING) { // Can't conflict return true; } + + if (data.mMouse == CLICK_LEFT + && data.mMask == MASK_NONE + && data.mKey == KEY_NONE) + { + if ((conlict_mask & CONFLICT_LMOUSE) == 0) + { + // Can't conflict + return true; + } + else + { + // simplify conflict mask + conlict_mask = CONFLICT_LMOUSE; + } + } + else + { + // simplify conflict mask + conlict_mask &= ~CONFLICT_LMOUSE; + } + std::map conflict_list; control_map_t::iterator cntrl_iter = mControlsMap.begin(); control_map_t::iterator cntrl_end = mControlsMap.end(); for (; cntrl_iter != cntrl_end; ++cntrl_iter) { + const U32 cmp_mask = cntrl_iter->second.mConflictMask; + if ((cmp_mask & conlict_mask) == 0) + { + // can't conflict + continue; + } S32 index = cntrl_iter->second.mKeyBind.findKeyData(data); - if (index >= 0 - && cntrl_iter->second.mConflictMask != CONFLICT_NOTHING - && (cntrl_iter->second.mConflictMask & conlict_mask) != 0) + if (index >= 0) { + if (cmp_mask != U32_MAX) + { + const LLKeyData cmp_data = cntrl_iter->second.mKeyBind.getKeyData(index); + if ((cmp_mask & CONFLICT_LMOUSE) == 0 + && cmp_data.mMouse == CLICK_LEFT + && cmp_data.mMask == MASK_NONE + && cmp_data.mKey == KEY_NONE) + { + // Does not conflict + continue; + } + } if (cntrl_iter->second.mAssignable) { // Potentially we can have multiple conflict flags conflicting -- cgit v1.2.3 From 48921a62322bd4eae17d1085256693aa66041dbd Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 15 Jul 2021 20:22:53 +0300 Subject: SL-443 Keybindings: Backward compatibility --- indra/newview/llkeyconflict.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'indra/newview/llkeyconflict.cpp') diff --git a/indra/newview/llkeyconflict.cpp b/indra/newview/llkeyconflict.cpp index 58a740e16a..3d3d652aa3 100644 --- a/indra/newview/llkeyconflict.cpp +++ b/indra/newview/llkeyconflict.cpp @@ -376,6 +376,22 @@ bool LLKeyConflictHandler::loadFromSettings(const ESourceMode &load_mode, const LL_ERRS() << "Not implememted mode " << load_mode << LL_ENDL; break; } + + // verify version + if (keys.version < 1) + { + // Updating from a version that was not aware of LMouse bindings. + // Assign defaults. + // + // mDefaultsMap is always going to have correct version so + // registerControl is usable, but using 'destination' just in case. + LLKeyConflict &type_data = (*destination)[script_mouse_handler_name]; + LLKeyData data(CLICK_LEFT, KEY_NONE, MASK_NONE, true); + type_data.mKeyBind.replaceKeyData(data, 0); + + // Mark this mode for an update + mHasUnsavedChanges = true; + } } return res; } @@ -416,6 +432,12 @@ void LLKeyConflictHandler::loadFromSettings(ESourceMode load_mode) } } mLoadMode = load_mode; + + if (mHasUnsavedChanges) + { + // We ended up with some settings assigned due to changes in version, resave + saveToSettings(false); + } } void LLKeyConflictHandler::saveToSettings(bool temporary) -- cgit v1.2.3 From e7563ff13fe1e6e77a0c6de5dcf0c1b67a6d2e2c Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 15 Jul 2021 20:28:26 +0300 Subject: SL-443 Keybindings: Backward compatibility #2 --- indra/newview/llkeyconflict.cpp | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'indra/newview/llkeyconflict.cpp') diff --git a/indra/newview/llkeyconflict.cpp b/indra/newview/llkeyconflict.cpp index 3d3d652aa3..86f3e2fc37 100644 --- a/indra/newview/llkeyconflict.cpp +++ b/indra/newview/llkeyconflict.cpp @@ -378,7 +378,7 @@ bool LLKeyConflictHandler::loadFromSettings(const ESourceMode &load_mode, const } // verify version - if (keys.version < 1) + if (keys.xml_version < 1) { // Updating from a version that was not aware of LMouse bindings. // Assign defaults. @@ -389,7 +389,8 @@ bool LLKeyConflictHandler::loadFromSettings(const ESourceMode &load_mode, const LLKeyData data(CLICK_LEFT, KEY_NONE, MASK_NONE, true); type_data.mKeyBind.replaceKeyData(data, 0); - // Mark this mode for an update + // Mark this mode for an update, once user clicks 'OK' in preferences + // it should get saved mHasUnsavedChanges = true; } } @@ -432,12 +433,6 @@ void LLKeyConflictHandler::loadFromSettings(ESourceMode load_mode) } } mLoadMode = load_mode; - - if (mHasUnsavedChanges) - { - // We ended up with some settings assigned due to changes in version, resave - saveToSettings(false); - } } void LLKeyConflictHandler::saveToSettings(bool temporary) @@ -597,6 +592,8 @@ void LLKeyConflictHandler::saveToSettings(bool temporary) break; } + keys.xml_version.set(keybindings_xml_version, true); + if (temporary) { // write to temporary xml and use it for gViewerInput @@ -821,9 +818,9 @@ void LLKeyConflictHandler::resetToDefault(const std::string &control_name) resetToDefaultAndResolve(control_name, false); } -void LLKeyConflictHandler::resetToDefaults(ESourceMode mode) +void LLKeyConflictHandler::resetToDefaultsAndResolve() { - if (mode == MODE_SAVED_SETTINGS) + if (mLoadMode == MODE_SAVED_SETTINGS) { control_map_t::iterator iter = mControlsMap.begin(); control_map_t::iterator end = mControlsMap.end(); @@ -836,7 +833,7 @@ void LLKeyConflictHandler::resetToDefaults(ESourceMode mode) else { mControlsMap.clear(); - generatePlaceholders(mode); + generatePlaceholders(mLoadMode); mControlsMap.insert(mDefaultsMap.begin(), mDefaultsMap.end()); } @@ -847,7 +844,7 @@ void LLKeyConflictHandler::resetToDefaults() { if (!empty()) { - resetToDefaults(mLoadMode); + resetToDefaultsAndResolve(); } else { @@ -857,7 +854,7 @@ void LLKeyConflictHandler::resetToDefaults() // 3. We are loading 'current' only to replace it // but it is reliable and works Todo: consider optimizing. loadFromSettings(mLoadMode); - resetToDefaults(mLoadMode); + resetToDefaultsAndResolve(); } } @@ -890,7 +887,7 @@ void LLKeyConflictHandler::resetKeyboardBindings() void LLKeyConflictHandler::generatePlaceholders(ESourceMode load_mode) { - // These placeholds are meant to cause conflict resolution when user tries to assign same control somewhere else + // These placeholders are meant to cause conflict resolution when user tries to assign same control somewhere else // also this can be used to pre-record controls that should not conflict or to assign conflict groups/masks if (load_mode == MODE_FIRST_PERSON) @@ -1005,18 +1002,6 @@ bool LLKeyConflictHandler::removeConflicts(const LLKeyData &data, U32 conlict_ma S32 index = cntrl_iter->second.mKeyBind.findKeyData(data); if (index >= 0) { - if (cmp_mask != U32_MAX) - { - const LLKeyData cmp_data = cntrl_iter->second.mKeyBind.getKeyData(index); - if ((cmp_mask & CONFLICT_LMOUSE) == 0 - && cmp_data.mMouse == CLICK_LEFT - && cmp_data.mMask == MASK_NONE - && cmp_data.mKey == KEY_NONE) - { - // Does not conflict - continue; - } - } if (cntrl_iter->second.mAssignable) { // Potentially we can have multiple conflict flags conflicting -- cgit v1.2.3 From 30c67f6f1836db6c2d3e235f1cc76cc8263888b1 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 30 Jul 2021 08:57:21 +0300 Subject: SL-443 Remove legacy keybindings code --- indra/newview/llkeyconflict.cpp | 62 ----------------------------------------- 1 file changed, 62 deletions(-) (limited to 'indra/newview/llkeyconflict.cpp') diff --git a/indra/newview/llkeyconflict.cpp b/indra/newview/llkeyconflict.cpp index 86f3e2fc37..861e3eb42f 100644 --- a/indra/newview/llkeyconflict.cpp +++ b/indra/newview/llkeyconflict.cpp @@ -638,68 +638,6 @@ void LLKeyConflictHandler::saveToSettings(bool temporary) } } -#if 1 - // Legacy support - // Remove #if-#endif section half a year after DRTVWR-501 releases. - // Update legacy settings in settings.xml - // We only care for third person view since legacy settings can't store - // more than one mode. - // We are saving this even if we are in temporary mode - preferences - // will restore values on cancel - if (mLoadMode == MODE_THIRD_PERSON && mHasUnsavedChanges) - { - bool value = canHandleMouse("walk_to", CLICK_DOUBLELEFT, MASK_NONE); - gSavedSettings.setBOOL("DoubleClickAutoPilot", value); - - value = canHandleMouse("walk_to", CLICK_LEFT, MASK_NONE); - gSavedSettings.setBOOL("ClickToWalk", value); - - // new method can save both toggle and push-to-talk values simultaneously, - // but legacy one can save only one. It also doesn't support mask. - LLKeyData data = getControl("toggle_voice", 0); - bool can_toggle = !data.isEmpty(); - if (!can_toggle) - { - data = getControl("voice_follow_key", 0); - } - - gSavedSettings.setBOOL("PushToTalkToggle", can_toggle); - if (data.isEmpty()) - { - // legacy viewer has a bug that might crash it if NONE value is assigned. - // just reset to default - gSavedSettings.getControl("PushToTalkButton")->resetToDefault(false); - } - else - { - if (data.mKey != KEY_NONE) - { - gSavedSettings.setString("PushToTalkButton", LLKeyboard::stringFromKey(data.mKey)); - } - else - { - std::string ctrl_value; - switch (data.mMouse) - { - case CLICK_MIDDLE: - ctrl_value = "MiddleMouse"; - break; - case CLICK_BUTTON4: - ctrl_value = "MouseButton4"; - break; - case CLICK_BUTTON5: - ctrl_value = "MouseButton5"; - break; - default: - ctrl_value = "MiddleMouse"; - break; - } - gSavedSettings.setString("PushToTalkButton", ctrl_value); - } - } - } -#endif - if (mLoadMode == MODE_THIRD_PERSON && mHasUnsavedChanges) { // Map floater should react to doubleclick if doubleclick for teleport is set -- cgit v1.2.3 From c748c1369ba04d3b28cc69329b7cea065cdf3b2b Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 12 Aug 2021 00:12:25 +0300 Subject: SL-443 Keybindings: Fix some settings not being loaded for editing --- indra/newview/llkeyconflict.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'indra/newview/llkeyconflict.cpp') diff --git a/indra/newview/llkeyconflict.cpp b/indra/newview/llkeyconflict.cpp index 861e3eb42f..83fb1ac7b5 100644 --- a/indra/newview/llkeyconflict.cpp +++ b/indra/newview/llkeyconflict.cpp @@ -428,8 +428,16 @@ void LLKeyConflictHandler::loadFromSettings(ESourceMode load_mode) filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, filename_default); if (!gDirUtilp->fileExists(filename) || !loadFromSettings(load_mode, filename, &mControlsMap)) { - // mind placeholders - mControlsMap.insert(mDefaultsMap.begin(), mDefaultsMap.end()); + // Mind placeholders + // Do not use mControlsMap.insert(mDefaultsMap) since mControlsMap has + // placeholders that won't be added over(to) by insert. + // Or instead move generatePlaceholders call to be after copying + control_map_t::iterator iter = mDefaultsMap.begin(); + while (iter != mDefaultsMap.end()) + { + mControlsMap[iter->first].mKeyBind = iter->second.mKeyBind; + iter++; + } } } mLoadMode = load_mode; @@ -771,8 +779,16 @@ void LLKeyConflictHandler::resetToDefaultsAndResolve() else { mControlsMap.clear(); - generatePlaceholders(mLoadMode); + + // Set key combinations. + // Copy from mDefaultsMap before doing generatePlaceholders, otherwise + // insert() will fail to add some keys into pre-existing values from + // generatePlaceholders() mControlsMap.insert(mDefaultsMap.begin(), mDefaultsMap.end()); + + // Set conflict masks and mark functions (un)assignable + generatePlaceholders(mLoadMode); + } mHasUnsavedChanges = true; -- cgit v1.2.3 From fc90fee5087c91bb8c4c93b5e9508706e46bd409 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 4 Mar 2022 22:24:59 +0200 Subject: SL-16976 SL-443 Keybindings: Backward compatibility #3 --- indra/newview/llkeyconflict.cpp | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'indra/newview/llkeyconflict.cpp') diff --git a/indra/newview/llkeyconflict.cpp b/indra/newview/llkeyconflict.cpp index 4c58c9e68c..d3ba18525b 100644 --- a/indra/newview/llkeyconflict.cpp +++ b/indra/newview/llkeyconflict.cpp @@ -376,23 +376,6 @@ bool LLKeyConflictHandler::loadFromSettings(const ESourceMode &load_mode, const LL_ERRS() << "Not implememted mode " << load_mode << LL_ENDL; break; } - - // verify version - if (keys.xml_version < 1) - { - // Updating from a version that was not aware of LMouse bindings. - // Assign defaults. - // - // mDefaultsMap is always going to have correct version so - // registerControl is usable, but using 'destination' just in case. - LLKeyConflict &type_data = (*destination)[script_mouse_handler_name]; - LLKeyData data(CLICK_LEFT, KEY_NONE, MASK_NONE, true); - type_data.mKeyBind.replaceKeyData(data, 0); - - // Mark this mode for an update, once user clicks 'OK' in preferences - // it should get saved - mHasUnsavedChanges = true; - } } return res; } -- cgit v1.2.3