use shorter commands

This commit is contained in:
Unrud 2018-06-26 06:01:16 +02:00
parent 1c7a277328
commit b5ed8ee23b
3 changed files with 30 additions and 23 deletions

File diff suppressed because one or more lines are too long

25
main.go
View file

@ -35,6 +35,7 @@ import (
"strconv"
"strings"
"time"
"unicode/utf8"
)
const (
@ -47,29 +48,35 @@ const (
)
func processCommand(plugin Plugin, command string) error {
commandParts := strings.Split(command, " ")
if commandParts[0] == "KeyboardText" {
text := strings.Join(commandParts[1:], " ")
if len(command) == 0 {
return errors.New("empty command")
}
if command[0] == 't' {
text := command[1:]
if !utf8.ValidString(text) {
return errors.New("invalid utf-8")
}
return plugin.KeyboardText(text)
}
if len(commandParts) != 3 {
arguments := strings.Split(command[1:], ";")
if len(arguments) != 2 {
return errors.New("wrong number of arguments")
}
x, err := strconv.ParseInt(commandParts[1], 10, 32)
x, err := strconv.ParseInt(arguments[0], 10, 32)
if err != nil {
return err
}
y, err := strconv.ParseInt(commandParts[2], 10, 32)
y, err := strconv.ParseInt(arguments[1], 10, 32)
if err != nil {
return err
}
if commandParts[0] == "PointerMove" {
if command[0] == 'm' {
return plugin.PointerMove(int(x), int(y))
}
if commandParts[0] == "PointerScroll" {
if command[0] == 's' {
return plugin.PointerScroll(int(x), int(y))
}
if commandParts[0] == "PointerButton" {
if command[0] == 'b' {
if x <= 0 || x > 3 {
return errors.New("unknown pointer button")
}

View file

@ -141,7 +141,7 @@ function calculatePointerAccelerationMult(speed) {
function onDraggingTimeout() {
draggingTimeout = null;
ws.send("PointerButton 1 0");
ws.send("b1;0");
}
function updateMoveAndScroll() {
@ -161,7 +161,7 @@ function onUpdateTimeout() {
moveXSum -= moveX;
moveYSum -= moveY;
idleUpdates = 0;
ws.send("PointerMove " + moveX + " " + moveY);
ws.send("m" + moveX + ";" + moveY);
}
var scrollX = Math.trunc(scrollXSum);
var scrollY = Math.trunc(scrollYSum);
@ -169,7 +169,7 @@ function onUpdateTimeout() {
scrollXSum -= scrollX;
scrollYSum -= scrollY;
idleUpdates = 0;
ws.send("PointerScroll " + scrollX + " " + scrollY);
ws.send("s" + scrollX + ";" + scrollY);
}
if (idleUpdates >= MAX_IDLE_UPDATES) {
clearInterval(updateTimer);
@ -222,7 +222,7 @@ function handleEnd(evt) {
}
if (ongoingTouches.length == 0 && touchReleasedCount >= 1 &&
dragging) {
ws.send("PointerButton 1 0");
ws.send("b1;0");
}
if (ongoingTouches.length == 0 && touchReleasedCount >= 1 &&
!touchMoved && evt.timeStamp - touchStart < TOUCH_TIMEOUT) {
@ -234,11 +234,11 @@ function handleEnd(evt) {
}else if (touchReleasedCount == 3) {
button = 2;
}
ws.send("PointerButton " + button + " 1");
ws.send("b" + button + ";1");
if (button == 1) {
draggingTimeout = setTimeout(onDraggingTimeout, TOUCH_TIMEOUT);
} else {
ws.send("PointerButton " + button + " 0");
ws.send("b" + button + ";0");
}
}
}
@ -365,7 +365,7 @@ window.addEventListener("load", function() {
document.getElementById("sendbutton").addEventListener("click",
function(e) {
if (text.value != "") {
ws.send("KeyboardText " + text.value);
ws.send("t" + text.value);
text.value = "";
}
window.history.back();