[gtk+/broadway: 22/71] Send mouse events from js



commit 1e3dffeee9cb2a9bccfbcebb5b4fe6df1e28b8a9
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Nov 19 20:21:20 2010 +0100

    Send mouse events from js

 gdk/broadway/broadway.js |   31 +++++++++++++++++++++++++++----
 1 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js
index 615f971..21561bb 100644
--- a/gdk/broadway/broadway.js
+++ b/gdk/broadway/broadway.js
@@ -66,6 +66,7 @@ function createXHR()
 
 var surfaces = {};
 var outstanding_commands = new Array();
+var input_socket = null;
 
 function apply_delta(id, img, x, y)
 {
@@ -102,6 +103,7 @@ function initContext(canvas, x, y)
   context.globalCompositeOperation = "copy"
   context.fillRect(0, 0, canvas.width, canvas.height);
   document.body.appendChild(canvas)
+
   return context
 }
 
@@ -284,17 +286,34 @@ function handleLoad(event)
     loc = loc.substr(0, loc.lastIndexOf('/')) + "/input";
     var ws = new WebSocket(loc, "broadway");
     ws.onopen = function() {
-      ws.send("Message to send1");
-      ws.send("Message to send2");
+      input_socket = ws;
     };
-    ws.onmessage = function (evt) { var msg = evt.data;
+    ws.onclose = function() {
+      input_socket = null;
     };
-    ws.onclose = function() { };
   } else {
      alert("WebSocket not supported, input will not work!");
   }
 }
 
+function on_mouse_move (ev) {
+  if (input_socket != null) {
+    input_socket.send("m" + ev.pageX + "," + ev.pageY);
+  }
+}
+
+function on_mouse_down (ev) {
+  if (input_socket != null) {
+    input_socket.send("b" + ev.pageX + "," + ev.pageY + "," + ev.button);
+  }
+}
+
+function on_mouse_up (ev) {
+  if (input_socket != null) {
+    input_socket.send("B" + ev.pageX + "," + ev.pageY + "," + ev.button);
+  }
+}
+
 function connect()
 {
   var xhr = createXHR();
@@ -309,4 +328,8 @@ function connect()
     xhr.onload = handleLoad;
     xhr.send(null);
   }
+
+  document.onmousemove = on_mouse_move;
+  document.onmousedown = on_mouse_down;
+  document.onmouseup = on_mouse_up;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]