[gtk+] [broadway] Parse broadway input messages earlier



commit 8aad17592e957af068a70dfb2553303adecdf24a
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Apr 1 15:08:28 2011 +0200

    [broadway] Parse broadway input messages earlier
    
    We now parse the broadway messages as soon as they are read from the wire.
    This will let us sanely do lookahead in the message queue later.

 gdk/broadway/broadway.js           |   39 +++++---
 gdk/broadway/gdkdevice-broadway.c  |   53 ++--------
 gdk/broadway/gdkdisplay-broadway.c |  108 ++++++++++++++++++--
 gdk/broadway/gdkdisplay-broadway.h |   61 +++++++++++
 gdk/broadway/gdkeventsource.c      |  200 ++++++++++++------------------------
 gdk/broadway/gdkprivate-broadway.h |   10 +-
 6 files changed, 264 insertions(+), 207 deletions(-)
---
diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js
index 4886bde..686464b 100644
--- a/gdk/broadway/broadway.js
+++ b/gdk/broadway/broadway.js
@@ -85,6 +85,7 @@ var lastSerial = 0;
 var lastX = 0;
 var lastY = 0;
 var lastState;
+var lastTimeStamp = 0;
 var realWindowWithMouse = 0;
 var windowWithMouse = 0;
 var surfaces = {};
@@ -433,7 +434,7 @@ function getSurfaceId(ev) {
 function sendInput(cmd, args)
 {
     if (inputSocket != null) {
-	inputSocket.send(cmd + ([lastSerial].concat(args)).join(","));
+	inputSocket.send(cmd + ([lastSerial, lastTimeStamp].concat(args)).join(","));
     }
 }
 
@@ -487,32 +488,39 @@ function getEffectiveEventTarget (id) {
     return id;
 }
 
+function updateForEvent(ev) {
+    lastTimeStamp = ev.timeStamp;
+}
+
 function onMouseMove (ev) {
+    updateForEvent(ev);
     var id = getSurfaceId(ev);
     id = getEffectiveEventTarget (id);
     var pos = getPositionsFromEvent(ev, id);
-    sendInput ("m", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, ev.timeStamp]);
+    sendInput ("m", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState]);
 }
 
 function onMouseOver (ev) {
+    updateForEvent(ev);
     var id = getSurfaceId(ev);
     realWindowWithMouse = id;
     id = getEffectiveEventTarget (id);
     var pos = getPositionsFromEvent(ev, id);
     windowWithMouse = id;
     if (windowWithMouse != 0) {
-	sendInput ("e", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, ev.timeStamp, GDK_CROSSING_NORMAL]);
+	sendInput ("e", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_NORMAL]);
     }
 }
 
 function onMouseOut (ev) {
+    updateForEvent(ev);
     var id = getSurfaceId(ev);
     var origId = id;
     id = getEffectiveEventTarget (id);
     var pos = getPositionsFromEvent(ev, id);
 
     if (id != 0) {
-	sendInput ("l", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, ev.timeStamp, GDK_CROSSING_NORMAL]);
+	sendInput ("l", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_NORMAL]);
     }
     realWindowWithMouse = 0;
     windowWithMouse = 0;
@@ -524,10 +532,10 @@ function doGrab(id, ownerEvents, time, implicit) {
     if (windowWithMouse != id) {
 	if (windowWithMouse != 0) {
 	    pos = getPositionsFromAbsCoord(lastX, lastY, windowWithMouse);
-	    sendInput ("l", [windowWithMouse, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, time, GDK_CROSSING_GRAB]);
+	    sendInput ("l", [windowWithMouse, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_GRAB]);
 	}
 	pos = getPositionsFromAbsCoord(lastX, lastY, id);
-	sendInput ("e", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, time, GDK_CROSSING_GRAB]);
+	sendInput ("e", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_GRAB]);
 	windowWithMouse = id;
     }
 
