-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathwindow.c
3947 lines (3541 loc) · 100 KB
/
window.c
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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
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
915
916
917
918
919
920
921
922
923
924
925
926
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
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2006, Red Hat, Inc.
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
RED HAT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Red Hat shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Red Hat.
Copyright 1987, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
*/
/* The panoramix components contained the following notice */
/*****************************************************************
Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Digital Equipment Corporation
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization from Digital
Equipment Corporation.
******************************************************************/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include "misc.h"
#include "scrnintstr.h"
#include "os.h"
#include "regionstr.h"
#include "validate.h"
#include "windowstr.h"
#include "input.h"
#include "inputstr.h"
#include "resource.h"
#include "colormapst.h"
#include "cursorstr.h"
#include "dixstruct.h"
#include "gcstruct.h"
#include "servermd.h"
#ifdef PANORAMIX
#include "panoramiX.h"
#include "panoramiXsrv.h"
#endif
#include "dixevents.h"
#include "globals.h"
#include "mi.h" /* miPaintWindow */
#include "privates.h"
#include "xace.h"
/******
* Window stuff for server
*
* CreateRootWindow, CreateWindow, ChangeWindowAttributes,
* GetWindowAttributes, DeleteWindow, DestroySubWindows,
* HandleSaveSet, ReparentWindow, MapWindow, MapSubWindows,
* UnmapWindow, UnmapSubWindows, ConfigureWindow, CirculateWindow,
* ChangeWindowDeviceCursor
******/
static unsigned char _back_lsb[4] = {0x88, 0x22, 0x44, 0x11};
static unsigned char _back_msb[4] = {0x11, 0x44, 0x22, 0x88};
static Bool WindowParentHasDeviceCursor(WindowPtr pWin,
DeviceIntPtr pDev,
CursorPtr pCurs);
static Bool
WindowSeekDeviceCursor(WindowPtr pWin,
DeviceIntPtr pDev,
DevCursNodePtr* pNode,
DevCursNodePtr* pPrev);
_X_EXPORT int screenIsSaved = SCREEN_SAVER_OFF;
_X_EXPORT ScreenSaverStuffRec savedScreenInfo[MAXSCREENS];
static int FocusPrivatesKeyIndex;
_X_EXPORT DevPrivateKey FocusPrivatesKey = &FocusPrivatesKeyIndex;
static Bool TileScreenSaver(int i, int kind);
#define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \
CWDontPropagate | CWOverrideRedirect | CWCursor )
#define BOXES_OVERLAP(b1, b2) \
(!( ((b1)->x2 <= (b2)->x1) || \
( ((b1)->x1 >= (b2)->x2)) || \
( ((b1)->y2 <= (b2)->y1)) || \
( ((b1)->y1 >= (b2)->y2)) ) )
#define RedirectSend(pWin) \
((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureRedirectMask)
#define SubSend(pWin) \
((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureNotifyMask)
#define StrSend(pWin) \
((pWin->eventMask|wOtherEventMasks(pWin)) & StructureNotifyMask)
#define SubStrSend(pWin,pParent) (StrSend(pWin) || SubSend(pParent))
#ifdef DEBUG
/******
* PrintWindowTree
* For debugging only
******/
static void
PrintChildren(WindowPtr p1, int indent)
{
WindowPtr p2;
int i;
while (p1)
{
p2 = p1->firstChild;
ErrorF("[dix] ");
for (i=0; i<indent; i++) ErrorF(" ");
ErrorF("%lx\n", p1->drawable.id);
miPrintRegion(&p1->clipList);
PrintChildren(p2, indent+4);
p1 = p1->nextSib;
}
}
static void
PrintWindowTree(void)
{
int i;
WindowPtr pWin, p1;
for (i=0; i<screenInfo.numScreens; i++)
{
ErrorF("[dix] WINDOW %d\n", i);
pWin = WindowTable[i];
miPrintRegion(&pWin->clipList);
p1 = pWin->firstChild;
PrintChildren(p1, 4);
}
}
#endif
_X_EXPORT int
TraverseTree(WindowPtr pWin, VisitWindowProcPtr func, pointer data)
{
int result;
WindowPtr pChild;
if (!(pChild = pWin))
return(WT_NOMATCH);
while (1)
{
result = (* func)(pChild, data);
if (result == WT_STOPWALKING)
return(WT_STOPWALKING);
if ((result == WT_WALKCHILDREN) && pChild->firstChild)
{
pChild = pChild->firstChild;
continue;
}
while (!pChild->nextSib && (pChild != pWin))
pChild = pChild->parent;
if (pChild == pWin)
break;
pChild = pChild->nextSib;
}
return(WT_NOMATCH);
}
/*****
* WalkTree
* Walk the window tree, for SCREEN, preforming FUNC(pWin, data) on
* each window. If FUNC returns WT_WALKCHILDREN, traverse the children,
* if it returns WT_DONTWALKCHILDREN, dont. If it returns WT_STOPWALKING
* exit WalkTree. Does depth-first traverse.
*****/
_X_EXPORT int
WalkTree(ScreenPtr pScreen, VisitWindowProcPtr func, pointer data)
{
return(TraverseTree(WindowTable[pScreen->myNum], func, data));
}
/* hack for forcing backing store on all windows */
int defaultBackingStore = NotUseful;
/* hack to force no backing store */
Bool disableBackingStore = FALSE;
Bool enableBackingStore = FALSE;
static void
SetWindowToDefaults(WindowPtr pWin)
{
FocusSemaphoresPtr sem;
pWin->prevSib = NullWindow;
pWin->firstChild = NullWindow;
pWin->lastChild = NullWindow;
pWin->valdata = (ValidatePtr)NULL;
pWin->optional = (WindowOptPtr)NULL;
pWin->cursorIsNone = TRUE;
pWin->backingStore = NotUseful;
pWin->DIXsaveUnder = FALSE;
pWin->backStorage = (pointer) NULL;
pWin->mapped = FALSE; /* off */
pWin->realized = FALSE; /* off */
pWin->viewable = FALSE;
pWin->visibility = VisibilityNotViewable;
pWin->overrideRedirect = FALSE;
pWin->saveUnder = FALSE;
pWin->bitGravity = ForgetGravity;
pWin->winGravity = NorthWestGravity;
pWin->eventMask = 0;
pWin->deliverableEvents = 0;
pWin->dontPropagate = 0;
pWin->forcedBS = FALSE;
pWin->redirectDraw = RedirectDrawNone;
pWin->forcedBG = FALSE;
sem = xcalloc(1, sizeof(FocusSemaphoresRec));
dixSetPrivate(&pWin->devPrivates, FocusPrivatesKey, sem);
#ifdef ROOTLESS
pWin->rootlessUnhittable = FALSE;
#endif
}
static void
MakeRootTile(WindowPtr pWin)
{
ScreenPtr pScreen = pWin->drawable.pScreen;
GCPtr pGC;
unsigned char back[128];
int len = BitmapBytePad(sizeof(long));
unsigned char *from, *to;
int i, j;
pWin->background.pixmap = (*pScreen->CreatePixmap)(pScreen, 4, 4,
pScreen->rootDepth, 0);
pWin->backgroundState = BackgroundPixmap;
pGC = GetScratchGC(pScreen->rootDepth, pScreen);
if (!pWin->background.pixmap || !pGC)
FatalError("could not create root tile");
{
CARD32 attributes[2];
attributes[0] = pScreen->whitePixel;
attributes[1] = pScreen->blackPixel;
(void)ChangeGC(pGC, GCForeground | GCBackground, attributes);
}
ValidateGC((DrawablePtr)pWin->background.pixmap, pGC);
from = (screenInfo.bitmapBitOrder == LSBFirst) ? _back_lsb : _back_msb;
to = back;
for (i = 4; i > 0; i--, from++)
for (j = len; j > 0; j--)
*to++ = *from;
(*pGC->ops->PutImage)((DrawablePtr)pWin->background.pixmap, pGC, 1,
0, 0, len, 4, 0, XYBitmap, (char *)back);
FreeScratchGC(pGC);
}
/*****
* CreateRootWindow
* Makes a window at initialization time for specified screen
*****/
Bool
CreateRootWindow(ScreenPtr pScreen)
{
WindowPtr pWin;
BoxRec box;
PixmapFormatRec *format;
pWin = (WindowPtr)xalloc(sizeof(WindowRec));
if (!pWin)
return FALSE;
savedScreenInfo[pScreen->myNum].pWindow = NULL;
savedScreenInfo[pScreen->myNum].wid = FakeClientID(0);
savedScreenInfo[pScreen->myNum].ExternalScreenSaver = NULL;
screenIsSaved = SCREEN_SAVER_OFF;
WindowTable[pScreen->myNum] = pWin;
pWin->drawable.pScreen = pScreen;
pWin->drawable.type = DRAWABLE_WINDOW;
pWin->devPrivates = NULL;
pWin->drawable.depth = pScreen->rootDepth;
for (format = screenInfo.formats;
format->depth != pScreen->rootDepth;
format++)
;
pWin->drawable.bitsPerPixel = format->bitsPerPixel;
pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
pWin->parent = NullWindow;
SetWindowToDefaults(pWin);
pWin->optional = (WindowOptRec *) xalloc (sizeof (WindowOptRec));
if (!pWin->optional)
return FALSE;
pWin->optional->dontPropagateMask = 0;
pWin->optional->otherEventMasks = 0;
pWin->optional->otherClients = NULL;
pWin->optional->passiveGrabs = NULL;
pWin->optional->userProps = NULL;
pWin->optional->backingBitPlanes = ~0L;
pWin->optional->backingPixel = 0;
pWin->optional->boundingShape = NULL;
pWin->optional->clipShape = NULL;
pWin->optional->inputShape = NULL;
pWin->optional->inputMasks = NULL;
pWin->optional->deviceCursors = NULL;
pWin->optional->geMasks = (GenericClientMasksPtr)xcalloc(1, sizeof(GenericClientMasksRec));
if (!pWin->optional->geMasks)
{
xfree(pWin->optional);
return FALSE;
}
pWin->optional->access.perm = NULL;
pWin->optional->access.deny = NULL;
pWin->optional->access.nperm = 0;
pWin->optional->access.ndeny = 0;
pWin->optional->access.defaultRule = 0;
pWin->optional->colormap = pScreen->defColormap;
pWin->optional->visual = pScreen->rootVisual;
pWin->nextSib = NullWindow;
pWin->drawable.id = FakeClientID(0);
pWin->origin.x = pWin->origin.y = 0;
pWin->drawable.height = pScreen->height;
pWin->drawable.width = pScreen->width;
pWin->drawable.x = pWin->drawable.y = 0;
box.x1 = 0;
box.y1 = 0;
box.x2 = pScreen->width;
box.y2 = pScreen->height;
REGION_INIT(pScreen, &pWin->clipList, &box, 1);
REGION_INIT(pScreen, &pWin->winSize, &box, 1);
REGION_INIT(pScreen, &pWin->borderSize, &box, 1);
REGION_INIT(pScreen, &pWin->borderClip, &box, 1);
pWin->drawable.class = InputOutput;
pWin->optional->visual = pScreen->rootVisual;
pWin->backgroundState = BackgroundPixel;
pWin->background.pixel = pScreen->whitePixel;
pWin->borderIsPixel = TRUE;
pWin->border.pixel = pScreen->blackPixel;
pWin->borderWidth = 0;
/* security creation/labeling check
*/
if (XaceHook(XACE_RESOURCE_ACCESS, serverClient, pWin->drawable.id,
RT_WINDOW, pWin, RT_NONE, NULL, DixCreateAccess))
return FALSE;
if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin))
return FALSE;
if (disableBackingStore)
pScreen->backingStoreSupport = NotUseful;
if (enableBackingStore)
pScreen->backingStoreSupport = Always;
pScreen->saveUnderSupport = NotUseful;
return TRUE;
}
void
InitRootWindow(WindowPtr pWin)
{
ScreenPtr pScreen = pWin->drawable.pScreen;
int backFlag = CWBorderPixel | CWCursor | CWBackingStore;
if (!(*pScreen->CreateWindow)(pWin))
return; /* XXX */
(*pScreen->PositionWindow)(pWin, 0, 0);
pWin->cursorIsNone = FALSE;
pWin->optional->cursor = rootCursor;
rootCursor->refcnt++;
if (party_like_its_1989) {
MakeRootTile(pWin);
backFlag |= CWBackPixmap;
} else {
if (whiteRoot)
pWin->background.pixel = pScreen->whitePixel;
else
pWin->background.pixel = pScreen->blackPixel;
backFlag |= CWBackPixel;
}
pWin->backingStore = defaultBackingStore;
pWin->forcedBS = (defaultBackingStore != NotUseful);
/* We SHOULD check for an error value here XXX */
(*pScreen->ChangeWindowAttributes)(pWin, backFlag);
MapWindow(pWin, serverClient);
}
/* Set the region to the intersection of the rectangle and the
* window's winSize. The window is typically the parent of the
* window from which the region came.
*/
static void
ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn,
int x, int y,
int w, int h)
{
ScreenPtr pScreen;
BoxRec box;
pScreen = pWin->drawable.pScreen;
box = *(REGION_EXTENTS(pScreen, &pWin->winSize));
/* we do these calculations to avoid overflows */
if (x > box.x1)
box.x1 = x;
if (y > box.y1)
box.y1 = y;
x += w;
if (x < box.x2)
box.x2 = x;
y += h;
if (y < box.y2)
box.y2 = y;
if (box.x1 > box.x2)
box.x2 = box.x1;
if (box.y1 > box.y2)
box.y2 = box.y1;
REGION_RESET(pScreen, Rgn, &box);
REGION_INTERSECT(pScreen, Rgn, Rgn, &pWin->winSize);
}
static RealChildHeadProc realChildHeadProc = NULL;
void
RegisterRealChildHeadProc (RealChildHeadProc proc)
{
realChildHeadProc = proc;
}
WindowPtr
RealChildHead(WindowPtr pWin)
{
if (realChildHeadProc) {
return realChildHeadProc (pWin);
}
if (!pWin->parent &&
(screenIsSaved == SCREEN_SAVER_ON) &&
(HasSaverWindow (pWin->drawable.pScreen->myNum)))
return (pWin->firstChild);
else
return (NullWindow);
}
/*****
* CreateWindow
* Makes a window in response to client request
*****/
_X_EXPORT WindowPtr
CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
unsigned h, unsigned bw, unsigned class, Mask vmask, XID *vlist,
int depth, ClientPtr client, VisualID visual, int *error)
{
WindowPtr pWin;
WindowPtr pHead;
ScreenPtr pScreen;
xEvent event;
int idepth, ivisual;
Bool fOK;
DepthPtr pDepth;
PixmapFormatRec *format;
WindowOptPtr ancwopt;
if (class == CopyFromParent)
class = pParent->drawable.class;
if ((class != InputOutput) && (class != InputOnly))
{
*error = BadValue;
client->errorValue = class;
return NullWindow;
}
if ((class != InputOnly) && (pParent->drawable.class == InputOnly))
{
*error = BadMatch;
return NullWindow;
}
if ((class == InputOnly) && ((bw != 0) || (depth != 0)))
{
*error = BadMatch;
return NullWindow;
}
pScreen = pParent->drawable.pScreen;
if ((class == InputOutput) && (depth == 0))
depth = pParent->drawable.depth;
ancwopt = pParent->optional;
if (!ancwopt)
ancwopt = FindWindowWithOptional(pParent)->optional;
if (visual == CopyFromParent) {
visual = ancwopt->visual;
}
/* Find out if the depth and visual are acceptable for this Screen */
if ((visual != ancwopt->visual) || (depth != pParent->drawable.depth))
{
fOK = FALSE;
for(idepth = 0; idepth < pScreen->numDepths; idepth++)
{
pDepth = (DepthPtr) &pScreen->allowedDepths[idepth];
if ((depth == pDepth->depth) || (depth == 0))
{
for (ivisual = 0; ivisual < pDepth->numVids; ivisual++)
{
if (visual == pDepth->vids[ivisual])
{
fOK = TRUE;
break;
}
}
}
}
if (fOK == FALSE)
{
*error = BadMatch;
return NullWindow;
}
}
if (((vmask & (CWBorderPixmap | CWBorderPixel)) == 0) &&
(class != InputOnly) &&
(depth != pParent->drawable.depth))
{
*error = BadMatch;
return NullWindow;
}
if (((vmask & CWColormap) == 0) &&
(class != InputOnly) &&
((visual != ancwopt->visual) || (ancwopt->colormap == None)))
{
*error = BadMatch;
return NullWindow;
}
pWin = (WindowPtr)xalloc(sizeof(WindowRec));
if (!pWin)
{
*error = BadAlloc;
return NullWindow;
}
pWin->drawable = pParent->drawable;
pWin->devPrivates = NULL;
pWin->drawable.depth = depth;
if (depth == pParent->drawable.depth)
pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel;
else
{
for (format = screenInfo.formats; format->depth != depth; format++)
;
pWin->drawable.bitsPerPixel = format->bitsPerPixel;
}
if (class == InputOnly)
pWin->drawable.type = (short) UNDRAWABLE_WINDOW;
pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
pWin->drawable.id = wid;
pWin->drawable.class = class;
pWin->parent = pParent;
SetWindowToDefaults(pWin);
if (visual != ancwopt->visual)
{
if (!MakeWindowOptional (pWin))
{
xfree (pWin);
*error = BadAlloc;
return NullWindow;
}
pWin->optional->visual = visual;
pWin->optional->colormap = None;
}
pWin->borderWidth = bw;
/* security creation/labeling check
*/
*error = XaceHook(XACE_RESOURCE_ACCESS, client, wid, RT_WINDOW, pWin,
RT_WINDOW, pWin->parent, DixCreateAccess|DixSetAttrAccess);
if (*error != Success) {
xfree(pWin);
return NullWindow;
}
pWin->backgroundState = XaceBackgroundNoneState(pWin);
pWin->background.pixel = pScreen->whitePixel;
pWin->borderIsPixel = pParent->borderIsPixel;
pWin->border = pParent->border;
if (pWin->borderIsPixel == FALSE)
pWin->border.pixmap->refcnt++;
pWin->origin.x = x + (int)bw;
pWin->origin.y = y + (int)bw;
pWin->drawable.width = w;
pWin->drawable.height = h;
pWin->drawable.x = pParent->drawable.x + x + (int)bw;
pWin->drawable.y = pParent->drawable.y + y + (int)bw;
/* set up clip list correctly for unobscured WindowPtr */
REGION_NULL(pScreen, &pWin->clipList);
REGION_NULL(pScreen, &pWin->borderClip);
REGION_NULL(pScreen, &pWin->winSize);
REGION_NULL(pScreen, &pWin->borderSize);
pHead = RealChildHead(pParent);
if (pHead)
{
pWin->nextSib = pHead->nextSib;
if (pHead->nextSib)
pHead->nextSib->prevSib = pWin;
else
pParent->lastChild = pWin;
pHead->nextSib = pWin;
pWin->prevSib = pHead;
}
else
{
pWin->nextSib = pParent->firstChild;
if (pParent->firstChild)
pParent->firstChild->prevSib = pWin;
else
pParent->lastChild = pWin;
pParent->firstChild = pWin;
}
SetWinSize (pWin);
SetBorderSize (pWin);
/* We SHOULD check for an error value here XXX */
if (!(*pScreen->CreateWindow)(pWin))
{
*error = BadAlloc;
DeleteWindow(pWin, None);
return NullWindow;
}
/* We SHOULD check for an error value here XXX */
(*pScreen->PositionWindow)(pWin, pWin->drawable.x, pWin->drawable.y);
if (!(vmask & CWEventMask))
RecalculateDeliverableEvents(pWin);
if (vmask)
*error = ChangeWindowAttributes(pWin, vmask, vlist, wClient (pWin));
else
*error = Success;
if (*error != Success)
{
DeleteWindow(pWin, None);
return NullWindow;
}
if (!(vmask & CWBackingStore) && (defaultBackingStore != NotUseful))
{
XID value = defaultBackingStore;
(void)ChangeWindowAttributes(pWin, CWBackingStore, &value, wClient (pWin));
pWin->forcedBS = TRUE;
}
if (SubSend(pParent))
{
event.u.u.type = CreateNotify;
event.u.createNotify.window = wid;
event.u.createNotify.parent = pParent->drawable.id;
event.u.createNotify.x = x;
event.u.createNotify.y = y;
event.u.createNotify.width = w;
event.u.createNotify.height = h;
event.u.createNotify.borderWidth = bw;
event.u.createNotify.override = pWin->overrideRedirect;
DeliverEvents(pParent, &event, 1, NullWindow);
}
return pWin;
}
static void
DisposeWindowOptional (WindowPtr pWin)
{
GenericMaskPtr gmask = NULL, next = NULL;
if (!pWin->optional)
return;
/*
* everything is peachy. Delete the optional record
* and clean up
*/
if (pWin->optional->cursor)
{
FreeCursor (pWin->optional->cursor, (Cursor)0);
pWin->cursorIsNone = FALSE;
}
else
pWin->cursorIsNone = TRUE;
if (pWin->optional->deviceCursors)
{
DevCursorList pList;
DevCursorList pPrev;
pList = pWin->optional->deviceCursors;
while(pList)
{
if (pList->cursor)
FreeCursor(pList->cursor, (XID)0);
pPrev = pList;
pList = pList->next;
xfree(pPrev);
}
pWin->optional->deviceCursors = NULL;
}
xfree(pWin->optional->access.perm);
xfree(pWin->optional->access.deny);
/* Remove generic event mask allocations */
if (pWin->optional->geMasks)
gmask = pWin->optional->geMasks->geClients;
while(gmask)
{
next = gmask->next;
xfree(gmask);
gmask = next;
}
xfree (pWin->optional->geMasks);
xfree (pWin->optional);
pWin->optional = NULL;
}
static void
FreeWindowResources(WindowPtr pWin)
{
ScreenPtr pScreen = pWin->drawable.pScreen;
DeleteWindowFromAnySaveSet(pWin);
DeleteWindowFromAnySelections(pWin);
DeleteWindowFromAnyEvents(pWin, TRUE);
REGION_UNINIT(pScreen, &pWin->clipList);
REGION_UNINIT(pScreen, &pWin->winSize);
REGION_UNINIT(pScreen, &pWin->borderClip);
REGION_UNINIT(pScreen, &pWin->borderSize);
if (wBoundingShape (pWin))
REGION_DESTROY(pScreen, wBoundingShape (pWin));
if (wClipShape (pWin))
REGION_DESTROY(pScreen, wClipShape (pWin));
if (wInputShape (pWin))
REGION_DESTROY(pScreen, wInputShape (pWin));
if (pWin->borderIsPixel == FALSE)
(*pScreen->DestroyPixmap)(pWin->border.pixmap);
if (pWin->backgroundState == BackgroundPixmap)
(*pScreen->DestroyPixmap)(pWin->background.pixmap);
DeleteAllWindowProperties(pWin);
/* We SHOULD check for an error value here XXX */
(*pScreen->DestroyWindow)(pWin);
DisposeWindowOptional (pWin);
}
static void
CrushTree(WindowPtr pWin)
{
WindowPtr pChild, pSib, pParent;
UnrealizeWindowProcPtr UnrealizeWindow;
xEvent event;
if (!(pChild = pWin->firstChild))
return;
UnrealizeWindow = pWin->drawable.pScreen->UnrealizeWindow;
while (1)
{
if (pChild->firstChild)
{
pChild = pChild->firstChild;
continue;
}
while (1)
{
pParent = pChild->parent;
if (SubStrSend(pChild, pParent))
{
event.u.u.type = DestroyNotify;
event.u.destroyNotify.window = pChild->drawable.id;
DeliverEvents(pChild, &event, 1, NullWindow);
}
FreeResource(pChild->drawable.id, RT_WINDOW);
pSib = pChild->nextSib;
pChild->viewable = FALSE;
if (pChild->realized)
{
pChild->realized = FALSE;
(*UnrealizeWindow)(pChild);
}
FreeWindowResources(pChild);
dixFreePrivates(pChild->devPrivates);
xfree(pChild);
if ( (pChild = pSib) )
break;
pChild = pParent;
pChild->firstChild = NullWindow;
pChild->lastChild = NullWindow;
if (pChild == pWin)
return;
}
}
}
/*****
* DeleteWindow
* Deletes child of window then window itself
* If wid is None, don't send any events
*****/
int
DeleteWindow(pointer value, XID wid)
{
WindowPtr pParent;
WindowPtr pWin = (WindowPtr)value;
xEvent event;
UnmapWindow(pWin, FALSE);
CrushTree(pWin);
pParent = pWin->parent;
if (wid && pParent && SubStrSend(pWin, pParent))
{
event.u.u.type = DestroyNotify;
event.u.destroyNotify.window = pWin->drawable.id;
DeliverEvents(pWin, &event, 1, NullWindow);
}
FreeWindowResources(pWin);
if (pParent)
{
if (pParent->firstChild == pWin)
pParent->firstChild = pWin->nextSib;
if (pParent->lastChild == pWin)
pParent->lastChild = pWin->prevSib;
if (pWin->nextSib)
pWin->nextSib->prevSib = pWin->prevSib;
if (pWin->prevSib)
pWin->prevSib->nextSib = pWin->nextSib;
}
xfree(dixLookupPrivate(&pWin->devPrivates, FocusPrivatesKey));
dixFreePrivates(pWin->devPrivates);
xfree(pWin);
return Success;
}
int
DestroySubwindows(WindowPtr pWin, ClientPtr client)
{
/* XXX
* The protocol is quite clear that each window should be
* destroyed in turn, however, unmapping all of the first
* eliminates most of the calls to ValidateTree. So,
* this implementation is incorrect in that all of the
* UnmapNotifies occur before all of the DestroyNotifies.
* If you care, simply delete the call to UnmapSubwindows.
*/
UnmapSubwindows(pWin);
while (pWin->lastChild) {
int rc = XaceHook(XACE_RESOURCE_ACCESS, client,
pWin->lastChild->drawable.id, RT_WINDOW,
pWin->lastChild, RT_NONE, NULL, DixDestroyAccess);
if (rc != Success)
return rc;
FreeResource(pWin->lastChild->drawable.id, RT_NONE);
}
return Success;
}
#define DeviceEventMasks (KeyPressMask | KeyReleaseMask | ButtonPressMask | \
ButtonReleaseMask | PointerMotionMask)