]> Pileus Git - ~andy/gtk/blob - gdk/directfb/gdkmain-directfb.c
gdk/directfb/gdkdirectfb.h gdk/directfb/gdkdisplay-directfb.c
[~andy/gtk] / gdk / directfb / gdkmain-directfb.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  * Copyright (C) 1998-1999 Tor Lillqvist
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  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
23  * file for a list of people on the GTK+ Team.
24  */
25
26 /*
27  * GTK+ DirectFB backend
28  * Copyright (C) 2001-2002  convergence integrated media GmbH
29  * Copyright (C) 2002-2004  convergence GmbH
30  * Written by Denis Oliver Kropp <dok@convergence.de> and
31  *            Sven Neumann <sven@convergence.de>
32  */
33
34 /*
35  Main entry point for 2.6 seems to be open_display so 
36  most stuff in main is moved over to gdkdisplay-directfb.c
37  I'll move stub functions here that make no sense for directfb
38  and true globals
39  Michael Emmel
40 */
41
42 #include <config.h>
43 #include <string.h> 
44 #include <stdlib.h> 
45 #include "gdk.h"
46
47 #include "gdkdisplay.h"
48 #include "gdkdirectfb.h"
49 #include "gdkprivate-directfb.h"
50
51 #include "gdkinternals.h"
52
53 #include "gdkinput-directfb.h"
54
55 #include "gdkintl.h"
56 #include "gdkalias.h"
57
58
59 void
60 _gdk_windowing_init (void)
61 {
62   /** 
63     Not that usable called before parse_args
64   **/
65 }
66
67 void
68 gdk_set_use_xshm (gboolean use_xshm)
69 {
70 }
71
72 gboolean
73 gdk_get_use_xshm (void)
74 {
75   return FALSE;
76 }
77
78 void
79 _gdk_windowing_display_set_sm_client_id (GdkDisplay *display,const gchar *sm_client_id)
80 {
81   g_message ("gdk_set_sm_client_id() is unimplemented.");
82 }
83
84
85 void
86 _gdk_windowing_exit (void)
87 {
88  
89   if (_gdk_display->buffer)
90     _gdk_display->buffer->Release (_gdk_display->buffer);
91
92   _gdk_directfb_keyboard_exit ();
93
94   if (_gdk_display->keyboard)
95     _gdk_display->keyboard->Release (_gdk_display->keyboard);
96
97   _gdk_display->layer->Release (_gdk_display->layer);
98
99    _gdk_display->directfb->Release (_gdk_display->directfb);
100
101   g_free (_gdk_display);
102   _gdk_display = NULL;
103 }
104
105 gchar *
106 gdk_get_display (void)
107 {
108   return g_strdup (gdk_display_get_name (gdk_display_get_default ()));
109 }
110
111
112 /* utils */
113 static const guint type_masks[] =
114 {
115   GDK_STRUCTURE_MASK,        /* GDK_DELETE            =  0, */
116   GDK_STRUCTURE_MASK,        /* GDK_DESTROY           =  1, */
117   GDK_EXPOSURE_MASK,         /* GDK_EXPOSE            =  2, */
118   GDK_POINTER_MOTION_MASK,   /* GDK_MOTION_NOTIFY     =  3, */
119   GDK_BUTTON_PRESS_MASK,     /* GDK_BUTTON_PRESS      =  4, */
120   GDK_BUTTON_PRESS_MASK,     /* GDK_2BUTTON_PRESS     =  5, */
121   GDK_BUTTON_PRESS_MASK,     /* GDK_3BUTTON_PRESS     =  6, */
122   GDK_BUTTON_RELEASE_MASK,   /* GDK_BUTTON_RELEASE    =  7, */
123   GDK_KEY_PRESS_MASK,        /* GDK_KEY_PRESS         =  8, */
124   GDK_KEY_RELEASE_MASK,      /* GDK_KEY_RELEASE       =  9, */
125   GDK_ENTER_NOTIFY_MASK,     /* GDK_ENTER_NOTIFY      = 10, */
126   GDK_LEAVE_NOTIFY_MASK,     /* GDK_LEAVE_NOTIFY      = 11, */
127   GDK_FOCUS_CHANGE_MASK,     /* GDK_FOCUS_CHANGE      = 12, */
128   GDK_STRUCTURE_MASK,        /* GDK_CONFIGURE         = 13, */
129   GDK_VISIBILITY_NOTIFY_MASK,/* GDK_MAP               = 14, */
130   GDK_VISIBILITY_NOTIFY_MASK,/* GDK_UNMAP             = 15, */
131   GDK_PROPERTY_CHANGE_MASK,  /* GDK_PROPERTY_NOTIFY   = 16, */
132   GDK_PROPERTY_CHANGE_MASK,  /* GDK_SELECTION_CLEAR   = 17, */
133   GDK_PROPERTY_CHANGE_MASK,  /* GDK_SELECTION_REQUEST = 18, */
134   GDK_PROPERTY_CHANGE_MASK,  /* GDK_SELECTION_NOTIFY  = 19, */
135   GDK_PROXIMITY_IN_MASK,     /* GDK_PROXIMITY_IN      = 20, */
136   GDK_PROXIMITY_OUT_MASK,    /* GDK_PROXIMITY_OUT     = 21, */
137   GDK_ALL_EVENTS_MASK,       /* GDK_DRAG_ENTER        = 22, */
138   GDK_ALL_EVENTS_MASK,       /* GDK_DRAG_LEAVE        = 23, */
139   GDK_ALL_EVENTS_MASK,       /* GDK_DRAG_MOTION       = 24, */
140   GDK_ALL_EVENTS_MASK,       /* GDK_DRAG_STATUS       = 25, */
141   GDK_ALL_EVENTS_MASK,       /* GDK_DROP_START        = 26, */
142   GDK_ALL_EVENTS_MASK,       /* GDK_DROP_FINISHED     = 27, */
143   GDK_ALL_EVENTS_MASK,       /* GDK_CLIENT_EVENT      = 28, */
144   GDK_VISIBILITY_NOTIFY_MASK,/* GDK_VISIBILITY_NOTIFY = 29, */
145   GDK_EXPOSURE_MASK,         /* GDK_NO_EXPOSE         = 30, */
146   GDK_SCROLL_MASK            /* GDK_SCROLL            = 31  */
147 };
148
149 GdkWindow *
150 gdk_directfb_other_event_window (GdkWindow    *window,
151                                  GdkEventType  type)
152 {
153   guint32    evmask;
154   GdkWindow *w;
155
156   w = window;
157   while (w != _gdk_parent_root)
158     {
159       /* Huge hack, so that we don't propagate events to GtkWindow->frame */
160       if ((w != window) &&
161           (GDK_WINDOW_OBJECT (w)->window_type != GDK_WINDOW_CHILD) &&
162           (g_object_get_data (G_OBJECT (w), "gdk-window-child-handler")))
163         break;
164
165       evmask = GDK_WINDOW_OBJECT (w)->event_mask;
166
167       if (evmask & type_masks[type])
168         return w;
169
170       w = gdk_window_get_parent (w);
171     }
172
173   return NULL;
174 }
175
176 GdkWindow *
177 gdk_directfb_pointer_event_window (GdkWindow    *window,
178                                    GdkEventType  type)
179 {
180   guint            evmask;
181   GdkModifierType  mask;
182   GdkWindow       *w;
183
184   gdk_directfb_mouse_get_info (NULL, NULL, &mask);
185
186   if (_gdk_directfb_pointer_grab_window && !_gdk_directfb_pointer_grab_owner_events )
187     {
188       evmask = _gdk_directfb_pointer_grab_events;
189
190       if (evmask & (GDK_BUTTON1_MOTION_MASK |
191                     GDK_BUTTON2_MOTION_MASK |
192                     GDK_BUTTON3_MOTION_MASK))
193         {
194           if (((mask & GDK_BUTTON1_MASK) &&
195                (evmask & GDK_BUTTON1_MOTION_MASK)) ||
196               ((mask & GDK_BUTTON2_MASK) &&
197                (evmask & GDK_BUTTON2_MOTION_MASK)) ||
198               ((mask & GDK_BUTTON3_MASK) &&
199                (evmask & GDK_BUTTON3_MOTION_MASK)))
200             evmask |= GDK_POINTER_MOTION_MASK;
201         }
202
203       if (evmask & type_masks[type]) {
204
205         if( _gdk_directfb_pointer_grab_owner_events ) {
206         return _gdk_directfb_pointer_grab_window;
207         }else {
208                 GdkWindowObject *obj= GDK_WINDOW_OBJECT(window);
209                 while (obj != NULL && 
210                     obj != GDK_WINDOW_OBJECT(_gdk_directfb_pointer_grab_window)) {
211                     obj = (GdkWindowObject *)obj->parent;
212                 }
213                 if( obj ==GDK_WINDOW_OBJECT(_gdk_directfb_pointer_grab_window) ) {
214                     return  window;
215                 }else {
216                     //was not  child of the grab window so return the grab window
217                     return _gdk_directfb_pointer_grab_window;
218                 }
219          }
220         }
221     }
222
223   w = window;
224   while (w != _gdk_parent_root)
225     {
226       /* Huge hack, so that we don't propagate events to GtkWindow->frame */
227       if ((w != window) &&
228           (GDK_WINDOW_OBJECT (w)->window_type != GDK_WINDOW_CHILD) &&
229           (g_object_get_data (G_OBJECT (w), "gdk-window-child-handler")))
230         break;
231
232       evmask = GDK_WINDOW_OBJECT (w)->event_mask;
233
234       if (evmask & (GDK_BUTTON1_MOTION_MASK |
235                     GDK_BUTTON2_MOTION_MASK |
236                     GDK_BUTTON3_MOTION_MASK))
237         {
238           if (((mask & GDK_BUTTON1_MASK) &&
239                (evmask & GDK_BUTTON1_MOTION_MASK)) ||
240               ((mask & GDK_BUTTON2_MASK) &&
241                (evmask & GDK_BUTTON2_MOTION_MASK)) ||
242               ((mask & GDK_BUTTON3_MASK) &&
243                (evmask & GDK_BUTTON3_MOTION_MASK)))
244             evmask |= GDK_POINTER_MOTION_MASK;
245         }
246
247       if (evmask & type_masks[type])
248         return w;
249
250       w = gdk_window_get_parent (w);
251     }
252
253   return NULL;
254 }
255
256 GdkWindow *
257 gdk_directfb_keyboard_event_window (GdkWindow    *window,
258                                     GdkEventType  type)
259 {
260   guint32    evmask;
261   GdkWindow *w;
262
263   if (_gdk_directfb_keyboard_grab_window &&
264       !_gdk_directfb_keyboard_grab_owner_events)
265     {
266       return _gdk_directfb_keyboard_grab_window;
267     }
268
269   w = window;
270   while (w != _gdk_parent_root)
271     {
272       /* Huge hack, so that we don't propagate events to GtkWindow->frame */
273       if ((w != window) &&
274           (GDK_WINDOW_OBJECT (w)->window_type != GDK_WINDOW_CHILD) &&
275           (g_object_get_data (G_OBJECT (w), "gdk-window-child-handler")))
276         break;
277
278       evmask = GDK_WINDOW_OBJECT (w)->event_mask;
279
280       if (evmask & type_masks[type])
281         return w;
282
283       w = gdk_window_get_parent (w);
284     }
285    return w;
286 }
287
288
289 GdkEvent *
290 gdk_directfb_event_make (GdkWindow    *window,
291                          GdkEventType  type)
292 {
293   GdkEvent *event    = gdk_event_new (GDK_NOTHING);
294   guint32   the_time = gdk_directfb_get_time ();
295   event->any.type       = type;
296   event->any.window     = g_object_ref (window);
297   event->any.send_event = FALSE;
298
299   switch (type)
300     {
301     case GDK_MOTION_NOTIFY:
302       event->motion.time = the_time;
303       event->motion.axes = NULL;
304       break;
305     case GDK_BUTTON_PRESS:
306     case GDK_2BUTTON_PRESS:
307     case GDK_3BUTTON_PRESS:
308     case GDK_BUTTON_RELEASE:
309       event->button.time = the_time;
310       event->button.axes = NULL;
311       break;
312     case GDK_KEY_PRESS:
313     case GDK_KEY_RELEASE:
314       event->key.time = the_time;
315       break;
316     case GDK_ENTER_NOTIFY:
317     case GDK_LEAVE_NOTIFY:
318       event->crossing.time = the_time;
319       break;
320     case GDK_PROPERTY_NOTIFY:
321       event->property.time = the_time;
322       break;
323     case GDK_SELECTION_CLEAR:
324     case GDK_SELECTION_REQUEST:
325     case GDK_SELECTION_NOTIFY:
326       event->selection.time = the_time;
327       break;
328     case GDK_PROXIMITY_IN:
329     case GDK_PROXIMITY_OUT:
330       event->proximity.time = the_time;
331       break;
332     case GDK_DRAG_ENTER:
333     case GDK_DRAG_LEAVE:
334     case GDK_DRAG_MOTION:
335     case GDK_DRAG_STATUS:
336     case GDK_DROP_START:
337     case GDK_DROP_FINISHED:
338       event->dnd.time = the_time;
339       break;
340     case GDK_SCROLL:
341       event->scroll.time = the_time;
342       break;
343     case GDK_FOCUS_CHANGE:
344     case GDK_CONFIGURE:
345     case GDK_MAP:
346     case GDK_UNMAP:
347     case GDK_CLIENT_EVENT:
348     case GDK_VISIBILITY_NOTIFY:
349     case GDK_NO_EXPOSE:
350     case GDK_DELETE:
351     case GDK_DESTROY:
352     case GDK_EXPOSE:
353     default:
354       break;
355     }
356
357   _gdk_event_queue_append (gdk_display_get_default (), event);
358
359   return event;
360 }
361
362 void
363 gdk_error_trap_push (void)
364 {
365 }
366
367 gint
368 gdk_error_trap_pop (void)
369 {
370   return 0;
371 }
372
373
374 /**
375  * gdk_pointer_grab_info_libgtk_only:
376  * @grab_window: location to store current grab window
377  * @owner_events: location to store boolean indicating whether
378  *   the @owner_events flag to gdk_pointer_grab() was %TRUE.
379  *
380  * Determines information about the current pointer grab.
381  * This is not public API and must not be used by applications.
382  *
383  * Return value: %TRUE if this application currently has the
384  *  pointer grabbed.
385  **/
386 gboolean
387 gdk_pointer_grab_info_libgtk_only (GdkDisplay *display,GdkWindow **grab_window,
388                                    gboolean    *owner_events)
389 {
390   if (_gdk_directfb_pointer_grab_window)
391     {
392       if (grab_window)
393         *grab_window = (GdkWindow *)_gdk_directfb_pointer_grab_window;
394       if (owner_events)
395         *owner_events = _gdk_directfb_pointer_grab_owner_events;
396
397       return TRUE;
398     }
399
400   return FALSE;
401 }
402
403 /**
404  * gdk_keyboard_grab_info_libgtk_only:
405  * @grab_window: location to store current grab window
406  * @owner_events: location to store boolean indicating whether
407  *   the @owner_events flag to gdk_keyboard_grab() was %TRUE.
408  *
409  * Determines information about the current keyboard grab.
410  * This is not public API and must not be used by applications.
411  *
412  * Return value: %TRUE if this application currently has the
413  *  keyboard grabbed.
414  **/
415 gboolean
416 gdk_keyboard_grab_info_libgtk_only (GdkDisplay *display,GdkWindow **grab_window,
417                                     gboolean    *owner_events)
418 {
419   if (_gdk_directfb_keyboard_grab_window)
420     {
421       if (grab_window)
422         *grab_window = (GdkWindow *) _gdk_directfb_keyboard_grab_window;
423       if (owner_events)
424         *owner_events = _gdk_directfb_keyboard_grab_owner_events;
425
426       return TRUE;
427     }
428
429   return FALSE;
430 }
431
432
433 GdkGrabStatus
434 gdk_keyboard_grab (GdkWindow *window,
435                    gint       owner_events,
436                    guint32    time) 
437 {
438         return gdk_directfb_keyboard_grab(gdk_display_get_default(),
439                         window,
440                         owner_events,
441                         time);
442
443 }
444
445 /*
446  *--------------------------------------------------------------
447  * gdk_pointer_grab
448  *
449  *   Grabs the pointer to a specific window
450  *
451  * Arguments:
452  *   "window" is the window which will receive the grab
453  *   "owner_events" specifies whether events will be reported as is,
454  *     or relative to "window"
455  *   "event_mask" masks only interesting events
456  *   "confine_to" limits the cursor movement to the specified window
457  *   "cursor" changes the cursor for the duration of the grab
458  *   "time" specifies the time
459  *
460  * Results:
461  *
462  * Side effects:
463  *   requires a corresponding call to gdk_pointer_ungrab
464  *
465  *--------------------------------------------------------------
466  */
467
468
469 GdkGrabStatus
470 gdk_display_pointer_grab (GdkDisplay *display,GdkWindow    *window,
471                   gint          owner_events,
472                   GdkEventMask  event_mask,
473                   GdkWindow    *confine_to,
474                   GdkCursor    *cursor,
475                   guint32       time)
476 {
477   g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
478   g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
479
480   return gdk_directfb_pointer_grab (window,
481                                     owner_events,
482                                     event_mask,
483                                     confine_to,
484                                     cursor,
485                                     time,
486                                     FALSE);
487 }
488
489 GdkGrabStatus
490 gdk_pointer_grab (GdkWindow *     window,
491                   gint            owner_events,
492                   GdkEventMask    event_mask,
493                   GdkWindow *     confine_to,
494                   GdkCursor *     cursor,
495                   guint32         time)
496 {
497         return gdk_directfb_pointer_grab(window, owner_events,event_mask,
498                 confine_to,cursor,time,FALSE);  
499 }
500
501 #define __GDK_MAIN_X11_C__
502 #include "gdkaliasdef.c"