summaryrefslogtreecommitdiff
path: root/gdk/x11/gdkgeometry-x11.c
blob: 40855e8abbf89bd489de38a0628928c8ab770a00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
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
510
511
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
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
584
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
/* 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
 * modify it under the terms of the GNU Library General Public
 * 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/* gdkgeometry-x11.c: emulation of 32 bit coordinates within the
 * limits of X. 
 *
 * By Owen Taylor <otaylor@redhat.com>
 * Copyright Red Hat, Inc. 2000
 */

#include "gdk.h"		/* For gdk_rectangle_intersect */
#include "gdkprivate-x11.h"
#include "gdkx.h"
#include "gdkregion.h"

typedef struct _GdkWindowQueueItem GdkWindowQueueItem;
typedef struct _GdkWindowParentPos GdkWindowParentPos;

typedef enum {
  GDK_WINDOW_QUEUE_TRANSLATE,
  GDK_WINDOW_QUEUE_ANTIEXPOSE
} GdkWindowQueueType;

struct _GdkWindowQueueItem
{
  GdkWindow *window;
  gulong serial;
  GdkWindowQueueType type;
  union {
    struct {
      gint dx;
      gint dy;
    } translate;
    struct {
      GdkRegion *area;
    } antiexpose;
  } u;
};

struct _GdkWindowParentPos
{
  gint x;
  gint y;
  gint x11_x;
  gint x11_y;
  GdkRectangle clip_rect;
};

static void gdk_window_compute_position   (GdkWindow          *window,
					   GdkWindowParentPos *parent_pos,
					   GdkXPositionInfo   *info);
static void gdk_window_compute_parent_pos (GdkWindow          *window,
					   GdkWindowParentPos *parent_pos);
static void gdk_window_premove            (GdkWindow          *window,
					   GdkWindowParentPos *parent_pos);
static void gdk_window_postmove           (GdkWindow          *window,
					   GdkWindowParentPos *parent_pos);
static void gdk_window_queue_translation  (GdkWindow          *window,
					   gint                dx,
					   gint                dy);
static void gdk_window_tmp_unset_bg       (GdkWindow          *window);
static void gdk_window_tmp_reset_bg       (GdkWindow          *window);
static void gdk_window_clip_changed       (GdkWindow          *window,
					   GdkRectangle       *old_clip,
					   GdkRectangle       *new_clip);

static GSList *translate_queue = NULL;

void
_gdk_windowing_window_get_offsets (GdkWindow *window,
				   gint      *x_offset,
				   gint      *y_offset)
{
  GdkWindowPrivate *private = (GdkWindowPrivate *)window;
  GdkWindowXData *data = (GdkWindowXData *)private->drawable.klass_data;

  *x_offset = data->position_info.x_offset;
  *y_offset = data->position_info.y_offset;
}

void
_gdk_window_init_position (GdkWindow *window)
{
  GdkWindowPrivate *private = (GdkWindowPrivate *)window;
  GdkWindowXData *data;
  GdkWindowParentPos parent_pos;

  g_return_if_fail (window != NULL);
  g_return_if_fail (GDK_IS_WINDOW (window));

  data = (GdkWindowXData *)private->drawable.klass_data;

  gdk_window_compute_parent_pos (window, &parent_pos);
  gdk_window_compute_position (window, &parent_pos, &data->position_info);
}

