ExternalKeyboard: Debounce the Connected/Disconnected events

Until we find a way to fine-tune the evdev device parsing, we'll often
have at least two devices per keyboard, but we only need a single event
;).
pull/9739/head
NiLuJe 2 years ago
parent b28d52a124
commit 2db294d0b7

@ -261,10 +261,15 @@ function ExternalKeyboard:_onEvdevInputRemove(evdev)
-- There's a two-pronged approach here: -- There's a two-pronged approach here:
-- * Call a static class method to modify the class state for future instances of said class -- * Call a static class method to modify the class state for future instances of said class
-- * Broadcast an Event so that all currently displayed widgets update their own state. -- * Broadcast an Event so that all currently displayed widgets update their own state.
-- This must come after, because widgets *may* rely on static class members. -- This must come after, because widgets *may* rely on static class members,
-- we have no guarantee about Event delivery order.
self:_broadcastDisconnected()
end
ExternalKeyboard._broadcastDisconnected = UIManager:debounce(0.5, false, function()
InputText.initInputEvents() InputText.initInputEvents()
UIManager:broadcastEvent(Event:new("PhysicalKeyboardDisconnected")) UIManager:broadcastEvent(Event:new("PhysicalKeyboardDisconnected"))
end end)
-- The keyboard events with the same key codes would override the original events. -- The keyboard events with the same key codes would override the original events.
-- That may cause embedded buttons to lose their original function and produce letters, -- That may cause embedded buttons to lose their original function and produce letters,
@ -342,9 +347,13 @@ function ExternalKeyboard:setupKeyboard(event_path)
timeout = 1, timeout = 1,
}) })
end end
self:_broadcastConnected()
end
ExternalKeyboard._broadcastConnected = UIManager:debounce(0.5, false, function()
InputText.initInputEvents() InputText.initInputEvents()
UIManager:broadcastEvent(Event:new("PhysicalKeyboardConnected")) UIManager:broadcastEvent(Event:new("PhysicalKeyboardConnected"))
end end)
function ExternalKeyboard:showHelp() function ExternalKeyboard:showHelp()
UIManager:show(InfoMessage:new { UIManager:show(InfoMessage:new {

Loading…
Cancel
Save