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.
22 * GTK+ DirectFB backend
23 * Copyright (C) 2001-2002 convergence integrated media GmbH
24 * Copyright (C) 2002-2004 convergence GmbH
25 * Written by Denis Oliver Kropp <dok@convergence.de> and
26 * Sven Neumann <sven@convergence.de>
33 #include "gdkdirectfb.h"
34 #include "gdkprivate-directfb.h"
36 #include <gdk/gdktestutils.h>
37 #include <gdk/gdkkeysyms.h>
41 static DFBInputDeviceKeySymbol
42 _gdk_keyval_to_directfb (guint keyval)
46 return DFB_KEY( UNICODE, keyval );
47 case GDK_F1 ... GDK_F12:
48 return keyval - GDK_F1 + DIKS_F1;
50 return DIKS_BACKSPACE;
60 return DIKS_CURSOR_LEFT;
62 return DIKS_CURSOR_UP;
64 return DIKS_CURSOR_RIGHT;
66 return DIKS_CURSOR_DOWN;
76 return DIKS_PAGE_DOWN;
85 /* TODO: handle them all */
93 static DFBInputDeviceModifierMask
94 _gdk_modifiers_to_directfb (GdkModifierType modifiers)
96 DFBInputDeviceModifierMask dfb_modifiers = 0;
98 if (modifiers & GDK_MOD1_MASK)
99 dfb_modifiers |= DIMM_ALT;
100 if (modifiers & GDK_MOD2_MASK)
101 dfb_modifiers |= DIMM_ALTGR;
102 if (modifiers & GDK_CONTROL_MASK)
103 dfb_modifiers |= DIMM_CONTROL;
104 if (modifiers & GDK_SHIFT_MASK)
105 dfb_modifiers |= DIMM_SHIFT;
107 return dfb_modifiers;
111 * gdk_test_render_sync
112 * @window: a mapped GdkWindow
114 * This function retrives a pixel from @window to force the windowing
115 * system to carry out any pending rendering commands.
116 * This function is intended to be used to syncronize with rendering
117 * pipelines, to benchmark windowing system rendering operations.
120 gdk_test_render_sync (GdkWindow *window)
122 _gdk_display->directfb->WaitIdle (_gdk_display->directfb);
126 * gdk_test_simulate_key
127 * @window: Gdk window to simulate a key event for.
128 * @x: x coordinate within @window for the key event.
129 * @y: y coordinate within @window for the key event.
130 * @keyval: A Gdk keyboard value.
131 * @modifiers: Keyboard modifiers the event is setup with.
132 * @key_pressrelease: either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
134 * This function is intended to be used in Gtk+ test programs.
135 * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
136 * the given (@x,@y) corrdinates within @window and simulate a
137 * key press or release event.
138 * When the mouse pointer is warped to the target location, use
139 * of this function outside of test programs that run in their
140 * own virtual windowing system (e.g. Xvfb) is not recommended.
141 * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
142 * be warped and @window origin will be used as mouse pointer
143 * location for the event.
144 * Also, gtk_test_simulate_key() is a fairly low level function,
145 * for most testing purposes, gtk_test_widget_send_key() is the
146 * right function to call which will generate a key press event
147 * followed by its accompanying key release event.
149 * Returns: wether all actions neccessary for a key event simulation were carried out successfully.
152 gdk_test_simulate_key (GdkWindow *window,
156 GdkModifierType modifiers,
157 GdkEventType key_pressrelease)
159 GdkWindowObject *private;
160 GdkWindowImplDirectFB *impl;
163 g_return_val_if_fail (GDK_IS_WINDOW(window), FALSE);
164 g_return_val_if_fail (key_pressrelease == GDK_KEY_PRESS ||
165 key_pressrelease == GDK_KEY_RELEASE, FALSE);
167 private = GDK_WINDOW_OBJECT (window);
168 impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
170 if (x >= 0 && y >= 0) {
172 impl->window->GetPosition (impl->window, &win_x, &win_y);
173 if (_gdk_display->layer->WarpCursor (_gdk_display->layer, win_x+x, win_y+y))
177 evt.clazz = DFEC_WINDOW;
178 evt.type = (key_pressrelease == GDK_KEY_PRESS) ? DWET_KEYDOWN : DWET_KEYUP;
179 #if ((DIRECTFB_MAJOR_VERSION > 1) || (DIRECTFB_MINOR_VERSION >= 2))
180 evt.flags = DWEF_NONE;
182 evt.window_id = impl->dfb_id;
185 _gdk_display->layer->GetCursorPosition (_gdk_display->layer, &evt.cx, &evt.cy);
187 evt.key_symbol = _gdk_keyval_to_directfb (keyval);
188 evt.modifiers = _gdk_modifiers_to_directfb (modifiers);
189 evt.locks = (modifiers & GDK_LOCK_MASK) ? DILS_CAPS : 0;
190 gettimeofday (&evt.timestamp, NULL);
192 _gdk_display->buffer->PostEvent (_gdk_display->buffer, DFB_EVENT(&evt));
198 * gdk_test_simulate_button
199 * @window: Gdk window to simulate a button event for.
200 * @x: x coordinate within @window for the button event.
201 * @y: y coordinate within @window for the button event.
202 * @button: Number of the pointer button for the event, usually 1, 2 or 3.
203 * @modifiers: Keyboard modifiers the event is setup with.
204 * @button_pressrelease: either %GDK_BUTTON_PRESS or %GDK_BUTTON_RELEASE
206 * This function is intended to be used in Gtk+ test programs.
207 * It will warp the mouse pointer to the given (@x,@y) corrdinates
208 * within @window and simulate a button press or release event.
209 * Because the mouse pointer needs to be warped to the target
210 * location, use of this function outside of test programs that
211 * run in their own virtual windowing system (e.g. Xvfb) is not
213 * Also, gtk_test_simulate_button() is a fairly low level function,
214 * for most testing purposes, gtk_test_widget_click() is the right
215 * function to call which will generate a button press event followed
216 * by its accompanying button release event.
218 * Returns: wether all actions neccessary for a button event simulation were carried out successfully.
221 gdk_test_simulate_button (GdkWindow *window,
224 guint button, /*1..3*/
225 GdkModifierType modifiers,
226 GdkEventType button_pressrelease)
228 GdkWindowObject *private;
229 GdkWindowImplDirectFB *impl;
232 g_return_val_if_fail (GDK_IS_WINDOW(window), FALSE);
233 g_return_val_if_fail (button_pressrelease == GDK_BUTTON_PRESS ||
234 button_pressrelease == GDK_BUTTON_RELEASE, FALSE);
236 private = GDK_WINDOW_OBJECT (window);
237 impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
239 if (x >= 0 && y >= 0) {
241 impl->window->GetPosition (impl->window, &win_x, &win_y);
242 if (_gdk_display->layer->WarpCursor (_gdk_display->layer, win_x+x, win_y+y))
246 evt.clazz = DFEC_WINDOW;
247 evt.type = (button_pressrelease == GDK_BUTTON_PRESS) ? DWET_BUTTONDOWN : DWET_BUTTONUP;
248 #if ((DIRECTFB_MAJOR_VERSION > 1) || (DIRECTFB_MINOR_VERSION >= 2))
249 evt.flags = DWEF_NONE;
251 evt.window_id = impl->dfb_id;
254 _gdk_display->layer->GetCursorPosition (_gdk_display->layer, &evt.cx, &evt.cy);
255 evt.modifiers = _gdk_modifiers_to_directfb (modifiers);
256 evt.locks = (modifiers & GDK_LOCK_MASK) ? DILS_CAPS : 0;
259 gettimeofday (&evt.timestamp, NULL);
261 _gdk_display->buffer->PostEvent (_gdk_display->buffer, DFB_EVENT(&evt));
266 #define __GDK_TEST_UTILS_X11_C__
267 #include "gdkaliasdef.c"