1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-11 21:17:45 +03:00

boot/init: Use the new evdev library

It still uses evdev internally, but first let's change the interface,
*then* change the implementation details.
This commit is contained in:
Samuel Dionne-Riel 2020-11-21 15:45:38 -05:00
parent f2d1cf95b2
commit 0037614821
3 changed files with 28 additions and 5 deletions

View File

@ -40,6 +40,7 @@ stdenv.mkDerivation {
# This is the "script" that will be loaded.
mrbc -o init.mrb \
$(find ${../lib} -type f | sort) \
$(find lib -type f | sort) \
$(get_tasks) \
init.rb

View File

@ -129,11 +129,7 @@ class Tasks::SwitchRoot < SingletonTask
"KEY_ESC", # QEMU doesn't pass through CTRL and SHIFT as expected here...
]
# Do *not* use System.run as it would fail the boot on return value != 0
system(LOADER, "/applets/key-held.mrb", *keys)
# It returns `0` on key being held.
$?.exitstatus == 0
Evdev.keys_held(keys)
end
# Checks if the user wants to select a generation.

26
boot/lib/evdev.rb Normal file
View File

@ -0,0 +1,26 @@
module Evdev
# TODO: Remove dependency on `evtest` and rather rely on direct evdev bindings.
def self.keys_held(keys)
# See:
# * https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h
# `evdev` works on `/dev/input/event*` nodes.
# Check them *all*. We can't know which is a keyboard.
Dir.glob("/dev/input/event*").each do |ev|
# `evtest` only tests one key at a time with `--query`...
keys.each do |key|
system("evtest", "--query", ev, "EV_KEY", key)
# One of the keys desired is held
if $?.exitstatus == 10
puts "#{key} is being held"
return true
end
# Failed for other reason
puts "Failed to run evtest, #{$?.exitstatus}" unless $?.exitstatus == 0
end
end
return false
end
end