gdkwindow-fb.c 50.4 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
2
3
4
/* GDK - The GIMP Drawing Kit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
6
7
8
9
10
11
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
15
16
17
18
19
20
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
Elliot Lee's avatar
Elliot Lee committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

#include "gdk.h"
#include "config.h"

#include "gdkwindow.h"
#include "gdkinputprivate.h"
#include "gdkprivate-fb.h"
#include "gdkinternals.h"

#include <limits.h>

Alexander Larsson's avatar
Alexander Larsson committed
37
38
/* Global variables: */
static GdkWindow *gdk_fb_window_containing_pointer = NULL;
39
static gpointer parent_class = NULL;
Elliot Lee's avatar
Elliot Lee committed
40

41
static void recompute_drawable (GdkDrawable *drawable);
42
static void gdk_fb_window_raise (GdkWindow *window);
43
44
45
46
static GdkRegion* gdk_window_fb_get_visible_region (GdkDrawable *drawable);

typedef struct
{
47
48
49
  GdkWindowChildChanged  changed;
  GdkWindowChildGetPos   get_pos;
  gpointer               user_data;
50
}  GdkWindowChildHandlerData;
Elliot Lee's avatar
Elliot Lee committed
51
52

static void
53
g_free_2nd (gpointer a, gpointer b, gpointer data)
Elliot Lee's avatar
Elliot Lee committed
54
{
55
  g_free (b);
Elliot Lee's avatar
Elliot Lee committed
56
57
58
}

static void
59
gdk_window_impl_fb_finalize (GObject *object)
Elliot Lee's avatar
Elliot Lee committed
60
{
61
  GdkWindowFBData *fbd = GDK_WINDOW_FBDATA (object);
Elliot Lee's avatar
Elliot Lee committed
62

63
64
  if (GDK_WINDOW_P (fbd->drawable_data.wrapper)->mapped)
    gdk_window_hide (fbd->drawable_data.wrapper);
Elliot Lee's avatar
Elliot Lee committed
65

66
67
  if (fbd->cursor)
    gdk_cursor_unref (fbd->cursor);
Elliot Lee's avatar
Elliot Lee committed
68

69
  if (fbd->properties)
Elliot Lee's avatar
Elliot Lee committed
70
    {
71
72
      g_hash_table_foreach (fbd->properties, g_free_2nd, NULL);
      g_hash_table_destroy (fbd->properties);
Elliot Lee's avatar
Elliot Lee committed
73
74
    }

75
  G_OBJECT_CLASS (parent_class)->finalize (object);
Elliot Lee's avatar
Elliot Lee committed
76
77
}

78
79
static void
gdk_window_impl_fb_class_init (GdkWindowFBClass *klass)
Elliot Lee's avatar
Elliot Lee committed
80
{
81
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
82
  GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
Elliot Lee's avatar
Elliot Lee committed
83
  
84
  parent_class = g_type_class_peek_parent (klass);
Elliot Lee's avatar
Elliot Lee committed
85

86
  object_class->finalize = gdk_window_impl_fb_finalize;
87
88
89
90
  
  /* Visible and clip regions are the same */
  drawable_class->get_clip_region = gdk_window_fb_get_visible_region;
  drawable_class->get_visible_region = gdk_window_fb_get_visible_region;
91
}
Elliot Lee's avatar
Elliot Lee committed
92

93
94
95
96
97
98
static void
gdk_window_impl_fb_init (GdkWindowFBData *impl)
{
  impl->drawable_data.depth = gdk_display->modeinfo.bits_per_pixel;
  impl->drawable_data.colormap = gdk_colormap_get_system ();
  impl->event_mask = GDK_STRUCTURE_MASK;
99
  impl->shape = NULL;
100
}
Elliot Lee's avatar
Elliot Lee committed
101

102
103
104
105
GType
_gdk_window_impl_get_type (void)
{
  static GType object_type = 0;
Elliot Lee's avatar
Elliot Lee committed
106

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  if (!object_type)
    {
      static const GTypeInfo object_info =
      {
        sizeof (GdkWindowFBClass),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) gdk_window_impl_fb_class_init,
        NULL,           /* class_finalize */
        NULL,           /* class_data */
        sizeof (GdkWindowFBData),
        0,              /* n_preallocs */
        (GInstanceInitFunc) gdk_window_impl_fb_init,
      };
      
      object_type = g_type_register_static (gdk_drawable_impl_fb_get_type(),
                                            "GdkWindowFB",
124
125
                                            &object_info,
					    0);
126
127
128
    }
  
  return object_type;
Elliot Lee's avatar
Elliot Lee committed
129
130
131
}

