This commit is contained in:
lordwelch 2018-10-20 16:49:09 -07:00
parent 9d04ddc8be
commit 47d8950fd4
2 changed files with 26 additions and 33 deletions

View File

@ -1,43 +1,39 @@
package main
import (
"flag"
"fmt"
"os"
"github.com/alexflint/go-arg"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
"timmy.narnian.us/git/timmy/hid"
"timmy.narnian.us/hid/ghid"
)
func main() {
var (
err error
args struct {
SHORTCUT string `arg:"-S,help:Keymap cycle shortcut"`
PATH string `arg:"-P,help:Path to config dir default: $XDG_CONFIG_HOME"`
ORDER []string `arg:"required,positional,help:Order of keymaps"`
}
SHORTCUT string
)
args.PATH = os.ExpandEnv("$XDG_CONFIG_HOME")
arg.MustParse(&args)
hid.KeymapOrder = args.ORDER
hid.KeymapPath = args.PATH
flag.StringVar(&SHORTCUT, "shortcut", "", "Keymap cycle shortcut")
flag.StringVar(&SHORTCUT, "s", "", "Keymap cycle shortcut")
flag.StringVar(&hid.KeymapPath, "path", os.ExpandEnv("$XDG_CONFIG_HOME"), "Path to config dir default: $XDG_CONFIG_HOME")
flag.StringVar(&hid.KeymapPath, "p", os.ExpandEnv("$XDG_CONFIG_HOME"), "Path to config dir default: $XDG_CONFIG_HOME")
flag.Parse()
hid.KeymapOrder = flag.Args()
fmt.Println(hid.KeymapPath)
hid.Hidg0, err = os.OpenFile("hidg0", os.O_APPEND|os.O_WRONLY, 0755)
file, err := os.OpenFile("/dev/hidg0", os.O_APPEND|os.O_WRONLY, 0755)
if err != nil {
panic(err)
}
hid.Write(transform.NewReader(os.Stdin, unicode.BOMOverride(unicode.UTF8.NewDecoder())))
hid.Hidg0 = file
defer file.Close()
// if err != nil {
// panic(err)
// }
hid.Write(os.Stdin)
if err != nil {
panic(err)
}
fmt.Println("Success!")
}

View File

@ -62,7 +62,7 @@ var (
"RSUPER": RSUPER,
"NONE": NONE,
}
Hidg0 io.WriteCloser
Hidg0 io.Writer
)
func (k Keyboard) Write(p []byte) (n int, err error) {
@ -71,9 +71,6 @@ func (k Keyboard) Write(p []byte) (n int, err error) {
func Write(r io.Reader) error {
_, err := io.Copy(Keyboard{}, r)
if closeCheck, ok := r.(io.Closer); ok {
closeCheck.Close()
}
return err
}
@ -99,37 +96,37 @@ func write(p []byte) (n int, err error) {
}
cur, ok := CurrentKeymap()[string(r)]
if !ok {
if i == 2 {
if i == 2 { // can't press two keys from different keymaps
if !changeKeymap(r) && ErrOnUnknownKey {
return index, fmt.Errorf("rune not in keymap: %c", r)
}
} else {
break press // I should make a temp var to hold this Usage id to reduce unneeded processing
break
}
}
// Check if this is a delay
if cur.DelayDelimiter {
index += s + parseDelay(p[index:])
break press // I should make a temp var to hold this Usage id to reduce unneeded processing
break
}
// Calculate next modifier byte
for _, v := range cur.Modifier {
mod = mod | flags[v]
}
// Set the modifier if it is the firs key otherwise
// Set the modifier if it is the first key otherwise
// check if the next modifier byte is the same
if i == 2 {
flag = mod
} else if flag != mod {
break press // I should make a temp var to hold this Usage id to reduce unneeded processing
break
}
// Check for duplicate key press. You can't press a key if it is already pressed.
for u := 2; u < i; u++ {
if cur.Decimal == report[u] {
break press // I should make a temp var to hold this Usage id to reduce unneeded processing
break press
}
}
report[i] = cur.Decimal