[gtk+/broadway: 220/246] broadway: Implement pointer query_status



commit 0cefd54122367c9f4b5a67a4d6c518f0b7700e1d
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Mar 11 14:56:31 2011 +0100

    broadway: Implement pointer query_status

 gdk/broadway/broadway.c            |   18 ++++++++
 gdk/broadway/broadway.h            |    2 +
 gdk/broadway/broadway.js           |   23 ++++++++-
 gdk/broadway/gdkdevice-broadway.c  |   85 +++++++++++++++++++++++++++++++++---
 gdk/broadway/gdkdisplay-broadway.h |    2 +-
 gdk/broadway/gdkeventsource.c      |    5 ++-
 6 files changed, 123 insertions(+), 12 deletions(-)
---
diff --git a/gdk/broadway/broadway.c b/gdk/broadway/broadway.c
index 40a93b4..b393879 100644
--- a/gdk/broadway/broadway.c
+++ b/gdk/broadway/broadway.c
@@ -643,6 +643,24 @@ broadway_output_copy_rectangles (BroadwayOutput *output,  int id,
   free (buf);
 }
 
+guint32
+broadway_output_query_pointer (BroadwayOutput *output, int id)
+{
+  char buf[HEADER_LEN + 3];
+  guint32 serial;
+  int p;
+
+  serial = output->serial;
+  p = write_header (output, buf, 'q');
+  append_uint16 (id, buf, &p);
+
+  assert (p == sizeof (buf));
+
+  broadway_output_write (output, buf, sizeof (buf));
+
+  return serial;
+}
+
 void
 broadway_output_new_surface(BroadwayOutput *output,  int id, int x, int y, int w, int h)
 {
diff --git a/gdk/broadway/broadway.h b/gdk/broadway/broadway.h
index 8c8589e..b0d3c2a 100644
--- a/gdk/broadway/broadway.h
+++ b/gdk/broadway/broadway.h
@@ -55,3 +55,5 @@ void            broadway_output_copy_rectangles (BroadwayOutput *output,
 						 int             n_rects,
 						 int             dx,
 						 int             dy);
+guint32         broadway_output_query_pointer   (BroadwayOutput *output,
+						 int id);
diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js
index c0f17f7..08c0fcb 100644
--- a/gdk/broadway/broadway.js
+++ b/gdk/broadway/broadway.js
@@ -64,6 +64,8 @@ function createXHR()
 }
 
 var last_serial = 0;
+var last_x = 0;
+var last_y = 0;
 var surfaces = {};
 var outstanding_commands = new Array();
 var input_socket = null;
@@ -240,6 +242,13 @@ function handleCommands(cmd_obj)
 	context.restore();
         break;
 
+      case 'q': // Query pointer
+        var id = base64_16(cmd, i);
+        i = i + 3;
+
+	send_input ("q", [last_x, last_y]);
+	break;
+
       default:
         alert("Unknown op " + command);
     }
@@ -284,16 +293,24 @@ function send_input(cmd, args)
   }
 }
 
+function update_positions_from_event(ev) {
+    last_x = ev.pageX;
+    last_y = ev.pageY;
+}
+
 function on_mouse_move (ev) {
-  send_input ("m", [get_surface_id(ev), ev.pageX, ev.pageY, ev.timeStamp])
+  update_positions_from_event(ev);
+  send_input ("m", [get_surface_id(ev), last_x, last_y, ev.timeStamp]);
 }
 
 function on_mouse_down (ev) {
-  send_input ("b", [get_surface_id(ev), ev.pageX, ev.pageY, ev.button, ev.timeStamp])
+  update_positions_from_event(ev);
+  send_input ("b", [get_surface_id(ev), last_x, last_y, ev.button, ev.timeStamp]);
 }
 
 function on_mouse_up (ev) {
-  send_input ("B", [get_surface_id(ev), ev.pageX, ev.pageY, ev.button, ev.timeStamp])
+  update_positions_from_event(ev);
+  send_input ("B", [get_surface_id(ev), last_x, last_y, ev.button, ev.timeStamp]);
 }
 
 var last_key_down = 0;