@@ -542,11 +550,11 @@ function doUngrab(time) {
     if (realWindowWithMouse != windowWithMouse) {
 	if (windowWithMouse != 0) {
 	    pos = getPositionsFromAbsCoord(lastX, lastY, windowWithMouse);
-	    sendInput ("l", [windowWithMouse, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, time, GDK_CROSSING_UNGRAB]);
+	    sendInput ("l", [windowWithMouse, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_UNGRAB]);
 	}
 	if (realWindowWithMouse != 0) {
 	    pos = getPositionsFromAbsCoord(lastX, lastY, realWindowWithMouse);
-	    sendInput ("e", [realWindowWithMouse, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, time, GDK_CROSSING_UNGRAB]);
+	    sendInput ("e", [realWindowWithMouse, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_UNGRAB]);
 	}
 	windowWithMouse = realWindowWithMouse;
     }
@@ -554,6 +562,7 @@ function doUngrab(time) {
 }
 
 function onMouseDown (ev) {
+    updateForEvent(ev);
     var id = getSurfaceId(ev);
     id = getEffectiveEventTarget (id);
     var pos = getPositionsFromEvent(ev, id);
@@ -561,16 +570,17 @@ function onMouseDown (ev) {
 	doGrab (id, false, ev.timeStamp, true);
     var button = ev.button + 1;
     lastState = lastState | getButtonMask (button);
-    sendInput ("b", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, ev.timeStamp, button]);
+    sendInput ("b", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, button]);
 }
 
 function onMouseUp (ev) {
+    updateForEvent(ev);
     var id = getSurfaceId(ev);
     id = getEffectiveEventTarget (id);
     var pos = getPositionsFromEvent(ev, id);
     var button = ev.button + 1;
     lastState = lastState & ~getButtonMask (button);
-    sendInput ("B", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, ev.timeStamp, button]);
+    sendInput ("B", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, button]);
 
     if (grab.window != null && grab.implicit)
 	doUngrab(ev.timeStamp);
@@ -578,16 +588,18 @@ function onMouseUp (ev) {
 
 var lastKeyDown = 0;
 function onKeyDown (ev) {
+    updateForEvent(ev);
     var keyCode = ev.keyCode;
     if (keyCode != lastKeyDown) {
-	sendInput ("k", [keyCode, ev.timeStamp]);
+	sendInput ("k", [keyCode]);
 	lastKeyDown = keyCode;
     }
 }
 
 function onKeyUp (ev) {
+    updateForEvent(ev);
     var keyCode = ev.keyCode;
-    sendInput ("K", [keyCode, ev.timeStamp]);
+    sendInput ("K", [keyCode]);
     lastKeyDown = 0;
 }
 
@@ -606,6 +618,7 @@ function cancelEvent(ev)
 
 function onMouseWheel(ev)
 {
+    updateForEvent(ev);
     ev = ev ? ev : window.event;
 
     var id = getSurfaceId(ev);
@@ -615,7 +628,7 @@ function onMouseWheel(ev)
     var dir = 0;
     if (offset > 0)
 	dir = 1;
-    sendInput ("s", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, ev.timeStamp, dir]);
+    sendInput ("s", [id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, dir]);
 
     return cancelEvent(ev);
 }