void
132
_gdk_windowing_window_init (void)
Elliot Lee's avatar
Elliot Lee committed
133
{
134
135
  GdkWindowAttr attr;

Elliot Lee's avatar
Elliot Lee committed
136
  GdkCursor *cursor;
137
138
139
140
  GdkWindowObject *private;

  attr.width = gdk_screen_width ();
  attr.height = gdk_screen_height ();
141
  attr.window_type = GDK_WINDOW_ROOT;
142
  attr.cursor = NULL;
143
144
  attr.event_mask = GDK_EXPOSURE_MASK;
  attr.wclass = GDK_INPUT_OUTPUT;
145
146
  gdk_parent_root = gdk_window_new (NULL, &attr, GDK_WA_CURSOR);
  private = (GdkWindowObject *)gdk_parent_root;
Elliot Lee's avatar
Elliot Lee committed
147

148
  private->mapped = TRUE;
Elliot Lee's avatar
Elliot Lee committed
149

150
151
  GDK_DRAWABLE_IMPL_FBDATA (gdk_parent_root)->lim_x = attr.width;
  GDK_DRAWABLE_IMPL_FBDATA (gdk_parent_root)->lim_y = attr.height;
152
153

  _gdk_fb_screen_gc = gdk_gc_new (gdk_parent_root);
154

155
  gdk_fb_drawable_clear (gdk_parent_root);
156
157
158
159
160
161
  
  /* Must be done after root is created, since gdk_cursor_new()
   * references gdk_parent_root.
   */
  cursor = gdk_cursor_new (GDK_LEFT_PTR);
  gdk_window_set_cursor (gdk_parent_root, cursor);
Elliot Lee's avatar
Elliot Lee committed
162
163
164
165
166
167
168
169
}

GdkWindow*
gdk_window_new (GdkWindow     *parent,
		GdkWindowAttr *attributes,
		gint           attributes_mask)
{
  GdkWindow *window;
170
171
  GdkWindowObject *private;
  GdkWindowObject *parent_private;
Elliot Lee's avatar
Elliot Lee committed
172
  GdkVisual *visual;
173
  GdkWindowFBData *impl;
Elliot Lee's avatar
Elliot Lee committed
174
175
176
177
178
179
180
181

  int x, y, depth;
  
  g_return_val_if_fail (attributes != NULL, NULL);
  
  if (!parent || attributes->window_type != GDK_WINDOW_CHILD)
    parent = gdk_parent_root;
  
182
  parent_private = (GdkWindowObject*) parent;
Elliot Lee's avatar
Elliot Lee committed
183
  
184
  window = (GdkWindow *)g_object_new (GDK_TYPE_WINDOW, NULL);
185
  private = (GdkWindowObject *)window;
Elliot Lee's avatar
Elliot Lee committed
186

187
  private->parent = parent_private;
Elliot Lee's avatar
Elliot Lee committed
188
189
190
191
192
193
194
195
196
197
198

  if (attributes_mask & GDK_WA_X)
    x = attributes->x;
  else
    x = 0;

  if (attributes_mask & GDK_WA_Y)
    y = attributes->y;
  else
    y = 0;

199
  gdk_window_set_events (window, attributes->event_mask);
Elliot Lee's avatar
Elliot Lee committed
200
201
202

  if (attributes_mask & GDK_WA_VISUAL)
    visual = attributes->visual;
203
  else
204
    visual = gdk_visual_get_system ();
Elliot Lee's avatar
Elliot Lee committed
205

206
207
  impl = (GdkWindowFBData *)private->impl;
  impl->drawable_data.wrapper = window;
Elliot Lee's avatar
Elliot Lee committed
208
209
  private->x = x;
  private->y = y;
210
211
212
  impl->drawable_data.width = (attributes->width > 1) ? (attributes->width) : (1);
  impl->drawable_data.height = (attributes->height > 1) ? (attributes->height) : (1);
  private->window_type = impl->drawable_data.window_type = attributes->window_type;
Alexander Larsson's avatar
Alexander Larsson committed
213
214
  impl->drawable_data.mem = gdk_display->fb_mem;
  impl->drawable_data.rowstride = gdk_display->fb_stride;
Elliot Lee's avatar
Elliot Lee committed
215
  gdk_window_move_resize (window, x, y,
216
			  impl->drawable_data.width, impl->drawable_data.height);
Elliot Lee's avatar
Elliot Lee committed
217
218
219
220
221
222

  if (attributes->wclass == GDK_INPUT_OUTPUT)
    {
      depth = visual->depth;

      private->input_only = FALSE;
223
      private->depth = impl->drawable_data.depth;
Elliot Lee's avatar
Elliot Lee committed
224
      
225
226
      if ((attributes_mask & GDK_WA_COLORMAP) &&
	  attributes->colormap)
227
228
	impl->drawable_data.colormap = attributes->colormap;
      else
229
	impl->drawable_data.colormap = gdk_colormap_get_system ();
Elliot Lee's avatar
Elliot Lee committed
230
      
231
      switch (impl->drawable_data.window_type)
Elliot Lee's avatar
Elliot Lee committed
232
233
234
235
236
	{
	case GDK_WINDOW_TOPLEVEL:
	case GDK_WINDOW_CHILD:
	case GDK_WINDOW_DIALOG:
	case GDK_WINDOW_TEMP:
237
	default:
Elliot Lee's avatar
Elliot Lee committed
238
239
240
	  break;
	  
	case GDK_WINDOW_ROOT:
241
	  if (gdk_parent_root)
242
	    g_error ("cannot make windows of type GDK_WINDOW_ROOT");
Elliot Lee's avatar
Elliot Lee committed
243
	  break;
244
245
	case GDK_DRAWABLE_PIXMAP:
	  g_error ("cannot make windows of type GDK_DRAWABLE_PIXMAP (use gdk_pixmap_new)");
Elliot Lee's avatar
Elliot Lee committed
246
247
248
249
250
251
252
	  break;
	}
    }
  else
    {
      depth = 0;
      private->input_only = TRUE;
253
      impl->drawable_data.colormap = NULL;
Elliot Lee's avatar
Elliot Lee committed
254
255
256
257
    }

  gdk_drawable_ref (window);
  
258
259
  if (impl->drawable_data.colormap)
    gdk_colormap_ref (impl->drawable_data.colormap);
Elliot Lee's avatar
Elliot Lee committed
260
261
262
263
  
  gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
				  (attributes->cursor) :
				  NULL));