void
_gdk_window_move_resize_child (GdkWindow *window,
			       gint       x,
			       gint       y,
			       gint       width,
			       gint       height)
{
  GdkWindowPrivate *private = (GdkWindowPrivate *)window;
  GdkXPositionInfo new_info;
  GdkWindowParentPos parent_pos;
  GdkWindowXData *data;
  GList *tmp_list;
  
  gint d_xoffset, d_yoffset;
  gint dx, dy;
  gboolean is_move;
  gboolean is_resize;
  
  g_return_if_fail (window != NULL);
  g_return_if_fail (GDK_IS_WINDOW (window));

  data = (GdkWindowXData *)private->drawable.klass_data;

  dx = x - private->x;
  dy = y - private->y;
  
  is_move = dx != 0 || dy != 0;
  is_resize = private->drawable.width != width || private->drawable.height != height;

  if (!is_move && !is_resize)
    return;
  
  private->x = x;
  private->y = y;
  private->drawable.width = width;
  private->drawable.height = height;

  gdk_window_compute_parent_pos (window, &parent_pos);
  gdk_window_compute_position (window, &parent_pos, &new_info);

  gdk_window_clip_changed (window, &data->position_info.clip_rect, &new_info.clip_rect);

  parent_pos.x += private->x;
  parent_pos.y += private->y;
  parent_pos.x11_x += new_info.x;
  parent_pos.x11_y += new_info.y;
  parent_pos.clip_rect = new_info.clip_rect;

  d_xoffset = new_info.x_offset - data->position_info.x_offset;
  d_yoffset = new_info.y_offset - data->position_info.y_offset;
  
  if (d_xoffset != 0 || d_yoffset != 0)
    {
      gint new_x0, new_y0, new_x1, new_y1;

      gdk_window_set_static_gravities (window, TRUE);

      if (d_xoffset < 0 || d_yoffset < 0)
	gdk_window_queue_translation (window, MIN (d_xoffset, 0), MIN (d_yoffset, 0));
	
      if (d_xoffset < 0)
	{
	  new_x0 = data->position_info.x + d_xoffset;
	  new_x1 = data->position_info.x + data->position_info.width;
	}
      else
	{
	  new_x0 = data->position_info.x;
	  new_x1 = data->position_info.x + new_info.width + d_xoffset;
	}

      if (d_yoffset < 0)
	{
	  new_y0 = data->position_info.y + d_yoffset;
	  new_y1 = data->position_info.y + data->position_info.height;
	}
      else
	{
	  new_y0 = data->position_info.y;
	  new_y1 = data->position_info.y + new_info.height + d_yoffset;
	}
      
      XMoveResizeWindow (GDK_DRAWABLE_XDISPLAY (window),
			 GDK_DRAWABLE_XID (window),
			 new_x0, new_y0, new_x1 - new_x0, new_y1 - new_y0);
      
      tmp_list = private->children;
      while (tmp_list)
	{
	  gdk_window_premove (tmp_list->data, &parent_pos);
	  tmp_list = tmp_list->next;
	}

      XMoveWindow (GDK_DRAWABLE_XDISPLAY (window),
		   GDK_DRAWABLE_XID (window),
		   new_x0 + dx, new_y0 + dy);
      
      if (d_xoffset > 0 || d_yoffset > 0)
	gdk_window_queue_translation (window, MAX (d_xoffset, 0), MAX (d_yoffset, 0));
      
      XMoveResizeWindow (GDK_DRAWABLE_XDISPLAY (window),
			 GDK_DRAWABLE_XID (window),
			 new_info.x, new_info.y, new_info.width, new_info.height);
      
      if (data->position_info.no_bg)
	gdk_window_tmp_reset_bg (window);

      if (!data->position_info.mapped && new_info.mapped && private->mapped)
	XMapWindow (GDK_DRAWABLE_XDISPLAY (window), GDK_DRAWABLE_XID (window));
      
      data->position_info = new_info;
      
      tmp_list = private->children;
      while (tmp_list)
	{
	  gdk_window_postmove (tmp_list->data, &parent_pos);
	  tmp_list = tmp_list->next;
	}
    }
  else
    {
      if (is_move && is_resize)
	gdk_window_set_static_gravities (window, FALSE);

      if (data->position_info.mapped && !new_info.mapped)
	XUnmapWindow (GDK_DRAWABLE_XDISPLAY (window), GDK_DRAWABLE_XID (window));
      
      tmp_list = private->children;
      while (tmp_list)
	{
	  gdk_window_premove (tmp_list->data, &parent_pos);
	  tmp_list = tmp_list->next;
	}

      if (is_resize)
	XMoveResizeWindow (GDK_DRAWABLE_XDISPLAY (window),
			   GDK_DRAWABLE_XID (window),
			   new_info.x, new_info.y, new_info.width, new_info.height);
      else
	XMoveWindow (GDK_DRAWABLE_XDISPLAY (window),
		     GDK_DRAWABLE_XID (window),
		     new_info.x, new_info.y);

      tmp_list = private->children;
      while (tmp_list)
	{
	  gdk_window_postmove (tmp_list->data, &parent_pos);
	  tmp_list = tmp_list->next;
	}

      if (data->position_info.no_bg)
	gdk_window_tmp_reset_bg (window);

      if (!data->position_info.mapped && new_info.mapped && private->mapped)
	XMapWindow (GDK_DRAWABLE_XDISPLAY (window), GDK_DRAWABLE_XID (window));

      data->position_info = new_info;
    }
}

