+
+ # scan /dev/hidraw*
+ foreach binding [input-bindings-list hidraw] {
+ manyset $binding devkind devid devinfo concrete concargs
+ switch -exact $devkind hidraw { } default continue
+ manyset $devinfo devtype
+ set rawmap([hidraw-descriptors/$devtype]) \
+ [list $devid $devtype $concrete]
+ }
+ if {[array exists rawmap]} {
+ set new_hidraws [lsort [glob -nocomplain -directory /dev hidraw*]]
+ foreach hidraw $new_hidraws {
+ upvar #0 hidraw/$hidraw raw
+ if {[info exists raw(chan)]} {
+ set found($raw(devid)) 1
+ continue
+ }
+ if {[lsearch -exact $old_hidraws $hidraw] >= 0} continue
+ if {[catch {
+ set chan [open $hidraw r+]
+ set descriptors [exec ./hidraw-ioctl -d <@ $chan]
+ if {![info exists rawmap($descriptors)]} {
+ set m [exec ./hidraw-ioctl -i <@ $chan]
+ error "unknown descriptors (unmatched device) $hidraw $m >$descriptors<"
+ }
+ } emsg]} {
+ upvar #0 hidraw_notified($hidraw) notified
+ if {![info exists notified] ||
+ [string compare $notified $emsg]} {
+ debug "ir $hidraw $emsg"
+ set notified $emsg
+ }
+ catch { close $chan }
+ catch { unset chan }
+ continue
+ }
+ manyset $rawmap($descriptors) devid devtype concrete
+ set found($devid) 1
+ if {![input-concrete-start-try $devid $concrete]} {
+ catch { close $chan }
+ continue
+ }
+ set raw(devid) $devid
+ set raw(chan) $chan
+ fconfigure $chan -buffering none -blocking no \
+ -encoding binary -eofchar {} -translation binary
+ fileevent $chan readable \
+ [list hidraw-readable/$devtype $chan $hidraw $devid]
+ input-binding-present $devid 1 "hidraw $hidraw"
+ }
+ set old_hidraws $new_hidraws
+ }
+
+ # try to start the input binding for all the unstarted found targets