264

Elliot Lee's avatar
Elliot Lee committed
265
  if (parent_private)
266
    parent_private->children = g_list_prepend (parent_private->children, window);
Elliot Lee's avatar
Elliot Lee committed
267
268
269
270
  
  return window;
}

271
/* This function is called when the XWindow is really gone.  */
Elliot Lee's avatar
Elliot Lee committed
272
void
273
274
275
_gdk_windowing_window_destroy (GdkWindow *window,
			       gboolean   recursing,
			       gboolean   foreign_destroy)
Elliot Lee's avatar
Elliot Lee committed
276
{
277
  GdkWindowObject *private;
278
279
  GdkRectangle r;

280
  private = (GdkWindowObject*) window;
Elliot Lee's avatar
Elliot Lee committed
281

282
283
284
285
286
287
  _gdk_selection_window_destroyed (window);

  r.x = private->x;
  r.y = private->y;
  r.width = GDK_DRAWABLE_IMPL_FBDATA (window)->width;
  r.height = GDK_DRAWABLE_IMPL_FBDATA (window)->height;
288
289
290
291
292
293
294
295
296
  /* Clear the root window, as it might be visible under
     the destroyed window */
  gdk_window_clear_area (gdk_parent_root,
			 r.x,
			 r.y,
			 r.width,
			 r.height);
  /* Invalidate the rect */
  gdk_window_invalidate_rect ((GdkWindow *)private->parent, &r, TRUE);
297
}
Elliot Lee's avatar
Elliot Lee committed
298

299
300
static gboolean
all_parents_shown (GdkWindowObject *private)
Elliot Lee's avatar
Elliot Lee committed
301
{
302
  while (private->mapped)
Elliot Lee's avatar
Elliot Lee committed
303
    {
304
305
      if (private->parent)
	private = (GdkWindowObject *)private->parent;
Elliot Lee's avatar
Elliot Lee committed
306
307
308
309
310
311
312
313
      else
	return TRUE;
    }

  return FALSE;
}

static void
314
send_map_events (GdkWindowObject *private, gboolean is_map)
Elliot Lee's avatar
Elliot Lee committed
315
316
{
  GList *l;
317
  GdkWindow *parent = (GdkWindow *)private->parent;
Elliot Lee's avatar
Elliot Lee committed
318

319
  g_assert (is_map);
320

321
  if (!private->mapped)
Elliot Lee's avatar
Elliot Lee committed
322
323
    return;

324
325
  if (is_map)
    gdk_event_make ((GdkWindow *)private, GDK_MAP, TRUE);
Elliot Lee's avatar
Elliot Lee committed
326

327
  if (private->input_only)
Elliot Lee's avatar
Elliot Lee committed
328
329
    return;

330
  if (!parent)
Elliot Lee's avatar
Elliot Lee committed
331
332
    parent = (GdkWindow *)private;

333
334
335
336
  if (((GDK_DRAWABLE_IMPL_FBDATA (private)->abs_x > GDK_DRAWABLE_IMPL_FBDATA (parent)->lim_x) ||
       (GDK_DRAWABLE_IMPL_FBDATA (private)->abs_y > GDK_DRAWABLE_IMPL_FBDATA (parent)->lim_y) ||
       (GDK_DRAWABLE_IMPL_FBDATA (private)->lim_x < GDK_DRAWABLE_IMPL_FBDATA (parent)->llim_x) ||
       (GDK_DRAWABLE_IMPL_FBDATA (private)->lim_y < GDK_DRAWABLE_IMPL_FBDATA (parent)->llim_y)))
Elliot Lee's avatar
Elliot Lee committed
337
338
     return;

339
340
  if (is_map)
    gdk_window_clear ((GdkWindow *)private);
Elliot Lee's avatar
Elliot Lee committed
341

342
343
  for (l = private->children; l; l = l->next)
    send_map_events (l->data, is_map);
Elliot Lee's avatar
Elliot Lee committed
344
345
}

346
/* Cut & paste versions of the stuff in gdkwindow.c, with the addition of clearing the newly exposed region. */
Elliot Lee's avatar
Elliot Lee committed
347
void
348
349
gdk_window_invalidate_region_clear(GdkWindow *window,
				   GdkRegion *region)