diff --git a/gdk/broadway/gdkdevice-broadway.c b/gdk/broadway/gdkdevice-broadway.c
index 0d0aaa9..b222d68 100644
--- a/gdk/broadway/gdkdevice-broadway.c
+++ b/gdk/broadway/gdkdevice-broadway.c
@@ -18,6 +18,7 @@
  */
 
 #include "config.h"
+#include <stdlib.h>
 
 #include "gdkdevice-broadway.h"
 
@@ -152,17 +153,87 @@ gdk_broadway_device_query_state (GdkDevice        *device,
 				 gint             *win_y,
 				 GdkModifierType  *mask)
 {
+  GdkDisplay *display;
+  GdkBroadwayDisplay *broadway_display;
+  GdkWindowImplBroadway *impl;
+  guint32 serial;
+  GdkScreen *screen;
+  char *reply;
+  gint device_root_x, device_root_y;
+
+  if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
+    return FALSE;
+
+  display = gdk_device_get_display (device);
+  broadway_display = GDK_BROADWAY_DISPLAY (display);
+
+  if (root_window)
+    {
+      screen = gdk_window_get_screen (window);
+      *root_window = gdk_screen_get_root_window (screen);
+    }
+
+  if (mask)
+    *mask = 0; /* TODO */
+
+  device_root_x = broadway_display->last_x;
+  device_root_y = broadway_display->last_y;
+
+  if (broadway_display->output)
+    {
+      impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
+
+      serial = broadway_output_query_pointer (broadway_display->output, impl->id);
+
+      reply = _gdk_broadway_display_block_for_input (display, 'q', serial);
+
+      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 , */
+
+	  g_free (reply);
+	}
+    }
+
+  /* Fallback when unconnected */
+
   if (root_x)
-    *root_x = 0;
+    *root_x = device_root_x;
   if (root_y)
-    *root_y = 0;
+    *root_y = device_root_y;
   if (win_x)
-    *win_x = 0;
+    *win_x = device_root_y - window->x;
   if (win_y)
-    *win_y = 0;
-  if (mask)
-    *mask = 0;
-  return FALSE;
+    *win_y = device_root_y - window->y;
+  if (child_window)
+    {
+      if (gdk_window_get_window_type (window) == GDK_WINDOW_ROOT)
+	{
+	  *child_window = broadway_display->mouse_in_toplevel;
+	  if (*child_window == NULL)
+	    *child_window = window;
+	}
+      else
+	{
+	  /* No native children */
+	  *child_window = window;
+	}
+    }
+
+  return TRUE;
 }
 
 static GdkGrabStatus
diff --git a/gdk/broadway/gdkdisplay-broadway.h b/gdk/broadway/gdkdisplay-broadway.h
index 76df17a..a7a07a5 100644
--- a/gdk/broadway/gdkdisplay-broadway.h
+++ b/gdk/broadway/gdkdisplay-broadway.h
@@ -56,7 +56,7 @@ struct _GdkBroadwayDisplay
 
   GSource *event_source;
   GdkWindow *mouse_in_toplevel;
-  int last_x, last_y;
+  int last_x, last_y; /* in root coords */
 
   /* Keyboard related information */
   GdkKeymap *keymap;
diff --git a/gdk/broadway/gdkeventsource.c b/gdk/broadway/gdkeventsource.c
index 8a6912c..78c51ee 100644
--- a/gdk/broadway/gdkeventsource.c
+++ b/gdk/broadway/gdkeventsource.c
@@ -284,8 +284,11 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
       }
 
     break;
+  case 'q':
+    g_printerr ("Got unexpected query pointer reply w serial %d\n", serial);
+    break;
   default:
-    g_print ("Unknown input command %s\n", message);
+    g_printerr ("Unknown input command %s\n", message);
     break;
   }
 }



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