InputContainer/FocusManager: Simplify key_events clearing on unplug

Thanks to @poire-z for the idea, it's indeed much nicer this way ;).
This commit is contained in:
NiLuJe
2022-11-01 23:22:07 +01:00
parent d585cd5d86
commit 925fd647dc
19 changed files with 66 additions and 141 deletions

View File

@@ -274,12 +274,17 @@ function FocusManager:onPhysicalKeyboardDisconnected()
local prev_key_events = KEY_EVENTS
populateEventMappings()
-- Remove what disappeared from KEY_EVENTS from self.key_events (if any).
-- NOTE: This is slightly overkill, we could very well live with a few unreachable mappings for the rest of this widget's life ;).
for k, _ in pairs(prev_key_events) do
if not KEY_EVENTS[k] then
self.key_events[k] = nil
-- If we still have keys, remove what disappeared from KEY_EVENTS from self.key_events (if any).
if Device:hasKeys() then
-- NOTE: This is slightly overkill, we could very well live with a few unreachable mappings for the rest of this widget's life ;).
for k, _ in pairs(prev_key_events) do
if not KEY_EVENTS[k] then
self.key_events[k] = nil
end
end
else
-- If we longer have keys at all, that's easy ;).
self.key_events = {}
end
self.builtin_key_events = BUILTIN_KEY_EVENTS
self.extra_key_events = EXTRA_KEY_EVENTS