Add options for configuring pointer and scroll speed
This commit is contained in:
parent
fecec13869
commit
98f4d1c692
2 changed files with 35 additions and 13 deletions
13
main.go
13
main.go
|
|
@ -49,6 +49,13 @@ const (
|
||||||
prettyAppName string = "Remote Touchpad"
|
prettyAppName string = "Remote Touchpad"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type config struct {
|
||||||
|
ScrollSpeed float64 `json:"scrollSpeed"`
|
||||||
|
MoveSpeed float64 `json:"moveSpeed"`
|
||||||
|
MouseScrollSpeed float64 `json:"mouseScrollSpeed"`
|
||||||
|
MouseMoveSpeed float64 `json:"mouseMoveSpeed"`
|
||||||
|
}
|
||||||
|
|
||||||
func processCommand(backend Backend, command string) error {
|
func processCommand(backend Backend, command string) error {
|
||||||
if len(command) == 0 {
|
if len(command) == 0 {
|
||||||
return errors.New("empty command")
|
return errors.New("empty command")
|
||||||
|
|
@ -146,11 +153,16 @@ func main() {
|
||||||
TerminalSetTitle(prettyAppName)
|
TerminalSetTitle(prettyAppName)
|
||||||
var bind, certFile, keyFile, secret string
|
var bind, certFile, keyFile, secret string
|
||||||
var showVersion bool
|
var showVersion bool
|
||||||
|
var config config
|
||||||
flag.BoolVar(&showVersion, "version", false, "show program's version number and exit")
|
flag.BoolVar(&showVersion, "version", false, "show program's version number and exit")
|
||||||
flag.StringVar(&bind, "bind", defaultBind, "bind server to [HOSTNAME]:PORT")
|
flag.StringVar(&bind, "bind", defaultBind, "bind server to [HOSTNAME]:PORT")
|
||||||
flag.StringVar(&secret, "secret", "", "shared secret for client authentication")
|
flag.StringVar(&secret, "secret", "", "shared secret for client authentication")
|
||||||
flag.StringVar(&certFile, "cert", "", "file containing TLS certificate")
|
flag.StringVar(&certFile, "cert", "", "file containing TLS certificate")
|
||||||
flag.StringVar(&keyFile, "key", "", "file containing TLS private key")
|
flag.StringVar(&keyFile, "key", "", "file containing TLS private key")
|
||||||
|
flag.Float64Var(&config.MoveSpeed, "move-speed", 1, "move speed multiplier")
|
||||||
|
flag.Float64Var(&config.ScrollSpeed, "scroll-speed", 1, "scroll speed multiplier")
|
||||||
|
flag.Float64Var(&config.MouseMoveSpeed, "mouse-move-speed", 1, "mouse move speed multiplier")
|
||||||
|
flag.Float64Var(&config.MouseScrollSpeed, "mouse-scroll-speed", 1, "mouse scroll speed multiplier")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if showVersion {
|
if showVersion {
|
||||||
fmt.Println(version)
|
fmt.Println(version)
|
||||||
|
|
@ -219,6 +231,7 @@ func main() {
|
||||||
if !challenge.verify(message) {
|
if !challenge.verify(message) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
websocket.JSON.Send(ws, config)
|
||||||
for {
|
for {
|
||||||
if err := websocket.Message.Receive(ws, &message); err != nil {
|
if err := websocket.Message.Receive(ws, &message); err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,8 @@ var KEY_BACK_SPACE = 15;
|
||||||
var KEY_DELETE = 16;
|
var KEY_DELETE = 16;
|
||||||
var KEY_RETURN = 17;
|
var KEY_RETURN = 17;
|
||||||
|
|
||||||
var ws;
|
var ws = null;
|
||||||
|
var config = null;
|
||||||
|
|
||||||
var touchMoved = false;
|
var touchMoved = false;
|
||||||
var touchStart = 0;
|
var touchStart = 0;
|
||||||
|
|
@ -312,9 +313,9 @@ function handleTouchmove(evt) {
|
||||||
}
|
}
|
||||||
if (touchMoved && evt.timeStamp - touchLastEnd >= TOUCH_TIMEOUT) {
|
if (touchMoved && evt.timeStamp - touchLastEnd >= TOUCH_TIMEOUT) {
|
||||||
if (ongoingTouches.length == 1 || dragging) {
|
if (ongoingTouches.length == 1 || dragging) {
|
||||||
updateMove(sumX, sumY);
|
updateMove(sumX*config.moveSpeed, sumY*config.moveSpeed);
|
||||||
} else if (ongoingTouches.length == 2) {
|
} else if (ongoingTouches.length == 2) {
|
||||||
updateScroll(-sumX, -sumY, false);
|
updateScroll(-sumX*config.scrollSpeed, -sumY*config.scrollSpeed, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -375,14 +376,14 @@ function handleMouseup(evt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMousemove(evt) {
|
function handleMousemove(evt) {
|
||||||
updateMove(evt.movementX, evt.movementY);
|
updateMove(evt.movementX*config.mouseMoveSpeed, evt.movementY*config.mouseMoveSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleWheel(evt) {
|
function handleWheel(evt) {
|
||||||
if (evt.deltaMode == WheelEvent.DOM_DELTA_PIXEL) {
|
if (evt.deltaMode == WheelEvent.DOM_DELTA_PIXEL) {
|
||||||
updateScroll(evt.deltaX, evt.deltaY, true);
|
updateScroll(evt.deltaX*config.mouseScrollSpeed, evt.deltaY*config.mouseScrollSpeed, true);
|
||||||
} else if (evt.deltaMode == WheelEvent.DOM_DELTA_LINE) {
|
} else if (evt.deltaMode == WheelEvent.DOM_DELTA_LINE) {
|
||||||
updateScroll(evt.deltaX*20, evt.deltaY*20, true);
|
updateScroll(evt.deltaX*20*config.mouseScrollSpeed, evt.deltaY*20*config.mouseScrollSpeed, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -398,7 +399,7 @@ window.addEventListener("load", function() {
|
||||||
"": 0,
|
"": 0,
|
||||||
"keyboard": 1
|
"keyboard": 1
|
||||||
};
|
};
|
||||||
var authenticated = false;
|
var ready = false;
|
||||||
var scenes = document.querySelectorAll("body > .scene");
|
var scenes = document.querySelectorAll("body > .scene");
|
||||||
var opening = document.getElementById("opening");
|
var opening = document.getElementById("opening");
|
||||||
var closed = document.getElementById("closed");
|
var closed = document.getElementById("closed");
|
||||||
|
|
@ -468,18 +469,26 @@ window.addEventListener("load", function() {
|
||||||
wsURL.protocol = wsURL.protocol == "http:" ? "ws:" : "wss:";
|
wsURL.protocol = wsURL.protocol == "http:" ? "ws:" : "wss:";
|
||||||
ws = new WebSocket(wsURL);
|
ws = new WebSocket(wsURL);
|
||||||
|
|
||||||
|
var authenticated = false;
|
||||||
ws.onmessage = function(evt) {
|
ws.onmessage = function(evt) {
|
||||||
if (authenticated) {
|
if (!authenticated) {
|
||||||
|
ws.send(challengeResponse(evt.data));
|
||||||
|
authenticated = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
config = JSON.parse(evt.data);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
ws.close();
|
ws.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ws.send(challengeResponse(evt.data));
|
ready = true;
|
||||||
authenticated = true;
|
|
||||||
window.onpopstate();
|
window.onpopstate();
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = function() {
|
ws.onclose = function() {
|
||||||
authenticated = false;
|
ready = false;
|
||||||
showScene(closed);
|
showScene(closed);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -544,7 +553,7 @@ window.addEventListener("load", function() {
|
||||||
history.back();
|
history.back();
|
||||||
});
|
});
|
||||||
window.onpopstate = function() {
|
window.onpopstate = function() {
|
||||||
if (authenticated) {
|
if (ready) {
|
||||||
if (pointerLockElement()) {
|
if (pointerLockElement()) {
|
||||||
showScene(mouse);
|
showScene(mouse);
|
||||||
} else if ((history.state || "").split(":")[0] == "keys") {
|
} else if ((history.state || "").split(":")[0] == "keys") {
|
||||||
|
|
@ -574,7 +583,7 @@ window.addEventListener("load", function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
addPointerlockchangeEventListener(function() {
|
addPointerlockchangeEventListener(function() {
|
||||||
if (pointerLockElement() && !authenticated) {
|
if (pointerLockElement() && !ready) {
|
||||||
exitPointerLock();
|
exitPointerLock();
|
||||||
}
|
}
|
||||||
window.onpopstate();
|
window.onpopstate();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue