summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
authorAndrés Cuervo <andrescuervor@gmail.com>2023-12-05 22:01:42 +0000
committerAndrés Cuervo <andrescuervor@gmail.com>2023-12-05 22:01:42 +0000
commit3653fc15441e45437d6ebd066f0a672593dec8cd (patch)
tree7bb05771f955ecd4759394474e2e230ef8f0e0cd /virtual-programs
parentIntegrate modifiers, fix esc-restart (diff)
downloadfolk-3653fc15441e45437d6ebd066f0a672593dec8cd.tar.gz
folk-3653fc15441e45437d6ebd066f0a672593dec8cd.zip
Add (non-differentiated) keypress logic to editor
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/editor.folk228
-rw-r--r--virtual-programs/keyboard.folk7
2 files changed, 120 insertions, 115 deletions
diff --git a/virtual-programs/editor.folk b/virtual-programs/editor.folk
index 7400a299..0e63cd85 100644
--- a/virtual-programs/editor.folk
+++ b/virtual-programs/editor.folk
@@ -250,131 +250,133 @@ proc getCurrentLineLength {lines cursor} {
string length $currentLine
}
-Every time keyboard claims key /currentCharacter/ is down with modifiers /modifier/ & the cursor is /cursor/ & $id has program code /code/ {
- Commit cursor {
- switch $currentCharacter {
- UP {
- set updatedCursor [updateCursor $cursor {y -1}]
- set currentLineLength [getCurrentLineLength $code $updatedCursor]
- if {[lindex $updatedCursor 0] > $currentLineLength} {
- Claim the cursor is [list [- $currentLineLength 1] [lindex $updatedCursor 1]]
- } else {
- Claim the cursor is $updatedCursor
+When /page/ is a keyboard with path /kbPath/ {
+ Every time keyboard $kbPath claims key /currentCharacter/ is down with modifiers /modifier/ & the cursor is /cursor/ & $id has program code /code/ {
+ Commit cursor {
+ switch $currentCharacter {
+ UP {
+ set updatedCursor [updateCursor $cursor {y -1}]
+ set currentLineLength [getCurrentLineLength $code $updatedCursor]
+ if {[lindex $updatedCursor 0] > $currentLineLength} {
+ Claim the cursor is [list [- $currentLineLength 1] [lindex $updatedCursor 1]]
+ } else {
+ Claim the cursor is $updatedCursor
+ }
}
- }
- DOWN {
- set linecount [llength [split $code "\n"]]
- set updatedCursor [updateCursor $cursor {y 1}]
- set currentLineLength [getCurrentLineLength $code $updatedCursor]
+ DOWN {
+ set linecount [llength [split $code "\n"]]
+ set updatedCursor [updateCursor $cursor {y 1}]
+ set currentLineLength [getCurrentLineLength $code $updatedCursor]
- if {[lindex $updatedCursor 1] == $linecount} {
- Claim the cursor is $cursor
- return
- } elseif {[lindex $updatedCursor 0] > $currentLineLength} {
- Claim the cursor is [list $currentLineLength [lindex $updatedCursor 1]]
- } else {
- Claim the cursor is $updatedCursor
+ if {[lindex $updatedCursor 1] == $linecount} {
+ Claim the cursor is $cursor
+ return
+ } elseif {[lindex $updatedCursor 0] > $currentLineLength} {
+ Claim the cursor is [list $currentLineLength [lindex $updatedCursor 1]]
+ } else {
+ Claim the cursor is $updatedCursor
+ }
}
- }
- RIGHT {
- set currentLineLength [getCurrentLineLength $code $cursor]
- # TODO: Check if the cursor is at the end of the line, if so cap it
- Claim the cursor is [updateCursor $cursor {x 1}]
- }
- LEFT { Claim the cursor is [updateCursor $cursor {x -1}] }
- BACKSPACE {
- # if cursor is at the beginning of the line, delete the newline
- if {[x $cursor] == 0} {
- set newCursor [updateCursor $cursor {y -1}]
- set previousLineLength [getCurrentLineLength $code $newCursor]
- set newCursor [list $previousLineLength [y $newCursor]]
- Claim the cursor is $newCursor
- } else {
- Claim the cursor is [updateCursor $cursor {x -1}]
+ RIGHT {
+ set currentLineLength [getCurrentLineLength $code $cursor]
+ # TODO: Check if the cursor is at the end of the line, if so cap it
+ Claim the cursor is [updateCursor $cursor {x 1}]
}
- Commit code { Claim $id has program code [deleteCharacter $code $cursor] }
- }
- SPACE {
- Claim the cursor is [updateCursor $cursor {x 1}]
- Commit code { Claim $id has program code [insertCharacter $code " " $cursor] }
- }
- ENTER {
- set updatedCursor [updateCursor $cursor {y 1}]
- Claim the cursor is [list 0 [lindex $updatedCursor 1]]
- Commit code { Claim $id has program code [insertNewline $code $cursor] }
- }
- DELETE -
- INSERT -
- MUTE -
- VOLUMEUP -
- VOLUMEDOWN -
- ESC -
- TAB -
- CAPSLOCK -
- LEFTSHIFT -
- RIGHTSHIFT -
- LEFTALT -
- RIGHTALT -
- LEFTCTRL -
- RIGHTCTRL {
- # TODO: Implement DELETE, operates like BACKSPACE, but in the opposite direction
- # TODO: MUTE VOLUMEUP VOLUMEDOWN
- # implement sound.folk that allows a system-wide
- # volume setting to be adjusted.
- # Perhaps `Wish $system volume is 0.5` or something
-
- Claim the cursor is $cursor
- }
- default {
- if {$modifier == "ctrl" & $currentCharacter == "p"} {
- # TODO: Save time instead and prevent printing the same code within the same ... second?
- When $id has printed /lastPrintedCode/ {
- if {$lastPrintedCode == $code} {
- Claim the cursor is $cursor
+ LEFT { Claim the cursor is [updateCursor $cursor {x -1}] }
+ BACKSPACE {
+ # if cursor is at the beginning of the line, delete the newline
+ if {[x $cursor] == 0} {
+ set newCursor [updateCursor $cursor {y -1}]
+ set previousLineLength [getCurrentLineLength $code $newCursor]
+ set newCursor [list $previousLineLength [y $newCursor]]
+ Claim the cursor is $newCursor
+ } else {
+ Claim the cursor is [updateCursor $cursor {x -1}]
+ }
+ Commit code { Claim $id has program code [deleteCharacter $code $cursor] }
+ }
+ SPACE {
+ Claim the cursor is [updateCursor $cursor {x 1}]
+ Commit code { Claim $id has program code [insertCharacter $code " " $cursor] }
+ }
+ ENTER {
+ set updatedCursor [updateCursor $cursor {y 1}]
+ Claim the cursor is [list 0 [lindex $updatedCursor 1]]
+ Commit code { Claim $id has program code [insertNewline $code $cursor] }
+ }
+ DELETE -
+ INSERT -
+ MUTE -
+ VOLUMEUP -
+ VOLUMEDOWN -
+ ESC -
+ TAB -
+ CAPSLOCK -
+ LEFTSHIFT -
+ RIGHTSHIFT -
+ LEFTALT -
+ RIGHTALT -
+ LEFTCTRL -
+ RIGHTCTRL {
+ # TODO: Implement DELETE, operates like BACKSPACE, but in the opposite direction
+ # TODO: MUTE VOLUMEUP VOLUMEDOWN
+ # implement sound.folk that allows a system-wide
+ # volume setting to be adjusted.
+ # Perhaps `Wish $system volume is 0.5` or something
+
+ Claim the cursor is $cursor
+ }
+ default {
+ if {$modifier == "ctrl" & $currentCharacter == "p"} {
+ # TODO: Save time instead and prevent printing the same code within the same ... second?
+ When $id has printed /lastPrintedCode/ {
+ if {$lastPrintedCode == $code} {
+ Claim the cursor is $cursor
+ if {$::debug_print} {
+ puts "Not printing the same code twice"
+ }
+ return
+ }
+ }
+ When /nobody/ has printed /lastPrintedCode/ {
if {$::debug_print} {
- puts "Not printing the same code twice"
+ puts "Printing $code"
}
+ Commit print { Claim $id has printed $code}
+ Wish to print $code with job id [expr {rand()}]
return
}
+ Commit code { Claim $id has program code $code}
+ Claim the cursor is $cursor
+ return
}
- When /nobody/ has printed /lastPrintedCode/ {
- if {$::debug_print} {
- puts "Printing $code"
- }
- Commit print { Claim $id has printed $code}
- Wish to print $code with job id [expr {rand()}]
+ if {$modifier == "ctrl" & $currentCharacter == "r"} {
+ Commit code { Claim $id has program code $baseCode }
+ Claim the cursor is [list 0 0]
return
}
- Commit code { Claim $id has program code $code}
- Claim the cursor is $cursor
- return
- }
- if {$modifier == "ctrl" & $currentCharacter == "r"} {
- Commit code { Claim $id has program code $baseCode }
- Claim the cursor is [list 0 0]
- return
- }
- if {$modifier == "ctrl" & $currentCharacter == "a"} {
- Commit code { Claim $id has program code $code}
- lassign $cursor x y
- Claim the cursor is [list 0 $y]
- return
- }
- if {$modifier == "ctrl" & $currentCharacter == "e"} {
- Commit code { Claim $id has program code $code}
- lassign $cursor x y
- Claim the cursor is [list [getLineLength $code $cursor] $y]
- return
- }
- if {$modifier == "ctrl" & $currentCharacter == "u"} {
- # delete from cursor back to 0 and move cursor to 0
- Commit code { Claim $id has program code [deleteToBeginning $code $cursor]}
- lassign $cursor x y
- Claim the cursor is [list 0 $y]
- return
+ if {$modifier == "ctrl" & $currentCharacter == "a"} {
+ Commit code { Claim $id has program code $code}
+ lassign $cursor x y
+ Claim the cursor is [list 0 $y]
+ return
+ }
+ if {$modifier == "ctrl" & $currentCharacter == "e"} {
+ Commit code { Claim $id has program code $code}
+ lassign $cursor x y
+ Claim the cursor is [list [getLineLength $code $cursor] $y]
+ return
+ }
+ if {$modifier == "ctrl" & $currentCharacter == "u"} {
+ # delete from cursor back to 0 and move cursor to 0
+ Commit code { Claim $id has program code [deleteToBeginning $code $cursor]}
+ lassign $cursor x y
+ Claim the cursor is [list 0 $y]
+ return
+ }
+ Claim the cursor is [updateCursor $cursor {x 1}]
+ Commit code { Claim $id has program code [insertCharacter $code $currentCharacter $cursor] }
}
- Claim the cursor is [updateCursor $cursor {x 1}]
- Commit code { Claim $id has program code [insertCharacter $code $currentCharacter $cursor] }
}
}
}
diff --git a/virtual-programs/keyboard.folk b/virtual-programs/keyboard.folk
index 080eb679..c3b3db6b 100644
--- a/virtual-programs/keyboard.folk
+++ b/virtual-programs/keyboard.folk
@@ -47,7 +47,8 @@ proc isKeyboard {device} {
#
# This function goes through each of them and checks if they are keyboards
proc walkInputEventPaths {} {
- set allDevices [glob -nocomplain "/dev/input/event*"]
+ # set allDevices [glob -nocomplain "/dev/input/event*"]
+ set allDevices [glob -nocomplain "/dev/input/by-path/*"]
set keyboards [list]
foreach device $allDevices {
set devLinks [getDEVLINKS $device]
@@ -78,6 +79,7 @@ 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" {
source "pi/KeyCodes.tcl"
Wish $::thisProcess shares statements like \
@@ -128,7 +130,8 @@ foreach keyboard $keyboardDevices {
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 [list $key] is [list $keyState] with modifiers [list $heldModifiers]
+ Assert keyboard $keyboardSpecifier claims key $key is $keyState with modifiers $heldModifiers
Step
}
}