diff --git a/gdk/broadway/gdkdevice-broadway.c b/gdk/broadway/gdkdevice-broadway.c
index 8c4679d..b99241f 100644
--- a/gdk/broadway/gdkdevice-broadway.c
+++ b/gdk/broadway/gdkdevice-broadway.c
@@ -158,8 +158,8 @@ gdk_broadway_device_query_state (GdkDevice        *device,
   GdkWindowImplBroadway *impl;
   guint32 serial;
   GdkScreen *screen;
-  char *reply;
-  gint device_root_x, device_root_y, device_win_x, device_win_y, id;
+  BroadwayInputMsg *reply;
+  gint device_root_x, device_root_y;
 
   if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
     return FALSE;
@@ -186,38 +186,18 @@ gdk_broadway_device_query_state (GdkDevice        *device,
 
       if (reply != NULL)
 	{
-	  char *p;
-	  char cmd;
-	  guint32 reply_serial;
-
-	  p = reply;
-
-	  cmd = *p++;
-	  reply_serial = (guint32)strtol(p, &p, 10);
-	  p++; /* Skip , */
-
-	  device_root_x = strtol(p, &p, 10);
-	  p++; /* Skip , */
-	  device_root_y = strtol(p, &p, 10);
-	  p++; /* Skip , */
-	  device_win_x = strtol(p, &p, 10);
-	  p++; /* Skip , */
-	  device_win_y = strtol(p, &p, 10);
-	  p++; /* Skip , */
-	  id = strtol(p, &p, 10);
-
 	  if (root_x)
-	    *root_x = device_root_x;
+	    *root_x = reply->query_reply.root_x;
 	  if (root_y)
-	    *root_y = device_root_y;
+	    *root_y = reply->query_reply.root_y;
 	  if (win_x)
-	    *win_x = device_win_x;
+	    *win_x = reply->query_reply.win_x;
 	  if (win_y)
-	    *win_y = device_win_y;
+	    *win_y = reply->query_reply.win_y;
 	  if (child_window)
 	    {
 	      if (gdk_window_get_window_type (window) == GDK_WINDOW_ROOT)
-		*child_window = g_hash_table_lookup (broadway_display->id_ht, GINT_TO_POINTER (id));
+		*child_window = g_hash_table_lookup (broadway_display->id_ht, GINT_TO_POINTER (reply->query_reply.window_with_mouse));
 	      else
 		*child_window = window; /* No native children */
 	    }
@@ -270,7 +250,7 @@ gdk_broadway_device_grab (GdkDevice    *device,
   GdkBroadwayDisplay *broadway_display;
   GdkWindowImplBroadway *impl;
   guint32 serial;
-  char *reply;
+  BroadwayInputMsg *reply;
 
   display = gdk_device_get_display (device);
   broadway_display = GDK_BROADWAY_DISPLAY (display);
@@ -292,22 +272,7 @@ gdk_broadway_device_grab (GdkDevice    *device,
 						 impl->id, owner_events, time_);
 	  reply = _gdk_broadway_display_block_for_input (display, 'g', serial, FALSE);
 	  if (reply != NULL)
-	    {
-	      char *p;
-	      char cmd;
-	      guint32 reply_serial;
-	      int res;
-
-	      p = reply;
-
-	      cmd = *p++;
-	      reply_serial = (guint32)strtol(p, &p, 10);
-	      p++; /* Skip , */
-
-	      res = strtol(p, &p, 10);
-
-	      return res;
-	    }
+	    return reply->grab_reply.res;
 	}
 
       return GDK_GRAB_NOT_VIEWABLE;
diff --git a/gdk/broadway/gdkdisplay-broadway.c b/gdk/broadway/gdkdisplay-broadway.c
index 4651ed1..839f665 100644
--- a/gdk/broadway/gdkdisplay-broadway.c
+++ b/gdk/broadway/gdkdisplay-broadway.c
@@ -151,7 +151,7 @@ broadway_input_free (BroadwayInput *input)
 static void
 process_input_messages (GdkBroadwayDisplay *broadway_display)
 {
-  char *message;
+  BroadwayInputMsg *message;
 
   while (broadway_display->input_messages)
     {
@@ -165,11 +165,101 @@ process_input_messages (GdkBroadwayDisplay *broadway_display)
     }
 }
 
+static char *
+parse_pointer_data (char *p, BroadwayInputPointerMsg *data)
+{
+  data->id = strtol (p, &p, 10);
+  p++; /* Skip , */
+  data->root_x = strtol (p, &p, 10);
+  p++; /* Skip , */
+  data->root_y = strtol (p, &p, 10);
+  p++; /* Skip , */
+  data->win_x = strtol (p, &p, 10);
+  p++; /* Skip , */
+  data->win_y = strtol (p, &p, 10);
+  p++; /* Skip , */
+  data->state = strtol (p, &p, 10);
+
+  return p;
+}
+
+static void
+parse_input_message (BroadwayInput *input, const char *message)
+{
+  GdkBroadwayDisplay *broadway_display;
+  BroadwayInputMsg msg;
+  char *p;
+
+  broadway_display = GDK_BROADWAY_DISPLAY (input->display);
+
+  p = (char *)message;
+  msg.base.type = *p++;
+  msg.base.serial = (guint32)strtol (p, &p, 10);
+  p++; /* Skip , */
+  msg.base.time = strtol(p, &p, 10);
+  p++; /* Skip , */
+
+  switch (msg.base.type) {
+  case 'e': /* Enter */
+  case 'l': /* Leave */
+    p = parse_pointer_data (p, &msg.pointer);
+    p++; /* Skip , */
+    msg.crossing.mode = strtol(p, &p, 10);
+    break;
+
+  case 'm': /* Mouse move */
+    p = parse_pointer_data (p, &msg.pointer);
+    break;
+
+  case 'b':
+  case 'B':
+    p = parse_pointer_data (p, &msg.pointer);
+    p++; /* Skip , */
+    msg.button.button = strtol(p, &p, 10);
+    break;
+
+  case 's':
+    p = parse_pointer_data (p, &msg.pointer);
+    p++; /* Skip , */
+    msg.scroll.dir = strtol(p, &p, 10);
+    break;
+
+  case 'k':
+  case 'K':
+    msg.key.key = strtol(p, &p, 10);
+    break;
+
+  case 'g':
+  case 'u':
+    msg.grab_reply.res = strtol(p, &p, 10);
+    break;
+
+  case 'q':
+    msg.query_reply.root_x = strtol(p, &p, 10);
+    p++; /* Skip , */
+    msg.query_reply.root_y = strtol(p, &p, 10);
+    p++; /* Skip , */
+    msg.query_reply.win_x = strtol(p, &p, 10);
+    p++; /* Skip , */
+    msg.query_reply.win_y = strtol(p, &p, 10);
+    p++; /* Skip , */
+    msg.query_reply.window_with_mouse = strtol(p, &p, 10);
+
+    break;
+  default:
+    g_printerr ("Unknown input command %s\n", message);
+    break;
+  }
+
+  broadway_display->input_messages = g_list_append (broadway_display->input_messages, g_memdup (&msg, sizeof (msg)));
+
+}
+
 static void
 parse_input (BroadwayInput *input)
 {
   GdkBroadwayDisplay *broadway_display;
-  char *buf, *ptr, *message;
+  char *buf, *ptr;
   gsize len;
 
   broadway_display = GDK_BROADWAY_DISPLAY (input->display);
@@ -189,10 +279,10 @@ parse_input (BroadwayInput *input)
 
   while ((ptr = memchr (buf, 0xff, len)) != NULL)
     {
+      *ptr = 0;
       ptr++;
 
-      message = g_strndup (buf+1, (ptr-1) - (buf + 1));
-      broadway_display->input_messages = g_list_append (broadway_display->input_messages, message);
+      parse_input_message (input, buf + 1);
 
       len -= ptr - buf;
       buf = ptr;
@@ -260,13 +350,12 @@ process_input_idle_cb (GdkBroadwayDisplay *display)
 }
 
 /* Note: This may be called while handling a message (i.e. sorta recursively) */
-char *
+BroadwayInputMsg *
 _gdk_broadway_display_block_for_input (GdkDisplay *display, char op,
 				       guint32 serial, gboolean remove_message)
 {
   GdkBroadwayDisplay *broadway_display;
-  char *message;
-  guint32 msg_serial;
+  BroadwayInputMsg *message;
   gboolean queued_idle;
   gssize res;
   guint8 buffer[1024];
@@ -291,10 +380,9 @@ _gdk_broadway_display_block_for_input (GdkDisplay *display, char op,
       {
 	message = l->data;
 
-	if (message[0] == op)
+	if (message->base.type == op)
 	  {
-	    msg_serial = (guint32)strtol(message+1, NULL, 10);
-	    if (msg_serial == serial)
+	    if (message->base.serial == serial)
 	      {
 		if (remove_message)
 		  broadway_display->input_messages =
diff --git a/gdk/broadway/gdkdisplay-broadway.h b/gdk/broadway/gdkdisplay-broadway.h
index a7a07a5..5bf38d9 100644
--- a/gdk/broadway/gdkdisplay-broadway.h
+++ b/gdk/broadway/gdkdisplay-broadway.h
@@ -45,6 +45,67 @@ typedef struct BroadwayInput BroadwayInput;
 #define GDK_IS_BROADWAY_DISPLAY_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_BROADWAY_DISPLAY))
 #define GDK_BROADWAY_DISPLAY_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_BROADWAY_DISPLAY, GdkBroadwayDisplayClass))
 
+typedef struct {
+  char type;
+  guint32 serial;
+  guint64 time;
+} BroadwayInputBaseMsg;
+
+typedef struct {
+  BroadwayInputBaseMsg base;
+  guint32 id;
+  int root_x;
+  int root_y;
+  int win_x;
+  int win_y;
+  guint32 state;
+} BroadwayInputPointerMsg;
+
+typedef struct {
+  BroadwayInputPointerMsg pointer;
+  guint32 mode;
+} BroadwayInputCrossingMsg;
+
+typedef struct {
+  BroadwayInputPointerMsg pointer;
+  guint32 button;
+} BroadwayInputButtonMsg;
+
+typedef struct {
+  BroadwayInputPointerMsg pointer;
+  int dir;
+} BroadwayInputScrollMsg;
+
+typedef struct {
+  BroadwayInputBaseMsg base;
+  int key;
+} BroadwayInputKeyMsg;
+
+typedef struct {
+  BroadwayInputBaseMsg base;
+  int res;
+} BroadwayInputGrabReply;
+
+typedef struct {
+  BroadwayInputBaseMsg base;
+  int root_x;
+  int root_y;
+  int win_x;
+  int win_y;
+  guint32 window_with_mouse;
+} BroadwayInputQueryReply;
+
+typedef union {
+  BroadwayInputBaseMsg base;
+  BroadwayInputPointerMsg pointer;
+  BroadwayInputCrossingMsg crossing;
+  BroadwayInputButtonMsg button;
+  BroadwayInputScrollMsg scroll;
+  BroadwayInputKeyMsg key;
+  BroadwayInputGrabReply grab_reply;
+  BroadwayInputQueryReply query_reply;
+} BroadwayInputMsg;
+
 struct _GdkBroadwayDisplay
 {
   GdkDisplay parent_instance;
diff --git a/gdk/broadway/gdkeventsource.c b/gdk/broadway/gdkeventsource.c
index 7b9e188..1b64ec0 100644
--- a/gdk/broadway/gdkeventsource.c
+++ b/gdk/broadway/gdkeventsource.c
@@ -88,90 +88,43 @@ gdk_event_source_check (GSource *source)
   return retval;
 }
 
-typedef struct {
-  int id;
-  int root_x;
-  int root_y;
-  int win_x;
-  int win_y;
-  guint32 state;
-  guint64 time;
-} PointerData;
-
-static char *
-parse_pointer_data (char *p, PointerData *data)
-{
-  data->id = strtol (p, &p, 10);
-  p++; /* Skip , */
-  data->root_x = strtol (p, &p, 10);
-  p++; /* Skip , */
-  data->root_y = strtol (p, &p, 10);
-  p++; /* Skip , */
-  data->win_x = strtol (p, &p, 10);
-  p++; /* Skip , */
-  data->win_y = strtol (p, &p, 10);
-  p++; /* Skip , */
-  data->state = strtol (p, &p, 10);
-  p++; /* Skip , */
-  data->time = strtol(p, &p, 10);
-
-  return p;
-}
-
-
 void
 _gdk_broadway_events_got_input (GdkDisplay *display,
-				const char *message)
+				BroadwayInputMsg *message)
 {
   GdkBroadwayDisplay *display_broadway = GDK_BROADWAY_DISPLAY (display);
   GdkScreen *screen;
-  GdkWindow *root, *window;
-  char *p;
-  int button, dir, key, mode;
-  guint32 serial;
-  guint64 time;
+  GdkWindow *window;
   GdkEvent *event = NULL;
-  char cmd;
   GList *node;
-  PointerData data;
 
   screen = gdk_display_get_default_screen (display);
-  root = gdk_screen_get_root_window (screen);
 
-  p = (char *)message;
-  cmd = *p++;
-  serial = (guint32)strtol (p, &p, 10);
-  p++; /* Skip , */
-  switch (cmd) {
+  switch (message->base.type) {
   case 'e': /* Enter */
-    p = parse_pointer_data (p, &data);
-    p++; /* Skip , */
-    mode = strtol(p, &p, 10);
+    display_broadway->last_x = message->pointer.root_x;
+    display_broadway->last_y = message->pointer.root_y;
 
-    display_broadway->last_x = data.root_x;
-    display_broadway->last_y = data.root_y;
-
-    window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (data.id));
+    window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (message->pointer.id));
 
     /* TODO: Unset when it dies */
     display_broadway->mouse_in_toplevel = window;
-
     if (window)
       {
 	event = gdk_event_new (GDK_ENTER_NOTIFY);
 	event->crossing.window = g_object_ref (window);
-	event->crossing.time = data.time;
-	event->crossing.x = data.win_x;
-	event->crossing.y = data.win_y;
-	event->crossing.x_root = data.root_x;
-	event->crossing.y_root = data.root_y;
-	event->crossing.state = data.state;
-	event->crossing.mode = mode;
+	event->crossing.time = message->base.time;
+	event->crossing.x = message->pointer.win_x;
+	event->crossing.y = message->pointer.win_y;
+	event->crossing.x_root = message->pointer.root_x;
+	event->crossing.y_root = message->pointer.root_y;
+	event->crossing.state = message->pointer.state;
+	event->crossing.mode = message->crossing.mode;
 	event->crossing.detail = GDK_NOTIFY_ANCESTOR;
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, serial);
+	_gdk_windowing_got_event (display, node, event, message->base.serial);
 
 	event = gdk_event_new (GDK_FOCUS_CHANGE);
 	event->focus_change.window = g_object_ref (window);
@@ -179,37 +132,32 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, serial);
+	_gdk_windowing_got_event (display, node, event, message->base.serial);
       }
     break;
   case 'l': /* Leave */
-    p = parse_pointer_data (p, &data);
-    p++; /* Skip , */
-    mode = strtol(p, &p, 10);
-
-    display_broadway->last_x = data.root_x;
-    display_broadway->last_y = data.root_y;
+    display_broadway->last_x = message->pointer.root_x;
+    display_broadway->last_y = message->pointer.root_y;
 
-    window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (data.id));
+    window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (message->pointer.id));
 
     display_broadway->mouse_in_toplevel = NULL;
-
     if (window)
       {
 	event = gdk_event_new (GDK_LEAVE_NOTIFY);
 	event->crossing.window = g_object_ref (window);
-	event->crossing.time = data.time;
-	event->crossing.x = data.win_x;
-	event->crossing.y = data.win_y;
-	event->crossing.x_root = data.root_x;
-	event->crossing.y_root = data.root_y;
-	event->crossing.state = data.state;
-	event->crossing.mode = mode;
+	event->crossing.time = message->base.time;
+	event->crossing.x = message->pointer.win_x;
+	event->crossing.y = message->pointer.win_y;
+	event->crossing.x_root = message->pointer.root_x;
+	event->crossing.y_root = message->pointer.root_y;
+	event->crossing.state = message->pointer.state;
+	event->crossing.mode = message->crossing.mode;
 	event->crossing.detail = GDK_NOTIFY_ANCESTOR;
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, serial);
+	_gdk_windowing_got_event (display, node, event, message->base.serial);
 
 	event = gdk_event_new (GDK_FOCUS_CHANGE);
 	event->focus_change.window = g_object_ref (window);
@@ -217,119 +165,101 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, serial);
+	_gdk_windowing_got_event (display, node, event, message->base.serial);
       }
     break;
   case 'm': /* Mouse move */
-    p = parse_pointer_data (p, &data);
-
-    display_broadway->last_x = data.root_x;
-    display_broadway->last_y = data.root_y;
-
-    window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (data.id));
+    display_broadway->last_x = message->pointer.root_x;
+    display_broadway->last_y = message->pointer.root_y;
 
+    window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (message->pointer.id));
     if (window)
       {
 	event = gdk_event_new (GDK_MOTION_NOTIFY);
 	event->motion.window = g_object_ref (window);
-	event->motion.time = data.time;
-	event->motion.x = data.win_x;
-	event->motion.y = data.win_y;
-	event->motion.x_root = data.root_x;
-	event->motion.y_root = data.root_y;
-	event->motion.state = data.state;
+	event->motion.time = message->base.time;
+	event->motion.x = message->pointer.win_x;
+	event->motion.y = message->pointer.win_y;
+	event->motion.x_root = message->pointer.root_x;
+	event->motion.y_root = message->pointer.root_y;
+	event->motion.state = message->pointer.state;
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, serial);
+	_gdk_windowing_got_event (display, node, event, message->base.serial);
       }
 
     break;
   case 'b':
   case 'B':
