1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19 
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.
23  */
24 
25 /*
26  * GTK+ DirectFB backend
27  * Copyright (C) 2001-2002  convergence integrated media GmbH
28  * Copyright (C) 2002-2004  convergence GmbH
29  * Written by Denis Oliver Kropp <dok@convergence.de> and
30  *            Sven Neumann <sven@convergence.de>
31  */
32 
33 #ifndef __GDK_PRIVATE_DIRECTFB_H__
34 #define __GDK_PRIVATE_DIRECTFB_H__
35 
36 //#include <gdk/gdk.h>
37 #include <gdk/gdkprivate.h>
38 #include "gdkinternals.h"
39 #include "gdkcursor.h"
40 #include "gdkdisplay-directfb.h"
41 #include "gdkregion-generic.h"
42 #include <cairo.h>
43 
44 #include <string.h>
45 
46 #include <directfb_util.h>
47 
48 
49 #define GDK_TYPE_DRAWABLE_IMPL_DIRECTFB       (gdk_drawable_impl_directfb_get_type ())
50 #define GDK_DRAWABLE_IMPL_DIRECTFB(object)    (G_TYPE_CHECK_INSTANCE_CAST ((object), \
51                                                                            GDK_TYPE_DRAWABLE_IMPL_DIRECTFB, \
52                                                                            GdkDrawableImplDirectFB))
53 #define GDK_IS_DRAWABLE_IMPL_DIRECTFB(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), \
54                                                                            GDK_TYPE_DRAWABLE_IMPL_DIRECTFB))
55 
56 #define GDK_TYPE_WINDOW_IMPL_DIRECTFB         (gdk_window_impl_directfb_get_type ())
57 #define GDK_WINDOW_IMPL_DIRECTFB(object)      (G_TYPE_CHECK_INSTANCE_CAST ((object), \
58                                                                            GDK_TYPE_WINDOW_IMPL_DIRECTFB, \
59                                                                            GdkWindowImplDirectFB))
60 #define GDK_IS_WINDOW_IMPL_DIRECTFB(object)   (G_TYPE_CHECK_INSTANCE_TYPE ((object), \
61                                                                            GDK_TYPE_WINDOW_IMPL_DIRECTFB))
62 
63 #define GDK_TYPE_PIXMAP_IMPL_DIRECTFB         (gdk_pixmap_impl_directfb_get_type ())
64 #define GDK_PIXMAP_IMPL_DIRECTFB(object)      (G_TYPE_CHECK_INSTANCE_CAST ((object), \
65                                                                            GDK_TYPE_PIXMAP_IMPL_DIRECTFB, \
66                                                                            GdkPixmapImplDirectFB))
67 #define GDK_IS_PIXMAP_IMPL_DIRECTFB(object)   (G_TYPE_CHECK_INSTANCE_TYPE ((object), \
68                                                                            GDK_TYPE_PIXMAP_IMPL_DIRECTFB))
69 
70 
71 typedef struct _GdkDrawableImplDirectFB GdkDrawableImplDirectFB;
72 typedef struct _GdkWindowImplDirectFB   GdkWindowImplDirectFB;
73 typedef struct _GdkPixmapImplDirectFB   GdkPixmapImplDirectFB;
74 
75 
76 struct _GdkDrawableImplDirectFB
77 {
78   GdkDrawable parent_object;
79 
80   GdkDrawable *wrapper;
81 
82   gboolean buffered;
83 
84   GdkRegion paint_region;
85   gint      paint_depth;
86   gint      width;
87   gint      height;
88   gint      abs_x;
89   gint      abs_y;
90 
91   GdkRegion clip_region;
92 
93   GdkColormap *colormap;
94 
95   IDirectFBSurface      *surface;
96   DFBSurfacePixelFormat  format;
97   cairo_surface_t       *cairo_surface;
98 };
99 
100 typedef struct
101 {
102   GdkDrawableClass parent_class;
103 } GdkDrawableImplDirectFBClass;
104 
105 GType      gdk_drawable_impl_directfb_get_type (void);
106 
107 void gdk_directfb_event_fill (GdkEvent     *event,
108                               GdkWindow    *window,
109                               GdkEventType  type);
110 GdkEvent *gdk_directfb_event_make (GdkWindow    *window,
111                                    GdkEventType  type);
112 
113 
114 /*
115  * Pixmap
116  */
117 
118 struct _GdkPixmapImplDirectFB
119 {
120   GdkDrawableImplDirectFB parent_instance;
121 };
122 
123 typedef struct
124 {
125   GdkDrawableImplDirectFBClass parent_class;
126 } GdkPixmapImplDirectFBClass;
127 
128 GType gdk_pixmap_impl_directfb_get_type (void);
129 
130 
131 
132 /*
133  * Window
134  */
135 
136 typedef struct
137 {
138   gulong   length;
139   GdkAtom  type;
140   gint     format;
141   guchar   data[1];
142 } GdkWindowProperty;
143 
144 
145 struct _GdkWindowImplDirectFB
146 {
147   GdkDrawableImplDirectFB drawable;
148 
149   IDirectFBWindow        *window;
150 
151   DFBWindowID             dfb_id;
152 
153   GdkCursor              *cursor;
154   GHashTable             *properties;
155 
156   guint8                  opacity;
157 
158   GdkWindowTypeHint       type_hint;
159 
160   DFBUpdates              flips;
161   DFBRegion               flip_regions[4];
162 };
163 
164 typedef struct
165 {
166   GdkDrawableImplDirectFBClass parent_class;
167 } GdkWindowImplDirectFBClass;
168 
169 GType gdk_window_impl_directfb_get_type        (void);
170 
171 void  gdk_directfb_window_send_crossing_events (GdkWindow       *src,
172                                                 GdkWindow       *dest,
173                                                 GdkCrossingMode  mode);
174 
175 GdkWindow * gdk_directfb_window_find_toplevel  (GdkWindow       *window);
176 
177 
178 void        gdk_directfb_window_id_table_insert (DFBWindowID  dfb_id,
179                                                  GdkWindow   *window);
180 void        gdk_directfb_window_id_table_remove (DFBWindowID  dfb_id);
181 GdkWindow * gdk_directfb_window_id_table_lookup (DFBWindowID  dfb_id);
182 
183 void        _gdk_directfb_window_get_offsets    (GdkWindow       *window,
184                                                  gint            *x_offset,
185                                                  gint            *y_offset);
186 void        _gdk_directfb_window_scroll         (GdkWindow       *window,
187                                                  gint             dx,
188                                                  gint             dy);
189 void        _gdk_directfb_window_move_region    (GdkWindow       *window,
190                                                  const GdkRegion *region,
191                                                  gint             dx,
192                                                  gint             dy);
193 
194 
195 typedef struct
196 {
197   GdkCursor         cursor;
198 
199   gint              hot_x;
200   gint              hot_y;
201   IDirectFBSurface *shape;
202 } GdkCursorDirectFB;
203 
204 typedef struct
205 {
206   GdkVisual              visual;
207   DFBSurfacePixelFormat  format;
208 } GdkVisualDirectFB;
209 
210 typedef struct
211 {
212   IDirectFBSurface *surface;
213 } GdkImageDirectFB;
214 
215 
216 #define GDK_TYPE_GC_DIRECTFB       (_gdk_gc_directfb_get_type ())
217 #define GDK_GC_DIRECTFB(object)    (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_GC_DIRECTFB, GdkGCDirectFB))
218 #define GDK_IS_GC_DIRECTFB(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_GC_DIRECTFB))
219 
220 typedef struct
221 {
222   GdkGC             parent_instance;
223 
224   GdkRegion         clip_region;
225 
226   GdkGCValuesMask   values_mask;
227   GdkGCValues       values;
228 } GdkGCDirectFB;
229 
230 typedef struct
231 {
232   GdkGCClass        parent_class;
233 } GdkGCDirectFBClass;
234 
235 GType     _gdk_gc_directfb_get_type (void);
236 
237 GdkGC    *_gdk_directfb_gc_new      (GdkDrawable     *drawable,
238                                      GdkGCValues     *values,
239                                      GdkGCValuesMask  values_mask);
240 
241 GdkImage* _gdk_directfb_copy_to_image (GdkDrawable  *drawable,
242                                        GdkImage     *image,
243                                        gint          src_x,
244                                        gint          src_y,
245                                        gint          dest_x,
246                                        gint          dest_y,
247                                        gint          width,
248                                        gint          height);
249 
250 void       gdk_directfb_event_windows_add    (GdkWindow *window);
251 void       gdk_directfb_event_windows_remove (GdkWindow *window);
252 
253 GdkGrabStatus gdk_directfb_keyboard_grab  (GdkDisplay          *display,
254                                            GdkWindow           *window,
255                                            gint                 owner_events,
256                                            guint32              time);
257 
258 void          gdk_directfb_keyboard_ungrab(GdkDisplay          *display,
259                                            guint32              time);
260 
261 GdkGrabStatus gdk_directfb_pointer_grab   (GdkWindow           *window,
262                                            gint                 owner_events,
263                                            GdkEventMask         event_mask,
264                                            GdkWindow           *confine_to,
265                                            GdkCursor           *cursor,
266                                            guint32              time,
267                                            gboolean             implicit_grab);
268 void          gdk_directfb_pointer_ungrab (guint32              time,
269                                            gboolean             implicit_grab);
270 
271 guint32       gdk_directfb_get_time       (void);
272 
273 GdkWindow  *gdk_directfb_pointer_event_window  (GdkWindow    *window,
274                                                 GdkEventType  type);
275 GdkWindow  *gdk_directfb_keyboard_event_window (GdkWindow    *window,
276                                                 GdkEventType  type);
277 GdkWindow  *gdk_directfb_other_event_window    (GdkWindow    *window,
278                                                 GdkEventType  type);
279 void       _gdk_selection_window_destroyed    (GdkWindow       *window);
280 
281 void       _gdk_directfb_move_resize_child (GdkWindow *window,
282                                             gint       x,
283                                             gint       y,
284                                             gint       width,
285                                             gint       height);
286 
287 GdkWindow  *gdk_directfb_child_at          (GdkWindow *window,
288                                             gint      *x,
289                                             gint      *y);
290 
291 GdkWindow  *gdk_directfb_window_find_focus (void);
292 
293 void        gdk_directfb_change_focus      (GdkWindow *new_focus_window);
294 
295 void        gdk_directfb_mouse_get_info    (gint            *x,
296                                             gint            *y,
297                                             GdkModifierType *mask);
298 
299 /**********************/
300 /*  Global variables  */
301 /**********************/
302 
303 extern GdkDisplayDFB *_gdk_display;
304 
305 /* Pointer grab info */
306 extern GdkWindow           * _gdk_directfb_pointer_grab_window;
307 extern gboolean              _gdk_directfb_pointer_grab_owner_events;
308 extern GdkWindow           * _gdk_directfb_pointer_grab_confine;
309 extern GdkEventMask          _gdk_directfb_pointer_grab_events;
310 extern GdkCursor           * _gdk_directfb_pointer_grab_cursor;
311 
312 /* Keyboard grab info */
313 extern GdkWindow           * _gdk_directfb_keyboard_grab_window;
314 extern GdkEventMask          _gdk_directfb_keyboard_grab_events;
315 extern gboolean              _gdk_directfb_keyboard_grab_owner_events;
316 
317 extern GdkScreen  *  _gdk_screen;
318 
319 extern GdkAtom               _gdk_selection_property;
320 
321 
322 IDirectFBPalette * gdk_directfb_colormap_get_palette (GdkColormap *colormap);
323 
324 
325 /* these are Linux-FB specific functions used for window decorations */
326 
327 typedef gboolean (* GdkWindowChildChanged) (GdkWindow *window,
328                                             gint       x,
329                                             gint       y,
330                                             gint       width,
331                                             gint       height,
332                                             gpointer   user_data);
333 typedef void     (* GdkWindowChildGetPos)  (GdkWindow *window,
334                                             gint      *x,
335                                             gint      *y,
336                                             gpointer   user_data);
337 
338 void gdk_fb_window_set_child_handler (GdkWindow              *window,
339                                       GdkWindowChildChanged  changed,
340                                       GdkWindowChildGetPos   get_pos,
341                                       gpointer               user_data);
342 
343 void gdk_directfb_clip_region (GdkDrawable  *drawable,
344                                GdkGC        *gc,
345                                GdkRectangle *draw_rect,
346                                GdkRegion    *ret_clip);
347 
348 
349 /* Utilities for avoiding mallocs */
350 
351 static inline void
temp_region_init_copy(GdkRegion * region,const GdkRegion * source)352 temp_region_init_copy (GdkRegion       *region,
353                        const GdkRegion *source)
354 {
355   if (region != source) /*  don't want to copy to itself */
356     {
357       if (region->size < source->numRects)
358         {
359           if (region->rects && region->rects != &region->extents)
360             g_free (region->rects);
361 
362           region->rects = g_new (GdkRegionBox, source->numRects);
363           region->size  = source->numRects;
364         }
365 
366       region->numRects = source->numRects;
367       region->extents  = source->extents;
368 
369       memcpy (region->rects, source->rects, source->numRects * sizeof (GdkRegionBox));
370     }
371 }
372 
373 static inline void
temp_region_init_rectangle(GdkRegion * region,const GdkRectangle * rect)374 temp_region_init_rectangle (GdkRegion          *region,
375                             const GdkRectangle *rect)
376 {
377   region->numRects   = 1;
378   region->rects      = &region->extents;
379   region->extents.x1 = rect->x;
380   region->extents.y1 = rect->y;
381   region->extents.x2 = rect->x + rect->width;
382   region->extents.y2 = rect->y + rect->height;
383   region->size       = 1;
384 }
385 
386 static inline void
temp_region_init_rectangle_vals(GdkRegion * region,int x,int y,int w,int h)387 temp_region_init_rectangle_vals (GdkRegion *region,
388                                  int        x,
389                                  int        y,
390                                  int        w,
391                                  int        h)
392 {
393   region->numRects   = 1;
394   region->rects      = &region->extents;
395   region->extents.x1 = x;
396   region->extents.y1 = y;
397   region->extents.x2 = x + w;
398   region->extents.y2 = y + h;
399   region->size       = 1;
400 }
401 
402 static inline void
temp_region_reset(GdkRegion * region)403 temp_region_reset (GdkRegion *region)
404 {
405   if (region->size > 32 && region->rects && region->rects != &region->extents) {
406     g_free (region->rects);
407 
408     region->size  = 1;
409     region->rects = &region->extents;
410   }
411 
412   region->numRects = 0;
413 }
414 
415 static inline void
temp_region_deinit(GdkRegion * region)416 temp_region_deinit (GdkRegion *region)
417 {
418   if (region->rects && region->rects != &region->extents) {
419     g_free (region->rects);
420     region->rects = NULL;
421   }
422 
423   region->numRects = 0;
424 }
425 
426 
427 #define GDKDFB_RECTANGLE_VALS_FROM_BOX(s)   (s)->x1, (s)->y1, (s)->x2-(s)->x1, (s)->y2-(s)->y1
428 
429 
430 #endif /* __GDK_PRIVATE_DIRECTFB_H__ */
431