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
|
/*
Copyright 1996, 1998, 2001 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.
*/
#define NEED_REPLIES
#define NEED_EVENTS
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <X11/X.h>
#include <X11/Xproto.h>
#include "misc.h"
#include "dixstruct.h"
#include "extnsionst.h"
#include "scrnintstr.h"
#include "windowstr.h"
#include "colormapst.h"
#include "servermd.h"
#define _XAG_SERVER_
#include <X11/extensions/Xagstr.h>
#include "xacestr.h"
#include "securitysrv.h"
#include <X11/Xfuncproto.h>
#define XSERV_t
#include <X11/Xtrans/Xtrans.h>
#include "../os/osdep.h"
#include <stdio.h>
#include "modinit.h"
#include "appgroup.h"
typedef struct _AppGroupRec {
struct _AppGroupRec* next;
XID appgroupId;
ClientPtr* clients;
int nclients;
ClientPtr leader;
Bool single_screen;
Window default_root;
VisualID root_visual;
Colormap default_colormap;
Pixel black_pixel;
Pixel white_pixel;
xConnSetupPrefix connSetupPrefix;
char* ConnectionInfo;
} AppGroupRec, *AppGroupPtr;
static int ProcXagDispatch(ClientPtr client);
static int SProcXagDispatch(ClientPtr client);
static void XagResetProc(ExtensionEntry* extEntry);
static int XagCallbackRefCount = 0;
static RESTYPE RT_APPGROUP;
static AppGroupPtr appGrpList = NULL;
extern xConnSetupPrefix connSetupPrefix;
extern char* ConnectionInfo;
extern int connBlockScreenStart;
static
int XagAppGroupFree(
pointer what,
XID id) /* unused */
{
int i;
AppGroupPtr pAppGrp = (AppGroupPtr) what;
if (pAppGrp->leader)
for (i = 0; i < pAppGrp->nclients; i++) {
if (pAppGrp->clients[i] == NULL) continue;
CloseDownClient (pAppGrp->clients[i]);
}
if (pAppGrp == appGrpList)
appGrpList = appGrpList->next;
else {
AppGroupPtr tpAppGrp;
for (tpAppGrp = appGrpList;
tpAppGrp->next != NULL;
tpAppGrp = tpAppGrp->next) {
if (tpAppGrp->next == pAppGrp) {
tpAppGrp->next = tpAppGrp->next->next;
break;
}
}
}
(void) xfree (pAppGrp->clients);
(void) xfree (pAppGrp->ConnectionInfo);
(void) xfree (what);
return Success;
}
static void XagClientStateChange(
CallbackListPtr* pcbl,
pointer nulldata,
pointer calldata)
{
NewClientInfoRec* pci = (NewClientInfoRec*) calldata;
ClientPtr pClient = pci->client;
AppGroupPtr pAppGrp = pClient->appgroup;
int slot;
if (!pAppGrp)
return;
switch (pClient->clientState) {
case ClientStateAuthenticating:
case ClientStateRunning:
case ClientStateCheckingSecurity:
break;
case ClientStateInitial:
case ClientStateCheckedSecurity:
slot = -1;
/* see the comment above about Initial vs. CheckedSecurity */
if (pAppGrp->nclients != 0) {
/* if this client already in AppGroup, don't add it again */
int i;
for (i = 0; i < pAppGrp->nclients; i++)
if (pClient == pAppGrp->clients[i]) return;
if (slot == -1 && pAppGrp->clients[i] == NULL)
slot = i;
}
if (slot == -1) {
slot = pAppGrp->nclients++;
pAppGrp->clients = (ClientPtr*) xrealloc (pAppGrp->clients,
pAppGrp->nclients * sizeof (ClientPtr));
}
pAppGrp->clients[slot] = pClient;
pClient->appgroup = pAppGrp;
break;
case ClientStateGone:
case ClientStateRetained: /* client disconnected, dump it */
{
int i;
for (i = 0; i < pAppGrp->nclients; i++)
if (pAppGrp->clients[i] == pClient) {
pAppGrp->clients[i] = NULL;
break;
}
}
pClient->appgroup = NULL; /* redundant, pClient will be freed */
break;
}
}
/*ARGSUSED*/
static
void XagResetProc(
ExtensionEntry* extEntry)
{
DeleteCallback (&ClientStateCallback, XagClientStateChange, NULL);
XagCallbackRefCount = 0;
while (appGrpList) XagAppGroupFree ((pointer) appGrpList, 0);
}
static
int ProcXagQueryVersion(
ClientPtr client)
{
/* REQUEST (xXagQueryVersionReq); */
xXagQueryVersionReply rep;
int n;
REQUEST_SIZE_MATCH (xXagQueryVersionReq);
rep.type = X_Reply;
rep.length = 0;
rep.sequence_number = client->sequence;
rep.server_major_version = XAG_MAJOR_VERSION;
rep.server_minor_version = XAG_MINOR_VERSION;
if (client->swapped) {
swaps (&rep.sequence_number, n);
swapl (&rep.length, n);
swaps (&rep.server_major_version, n);
swaps (&rep.server_minor_version, n);
}
WriteToClient (client, sizeof (xXagQueryVersionReply), (char *)&rep);
return client->noClientException;
}
static
void ProcessAttr(
AppGroupPtr pAppGrp,
ClientPtr client,
unsigned int attrib_mask,
CARD32* attribs)
{
int i;
for (i = 0; i <= XagNappGroupLeader; i++) {
switch (attrib_mask & (1 << i)) {
case XagSingleScreenMask:
pAppGrp->single_screen = *attribs;
break;
case XagDefaultRootMask:
pAppGrp->default_root = *attribs;
break;
case XagRootVisualMask:
pAppGrp->root_visual = *attribs;
break;
case XagDefaultColormapMask:
pAppGrp->default_colormap = *attribs;
break;
case XagBlackPixelMask:
pAppGrp->black_pixel = *attribs;
break;
case XagWhitePixelMask:
pAppGrp->white_pixel = *attribs;
break;
case XagAppGroupLeaderMask:
pAppGrp->leader = client;
break;
default: continue;
}
attribs++;
}
}
static
void CreateConnectionInfo(
AppGroupPtr pAppGrp)
{
xWindowRoot* rootp;
xWindowRoot* roots[MAXSCREENS];
unsigned int rootlens[MAXSCREENS];
xDepth* depth;
int olen;
int snum, i;
rootp = (xWindowRoot*) (ConnectionInfo + connBlockScreenStart);
for (snum = 0; snum < screenInfo.numScreens; snum++) {
rootlens[snum] = sizeof (xWindowRoot);
roots[snum] = rootp;
depth = (xDepth*) (rootp + 1);
for (i = 0; i < rootp->nDepths; i++) {
rootlens[snum] += sizeof (xDepth) +
depth->nVisuals * sizeof (xVisualType);
depth = (xDepth *)(((char*)(depth + 1)) +
depth->nVisuals * sizeof (xVisualType));
}
rootp = (xWindowRoot*) depth;
}
snum = 0;
if (pAppGrp->default_root) {
for (; snum < screenInfo.numVideoScreens; snum++) {
if (roots[snum]->windowId == pAppGrp->default_root)
break;
}
}
olen = connBlockScreenStart + rootlens[snum];
for (i = screenInfo.numVideoScreens; i < screenInfo.numScreens; i++)
olen += rootlens[i];
pAppGrp->ConnectionInfo = (char*) xalloc (olen);
if (!pAppGrp->ConnectionInfo)
return;
memmove (pAppGrp->ConnectionInfo, ConnectionInfo, connBlockScreenStart);
((xConnSetup*) (pAppGrp->ConnectionInfo))->numRoots =
1 + screenInfo.numScreens - screenInfo.numVideoScreens;
memmove (pAppGrp->ConnectionInfo + connBlockScreenStart,
(void*) roots[snum], rootlens[snum]);
rootp = (xWindowRoot*) (pAppGrp->ConnectionInfo + connBlockScreenStart);
if (pAppGrp->default_colormap) {
rootp->defaultColormap = pAppGrp->default_colormap;
rootp->whitePixel = pAppGrp->white_pixel;
rootp->blackPixel = pAppGrp->black_pixel;
}
if (pAppGrp->root_visual)
rootp->rootVisualID = pAppGrp->root_visual;
rootp = (xWindowRoot*) (((char*)rootp) + rootlens[snum]);
for (i = screenInfo.numVideoScreens; i < screenInfo.numScreens; i++) {
memmove ((void*) rootp, (void*) roots[i], rootlens[i]);
rootp = (xWindowRoot*) (((char*) rootp) + rootlens[i]);
}
pAppGrp->connSetupPrefix = connSetupPrefix;
pAppGrp->connSetupPrefix.length = olen >> 2;
}
static
AppGroupPtr CreateAppGroup(
ClientPtr client,
XID appgroupId,
unsigned int attrib_mask,
CARD32* attribs)
{
AppGroupPtr pAppGrp;
pAppGrp = (AppGroupPtr) xalloc (sizeof(AppGroupRec));
if (pAppGrp) {
pAppGrp->next = appGrpList;
appGrpList = pAppGrp;
pAppGrp->appgroupId = appgroupId;
pAppGrp->clients = (ClientPtr*) xalloc (0);
pAppGrp->nclients = 0;
pAppGrp->leader = NULL;
pAppGrp->default_root = 0;
pAppGrp->root_visual = 0;
pAppGrp->default_colormap = 0;
pAppGrp->black_pixel = -1;
pAppGrp->white_pixel = -1;
pAppGrp->ConnectionInfo = NULL;
ProcessAttr (pAppGrp, client, attrib_mask, attribs);
}
return pAppGrp;
}
static
int AttrValidate(
ClientPtr client,
int attrib_mask,
AppGroupPtr pAppGrp)
{
WindowPtr pWin;
int idepth, ivids, found, rc;
ScreenPtr pScreen;
DepthPtr pDepth;
ColormapPtr pColormap;
rc = dixLookupWindow(&pWin, pAppGrp->default_root, client,
DixUnknownAccess);
if (rc != Success)
return rc;
pScreen = pWin->drawable.pScreen;
if (WindowTable[pScreen->myNum]->drawable.id != pAppGrp->default_root)
return BadWindow;
pDepth = pScreen->allowedDepths;
if (pAppGrp->root_visual) {
found = FALSE;
for (idepth = 0; idepth < pScreen->numDepths; idepth++, pDepth++) {
for (ivids = 0; ivids < pDepth->numVids; ivids++) {
if (pAppGrp->root_visual == pDepth->vids[ivids]) {
found = TRUE;
break;
}
}
}
if (!found)
return BadMatch;
}
if (pAppGrp->default_colormap) {
pColormap = (ColormapPtr)LookupIDByType (pAppGrp->default_colormap, RT_COLORMAP);
/* XXX check that pColormap is not NULL */
if (pColormap->pScreen != pScreen)
return BadColor;
if (pColormap->pVisual->vid != (pAppGrp->root_visual ? pAppGrp->root_visual : pScreen->rootVisual))
return BadMatch;
}
return client->noClientException;
}
static int ProcXagCreate (
ClientPtr client)
{
REQUEST (xXagCreateReq);
AppGroupPtr pAppGrp;
int ret;
REQUEST_AT_LEAST_SIZE (xXagCreateReq);
LEGAL_NEW_RESOURCE (stuff->app_group, client);
pAppGrp = CreateAppGroup (client, stuff->app_group,
stuff->attrib_mask, (CARD32*) &stuff[1]);
if (!pAppGrp)
return BadAlloc;
ret = AttrValidate (client, stuff->attrib_mask, pAppGrp);
if (ret != Success) {
XagAppGroupFree ((pointer)pAppGrp, (XID)0);
return ret;
}
if (pAppGrp->single_screen) {
CreateConnectionInfo (pAppGrp);
if (!pAppGrp->ConnectionInfo)
return BadAlloc;
}
if (!AddResource (stuff->app_group, RT_APPGROUP, (pointer)pAppGrp))
return BadAlloc;
if (XagCallbackRefCount++ == 0)
(void) AddCallback (&ClientStateCallback, XagClientStateChange, NULL);
return client->noClientException;
}
static int ProcXagDestroy(
ClientPtr client)
{
AppGroupPtr pAppGrp;
REQUEST (xXagDestroyReq);
REQUEST_SIZE_MATCH (xXagDestroyReq);
pAppGrp = (AppGroupPtr)SecurityLookupIDByType (client,
(XID)stuff->app_group, RT_APPGROUP, DixReadAccess);
if (!pAppGrp) return XagBadAppGroup;
FreeResource ((XID)stuff->app_group, RT_NONE);
if (--XagCallbackRefCount == 0)
(void) DeleteCallback (&ClientStateCallback, XagClientStateChange, NULL);
return client->noClientException;
}
static
int ProcXagGetAttr(
ClientPtr client)
{
AppGroupPtr pAppGrp;
REQUEST (xXagGetAttrReq);
xXagGetAttrReply rep;
int n;
REQUEST_SIZE_MATCH (xXagGetAttrReq);
pAppGrp = (AppGroupPtr)SecurityLookupIDByType (client,
(XID)stuff->app_group, RT_APPGROUP, DixReadAccess);
if (!pAppGrp) return XagBadAppGroup;
rep.type = X_Reply;
rep.length = 0;
rep.sequence_number = client->sequence;
rep.default_root = pAppGrp->default_root;
rep.root_visual = pAppGrp->root_visual;
rep.default_colormap = pAppGrp->default_colormap;
rep.black_pixel = pAppGrp->black_pixel;
rep.white_pixel = pAppGrp->white_pixel;
rep.single_screen = pAppGrp->single_screen;
rep.app_group_leader = (pAppGrp->leader) ? 1 : 0;
if (client->swapped) {
swaps (&rep.sequence_number, n);
swapl (&rep.length, n);
swapl (&rep.default_root, n);
swapl (&rep.root_visual, n);
swapl (&rep.default_colormap, n);
swapl (&rep.black_pixel, n);
swapl (&rep.white_pixel, n);
}
WriteToClient (client, sizeof (xXagGetAttrReply), (char *)&rep);
return client->noClientException;
}
static
int ProcXagQuery(
ClientPtr client)
{
ClientPtr pClient;
AppGroupPtr pAppGrp;
REQUEST (xXagQueryReq);
int n, rc;
REQUEST_SIZE_MATCH (xXagQueryReq);
rc = dixLookupClient(&pClient, stuff->resource, client, DixUnknownAccess);
if (rc != Success)
return rc;
for (pAppGrp = appGrpList; pAppGrp != NULL; pAppGrp = pAppGrp->next)
for (n = 0; n < pAppGrp->nclients; n++)
if (pAppGrp->clients[n] == pClient) {
xXagQueryReply rep;
rep.type = X_Reply;
rep.length = 0;
rep.sequence_number = client->sequence;
rep.app_group = pAppGrp->appgroupId;
if (client->swapped) {
swaps (&rep.sequence_number, n);
swapl (&rep.length, n);
swapl (&rep.app_group, n);
}
WriteToClient (client, sizeof (xXagQueryReply), (char *)&rep);
return client->noClientException;
}
return BadMatch;
}
static
int ProcXagCreateAssoc(
ClientPtr client)
{
REQUEST (xXagCreateAssocReq);
REQUEST_SIZE_MATCH (xXagCreateAssocReq);
#ifdef WIN32
if (stuff->window_type != XagWindowTypeWin32)
#else
if (stuff->window_type != XagWindowTypeX11)
#endif
return BadMatch;
#if defined(WIN32) || defined(__CYGWIN__) /* and Mac, etc */
if (!LocalClient (client))
return BadAccess;
#endif
/* Macintosh, OS/2, and MS-Windows servers have some work to do here */
return client->noClientException;
}
static
int ProcXagDestroyAssoc(
ClientPtr client)
{
/* REQUEST (xXagDestroyAssocReq); */
REQUEST_SIZE_MATCH (xXagDestroyAssocReq);
/* Macintosh, OS/2, and MS-Windows servers have some work to do here */
return client->noClientException;
}
static
int ProcXagDispatch (
ClientPtr client)
{
REQUEST (xReq);
switch (stuff->data)
{
case X_XagQueryVersion:
return ProcXagQueryVersion (client);
case X_XagCreate:
return ProcXagCreate (client);
case X_XagDestroy:
return ProcXagDestroy (client);
case X_XagGetAttr:
return ProcXagGetAttr (client);
case X_XagQuery:
return ProcXagQuery (client);
case X_XagCreateAssoc:
return ProcXagCreateAssoc (client);
case X_XagDestroyAssoc:
return ProcXagDestroyAssoc (client);
default:
return BadRequest;
}
}
static
int SProcXagQueryVersion(
ClientPtr client)
{
int n;
REQUEST(xXagQueryVersionReq);
swaps(&stuff->length, n);
return ProcXagQueryVersion(client);
}
static
int SProcXagCreate(
ClientPtr client)
{
int n;
REQUEST (xXagCreateReq);
swaps (&stuff->length, n);
REQUEST_AT_LEAST_SIZE (xXagCreateReq);
swapl (&stuff->app_group, n);
swapl (&stuff->attrib_mask, n);
SwapRestL (stuff);
return ProcXagCreate (client);
}
static
int SProcXagDestroy(
ClientPtr client)
{
int n;
REQUEST (xXagDestroyReq);
swaps (&stuff->length, n);
REQUEST_SIZE_MATCH (xXagDestroyReq);
swapl (&stuff->app_group, n);
return ProcXagDestroy (client);
}
static
int SProcXagGetAttr(
ClientPtr client)
{
int n;
REQUEST (xXagGetAttrReq);
swaps (&stuff->length, n);
REQUEST_SIZE_MATCH (xXagGetAttrReq);
swapl (&stuff->app_group, n);
return ProcXagGetAttr (client);
}
static
int SProcXagQuery(
ClientPtr client)
{
int n;
REQUEST (xXagQueryReq);
swaps (&stuff->length, n);
REQUEST_SIZE_MATCH (xXagQueryReq);
swapl (&stuff->resource, n);
return ProcXagQuery (client);
}
static
int SProcXagCreateAssoc(
ClientPtr client)
{
int n;
REQUEST (xXagCreateAssocReq);
swaps (&stuff->length, n);
REQUEST_SIZE_MATCH (xXagCreateAssocReq);
swapl (&stuff->window, n);
swapl (&stuff->window_type, n);
swaps (&stuff->system_window_len, n);
return ProcXagCreateAssoc (client);
}
static
int SProcXagDestroyAssoc(
ClientPtr client)
{
int n;
REQUEST (xXagDestroyAssocReq);
swaps (&stuff->length, n);
REQUEST_SIZE_MATCH (xXagDestroyAssocReq);
swapl (&stuff->window, n);
return ProcXagDestroyAssoc (client);
}
static
int SProcXagDispatch(
ClientPtr client)
{
REQUEST(xReq);
switch (stuff->data)
{
case X_XagQueryVersion:
return SProcXagQueryVersion (client);
case X_XagCreate:
return SProcXagCreate (client);
case X_XagDestroy:
return SProcXagDestroy (client);
case X_XagGetAttr:
return SProcXagGetAttr (client);
case X_XagQuery:
return SProcXagQuery (client);
case X_XagCreateAssoc:
return SProcXagCreateAssoc (client);
case X_XagDestroyAssoc:
return SProcXagDestroyAssoc (client);
default:
return BadRequest;
}
}
Colormap XagDefaultColormap(
ClientPtr client)
{
return (client->appgroup ? client->appgroup->default_colormap : None);
}
VisualID XagRootVisual(
ClientPtr client)
{
return (client->appgroup ? client->appgroup->root_visual : 0);
}
ClientPtr XagLeader(
ClientPtr client)
{
return (client->appgroup ? client->appgroup->leader : NULL);
}
/*
* Return whether the Map request event should be sent to the appgroup leader.
* We don't want to send it to the leader when the window is on a different
* screen, e.g. a print screen.
*/
Bool XagIsControlledRoot(
ClientPtr client,
WindowPtr pParent)
{
if (client->appgroup) {
if (client->appgroup->single_screen &&
pParent->drawable.id == client->appgroup->default_root)
return TRUE;
else if (!pParent->parent)
return TRUE;
else
return FALSE;
}
return FALSE;
}
void XagConnectionInfo(
ClientPtr client,
xConnSetupPrefix** conn_prefix,
char** conn_info,
int* num_screen)
{
if (client->appgroup && client->appgroup->ConnectionInfo) {
*conn_prefix = &client->appgroup->connSetupPrefix;
*conn_info = client->appgroup->ConnectionInfo;
*num_screen = ((xConnSetup*)(client->appgroup->ConnectionInfo))->numRoots;
}
}
XID XagId(
ClientPtr client)
{
return (client->appgroup ? client->appgroup->appgroupId : 0);
}
static void XagCallClientStateChange(
CallbackListPtr *pcbl,
pointer nulldata,
pointer calldata)
{
XaceAuthAvailRec* rec = (XaceAuthAvailRec*) calldata;
ClientPtr pClient = rec->client;
if (!pClient->appgroup) {
SecurityAuthorizationPtr pAuth;
XID authId = rec->authId;
/* can't use SecurityLookupIDByType here -- client
* security state hasn't been setup yet.
*/
pAuth = (SecurityAuthorizationPtr)LookupIDByType(authId,
SecurityAuthorizationResType);
if (!pAuth)
return;
pClient->appgroup = (AppGroupPtr)LookupIDByType(pAuth->group,
RT_APPGROUP);
}
if (pClient->appgroup) {
NewClientInfoRec clientinfo;
clientinfo.client = pClient;
XagClientStateChange (NULL, NULL, (pointer)&clientinfo);
}
}
void
XagExtensionInit(INITARGS)
{
if (AddExtension (XAGNAME,
0,
XagNumberErrors,
ProcXagDispatch,
SProcXagDispatch,
XagResetProc,
StandardMinorOpcode)) {
RT_APPGROUP = CreateNewResourceType (XagAppGroupFree);
XaceRegisterCallback(XACE_AUTH_AVAIL, XagCallClientStateChange, NULL);
}
}
|