summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
authorAndrés Cuervo <andrescuervor@gmail.com>2023-12-06 23:04:15 +0000
committerAndrés Cuervo <andrescuervor@gmail.com>2023-12-06 23:04:15 +0000
commit701a4f3d6d97e1eac6e85f03635f82637a19e6e9 (patch)
tree63d1d6a0fe006ab347fd1c03410b22b5b2596991 /virtual-programs
parentAdd (non-differentiated) keypress logic to editor (diff)
downloadfolk-701a4f3d6d97e1eac6e85f03635f82637a19e6e9.tar.gz
folk-701a4f3d6d97e1eac6e85f03635f82637a19e6e9.zip
Simplify keyboards claim
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/keyboard.folk98
1 files changed, 10 insertions, 88 deletions
diff --git a/virtual-programs/keyboard.folk b/virtual-programs/keyboard.folk
index c3b3db6b..c52f119c 100644
--- a/virtual-programs/keyboard.folk
+++ b/virtual-programs/keyboard.folk
@@ -4,26 +4,8 @@ proc udevadmProperties {device} {
return [exec udevadm info --query=property --name=$device]
}
-proc getDEVLINKS {device} {
- set properties [udevadmProperties $device]
- if {$properties eq ""} {
- return ""
- }
- set devlinks [list]
- foreach line [split $properties \n] {
- if {[string match "DEVLINKS=*" $line]} {
- set devlinks [string replace $line 0 8]
- foreach path [split $devlinks " "] {
- lappend devlinks $path
- }
- }
- }
-
- return $devlinks
-}
-
-proc establishKeyPressListener {eventPath} {
- set kb [open $eventPath r]
+proc establishKeyPressListener {keyboard} {
+ set kb [open $keyboard r]
fconfigure $kb -translation binary
return $kb
}
@@ -51,36 +33,24 @@ proc walkInputEventPaths {} {
set allDevices [glob -nocomplain "/dev/input/by-path/*"]
set keyboards [list]
foreach device $allDevices {
- set devLinks [getDEVLINKS $device]
- if {[llength $devLinks] > 0 && [isKeyboard $device]} {
+ if {[isKeyboard $device]} {
if {[file readable $device] == 0} {
puts "Device $device is not readable. Attempting to change permissions."
# Attempt to change permissions so that the file can be read
exec sudo chmod +r $device
}
- lappend keyboards [dict create eventPath $device devLinks $devLinks]
+ lappend keyboards $device
}
}
return $keyboards
}
-proc findMatchingEventPath {searchList eventPath} {
- foreach element $searchList {
- set elEventPath [dict get $element eventPath]
- if {$eventPath eq $elEventPath} {
- return $element
- }
- }
- return 0
-}
-
set keyboardDevices [walkInputEventPaths]
# go through each keyboard device and start a process that
foreach keyboard $keyboardDevices {
- set eventPath [dict get $keyboard eventPath]
Claim keyboards are $keyboardDevices
- Start process "keyboard-$eventPath" {
+ Start process "keyboard-$keyboard" {
source "pi/KeyCodes.tcl"
Wish $::thisProcess shares statements like \
[list keyboard /kb/ claims key /k/ is /t/ with modifiers /m/]
@@ -90,8 +60,8 @@ foreach keyboard $keyboardDevices {
set evtBytes 24
set evtFormat wwssi
}
- set keyboardSpecifier $eventPath
- variable eventPathChannel [open $eventPath r]
+ set keyboardSpecifier $keyboard
+ variable keyboardChannel [open $keyboard r]
set keyStates [list up down repeat]
set modifiers [dict create \
shift 0 \
@@ -99,20 +69,16 @@ foreach keyboard $keyboardDevices {
alt 0 \
]
while 1 {
- binary scan [read $eventPathChannel $evtBytes] $evtFormat tvSec tvUsec type code value
+ binary scan [read $keyboardChannel $evtBytes] $evtFormat tvSec tvUsec type code value
if {$type > 0x04} {
- set eventPathChannel [open $eventPath r]
- binary scan [read $eventPathChannel $evtBytes] $evtFormat tvSec tvUsec type code value
+ set keyboardChannel [open $keyboard r]
+ binary scan [read $keyboardChannel $evtBytes] $evtFormat tvSec tvUsec type code value
}
if {$type == 0x01} {
set shift [dict get $modifiers shift]
set key [keyFromCode $code $shift]
set keyState [lindex $keyStates $value]
- # dict set modifiers shift 0
- # dict set modifiers alt 0
- # dict set modifiers ctrl 0
-
set isDown [expr {$keyState != "up"}]
if {[string match *SHIFT $key]} {
dict set modifiers shift $isDown
@@ -125,54 +91,10 @@ foreach keyboard $keyboardDevices {
}
set heldModifiers [dict keys [dict filter $modifiers value 1]]
- puts "shift: [string match *SHIFT $key] | $key"
- puts "modifiers: $heldModifiers"
-
- puts "got key event ($keyboardSpecifier): $code => $key | $value"
Retract keyboard $keyboardSpecifier claims key /k/ is /t/ with modifiers /m/
- # Assert keyboard $keyboardSpecifier claims key [list $key] is [list $keyState] with modifiers [list $heldModifiers]
Assert keyboard $keyboardSpecifier claims key $key is $keyState with modifiers $heldModifiers
Step
}
}
- # set kbEventPath [open $eventPath r]
- # set keyStates [list up down repeat]
- # set modifiers [dict create \
- # shift 0 \
- # ctrl 0 \
- # alt 0 \
- # ]
-
- # set shift [dict get $modifiers shift]
- # set key [keyFromCode $keyCode $shift]
- # set keyState [lindex $keyStates $eventType]
-
- # set isDown [expr {$keyState != "up"}]
- # if {[string match *SHIFT $key]} {
- # dict set modifiers shift $isDown
- # }
- # if {[string match *CTRL $key]} {
- # dict set modifiers ctrl $isDown
- # }
- # if {[string match *ALT $key]} {
- # dict set modifiers alt $isDown
- # }
-
- # set heldModifiers [dict keys [dict filter $modifiers value 1]]
-
- # while 1 {
- # binary scan [read $kbEventPath $evtBytes] $evtFormat tvSec tvUsec type code value
- # if {$type == 0x01} {
- # Retract keyboard $keyboardSpecifier claims key /k/ is /t/ with modifiers /m/
- # Assert keyboard $keyboardSpecifier claims key [list $key] is [list $keyState] with modifiers [list $heldModifiers]
- # puts "got key event ($keyboardSpecifier): $key $keyState $heldModifiers"
- # # return [list $code $value]
- # }
- # }
- # # establishKeyPressListener $eventPath
- # # foreach devlink [dict get $keyboard devLinks] {
- # # puts " -- : $devlink"
- # # establishKeyPressListener $devlink
- # # }
}
} \ No newline at end of file