Elliot Lee's avatar
Elliot Lee committed
350
{
351
  int i;
352
  GdkWindowObject *private = GDK_WINDOW_P (window);
353

354
  if (private->input_only || !private->mapped)
355
356
    return;

357
358
359
360
361
362
363
  if (private->bg_pixmap != GDK_NO_BG)
    for (i = 0; i < region->numRects; i++)
      gdk_window_clear_area (window,
			     region->rects[i].x1,
			     region->rects[i].y1,
			     region->rects[i].x2 - region->rects[i].x1,
			     region->rects[i].y2 - region->rects[i].y1);
364

365
  gdk_window_invalidate_region (window, region, FALSE);
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

  {
    GList *tmp_list;
    GdkRectangle child_rect;
    GdkRegion *child_region;

    tmp_list = private->children;
    while (tmp_list)
      {
	GdkWindowObject *child = tmp_list->data;
	tmp_list = tmp_list->next;

	if (!child->input_only)
	  {
	    gint width, height;

	    gdk_drawable_get_size (GDK_DRAWABLE (child),
				   &width, &height);
              
	    child_rect.x = child->x;
	    child_rect.y = child->y;
	    child_rect.width = width;
	    child_rect.height = height;
	      
	    child_region = gdk_region_rectangle (&child_rect);
	    gdk_region_intersect (child_region, region);
	      
	    if (!gdk_region_empty (child_region))
	      {
		gdk_region_offset (child_region, - child_rect.x, - child_rect.y);
		gdk_window_invalidate_region_clear ((GdkWindow *)child, child_region);
	      }
	      
	    gdk_region_destroy (child_region);
	  }
      }
  }  
Elliot Lee's avatar
Elliot Lee committed
403
404
}

405
void
406
407
gdk_window_invalidate_rect_clear (GdkWindow *window,
				  GdkRectangle *rect)
Elliot Lee's avatar
Elliot Lee committed
408
{
409
  GdkWindowObject *private = GDK_WINDOW_P (window);
Elliot Lee's avatar
Elliot Lee committed
410

411
  if (private->input_only || !private->mapped)
412
    return;
Elliot Lee's avatar
Elliot Lee committed
413

414
415
416
  if (GDK_WINDOW_P (window)->bg_pixmap != GDK_NO_BG)
    gdk_window_clear_area (window, rect->x, rect->y, rect->width, rect->height);
  gdk_window_invalidate_rect (window, rect, FALSE);
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431

  {
    GList *tmp_list;
    GdkRectangle child_rect, new_rect;

    tmp_list = private->children;
    while (tmp_list)
      {
	GdkWindowObject *child = tmp_list->data;
	tmp_list = tmp_list->next;

	if (!child->input_only)
	  {
	    gint width, height;

432
433
	    width = GDK_DRAWABLE_IMPL_FBDATA (child)->width;
	    height = GDK_DRAWABLE_IMPL_FBDATA (child)->height;
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
              
	    child_rect.x = child->x;
	    child_rect.y = child->y;
	    child_rect.width = width;
	    child_rect.height = height;
	      
	    if (gdk_rectangle_intersect (rect, &child_rect, &new_rect))
	      {
		new_rect.x -= child_rect.x;
		new_rect.y -= child_rect.y;
		  
		gdk_window_invalidate_rect_clear ((GdkWindow *)child, &new_rect);
	      }
	  }
      }
  }
}
Elliot Lee's avatar
Elliot Lee committed
451

452
void
453
gdk_fb_redraw_all (void)
454
455
456
{
  GdkRectangle r;
  r.x = r.y = 0;
457
458
459
460
  r.width = GDK_DRAWABLE_IMPL_FBDATA (gdk_parent_root)->width;
  r.height = GDK_DRAWABLE_IMPL_FBDATA (gdk_parent_root)->height;
  gdk_window_invalidate_rect_clear (gdk_parent_root, &r);
  gdk_window_process_all_updates ();
Elliot Lee's avatar
Elliot Lee committed
461
462
}

463
464
465

/* Focus follows pointer */
GdkWindow *
466
_gdk_fb_window_find_focus (GdkWindow *window_with_mouse)
467
468
469
{
  if (_gdk_fb_keyboard_grab_window)
    return _gdk_fb_keyboard_grab_window;
470
  else if (window_with_mouse)
471
    {
472
      GdkWindowObject *priv = (GdkWindowObject *)window_with_mouse;
473
474
475
476
477
478
479
480
481
482
483
      while (priv != (GdkWindowObject *)gdk_parent_root)
	{
	  if ((priv->parent == (GdkWindowObject *)gdk_parent_root) && priv->mapped)
	    return (GdkWindow *)priv;
	  priv = priv->parent;
	}
    }
 
  return gdk_parent_root;
}

484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
GdkWindow *
gdk_fb_window_find_focus (void)
{
  return _gdk_fb_window_find_focus (gdk_fb_window_containing_pointer);
}


static void
gdk_fb_send_focus_change (GdkWindow *old_window_containing_pointer,
			  GdkWindow *new_window_containing_pointer)
{
  GdkEventFocus *event;
  GdkWindow *old_win, *new_win;
  old_win = _gdk_fb_window_find_focus (old_window_containing_pointer);
  new_win = _gdk_fb_window_find_focus (new_window_containing_pointer);

  if (old_win != new_win)
    {
      event = (GdkEventFocus *)gdk_event_make (old_win, GDK_FOCUS_CHANGE, TRUE);
      if (event)
	event->in = FALSE;
      event = (GdkEventFocus *)gdk_event_make (new_win, GDK_FOCUS_CHANGE, TRUE);
      if (event)
	event->in = TRUE;
    }
}
510

