[gtk+] [broadway] Serialize event times



commit 095ccf9c11bc91b6a850bafd9cb94bb074218075
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Apr 7 19:12:51 2011 +0200

    [broadway] Serialize event times
    
    Event times come from the browser and may change weirdly when we reconnect
    with another browser, so we normalize these to be strictly increasing
    and with a 5 second gap for each reconnect.

 gdk/broadway/gdkdevice-broadway.c  |    2 +-
 gdk/broadway/gdkdisplay-broadway.c |   23 ++++++++++++++++++++++-
 gdk/broadway/gdkdisplay-broadway.h |    6 +-----
 gdk/broadway/gdkeventsource.c      |    2 --
 4 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/gdk/broadway/gdkdevice-broadway.c b/gdk/broadway/gdkdevice-broadway.c
index 11bfe53..6b514ea 100644
--- a/gdk/broadway/gdkdevice-broadway.c
+++ b/gdk/broadway/gdkdevice-broadway.c
@@ -263,7 +263,7 @@ gdk_broadway_device_grab (GdkDevice    *device,
 	return GDK_GRAB_ALREADY_GRABBED;
 
       if (time_ == 0)
-	time_ = broadway_display->last_event_time;
+	time_ = broadway_display->last_seen_time;
 
       broadway_display->pointer_grab_window = window;
       broadway_display->pointer_grab_owner_events = owner_events;
diff --git a/gdk/broadway/gdkdisplay-broadway.c b/gdk/broadway/gdkdisplay-broadway.c
index b39d4e1..17b876b 100644
--- a/gdk/broadway/gdkdisplay-broadway.c
+++ b/gdk/broadway/gdkdisplay-broadway.c
@@ -62,6 +62,7 @@ gdk_event_init (GdkDisplay *display)
   broadway_display = GDK_BROADWAY_DISPLAY (display);
   broadway_display->event_source = _gdk_broadway_event_source_new (display);
   broadway_display->saved_serial = 1;
+  broadway_display->last_seen_time = 1;
 }
 
 static void
@@ -137,6 +138,8 @@ struct BroadwayInput {
   GSocketConnection *connection;
   GByteArray *buffer;
   GSource *source;
+  gboolean seen_time;
+  gint64 time_base;
 };
 
 static void
@@ -200,6 +203,7 @@ parse_input_message (BroadwayInput *input, const char *message)
   GdkBroadwayDisplay *broadway_display;
   BroadwayInputMsg msg;
   char *p;
+  gint64 time_;
 
   broadway_display = GDK_BROADWAY_DISPLAY (input->display);
 
@@ -207,9 +211,26 @@ parse_input_message (BroadwayInput *input, const char *message)
   msg.base.type = *p++;
   msg.base.serial = (guint32)strtol (p, &p, 10);
   p++; /* Skip , */
-  msg.base.time = strtol(p, &p, 10);
+  time_ = strtol(p, &p, 10);
   p++; /* Skip , */
 
+  if (time_ == 0) {
+    time_ = broadway_display->last_seen_time;
+  } else {
+    if (!input->seen_time) {
+      input->seen_time = TRUE;
+      /* Calculate time base so that any following times are normalized to start
+	 5 seconds after last_seen_time, to avoid issues that could appear when
+	 a long hiatus due to a reconnect seems to be instant */
+      input->time_base = time_ - (broadway_display->last_seen_time + 5000);
+    } 
+    time_ = time_ - input->time_base;
+  }
+
+  broadway_display->last_seen_time = time_;
+
+  msg.base.time = time_;
+
   switch (msg.base.type) {
   case 'e': /* Enter */
   case 'l': /* Leave */
diff --git a/gdk/broadway/gdkdisplay-broadway.h b/gdk/broadway/gdkdisplay-broadway.h
index 029e88d..433c9b4 100644
--- a/gdk/broadway/gdkdisplay-broadway.h
+++ b/gdk/broadway/gdkdisplay-broadway.h
@@ -150,21 +150,17 @@ struct _GdkBroadwayDisplay
   /* input GdkDevice list */
   GList *input_devices;
 
-  /* Time of most recent user interaction. */
-  gulong user_time;
-
   /* The offscreen window that has the pointer in it (if any) */
   GdkWindow *active_offscreen_window;
 
   GSocketService *service;
   BroadwayOutput *output;
   guint32 saved_serial;
+  guint64 last_seen_time;
   BroadwayInput *input;
   GList *input_messages;
   guint process_input_idle;
 
-  guint64 last_event_time;
-
   /* Explicit pointer grabs: */
   GdkWindow *pointer_grab_window;
   guint32 pointer_grab_time;
diff --git a/gdk/broadway/gdkeventsource.c b/gdk/broadway/gdkeventsource.c
index 6cefc47..a2864da 100644
--- a/gdk/broadway/gdkeventsource.c
+++ b/gdk/broadway/gdkeventsource.c
@@ -98,8 +98,6 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
   GdkEvent *event = NULL;
   GList *node;
 
-  display_broadway->last_event_time = message->base.time;
-
   switch (message->base.type) {
   case 'e': /* Enter */
     display_broadway->last_x = message->pointer.root_x;



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