-    p = parse_pointer_data (p, &data);
-    p++; /* Skip , */
-    button = strtol(p, &p, 10);
-    display_broadway->last_x = data.root_x;
-    display_broadway->last_y = data.root_y;
-
-    window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (data.id));
+    display_broadway->last_x = message->pointer.root_x;
+    display_broadway->last_y = message->pointer.root_y;
 
+    window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (message->pointer.id));
     if (window)
       {
-	event = gdk_event_new (cmd == 'b' ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE);
+	event = gdk_event_new (message->base.type == 'b' ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE);
 	event->button.window = g_object_ref (window);
-	event->button.time = data.time;
-	event->button.x = data.win_x;
-	event->button.y = data.win_y;
-	event->button.x_root = data.root_x;
-	event->button.y_root = data.root_y;
-	event->button.button = button;
-	event->button.state = data.state;
+	event->button.time = message->base.time;
+	event->button.x = message->pointer.win_x;
+	event->button.y = message->pointer.win_y;
+	event->button.x_root = message->pointer.root_x;
+	event->button.y_root = message->pointer.root_y;
+	event->button.button = message->button.button;
+	event->button.state = message->pointer.state;
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, serial);
+	_gdk_windowing_got_event (display, node, event, message->base.serial);
       }
 
     break;
   case 's':