Alexander Larsson's avatar
Alexander Larsson committed
511
static GdkWindow *
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
gdk_fb_find_common_ancestor (GdkWindow *win1,
			     GdkWindow *win2)
{
  GdkWindowObject *tmp;
  GList *path1 = NULL, *path2 = NULL;
  GList *list1, *list2;
  
  tmp = GDK_WINDOW_OBJECT (win1);
  while (tmp) 
    {
      path1 = g_list_prepend(path1, tmp);
      tmp = tmp->parent;
    }

  tmp = GDK_WINDOW_OBJECT (win2);
  while (tmp) 
    {
      path2 = g_list_prepend(path2, tmp);
      tmp = tmp->parent;
    }
  
  list1 = path1;
  list2 = path2;
  tmp = NULL;
  while (list1 && list2 && (list1->data == list2->data)) 
    {
      tmp = (GdkWindowObject *)list1->data;
      list1 = g_list_next (list1);
      list2 = g_list_next (list2);
    }
  g_list_free (path1);
  g_list_free (path2);
  return GDK_WINDOW (tmp);
}

Alexander Larsson's avatar
Alexander Larsson committed
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
void
gdk_fb_window_send_crossing_events (GdkWindow *dest,
				    GdkCrossingMode mode)
{
  GdkWindow *c;
  GdkWindow *win, *last, *next;
  GdkEvent *event;
  gint x, y, x_int, y_int;
  GdkModifierType my_mask;
  GList *path, *list;
  gboolean non_linear;
  gboolean only_grabbed_window;
  GdkWindow *a;
  GdkWindow *b;

  if ((mode == GDK_CROSSING_NORMAL) &&
      (dest == gdk_fb_window_containing_pointer))
    return;

  if (gdk_fb_window_containing_pointer == NULL)
    gdk_fb_window_containing_pointer = gdk_window_ref (gdk_parent_root);

  if (mode == GDK_CROSSING_UNGRAB)
    a = _gdk_fb_pointer_grab_window;
  else
    a = gdk_fb_window_containing_pointer;
  b = dest;

  /* When grab in progress only send normal crossing events about
   * the grabbed window.
   */
  only_grabbed_window = (_gdk_fb_pointer_grab_window_events != NULL) &&
                        (mode == GDK_CROSSING_NORMAL);
  
  if (a==b)
    return;

584
  gdk_fb_mouse_get_info (&x, &y, &my_mask);
Alexander Larsson's avatar
Alexander Larsson committed
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713

  c = gdk_fb_find_common_ancestor (a, b);

  non_linear = (c != a) && (c != b);

  if (!only_grabbed_window || (a == _gdk_fb_pointer_grab_window))
    event = gdk_event_make (a, GDK_LEAVE_NOTIFY, TRUE);
  else
    event = NULL;
  if (event)
    {
      event->crossing.subwindow = NULL;
      gdk_window_get_root_origin (a, &x_int, &y_int);
      event->crossing.x = x - x_int;
      event->crossing.y = y - y_int;
      event->crossing.x_root = x;
      event->crossing.y_root = y;
      event->crossing.mode = mode;
      if (non_linear)
	event->crossing.detail = GDK_NOTIFY_NONLINEAR;
      else if (c==a)
	event->crossing.detail = GDK_NOTIFY_INFERIOR;
      else
	event->crossing.detail = GDK_NOTIFY_ANCESTOR;
      event->crossing.focus = FALSE;
      event->crossing.state = my_mask;
    }
  
  /* Traverse up from a to (excluding) c */
  if (c != a)
    {
      last = a;
      win = GDK_WINDOW (GDK_WINDOW_OBJECT (a)->parent);
      while (win != c)
	{
	  if (!only_grabbed_window || (win == _gdk_fb_pointer_grab_window))
	    event = gdk_event_make (win, GDK_LEAVE_NOTIFY, TRUE);
	  else
	    event = NULL;
	  if (event)
	    {
	      event->crossing.subwindow = gdk_window_ref (last);
	      gdk_window_get_root_origin (win, &x_int, &y_int);
	      event->crossing.x = x - x_int;
	      event->crossing.y = y - y_int;
	      event->crossing.x_root = x;
	      event->crossing.y_root = y;
	      event->crossing.mode = mode;
	      if (non_linear)
		event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
	      else
		event->crossing.detail = GDK_NOTIFY_VIRTUAL;
	      event->crossing.focus = FALSE;
	      event->crossing.state = my_mask;
	    }
	  last = win;
	  win = GDK_WINDOW (GDK_WINDOW_OBJECT (win)->parent);
	}
    }
  
  /* Traverse down from c to b */
  if (c != b) 
    {
      path = NULL;
      win = GDK_WINDOW( GDK_WINDOW_OBJECT (b)->parent);
      while (win != c)
	{
	  path = g_list_prepend (path, win);
	  win = GDK_WINDOW( GDK_WINDOW_OBJECT (win)->parent);
	}
      
      list = path;
      while (list) 
	{
	  win = (GdkWindow *)list->data;
	  list = g_list_next (list);
	  if (list)
	    next = (GdkWindow *)list->data;
	  else 
	    next = b;
	  
	  if (!only_grabbed_window || (win == _gdk_fb_pointer_grab_window))
	    event = gdk_event_make (win, GDK_ENTER_NOTIFY, TRUE);
	  else
	    event = NULL;
	  if (event)
	    {
	      event->crossing.subwindow = gdk_window_ref (next);
	      gdk_window_get_root_origin (win, &x_int, &y_int);
	      event->crossing.x = x - x_int;
	      event->crossing.y = y - y_int;
	      event->crossing.x_root = x;
	      event->crossing.y_root = y;
	      event->crossing.mode = mode;
	      if (non_linear)
		event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
	      else
		event->crossing.detail = GDK_NOTIFY_VIRTUAL;
	      event->crossing.focus = FALSE;
	      event->crossing.state = my_mask;
	    }
	}
      g_list_free (path);
    }

  if (!only_grabbed_window || (b == _gdk_fb_pointer_grab_window))
    event = gdk_event_make (b, GDK_ENTER_NOTIFY, TRUE);
  else
    event = NULL;
  if (event)
    {
      event->crossing.subwindow = NULL;
      gdk_window_get_root_origin (b, &x_int, &y_int);
      event->crossing.x = x - x_int;
      event->crossing.y = y - y_int;
      event->crossing.x_root = x;
      event->crossing.y_root = y;
      event->crossing.mode = mode;
      if (non_linear)
	event->crossing.detail = GDK_NOTIFY_NONLINEAR;
      else if (c==a)
	event->crossing.detail = GDK_NOTIFY_ANCESTOR;
      else
	event->crossing.detail = GDK_NOTIFY_INFERIOR;
      event->crossing.focus = FALSE;
      event->crossing.state = my_mask;
    }

  if ((mode != GDK_CROSSING_GRAB) &&
714
715
      (b != gdk_fb_window_containing_pointer) &&
      !only_grabbed_window)
Alexander Larsson's avatar
Alexander Larsson committed
716
    {
717
      gdk_fb_send_focus_change (gdk_fb_window_containing_pointer, b);
Alexander Larsson's avatar
Alexander Larsson committed
718
719
720
721
722
      gdk_window_unref (gdk_fb_window_containing_pointer);
      gdk_fb_window_containing_pointer = gdk_window_ref (b);
    }
}

