Skip to content

Commit af235c5

Browse files
committed
allow mixind modifier and key keybinds
1 parent 8575a64 commit af235c5

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

sources/libengine/keybinds.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ namespace cage
8585
case 347: // right super
8686
return any(requiredFlags & ModifiersFlags::Super) ? Response : KeybindModesFlags::None;
8787
}
88+
if (input.key == 0 && any(input.mods & requiredFlags))
89+
return Response;
8890
return KeybindModesFlags::None;
8991
}
9092

@@ -251,8 +253,12 @@ namespace cage
251253

252254
CAGE_FORCE_INLINE void make(const GenericInput &input)
253255
{
254-
if (config.devices == KeybindDevicesFlags::Modifiers)
255-
return makeModifiersMatcher(input);
256+
if (any(config.devices & KeybindDevicesFlags::Modifiers) && input.has<input::KeyPress>())
257+
{
258+
const input::KeyPress in = input.get<input::KeyPress>();
259+
if (any(in.mods) && none(in.mods & config.forbiddenFlags))
260+
result = ModifiersMatcher{ base(in.mods) };
261+
}
256262
make<input::KeyPress>(input);
257263
make<input::KeyRepeat>(input);
258264
make<input::KeyRelease>(input);
@@ -261,16 +267,6 @@ namespace cage
261267
make<input::MouseRelease>(input);
262268
make<input::MouseWheel>(input);
263269
}
264-
265-
CAGE_FORCE_INLINE void makeModifiersMatcher(const GenericInput &input)
266-
{
267-
if (input.has<input::KeyPress>())
268-
{
269-
const input::KeyPress in = input.get<input::KeyPress>();
270-
if (none(in.mods & config.forbiddenFlags))
271-
result = ModifiersMatcher{ base(in.mods) };
272-
}
273-
}
274270
};
275271

276272
Matcher makeMatcher(const KeybindCreateConfig &config, const GenericInput &input)
@@ -279,8 +275,7 @@ namespace cage
279275
maker.make(input);
280276
if (!std::holds_alternative<std::monostate>(maker.result))
281277
{
282-
if (config.devices != KeybindDevicesFlags::Modifiers) // modifiers are defined without the actual keys
283-
CAGE_ASSERT(any(matchesInput(input, maker.result)));
278+
CAGE_ASSERT(any(matchesInput(input, maker.result)));
284279
}
285280
return maker.result;
286281
}
@@ -292,7 +287,6 @@ namespace cage
292287
CAGE_ASSERT(none(config.requiredFlags & config.forbiddenFlags));
293288
CAGE_ASSERT(any(config.devices));
294289
CAGE_ASSERT(none(config.devices & KeybindDevicesFlags::WheelRoll) || none(config.devices & KeybindDevicesFlags::WheelScroll)); // these two flags are mutually exclusive
295-
CAGE_ASSERT(none(config.devices & KeybindDevicesFlags::Modifiers) || config.devices == KeybindDevicesFlags::Modifiers); // modifiers is exclusive with all other flags
296290
CAGE_ASSERT(any(config.modes));
297291
if (config.guiTextId == 0)
298292
config.guiTextId = HashString(config.id);
@@ -438,7 +432,7 @@ namespace cage
438432
}
439433
if (in.has<input::KeyRelease>() || in.has<input::KeyRepeat>())
440434
return false;
441-
if (in.has<input::KeyPress>() && config.devices != KeybindDevicesFlags::Modifiers)
435+
if (in.has<input::KeyPress>() && none(config.devices & KeybindDevicesFlags::Modifiers))
442436
{
443437
const input::KeyPress k = in.get<input::KeyPress>();
444438
switch (k.key)
@@ -761,9 +755,15 @@ namespace cage
761755
if (ini->sectionExists(k->config.id))
762756
{
763757
k->clear();
764-
for (const String &it : ini->items(k->config.id))
758+
if (ini->itemExists(k->config.id, "count"))
759+
{
760+
const uint32 cnt = ini->getUint32(k->config.id, "count");
761+
for (uint32 i = 0; i < cnt; i++)
762+
k->matchers.push_back(fromString(ini->get(k->config.id, Stringizer() + i)));
763+
}
764+
else
765765
{
766-
if (it != "count")
766+
for (const String &it : ini->items(k->config.id))
767767
k->matchers.push_back(fromString(ini->get(k->config.id, it)));
768768
}
769769
}

0 commit comments

Comments
 (0)