-    p = parse_pointer_data (p, &data);
-    p++; /* Skip , */
-    dir = strtol(p, &p, 10);
-    display_broadway->last_x = data.root_x;
-    display_broadway->last_y = data.root_y;
-
-    window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (data.id));
+    display_broadway->last_x = message->pointer.root_x;
+    display_broadway->last_y = message->pointer.root_y;
 
+    window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (message->pointer.id));
     if (window)
       {
 	event = gdk_event_new (GDK_SCROLL);
 	event->scroll.window = g_object_ref (window);
-	event->scroll.time = data.time;
-	event->scroll.x = data.win_x;
-	event->scroll.y = data.win_y;
-	event->scroll.x_root = data.root_x;
-	event->scroll.y_root = data.root_y;
-	event->scroll.direction = dir == 0 ? GDK_SCROLL_UP : GDK_SCROLL_DOWN;
+	event->scroll.time = message->base.time;
+	event->scroll.x = message->pointer.win_x;
+	event->scroll.y = message->pointer.win_y;
+	event->scroll.x_root = message->pointer.root_x;
+	event->scroll.y_root = message->pointer.root_y;
+	event->scroll.direction = message->scroll.dir == 0 ? GDK_SCROLL_UP : GDK_SCROLL_DOWN;
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, serial);
+	_gdk_windowing_got_event (display, node, event, message->base.serial);
       }
 
     break;
   case 'k':
   case 'K':
