libobs: Fix issue 4408 (hotkey logic)

If obs_core_hotkeys.strict_modifiers is true (new default),
hotkey is triggered only if current key modifiers exactly match
the hotkey definition. If false, legacy behavior is selected.
This commit is contained in:
OldBaldGeek 2021-08-06 16:16:01 -05:00 committed by Jim
parent 1705edf8f9
commit bb6787968c
2 changed files with 6 additions and 4 deletions

View file

@ -1194,9 +1194,10 @@ static inline bool modifiers_match(obs_hotkey_binding_t *binding,
uint32_t modifiers_, bool strict_modifiers)
{
uint32_t modifiers = binding->key.modifiers;
return !modifiers ||
(!strict_modifiers && (modifiers & modifiers_) == modifiers) ||
(strict_modifiers && modifiers == modifiers_);
if (!strict_modifiers)
return (modifiers & modifiers_) == modifiers;
else
return modifiers == modifiers_;
}
static inline bool is_pressed(obs_key_t key)
@ -1243,7 +1244,7 @@ static inline void handle_binding(obs_hotkey_binding_t *binding,
modifiers_match(binding, modifiers, strict_modifiers);
bool modifiers_only = binding->key.key == OBS_KEY_NONE;
if (!binding->key.modifiers)
if (!strict_modifiers && !binding->key.modifiers)
binding->modifiers_match = true;
if (modifiers_only)

View file

@ -990,6 +990,7 @@ static inline bool obs_init_hotkeys(void)
NULL))
goto fail;
hotkeys->strict_modifiers = true;
hotkeys->hotkey_thread_initialized = true;
success = true;