Make the Evdev plug/unplug events send the full path instead of just the

number.

Update ExternalKeyboard accordingly, and make it ask for an explicit
Input close on unplug.

We previously relied on an internal ENODEV check in the Lua/C module.
reviewable/pr11807/r4
NiLuJe 3 weeks ago
parent ab5f35c38b
commit 27ab744173

@ -62,11 +62,15 @@ function UIManager:init()
UsbDevicePlugIn = function(input_event)
-- Retrieve the argument set by Input:handleKeyBoardEv
local evdev = table.remove(Input.fake_event_args[input_event])
self:broadcastEvent(Event:new("EvdevInputInsert", evdev))
local path = "/dev/input/event" .. tostring(evdev)
self:broadcastEvent(Event:new("EvdevInputInsert", path))
end,
UsbDevicePlugOut = function(input_event)
local evdev = table.remove(Input.fake_event_args[input_event])
self:broadcastEvent(Event:new("EvdevInputRemove", evdev))
local path = "/dev/input/event" .. tostring(evdev)
self:broadcastEvent(Event:new("EvdevInputRemove", path))
end,
}
self.poweroff_action = function()

@ -224,18 +224,17 @@ function ExternalKeyboard:onExit()
end
end
function ExternalKeyboard:_onEvdevInputInsert(evdev)
self:setupKeyboard("/dev/input/event" .. tostring(evdev))
function ExternalKeyboard:_onEvdevInputInsert(event_path)
self:setupKeyboard(event_path)
end
function ExternalKeyboard:onEvdevInputInsert(evdev)
function ExternalKeyboard:onEvdevInputInsert(path)
-- Leave time for the kernel to actually create the device
UIManager:scheduleIn(0.5, self._onEvdevInputInsert, self, evdev)
UIManager:scheduleIn(0.5, self._onEvdevInputInsert, self, path)
end
function ExternalKeyboard:_onEvdevInputRemove(evdev)
function ExternalKeyboard:_onEvdevInputRemove(event_path)
-- Check that a keyboard we know about really was disconnected. Another input device could've been unplugged.
local event_path = "/dev/input/event" .. tostring(evdev)
if not ExternalKeyboard.keyboard_fds[event_path] then
logger.dbg("ExternalKeyboard:onEvdevInputRemove:", event_path, "was not a keyboard we knew about")
return
@ -248,6 +247,9 @@ function ExternalKeyboard:_onEvdevInputRemove(evdev)
return
end
-- Close our Input handle on it
Device.input.close(event_path)
ExternalKeyboard.keyboard_fds[event_path] = nil
ExternalKeyboard.connected_keyboards = ExternalKeyboard.connected_keyboards - 1
logger.dbg("ExternalKeyboard: USB keyboard", event_path, "was disconnected; total:", ExternalKeyboard.connected_keyboards)
@ -277,6 +279,10 @@ function ExternalKeyboard:_onEvdevInputRemove(evdev)
self:_broadcastDisconnected()
end
function ExternalKeyboard:onEvdevInputRemove(path)
UIManager:scheduleIn(0.5, self._onEvdevInputRemove, self, path)
end
ExternalKeyboard._broadcastDisconnected = UIManager:debounce(0.5, false, function()
InputText.initInputEvents()
UIManager:broadcastEvent(Event:new("PhysicalKeyboardDisconnected"))
@ -335,10 +341,6 @@ function ExternalKeyboard:findAndSetupKeyboards()
end
end
function ExternalKeyboard:onEvdevInputRemove(evdev)
UIManager:scheduleIn(0.5, self._onEvdevInputRemove, self, evdev)
end
function ExternalKeyboard:setupKeyboard(data)
local keyboard_info
if type(data) == "table" then

Loading…
Cancel
Save