]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdktestutils-x11.c
gdk: Rename GdkWindowObject to GdkWindow
[~andy/gtk] / gdk / x11 / gdktestutils-x11.c
index e1fdfa90553c8a9fb5538992c3d98d99de5aa559..960301b1e3ab4b88577e1198540886b33bac10ab 100644 (file)
@@ -1,5 +1,6 @@
 /* Gtk+ testing utilities
- * Copyright (C) 2007 Tim Janik
+ * Copyright (C) 2007 Imendio AB
+ * Authors: Tim Janik
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
-#include <gdk/gdktestutils.h>
-#include <gdk/gdkkeysyms.h>
-#include <x11/gdkx.h>
-#include "gdkalias.h"
+
+#include "config.h"
+
+#include "gdktestutils.h"
+
+#include "gdkkeysyms.h"
+#include "gdkx.h"
 
 #include <X11/Xlib.h>
 
 /**
- * gdk_test_render_sync
- * @window: a mapped GdkWindow
+ * gdk_test_render_sync:
+ * @window: a mapped #GdkWindow
  *
- * This function retrives a pixel from @window to force the windowing
+ * This function retrieves a pixel from @window to force the windowing
  * system to carry out any pending rendering commands.
  * This function is intended to be used to syncronize with rendering
  * pipelines, to benchmark windowing system rendering operations.
+ *
+ * Since: 2.14
  **/
 void
 gdk_test_render_sync (GdkWindow *window)
 {
-  static GdkImage *p1image = NULL;
+  Display *display = GDK_WINDOW_XDISPLAY (window);
+  XImage *ximage;
+
   /* syncronize to X drawing queue, see:
    * http://mail.gnome.org/archives/gtk-devel-list/2006-October/msg00103.html
    */
-  p1image = gdk_drawable_copy_to_image (window, p1image, 0, 0, 0, 0, 1, 1);
+  ximage = XGetImage (display, DefaultRootWindow (display),
+                     0, 0, 1, 1, AllPlanes, ZPixmap);
+  if (ximage != NULL)
+    XDestroyImage (ximage);
 }
 
 /**
  * gdk_test_simulate_key
- * @window: Gdk window to simulate a key event for.
+ * @window: a #GdkWindow to simulate a key event for.
  * @x:      x coordinate within @window for the key event.
  * @y:      y coordinate within @window for the key event.
- * @keyval: A Gdk keyboard value.
+ * @keyval: A GDK keyboard value.
  * @modifiers: Keyboard modifiers the event is setup with.
  * @key_pressrelease: either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
  *
- * This function is intended to be used in Gtk+ test programs.
+ * This function is intended to be used in GTK+ test programs.
  * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
  * the given (@x,@y) corrdinates within @window and simulate a
  * key press or release event.
+ *
  * When the mouse pointer is warped to the target location, use
  * of this function outside of test programs that run in their
  * own virtual windowing system (e.g. Xvfb) is not recommended.
  * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
  * be warped and @window origin will be used as mouse pointer
  * location for the event.
+ *
  * Also, gtk_test_simulate_key() is a fairly low level function,
  * for most testing purposes, gtk_test_widget_send_key() is the
  * right function to call which will generate a key press event
  * followed by its accompanying key release event.
  *
- * Returns: wether all actions neccessary for a key event simulation were carried out successfully.
+ * Returns: whether all actions neccessary for a key event simulation 
+ *     were carried out successfully.
+ *
+ * Since: 2.14
  **/
 gboolean
 gdk_test_simulate_key (GdkWindow      *window,
@@ -89,15 +105,21 @@ gdk_test_simulate_key (GdkWindow      *window,
   g_return_val_if_fail (window != NULL, FALSE);
   if (!GDK_WINDOW_IS_MAPPED (window))
     return FALSE;
-  screen = gdk_colormap_get_screen (gdk_drawable_get_colormap (window));
+
+  screen = gdk_window_get_screen (window);
+
   if (x < 0 && y < 0)
     {
-      gdk_drawable_get_size (window, &x, &y);
-      x /= 2;
-      y /= 2;
+      x = window->width / 2;
+      y = window->height / 2;
     }
+
+  /* Convert to impl coordinates */
+  x = x + window->abs_x;
+  y = y + window->abs_y;
+
   xev.type = key_pressrelease == GDK_KEY_PRESS ? KeyPress : KeyRelease;
-  xev.display = GDK_DRAWABLE_XDISPLAY (window);
+  xev.display = GDK_WINDOW_XDISPLAY (window);
   xev.window = GDK_WINDOW_XID (window);
   xev.root = RootWindow (xev.display, GDK_SCREEN_XNUMBER (screen));
   xev.subwindow = 0;
@@ -108,7 +130,7 @@ gdk_test_simulate_key (GdkWindow      *window,
   xev.y_root = 0;
   xev.state = modifiers;
   xev.keycode = 0;
-  success = gdk_keymap_get_entries_for_keyval (gdk_keymap_get_for_display (gdk_drawable_get_display (window)), keyval, &keys, &n_keys);
+  success = gdk_keymap_get_entries_for_keyval (gdk_keymap_get_for_display (gdk_window_get_display (window)), keyval, &keys, &n_keys);
   success &= n_keys > 0;
   if (success)
     {
@@ -142,26 +164,30 @@ gdk_test_simulate_key (GdkWindow      *window,
 
 /**
  * gdk_test_simulate_button
- * @window: Gdk window to simulate a button event for.
+ * @window: a #GdkWindow to simulate a button event for.
  * @x:      x coordinate within @window for the button event.
  * @y:      y coordinate within @window for the button event.
  * @button: Number of the pointer button for the event, usually 1, 2 or 3.
  * @modifiers: Keyboard modifiers the event is setup with.
  * @button_pressrelease: either %GDK_BUTTON_PRESS or %GDK_BUTTON_RELEASE
  *
- * This function is intended to be used in Gtk+ test programs.
+ * This function is intended to be used in GTK+ test programs.
  * It will warp the mouse pointer to the given (@x,@y) corrdinates
  * within @window and simulate a button press or release event.
  * Because the mouse pointer needs to be warped to the target
  * location, use of this function outside of test programs that
  * run in their own virtual windowing system (e.g. Xvfb) is not
  * recommended.
+ *
  * Also, gtk_test_simulate_button() is a fairly low level function,
  * for most testing purposes, gtk_test_widget_click() is the right
  * function to call which will generate a button press event followed
  * by its accompanying button release event.
  *
- * Returns: wether all actions neccessary for a button event simulation were carried out successfully.
+ * Returns: whether all actions neccessary for a button event simulation 
+ *     were carried out successfully.
+ *
+ * Since: 2.14
  **/
 gboolean
 gdk_test_simulate_button (GdkWindow      *window,
@@ -177,19 +203,28 @@ gdk_test_simulate_button (GdkWindow      *window,
     0,  /* serial */
     1,  /* send_event */
   };
+  gboolean success;
+
   g_return_val_if_fail (button_pressrelease == GDK_BUTTON_PRESS || button_pressrelease == GDK_BUTTON_RELEASE, FALSE);
   g_return_val_if_fail (window != NULL, FALSE);
+
   if (!GDK_WINDOW_IS_MAPPED (window))
     return FALSE;
-  screen = gdk_colormap_get_screen (gdk_drawable_get_colormap (window));
+
+  screen = gdk_window_get_screen (window);
+
   if (x < 0 && y < 0)
     {
-      gdk_drawable_get_size (window, &x, &y);
-      x /= 2;
-      y /= 2;
+      x = window->width / 2;
+      y = window->height / 2;
     }
+
+  /* Convert to impl coordinates */
+  x = x + window->abs_x;
+  y = y + window->abs_y;
+
   xev.type = button_pressrelease == GDK_BUTTON_PRESS ? ButtonPress : ButtonRelease;
-  xev.display = GDK_DRAWABLE_XDISPLAY (window);
+  xev.display = GDK_WINDOW_XDISPLAY (window);
   xev.window = GDK_WINDOW_XID (window);
   xev.root = RootWindow (xev.display, GDK_SCREEN_XNUMBER (screen));
   xev.subwindow = 0;
@@ -206,13 +241,10 @@ gdk_test_simulate_button (GdkWindow      *window,
                                            &xev.subwindow);
   if (!xev.subwindow)
     xev.subwindow = xev.window;
-  gboolean success = xev.same_screen;
+  success = xev.same_screen;
   success &= 0 != XWarpPointer (xev.display, None, xev.window, 0, 0, 0, 0, xev.x, xev.y);
   success &= 0 != XSendEvent (xev.display, xev.window, True, button_pressrelease == GDK_BUTTON_PRESS ? ButtonPressMask : ButtonReleaseMask, (XEvent*) &xev);
   XSync (xev.display, False);
   success &= 0 == gdk_error_trap_pop();
   return success;
 }
-
-#define __GDK_TEST_UTILS_X11_C__
-#include "gdkaliasdef.c"