2017-07-14 06:41:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/bendahl/uinput"
|
|
|
|
"github.com/gvalkov/golang-evdev"
|
|
|
|
)
|
|
|
|
|
|
|
|
var configFile = flag.String("config", filepath.Join(os.Getenv("HOME"), ".shuttle-go.json"), "Location to the .shuttle-go.json configuration")
|
2017-08-07 04:40:43 +00:00
|
|
|
var logFile = flag.String("log-file", "", "Log to a file instead of stdout")
|
2017-07-14 06:41:48 +00:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2017-08-07 04:40:43 +00:00
|
|
|
if *logFile != "" {
|
|
|
|
log, err := os.Create(*logFile)
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(101)
|
|
|
|
}
|
|
|
|
defer log.Close()
|
|
|
|
os.Stderr = log
|
|
|
|
os.Stdout = log
|
2017-07-14 06:41:48 +00:00
|
|
|
}
|
|
|
|
|
2017-08-07 04:40:43 +00:00
|
|
|
devicePath := "/dev/input/by-id/usb-Contour_Design_ShuttlePRO_v2-event-if00"
|
|
|
|
if len(flag.Args()) == 1 {
|
|
|
|
devicePath = flag.Arg(0)
|
|
|
|
}
|
|
|
|
fmt.Println("Using device", devicePath)
|
|
|
|
|
|
|
|
if err := LoadConfig(*configFile); err != nil {
|
2017-07-14 06:41:48 +00:00
|
|
|
fmt.Println("Error reading configuration:", err)
|
|
|
|
os.Exit(10)
|
|
|
|
}
|
|
|
|
|
2017-07-14 22:42:50 +00:00
|
|
|
go disableXInputPointer()
|
|
|
|
|
2017-07-14 06:41:48 +00:00
|
|
|
// X-window title change watcher
|
|
|
|
watcher := NewWindowWatcher()
|
|
|
|
if err := watcher.Setup(); err != nil {
|
|
|
|
fmt.Println("Error watching X window:", err)
|
|
|
|
os.Exit(3)
|
|
|
|
}
|
|
|
|
|
|
|
|
go watcher.Run()
|
|
|
|
|
|
|
|
// Virtual keyboard
|
2017-07-14 22:42:50 +00:00
|
|
|
vk, err := uinput.CreateKeyboard("/dev/uinput", []byte("Go Virtual Shuttle Pro V2"))
|
2017-07-14 06:41:48 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Println("Can't open dev:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shuttle device event receiver
|
2017-08-07 04:40:43 +00:00
|
|
|
dev, err := evdev.Open(devicePath)
|
2017-07-14 06:41:48 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Couldn't open Shuttle device:", err)
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("ready")
|
|
|
|
mapper := NewMapper(vk, dev)
|
2017-07-14 21:25:51 +00:00
|
|
|
mapper.watcher = watcher
|
2017-07-14 06:41:48 +00:00
|
|
|
for {
|
|
|
|
if err := mapper.Process(); err != nil {
|
|
|
|
fmt.Println("Error processing input events (continuing):", err)
|
2017-08-07 04:40:43 +00:00
|
|
|
os.Exit(123)
|
2017-07-14 06:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|