static void
gdk_window_compute_position (GdkWindow          *window,
			     GdkWindowParentPos *parent_pos,
			     GdkXPositionInfo   *info)
{
  GdkWindowPrivate *private = (GdkWindowPrivate *)window;
  int parent_x_offset;
  int parent_y_offset;
  
  info->big = FALSE;
  
  if (private->drawable.width <= 32768)
    {
      info->width = private->drawable.width;
      info->x = parent_pos->x + private->x - parent_pos->x11_x;
    }
  else
    {
      info->big = TRUE;
      info->width = 32768;
      if (parent_pos->x + private->x < -16384)
	{
	  if (parent_pos->x + private->x + private->drawable.width < 16384)
	    info->x = parent_pos->x + private->x + private->drawable.width - 32768 - parent_pos->x11_x;
	  else
	    info->x = -16384 - parent_pos->x11_y;
	}
      else
	info->x = parent_pos->x + private->x - parent_pos->x11_x;
    }

  if (private->drawable.height <= 32768)
    {
      info->height = private->drawable.height;
      info->y = parent_pos->y + private->y - parent_pos->x11_y;
    }
  else
    {
      info->big = TRUE;
      info->height = 32768;
      if (parent_pos->y + private->y < -16384)
	{
	  if (parent_pos->y + private->y + private->drawable.height < 16384)
	    info->y = parent_pos->y + private->y + private->drawable.height - 32768 - parent_pos->x11_y;
	  else
	    info->y = -16384 - parent_pos->x11_y;
	}
      else
	info->y = parent_pos->y + private->y - parent_pos->x11_y;
    }

  parent_x_offset = parent_pos->x11_x - parent_pos->x;
  parent_y_offset = parent_pos->x11_y - parent_pos->y;
  
  info->x_offset = parent_x_offset + info->x - private->x;
  info->y_offset = parent_y_offset + info->y - private->y;

  /* We don't considering the clipping of toplevel windows and their immediate children
   * by their parents, and simply always map those windows.
   */
  if (parent_pos->clip_rect.width == G_MAXINT)
    info->mapped = TRUE;
  /* Check if the window would wrap around into the visible space in either direction */
  else if (info->x + parent_x_offset < parent_pos->clip_rect.x + parent_pos->clip_rect.width - 65536 ||
      info->x + info->width + parent_x_offset > parent_pos->clip_rect.x + 65536 ||
      info->y + parent_y_offset < parent_pos->clip_rect.y + parent_pos->clip_rect.height - 65536 ||
      info->y + info->width + parent_y_offset  > parent_pos->clip_rect.y + 65536)
    info->mapped = FALSE;
  else
    info->mapped = TRUE;

  info->no_bg = FALSE;

  if (GDK_DRAWABLE_TYPE (private) == GDK_WINDOW_CHILD)
    {
      info->clip_rect.x = private->x;
      info->clip_rect.y = private->y;
      info->clip_rect.width = private->drawable.width;
      info->clip_rect.height = private->drawable.height;
      
      gdk_rectangle_intersect (&info->clip_rect, &parent_pos->clip_rect, &info->clip_rect);

      info->clip_rect.x -= private->x;
      info->clip_rect.y -= private->y;
    }
  else
    {
      info->clip_rect.x = 0;
      info->clip_rect.y = 0;
      info->clip_rect.width = G_MAXINT;
      info->clip_rect.height = G_MAXINT;
    }
}

