]> Pileus Git - ~andy/gtk/blob - gdk/directfb/gdkwindow-directfb.c
122d54ed2be0f5d0f9d1c4b4b8a9d9c866fa3127
[~andy/gtk] / gdk / directfb / gdkwindow-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 #include <config.h>
35 #include "gdk.h"
36 #include "gdkwindow.h"
37
38 #include "gdkdirectfb.h"
39 #include "gdkprivate-directfb.h"
40 #include "gdkdisplay-directfb.h"
41
42 #include "gdkregion-generic.h"
43
44 #include "gdkinternals.h"
45 #include "gdkalias.h"
46 #include "cairo.h"
47 #include <assert.h>
48
49 #include <directfb_util.h>
50
51 static GdkRegion * gdk_window_impl_directfb_get_visible_region (GdkDrawable *drawable);
52 static void        gdk_window_impl_directfb_set_colormap       (GdkDrawable *drawable,
53                                                                 GdkColormap *colormap);
54 static void gdk_window_impl_directfb_init       (GdkWindowImplDirectFB      *window);
55 static void gdk_window_impl_directfb_class_init (GdkWindowImplDirectFBClass *klass);
56 static void gdk_window_impl_directfb_finalize   (GObject                    *object);
57
58 typedef struct
59 {
60   GdkWindowChildChanged  changed;
61   GdkWindowChildGetPos   get_pos;
62   gpointer               user_data;
63 } GdkWindowChildHandlerData;
64
65
66 /* Code for dirty-region queueing
67  */
68 static GSList *update_windows = NULL;
69 static guint update_idle = 0;
70
71 static void
72 gdk_window_directfb_process_all_updates (void)
73 {
74   GSList *old_update_windows = update_windows;
75   GSList *tmp_list = update_windows;
76
77   if (update_idle)
78     g_source_remove (update_idle);
79   
80   update_windows = NULL;
81   update_idle = 0;
82
83   g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
84   
85   while (tmp_list)
86     {
87       GdkWindowObject *private = (GdkWindowObject *)tmp_list->data;
88       
89       if (private->update_freeze_count)
90         update_windows = g_slist_prepend (update_windows, private);
91       else
92         gdk_window_process_updates(tmp_list->data,TRUE);
93       
94       g_object_unref (tmp_list->data);
95       tmp_list = tmp_list->next;
96     }
97
98
99 #ifndef GDK_DIRECTFB_NO_EXPERIMENTS
100   tmp_list = old_update_windows;
101
102   g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
103
104   while (tmp_list) {
105        GdkWindowObject *top = GDK_WINDOW_OBJECT( gdk_window_get_toplevel( tmp_list->data ) );
106
107        if (top) {
108             GdkWindowImplDirectFB *wimpl = GDK_WINDOW_IMPL_DIRECTFB (top->impl);
109
110             if (wimpl->flips.num_regions) {
111                  //direct_log_printf( NULL, "Flipping bounding box of paints: %d,%d - %dx%d (top %p, wimpl %p)\n",
112                  //                   DFB_RECTANGLE_VALS_FROM_REGION( &wimpl->flips.bounding ), top, wimpl );
113
114                  wimpl->drawable.surface->Flip( wimpl->drawable.surface, &wimpl->flips.bounding, DSFLIP_NONE );
115
116                  dfb_updates_reset( &wimpl->flips );
117             }
118        }
119
120
121        g_object_unref (tmp_list->data);
122        tmp_list = tmp_list->next;
123   }
124 #endif
125
126
127   g_slist_free (old_update_windows);
128
129 }
130
131 static gboolean
132 gdk_window_update_idle (gpointer data)
133 {
134   gdk_window_directfb_process_all_updates ();
135   
136   return FALSE;
137 }
138
139 static void
140 gdk_window_schedule_update (GdkWindow *window)
141 {
142   if (window && GDK_WINDOW_OBJECT (window)->update_freeze_count)
143     return;
144
145   if (!update_idle)
146     {
147       update_idle = gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW,
148                                      gdk_window_update_idle, NULL, NULL);
149     }
150 }
151
152
153 static GdkWindow *gdk_directfb_window_containing_pointer = NULL;
154 static GdkWindow *gdk_directfb_focused_window            = NULL;
155 static gpointer   parent_class                           = NULL;
156 GdkWindow * _gdk_parent_root = NULL;
157 static void
158 gdk_window_impl_directfb_paintable_init (GdkPaintableIface *iface);
159
160
161
162
163
164 GType
165 gdk_window_impl_directfb_get_type (void)
166 {
167   static GType object_type = 0;
168
169   if (!object_type)
170     {
171       static const GTypeInfo object_info =
172         {
173           sizeof (GdkWindowImplDirectFBClass),
174           (GBaseInitFunc) NULL,
175           (GBaseFinalizeFunc) NULL,
176           (GClassInitFunc) gdk_window_impl_directfb_class_init,
177           NULL,           /* class_finalize */
178           NULL,           /* class_data */
179           sizeof (GdkWindowImplDirectFB),
180           0,              /* n_preallocs */
181           (GInstanceInitFunc) gdk_window_impl_directfb_init,
182         };
183
184     static const GInterfaceInfo paintable_info =
185       {
186     (GInterfaceInitFunc) gdk_window_impl_directfb_paintable_init,
187     NULL,
188     NULL
189       };
190
191       object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_DIRECTFB,
192                                             "GdkWindowImplDirectFB",
193                                             &object_info, 0);
194        g_type_add_interface_static (object_type,
195                    GDK_TYPE_PAINTABLE,
196                    &paintable_info);
197
198     }
199
200   return object_type;
201 }
202
203 GType
204 _gdk_window_impl_get_type (void)
205 {
206   return gdk_window_impl_directfb_get_type ();
207 }
208
209 static void
210 gdk_window_impl_directfb_init (GdkWindowImplDirectFB *impl)
211 {
212   impl->drawable.width  = 1;
213   impl->drawable.height = 1;
214   //cannot use gdk_cursor_new here since gdk_display_get_default
215   //does not work yet.
216   impl->cursor          = gdk_cursor_new_for_display (GDK_DISPLAY_OBJECT(_gdk_display),GDK_LEFT_PTR);
217   impl->opacity         = 255;
218 }
219
220 static void
221 gdk_window_impl_directfb_class_init (GdkWindowImplDirectFBClass *klass)
222 {
223   GObjectClass     *object_class   = G_OBJECT_CLASS (klass);
224   GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
225
226   parent_class = g_type_class_peek_parent (klass);
227
228   object_class->finalize = gdk_window_impl_directfb_finalize;
229
230   drawable_class->set_colormap = gdk_window_impl_directfb_set_colormap;
231
232   /* Visible and clip regions are the same */
233
234   drawable_class->get_clip_region =
235     gdk_window_impl_directfb_get_visible_region;
236
237   drawable_class->get_visible_region =
238     gdk_window_impl_directfb_get_visible_region;
239 }
240
241 static void
242 g_free_2nd (gpointer a,
243             gpointer b,
244             gpointer data)
245 {
246   g_free (b);
247 }
248
249 static void
250 gdk_window_impl_directfb_finalize (GObject *object)
251 {
252   GdkWindowImplDirectFB *impl = GDK_WINDOW_IMPL_DIRECTFB (object);
253
254   if (GDK_WINDOW_IS_MAPPED (impl->drawable.wrapper))
255     gdk_window_hide (impl->drawable.wrapper);
256
257   if (impl->cursor)
258     gdk_cursor_unref (impl->cursor);
259
260   if (impl->properties)
261     {
262       g_hash_table_foreach (impl->properties, g_free_2nd, NULL);
263       g_hash_table_destroy (impl->properties);
264     }
265   if (impl->window)
266     {
267       gdk_directfb_window_id_table_remove (impl->dfb_id);
268           /* native window resource must be release before we can finalize !*/
269       impl->window = NULL;
270     }
271
272   if (G_OBJECT_CLASS (parent_class)->finalize)
273     G_OBJECT_CLASS (parent_class)->finalize (object);
274 }
275
276 static GdkRegion*
277 gdk_window_impl_directfb_get_visible_region (GdkDrawable *drawable)
278 {
279   GdkDrawableImplDirectFB *priv = GDK_DRAWABLE_IMPL_DIRECTFB (drawable);
280   GdkRectangle             rect = { 0, 0, 0, 0 };
281   DFBRectangle             drect = { 0, 0, 0, 0 };
282
283   if (priv->surface)
284   priv->surface->GetVisibleRectangle (priv->surface, &drect);
285   rect.x= drect.x;
286   rect.y= drect.y;
287   rect.width=drect.w;
288   rect.height=drect.h;
289   return gdk_region_rectangle (&rect);
290 }
291
292 static void
293 gdk_window_impl_directfb_set_colormap (GdkDrawable *drawable,
294                                        GdkColormap *colormap)
295 {
296   GDK_DRAWABLE_CLASS (parent_class)->set_colormap (drawable, colormap);
297
298   if (colormap)
299     {
300        GdkDrawableImplDirectFB *priv = GDK_DRAWABLE_IMPL_DIRECTFB (drawable);
301
302        if (priv->surface)
303          {
304            IDirectFBPalette *palette = gdk_directfb_colormap_get_palette (colormap);
305
306            if (palette)
307              priv->surface->SetPalette (priv->surface, palette);
308          }
309     }
310 }
311
312
313 static gboolean
314 create_directfb_window (GdkWindowImplDirectFB *impl,
315                         DFBWindowDescription  *desc,
316                         DFBWindowOptions       window_options)
317 {
318   DFBResult        ret;
319   IDirectFBWindow *window;
320
321   ret = _gdk_display->layer->CreateWindow (_gdk_display->layer, desc, &window);
322
323   if (ret != DFB_OK)
324     {
325       DirectFBError ("gdk_window_new: Layer->CreateWindow failed", ret);
326       g_assert (0);
327       return FALSE;
328     }
329
330   if ((desc->flags & DWDESC_CAPS) && (desc->caps & DWCAPS_INPUTONLY))
331   {
332     impl->drawable.surface = NULL;
333   } else 
334     window->GetSurface (window, &impl->drawable.surface);
335
336   if (window_options)
337     {
338       DFBWindowOptions options;
339       window->GetOptions (window, &options);
340       window->SetOptions (window,  options | window_options);
341     }
342
343   impl->window = window;
344
345 #ifndef GDK_DIRECTFB_NO_EXPERIMENTS
346   //direct_log_printf( NULL, "Initializing (window %p, wimpl %p)\n", win, impl );
347
348   dfb_updates_init( &impl->flips, impl->flip_regions, G_N_ELEMENTS(impl->flip_regions) );
349 #endif
350
351   return TRUE;
352 }
353
354 void
355 _gdk_windowing_window_init (void)
356 {
357   GdkWindowObject       *private;
358   GdkWindowImplDirectFB *impl;
359   DFBDisplayLayerConfig  dlc;
360
361   g_assert (_gdk_parent_root == NULL);
362
363   _gdk_display->layer->GetConfiguration( 
364         _gdk_display->layer, &dlc );
365
366   _gdk_parent_root = g_object_new (GDK_TYPE_WINDOW, NULL);
367   private = GDK_WINDOW_OBJECT (_gdk_parent_root);
368   impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
369
370   private->window_type = GDK_WINDOW_ROOT;
371   private->state       = 0;
372   private->children    = NULL;
373 //  impl->drawable.paint_region   = NULL;
374   impl->gdkWindow      = _gdk_parent_root;
375   impl->window           = NULL;
376   impl->drawable.abs_x   = 0;
377   impl->drawable.abs_y   = 0;
378   impl->drawable.width   = dlc.width;
379   impl->drawable.height  = dlc.height;
380   impl->drawable.wrapper = GDK_DRAWABLE (private);
381   /* custom root window init */
382   {
383     DFBWindowDescription   desc;
384     desc.flags = 0;
385         /*XXX I must do this now its a bug  ALPHA ROOT*/
386
387     desc.flags = DWDESC_CAPS;
388     desc.caps = 0;
389     desc.caps  |= DWCAPS_NODECORATION;
390     desc.caps  |= DWCAPS_ALPHACHANNEL;
391     desc.flags |= ( DWDESC_WIDTH | DWDESC_HEIGHT |
392                       DWDESC_POSX  | DWDESC_POSY );
393     desc.posx   = 0;
394     desc.posy   = 0;
395     desc.width  = dlc.width;
396     desc.height = dlc.height;
397     create_directfb_window (impl,&desc,0);
398         g_assert(impl->window != NULL);
399     g_assert(impl->drawable.surface != NULL );
400   }
401   impl->drawable.surface->GetPixelFormat(impl->drawable.surface,&impl->drawable.format); 
402   private->depth = DFB_BITS_PER_PIXEL(impl->drawable.format);
403   /*
404         Now we can set up the system colormap
405   */
406   gdk_drawable_set_colormap (GDK_DRAWABLE (_gdk_parent_root),gdk_colormap_get_system());
407 }
408
409
410
411 GdkWindow *
412 gdk_directfb_window_new (GdkWindow              *parent,
413                          GdkWindowAttr          *attributes,
414                          gint                    attributes_mask,
415                          DFBWindowCapabilities   window_caps,
416                          DFBWindowOptions        window_options,
417                          DFBSurfaceCapabilities  surface_caps)
418 {
419   GdkWindow             *window;
420   GdkWindowObject       *private;
421   GdkWindowObject       *parent_private;
422   GdkWindowImplDirectFB *impl;
423   GdkWindowImplDirectFB *parent_impl;
424   GdkVisual             *visual;
425   DFBWindowDescription   desc;
426   gint x, y;
427
428   g_return_val_if_fail (attributes != NULL, NULL);
429
430   if (!parent || attributes->window_type != GDK_WINDOW_CHILD)
431     parent = _gdk_parent_root;
432
433   window = g_object_new (GDK_TYPE_WINDOW, NULL);
434   private = GDK_WINDOW_OBJECT (window);
435
436   parent_private = GDK_WINDOW_OBJECT (parent);
437   parent_impl = GDK_WINDOW_IMPL_DIRECTFB (parent_private->impl);
438   private->parent = parent_private;
439
440   x = (attributes_mask & GDK_WA_X) ? attributes->x : 0;
441   y = (attributes_mask & GDK_WA_Y) ? attributes->y : 0;
442
443   gdk_window_set_events (window, attributes->event_mask | GDK_STRUCTURE_MASK);
444
445   impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
446   impl->drawable.wrapper = GDK_DRAWABLE (window);
447   impl->gdkWindow      = window;
448
449   private->x = x;
450   private->y = y;
451
452   _gdk_directfb_calc_abs (window);
453
454   impl->drawable.width  = MAX (1, attributes->width);
455   impl->drawable.height = MAX (1, attributes->height);
456
457   private->window_type = attributes->window_type;
458
459   desc.flags = 0;
460
461   if (attributes_mask & GDK_WA_VISUAL)
462     visual = attributes->visual;
463   else
464     visual = gdk_drawable_get_visual (parent);
465
466   switch (attributes->wclass)
467     {
468     case GDK_INPUT_OUTPUT:
469       private->input_only = FALSE;
470
471       desc.flags |= DWDESC_PIXELFORMAT;
472       desc.pixelformat = ((GdkVisualDirectFB *) visual)->format;
473
474       if (DFB_PIXELFORMAT_HAS_ALPHA (desc.pixelformat))
475         {
476           desc.flags |= DWDESC_CAPS;
477           desc.caps = DWCAPS_ALPHACHANNEL;
478         }
479       break;
480
481     case GDK_INPUT_ONLY:
482       private->input_only = TRUE;
483       desc.flags |= DWDESC_CAPS;
484       desc.caps = DWCAPS_INPUTONLY;
485       break;
486
487     default:
488       g_warning ("gdk_window_new: unsupported window class\n");
489       _gdk_window_destroy (window, FALSE);
490       return NULL;
491     }
492
493   switch (private->window_type)
494     {
495     case GDK_WINDOW_TOPLEVEL:
496     case GDK_WINDOW_DIALOG:
497     case GDK_WINDOW_TEMP:
498       desc.flags |= ( DWDESC_WIDTH | DWDESC_HEIGHT |
499                       DWDESC_POSX  | DWDESC_POSY );
500       desc.posx   = x;
501       desc.posy   = y;
502       desc.width  = impl->drawable.width;
503       desc.height = impl->drawable.height;
504 #if 0
505       if (window_caps)
506         {
507           if (! (desc.flags & DWDESC_CAPS))
508             {
509               desc.flags |= DWDESC_CAPS;
510               desc.caps   = DWCAPS_NONE;
511             }
512
513           desc.caps |= window_caps;
514         }
515
516       if (surface_caps)
517         {
518           desc.flags |= DWDESC_SURFACE_CAPS;
519           desc.surface_caps = surface_caps;
520         }
521 #endif
522
523       if (!create_directfb_window (impl, &desc, window_options))
524         {
525                   g_assert(0);
526           _gdk_window_destroy (window, FALSE);
527           return NULL;
528         }
529         if( desc.caps != DWCAPS_INPUTONLY )
530                         impl->window->SetOpacity(impl->window, 0x00 );
531       break;
532
533     case GDK_WINDOW_CHILD:
534            impl->window=NULL;
535       if (!private->input_only && parent_impl->drawable.surface)
536         {
537
538           DFBRectangle rect =
539           { x, y, impl->drawable.width, impl->drawable.height };
540           parent_impl->drawable.surface->GetSubSurface (parent_impl->drawable.surface,
541                                                         &rect,
542                                                         &impl->drawable.surface);
543         }
544       break;
545
546     default:
547       g_warning ("gdk_window_new: unsupported window type: %d",
548                  private->window_type);
549       _gdk_window_destroy (window, FALSE);
550       return NULL;
551     }
552
553   if (impl->drawable.surface)
554     {
555       GdkColormap *colormap;
556
557       impl->drawable.surface->GetPixelFormat (impl->drawable.surface,
558                                               &impl->drawable.format);
559
560           private->depth = DFB_BITS_PER_PIXEL(impl->drawable.format);
561
562       if ((attributes_mask & GDK_WA_COLORMAP) && attributes->colormap)
563         {
564           colormap = attributes->colormap;
565         }
566       else
567         {
568           if (gdk_visual_get_system () == visual)
569             colormap = gdk_colormap_get_system ();
570           else
571             colormap =gdk_drawable_get_colormap (parent);
572         }
573
574       gdk_drawable_set_colormap (GDK_DRAWABLE (window), colormap);
575     }
576   else
577     {
578       impl->drawable.format = ((GdkVisualDirectFB *)visual)->format;
579           private->depth = visual->depth;
580     }
581
582   gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
583                                   (attributes->cursor) : NULL));
584
585   if (parent_private)
586     parent_private->children = g_list_prepend (parent_private->children,
587                                                window);
588
589   /* we hold a reference count on ourselves */
590   g_object_ref (window);
591
592   if (impl->window)
593     {
594       impl->window->GetID (impl->window, &impl->dfb_id);
595       gdk_directfb_window_id_table_insert (impl->dfb_id, window);
596       gdk_directfb_event_windows_add (window);
597     }
598
599   if (attributes_mask & GDK_WA_TYPE_HINT)
600     gdk_window_set_type_hint (window, attributes->type_hint);
601
602   return window;
603 }
604
605 GdkWindow *
606 gdk_window_new (GdkWindow     *parent,
607                 GdkWindowAttr *attributes,
608                 gint           attributes_mask)
609 {
610   g_return_val_if_fail (attributes != NULL, NULL);
611
612   return gdk_directfb_window_new (parent, attributes, attributes_mask,
613                                   DWCAPS_NONE, DWOP_NONE, DSCAPS_NONE);
614 }
615 void
616 _gdk_windowing_window_destroy_foreign (GdkWindow *window)
617 {
618   /* It's somebody else's window, but in our heirarchy,
619    * so reparent it to the root window, and then send
620    * it a delete event, as if we were a WM
621    */
622         _gdk_windowing_window_destroy (window,TRUE,TRUE);
623 }
624
625
626 void
627 _gdk_windowing_window_destroy (GdkWindow *window,
628                                gboolean   recursing,
629                                gboolean   foreign_destroy)
630 {
631   GdkWindowObject       *private;
632   GdkWindowImplDirectFB *impl;
633
634   g_return_if_fail (GDK_IS_WINDOW (window));
635
636   private = GDK_WINDOW_OBJECT (window);
637   impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
638
639   _gdk_selection_window_destroyed (window);
640 #if (DIRECTFB_MAJOR_VERSION >= 1)
641   gdk_directfb_event_windows_remove (window);
642 #endif
643   if (window == _gdk_directfb_pointer_grab_window)
644     gdk_pointer_ungrab (GDK_CURRENT_TIME);
645   if (window == _gdk_directfb_keyboard_grab_window)
646     gdk_keyboard_ungrab (GDK_CURRENT_TIME);
647
648   if (window == gdk_directfb_focused_window)
649     gdk_directfb_change_focus (NULL);
650
651
652   if (impl->drawable.surface) {
653     GdkDrawableImplDirectFB *dimpl = GDK_DRAWABLE_IMPL_DIRECTFB (private->impl);
654     if(dimpl->cairo_surface) {
655       cairo_surface_destroy(dimpl->cairo_surface);
656       dimpl->cairo_surface= NULL;
657     }
658     impl->drawable.surface->Release (impl->drawable.surface);
659     impl->drawable.surface = NULL;
660   }
661
662   if (!recursing && !foreign_destroy && impl->window ) {
663         impl->window->SetOpacity (impl->window,0);
664                 impl->window->Close(impl->window);
665         impl->window->Release(impl->window);
666         impl->window = NULL;
667   }
668 }
669
670 /* This function is called when the window is really gone.
671  */
672 void
673 gdk_window_destroy_notify (GdkWindow *window)
674 {
675   g_return_if_fail (GDK_IS_WINDOW (window));
676
677   if (!GDK_WINDOW_DESTROYED (window))
678     {
679       if (GDK_WINDOW_TYPE(window) != GDK_WINDOW_FOREIGN)
680         g_warning ("GdkWindow %p unexpectedly destroyed", window);
681
682       _gdk_window_destroy (window, TRUE);
683     }
684    g_object_unref (window);
685 }
686
687 /* Focus follows pointer */
688 GdkWindow *
689 gdk_directfb_window_find_toplevel (GdkWindow *window)
690 {
691   while (window && window != _gdk_parent_root)
692     {
693       GdkWindow *parent = (GdkWindow *) (GDK_WINDOW_OBJECT (window))->parent;
694
695       if ((parent == _gdk_parent_root) && GDK_WINDOW_IS_MAPPED (window))
696         return window;
697
698       window = parent;
699     }
700
701   return _gdk_parent_root;
702 }
703
704 GdkWindow *
705 gdk_directfb_window_find_focus (void)
706 {
707   if (_gdk_directfb_keyboard_grab_window)
708     return _gdk_directfb_keyboard_grab_window;
709
710   if (!gdk_directfb_focused_window)
711     gdk_directfb_focused_window = g_object_ref (_gdk_parent_root);
712
713   return gdk_directfb_focused_window;
714 }
715
716 void
717 gdk_directfb_change_focus (GdkWindow *new_focus_window)
718 {
719   GdkEventFocus *event;
720   GdkWindow     *old_win;
721   GdkWindow     *new_win;
722   GdkWindow     *event_win;
723
724
725   /* No focus changes while the pointer is grabbed */
726   if (_gdk_directfb_pointer_grab_window)
727     return;
728
729   old_win = gdk_directfb_focused_window;
730   new_win = gdk_directfb_window_find_toplevel (new_focus_window);
731
732   if (old_win == new_win)
733     return;
734
735   if (old_win)
736     {
737       event_win = gdk_directfb_keyboard_event_window (old_win,
738                                                       GDK_FOCUS_CHANGE);
739       if (event_win)
740         {
741           event = (GdkEventFocus *) gdk_directfb_event_make (event_win,
742                                                              GDK_FOCUS_CHANGE);
743           event->in = FALSE;
744         }
745     }
746
747   event_win = gdk_directfb_keyboard_event_window (new_win,
748                                                   GDK_FOCUS_CHANGE);
749   if (event_win)
750     {
751       event = (GdkEventFocus *) gdk_directfb_event_make (event_win,
752                                                          GDK_FOCUS_CHANGE);
753       event->in = TRUE;
754     }
755
756   if (gdk_directfb_focused_window)
757     g_object_unref (gdk_directfb_focused_window);
758   gdk_directfb_focused_window = g_object_ref (new_win);
759 }
760
761 void
762 gdk_window_set_accept_focus (GdkWindow *window,
763                              gboolean accept_focus)
764 {
765   GdkWindowObject *private;
766   g_return_if_fail (window != NULL);
767   g_return_if_fail (GDK_IS_WINDOW (window));
768                                                                                                                       
769   private = (GdkWindowObject *)window;
770                                                                                                                       
771   accept_focus = accept_focus != FALSE;
772                                                                                                                       
773   if (private->accept_focus != accept_focus)
774     private->accept_focus = accept_focus;
775
776 }
777
778 void
779 gdk_window_set_focus_on_map (GdkWindow *window,
780                              gboolean focus_on_map)
781 {
782   GdkWindowObject *private;
783   g_return_if_fail (window != NULL);
784   g_return_if_fail (GDK_IS_WINDOW (window));
785                                                                                                                       
786   private = (GdkWindowObject *)window;
787                                                                                                                       
788   focus_on_map = focus_on_map != FALSE;
789                                                                                                                       
790   if (private->focus_on_map != focus_on_map)
791     private->focus_on_map = focus_on_map;
792 }
793
794 static gboolean
795 gdk_directfb_window_raise (GdkWindow *window)
796 {
797   GdkWindowObject *parent;
798
799   parent = GDK_WINDOW_OBJECT (window)->parent;
800
801   if (parent->children->data == window)
802     return FALSE;
803
804   parent->children = g_list_remove (parent->children, window);
805   parent->children = g_list_prepend (parent->children, window);
806
807   return TRUE;
808 }
809
810 static void
811 gdk_directfb_window_lower (GdkWindow *window)
812 {
813   GdkWindowObject *parent;
814
815   parent = GDK_WINDOW_OBJECT (window)->parent;
816
817   parent->children = g_list_remove (parent->children, window);
818   parent->children = g_list_append (parent->children, window);
819 }
820
821 static gboolean
822 all_parents_shown (GdkWindowObject *private)
823 {
824   while (GDK_WINDOW_IS_MAPPED (private))
825     {
826       if (private->parent)
827         private = GDK_WINDOW_OBJECT (private)->parent;
828       else
829         return TRUE;
830     }
831
832   return FALSE;
833 }
834
835 static void
836 send_map_events (GdkWindowObject *private)
837 {
838   GList     *list;
839   GdkWindow *event_win;
840
841   if (!GDK_WINDOW_IS_MAPPED (private))
842     return;
843
844   event_win = gdk_directfb_other_event_window ((GdkWindow *) private, GDK_MAP);
845   if (event_win)
846     gdk_directfb_event_make (event_win, GDK_MAP);
847
848   for (list = private->children; list; list = list->next)
849     send_map_events (list->data);
850 }
851
852 static GdkWindow *
853 gdk_directfb_find_common_ancestor (GdkWindow *win1,
854                                    GdkWindow *win2)
855 {
856   GdkWindowObject *a;
857   GdkWindowObject *b;
858
859   for (a = GDK_WINDOW_OBJECT (win1); a; a = a->parent)
860     for (b = GDK_WINDOW_OBJECT (win2); b; b = b->parent)
861       {
862         if (a == b)
863           return GDK_WINDOW (a);
864       }
865
866   return NULL;
867 }
868
869 void
870 gdk_directfb_window_send_crossing_events (GdkWindow       *src,
871                                           GdkWindow       *dest,
872                                           GdkCrossingMode  mode)
873 {
874   GdkWindow       *c;
875   GdkWindow       *win, *last, *next;
876   GdkEvent        *event;
877   gint             x, y, x_int, y_int;
878   GdkModifierType  modifiers;
879   GSList          *path, *list;
880   gboolean         non_linear;
881   GdkWindow       *a;
882   GdkWindow       *b;
883   GdkWindow       *event_win;
884
885   /* Do a possible cursor change before checking if we need to
886      generate crossing events so cursor changes due to pointer
887      grabs work correctly. */
888   {
889     static GdkCursorDirectFB *last_cursor = NULL;
890
891     GdkWindowObject       *private = GDK_WINDOW_OBJECT (dest);
892     GdkWindowImplDirectFB *impl    = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
893     GdkCursorDirectFB     *cursor;
894
895     if (_gdk_directfb_pointer_grab_cursor)
896       cursor = (GdkCursorDirectFB*) _gdk_directfb_pointer_grab_cursor;
897     else
898       cursor = (GdkCursorDirectFB*) impl->cursor;
899
900     if (cursor != last_cursor)
901       {
902         win     = gdk_directfb_window_find_toplevel (dest);
903         private = GDK_WINDOW_OBJECT (win);
904         impl    = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
905
906         if (impl->window)
907           impl->window->SetCursorShape (impl->window,
908                                         cursor->shape,
909                                         cursor->hot_x, cursor->hot_y);
910         last_cursor = cursor;
911       }
912   }
913
914   if (dest == gdk_directfb_window_containing_pointer)
915     return;
916
917   if (gdk_directfb_window_containing_pointer == NULL)
918     gdk_directfb_window_containing_pointer = g_object_ref (_gdk_parent_root);
919
920   if (src)
921     a = src;
922   else
923     a = gdk_directfb_window_containing_pointer;
924
925   b = dest;
926
927   if (a == b)
928     return;
929
930   /* gdk_directfb_window_containing_pointer might have been destroyed.
931    * The refcount we hold on it should keep it, but it's parents
932    * might have died.
933    */
934   if (GDK_WINDOW_DESTROYED (a))
935     a = _gdk_parent_root;
936
937   gdk_directfb_mouse_get_info (&x, &y, &modifiers);
938
939   c = gdk_directfb_find_common_ancestor (a, b);
940
941   non_linear = (c != a) && (c != b);
942
943   event_win = gdk_directfb_pointer_event_window (a, GDK_LEAVE_NOTIFY);
944   if (event_win)
945     {
946       event = gdk_directfb_event_make (event_win, GDK_LEAVE_NOTIFY);
947       event->crossing.subwindow = NULL;
948
949       gdk_window_get_origin (a, &x_int, &y_int);
950
951       event->crossing.x      = x - x_int;
952       event->crossing.y      = y - y_int;
953       event->crossing.x_root = x;
954       event->crossing.y_root = y;
955       event->crossing.mode   = mode;
956
957       if (non_linear)
958         event->crossing.detail = GDK_NOTIFY_NONLINEAR;
959       else if (c == a)
960         event->crossing.detail = GDK_NOTIFY_INFERIOR;
961       else
962         event->crossing.detail = GDK_NOTIFY_ANCESTOR;
963
964       event->crossing.focus = FALSE;
965       event->crossing.state = modifiers;
966     }
967
968    /* Traverse up from a to (excluding) c */
969   if (c != a)
970     {
971       last = a;
972       win = GDK_WINDOW (GDK_WINDOW_OBJECT (a)->parent);
973       while (win != c)
974         {
975           event_win =
976             gdk_directfb_pointer_event_window (win, GDK_LEAVE_NOTIFY);
977
978           if (event_win)
979             {
980               event = gdk_directfb_event_make (event_win, GDK_LEAVE_NOTIFY);
981
982               event->crossing.subwindow = g_object_ref (last);
983
984               gdk_window_get_origin (win, &x_int, &y_int);
985
986               event->crossing.x      = x - x_int;
987               event->crossing.y      = y - y_int;
988               event->crossing.x_root = x;
989               event->crossing.y_root = y;
990               event->crossing.mode   = mode;
991
992               if (non_linear)
993                 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
994               else
995                 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
996
997               event->crossing.focus = FALSE;
998               event->crossing.state = modifiers;
999             }
1000
1001           last = win;
1002           win = GDK_WINDOW (GDK_WINDOW_OBJECT (win)->parent);
1003         }
1004     }
1005
1006   /* Traverse down from c to b */
1007   if (c != b)
1008     {
1009       path = NULL;
1010       win = GDK_WINDOW (GDK_WINDOW_OBJECT (b)->parent);
1011       while (win != c)
1012         {
1013           path = g_slist_prepend (path, win);
1014           win = GDK_WINDOW (GDK_WINDOW_OBJECT (win)->parent);
1015         }
1016
1017       list = path;
1018       while (list)
1019         {
1020           win = GDK_WINDOW (list->data);
1021           list = g_slist_next (list);
1022
1023           if (list)
1024             next = GDK_WINDOW (list->data);
1025           else
1026             next = b;
1027
1028           event_win =
1029             gdk_directfb_pointer_event_window (win, GDK_ENTER_NOTIFY);
1030
1031           if (event_win)
1032             {
1033               event = gdk_directfb_event_make (event_win, GDK_ENTER_NOTIFY);
1034
1035               event->crossing.subwindow = g_object_ref (next);
1036
1037               gdk_window_get_origin (win, &x_int, &y_int);
1038
1039               event->crossing.x      = x - x_int;
1040               event->crossing.y      = y - y_int;
1041               event->crossing.x_root = x;
1042               event->crossing.y_root = y;
1043               event->crossing.mode   = mode;
1044
1045               if (non_linear)
1046                 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1047               else
1048                 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1049
1050               event->crossing.focus = FALSE;
1051               event->crossing.state = modifiers;
1052             }
1053         }
1054
1055       g_slist_free (path);
1056     }
1057
1058   event_win = gdk_directfb_pointer_event_window (b, GDK_ENTER_NOTIFY);
1059   if (event_win)
1060     {
1061       event = gdk_directfb_event_make (event_win, GDK_ENTER_NOTIFY);
1062
1063       event->crossing.subwindow = NULL;
1064
1065       gdk_window_get_origin (b, &x_int, &y_int);
1066
1067       event->crossing.x      = x - x_int;
1068       event->crossing.y      = y - y_int;
1069       event->crossing.x_root = x;
1070       event->crossing.y_root = y;
1071       event->crossing.mode   = mode;
1072
1073       if (non_linear)
1074         event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1075       else if (c==a)
1076         event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1077       else
1078         event->crossing.detail = GDK_NOTIFY_INFERIOR;
1079
1080       event->crossing.focus = FALSE;
1081       event->crossing.state = modifiers;
1082     }
1083
1084   if (mode != GDK_CROSSING_GRAB)
1085     {
1086       //this seems to cause focus to change as the pointer moves yuck
1087       //gdk_directfb_change_focus (b);
1088       if (b != gdk_directfb_window_containing_pointer)
1089         {
1090           g_object_unref (gdk_directfb_window_containing_pointer);
1091           gdk_directfb_window_containing_pointer = g_object_ref (b);
1092         }
1093     }
1094 }
1095
1096 static void
1097 show_window_internal (GdkWindow *window,
1098                       gboolean   raise)
1099 {
1100   GdkWindowObject       *private;
1101   GdkWindowImplDirectFB *impl;
1102   GdkWindow             *mousewin;
1103
1104   private = GDK_WINDOW_OBJECT (window);
1105   impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
1106
1107   if (!private->destroyed && !GDK_WINDOW_IS_MAPPED (private))
1108     {
1109       private->state &= ~GDK_WINDOW_STATE_WITHDRAWN;
1110
1111       if (raise)
1112         gdk_window_raise (window);
1113
1114       if (all_parents_shown (GDK_WINDOW_OBJECT (private)->parent))
1115         {
1116           send_map_events (private);
1117
1118           mousewin = gdk_window_at_pointer (NULL, NULL);
1119           gdk_directfb_window_send_crossing_events (NULL, mousewin,
1120                                                     GDK_CROSSING_NORMAL);
1121
1122           if (private->input_only)
1123             return;
1124
1125           gdk_window_invalidate_rect (window, NULL, TRUE);
1126         }
1127     }
1128
1129   if (impl->window)
1130     {
1131       if (gdk_directfb_apply_focus_opacity)
1132         impl->window->SetOpacity (impl->window,
1133                                   (impl->opacity >> 1) + (impl->opacity >> 2));
1134       else
1135         impl->window->SetOpacity (impl->window, impl->opacity);
1136           /* if its the first window focus it */
1137     }
1138 }
1139
1140 void
1141 gdk_window_show_unraised (GdkWindow *window)
1142 {
1143   g_return_if_fail (GDK_IS_WINDOW (window));
1144
1145   show_window_internal (window, FALSE);
1146 }
1147
1148 void
1149 gdk_window_show (GdkWindow *window)
1150 {
1151   g_return_if_fail (GDK_IS_WINDOW (window));
1152
1153   show_window_internal (window, TRUE);
1154 }
1155
1156 void
1157 gdk_window_hide (GdkWindow *window)
1158 {
1159   GdkWindowObject       *private;
1160   GdkWindowImplDirectFB *impl;
1161   GdkWindow             *mousewin;
1162   GdkWindow             *event_win;
1163
1164   g_return_if_fail (GDK_IS_WINDOW (window));
1165
1166   private = GDK_WINDOW_OBJECT (window);
1167   impl    = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
1168
1169   if (impl->window)
1170     impl->window->SetOpacity (impl->window, 0);
1171
1172   if (!private->destroyed && GDK_WINDOW_IS_MAPPED (private))
1173     {
1174       GdkEvent *event;
1175
1176       private->state |= GDK_WINDOW_STATE_WITHDRAWN;
1177
1178       if (!private->input_only && private->parent)
1179         {
1180           _gdk_windowing_window_clear_area (GDK_WINDOW (private->parent),
1181                                             private->x,
1182                                             private->y,
1183                                             impl->drawable.width,
1184                                             impl->drawable.height);
1185         }
1186
1187       event_win = gdk_directfb_other_event_window (window, GDK_UNMAP);
1188       if (event_win)
1189         event = gdk_directfb_event_make (event_win, GDK_UNMAP);
1190
1191       mousewin = gdk_window_at_pointer (NULL, NULL);
1192       gdk_directfb_window_send_crossing_events (NULL,
1193                                                 mousewin,
1194                                                 GDK_CROSSING_NORMAL);
1195
1196       if (window == _gdk_directfb_pointer_grab_window)
1197         gdk_pointer_ungrab (GDK_CURRENT_TIME);
1198       if (window == _gdk_directfb_keyboard_grab_window)
1199         gdk_keyboard_ungrab (GDK_CURRENT_TIME);
1200     }
1201 }
1202
1203 void
1204 gdk_window_withdraw (GdkWindow *window)
1205 {
1206   g_return_if_fail (GDK_IS_WINDOW (window));
1207
1208   /* for now this should be enough */
1209   gdk_window_hide (window);
1210 }
1211
1212 void
1213 gdk_window_move (GdkWindow *window,
1214                  gint       x,
1215                  gint       y)
1216 {
1217   GdkWindowObject       *private;
1218   GdkWindowImplDirectFB *impl;
1219
1220   g_return_if_fail (GDK_IS_WINDOW (window));
1221
1222   private = GDK_WINDOW_OBJECT (window);
1223   impl    = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
1224
1225   if (impl->window)
1226     {
1227           private->x = x;
1228           private->y = y;
1229       impl->window->MoveTo (impl->window, x, y);
1230     }
1231   else
1232     {
1233           gint width=impl->drawable.width;
1234           gint height=impl->drawable.height;
1235       GdkRectangle  old =
1236       { private->x, private->y,width,height };
1237
1238       _gdk_directfb_move_resize_child (window, x, y, width, height);
1239       _gdk_directfb_calc_abs (window);
1240
1241       if (GDK_WINDOW_IS_MAPPED (private))
1242         {
1243           GdkWindow    *mousewin;
1244           GdkRectangle  new = { x, y, width, height };
1245
1246           gdk_rectangle_union (&new, &old, &new);
1247           gdk_window_invalidate_rect (GDK_WINDOW (private->parent), &new,TRUE);
1248
1249           /* The window the pointer is in might have changed */
1250           mousewin = gdk_window_at_pointer (NULL, NULL);
1251           gdk_directfb_window_send_crossing_events (NULL, mousewin,
1252                                                     GDK_CROSSING_NORMAL);
1253         }
1254     }
1255 }
1256
1257 void
1258 gdk_window_resize (GdkWindow *window,
1259                    gint       width,
1260                    gint       height)
1261 {
1262   GdkWindowObject *private;
1263   gint             x, y;
1264
1265   g_return_if_fail (GDK_IS_WINDOW (window));
1266
1267   private = GDK_WINDOW_OBJECT (window);
1268
1269   x = private->x;
1270   y = private->y;
1271
1272   if (private->parent && (private->parent->window_type != GDK_WINDOW_CHILD))
1273     {
1274       GdkWindowChildHandlerData *data;
1275
1276       data = g_object_get_data (G_OBJECT (private->parent),
1277                                 "gdk-window-child-handler");
1278
1279       if (data)
1280         (*data->get_pos) (window, &x, &y, data->user_data);
1281     }
1282
1283   gdk_window_move_resize (window, x, y, width, height);
1284 }
1285
1286 void
1287 _gdk_directfb_move_resize_child (GdkWindow *window,
1288                                  gint       x,
1289                                  gint       y,
1290                                  gint       width,
1291                                  gint       height)
1292 {
1293   GdkWindowObject       *private;
1294   GdkWindowImplDirectFB *impl;
1295   GdkWindowImplDirectFB *parent_impl;
1296   GList                 *list;
1297
1298   g_return_if_fail (GDK_IS_WINDOW (window));
1299
1300   private = GDK_WINDOW_OBJECT (window);
1301   impl    = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
1302
1303   private->x = x;
1304   private->y = y;
1305
1306   impl->drawable.width  = width;
1307   impl->drawable.height = height;
1308
1309   if (!private->input_only)
1310     {
1311     if (impl->drawable.surface) {
1312       GdkDrawableImplDirectFB *dimpl = GDK_DRAWABLE_IMPL_DIRECTFB (private->impl);
1313       if(dimpl->cairo_surface) {
1314         cairo_surface_destroy(dimpl->cairo_surface);
1315         dimpl->cairo_surface= NULL;
1316       }
1317     impl->drawable.surface->Release (impl->drawable.surface);
1318     impl->drawable.surface = NULL;
1319   }
1320
1321       parent_impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (private->parent)->impl);
1322
1323       if (parent_impl->drawable.surface)
1324         {
1325           DFBRectangle rect = { x, y, width, height };
1326
1327           parent_impl->drawable.surface->GetSubSurface (parent_impl->drawable.surface,
1328                                                         &rect,
1329                                                         &impl->drawable.surface);
1330         }
1331     }
1332
1333   for (list = private->children; list; list = list->next)
1334     {
1335       private = GDK_WINDOW_OBJECT (list->data);
1336           impl  = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
1337       _gdk_directfb_move_resize_child (list->data,
1338                                        private->x, private->y,
1339                                        impl->drawable.width, impl->drawable.height);
1340     }
1341 }
1342
1343 void
1344 gdk_window_move_resize (GdkWindow *window,
1345                         gint       x,
1346                         gint       y,
1347                         gint       width,
1348                         gint       height)
1349 {
1350   GdkWindowObject       *private;
1351   GdkWindowImplDirectFB *impl;
1352
1353   g_return_if_fail (GDK_IS_WINDOW (window));
1354
1355   private = GDK_WINDOW_OBJECT (window);
1356   impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
1357
1358   if (width < 1)
1359      width = 1;
1360   if (height < 1)
1361     height = 1;
1362
1363   if (private->destroyed ||
1364       (private->x == x  &&  private->y == y  &&
1365        impl->drawable.width == width  &&  impl->drawable.height == height))
1366     return;
1367
1368   if (private->parent && (private->parent->window_type != GDK_WINDOW_CHILD))
1369     {
1370       GdkWindowChildHandlerData *data;
1371
1372       data = g_object_get_data (G_OBJECT (private->parent),
1373                                 "gdk-window-child-handler");
1374
1375       if (data &&
1376           (*data->changed) (window, x, y, width, height, data->user_data))
1377         return;
1378     }
1379
1380   if (impl->drawable.width == width  &&  impl->drawable.height == height)
1381     {
1382       gdk_window_move (window, x, y);
1383     }
1384   else if (impl->window)
1385     {
1386           private->x = x;
1387           private->y = y;
1388       impl->window->MoveTo (impl->window, x, y);
1389       impl->window->Resize (impl->window, width, height);
1390     }
1391   else
1392     {
1393       GdkRectangle  old =
1394       { private->x, private->y, impl->drawable.width, impl->drawable.height };
1395       _gdk_directfb_move_resize_child (window, x, y, width, height);
1396       _gdk_directfb_calc_abs (window);
1397
1398       if (GDK_WINDOW_IS_MAPPED (private))
1399         {
1400           GdkWindow    *mousewin;
1401           GdkRectangle  new = { x, y, width, height };
1402
1403           gdk_rectangle_union (&new, &old, &new);
1404           gdk_window_invalidate_rect (GDK_WINDOW (private->parent), &new,TRUE);
1405
1406           /* The window the pointer is in might have changed */
1407           mousewin = gdk_window_at_pointer (NULL, NULL);
1408           gdk_directfb_window_send_crossing_events (NULL, mousewin,
1409                                                     GDK_CROSSING_NORMAL);
1410         }
1411     }
1412 }
1413
1414 void
1415 gdk_window_reparent (GdkWindow *window,
1416                      GdkWindow *new_parent,
1417                      gint       x,
1418                      gint       y)
1419 {
1420   GdkWindowObject *window_private;
1421   GdkWindowObject *parent_private;
1422   GdkWindowObject *old_parent_private;
1423   GdkWindowImplDirectFB *impl;
1424   GdkWindowImplDirectFB *parent_impl;
1425   GdkVisual             *visual;
1426
1427   g_return_if_fail (GDK_IS_WINDOW (window));
1428
1429   if (GDK_WINDOW_DESTROYED (window))
1430     return;
1431
1432   if (!new_parent)
1433     new_parent = _gdk_parent_root;
1434
1435   window_private = (GdkWindowObject *) window;
1436   old_parent_private = (GdkWindowObject *) window_private->parent;
1437   parent_private = (GdkWindowObject *) new_parent;
1438   parent_impl = GDK_WINDOW_IMPL_DIRECTFB (parent_private->impl);
1439   visual = gdk_drawable_get_visual (window);
1440
1441   /* already parented */
1442   if( window_private->parent == (GdkWindowObject *)new_parent )
1443           return;
1444
1445   window_private->parent = (GdkWindowObject *) new_parent;
1446
1447   if (old_parent_private)
1448     {
1449       old_parent_private->children =
1450         g_list_remove (old_parent_private->children, window);
1451     }
1452
1453     parent_private->children = g_list_prepend (parent_private->children, window);
1454
1455     impl = GDK_WINDOW_IMPL_DIRECTFB (window_private->impl);
1456
1457     if( impl->drawable.surface ) {
1458         impl->drawable.surface->Release (impl->drawable.surface);
1459         impl->drawable.surface = NULL;
1460     }
1461
1462     if( impl->window != NULL ) { 
1463         gdk_directfb_window_id_table_remove (impl->dfb_id);
1464         impl->window->SetOpacity (impl->window,0);
1465                 impl->window->Close(impl->window);
1466         impl->window->Release(impl->window);
1467         impl->window = NULL;
1468     }
1469
1470     //create window were a child of the root now
1471     if( window_private->parent == (GdkWindowObject *)_gdk_parent_root)  {
1472         DFBWindowDescription  desc;
1473         DFBWindowOptions  window_options = DWOP_NONE;
1474         desc.flags = DWDESC_CAPS;
1475         if( window_private->input_only ) {
1476             desc.caps = DWCAPS_INPUTONLY;
1477         } else {
1478             desc.flags |= DWDESC_PIXELFORMAT;
1479             desc.pixelformat = ((GdkVisualDirectFB *) visual)->format;
1480             if (DFB_PIXELFORMAT_HAS_ALPHA (desc.pixelformat)) {
1481                 desc.flags |= DWDESC_CAPS;
1482                 desc.caps = DWCAPS_ALPHACHANNEL;
1483             }
1484        }
1485        if( window_private->window_type ==  GDK_WINDOW_CHILD )
1486            window_private->window_type = GDK_WINDOW_TOPLEVEL;
1487         desc.flags |= ( DWDESC_WIDTH | DWDESC_HEIGHT |
1488                       DWDESC_POSX  | DWDESC_POSY );
1489         desc.posx   = x;
1490         desc.posy   = y;
1491         desc.width  = impl->drawable.width;
1492         desc.height = impl->drawable.height;
1493         if (!create_directfb_window (impl, &desc, window_options))
1494         {
1495                   g_assert(0);
1496           _gdk_window_destroy (window, FALSE);
1497           return;
1498         }
1499         /* we hold a reference count on ourselves */
1500         g_object_ref (window);
1501         impl->window->GetID (impl->window, &impl->dfb_id);
1502         gdk_directfb_window_id_table_insert (impl->dfb_id, window);
1503         gdk_directfb_event_windows_add (window);
1504    } else {
1505           DFBRectangle rect = { x, y, impl->drawable.width,
1506                                      impl->drawable.height};
1507           impl->window = NULL;
1508           parent_impl->drawable.surface->GetSubSurface (
1509                           parent_impl->drawable.surface,
1510                           &rect,
1511                           &impl->drawable.surface);
1512    }
1513 }
1514
1515 void
1516 _gdk_windowing_window_clear_area (GdkWindow *window,
1517                                   gint       x,
1518                                   gint       y,
1519                                   gint       width,
1520                                   gint       height)
1521 {
1522   GdkWindowObject         *private;
1523   GdkDrawableImplDirectFB *impl;
1524   GdkPixmap               *bg_pixmap;
1525   GdkWindowObject         *relative_to;
1526   GdkGC                   *gc = NULL;
1527   gint                     dx = 0;
1528   gint                     dy = 0;
1529
1530   g_return_if_fail (GDK_IS_WINDOW (window));
1531
1532   if (GDK_WINDOW_DESTROYED (window))
1533     return;
1534
1535   private = GDK_WINDOW_OBJECT (window);
1536
1537   impl = GDK_DRAWABLE_IMPL_DIRECTFB (private->impl);
1538
1539   /**
1540         Follow XClearArea definition for zero height width
1541   **/
1542   if( width == 0 )  
1543                 width = impl->width-x;
1544   if( height == 0 )  
1545                 height = impl->height-y;
1546
1547   bg_pixmap = private->bg_pixmap;
1548
1549   for (relative_to = private;
1550        relative_to && bg_pixmap == GDK_PARENT_RELATIVE_BG;
1551        relative_to = relative_to->parent)
1552     {
1553       bg_pixmap = relative_to->bg_pixmap;
1554       dx += relative_to->x;
1555       dy += relative_to->y;
1556     }
1557
1558   if (bg_pixmap == GDK_NO_BG)
1559     return;
1560
1561   if (bg_pixmap && bg_pixmap != GDK_PARENT_RELATIVE_BG)
1562     {
1563       GdkGCValues  values;
1564
1565       values.fill = GDK_TILED;
1566       values.tile = bg_pixmap;
1567       values.ts_x_origin = - dx;
1568       values.ts_y_origin = - dy;
1569
1570       gc = gdk_gc_new_with_values (GDK_DRAWABLE (impl), &values,
1571                                    GDK_GC_FILL | GDK_GC_TILE |
1572                                    GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
1573     }
1574   else 
1575     {
1576       /* GDK_PARENT_RELATIVE_BG, but no pixmap,
1577          get the color from the parent window. */
1578
1579       GdkGCValues  values;
1580
1581       values.foreground = relative_to->bg_color;
1582
1583       gc = gdk_gc_new_with_values (GDK_DRAWABLE (impl), &values,
1584                                    GDK_GC_FOREGROUND);
1585     }
1586
1587   gdk_draw_rectangle (GDK_DRAWABLE (impl),
1588                                 gc, TRUE, x, y, width, height);
1589
1590   if (gc)
1591     g_object_unref (gc);
1592 }
1593
1594 void
1595 _gdk_windowing_window_clear_area_e (GdkWindow *window,
1596                                     gint       x,
1597                                     gint       y,
1598                                     gint       width,
1599                                     gint       height)
1600 {
1601   GdkRectangle  rect;
1602   GdkWindowObject       *private;
1603   GdkWindowImplDirectFB *impl;
1604
1605   g_return_if_fail (GDK_IS_WINDOW (window));
1606
1607   private = GDK_WINDOW_OBJECT (window);
1608   impl    = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
1609
1610   /**
1611         Follow XClearArea definition for zero height width
1612   **/
1613   if( width == 0 )  
1614                 width = impl->drawable.width-x;
1615   if( height == 0 )  
1616                 height = impl->drawable.height-y;
1617
1618   rect.x = x;
1619   rect.y = y;
1620   rect.width = width;
1621   rect.height = height;
1622
1623   g_return_if_fail (GDK_IS_WINDOW (window));
1624
1625   if (GDK_WINDOW_DESTROYED (window))
1626     return;
1627
1628   _gdk_windowing_window_clear_area (window, x, y, width, height);
1629
1630   gdk_window_invalidate_rect (window, &rect, TRUE);
1631 }
1632
1633 void
1634 gdk_window_raise (GdkWindow *window)
1635 {
1636   GdkWindowImplDirectFB *impl;
1637
1638   g_return_if_fail (GDK_IS_WINDOW (window));
1639
1640   if (GDK_WINDOW_DESTROYED (window))
1641     return;
1642
1643   impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (window)->impl);
1644
1645   if (impl->window)
1646     {
1647       DFBResult ret;
1648
1649       ret = impl->window->RaiseToTop (impl->window);
1650       if (ret)
1651         DirectFBError ("gdkwindow-directfb.c: RaiseToTop", ret);
1652       else
1653         gdk_directfb_window_raise (window);
1654     }
1655   else
1656     {
1657       if (gdk_directfb_window_raise (window))
1658         gdk_window_invalidate_rect (window, NULL, TRUE);
1659     }
1660 }
1661
1662 void
1663 gdk_window_lower (GdkWindow *window)
1664 {
1665   GdkWindowImplDirectFB *impl;
1666
1667   g_return_if_fail (GDK_IS_WINDOW (window));
1668
1669   if (GDK_WINDOW_DESTROYED (window))
1670     return;
1671
1672   impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (window)->impl);
1673
1674   if (impl->window)
1675     {
1676       DFBResult ret;
1677
1678       ret = impl->window->LowerToBottom (impl->window);
1679       if (ret)
1680         DirectFBError ("gdkwindow-directfb.c: LowerToBottom", ret);
1681       else
1682         gdk_directfb_window_lower (window);
1683     }
1684   else
1685     {
1686       gdk_directfb_window_lower (window);
1687       gdk_window_invalidate_rect (window, NULL, TRUE);
1688     }
1689 }
1690
1691 void
1692 gdk_window_set_hints (GdkWindow *window,
1693                       gint       x,
1694                       gint       y,
1695                       gint       min_width,
1696                       gint       min_height,
1697                       gint       max_width,
1698                       gint       max_height,
1699                       gint       flags)
1700 {
1701   g_return_if_fail (GDK_IS_WINDOW (window));
1702
1703   if (GDK_WINDOW_DESTROYED (window))
1704     return;
1705
1706   /* N/A */
1707 }
1708
1709 void
1710 gdk_window_set_geometry_hints (GdkWindow      *window,
1711                                GdkGeometry    *geometry,
1712                                GdkWindowHints  geom_mask)
1713 {
1714   g_return_if_fail (GDK_IS_WINDOW (window));
1715
1716   if (GDK_WINDOW_DESTROYED (window))
1717     return;
1718
1719   /* N/A */
1720 }
1721
1722 void
1723 gdk_window_set_title (GdkWindow   *window,
1724                       const gchar *title)
1725 {
1726   g_return_if_fail (GDK_IS_WINDOW (window));
1727
1728   if (GDK_WINDOW_DESTROYED (window))
1729     return;
1730
1731   /* N/A */
1732 }
1733
1734 void
1735 gdk_window_set_role (GdkWindow   *window,
1736                      const gchar *role)
1737 {
1738   g_return_if_fail (GDK_IS_WINDOW (window));
1739
1740   if (GDK_WINDOW_DESTROYED (window))
1741     return;
1742
1743   /* N/A */
1744 }
1745
1746 /**
1747  * gdk_window_set_startup_id:
1748  * @window: a toplevel #GdkWindow
1749  * @startup_id: a string with startup-notification identifier
1750  *
1751  * When using GTK+, typically you should use gtk_window_set_startup_id()
1752  * instead of this low-level function.
1753  *
1754  * Since: 2.12
1755  *
1756  **/
1757 void          
1758 gdk_window_set_startup_id (GdkWindow   *window,
1759                      const gchar *startup_id)
1760 {
1761 }
1762
1763 void
1764 gdk_window_set_transient_for (GdkWindow *window,
1765                               GdkWindow *parent)
1766 {
1767   GdkWindowObject *private;
1768   GdkWindowObject *root;
1769   gint i;
1770
1771   g_return_if_fail (GDK_IS_WINDOW (window));
1772   g_return_if_fail (GDK_IS_WINDOW (parent));
1773
1774   private = GDK_WINDOW_OBJECT (window);
1775   root    = GDK_WINDOW_OBJECT (_gdk_parent_root);
1776
1777   g_return_if_fail (GDK_WINDOW (private->parent) == _gdk_parent_root);
1778   g_return_if_fail (GDK_WINDOW (GDK_WINDOW_OBJECT (parent)->parent) == _gdk_parent_root);
1779
1780   root->children = g_list_remove (root->children, window);
1781
1782   i = g_list_index (root->children, parent);
1783   if (i < 0)
1784     root->children = g_list_prepend (root->children, window);
1785   else
1786     root->children = g_list_insert (root->children, window, i);
1787 }
1788
1789 void
1790 gdk_window_set_background (GdkWindow *window,
1791                            const GdkColor  *color)
1792 {
1793   GdkWindowObject *private;
1794
1795   g_return_if_fail (GDK_IS_WINDOW (window));
1796
1797   g_return_if_fail (color != NULL);
1798
1799   private = GDK_WINDOW_OBJECT (window);
1800   private->bg_color = *color;
1801
1802   if (private->bg_pixmap &&
1803       private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1804       private->bg_pixmap != GDK_NO_BG)
1805     g_object_unref (private->bg_pixmap);
1806
1807   private->bg_pixmap = NULL;
1808 }
1809
1810 void
1811 gdk_window_set_back_pixmap (GdkWindow *window,
1812                             GdkPixmap *pixmap,
1813                             gint       parent_relative)
1814 {
1815   GdkWindowObject *private;
1816   GdkPixmap       *old_pixmap;
1817
1818   g_return_if_fail (GDK_IS_WINDOW (window));
1819   g_return_if_fail (pixmap == NULL || !parent_relative);
1820
1821   private = GDK_WINDOW_OBJECT (window);
1822   old_pixmap = private->bg_pixmap;
1823
1824   if (private->bg_pixmap &&
1825       private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
1826       private->bg_pixmap != GDK_NO_BG)
1827     {
1828       g_object_unref (private->bg_pixmap);
1829     }
1830
1831   if (parent_relative)
1832     {
1833       private->bg_pixmap = GDK_PARENT_RELATIVE_BG;
1834     }
1835   else
1836     {
1837       if (pixmap)
1838         {
1839           g_object_ref (pixmap);
1840           private->bg_pixmap = pixmap;
1841         }
1842       else
1843         {
1844           private->bg_pixmap = GDK_NO_BG;
1845         }
1846     }
1847 }
1848
1849 void
1850 gdk_window_set_cursor (GdkWindow *window,
1851                        GdkCursor *cursor)
1852 {
1853   GdkWindowImplDirectFB *impl;
1854   GdkCursor             *old_cursor;
1855
1856   g_return_if_fail (GDK_IS_WINDOW (window));
1857
1858   impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (window)->impl);
1859   old_cursor = impl->cursor;
1860
1861   impl->cursor = (cursor ?
1862                   gdk_cursor_ref (cursor) : gdk_cursor_new (GDK_LEFT_PTR));
1863
1864   if (gdk_window_at_pointer (NULL, NULL) == window)
1865     {
1866       /* This is a bit evil but we want to keep all cursor changes in
1867          one place, so let gdk_directfb_window_send_crossing_events
1868          do the work for us. */
1869
1870       gdk_directfb_window_send_crossing_events (window, window,
1871                                                 GDK_CROSSING_NORMAL);
1872     }
1873   else if (impl->window)
1874     {
1875       GdkCursorDirectFB *dfb_cursor = (GdkCursorDirectFB *) impl->cursor;
1876
1877       /* this branch takes care of setting the cursor for unmapped windows */
1878
1879       impl->window->SetCursorShape (impl->window,
1880                                     dfb_cursor->shape,
1881                                     dfb_cursor->hot_x, dfb_cursor->hot_y);
1882     }
1883
1884   if (old_cursor)
1885     gdk_cursor_unref (old_cursor);
1886 }
1887
1888 void
1889 gdk_window_get_geometry (GdkWindow *window,
1890                          gint      *x,
1891                          gint      *y,
1892                          gint      *width,
1893                          gint      *height,
1894                          gint      *depth)
1895 {
1896   GdkWindowObject         *private;
1897   GdkDrawableImplDirectFB *impl;
1898
1899   g_return_if_fail (GDK_IS_WINDOW (window));
1900
1901   private = GDK_WINDOW_OBJECT (window);
1902   impl    = GDK_DRAWABLE_IMPL_DIRECTFB (private->impl);
1903
1904   if (!GDK_WINDOW_DESTROYED (window))
1905     {
1906       if (x)
1907         *x = private->x;
1908
1909       if (y)
1910         *y = private->y;
1911
1912       if (width)
1913         *width = impl->width;
1914
1915       if (height)
1916         *height = impl->height;
1917
1918       if (depth)
1919         *depth = DFB_BITS_PER_PIXEL(impl->format);
1920     }
1921 }
1922
1923 void
1924 _gdk_directfb_calc_abs (GdkWindow *window)
1925 {
1926   GdkWindowObject         *private;
1927   GdkDrawableImplDirectFB *impl;
1928   GList                   *list;
1929
1930   g_return_if_fail (GDK_IS_WINDOW (window));
1931
1932   private = GDK_WINDOW_OBJECT (window);
1933   impl = GDK_DRAWABLE_IMPL_DIRECTFB (private->impl);
1934
1935   impl->abs_x = private->x;
1936   impl->abs_y = private->y;
1937
1938   if (private->parent)
1939     {
1940       GdkDrawableImplDirectFB *parent_impl =
1941         GDK_DRAWABLE_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (private->parent)->impl);
1942
1943       impl->abs_x += parent_impl->abs_x;
1944       impl->abs_y += parent_impl->abs_y;
1945     }
1946
1947   for (list = private->children; list; list = list->next)
1948     {
1949       _gdk_directfb_calc_abs (list->data);
1950     }
1951 }
1952
1953 gboolean
1954 gdk_window_get_origin (GdkWindow *window,
1955                        gint      *x,
1956                        gint      *y)
1957 {
1958   g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
1959
1960   if (!GDK_WINDOW_DESTROYED (window))
1961     {
1962       GdkDrawableImplDirectFB *impl;
1963
1964       impl = GDK_DRAWABLE_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (window)->impl);
1965
1966       if (x)
1967         *x = impl->abs_x;
1968       if (y)
1969         *y = impl->abs_y;
1970
1971       return TRUE;
1972     }
1973
1974   return FALSE;
1975 }
1976
1977 gboolean
1978 gdk_window_get_deskrelative_origin (GdkWindow *window,
1979                                     gint      *x,
1980                                     gint      *y)
1981 {
1982   return gdk_window_get_origin (window, x, y);
1983 }
1984
1985 void
1986 gdk_window_get_root_origin (GdkWindow *window,
1987                             gint      *x,
1988                             gint      *y)
1989 {
1990   GdkWindowObject *rover;
1991
1992   g_return_if_fail (GDK_IS_WINDOW (window));
1993
1994   rover = (GdkWindowObject*) window;
1995   if (x)
1996     *x = 0;
1997   if (y)
1998     *y = 0;
1999
2000   if (GDK_WINDOW_DESTROYED (window))
2001     return;
2002
2003   while (rover->parent && ((GdkWindowObject*) rover->parent)->parent)
2004     rover = (GdkWindowObject *) rover->parent;
2005   if (rover->destroyed)
2006     return;
2007
2008   if (x)
2009     *x = rover->x;
2010   if (y)
2011     *y = rover->y;
2012 }
2013
2014 GdkWindow *
2015 _gdk_windowing_window_get_pointer (GdkDisplay      *display,
2016                                    GdkWindow       *window,
2017                                    gint            *x,
2018                                    gint            *y,
2019                                    GdkModifierType *mask)
2020 {
2021   GdkWindow               *retval = NULL;
2022   gint                     rx, ry, wx, wy;
2023   GdkDrawableImplDirectFB *impl;
2024
2025   g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
2026
2027   if (!window)
2028     window = _gdk_parent_root;
2029
2030   gdk_directfb_mouse_get_info (&rx, &ry, mask);
2031
2032   wx = rx;
2033   wy = ry;
2034   retval = gdk_directfb_child_at (_gdk_parent_root, &wx, &wy);
2035
2036   impl = GDK_DRAWABLE_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (window)->impl);
2037
2038   if (x)
2039     *x = rx - impl->abs_x;
2040   if (y)
2041     *y = ry - impl->abs_y;
2042
2043   return retval;
2044 }
2045
2046 GdkWindow *
2047 _gdk_windowing_window_at_pointer (GdkDisplay *display,
2048                                   gint       *win_x,
2049                                   gint       *win_y)
2050 {
2051   GdkWindow *retval;
2052   gint       wx, wy;
2053
2054   if (!win_x || !win_y)
2055   gdk_directfb_mouse_get_info (&wx, &wy, NULL);
2056
2057   if (win_x)
2058     wx = *win_x;
2059
2060   if (win_y)
2061     wy = *win_y;
2062
2063   retval = gdk_directfb_child_at (_gdk_parent_root, &wx, &wy);
2064
2065   if (win_x)
2066     *win_x = wx;
2067
2068   if (win_y)
2069     *win_y = wy;
2070
2071   return retval;
2072 }
2073
2074 void
2075 _gdk_windowing_get_pointer (GdkDisplay       *display,
2076                             GdkScreen       **screen,
2077                             gint             *x,
2078                             gint             *y,
2079                             GdkModifierType  *mask)
2080 {
2081 (void)screen;
2082 if(screen) {
2083         *screen = gdk_display_get_default_screen  (display);
2084 }
2085 _gdk_windowing_window_get_pointer (display,
2086                                    _gdk_windowing_window_at_pointer(display,NULL,NULL),x,y,mask);
2087
2088 }
2089
2090 GdkEventMask
2091 gdk_window_get_events (GdkWindow *window)
2092 {
2093   g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2094
2095   if (GDK_WINDOW_DESTROYED (window))
2096     return 0;
2097   else
2098     return GDK_WINDOW_OBJECT (window)->event_mask;
2099 }
2100
2101 void
2102 gdk_window_set_events (GdkWindow    *window,
2103                        GdkEventMask  event_mask)
2104 {
2105   g_return_if_fail (GDK_IS_WINDOW (window));
2106
2107   if (event_mask & GDK_BUTTON_MOTION_MASK)
2108     event_mask |= (GDK_BUTTON1_MOTION_MASK |
2109                    GDK_BUTTON2_MOTION_MASK |
2110                    GDK_BUTTON3_MOTION_MASK);
2111
2112   GDK_WINDOW_OBJECT (window)->event_mask = event_mask;
2113 }
2114
2115 void
2116 gdk_window_shape_combine_mask (GdkWindow *window,
2117                                GdkBitmap *mask,
2118                                gint       x,
2119                                gint       y)
2120 {
2121 }
2122
2123 void
2124 gdk_window_input_shape_combine_mask (GdkWindow *window,
2125                                     GdkBitmap *mask,
2126                                     gint       x,
2127                                     gint       y)
2128 {
2129 }
2130
2131 void
2132 gdk_window_shape_combine_region (GdkWindow       *window,
2133                                  const GdkRegion *shape_region,
2134                                  gint             offset_x,
2135                                  gint             offset_y)
2136 {
2137 }
2138
2139 void
2140 gdk_window_input_shape_combine_region (GdkWindow       *window,
2141                                        const GdkRegion *shape_region,
2142                                        gint             offset_x,
2143                                        gint             offset_y)
2144 {
2145 }
2146
2147 void
2148 gdk_window_set_override_redirect (GdkWindow *window,
2149                                   gboolean   override_redirect)
2150 {
2151   g_return_if_fail (GDK_IS_WINDOW (window));
2152
2153   if (GDK_WINDOW_DESTROYED (window))
2154     return;
2155
2156   /* N/A */
2157 }
2158
2159 void
2160 gdk_window_set_icon_list (GdkWindow *window,
2161                           GList     *pixbufs)
2162 {
2163   g_return_if_fail (GDK_IS_WINDOW (window));
2164
2165   if (GDK_WINDOW_DESTROYED (window))
2166     return;
2167
2168   /* N/A */
2169 }
2170
2171 void
2172 gdk_window_set_icon (GdkWindow *window,
2173                      GdkWindow *icon_window,
2174                      GdkPixmap *pixmap,
2175                      GdkBitmap *mask)
2176 {
2177   g_return_if_fail (GDK_IS_WINDOW (window));
2178
2179   if (GDK_WINDOW_DESTROYED (window))
2180     return;
2181
2182   /* N/A */
2183 }
2184
2185 void
2186 gdk_window_set_icon_name (GdkWindow   *window,
2187                           const gchar *name)
2188 {
2189   g_return_if_fail (GDK_IS_WINDOW (window));
2190
2191   if (GDK_WINDOW_DESTROYED (window))
2192     return;
2193
2194   /* N/A */
2195 }
2196
2197 void
2198 gdk_window_iconify (GdkWindow *window)
2199 {
2200   g_return_if_fail (GDK_IS_WINDOW (window));
2201
2202   if (GDK_WINDOW_DESTROYED (window))
2203     return;
2204
2205   gdk_window_hide (window);
2206 }
2207
2208 void
2209 gdk_window_deiconify (GdkWindow *window)
2210 {
2211   g_return_if_fail (GDK_IS_WINDOW (window));
2212
2213   if (GDK_WINDOW_DESTROYED (window))
2214     return;
2215
2216   gdk_window_show (window);
2217 }
2218
2219 void
2220 gdk_window_stick (GdkWindow *window)
2221 {
2222   g_return_if_fail (GDK_IS_WINDOW (window));
2223
2224   if (GDK_WINDOW_DESTROYED (window))
2225     return;
2226
2227   /* N/A */
2228 }
2229
2230 void
2231 gdk_window_unstick (GdkWindow *window)
2232 {
2233   g_return_if_fail (GDK_IS_WINDOW (window));
2234
2235   if (GDK_WINDOW_DESTROYED (window))
2236     return;
2237
2238   /* N/A */
2239 }
2240
2241 void
2242 gdk_directfb_window_set_opacity (GdkWindow *window,
2243                                  guchar     opacity)
2244 {
2245   GdkWindowImplDirectFB *impl;
2246
2247   g_return_if_fail (GDK_IS_WINDOW (window));
2248
2249   if (GDK_WINDOW_DESTROYED (window))
2250     return;
2251
2252   impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (window)->impl);
2253
2254   impl->opacity = opacity;
2255
2256   if (impl->window && GDK_WINDOW_IS_MAPPED (window))
2257     {
2258       if (gdk_directfb_apply_focus_opacity &&
2259           window == gdk_directfb_focused_window)
2260         impl->window->SetOpacity (impl->window,
2261                                   (impl->opacity >> 1) + (impl->opacity >> 2));
2262       else
2263         impl->window->SetOpacity (impl->window, impl->opacity);
2264     }
2265 }
2266
2267 void
2268 gdk_window_focus (GdkWindow *window,
2269                   guint32    timestamp)
2270 {
2271   GdkWindow *toplevel;
2272
2273   g_return_if_fail (GDK_IS_WINDOW (window));
2274
2275   if (GDK_WINDOW_DESTROYED (window))
2276     return;
2277
2278   toplevel = gdk_directfb_window_find_toplevel (window);
2279   if (toplevel != _gdk_parent_root)
2280     {
2281       GdkWindowImplDirectFB *impl;
2282
2283       impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (toplevel)->impl);
2284
2285       impl->window->RequestFocus (impl->window);
2286     }
2287 }
2288
2289 void
2290 gdk_window_maximize (GdkWindow *window)
2291 {
2292   g_return_if_fail (GDK_IS_WINDOW (window));
2293
2294   if (GDK_WINDOW_DESTROYED (window))
2295     return;
2296
2297   /* N/A */
2298 }
2299
2300 void
2301 gdk_window_unmaximize (GdkWindow *window)
2302 {
2303   g_return_if_fail (GDK_IS_WINDOW (window));
2304
2305   if (GDK_WINDOW_DESTROYED (window))
2306     return;
2307
2308   /* N/A */
2309 }
2310
2311 void
2312 gdk_window_set_type_hint (GdkWindow        *window,
2313                           GdkWindowTypeHint hint)
2314 {
2315   g_return_if_fail (GDK_IS_WINDOW (window));
2316
2317   if (GDK_WINDOW_DESTROYED (window))
2318     return;
2319
2320   GDK_NOTE (MISC, g_print ("gdk_window_set_type_hint: 0x%x: %d\n",
2321                GDK_WINDOW_DFB_ID (window), hint));
2322
2323   ((GdkWindowImplDirectFB *)((GdkWindowObject *)window)->impl)->type_hint = hint;
2324
2325
2326   /* N/A */
2327 }
2328
2329 GdkWindowTypeHint
2330 gdk_window_get_type_hint (GdkWindow *window)
2331 {
2332   g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_WINDOW_TYPE_HINT_NORMAL);
2333   
2334   if (GDK_WINDOW_DESTROYED (window))
2335     return GDK_WINDOW_TYPE_HINT_NORMAL;
2336
2337   return GDK_WINDOW_IMPL_DIRECTFB (((GdkWindowObject *) window)->impl)->type_hint;
2338 }
2339
2340 void
2341 gdk_window_set_modal_hint (GdkWindow *window,
2342                            gboolean   modal)
2343 {
2344   GdkWindowImplDirectFB *impl;
2345
2346   g_return_if_fail (GDK_IS_WINDOW (window));
2347
2348   if (GDK_WINDOW_DESTROYED (window))
2349     return;
2350
2351   impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (window)->impl);
2352
2353   if (impl->window)
2354     {
2355       impl->window->SetStackingClass (impl->window,
2356                                       modal ? DWSC_UPPER : DWSC_MIDDLE);
2357     }
2358 }
2359
2360 void
2361 gdk_window_set_skip_taskbar_hint (GdkWindow *window,
2362                                   gboolean   skips_taskbar)
2363 {
2364   g_return_if_fail (GDK_IS_WINDOW (window));
2365 }
2366
2367 void
2368 gdk_window_set_skip_pager_hint (GdkWindow *window,
2369                                 gboolean   skips_pager)
2370 {
2371   g_return_if_fail (GDK_IS_WINDOW (window));
2372 }
2373
2374
2375 void
2376 gdk_window_set_group (GdkWindow *window,
2377                       GdkWindow *leader)
2378 {
2379   g_return_if_fail (GDK_IS_WINDOW (window));
2380   g_return_if_fail (GDK_IS_WINDOW (leader));
2381  g_warning(" DirectFb set_group groups not supported \n");
2382
2383   if (GDK_WINDOW_DESTROYED (window))
2384     return;
2385
2386   /* N/A */
2387 }
2388
2389 GdkWindow * gdk_window_get_group (GdkWindow *window)
2390 {
2391  g_warning(" DirectFb get_group groups not supported \n");
2392  return window; 
2393 }
2394
2395 void
2396 gdk_fb_window_set_child_handler (GdkWindow             *window,
2397                                  GdkWindowChildChanged  changed,
2398                                  GdkWindowChildGetPos   get_pos,
2399                                  gpointer               user_data)
2400 {
2401   GdkWindowChildHandlerData *data;
2402
2403   g_return_if_fail (GDK_IS_WINDOW (window));
2404
2405   data = g_new (GdkWindowChildHandlerData, 1);
2406   data->changed   = changed;
2407   data->get_pos   = get_pos;
2408   data->user_data = user_data;
2409
2410   g_object_set_data_full (G_OBJECT (window), "gdk-window-child-handler",
2411                           data, (GDestroyNotify) g_free);
2412 }
2413
2414 void
2415 gdk_window_set_decorations (GdkWindow       *window,
2416                             GdkWMDecoration  decorations)
2417 {
2418   GdkWMDecoration *dec;
2419
2420   g_return_if_fail (GDK_IS_WINDOW (window));
2421
2422   dec = g_new (GdkWMDecoration, 1);
2423   *dec = decorations;
2424
2425   g_object_set_data_full (G_OBJECT (window), "gdk-window-decorations",
2426                           dec, (GDestroyNotify) g_free);
2427 }
2428
2429 gboolean
2430 gdk_window_get_decorations (GdkWindow       *window,
2431                             GdkWMDecoration *decorations)
2432 {
2433   GdkWMDecoration *dec;
2434
2435   g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2436
2437   dec = g_object_get_data (G_OBJECT (window), "gdk-window-decorations");
2438   if (dec)
2439     {
2440       *decorations = *dec;
2441       return TRUE;
2442     }
2443   return FALSE;
2444 }
2445
2446 void
2447 gdk_window_set_functions (GdkWindow     *window,
2448                           GdkWMFunction  functions)
2449 {
2450   g_return_if_fail (GDK_IS_WINDOW (window));
2451
2452   if (GDK_WINDOW_DESTROYED (window))
2453     return;
2454
2455   /* N/A */
2456   g_message("unimplemented %s", G_GNUC_FUNCTION);
2457 }
2458
2459 void
2460 gdk_window_set_child_shapes (GdkWindow *window)
2461 {
2462 }
2463
2464 void
2465 gdk_window_merge_child_shapes (GdkWindow *window)
2466 {
2467 }
2468
2469 void
2470 gdk_window_set_child_input_shapes (GdkWindow *window)
2471 {
2472 }
2473
2474 void
2475 gdk_window_merge_child_input_shapes (GdkWindow *window)
2476 {
2477 }
2478
2479 gboolean
2480 gdk_window_set_static_gravities (GdkWindow *window,
2481                                  gboolean   use_static)
2482 {
2483   g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
2484
2485   if (GDK_WINDOW_DESTROYED (window))
2486     return FALSE;
2487
2488   /* N/A */
2489   g_message("unimplemented %s", G_GNUC_FUNCTION);
2490
2491   return FALSE;
2492 }
2493
2494 void
2495 gdk_window_begin_resize_drag (GdkWindow     *window,
2496                               GdkWindowEdge  edge,
2497                               gint           button,
2498                               gint           root_x,
2499                               gint           root_y,
2500                               guint32        timestamp)
2501 {
2502   g_return_if_fail (GDK_IS_WINDOW (window));
2503
2504   if (GDK_WINDOW_DESTROYED (window))
2505     return;
2506
2507   g_message("unimplemented %s", G_GNUC_FUNCTION);
2508 }
2509
2510 void
2511 gdk_window_begin_move_drag (GdkWindow *window,
2512                             gint       button,
2513                             gint       root_x,
2514                             gint       root_y,
2515                             guint32    timestamp)
2516 {
2517   g_return_if_fail (GDK_IS_WINDOW (window));
2518
2519   if (GDK_WINDOW_DESTROYED (window))
2520     return;
2521
2522   g_message("unimplemented %s", G_GNUC_FUNCTION);
2523 }
2524
2525 /**
2526  * gdk_window_get_frame_extents:
2527  * @window: a #GdkWindow
2528  * @rect: rectangle to fill with bounding box of the window frame
2529  *
2530  * Obtains the bounding box of the window, including window manager
2531  * titlebar/borders if any. The frame position is given in root window
2532  * coordinates. To get the position of the window itself (rather than
2533  * the frame) in root window coordinates, use gdk_window_get_origin().
2534  *
2535  **/
2536 void
2537 gdk_window_get_frame_extents (GdkWindow    *window,
2538                               GdkRectangle *rect)
2539 {
2540   GdkWindowObject         *private;
2541   GdkDrawableImplDirectFB *impl;
2542
2543   g_return_if_fail (GDK_IS_WINDOW (window));
2544   g_return_if_fail (rect != NULL);
2545
2546   if (GDK_WINDOW_DESTROYED (window))
2547     return;
2548
2549   private = GDK_WINDOW_OBJECT (window);
2550
2551   while (private->parent && ((GdkWindowObject*) private->parent)->parent)
2552     private = (GdkWindowObject*) private->parent;
2553   if (GDK_WINDOW_DESTROYED (window))
2554     return;
2555
2556   impl = GDK_DRAWABLE_IMPL_DIRECTFB (private->impl);
2557
2558   rect->x      = impl->abs_x;
2559   rect->y      = impl->abs_x;
2560   rect->width  = impl->width;
2561   rect->height = impl->height;
2562 }
2563
2564 /*
2565  * Given a directfb window and a subsurface of that window
2566  * create a gdkwindow child wrapper
2567  */
2568 #if (DIRECTFB_MAJOR_VERSION >= 1)
2569 GdkWindow *gdk_directfb_create_child_window(GdkWindow *parent,
2570                                 IDirectFBSurface *subsurface)
2571 {
2572   GdkWindow             *window;
2573   GdkWindowObject       *private;
2574   GdkWindowObject       *parent_private;
2575   GdkWindowImplDirectFB *impl;
2576   GdkWindowImplDirectFB *parent_impl;
2577   gint x,y,w,h;
2578
2579   g_return_val_if_fail (parent != NULL, NULL);
2580
2581   window = g_object_new (GDK_TYPE_WINDOW, NULL);
2582   private = GDK_WINDOW_OBJECT (window);
2583   parent_private = GDK_WINDOW_OBJECT (parent);
2584   parent_impl = GDK_WINDOW_IMPL_DIRECTFB (parent_private->impl);
2585   private->parent = parent_private;
2586
2587   subsurface->GetPosition(subsurface,&x,&y);
2588   subsurface->GetSize(subsurface,&w,&h);
2589
2590   impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
2591   impl->drawable.wrapper = GDK_DRAWABLE (window);
2592
2593   private->x = x;
2594   private->y = y;
2595
2596   _gdk_directfb_calc_abs (window);
2597
2598   impl->drawable.width  = w;
2599   impl->drawable.height = h;
2600   private->window_type = GDK_WINDOW_CHILD;
2601   impl->drawable.surface = subsurface;
2602   impl->drawable.format = parent_impl->drawable.format;
2603   private->depth = parent_private->depth;
2604   gdk_drawable_set_colormap (GDK_DRAWABLE (window),
2605         gdk_drawable_get_colormap (parent));
2606   gdk_window_set_cursor (window, NULL);
2607   parent_private->children = g_list_prepend (parent_private->children,window);
2608   /*we hold a reference count on ourselves */
2609   g_object_ref (window);
2610
2611   return window;
2612
2613 }
2614 #endif
2615
2616 /*
2617  * The wrapping is not perfect since directfb does not give full access
2618  * to the current state of a window event mask etc need to fix dfb
2619  */
2620 GdkWindow *
2621 gdk_window_foreign_new_for_display (GdkDisplay* display,GdkNativeWindow anid)
2622 {
2623     GdkWindow *window = NULL;
2624     GdkWindow              *parent =NULL;
2625     GdkWindowObject       *private =NULL;
2626     GdkWindowObject       *parent_private =NULL;
2627     GdkWindowImplDirectFB *parent_impl =NULL;
2628     GdkWindowImplDirectFB *impl =NULL;
2629     DFBWindowOptions options;
2630     DFBResult        ret;
2631     GdkDisplayDFB * gdkdisplay =  _gdk_display;
2632     IDirectFBWindow *dfbwindow;
2633
2634     window = gdk_window_lookup (anid);
2635
2636     if (window) {
2637         g_object_ref (window);
2638         return window;
2639     }
2640     if( display != NULL )
2641             gdkdisplay = GDK_DISPLAY_DFB(display);
2642
2643     ret = gdkdisplay->layer->GetWindow (gdkdisplay->layer,
2644                     (DFBWindowID)anid,&dfbwindow);
2645
2646     if (ret != DFB_OK) {
2647         DirectFBError ("gdk_window_new: Layer->GetWindow failed", ret);
2648         return NULL;
2649     }
2650
2651     parent = _gdk_parent_root;
2652
2653     if(parent) {
2654         parent_private = GDK_WINDOW_OBJECT (parent);
2655         parent_impl = GDK_WINDOW_IMPL_DIRECTFB (parent_private->impl);
2656     }
2657
2658     window = g_object_new (GDK_TYPE_WINDOW, NULL);
2659     /* we hold a reference count on ourselves */
2660     g_object_ref (window);
2661     private = GDK_WINDOW_OBJECT (window);
2662     private->parent = parent_private;
2663     private->window_type = GDK_WINDOW_TOPLEVEL;
2664     impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
2665
2666     impl->drawable.wrapper = GDK_DRAWABLE (window);
2667     impl->window = dfbwindow;
2668     dfbwindow->GetOptions(dfbwindow,&options);
2669     dfbwindow->GetPosition(dfbwindow,&private->x,&private->y);
2670     dfbwindow->GetSize(dfbwindow,&impl->drawable.width,&impl->drawable.height);
2671
2672
2673     private->input_only = FALSE;
2674
2675     if( dfbwindow->GetSurface (dfbwindow, &impl->drawable.surface) == DFB_UNSUPPORTED ){
2676         private->input_only = TRUE;
2677         impl->drawable.surface = NULL;
2678     }
2679     /*
2680      * Position ourselevs
2681      */
2682     _gdk_directfb_calc_abs (window);
2683
2684     /* We default to all events least surprise to the user 
2685      * minus the poll for motion events 
2686      */
2687     gdk_window_set_events (window, (GDK_ALL_EVENTS_MASK ^ GDK_POINTER_MOTION_HINT_MASK));
2688
2689     if (impl->drawable.surface)
2690     {
2691       impl->drawable.surface->GetPixelFormat (impl->drawable.surface,
2692                                               &impl->drawable.format);
2693
2694           private->depth = DFB_BITS_PER_PIXEL(impl->drawable.format);
2695       if( parent )
2696         gdk_drawable_set_colormap (GDK_DRAWABLE (window), gdk_drawable_get_colormap (parent));
2697       else
2698         gdk_drawable_set_colormap (GDK_DRAWABLE (window), gdk_colormap_get_system());
2699     }
2700
2701     //can  be null for the soft cursor window itself when
2702     //running a gtk directfb wm
2703     if( gdk_display_get_default() != NULL ) {
2704         gdk_window_set_cursor (window,NULL);
2705     }
2706
2707     if (parent_private)
2708         parent_private->children = g_list_prepend (parent_private->children,
2709                                                window);
2710     impl->dfb_id = (DFBWindowID)anid; 
2711     gdk_directfb_window_id_table_insert (impl->dfb_id, window);
2712     gdk_directfb_event_windows_add (window);
2713
2714     return window;
2715 }
2716
2717 GdkWindow *
2718 gdk_window_lookup_for_display (GdkDisplay *display,GdkNativeWindow anid)
2719 {
2720   return gdk_directfb_window_id_table_lookup ((DFBWindowID) anid);
2721 }
2722
2723 GdkWindow *
2724 gdk_window_lookup (GdkNativeWindow anid)
2725 {
2726   return gdk_directfb_window_id_table_lookup ((DFBWindowID) anid);
2727 }
2728
2729 IDirectFBWindow *gdk_directfb_window_lookup(GdkWindow *window )
2730 {
2731   GdkWindowObject       *private;
2732   GdkWindowImplDirectFB *impl;
2733   g_return_val_if_fail (GDK_IS_WINDOW (window),NULL);
2734   private = GDK_WINDOW_OBJECT (window);
2735   impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
2736   return impl->window;
2737 }
2738
2739 IDirectFBSurface *gdk_directfb_surface_lookup(GdkWindow *window)
2740 {
2741   GdkWindowObject       *private;
2742   GdkWindowImplDirectFB *impl;
2743   g_return_val_if_fail (GDK_IS_WINDOW (window),NULL);
2744   private = GDK_WINDOW_OBJECT (window);
2745   impl = GDK_WINDOW_IMPL_DIRECTFB (private->impl);
2746   return impl->drawable.surface;
2747 }
2748
2749 void
2750 gdk_window_fullscreen (GdkWindow *window)
2751 {
2752   g_return_if_fail (GDK_IS_WINDOW (window));
2753   g_warning ("gdk_window_fullscreen() not implemented.\n");
2754 }
2755
2756 void
2757 gdk_window_unfullscreen (GdkWindow *window)
2758 {
2759   g_return_if_fail (GDK_IS_WINDOW (window));
2760   /* g_warning ("gdk_window_unfullscreen() not implemented.\n");*/
2761 }
2762
2763 void
2764 gdk_window_set_keep_above (GdkWindow *window, gboolean setting)
2765 {
2766   g_return_if_fail (GDK_IS_WINDOW (window));
2767   static gboolean first_call = TRUE;
2768   if (first_call) {
2769   g_warning ("gdk_window_set_keep_above() not implemented.\n");
2770         first_call=FALSE;
2771   }
2772         
2773 }
2774
2775 void
2776 gdk_window_set_keep_below (GdkWindow *window, gboolean setting)
2777 {
2778   g_return_if_fail (GDK_IS_WINDOW (window));
2779   static gboolean first_call = TRUE;
2780   if (first_call) {
2781   g_warning ("gdk_window_set_keep_below() not implemented.\n");
2782   first_call=FALSE;
2783   }
2784   
2785 }
2786
2787 void
2788 gdk_window_enable_synchronized_configure (GdkWindow *window)
2789 {
2790 }
2791
2792 void
2793 gdk_window_configure_finished (GdkWindow *window)
2794 {
2795 }
2796
2797 void
2798 gdk_display_warp_pointer (GdkDisplay *display,
2799                           GdkScreen  *screen,
2800                           gint        x,
2801                           gint        y)
2802 {
2803   g_warning ("gdk_display_warp_pointer() not implemented.\n");
2804 }
2805
2806 void
2807 gdk_window_set_urgency_hint (GdkWindow *window,
2808                              gboolean   urgent)
2809 {
2810   g_return_if_fail (GDK_IS_WINDOW (window));
2811   g_return_if_fail (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD);
2812
2813   if (GDK_WINDOW_DESTROYED (window))
2814     return;
2815
2816   g_warning ("gdk_window_set_urgency_hint() not implemented.\n");
2817
2818 }
2819
2820 static void
2821 gdk_window_impl_directfb_invalidate_maybe_recurse (GdkPaintable *paintable,
2822                                                    GdkRegion    *region,
2823                                                    gboolean    (*child_func) (GdkWindow *, gpointer),
2824                                                    gpointer      user_data)
2825 {
2826   GdkWindow *window;
2827   GdkWindowObject *private;
2828   GdkWindowImplDirectFB *wimpl;
2829   GdkDrawableImplDirectFB *impl;
2830
2831   wimpl = GDK_WINDOW_IMPL_DIRECTFB (paintable);
2832   impl = (GdkDrawableImplDirectFB *)wimpl;
2833   window = wimpl->gdkWindow;
2834   private = (GdkWindowObject *)window;
2835
2836   GdkRegion visible_region;
2837   GList *tmp_list;
2838
2839   g_return_if_fail (window != NULL);
2840   g_return_if_fail (GDK_IS_WINDOW (window));
2841
2842   if (GDK_WINDOW_DESTROYED (window))
2843     return;
2844   
2845   if (private->input_only || !GDK_WINDOW_IS_MAPPED (window))
2846     return;
2847
2848   temp_region_init_rectangle_vals( &visible_region, 0, 0, impl->width, impl->height );
2849   gdk_region_intersect (&visible_region, region);
2850
2851   tmp_list = private->children;
2852   while (tmp_list)
2853     {
2854       GdkWindowObject         *child = tmp_list->data;
2855       GdkDrawableImplDirectFB *cimpl = (GdkDrawableImplDirectFB *) child->impl;
2856       
2857       if (!child->input_only)
2858         {
2859           GdkRegion child_region;
2860           
2861           temp_region_init_rectangle_vals( &child_region, child->x, child->y, cimpl->width, cimpl->height );
2862           
2863           /* remove child area from the invalid area of the parent */
2864           if (GDK_WINDOW_IS_MAPPED (child) && !child->shaped)
2865             gdk_region_subtract (&visible_region, &child_region);
2866           
2867           if (child_func && (*child_func) ((GdkWindow *)child, user_data))
2868             {
2869               gdk_region_offset (region, - child->x, - child->y);
2870               gdk_region_offset (&child_region, - child->x, - child->y);
2871               gdk_region_intersect (&child_region, region);
2872               
2873               gdk_window_invalidate_maybe_recurse ((GdkWindow *)child,
2874                                                    &child_region, child_func, user_data);
2875               
2876               gdk_region_offset (region, child->x, child->y);
2877             }
2878
2879           temp_region_deinit( &child_region );
2880         }
2881
2882       tmp_list = tmp_list->next;
2883     }
2884   
2885   if (!gdk_region_empty (&visible_region))
2886     {
2887       
2888       if (private->update_area)
2889         {
2890           gdk_region_union (private->update_area, &visible_region);
2891         }
2892       else
2893         {
2894           update_windows = g_slist_prepend (update_windows, window);
2895           private->update_area = gdk_region_copy (&visible_region);
2896           gdk_window_schedule_update (window);
2897         }
2898     }
2899
2900   temp_region_deinit( &visible_region );
2901 }
2902
2903
2904 static void
2905 gdk_window_impl_directfb_process_updates (GdkPaintable *paintable,
2906                                           gboolean      update_children)
2907 {
2908   GdkWindow *window;
2909   GdkWindowObject *private;
2910   GdkWindowImplDirectFB *wimpl;
2911   GdkDrawableImplDirectFB *impl;
2912
2913   wimpl = GDK_WINDOW_IMPL_DIRECTFB (paintable);
2914   impl = (GdkDrawableImplDirectFB *)wimpl;
2915   window = wimpl->gdkWindow;
2916   private = (GdkWindowObject *)window;
2917   gboolean save_region = FALSE;
2918
2919   /* If an update got queued during update processing, we can get a
2920    * window in the update queue that has an empty update_area.
2921    * just ignore it.
2922    */
2923   if (private->update_area)
2924     {
2925       GdkRegion *update_area = private->update_area;
2926       private->update_area = NULL;
2927       
2928       if (_gdk_event_func && gdk_window_is_viewable (window))
2929         {
2930           GdkRegion *expose_region;
2931           GdkRegion  window_region;
2932           save_region = _gdk_windowing_window_queue_antiexpose (window, update_area);
2933
2934           if (save_region)
2935             expose_region = gdk_region_copy (update_area);
2936           else
2937             expose_region = update_area;
2938           
2939           temp_region_init_rectangle_vals( &window_region, 0, 0, impl->width, impl->height );
2940           gdk_region_intersect (expose_region,
2941                                 &window_region);
2942           temp_region_deinit (&window_region);
2943           
2944           if (!gdk_region_empty (expose_region) &&
2945               (private->event_mask & GDK_EXPOSURE_MASK))
2946             {
2947               GdkEvent event;
2948               
2949               event.expose.type = GDK_EXPOSE;
2950               event.expose.window = g_object_ref (window);
2951               event.expose.send_event = FALSE;
2952               event.expose.count = 0;
2953               event.expose.region = expose_region;
2954               gdk_region_get_clipbox (expose_region, &event.expose.area);
2955               (*_gdk_event_func) (&event, _gdk_event_data);
2956               
2957               g_object_unref (window);
2958             }
2959
2960           if (expose_region != update_area)
2961             gdk_region_destroy (expose_region);
2962         }
2963       if (!save_region)
2964         gdk_region_destroy (update_area);
2965     }
2966 }
2967
2968
2969 static void
2970 gdk_window_impl_directfb_begin_paint_region (GdkPaintable *paintable,
2971                                              GdkRegion    *region)
2972 {
2973   GdkDrawableImplDirectFB *impl;
2974   GdkWindowImplDirectFB *wimpl;
2975   gint                     i;
2976
2977
2978   g_assert (region != NULL );
2979   wimpl = GDK_WINDOW_IMPL_DIRECTFB (paintable);
2980   impl = (GdkDrawableImplDirectFB *)wimpl;
2981
2982   if (!region)
2983     return;
2984
2985   if (impl->buffered) {
2986        g_assert( impl->paint_depth > 0 );
2987
2988        gdk_region_union (&impl->paint_region, region);
2989   }
2990   else {
2991        g_assert( impl->paint_depth == 0 );
2992
2993        gdk_directfb_clip_region( GDK_DRAWABLE(paintable), NULL, NULL, &impl->clip_region );
2994
2995        temp_region_init_copy( &impl->paint_region, region );
2996
2997        impl->buffered = TRUE;
2998   }
2999
3000   gdk_region_intersect (&impl->paint_region, &impl->clip_region);
3001
3002   impl->paint_depth++;
3003
3004
3005   for (i = 0; i < region->numRects; i++)
3006     {
3007       GdkRegionBox *box = &region->rects[i];
3008
3009       _gdk_windowing_window_clear_area (GDK_WINDOW(wimpl->gdkWindow),
3010                                         box->x1,
3011                                         box->y1,
3012                                         box->x2 - box->x1,
3013                                         box->y2 - box->y1);
3014                                         
3015     }
3016 }
3017
3018 static void
3019 gdk_window_impl_directfb_end_paint (GdkPaintable *paintable)
3020 {
3021   GdkDrawableImplDirectFB *impl;
3022
3023   impl = GDK_DRAWABLE_IMPL_DIRECTFB (paintable);
3024
3025   g_return_if_fail (impl->paint_depth > 0);
3026
3027   g_assert( impl->buffered );
3028
3029   impl->paint_depth--;
3030
3031 #ifdef GDK_DIRECTFB_NO_EXPERIMENTS
3032   if (impl->paint_depth == 0)
3033     {
3034       impl->buffered = FALSE;
3035
3036       if (impl->paint_region.numRects)
3037         {
3038           DFBRegion reg = { impl->paint_region.extents.x1,
3039                             impl->paint_region.extents.y1,
3040                             impl->paint_region.extents.x2 ,
3041                             impl->paint_region.extents.y2 };
3042
3043           impl->surface->Flip( impl->surface, &reg, 0 );
3044
3045           temp_region_reset( &impl->paint_region );
3046         }
3047     }
3048 #else
3049   if (impl->paint_depth == 0) {
3050        impl->buffered = FALSE;
3051
3052        temp_region_deinit( &impl->clip_region );
3053
3054        if (impl->paint_region.numRects) {
3055             GdkWindow *window = GDK_WINDOW( impl->wrapper );
3056
3057             if (GDK_IS_WINDOW(window)) {
3058                  GdkWindowObject *top = GDK_WINDOW_OBJECT( gdk_window_get_toplevel( window ) );
3059
3060                  if (top) {
3061                       DFBRegion              reg;
3062                       GdkWindowImplDirectFB *wimpl = GDK_WINDOW_IMPL_DIRECTFB (top->impl);
3063
3064                       reg.x1 = impl->abs_x - top->x + impl->paint_region.extents.x1;
3065                       reg.y1 = impl->abs_y - top->y + impl->paint_region.extents.y1;
3066                       reg.x2 = impl->abs_x - top->x + impl->paint_region.extents.x2 - 1;
3067                       reg.y2 = impl->abs_y - top->y + impl->paint_region.extents.y2 - 1;
3068
3069                       //direct_log_printf( NULL, "Adding bounding box of paint: %d,%d - %dx%d (top %p, wimpl %p)\n",
3070                       //                   DFB_RECTANGLE_VALS_FROM_REGION( &reg ), top, wimpl );
3071
3072                       dfb_updates_add( &wimpl->flips, &reg );
3073                  }
3074             }
3075
3076             temp_region_reset( &impl->paint_region );
3077        }
3078   }
3079 #endif
3080 }
3081
3082
3083 static void
3084 gdk_window_impl_directfb_paintable_init (GdkPaintableIface *iface)
3085 {
3086   iface->begin_paint_region = gdk_window_impl_directfb_begin_paint_region;
3087   iface->end_paint = gdk_window_impl_directfb_end_paint;
3088
3089   iface->invalidate_maybe_recurse = gdk_window_impl_directfb_invalidate_maybe_recurse;
3090   iface->process_updates = gdk_window_impl_directfb_process_updates;
3091 }
3092
3093 void
3094 gdk_window_beep (GdkWindow *window)
3095 {
3096   gdk_display_beep (gdk_display_get_default());
3097 }
3098
3099 void
3100 gdk_window_set_opacity (GdkWindow *window,
3101                         gdouble    opacity)
3102 {
3103   GdkDisplay *display;
3104   guint8 cardinal;
3105   
3106   g_return_if_fail (GDK_IS_WINDOW (window));
3107
3108   if (GDK_WINDOW_DESTROYED (window))
3109     return;
3110
3111   display = gdk_drawable_get_display (window);
3112
3113   if (opacity < 0)
3114     opacity = 0;
3115   else if (opacity > 1)
3116     opacity = 1;
3117   cardinal = opacity * 0xff;
3118   gdk_directfb_window_set_opacity(window,cardinal);
3119 }
3120
3121 void
3122 _gdk_windowing_window_set_composited (GdkWindow *window,
3123                                       gboolean   composited)
3124 {
3125 }
3126
3127
3128 #define __GDK_WINDOW_X11_C__
3129 #include "gdkaliasdef.c"
3130