@@ -101,7 +101,7 @@ bool KeyMapping::hasMeta() const
101
101
return keys.meta != KEY_CODE::KEY_IGNORE;
102
102
}
103
103
104
- bool KeyMapping::toString (char * pOutStr ) const
104
+ std::string KeyMapping::toString () const
105
105
{
106
106
// Figure out if the keycode is for mouse or keyboard and print the name of
107
107
// the respective key/mouse button to `asciiSub`
@@ -115,23 +115,21 @@ bool KeyMapping::toString(char* pOutStr) const
115
115
mouseKeyCodeToString (keys.input .value .mouseKeyCode , (char *)&asciiSub, 20 );
116
116
break ;
117
117
default :
118
- strcpy (asciiSub, " NOT VALID" );
119
118
debug (LOG_WZ, " Encountered invalid key mapping source %u while converting mapping to string!" , static_cast <unsigned int >(keys.input .source ));
120
- return true ;
119
+ return std::string ( " NOT VALID " ) ;
121
120
}
122
121
123
122
if (hasMeta ())
124
123
{
125
124
char asciiMeta[20 ] = " \0 " ;
126
125
keyScanToString (keys.meta , (char *)&asciiMeta, 20 );
127
126
128
- sprintf (pOutStr, " %s %s" , asciiMeta, asciiSub);
127
+ return astringf ( " %s %s" , asciiMeta, asciiSub);
129
128
}
130
129
else
131
130
{
132
- sprintf (pOutStr, " %s " , asciiSub);
131
+ return std::string ( asciiSub);
133
132
}
134
- return true ;
135
133
}
136
134
137
135
@@ -185,10 +183,10 @@ KeyMapping& KeyMappings::add(const KeyCombination keys, const KeyFunctionInfo& i
185
183
return keyMappings.back ();
186
184
}
187
185
188
- nonstd::optional<std::reference_wrapper<KeyMapping>> KeyMappings::get (const KeyFunctionInfo& info , const KeyMappingSlot slot)
186
+ nonstd::optional<std::reference_wrapper<KeyMapping>> KeyMappings::get (const std::string& name , const KeyMappingSlot slot)
189
187
{
190
- auto mapping = std::find_if (keyMappings.begin (), keyMappings.end (), [&info , slot](const KeyMapping& mapping) {
191
- return mapping.info .name == info. name && mapping.slot == slot;
188
+ auto mapping = std::find_if (keyMappings.begin (), keyMappings.end (), [&name , slot](const KeyMapping& mapping) {
189
+ return mapping.info .name == name && mapping.slot == slot;
192
190
});
193
191
if (mapping != keyMappings.end ())
194
192
{
@@ -198,6 +196,11 @@ nonstd::optional<std::reference_wrapper<KeyMapping>> KeyMappings::get(const KeyF
198
196
return nonstd::nullopt;
199
197
}
200
198
199
+ nonstd::optional<std::reference_wrapper<KeyMapping>> KeyMappings::get (const KeyFunctionInfo& info, const KeyMappingSlot slot)
200
+ {
201
+ return get (info.name , slot);
202
+ }
203
+
201
204
std::vector<std::reference_wrapper<KeyMapping>> KeyMappings::find (const KEY_CODE meta, const KeyMappingInput input)
202
205
{
203
206
std::vector<std::reference_wrapper<KeyMapping>> matches;
0 commit comments