2007-11-20 15:03:31 +00:00
|
|
|
/* Gtk+ testing utilities
|
2007-11-20 17:44:06 +00:00
|
|
|
* Copyright (C) 2007 Imendio AB
|
|
|
|
* Authors: Tim Janik
|
2007-11-20 15:03:31 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2010-10-15 02:05:51 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gdktestutils.h"
|
|
|
|
|
|
|
|
#include "gdkkeysyms.h"
|
2010-12-16 03:09:35 +00:00
|
|
|
#include "gdkprivate-x11.h"
|
2007-11-20 15:03:31 +00:00
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
|
|
|
void
|
2010-12-16 06:21:49 +00:00
|
|
|
_gdk_x11_window_sync_rendering (GdkWindow *window)
|
2007-11-20 15:03:31 +00:00
|
|
|
{
|
2010-10-05 23:05:19 +00:00
|
|
|
Display *display = GDK_WINDOW_XDISPLAY (window);
|
2010-07-13 21:28:20 +00:00
|
|
|
XImage *ximage;
|
|
|
|
|
2007-11-20 15:03:31 +00:00
|
|
|
/* syncronize to X drawing queue, see:
|
|
|
|
* http://mail.gnome.org/archives/gtk-devel-list/2006-October/msg00103.html
|
|
|
|
*/
|
2010-07-13 21:28:20 +00:00
|
|
|
ximage = XGetImage (display, DefaultRootWindow (display),
|
|
|
|
0, 0, 1, 1, AllPlanes, ZPixmap);
|
|
|
|
if (ximage != NULL)
|
|
|
|
XDestroyImage (ximage);
|
2007-11-20 15:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2010-12-16 06:21:49 +00:00
|
|
|
_gdk_x11_window_simulate_key (GdkWindow *window,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
guint keyval,
|
|
|
|
GdkModifierType modifiers,
|
|
|
|
GdkEventType key_pressrelease)
|
2007-11-20 15:03:31 +00:00
|
|
|
{
|
|
|
|
GdkScreen *screen;
|
|
|
|
GdkKeymapKey *keys = NULL;
|
|
|
|
gboolean success;
|
|
|
|
gint n_keys = 0;
|
|
|
|
XKeyEvent xev = {
|
|
|
|
0, /* type */
|
|
|
|
0, /* serial */
|
|
|
|
1, /* send_event */
|
|
|
|
};
|
|
|
|
g_return_val_if_fail (key_pressrelease == GDK_KEY_PRESS || key_pressrelease == GDK_KEY_RELEASE, FALSE);
|
|
|
|
g_return_val_if_fail (window != NULL, FALSE);
|
|
|
|
if (!GDK_WINDOW_IS_MAPPED (window))
|
|
|
|
return FALSE;
|
2010-09-20 10:52:26 +00:00
|
|
|
|
2010-08-28 23:53:58 +00:00
|
|
|
screen = gdk_window_get_screen (window);
|
2010-09-20 10:52:26 +00:00
|
|
|
|
2007-11-20 15:03:31 +00:00
|
|
|
if (x < 0 && y < 0)
|
|
|
|
{
|
2010-11-22 23:55:39 +00:00
|
|
|
x = window->width / 2;
|
|
|
|
y = window->height / 2;
|
2007-11-20 15:03:31 +00:00
|
|
|
}
|
2009-07-08 16:40:05 +00:00
|
|
|
|
|
|
|
/* Convert to impl coordinates */
|
2010-11-22 23:55:39 +00:00
|
|
|
x = x + window->abs_x;
|
|
|
|
y = y + window->abs_y;
|
2009-07-08 16:40:05 +00:00
|
|
|
|
2007-11-20 15:03:31 +00:00
|
|
|
xev.type = key_pressrelease == GDK_KEY_PRESS ? KeyPress : KeyRelease;
|
2010-10-05 23:22:45 +00:00
|
|
|
xev.display = GDK_WINDOW_XDISPLAY (window);
|
2007-11-20 15:03:31 +00:00
|
|
|
xev.window = GDK_WINDOW_XID (window);
|
2010-12-21 01:32:13 +00:00
|
|
|
xev.root = RootWindow (xev.display, GDK_X11_SCREEN (screen)->screen_num);
|
2007-11-20 15:03:31 +00:00
|
|
|
xev.subwindow = 0;
|
|
|
|
xev.time = 0;
|
|
|
|
xev.x = MAX (x, 0);
|
|
|
|
xev.y = MAX (y, 0);
|
|
|
|
xev.x_root = 0;
|
|
|
|
xev.y_root = 0;
|
|
|
|
xev.state = modifiers;
|
|
|
|
xev.keycode = 0;
|
2010-08-29 00:08:47 +00:00
|
|
|
success = gdk_keymap_get_entries_for_keyval (gdk_keymap_get_for_display (gdk_window_get_display (window)), keyval, &keys, &n_keys);
|
2007-11-20 15:03:31 +00:00
|
|
|
success &= n_keys > 0;
|
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
for (i = 0; i < n_keys; i++)
|
2011-02-01 22:07:21 +00:00
|
|
|
if (keys[i].group == 0 && (keys[i].level == 0 || keys[i].level == 1))
|
2007-11-20 15:03:31 +00:00
|
|
|
{
|
|
|
|
xev.keycode = keys[i].keycode;
|
2011-02-01 22:07:21 +00:00
|
|
|
if (keys[i].level == 1)
|
|
|
|
{
|
|
|
|
/* Assume shift takes us to level 1 */
|
|
|
|
xev.state |= GDK_SHIFT_MASK;
|
|
|
|
}
|
2007-11-20 15:03:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-02-01 22:07:21 +00:00
|
|
|
if (i >= n_keys) /* no match for group==0 and level==0 or 1 */
|
2007-11-20 15:03:31 +00:00
|
|
|
xev.keycode = keys[0].keycode;
|
|
|
|
}
|
|
|
|
g_free (keys);
|
|
|
|
if (!success)
|
|
|
|
return FALSE;
|
2010-12-15 07:05:05 +00:00
|
|
|
gdk_x11_display_error_trap_push (GDK_WINDOW_DISPLAY (window));
|
2007-11-20 15:03:31 +00:00
|
|
|
xev.same_screen = XTranslateCoordinates (xev.display, xev.window, xev.root,
|
|
|
|
xev.x, xev.y, &xev.x_root, &xev.y_root,
|
|
|
|
&xev.subwindow);
|
|
|
|
if (!xev.subwindow)
|
|
|
|
xev.subwindow = xev.window;
|
|
|
|
success &= xev.same_screen;
|
|
|
|
if (x >= 0 && y >= 0)
|
|
|
|
success &= 0 != XWarpPointer (xev.display, None, xev.window, 0, 0, 0, 0, xev.x, xev.y);
|
|
|
|
success &= 0 != XSendEvent (xev.display, xev.window, True, key_pressrelease == GDK_KEY_PRESS ? KeyPressMask : KeyReleaseMask, (XEvent*) &xev);
|
|
|
|
XSync (xev.display, False);
|
2010-12-15 07:05:05 +00:00
|
|
|
success &= 0 == gdk_x11_display_error_trap_pop (GDK_WINDOW_DISPLAY (window));
|
2007-11-20 15:03:31 +00:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2010-12-16 06:21:49 +00:00
|
|
|
_gdk_x11_window_simulate_button (GdkWindow *window,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
guint button, /*1..3*/
|
|
|
|
GdkModifierType modifiers,
|
|
|
|
GdkEventType button_pressrelease)
|
2007-11-20 15:03:31 +00:00
|
|
|
{
|
|
|
|
GdkScreen *screen;
|
|
|
|
XButtonEvent xev = {
|
|
|
|
0, /* type */
|
|
|
|
0, /* serial */
|
|
|
|
1, /* send_event */
|
|
|
|
};
|
2008-12-13 08:05:11 +00:00
|
|
|
gboolean success;
|
|
|
|
|
2007-11-20 15:03:31 +00:00
|
|
|
g_return_val_if_fail (button_pressrelease == GDK_BUTTON_PRESS || button_pressrelease == GDK_BUTTON_RELEASE, FALSE);
|
|
|
|
g_return_val_if_fail (window != NULL, FALSE);
|
2008-12-13 08:05:11 +00:00
|
|
|
|
2007-11-20 15:03:31 +00:00
|
|
|
if (!GDK_WINDOW_IS_MAPPED (window))
|
|
|
|
return FALSE;
|
2010-09-20 10:52:26 +00:00
|
|
|
|
2010-08-28 23:53:58 +00:00
|
|
|
screen = gdk_window_get_screen (window);
|
2010-09-20 10:52:26 +00:00
|
|
|
|
2007-11-20 15:03:31 +00:00
|
|
|
if (x < 0 && y < 0)
|
|
|
|
{
|
2010-11-22 23:55:39 +00:00
|
|
|
x = window->width / 2;
|
|
|
|
y = window->height / 2;
|
2007-11-20 15:03:31 +00:00
|
|
|
}
|
2009-07-08 16:40:05 +00:00
|
|
|
|
|
|
|
/* Convert to impl coordinates */
|
2010-11-22 23:55:39 +00:00
|
|
|
x = x + window->abs_x;
|
|
|
|
y = y + window->abs_y;
|
2009-07-08 16:40:05 +00:00
|
|
|
|
2007-11-20 15:03:31 +00:00
|
|
|
xev.type = button_pressrelease == GDK_BUTTON_PRESS ? ButtonPress : ButtonRelease;
|
2010-10-05 23:22:45 +00:00
|
|
|
xev.display = GDK_WINDOW_XDISPLAY (window);
|
2007-11-20 15:03:31 +00:00
|
|
|
xev.window = GDK_WINDOW_XID (window);
|
2010-12-21 01:32:13 +00:00
|
|
|
xev.root = RootWindow (xev.display, GDK_X11_SCREEN (screen)->screen_num);
|
2007-11-20 15:03:31 +00:00
|
|
|
xev.subwindow = 0;
|
|
|
|
xev.time = 0;
|
|
|
|
xev.x = x;
|
|
|
|
xev.y = y;
|
|
|
|
xev.x_root = 0;
|
|
|
|
xev.y_root = 0;
|
|
|
|
xev.state = modifiers;
|
|
|
|
xev.button = button;
|
2010-12-15 07:05:05 +00:00
|
|
|
gdk_x11_display_error_trap_push (GDK_WINDOW_DISPLAY (window));
|
2007-11-20 15:03:31 +00:00
|
|
|
xev.same_screen = XTranslateCoordinates (xev.display, xev.window, xev.root,
|
|
|
|
xev.x, xev.y, &xev.x_root, &xev.y_root,
|
|
|
|
&xev.subwindow);
|
|
|
|
if (!xev.subwindow)
|
|
|
|
xev.subwindow = xev.window;
|
2008-12-13 08:05:11 +00:00
|
|
|
success = xev.same_screen;
|
2007-11-20 15:03:31 +00:00
|
|
|
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);
|
2010-12-15 07:05:05 +00:00
|
|
|
success &= 0 == gdk_x11_display_error_trap_pop(GDK_WINDOW_DISPLAY (window));
|
2007-11-20 15:03:31 +00:00
|
|
|
return success;
|
|
|
|
}
|