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>
40 static DFBInputDeviceKeySymbol
41 _gdk_keyval_to_directfb (guint keyval)
45 return DFB_KEY( UNICODE, keyval );
46 case GDK_F1 ... GDK_F12:
47 return keyval - GDK_F1 + DIKS_F1;
49 return DIKS_BACKSPACE;
59 return DIKS_CURSOR_LEFT;
61 return DIKS_CURSOR_UP;
63 return DIKS_CURSOR_RIGHT;
65 return DIKS_CURSOR_DOWN;
75 return DIKS_PAGE_DOWN;
84 /* TODO: handle them all */
92 static DFBInputDeviceModifierMask
93 _gdk_modifiers_to_directfb (GdkModifierType modifiers)
95 DFBInputDeviceModifierMask dfb_modifiers = 0;
97 if (modifiers & GDK_MOD1_MASK)
98 dfb_modifiers |= DIMM_ALT;
99 if (modifiers & GDK_MOD2_MASK)
100 dfb_modifiers |= DIMM_ALTGR;
101 if (modifiers & GDK_CONTROL_MASK)
102 dfb_modifiers |= DIMM_CONTROL;
103 if (modifiers & GDK_SHIFT_MASK)
104 dfb_modifiers |= DIMM_SHIFT;
106 return dfb_modifiers;
110 * gdk_test_render_sync
111 * @window: a mapped GdkWindow
113 * This function retrives a pixel from @window to force the windowing
114 * system to carry out any pending rendering commands.
115 * This function is intended to be used to syncronize with rendering
116 * pipelines, to benchmark windowing system rendering operations.
119 gdk_test_render_sync (GdkWindow *window)
121 _gdk_display->directfb->WaitIdle (_gdk_display->directfb);
125 * gdk_test_simulate_key
126 * @window: Gdk window to simulate a key event for.
127 * @x: x coordinate within @window for the key event.
128 * @y: y coordinate within @window for the key event.
129 * @keyval: A Gdk keyboard value.
130 * @modifiers: Keyboard modifiers the event is setup with.
131 * @key_pressrelease: either %GDK_KEY_PRESS or %GDK_KEY_RELEASE
133 * This function is intended to be used in Gtk+ test programs.
134 * If (@x,@y) are > (-1,-1), it will warp the mouse pointer to
135 * the given (@x,@y) corrdinates within @window and simulate a
136 * key press or release event.
137 * When the mouse pointer is warped to the target location, use
138 * of this function outside of test programs that run in their
139 * own virtual windowing system (e.g. Xvfb) is not recommended.
140 * If (@x,@y) are passed as (-1,-1), the mouse pointer will not
141 * be warped and @window origin will be used as mouse pointer
142 * location for the event.
143 * Also, gtk_test_simulate_key() is a fairly low level function,
144 * for most testing purposes, gtk_test_widget_send_key() is the
145 * right function to call which will generate a key press event
146 * followed by its accompanying key release event.
148 * Returns: wether all actions neccessary for a key event simulation were carried out successfully.
151 gdk_test_simulate_key (GdkWindow *window,
155 GdkModifierType modifiers,
156 GdkEventType key_pressrelease)
158 GdkWindowObject *private;
159 GdkWindowImplDirectFB *impl;
162 g_return_val_if_fail (GDK_IS_WINDOW(window), FALSE);
163 g_return_val_if_fail (key_pressrelease == GDK_KEY_PRESS ||
164 key_pressrelease == GDK_KEY_RELEASE, FALSE);
166 private = GDK_WINDOW_OBJECT (window);
167 impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
169 if (x >= 0 && y >= 0) {
171 impl->window->GetPosition (impl->window, &win_x, &win_y);
172 if (_gdk_display->layer->WarpCursor (_gdk_display->layer, win_x+x, win_y+y))
176 evt.clazz = DFEC_WINDOW;
177 evt.type = (key_pressrelease == GDK_KEY_PRESS) ? DWET_KEYDOWN : DWET_KEYUP;
178 #if ((DIRECTFB_MAJOR_VERSION > 1) || (DIRECTFB_MINOR_VERSION >= 2))
179 evt.flags = DWEF_NONE;
181 evt.window_id = impl->dfb_id;
184 _gdk_display->layer->GetCursorPosition (_gdk_display->layer, &evt.cx, &evt.cy);
186 evt.key_symbol = _gdk_keyval_to_directfb (keyval);
187 evt.modifiers = _gdk_modifiers_to_directfb (modifiers);
188 evt.locks = (modifiers & GDK_LOCK_MASK) ? DILS_CAPS : 0;
189 gettimeofday (&evt.timestamp, NULL);
191 _gdk_display->buffer->PostEvent (_gdk_display->buffer, DFB_EVENT(&evt));
197 * gdk_test_simulate_button
198 * @window: Gdk window to simulate a button event for.
199 * @x: x coordinate within @window for the button event.
200 * @y: y coordinate within @window for the button event.
201 * @button: Number of the pointer button for the event, usually 1, 2 or 3.
202 * @modifiers: Keyboard modifiers the event is setup with.
203 * @button_pressrelease: either %GDK_BUTTON_PRESS or %GDK_BUTTON_RELEASE
205 * This function is intended to be used in Gtk+ test programs.
206 * It will warp the mouse pointer to the given (@x,@y) corrdinates
207 * within @window and simulate a button press or release event.
208 * Because the mouse pointer needs to be warped to the target
209 * location, use of this function outside of test programs that
210 * run in their own virtual windowing system (e.g. Xvfb) is not
212 * Also, gtk_test_simulate_button() is a fairly low level function,
213 * for most testing purposes, gtk_test_widget_click() is the right
214 * function to call which will generate a button press event followed
215 * by its accompanying button release event.
217 * Returns: wether all actions neccessary for a button event simulation were carried out successfully.
220 gdk_test_simulate_button (GdkWindow *window,
223 guint button, /*1..3*/
224 GdkModifierType modifiers,
225 GdkEventType button_pressrelease)
227 GdkWindowObject *private;
228 GdkWindowImplDirectFB *impl;
231 g_return_val_if_fail (GDK_IS_WINDOW(window), FALSE);
232 g_return_val_if_fail (button_pressrelease == GDK_BUTTON_PRESS ||
233 button_pressrelease == GDK_BUTTON_RELEASE, FALSE);
235 private = GDK_WINDOW_OBJECT (window);
236 impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
238 if (x >= 0 && y >= 0) {
240 impl->window->GetPosition (impl->window, &win_x, &win_y);
241 if (_gdk_display->layer->WarpCursor (_gdk_display->layer, win_x+x, win_y+y))
245 evt.clazz = DFEC_WINDOW;
246 evt.type = (button_pressrelease == GDK_BUTTON_PRESS) ? DWET_BUTTONDOWN : DWET_BUTTONUP;
247 #if ((DIRECTFB_MAJOR_VERSION > 1) || (DIRECTFB_MINOR_VERSION >= 2))
248 evt.flags = DWEF_NONE;
250 evt.window_id = impl->dfb_id;
253 _gdk_display->layer->GetCursorPosition (_gdk_display->layer, &evt.cx, &evt.cy);
254 evt.modifiers = _gdk_modifiers_to_directfb (modifiers);
255 evt.locks = (modifiers & GDK_LOCK_MASK) ? DILS_CAPS : 0;
258 gettimeofday (&evt.timestamp, NULL);
260 _gdk_display->buffer->PostEvent (_gdk_display->buffer, DFB_EVENT(&evt));