diff options
Diffstat (limited to 'virtual-programs/keyboard.folk')
| -rw-r--r-- | virtual-programs/keyboard.folk | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/virtual-programs/keyboard.folk b/virtual-programs/keyboard.folk index 46b2ebf0..fa242379 100644 --- a/virtual-programs/keyboard.folk +++ b/virtual-programs/keyboard.folk @@ -42,17 +42,30 @@ proc walkInputEventPaths {} { } set keyboardDevices [walkInputEventPaths] +set globalKeymap [keymap load "us"] # go through each keyboard device and start a process that foreach keyboard $keyboardDevices { Claim the keyboards are $keyboardDevices Start process "keyboard-$keyboard" { source "lib/Keymap.tcl" - set km [keymap load "us"] set KEY_STATES [list up down repeat] Wish $::thisProcess shares statements like \ - [list keyboard /kb/ claims key /k/ is /t/ with modifiers /m/ timestamp /timestamp/] + [list keyboard /kb/ claims key /k/ is /t/ with timestamp /timestamp/] + Wish $::thisProcess receives statements like \ + [list /someone/ claims /page/ is a keyboard with path $keyboard locale /locale/] + + set ::localKeymap "" + When $keyboardSpecifier is a keyboard with path $keyboard locale /locale/ { + set ::localKeymap [keymap load $locale] + + On unmatch { + keymap destroy $::localKeymap + set ::localKeymap "" + } + } + variable evtBytes 16 variable evtFormat iissi if {[exec getconf LONG_BIT] == 64} { @@ -64,42 +77,35 @@ foreach keyboard $keyboardDevices { variable keyboardChannel [open $keyboard r] chan configure $keyboardChannel -translation binary - set modifiers [dict create \ - shift 0 \ - ctrl 0 \ - alt 0 \ - ] + set modifiers [dict map {k v} $keymap::modWeights 0] while 1 { binary scan [read $keyboardChannel $evtBytes] $evtFormat \ tvSec tvUsec type code value if {$type == 0x01} { ;# EV_KEY - set shift [dict get $modifiers shift] - set key [keymap resolve $km $code $shift] + set activeKeymap [expr {$localKeymap eq "" ? $globalKeymap : $localKeymap}] + set mods [+ {*}[dict values $modifiers]] + set key [keymap resolve $activeKeymap $code $mods] if {$key eq ""} { continue } set keyState [lindex $KEY_STATES $value] set isDown [expr {$keyState != "up"}] - if {$key eq "Shift"} { - dict set modifiers shift $isDown - } elseif {$key eq "Control"} { - dict set modifiers ctrl $isDown - } elseif {$key eq "Alt"} { - dict set modifiers alt $isDown + if {[dict exists $keymap::modWeights $key]} { + set weight [dict get $keymap::modWeights $key] + dict set modifiers $key [expr {$isDown * $weight}] } - set heldModifiers [dict keys [dict filter $modifiers value 1]] set now [clock milliseconds] - Assert keyboard $keyboardSpecifier claims key $key is $keyState with \ - modifiers $heldModifiers timestamp $now + Assert keyboard $keyboardSpecifier claims key $key is $keyState with timestamp $now + puts "Assert keyboard $keyboardSpecifier claims key $key is $keyState with timestamp $now" # Retract all key events that are more than 5 seconds old. - set events [Statements::findMatches [list keyboard $keyboardSpecifier claims key /key/ is /keyState/ with modifiers /ms/ timestamp /timestamp/]] + set events [Statements::findMatches [list keyboard $keyboardSpecifier claims key /key/ is /keyState/ with timestamp /timestamp/]] foreach event $events { dict with event { if {$now - $timestamp > 5000} { - Retract keyboard $keyboardSpecifier claims key $key is $keyState with modifiers $ms timestamp $timestamp + Retract keyboard $keyboardSpecifier claims key $key is $keyState with timestamp $timestamp } } } |