static void
gdk_window_compute_parent_pos (GdkWindow          *window,
			       GdkWindowParentPos *parent_pos)
{
  GdkWindowPrivate *private = (GdkWindowPrivate *)window;
  GdkWindowXData *data;
  GdkRectangle tmp_clip;
  
  int clip_xoffset = 0;
  int clip_yoffset = 0;

  parent_pos->x = 0;
  parent_pos->y = 0;
  parent_pos->x11_x = 0;
  parent_pos->x11_y = 0;

  /* We take a simple approach here and simply consider toplevel
   * windows not to clip their children on the right/bottom, since the
   * size of toplevel windows is not directly under our
   * control. Clipping only really matters when scrolling and
   * generally we aren't going to be moving the immediate child of a
   * toplevel beyond the bounds of that toplevel.
   *
   * We could go ahead and recompute the clips of toplevel windows and
   * their descendents when we receive size notification, but it would
   * probably not be an improvement in most cases.
   */
  parent_pos->clip_rect.x = 0;
  parent_pos->clip_rect.y = 0;
  parent_pos->clip_rect.width = G_MAXINT;
  parent_pos->clip_rect.height = G_MAXINT;

  private = (GdkWindowPrivate *)private->parent;
  while (private && private->drawable.window_type == GDK_WINDOW_CHILD)
    {
      data = (GdkWindowXData *)private->drawable.klass_data;

      tmp_clip.x = - clip_xoffset;
      tmp_clip.y = - clip_yoffset;
      tmp_clip.width = private->drawable.width;
      tmp_clip.height = private->drawable.height;

      gdk_rectangle_intersect (&parent_pos->clip_rect, &tmp_clip, &parent_pos->clip_rect);

      parent_pos->x += private->x;
      parent_pos->y += private->y;
      parent_pos->x11_x += data->position_info.x;
      parent_pos->x11_y += data->position_info.y;

      clip_xoffset += private->x;
      clip_yoffset += private->y;

      private = (GdkWindowPrivate *)private->parent;
    }
}

static void
gdk_window_premove (GdkWindow          *window,
		    GdkWindowParentPos *parent_pos)
{
  GdkWindowPrivate *private = (GdkWindowPrivate *)window;
  GdkWindowXData *data = GDK_WINDOW_XDATA (window);
  GdkXPositionInfo new_info;
  GList *tmp_list;
  gint d_xoffset, d_yoffset;
  GdkWindowParentPos this_pos;
  
  gdk_window_compute_position (window, parent_pos, &new_info);

  gdk_window_clip_changed (window, &data->position_info.clip_rect, &new_info.clip_rect);

  this_pos.x = parent_pos->x + private->x;
  this_pos.y = parent_pos->y + private->y;
  this_pos.x11_x = parent_pos->x11_x + new_info.x;
  this_pos.x11_y = parent_pos->x11_y + new_info.y;
  this_pos.clip_rect = new_info.clip_rect;

  if (data->position_info.mapped && !new_info.mapped)
    XUnmapWindow (GDK_DRAWABLE_XDISPLAY (window), GDK_DRAWABLE_XID (window));

  d_xoffset = new_info.x_offset - data->position_info.x_offset;
  d_yoffset = new_info.y_offset - data->position_info.y_offset;
  
  if (d_xoffset != 0 || d_yoffset != 0)
    {
      gint new_x0, new_y0, new_x1, new_y1;

      if (d_xoffset < 0 || d_yoffset < 0)
	gdk_window_queue_translation (window, MIN (d_xoffset, 0), MIN (d_yoffset, 0));
	
      if (d_xoffset < 0)
	{
	  new_x0 = data->position_info.x + d_xoffset;
	  new_x1 = data->position_info.x + data->position_info.width;
	}
      else
	{
	  new_x0 = data->position_info.x;
	  new_x1 = data->position_info.x + new_info.width + d_xoffset;
	}

      if (d_yoffset < 0)
	{
	  new_y0 = data->position_info.y + d_yoffset;
	  new_y1 = data->position_info.y + data->position_info.height;
	}
      else
	{
	  new_y0 = data->position_info.y;
	  new_y1 = data->position_info.y + new_info.height + d_yoffset;
	}

      XMoveResizeWindow (GDK_DRAWABLE_XDISPLAY (window),
			 GDK_DRAWABLE_XID (window),
			 new_x0, new_y0, new_x1 - new_x0, new_y1 - new_y0);
    }

  tmp_list = private->children;
  while (tmp_list)
    {
      gdk_window_premove (tmp_list->data, &this_pos);
      tmp_list = tmp_list->next;
    }
}

