[Scummvm-git-logs] scummvm branch-2-7 -> cb3cd5e245d53bb5090a68a7b6a52c73ecc763e4

sev- noreply at scummvm.org
Fri Mar 24 10:30:31 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
cb3cd5e245 KEYMAPPER: Allow multiple inputs bound to a keymap action as defaults (#4830)


Commit: cb3cd5e245d53bb5090a68a7b6a52c73ecc763e4
    https://github.com/scummvm/scummvm/commit/cb3cd5e245d53bb5090a68a7b6a52c73ecc763e4
Author: Athanasios Antoniou (a.antoniou79 at gmail.com)
Date: 2023-03-24T11:30:01+01:00

Commit Message:
KEYMAPPER: Allow multiple inputs bound to a keymap action as defaults (#4830)

This allows backeds to override a keymap action mapping with lists of mapped hardware inputs instead of just one hardware input id

However, it will still be an overridding, so it will require all hardware input ids for a given keymap action to be added.
In other words, if a backend uses addDefaultBinding() for a given action, it will not ADD to any existing mappings of the action,
other than the ones that the backend itself has added (with addDefaultBinding())

Changed paths:
    backends/keymapper/keymap.cpp
    backends/keymapper/keymapper-defaults.h


diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp
index b0840e266b0..13ae415843d 100644
--- a/backends/keymapper/keymap.cpp
+++ b/backends/keymapper/keymap.cpp
@@ -256,19 +256,13 @@ StringArray Keymap::getActionDefaultMappings(Action *action) {
 	if (_backendDefaultBindings) {
 		KeymapperDefaultBindings::const_iterator it = _backendDefaultBindings->findDefaultBinding(_id, action->id);
 		if (it != _backendDefaultBindings->end()) {
-			if (it->_value.empty()) {
-				return StringArray();
-			}
-			return StringArray(1, it->_value);
+			return it->_value;
 		}
 
 		// If no keymap-specific default mapping was found, look for a standard action binding
 		it = _backendDefaultBindings->findDefaultBinding(kStandardActionsKeymapName, action->id);
 		if (it != _backendDefaultBindings->end()) {
-			if (it->_value.empty()) {
-				return StringArray();
-			}
-			return StringArray(1, it->_value);
+			return it->_value;
 		}
 	}
 
diff --git a/backends/keymapper/keymapper-defaults.h b/backends/keymapper/keymapper-defaults.h
index 2dbf6e61576..8a691bccb90 100644
--- a/backends/keymapper/keymapper-defaults.h
+++ b/backends/keymapper/keymapper-defaults.h
@@ -29,7 +29,7 @@
 
 namespace Common {
 
-class KeymapperDefaultBindings : public HashMap<String, String> {
+class KeymapperDefaultBindings : public HashMap<String, StringArray> {
 public:
 	/**
 	 * This sets a default hwInput for a given Keymap Action
@@ -37,12 +37,42 @@ public:
 	 * @param actionId String representing Action id (Action.id)
 	 * @param hwInputId String representing the HardwareInput id (HardwareInput.id)
 	 */
-	void setDefaultBinding(String keymapId, String actionId, String hwInputId) { setVal(keymapId + "_" + actionId, hwInputId); }
+	void setDefaultBinding(String keymapId, String actionId, String hwInputId) {
+		setVal(keymapId + "_" + actionId, hwInputId.empty() ? StringArray() : StringArray(1, hwInputId));
+	}
+
+	/**
+	* This adds a default hwInput for a given Keymap Action
+	* @param keymapId String representing Keymap id (Keymap.name)
+	* @param actionId String representing Action id (Action.id)
+	* @param hwInputId String representing the HardwareInput id (HardwareInput.id)
+	*/
+	void addDefaultBinding(String keymapId, String actionId, String hwInputId) {
+		// NOTE: addDefaultBinding() cannot be used to remove bindings;
+		// use setDefaultBinding() with a nullptr or empty string as hwInputId instead.
+		if (hwInputId.empty()) {
+			return;
+		}
+
+		KeymapperDefaultBindings::iterator it = findDefaultBinding(keymapId, actionId);
+		if (it != end()) {
+			// Don't allow an input to map to the same action multiple times
+			StringArray &itv = it->_value;
+
+			Array<String>::const_iterator found = Common::find(itv.begin(), itv.end(), hwInputId);
+			if (found == itv.end()) {
+				itv.push_back(hwInputId);
+			}
+		} else {
+			setDefaultBinding(keymapId, actionId, hwInputId);
+		}
+	}
+
 	/**
 	 * This retrieves the assigned default hwKey for a given Keymap Action
 	 * @param keymapId String representing Keymap id (Keymap.name)
 	 * @param actionId String representing Action id (Action.id)
-	 * @return String representing the HardwareInput id (HardwareInput.id)
+	 * @return StringArray representing the list of HardwareInput ids (HardwareInput.id) that are mapped to Keymap Action
 	 */
 	const_iterator findDefaultBinding(String keymapId, String actionId) const {
 		return find(keymapId + "_" + actionId);




More information about the Scummvm-git-logs mailing list