summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-08-20 00:59:09 +0300
committerDevaev Maxim <[email protected]>2018-08-20 00:59:09 +0300
commit102b1b666d8a407b93e6af6d2d24282d0fba7fb7 (patch)
tree4afca1e3187109f3c357c1dce982176c853f63e1
parent49b83948c0a41bb807be716a866b02a5c4124833 (diff)
touch events as mouse - test
-rw-r--r--kvmd/web/js/mouse.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/kvmd/web/js/mouse.js b/kvmd/web/js/mouse.js
index 4be05c99..1ba1f850 100644
--- a/kvmd/web/js/mouse.js
+++ b/kvmd/web/js/mouse.js
@@ -21,6 +21,9 @@ function Mouse() {
$("stream-box").onmousemove = __moveHandler;
$("stream-box").onwheel = __wheelHandler;
+ $("stream-box").ontouchstart = (event) => __touchHandler(event, true);
+ $("stream-box").ontouchend = (event) => __touchHandler(event, false);
+
setInterval(__sendMove, 100);
};
@@ -55,6 +58,28 @@ function Mouse() {
self.updateLeds();
};
+ var __touchHandler = function(event, state) {
+ if (state) {
+ var rect = event.touches[0].target.getBoundingClientRect();
+ __current_pos = {
+ x: Math.round(event.touches[0].clientX - rect.left),
+ y: Math.round(event.touches[0].clientY - rect.top),
+ };
+ __sendMove();
+ }
+ var button = "left"; // TODO
+ tools.debug("Mouse button", (state ? "pressed:" : "released:"), button);
+ if (__ws) {
+ __ws.send(JSON.stringify({
+ event_type: "mouse_button",
+ button: button,
+ state: state,
+ }));
+ }
+ event.stopPropagation();
+ event.preventDefault();
+ };
+
var __buttonHandler = function(event, state) {
// https://www.w3schools.com/jsref/event_button.asp
var button = null;