summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/editor.folk160
-rw-r--r--virtual-programs/esc-restart.folk2
-rw-r--r--virtual-programs/keyboard.folk46
-rw-r--r--virtual-programs/terminal.folk5
-rw-r--r--virtual-programs/web/web-keyboards.folk4
5 files changed, 100 insertions, 117 deletions
diff --git a/virtual-programs/editor.folk b/virtual-programs/editor.folk
index 624b9387..6ac074dd 100644
--- a/virtual-programs/editor.folk
+++ b/virtual-programs/editor.folk
@@ -15,8 +15,8 @@ When /page/ is a keyboard with path /kbPath/ &\
Claim $id has region [region move $r up 210%]
When /nobody/ claims $id has program code /c/ {
Commit "code$kbPath" {
- Claim $id has program code $baseCode
- Claim $id has editor code $baseCode
+ Claim $id has program code $baseCode
+ Claim $id has editor code $baseCode
}
}
@@ -191,7 +191,7 @@ proc getCurrentLineLength {lines cursor} {
When /page/ is a keyboard with path /kbPath/ & /page/ is an editor {
set id "$page$kbPath"
- Every time keyboard $kbPath claims key /currentCharacter/ is /keyState/ with modifiers /modifier/ timestamp /timestamp/ &\
+ Every time keyboard $kbPath claims key /currentCharacter/ is /keyState/ with timestamp /timestamp/ &\
the $kbPath cursor is /cursor/ &\
$id has program code /code/ &\
$id has editor code /editorCode/ &\
@@ -199,7 +199,7 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor {
if {($keyState == "down" || $keyState == "repeat") & $timestamp > ($startTime * 1000) } {
Commit "cursor$kbPath" {
switch $currentCharacter {
- UP {
+ Up {
set updatedCursor [updateCursor $cursor {y -1}]
set currentLineLength [getCurrentLineLength $editorCode $updatedCursor]
if {[x $updatedCursor] > $currentLineLength} {
@@ -208,7 +208,7 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor {
Claim the $kbPath cursor is $updatedCursor
}
}
- DOWN {
+ Down {
set linecount [llength [split $editorCode "\n"]]
set updatedCursor [updateCursor $cursor {y 1}]
set currentLineLength [getCurrentLineLength $editorCode $updatedCursor]
@@ -222,7 +222,7 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor {
Claim the $kbPath cursor is $updatedCursor
}
}
- RIGHT {
+ Right {
set currentLineLength [getCurrentLineLength $editorCode $cursor]
if {[x $cursor] == $currentLineLength} {
if {[y $cursor] == [expr {[llength [split $editorCode "\n"]] - 1}]} {
@@ -235,7 +235,7 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor {
Claim the $kbPath cursor is [updateCursor $cursor {x 1}]
}
}
- LEFT {
+ Left {
if {[x $cursor] == 0 && [y $cursor] == 0} {
Claim the $kbPath cursor is $cursor
} elseif {[x $cursor] == 0} {
@@ -247,7 +247,7 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor {
Claim the $kbPath cursor is [updateCursor $cursor {x -1}]
}
}
- BACKSPACE {
+ Remove {
# if cursor is at the beginning of the line, delete the newline
if {[x $cursor] == 0 && [y $cursor] > 0} {
set newCursor [updateCursor $cursor {y -1}]
@@ -262,14 +262,14 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor {
Claim $id has editor code [deleteCharacter $editorCode $cursor]
}
}
- SPACE {
+ space {
Claim the $kbPath cursor is [updateCursor $cursor {x 1}]
Commit "code$kbPath" {
Claim $id has program code $code
Claim $id has editor code [insertCharacter $editorCode " " $cursor]
}
}
- ENTER {
+ Return {
set updatedCursor [updateCursor $cursor {y 1}]
Claim the $kbPath cursor is [list 0 [y $updatedCursor]]
Commit "code$kbPath" {
@@ -277,99 +277,77 @@ When /page/ is a keyboard with path /kbPath/ & /page/ is an editor {
Claim $id has editor code [insertNewline $editorCode $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 $kbPath cursor is $cursor
- }
- default {
- if {$modifier == "ctrl" & $currentCharacter == "p"} {
- When $id has printed /lastPrintedCode/ at /previousTime/ {
- if {($timestamp - $previousTime) < 1000} {
- Commit "code$kbPath" {
- Claim $id has program code $code
- Claim $id has editor code $editorCode
- }
- Claim the $kbPath cursor is $cursor
- return
+ # 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
+ Control_p {
+ When $id has printed /lastPrintedCode/ at /previousTime/ {
+ if {($timestamp - $previousTime) < 1000} {
+ Commit "code$kbPath" {
+ Claim $id has program code $code
+ Claim $id has editor code $editorCode
}
+ Claim the $kbPath cursor is $cursor
}
+ }
- Commit print { Claim $id has printed $code at $timestamp}
- Wish to print $code with job-id [expr {rand()}]
+ Commit print { Claim $id has printed $code at $timestamp}
+ Wish to print $code with job-id [expr {rand()}]
- Commit "code$kbPath" {
- Claim $id has program code $code
- Claim $id has editor code $editorCode
- }
- Claim the $kbPath cursor is $cursor
- return
+ Commit "code$kbPath" {
+ Claim $id has program code $code
+ Claim $id has editor code $editorCode
}
- if {$modifier == "ctrl" & $currentCharacter == "r"} {
- Commit "code$kbPath" {
- Claim $id has program code $baseCode
- Claim $id has editor code $baseCode
- }
- Claim the $kbPath cursor is [list 0 0]
- return
+ Claim the $kbPath cursor is $cursor
+ }
+ Control_r {
+ Commit "code$kbPath" {
+ Claim $id has program code $baseCode
+ Claim $id has editor code $baseCode
}
- if {$modifier == "ctrl" & $currentCharacter == "s"} {
- Commit "code$kbPath" {
- Claim $id has program code $editorCode
- Claim $id has editor code $editorCode
- }
- Claim the $kbPath cursor is $cursor
- return
+ Claim the $kbPath cursor is [list 0 0]
+ }
+ Control_s {
+ Commit "code$kbPath" {
+ Claim $id has program code $editorCode
+ Claim $id has editor code $editorCode
}
- if {$modifier == "ctrl" & $currentCharacter == "a"} {
- Commit "code$kbPath" {
- Claim $id has program code $code
- Claim $id has editor code $editorCode
- }
- lassign $cursor x y
- Claim the $kbPath cursor is [list 0 $y]
- return
+ Claim the $kbPath cursor is $cursor
+ }
+ Control_a {
+ Commit "code$kbPath" {
+ Claim $id has program code $code
+ Claim $id has editor code $editorCode
}
- if {$modifier == "ctrl" & $currentCharacter == "e"} {
- Commit "code$kbPath" {
- Claim $id has program code $code
- Claim $id has editor code $editorCode
- }
- lassign $cursor x y
- Claim the $kbPath cursor is [list [getLineLength $editorCode $cursor] $y]
- return
+ lassign $cursor x y
+ Claim the $kbPath cursor is [list 0 $y]
+ }
+ Control_e {
+ Commit "code$kbPath" {
+ Claim $id has program code $code
+ Claim $id has editor code $editorCode
}
- if {$modifier == "ctrl" & $currentCharacter == "u"} {
- # delete from cursor back to 0 and move cursor to 0
+ lassign $cursor x y
+ Claim the $kbPath cursor is [list [getLineLength $editorCode $cursor] $y]
+ }
+ Control_u {
+ # delete from cursor back to 0 and move cursor to 0
+ Commit "code$kbPath" {
+ Claim $id has program code $code
+ Claim $id has editor code [deleteToBeginning $editorCode $cursor]
+ }
+ lassign $cursor x y
+ Claim the $kbPath cursor is [list 0 $y]
+ }
+ default {
+ if {[set printable [keymap::printable $currentCharacter]] neq ""} {
+ Claim the $kbPath cursor is [updateCursor $cursor {x 1}]
Commit "code$kbPath" {
Claim $id has program code $code
- Claim $id has editor code [deleteToBeginning $editorCode $cursor]
+ Claim $id has editor code [insertCharacter $editorCode $printable $cursor]
}
- lassign $cursor x y
- Claim the $kbPath cursor is [list 0 $y]
- return
- }
- Claim the $kbPath cursor is [updateCursor $cursor {x 1}]
- Commit "code$kbPath" {
- Claim $id has program code $code
- Claim $id has editor code [insertCharacter $editorCode $currentCharacter $cursor]
}
}
}
diff --git a/virtual-programs/esc-restart.folk b/virtual-programs/esc-restart.folk
index 17b56163..1be6e0c7 100644
--- a/virtual-programs/esc-restart.folk
+++ b/virtual-programs/esc-restart.folk
@@ -1,3 +1,3 @@
-When keyboard /k/ claims key ESC is down with modifiers alt timestamp /any/ {
+When keyboard /k/ claims key Meta_Escape is down with timestamp /any/ {
exec sudo systemctl restart folk
}
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
}
}
}
diff --git a/virtual-programs/terminal.folk b/virtual-programs/terminal.folk
index e5de23dd..a604fbd7 100644
--- a/virtual-programs/terminal.folk
+++ b/virtual-programs/terminal.folk
@@ -77,10 +77,9 @@ When /anyone/ wishes /thing/ is a terminal spawning /cmd/ {
}
When /anyone/ claims $thing has keyboard input \
- & keyboard /anyone/ claims key /key/ is /direction/ with modifiers /modifiers/ timestamp /timestamp/ {
+ & keyboard /anyone/ claims key /key/ is /direction/ timestamp /timestamp/ {
if {$direction != "up"} {
- set ctrlPressed [expr {"ctrl" in $modifiers}]
- Terminal::write $term $key $ctrlPressed
+ Terminal::write $term $key
}
}
}
diff --git a/virtual-programs/web/web-keyboards.folk b/virtual-programs/web/web-keyboards.folk
index 2e3c5afa..b1668c69 100644
--- a/virtual-programs/web/web-keyboards.folk
+++ b/virtual-programs/web/web-keyboards.folk
@@ -23,7 +23,7 @@ When the keyboards are /keyboards/ {
ws.onopen = () => {
document.getElementById('status').innerHTML = "<span style=background-color:seagreen;color:white;>Connnected</span>";
send(`
- Assert when keyboard /kb/ claims key /k/ is down with modifiers /m/ timestamp /ts/ {{chan kb k m ts} {
+ Assert when keyboard /kb/ claims key /k/ is down timestamp /ts/ {{chan kb k ts} {
if {\$ts > [clock milliseconds]} {
::websocket::send \$chan text "\$kb||\$k"
}
@@ -32,7 +32,7 @@ When the keyboards are /keyboards/ {
};
ws.onclose = window.onbeforeunload = () => {
document.getElementById('status').innerHTML = "<span style=background-color:red;color:white;>Disconnnected</span>";
- send(`Retract when keyboard /kb/ claims key /k/ is down with modifiers /m/ timestamp /ts/ /anything/ with environment \[list \$chan]`)
+ send(`Retract when keyboard /kb/ claims key /k/ is down timestamp /ts/ /anything/ with environment \[list \$chan]`)
setTimeout(() => { wsConnect(); }, 1000);
};
ws.onerror = (err) => {