-    key = strtol(p, &p, 10);
-    p++; /* Skip , */
-    time = strtol(p, &p, 10);
-
     window = display_broadway->mouse_in_toplevel;
 
     if (window)
       {
-	event = gdk_event_new (cmd == 'k' ? GDK_KEY_PRESS : GDK_KEY_RELEASE);
+	event = gdk_event_new (message->base.type == 'k' ? GDK_KEY_PRESS : GDK_KEY_RELEASE);
 	event->key.window = g_object_ref (window);
-	event->key.time = time;
-	event->key.keyval = key;
+	event->key.time = message->base.time;
+	event->key.keyval = message->key.key;
 	event->key.length = 0;
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, serial);
+	_gdk_windowing_got_event (display, node, event, message->base.serial);
       }
 
     break;
   case 'g':
   case 'u':
-    _gdk_display_device_grab_update (display, display->core_pointer, NULL, serial);
-    break;
-  case 'q':
-    g_printerr ("Got unexpected query pointer reply w serial %d\n", serial);
+    _gdk_display_device_grab_update (display, display->core_pointer, NULL, message->base.serial);
     break;
   default:
-    g_printerr ("Unknown input command %s\n", message);
+    g_printerr ("Unknown input command %c\n", message->base.type);
     break;
   }
 }