Elliot Lee's avatar
Elliot Lee committed
723
724
725
void
gdk_window_show (GdkWindow *window)
{
726
  GdkWindowObject *private;
727
728
  GdkWindow *mousewin;

Elliot Lee's avatar
Elliot Lee committed
729
730
  g_return_if_fail (window != NULL);
  
731
  private = (GdkWindowObject*) window;
Elliot Lee's avatar
Elliot Lee committed
732

733
  if (!private->destroyed && !private->mapped)
Elliot Lee's avatar
Elliot Lee committed
734
735
    {
      private->mapped = TRUE;
736
737
      gdk_fb_window_raise (window);
      
738
      if (all_parents_shown ((GdkWindowObject *)private->parent))
Elliot Lee's avatar
Elliot Lee committed
739
	{
740
741
	  GdkRectangle rect;

742
	  recompute_drawable ((GdkDrawable *)window);
743

744
	  send_map_events (private, TRUE);
Elliot Lee's avatar
Elliot Lee committed
745

746
747
748
	  mousewin = gdk_window_at_pointer (NULL, NULL);
	  gdk_fb_window_send_crossing_events (mousewin, 
					      GDK_CROSSING_NORMAL);
Elliot Lee's avatar
Elliot Lee committed
749

750
	  if (private->input_only)
751
	    return;
Elliot Lee's avatar
Elliot Lee committed
752

753
754
755
756
	  rect.x = GDK_DRAWABLE_IMPL_FBDATA (window)->llim_x;
	  rect.y = GDK_DRAWABLE_IMPL_FBDATA (window)->llim_y;
	  rect.width = GDK_DRAWABLE_IMPL_FBDATA (window)->lim_x - rect.x;
	  rect.height = GDK_DRAWABLE_IMPL_FBDATA (window)->lim_y - rect.y;
757
	  gdk_window_invalidate_rect (gdk_parent_root, &rect, TRUE);
758
	}
Elliot Lee's avatar
Elliot Lee committed
759
760
761
762
763
764
    }
}

void
gdk_window_hide (GdkWindow *window)
{
765
  GdkWindowObject *private;
766
  GdkWindow *mousewin;
Elliot Lee's avatar
Elliot Lee committed
767
768
769
  
  g_return_if_fail (window != NULL);
  
770
  private = (GdkWindowObject*) window;
Elliot Lee's avatar
Elliot Lee committed
771

772
  if (!private->destroyed && private->mapped)
Elliot Lee's avatar
Elliot Lee committed
773
774
775
    {
      GdkEvent *event;
      GdkRectangle r;
776
      gboolean do_hide;
Elliot Lee's avatar
Elliot Lee committed
777

778
      event = gdk_event_make (window, GDK_UNMAP, TRUE);
Elliot Lee's avatar
Elliot Lee committed
779

780
781
782
783
      r.x = GDK_DRAWABLE_IMPL_FBDATA (window)->llim_x;
      r.y = GDK_DRAWABLE_IMPL_FBDATA (window)->llim_y;
      r.width = GDK_DRAWABLE_IMPL_FBDATA (window)->lim_x - r.x;
      r.height = GDK_DRAWABLE_IMPL_FBDATA (window)->lim_y - r.y;
Elliot Lee's avatar
Elliot Lee committed
784
785
786

      private->mapped = FALSE;

787
788
789
      mousewin = gdk_window_at_pointer (NULL, NULL);
      gdk_fb_window_send_crossing_events (mousewin, 
					  GDK_CROSSING_NORMAL);
790

791
      do_hide = gdk_fb_cursor_need_hide (&r);
792

793
794
795
796
797
798
      if (do_hide)
	gdk_fb_cursor_hide ();
      if (window == _gdk_fb_pointer_grab_window)
	gdk_pointer_ungrab (GDK_CURRENT_TIME);
      if (window == _gdk_fb_keyboard_grab_window)
	gdk_keyboard_ungrab (GDK_CURRENT_TIME);
799
800
801
802
803
804
805
806
807
808
809

      /* Clear the root window, as it might be visible under
	 the hidden window*/
      gdk_window_clear_area (gdk_parent_root,
			     r.x,
			     r.y,
			     r.width,
			     r.height);
      /* Invalidate the rect */
      gdk_window_invalidate_rect (gdk_parent_root, &r, TRUE);
      
810
811
      if (do_hide)
	gdk_fb_cursor_unhide ();
Elliot Lee's avatar
Elliot Lee committed
812
813
814
815
816
817
    }
}

