[gtk+] broadway: Improve touch events



commit 67bcc6f04f4b1fb393790ea98957e581c6d253e9
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Nov 14 11:03:10 2013 +0100

    broadway: Improve touch events
    
    We now respect core pointer grabs, and we do the pointer emulation
    detection on the browser side.

 gdk/broadway/broadway-protocol.h   |    1 +
 gdk/broadway/broadway-server.c     |    9 ++++++-
 gdk/broadway/broadway-server.h     |    2 +
 gdk/broadway/broadway.js           |   44 +++++++++++++++++++++++++++++++-----
 gdk/broadway/gdkbroadway-server.c  |    2 -
 gdk/broadway/gdkdisplay-broadway.h |    2 -
 gdk/broadway/gdkeventsource.c      |   18 ++------------
 7 files changed, 52 insertions(+), 26 deletions(-)
---
diff --git a/gdk/broadway/broadway-protocol.h b/gdk/broadway/broadway-protocol.h
index db0c4f1..0e82e94 100644
--- a/gdk/broadway/broadway-protocol.h
+++ b/gdk/broadway/broadway-protocol.h
@@ -82,6 +82,7 @@ typedef struct {
   guint32 touch_type;
   guint32 event_window_id;
   guint32 sequence_id;
+  guint32 is_emulated;
   gint32 root_x;
   gint32 root_y;
   gint32 win_x;
diff --git a/gdk/broadway/broadway-server.c b/gdk/broadway/broadway-server.c
index 3b3baa8..fb2741e 100644
--- a/gdk/broadway/broadway-server.c
+++ b/gdk/broadway/broadway-server.c
@@ -238,7 +238,7 @@ update_event_state (BroadwayServer *server,
     server->real_mouse_in_toplevel_id = message->pointer.mouse_window_id;
     break;
   case BROADWAY_EVENT_TOUCH:
-    if (message->touch.touch_type == 0 &&
+    if (message->touch.touch_type == 0 && message->touch.is_emulated &&
         server->focused_window_id != message->touch.event_window_id)
       {
         broadway_server_window_raise (server, message->touch.event_window_id);
@@ -246,6 +246,12 @@ update_event_state (BroadwayServer *server,
         broadway_server_flush (server);
       }
 
+    if (message->touch.is_emulated)
+      {
+        server->last_x = message->pointer.root_x;
+        server->last_y = message->pointer.root_y;
+      }
+
     server->last_state = message->touch.state;
     break;
   case BROADWAY_EVENT_KEY_PRESS:
@@ -386,6 +392,7 @@ parse_touch_data (guint32 *p, BroadwayInputTouchMsg *data)
   data->touch_type = ntohl (*p++);
   data->event_window_id = ntohl (*p++);
   data->sequence_id = ntohl (*p++);
+  data->is_emulated = ntohl (*p++);
   data->root_x = ntohl (*p++);
   data->root_y = ntohl (*p++);
   data->win_x = ntohl (*p++);
diff --git a/gdk/broadway/broadway-server.h b/gdk/broadway/broadway-server.h
index c073c98..1021e44 100644
--- a/gdk/broadway/broadway-server.h
+++ b/gdk/broadway/broadway-server.h
@@ -46,6 +46,8 @@ guint32             broadway_server_grab_pointer             (BroadwayServer   *
 guint32             broadway_server_ungrab_pointer           (BroadwayServer   *server,
                                                              guint32           time_);
 gint32              broadway_server_get_mouse_toplevel       (BroadwayServer   *server);
+void                broadway_server_set_show_keyboard        (BroadwayServer   *server,
+                                                              gboolean          show);
 guint32             broadway_server_new_window               (BroadwayServer   *server,
                                                              int               x,
                                                              int               y,
diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js
index f8a9440..028555d 100644
--- a/gdk/broadway/broadway.js
+++ b/gdk/broadway/broadway.js
@@ -106,6 +106,7 @@ var debugDecoding = false;
 var fakeInput = null;
 var showKeyboard = false;
 var showKeyboardChanged = false;
+var firstTouchDownId = null;
 
 var GDK_CROSSING_NORMAL = 0;
 var GDK_CROSSING_GRAB = 1;
@@ -2488,10 +2489,28 @@ function onTouchStart(ev) {
     for (var i = 0; i < ev.changedTouches.length; i++) {
         var touch = ev.changedTouches.item(i);
 
-        var id = getSurfaceId(touch);
+        var origId = getSurfaceId(touch);
+        var id = getEffectiveEventTarget (origId);
         var pos = getPositionsFromEvent(touch, id);
+        var isEmulated = 0;
 
-        sendInput ("t", [0, id, touch.identifier, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState]);
+        if (firstTouchDownId == null) {
+            firstTouchDownId = touch.identifier;
+            isEmulated = 1;
+
+            if (realWindowWithMouse != origId || id != windowWithMouse) {
+                if (id != 0) {
+                    sendInput ("l", [realWindowWithMouse, id, pos.rootX, pos.rootY, pos.winX, pos.winY, 
lastState, GDK_CROSSING_NORMAL]);
+                }
+
+                windowWithMouse = id;
+                realWindowWithMouse = origId;
+
+                sendInput ("e", [origId, id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, 
GDK_CROSSING_NORMAL]);
+            }
+        }
+
+        sendInput ("t", [0, id, touch.identifier, isEmulated, pos.rootX, pos.rootY, pos.winX, pos.winY, 
lastState]);
     }
 }
 
@@ -2504,10 +2523,16 @@ function onTouchMove(ev) {
     for (var i = 0; i < ev.changedTouches.length; i++) {
         var touch = ev.changedTouches.item(i);
 
-        var id = getSurfaceId(touch);
+        var origId = getSurfaceId(touch);
+        var id = getEffectiveEventTarget (origId);
         var pos = getPositionsFromEvent(touch, id);
 
-        sendInput ("t", [1, id, touch.identifier, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState]);
+        var isEmulated = 0;
+        if (firstTouchDownId == touch.identifier) {
+            isEmulated = 1;
+        }
+
+        sendInput ("t", [1, id, touch.identifier, isEmulated, pos.rootX, pos.rootY, pos.winX, pos.winY, 
lastState]);
     }
 }
 
@@ -2520,10 +2545,17 @@ function onTouchEnd(ev) {
     for (var i = 0; i < ev.changedTouches.length; i++) {
         var touch = ev.changedTouches.item(i);
 
-        var id = getSurfaceId(touch);
+        var origId = getSurfaceId(touch);
+        var id = getEffectiveEventTarget (origId);
         var pos = getPositionsFromEvent(touch, id);
 
-        sendInput ("t", [2, id, touch.identifier, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState]);
+        var isEmulated = 0;
+        if (firstTouchDownId == touch.identifier) {
+            isEmulated = 1;
+            firstTouchDownId = null;
+        }
+
+        sendInput ("t", [2, id, touch.identifier, isEmulated, pos.rootX, pos.rootY, pos.winX, pos.winY, 
lastState]);
     }
 }
 
diff --git a/gdk/broadway/gdkbroadway-server.c b/gdk/broadway/gdkbroadway-server.c
index 6389c7f..55ab58b 100644
--- a/gdk/broadway/gdkbroadway-server.c
+++ b/gdk/broadway/gdkbroadway-server.c
@@ -804,6 +804,4 @@ _gdk_broadway_server_set_show_keyboard (GdkBroadwayServer *server,
   msg.show_keyboard = show;
   gdk_broadway_server_send_message (server, msg,
                                    BROADWAY_REQUEST_SET_SHOW_KEYBOARD);
-
-  return TRUE;
 }
diff --git a/gdk/broadway/gdkdisplay-broadway.h b/gdk/broadway/gdkdisplay-broadway.h
index 9066261..401ac6f 100644
--- a/gdk/broadway/gdkdisplay-broadway.h
+++ b/gdk/broadway/gdkdisplay-broadway.h
@@ -59,8 +59,6 @@ struct _GdkBroadwayDisplay
 
   GdkBroadwayServer *server;
 
-  guint32 touch_sequence_down;
-
   gpointer move_resize_data;
 };
 
diff --git a/gdk/broadway/gdkeventsource.c b/gdk/broadway/gdkeventsource.c
index bb2a19f..08dd073 100644
--- a/gdk/broadway/gdkeventsource.c
+++ b/gdk/broadway/gdkeventsource.c
@@ -214,7 +214,6 @@ _gdk_broadway_events_got_input (BroadwayInputMsg *message)
     if (window)
       {
         GdkEventType event_type = 0;
-        gboolean is_first_down = FALSE;
 
         switch (message->touch.touch_type) {
         case 0:
@@ -230,25 +229,14 @@ _gdk_broadway_events_got_input (BroadwayInputMsg *message)
           g_printerr ("_gdk_broadway_events_got_input - Unknown touch type %d\n", message->touch.touch_type);
         }
 
-        if (event_type == GDK_TOUCH_BEGIN &&
-            display_broadway->touch_sequence_down == 0)
-          display_broadway->touch_sequence_down = message->touch.sequence_id;
-
-        if (display_broadway->touch_sequence_down == message->touch.sequence_id)
-          is_first_down = TRUE;
-
-        if (event_type == GDK_TOUCH_END &&
-            display_broadway->touch_sequence_down == message->touch.sequence_id)
-          display_broadway->touch_sequence_down = 0;
-
         if (event_type != GDK_TOUCH_BEGIN &&
-            is_first_down && _gdk_broadway_moveresize_handle_event (display, message))
+            message->touch.is_emulated && _gdk_broadway_moveresize_handle_event (display, message))
           break;
 
        event = gdk_event_new (event_type);
        event->touch.window = g_object_ref (window);
        event->touch.sequence = GUINT_TO_POINTER(message->touch.sequence_id);
-       event->touch.emulating_pointer = is_first_down;
+       event->touch.emulating_pointer = message->touch.is_emulated;
        event->touch.time = message->base.time;
        event->touch.x = message->touch.win_x;
        event->touch.y = message->touch.win_y;
@@ -259,7 +247,7 @@ _gdk_broadway_events_got_input (BroadwayInputMsg *message)
        gdk_event_set_device (event, device_manager->core_pointer);
        gdk_event_set_source_device (event, device_manager->touchscreen);
 
-        if (is_first_down)
+        if (message->touch.is_emulated)
           _gdk_event_set_pointer_emulated (event, TRUE);
 
         if (event_type == GDK_TOUCH_BEGIN || event_type == GDK_TOUCH_UPDATE)


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