diff --git a/gdk/broadway/gdkprivate-broadway.h b/gdk/broadway/gdkprivate-broadway.h
index a442439..19f9acb 100644
--- a/gdk/broadway/gdkprivate-broadway.h
+++ b/gdk/broadway/gdkprivate-broadway.h
@@ -121,7 +121,7 @@ void _gdk_broadway_screen_query_visual_types (GdkScreen * screen,
 GList *_gdk_broadway_screen_list_visuals (GdkScreen *screen);
 
 void _gdk_broadway_events_got_input      (GdkDisplay *display,
-					  const char *message);
+					  BroadwayInputMsg *message);
 
 void _gdk_broadway_screen_init_root_window (GdkScreen *screen);
 void _gdk_broadway_screen_init_visuals (GdkScreen *screen);
@@ -187,10 +187,10 @@ gint _gdk_broadway_display_text_property_to_utf8_list (GdkDisplay    *display,
 gchar *_gdk_broadway_display_utf8_to_string_target (GdkDisplay  *display,
 						    const gchar *str);
 GdkKeymap* _gdk_broadway_display_get_keymap (GdkDisplay *display);
-char * _gdk_broadway_display_block_for_input (GdkDisplay *display,
-					      char op,
-					      guint32 serial,
-					      gboolean remove);
+BroadwayInputMsg * _gdk_broadway_display_block_for_input (GdkDisplay *display,
+							  char op,
+							  guint32 serial,
+							  gboolean remove);
 
 /* Window methods - testing */
 void     _gdk_broadway_window_sync_rendering    (GdkWindow       *window);



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