static void
gdk_window_postmove (GdkWindow          *window,
		     GdkWindowParentPos *parent_pos)
{
  GdkWindowPrivate *private = (GdkWindowPrivate *)window;
  GdkWindowXData *data = (GdkWindowXData *)private->drawable.klass_data;
  GdkXPositionInfo new_info;
  GList *tmp_list;
  gint d_xoffset, d_yoffset;
  GdkWindowParentPos this_pos;
  
  gdk_window_compute_position (window, parent_pos, &new_info);

  this_pos.x = parent_pos->x + private->x;
  this_pos.y = parent_pos->y + private->y;
  this_pos.x11_x = parent_pos->x11_x + new_info.x;
  this_pos.x11_y = parent_pos->x11_y + new_info.y;
  this_pos.clip_rect = new_info.clip_rect;

  d_xoffset = new_info.x_offset - data->position_info.x_offset;
  d_yoffset = new_info.y_offset - data->position_info.y_offset;
  
  if (d_xoffset != 0 || d_yoffset != 0)
    {
      if (d_xoffset > 0 || d_yoffset > 0)
	gdk_window_queue_translation (window, MAX (d_xoffset, 0), MAX (d_yoffset, 0));
	
      XMoveResizeWindow (GDK_DRAWABLE_XDISPLAY (window),
			 GDK_DRAWABLE_XID (window),
			 new_info.x, new_info.y, new_info.width, new_info.height);
    }

  if (!data->position_info.mapped && new_info.mapped && private->mapped)
    XMapWindow (GDK_DRAWABLE_XDISPLAY (window), GDK_DRAWABLE_XID (window));

  if (data->position_info.no_bg)
    gdk_window_tmp_reset_bg (window);

  data->position_info = new_info;

  tmp_list = private->children;
  while (tmp_list)
    {
      gdk_window_postmove (tmp_list->data, &this_pos);
      tmp_list = tmp_list->next;
    }
}

static void
gdk_window_queue_translation (GdkWindow *window,
			      gint       dx,
			      gint       dy)
{
  GdkWindowQueueItem *item = g_new (GdkWindowQueueItem, 1);
  item->window = window;
  item->serial = NextRequest (GDK_WINDOW_XDISPLAY (window));
  item->type = GDK_WINDOW_QUEUE_TRANSLATE;
  item->u.translate.dx = dx;
  item->u.translate.dy = dy;

  gdk_drawable_ref (window);
  translate_queue = g_slist_append (translate_queue, item);
}

gboolean
_gdk_windowing_window_queue_antiexpose (GdkWindow *window,
					GdkRegion *area)
{
  GdkWindowQueueItem *item = g_new (GdkWindowQueueItem, 1);
  item->window = window;
  item->serial = NextRequest (GDK_WINDOW_XDISPLAY (window));
  item->type = GDK_WINDOW_QUEUE_ANTIEXPOSE;
  item->u.antiexpose.area = area;

  gdk_drawable_ref (window);
  translate_queue = g_slist_append (translate_queue, item);

  return TRUE;
}

