1 /* Gtk+ testing utilities
2 * Copyright (C) 2007 Imendio AB
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include "gdktestutils.h"
25 #include "gdkkeysyms.h"
26 #include "gdkprivate-x11.h"
31 _gdk_x11_window_sync_rendering (GdkWindow *window)
33 Display *display = GDK_WINDOW_XDISPLAY (window);
36 /* syncronize to X drawing queue, see:
37 * http://mail.gnome.org/archives/gtk-devel-list/2006-October/msg00103.html
39 ximage = XGetImage (display, DefaultRootWindow (display),
40 0, 0, 1, 1, AllPlanes, ZPixmap);
42 XDestroyImage (ximage);
46 _gdk_x11_window_simulate_key (GdkWindow *window,
50 GdkModifierType modifiers,
51 GdkEventType key_pressrelease)
54 GdkKeymapKey *keys = NULL;
62 g_return_val_if_fail (key_pressrelease == GDK_KEY_PRESS || key_pressrelease == GDK_KEY_RELEASE, FALSE);
63 g_return_val_if_fail (window != NULL, FALSE);
64 if (!GDK_WINDOW_IS_MAPPED (window))
67 screen = gdk_window_get_screen (window);
71 x = window->width / 2;
72 y = window->height / 2;
75 /* Convert to impl coordinates */
76 x = x + window->abs_x;
77 y = y + window->abs_y;
79 xev.type = key_pressrelease == GDK_KEY_PRESS ? KeyPress : KeyRelease;
80 xev.display = GDK_WINDOW_XDISPLAY (window);
81 xev.window = GDK_WINDOW_XID (window);
82 xev.root = RootWindow (xev.display, GDK_X11_SCREEN (screen)->screen_num);
89 xev.state = modifiers;
91 success = gdk_keymap_get_entries_for_keyval (gdk_keymap_get_for_display (gdk_window_get_display (window)), keyval, &keys, &n_keys);
92 success &= n_keys > 0;
96 for (i = 0; i < n_keys; i++)
97 if (keys[i].group == 0 && (keys[i].level == 0 || keys[i].level == 1))
99 xev.keycode = keys[i].keycode;
100 if (keys[i].level == 1)
102 /* Assume shift takes us to level 1 */
103 xev.state |= GDK_SHIFT_MASK;
107 if (i >= n_keys) /* no match for group==0 and level==0 or 1 */
108 xev.keycode = keys[0].keycode;
113 gdk_x11_display_error_trap_push (GDK_WINDOW_DISPLAY (window));
114 xev.same_screen = XTranslateCoordinates (xev.display, xev.window, xev.root,
115 xev.x, xev.y, &xev.x_root, &xev.y_root,
118 xev.subwindow = xev.window;
119 success &= xev.same_screen;
120 if (x >= 0 && y >= 0)
121 success &= 0 != XWarpPointer (xev.display, None, xev.window, 0, 0, 0, 0, xev.x, xev.y);
122 success &= 0 != XSendEvent (xev.display, xev.window, True, key_pressrelease == GDK_KEY_PRESS ? KeyPressMask : KeyReleaseMask, (XEvent*) &xev);
123 XSync (xev.display, False);
124 success &= 0 == gdk_x11_display_error_trap_pop (GDK_WINDOW_DISPLAY (window));
129 _gdk_x11_window_simulate_button (GdkWindow *window,
132 guint button, /*1..3*/
133 GdkModifierType modifiers,
134 GdkEventType button_pressrelease)
144 g_return_val_if_fail (button_pressrelease == GDK_BUTTON_PRESS || button_pressrelease == GDK_BUTTON_RELEASE, FALSE);
145 g_return_val_if_fail (window != NULL, FALSE);
147 if (!GDK_WINDOW_IS_MAPPED (window))
150 screen = gdk_window_get_screen (window);
154 x = window->width / 2;
155 y = window->height / 2;
158 /* Convert to impl coordinates */
159 x = x + window->abs_x;
160 y = y + window->abs_y;
162 xev.type = button_pressrelease == GDK_BUTTON_PRESS ? ButtonPress : ButtonRelease;
163 xev.display = GDK_WINDOW_XDISPLAY (window);
164 xev.window = GDK_WINDOW_XID (window);
165 xev.root = RootWindow (xev.display, GDK_X11_SCREEN (screen)->screen_num);
172 xev.state = modifiers;
174 gdk_x11_display_error_trap_push (GDK_WINDOW_DISPLAY (window));
175 xev.same_screen = XTranslateCoordinates (xev.display, xev.window, xev.root,
176 xev.x, xev.y, &xev.x_root, &xev.y_root,
179 xev.subwindow = xev.window;
180 success = xev.same_screen;
181 success &= 0 != XWarpPointer (xev.display, None, xev.window, 0, 0, 0, 0, xev.x, xev.y);
182 success &= 0 != XSendEvent (xev.display, xev.window, True, button_pressrelease == GDK_BUTTON_PRESS ? ButtonPressMask : ButtonReleaseMask, (XEvent*) &xev);
183 XSync (xev.display, False);
184 success &= 0 == gdk_x11_display_error_trap_pop(GDK_WINDOW_DISPLAY (window));