]> Pileus Git - ~andy/gtk/blob - gdk/directfb/gdktestutils-directfb.c
Fix compilation with DirectFB 1.0
[~andy/gtk] / gdk / directfb / gdktestutils-directfb.c
1 /* Gtk+ testing utilities
2  * Copyright (C) 2007 Imendio AB
3  * Authors: Tim Janik
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 /*
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>
27  */
28 #include "config.h"
29
30 #include <unistd.h>
31
32 #include "gdk.h"
33 #include "gdkdirectfb.h"
34 #include "gdkprivate-directfb.h"
35
36 #include <gdk/gdktestutils.h>
37 #include <gdk/gdkkeysyms.h>
38 #include "gdkalias.h"
39
40
41 static DFBInputDeviceKeySymbol
42 _gdk_keyval_to_directfb (guint keyval)
43 {
44   switch (keyval) {
45     case 0 ... 127:
46       return DFB_KEY( UNICODE, keyval );
47     case GDK_F1 ... GDK_F12:
48       return keyval - GDK_F1 + DIKS_F1;
49     case GDK_BackSpace:
50       return DIKS_BACKSPACE;
51     case GDK_Tab:
52       return DIKS_TAB;
53     case GDK_Return:
54       return DIKS_RETURN;
55     case GDK_Escape:
56       return DIKS_ESCAPE;
57     case GDK_Delete:
58       return DIKS_DELETE; 
59     case GDK_Left:
60       return DIKS_CURSOR_LEFT;
61     case GDK_Up:
62       return DIKS_CURSOR_UP;
63     case GDK_Right:
64       return DIKS_CURSOR_RIGHT;
65     case GDK_Down:
66       return DIKS_CURSOR_DOWN;
67     case GDK_Insert:
68       return DIKS_INSERT;
69     case GDK_Home:
70       return DIKS_HOME;
71     case GDK_End:
72       return DIKS_END;
73     case GDK_Page_Up:
74       return DIKS_PAGE_UP;
75     case GDK_Page_Down:
76       return DIKS_PAGE_DOWN;
77     case GDK_Print:
78       return DIKS_PRINT;
79     case GDK_Pause:
80       return DIKS_PAUSE;
81     case GDK_Clear:
82       return DIKS_CLEAR;
83     case GDK_Cancel:
84       return DIKS_CANCEL;
85       /* TODO: handle them all */
86     default:
87       break;
88   }
89
90   return DIKS_NULL;
91 }
92
93 static DFBInputDeviceModifierMask
94 _gdk_modifiers_to_directfb (GdkModifierType modifiers)
95 {
96   DFBInputDeviceModifierMask dfb_modifiers = 0;
97   
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;
106
107   return dfb_modifiers;
108 }
109
110 /**
111  * gdk_test_render_sync
112  * @window: a mapped GdkWindow
113  *
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.
118  **/
119 void
120 gdk_test_render_sync (GdkWindow *window)
121 {
122   _gdk_display->directfb->WaitIdle (_gdk_display->directfb);    
123 }
124
125 /**
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
133  *
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.
148  *
149  * Returns: wether all actions neccessary for a key event simulation were carried out successfully.
150  **/
151 gboolean
152 gdk_test_simulate_key (GdkWindow      *window,
153                        gint            x,
154                        gint            y,
155                        guint           keyval,
156                        GdkModifierType modifiers,
157                        GdkEventType    key_pressrelease)
158 {
159   GdkWindowObject       *private;
160   GdkWindowImplDirectFB *impl;
161   DFBWindowEvent         evt; 
162
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);
166   
167   private = GDK_WINDOW_OBJECT (window);
168   impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
169
170   if (x >= 0 && y >= 0) {
171     int win_x, win_y;
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))
174       return FALSE;
175   }
176  
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;
181 #endif
182   evt.window_id  = impl->dfb_id;
183   evt.x          = MAX(x, 0);
184   evt.y          = MAX(y, 0);
185   _gdk_display->layer->GetCursorPosition (_gdk_display->layer, &evt.cx, &evt.cy);
186   evt.key_code   = -1;
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);
191
192   _gdk_display->buffer->PostEvent (_gdk_display->buffer, DFB_EVENT(&evt));
193
194   return TRUE;
195 }
196
197 /**
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
205  *
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
212  * recommended.
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.
217  *
218  * Returns: wether all actions neccessary for a button event simulation were carried out successfully.
219  **/
220 gboolean
221 gdk_test_simulate_button (GdkWindow      *window,
222                           gint            x,
223                           gint            y,
224                           guint           button, /*1..3*/
225                           GdkModifierType modifiers,
226                           GdkEventType    button_pressrelease)
227 {
228   GdkWindowObject       *private;
229   GdkWindowImplDirectFB *impl;
230   DFBWindowEvent         evt;  
231   
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);
235   
236   private = GDK_WINDOW_OBJECT (window);
237   impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
238
239   if (x >= 0 && y >= 0) {
240     int win_x, win_y;
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))
243       return FALSE;
244   }
245
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;
250 #endif
251   evt.window_id  = impl->dfb_id;
252   evt.x          = MAX(x, 0);
253   evt.y          = MAX(y, 0); 
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;
257   evt.button     = button;
258   evt.buttons    = 0;
259   gettimeofday (&evt.timestamp, NULL);
260
261   _gdk_display->buffer->PostEvent (_gdk_display->buffer, DFB_EVENT(&evt));
262
263   return TRUE;
264 }
265
266 #define __GDK_TEST_UTILS_X11_C__
267 #include "gdkaliasdef.c"