void
_gdk_window_process_expose (GdkWindow    *window,
			    gulong        serial,
			    GdkRectangle *area)
{
  GdkWindowXData *data = GDK_WINDOW_XDATA (window);
  GdkRegion *invalidate_region = gdk_region_rectangle (area);
  GdkRegion *clip_region;

  GSList *tmp_list = translate_queue;

  while (tmp_list)
    {
      GdkWindowQueueItem *item = tmp_list->data;
      tmp_list = tmp_list->next;

      if (serial < item->serial)
	{
	  if (item->window == window)
	    {
	      if (item->type == GDK_WINDOW_QUEUE_TRANSLATE)
		gdk_region_offset (invalidate_region, - item->u.translate.dx, - item->u.translate.dy);
	      else		/* anti-expose */
		gdk_region_subtract (invalidate_region, item->u.antiexpose.area);
	    }
	}
      else
	{
	  GSList *tmp_link = translate_queue;
	  
	  translate_queue = g_slist_remove_link (translate_queue, translate_queue);
	  gdk_drawable_unref (item->window);

	  if (item->type == GDK_WINDOW_QUEUE_ANTIEXPOSE)
	    gdk_region_destroy (item->u.antiexpose.area);
	  
	  g_free (item);
	  g_slist_free_1 (tmp_link);
	}
    }

  clip_region = gdk_region_rectangle (&data->position_info.clip_rect);
  gdk_region_intersect (invalidate_region, clip_region);

  if (!gdk_region_empty (invalidate_region))
    gdk_window_invalidate_region (window, invalidate_region, FALSE);

  gdk_region_destroy (invalidate_region);
  gdk_region_destroy (clip_region);
}

static void
gdk_window_tmp_unset_bg (GdkWindow *window)
{
  GdkWindowPrivate *private = (GdkWindowPrivate *)window;
  GdkWindowXData *data = GDK_WINDOW_XDATA (window);

  data->position_info.no_bg = TRUE;

  if (private->bg_pixmap != GDK_NO_BG)
    XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
				GDK_DRAWABLE_XID (window), None);
}

static void
gdk_window_tmp_reset_bg (GdkWindow *window)
{
  GdkWindowPrivate *private = (GdkWindowPrivate *)window;
  GdkWindowXData *data = GDK_WINDOW_XDATA (window);

  data->position_info.no_bg = FALSE;

  if (private->bg_pixmap == GDK_NO_BG)
    return;
  
  if (private->bg_pixmap)
    {
      Pixmap xpixmap;

      if (private->bg_pixmap == GDK_PARENT_RELATIVE_BG)
	xpixmap = ParentRelative;
      else 
	xpixmap = GDK_DRAWABLE_XID (private->bg_pixmap);

      XSetWindowBackgroundPixmap (GDK_DRAWABLE_XDISPLAY (window),
				  GDK_DRAWABLE_XID (window), xpixmap);
    }
  else
    {
      XSetWindowBackground (GDK_DRAWABLE_XDISPLAY (window),
			    GDK_DRAWABLE_XID (window),
			    private->bg_color.pixel);
    }
}

static void
gdk_window_clip_changed (GdkWindow *window, GdkRectangle *old_clip, GdkRectangle *new_clip)
{
  GdkWindowPrivate *private = (GdkWindowPrivate *)window;

  GdkRegion *old_clip_region;
  GdkRegion *new_clip_region;

  if (private->input_only)
    return;
    
  old_clip_region = gdk_region_rectangle (old_clip);
  new_clip_region = gdk_region_rectangle (new_clip);

  /* Trim invalid region of window to new clip rectangle
   */
  if (private->update_area)
    gdk_region_intersect (private->update_area, new_clip_region);

  /* Invalidate newly exposed portion of window
   */
  gdk_region_subtract (new_clip_region, old_clip_region);
  if (!gdk_region_empty (new_clip_region))
    {
      gdk_window_tmp_unset_bg (window);
      gdk_window_invalidate_region (window, new_clip_region, FALSE);
    }

  gdk_region_destroy (new_clip_region);
  gdk_region_destroy (old_clip_region);
}