void
gdk_window_withdraw (GdkWindow *window)
{
818
  gdk_window_hide (window);
Elliot Lee's avatar
Elliot Lee committed
819
820
821
822
823
824
825
}

void
gdk_window_move (GdkWindow *window,
		 gint       x,
		 gint       y)
{
826
  GdkWindowObject *private = (GdkWindowObject *)window;
Elliot Lee's avatar
Elliot Lee committed
827
828
829
830
831
  
  g_return_if_fail (window != NULL);
  g_return_if_fail (GDK_IS_WINDOW (window));

  gdk_window_move_resize (window, x, y,
832
833
			  GDK_DRAWABLE_IMPL_FBDATA (private)->width,
			  GDK_DRAWABLE_IMPL_FBDATA (private)->height);
Elliot Lee's avatar
Elliot Lee committed
834
835
836
837
838
839
840
}

void
gdk_window_resize (GdkWindow *window,
		   gint       width,
		   gint       height)
{
841
  GdkWindowObject *private;
842
  gint x, y;
Elliot Lee's avatar
Elliot Lee committed
843
844
845
846
  
  g_return_if_fail (window != NULL);
  g_return_if_fail (GDK_IS_WINDOW (window));
  
847
  private = (GdkWindowObject*) window;
Elliot Lee's avatar
Elliot Lee committed
848
849
850
851
852
  
  if (width < 1)
    width = 1;
  if (height < 1)
    height = 1;
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867

  x = private->x;
  y = private->y;
  
  if (private->parent && (private->parent->window_type != GDK_WINDOW_CHILD))
    {
      GdkWindowChildHandlerData *data;
      
      data = g_object_get_data (G_OBJECT (private->parent), "gdk-window-child-handler");

      if (data)
	(*data->get_pos) (window, &x, &y, data->user_data);
    }

  gdk_window_move_resize (window, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
868
869
870
}

static void
871
872
recompute_abs_positions(GdkDrawable *drawable,
			gint parent_x, gint parent_y,
Elliot Lee's avatar
Elliot Lee committed
873
874
875
876
877
			gint parent_llim_x, gint parent_llim_y,
			gint parent_lim_x, gint parent_lim_y)
{
  GList *l;

878
  if (GDK_IS_WINDOW (drawable))
Elliot Lee's avatar
Elliot Lee committed
879
    {
880
      GdkWindowObject *private = GDK_WINDOW_P (drawable);
881
      int x, y;
Elliot Lee's avatar
Elliot Lee committed
882

883
      if (!private->mapped)
Elliot Lee's avatar
Elliot Lee committed
884
885
	return;

886
      
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
      GDK_DRAWABLE_IMPL_FBDATA (private)->abs_x = parent_x + private->x;
      GDK_DRAWABLE_IMPL_FBDATA (private)->abs_y = parent_y + private->y;
      x = MAX (parent_llim_x, GDK_DRAWABLE_IMPL_FBDATA (private)->abs_x);
      x = MIN (x, parent_lim_x);
      GDK_DRAWABLE_IMPL_FBDATA (private)->llim_x = x;
      y = MAX (parent_llim_y, GDK_DRAWABLE_IMPL_FBDATA (private)->abs_y);
      y = MIN (y, parent_lim_y);
      GDK_DRAWABLE_IMPL_FBDATA (private)->llim_y = y;
      x = MIN (parent_lim_x,
	       GDK_DRAWABLE_IMPL_FBDATA (private)->abs_x + GDK_DRAWABLE_IMPL_FBDATA (private)->width);
      x = MAX (x, GDK_DRAWABLE_IMPL_FBDATA (private)->llim_x);
      GDK_DRAWABLE_IMPL_FBDATA (private)->lim_x = x;
      y = MIN (parent_lim_y,
	       GDK_DRAWABLE_IMPL_FBDATA (private)->abs_y + GDK_DRAWABLE_IMPL_FBDATA (private)->height);
      y = MAX (y, GDK_DRAWABLE_IMPL_FBDATA (private)->llim_y);
      GDK_DRAWABLE_IMPL_FBDATA (private)->lim_y = y;

      g_assert (GDK_DRAWABLE_IMPL_FBDATA (private)->llim_x <= GDK_DRAWABLE_IMPL_FBDATA (private)->lim_x);
      g_assert (GDK_DRAWABLE_IMPL_FBDATA (private)->llim_y <= GDK_DRAWABLE_IMPL_FBDATA (private)->lim_y);

      for (l = private->children; l; l = l->next)
	recompute_abs_positions (l->data,
				 GDK_DRAWABLE_IMPL_FBDATA (private)->abs_x,
				 GDK_DRAWABLE_IMPL_FBDATA (private)->abs_y,
				 GDK_DRAWABLE_IMPL_FBDATA (private)->llim_x,
				 GDK_DRAWABLE_IMPL_FBDATA (private)->llim_y,
				 GDK_DRAWABLE_IMPL_FBDATA (private)->lim_x,
				 GDK_DRAWABLE_IMPL_FBDATA (private)->lim_y);
Elliot Lee's avatar
Elliot Lee committed
915
916
917
    }
  else
    {
918
919
920
921
922
923
      GDK_DRAWABLE_IMPL_FBDATA (drawable)->abs_x = 0;
      GDK_DRAWABLE_IMPL_FBDATA (drawable)->abs_y = 0;
      GDK_DRAWABLE_IMPL_FBDATA (drawable)->llim_x = 0;
      GDK_DRAWABLE_IMPL_FBDATA (drawable)->llim_y = 0;
      GDK_DRAWABLE_IMPL_FBDATA (drawable)->lim_x = GDK_DRAWABLE_IMPL_FBDATA (drawable)->width;
      GDK_DRAWABLE_IMPL_FBDATA (drawable)->lim_y = GDK_DRAWABLE_IMPL_FBDATA (drawable)->height;
Elliot Lee's avatar
Elliot Lee committed
924
925
926
    }
}

Alexander Larsson's avatar
Alexander Larsson committed
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
static void
recompute_rowstride(GdkDrawable *drawable)
{
  GList *l;
  GdkWindowObject *private;

  g_return_if_fail (GDK_IS_WINDOW (drawable));

  private = GDK_WINDOW_P (drawable);

  GDK_DRAWABLE_IMPL_FBDATA (private)->rowstride = gdk_display->fb_stride;
  for (l = private->children; l; l = l->next)
    recompute_rowstride (l->data);
}

void
gdk_fb_recompute_all (void)
{
  GDK_DRAWABLE_IMPL_FBDATA (gdk_parent_root)->width = gdk_display->fb_width;
  GDK_DRAWABLE_IMPL_FBDATA (gdk_parent_root)->height = gdk_display->fb_height;
  
  recompute_abs_positions (gdk_parent_root,
			   0, 0, 0, 0,
			   gdk_display->fb_width, gdk_display->fb_height);
  recompute_rowstride (gdk_parent_root);
}

Elliot Lee's avatar
Elliot Lee committed
954
static void
955
recompute_drawable (GdkDrawable *drawable)
Elliot Lee's avatar
Elliot Lee committed
956
{
957
  if (GDK_IS_WINDOW (drawable))
Elliot Lee's avatar
Elliot Lee committed
958
    {
959
      GdkWindowObject *private = GDK_WINDOW_P (drawable);
Elliot Lee's avatar
Elliot Lee committed
960
961
      GdkWindow *parent;

962
      parent = (GdkWindow *)private->parent;
963
      if (!parent)
Elliot Lee's avatar
Elliot Lee committed
964
965
	parent = gdk_parent_root;

966
967
968
969
970
971
972
      recompute_abs_positions (drawable,
			       GDK_DRAWABLE_IMPL_FBDATA (parent)->abs_x,
			       GDK_DRAWABLE_IMPL_FBDATA (parent)->abs_y,
			       GDK_DRAWABLE_IMPL_FBDATA (parent)->llim_x,
			       GDK_DRAWABLE_IMPL_FBDATA (parent)->llim_y,
			       GDK_DRAWABLE_IMPL_FBDATA (parent)->lim_x,
			       GDK_DRAWABLE_IMPL_FBDATA (parent)->lim_y);
Elliot Lee's avatar
Elliot Lee committed
973
974
    }
  else
975
    recompute_abs_positions (drawable, 0, 0, 0, 0, INT_MAX, INT_MAX);
Elliot Lee's avatar
Elliot Lee committed
976
977
978
}

void
979
980
981
982
983
984
gdk_fb_window_move_resize (GdkWindow *window,
			   gint       x,
			   gint       y,
			   gint       width,
			   gint       height,
			   gboolean   send_expose_events)
Elliot Lee's avatar
Elliot Lee committed
985
{
986
  GdkWindowObject *private;
987
  gint dx, dy, dw, dh;
988
  gint i, draw_dir;
989
990
  GdkEvent *event;
  GdkWindow *mousewin;
991
992
  GdkRectangle root_rect;
  GdkRectangle update_rect;
993

Elliot Lee's avatar
Elliot Lee committed
994
995
996
997
998
999
1000
  g_return_if_fail (window != NULL);
  g_return_if_fail (GDK_IS_WINDOW (window));

  if (width < 1)
    width = 1;
  if (height < 1)
    height = 1;