[Scummvm-git-logs] scummvm master -> 3565d0e3128bd7914e70637290877b14581d3f6b
sev-
noreply at scummvm.org
Fri Mar 24 10:28:28 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:
3565d0e312 KEYMAPPER: Allow multiple inputs bound to a keymap action as defaults (#4830)
Commit: 3565d0e3128bd7914e70637290877b14581d3f6b
https://github.com/scummvm/scummvm/commit/3565d0e3128bd7914e70637290877b14581d3f6b
Author: Athanasios Antoniou (a.antoniou79 at gmail.com)
Date: 2023-03-24T11:28:24+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