1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
25 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 ******************************************************************/
47 #ifdef HAVE_DIX_CONFIG_H
48 #include <dix-config.h>
52 #include <X11/Xproto.h>
53 #include "windowstr.h"
54 #include "propertyst.h"
55 #include "dixstruct.h"
60 /*****************************************************************
63 * dixLookupProperty, dixChangeProperty, DeleteProperty
65 * Properties belong to windows. The list of properties should not be
66 * traversed directly. Instead, use the three functions listed above.
68 *****************************************************************/
72 PrintPropertys(WindowPtr pWin
)
77 pProp
= pWin
->userProps
;
79 ErrorF("[dix] %x %x\n", pProp
->propertyName
, pProp
->type
);
80 ErrorF("[dix] property format: %d\n", pProp
->format
);
81 ErrorF("[dix] property data: \n");
82 for (j
= 0; j
< (pProp
->format
/ 8) * pProp
->size
; j
++)
83 ErrorF("[dix] %c\n", pProp
->data
[j
]);
90 dixLookupProperty(PropertyPtr
*result
, WindowPtr pWin
, Atom propertyName
,
91 ClientPtr client
, Mask access_mode
)
96 client
->errorValue
= propertyName
;
98 for (pProp
= wUserProps(pWin
); pProp
; pProp
= pProp
->next
)
99 if (pProp
->propertyName
== propertyName
)
103 rc
= XaceHookPropertyAccess(client
, pWin
, &pProp
, access_mode
);
109 deliverPropertyNotifyEvent(WindowPtr pWin
, int state
, Atom atom
)
112 .u
.property
.window
= pWin
->drawable
.id
,
113 .u
.property
.state
= state
,
114 .u
.property
.atom
= atom
,
115 .u
.property
.time
= currentTime
.milliseconds
117 event
.u
.u
.type
= PropertyNotify
;
118 DeliverEvents(pWin
, &event
, 1, (WindowPtr
) NULL
);
122 ProcRotateProperties(ClientPtr client
)
126 REQUEST(xRotatePropertiesReq
);
129 PropertyPtr
*props
; /* array of pointer */
130 PropertyPtr pProp
, saved
;
132 REQUEST_FIXED_SIZE(xRotatePropertiesReq
, stuff
->nAtoms
<< 2);
134 rc
= dixLookupWindow(&pWin
, stuff
->window
, client
, DixSetPropAccess
);
135 if (rc
!= Success
|| stuff
->nAtoms
<= 0)
138 atoms
= (Atom
*) &stuff
[1];
139 props
= malloc(stuff
->nAtoms
* sizeof(PropertyPtr
));
140 saved
= malloc(stuff
->nAtoms
* sizeof(PropertyRec
));
141 if (!props
|| !saved
) {
146 for (i
= 0; i
< stuff
->nAtoms
; i
++) {
147 if (!ValidAtom(atoms
[i
])) {
149 client
->errorValue
= atoms
[i
];
152 for (j
= i
+ 1; j
< stuff
->nAtoms
; j
++)
153 if (atoms
[j
] == atoms
[i
]) {
158 rc
= dixLookupProperty(&pProp
, pWin
, atoms
[i
], client
,
159 DixReadAccess
| DixWriteAccess
);
166 delta
= stuff
->nPositions
;
168 /* If the rotation is a complete 360 degrees, then moving the properties
169 around and generating PropertyNotify events should be skipped. */
171 if (abs(delta
) % stuff
->nAtoms
) {
172 while (delta
< 0) /* faster if abs value is small */
173 delta
+= stuff
->nAtoms
;
174 for (i
= 0; i
< stuff
->nAtoms
; i
++) {
175 j
= (i
+ delta
) % stuff
->nAtoms
;
176 deliverPropertyNotifyEvent(pWin
, PropertyNewValue
, atoms
[i
]);
178 /* Preserve name and devPrivates */
179 props
[j
]->type
= saved
[i
].type
;
180 props
[j
]->format
= saved
[i
].format
;
181 props
[j
]->size
= saved
[i
].size
;
182 props
[j
]->data
= saved
[i
].data
;
192 ProcChangeProperty(ClientPtr client
)
197 int sizeInBytes
, totalSize
, err
;
199 REQUEST(xChangePropertyReq
);
201 REQUEST_AT_LEAST_SIZE(xChangePropertyReq
);
203 format
= stuff
->format
;
205 if ((mode
!= PropModeReplace
) && (mode
!= PropModeAppend
) &&
206 (mode
!= PropModePrepend
)) {
207 client
->errorValue
= mode
;
210 if ((format
!= 8) && (format
!= 16) && (format
!= 32)) {
211 client
->errorValue
= format
;
215 if (len
> bytes_to_int32(0xffffffff - sizeof(xChangePropertyReq
)))
217 sizeInBytes
= format
>> 3;
218 totalSize
= len
* sizeInBytes
;
219 REQUEST_FIXED_SIZE(xChangePropertyReq
, totalSize
);
221 err
= dixLookupWindow(&pWin
, stuff
->window
, client
, DixSetPropAccess
);
224 if (!ValidAtom(stuff
->property
)) {
225 client
->errorValue
= stuff
->property
;
228 if (!ValidAtom(stuff
->type
)) {
229 client
->errorValue
= stuff
->type
;
233 err
= dixChangeWindowProperty(client
, pWin
, stuff
->property
, stuff
->type
,
234 (int) format
, (int) mode
, len
, &stuff
[1],
243 dixChangeWindowProperty(ClientPtr pClient
, WindowPtr pWin
, Atom property
,
244 Atom type
, int format
, int mode
, unsigned long len
,
245 pointer value
, Bool sendevent
)
248 PropertyRec savedProp
;
249 int sizeInBytes
, totalSize
, rc
;
253 sizeInBytes
= format
>> 3;
254 totalSize
= len
* sizeInBytes
;
255 access_mode
= (mode
== PropModeReplace
) ? DixWriteAccess
: DixBlendAccess
;
257 /* first see if property already exists */
258 rc
= dixLookupProperty(&pProp
, pWin
, property
, pClient
, access_mode
);
260 if (rc
== BadMatch
) { /* just add to list */
261 if (!pWin
->optional
&& !MakeWindowOptional(pWin
))
263 pProp
= dixAllocateObjectWithPrivates(PropertyRec
, PRIVATE_PROPERTY
);
266 data
= malloc(totalSize
);
268 dixFreeObjectWithPrivates(pProp
, PRIVATE_PROPERTY
);
271 memcpy(data
, value
, totalSize
);
272 pProp
->propertyName
= property
;
274 pProp
->format
= format
;
277 rc
= XaceHookPropertyAccess(pClient
, pWin
, &pProp
,
278 DixCreateAccess
| DixWriteAccess
);
281 dixFreeObjectWithPrivates(pProp
, PRIVATE_PROPERTY
);
282 pClient
->errorValue
= property
;
285 pProp
->next
= pWin
->optional
->userProps
;
286 pWin
->optional
->userProps
= pProp
;
288 else if (rc
== Success
) {
289 /* To append or prepend to a property the request format and type
290 must match those of the already defined property. The
291 existing format and type are irrelevant when using the mode
292 "PropModeReplace" since they will be written over. */
294 if ((format
!= pProp
->format
) && (mode
!= PropModeReplace
))
296 if ((pProp
->type
!= type
) && (mode
!= PropModeReplace
))
299 /* save the old values for later */
302 if (mode
== PropModeReplace
) {
303 data
= malloc(totalSize
);
306 memcpy(data
, value
, totalSize
);
310 pProp
->format
= format
;
315 else if (mode
== PropModeAppend
) {
316 data
= malloc((pProp
->size
+ len
) * sizeInBytes
);
319 memcpy(data
, pProp
->data
, pProp
->size
* sizeInBytes
);
320 memcpy(data
+ pProp
->size
* sizeInBytes
, value
, totalSize
);
324 else if (mode
== PropModePrepend
) {
325 data
= malloc(sizeInBytes
* (len
+ pProp
->size
));
328 memcpy(data
+ totalSize
, pProp
->data
, pProp
->size
* sizeInBytes
);
329 memcpy(data
, value
, totalSize
);
334 /* Allow security modules to check the new content */
335 access_mode
|= DixPostAccess
;
336 rc
= XaceHookPropertyAccess(pClient
, pWin
, &pProp
, access_mode
);
338 if (savedProp
.data
!= pProp
->data
)
339 free(savedProp
.data
);
342 if (savedProp
.data
!= pProp
->data
)
352 deliverPropertyNotifyEvent(pWin
, PropertyNewValue
, pProp
->propertyName
);
358 ChangeWindowProperty(WindowPtr pWin
, Atom property
, Atom type
, int format
,
359 int mode
, unsigned long len
, pointer value
, Bool sendevent
)
361 return dixChangeWindowProperty(serverClient
, pWin
, property
, type
, format
,
362 mode
, len
, value
, sendevent
);
366 DeleteProperty(ClientPtr client
, WindowPtr pWin
, Atom propName
)
368 PropertyPtr pProp
, prevProp
;
371 rc
= dixLookupProperty(&pProp
, pWin
, propName
, client
, DixDestroyAccess
);
373 return Success
; /* Succeed if property does not exist */
376 if (pWin
->optional
->userProps
== pProp
) {
377 /* Takes care of head */
378 if (!(pWin
->optional
->userProps
= pProp
->next
))
379 CheckWindowOptionalNeed(pWin
);
382 /* Need to traverse to find the previous element */
383 prevProp
= pWin
->optional
->userProps
;
384 while (prevProp
->next
!= pProp
)
385 prevProp
= prevProp
->next
;
386 prevProp
->next
= pProp
->next
;
389 deliverPropertyNotifyEvent(pWin
, PropertyDelete
, pProp
->propertyName
);
391 dixFreeObjectWithPrivates(pProp
, PRIVATE_PROPERTY
);
397 DeleteAllWindowProperties(WindowPtr pWin
)
399 PropertyPtr pProp
, pNextProp
;
401 pProp
= wUserProps(pWin
);
403 deliverPropertyNotifyEvent(pWin
, PropertyDelete
, pProp
->propertyName
);
404 pNextProp
= pProp
->next
;
406 dixFreeObjectWithPrivates(pProp
, PRIVATE_PROPERTY
);
411 pWin
->optional
->userProps
= NULL
;
415 NullPropertyReply(ClientPtr client
, ATOM propertyType
, int format
)
417 xGetPropertyReply reply
= {
420 .sequenceNumber
= client
->sequence
,
422 .propertyType
= propertyType
,
426 WriteReplyToClient(client
, sizeof(xGenericReply
), &reply
);
432 * If type Any is specified, returns the property from the specified
433 * window regardless of its type. If a type is specified, returns the
434 * property only if its type equals the specified type.
435 * If delete is True and a property is returned, the property is also
436 * deleted from the window and a PropertyNotify event is generated on the
441 ProcGetProperty(ClientPtr client
)
443 PropertyPtr pProp
, prevProp
;
444 unsigned long n
, len
, ind
;
447 xGetPropertyReply reply
;
448 Mask win_mode
= DixGetPropAccess
, prop_mode
= DixReadAccess
;
450 REQUEST(xGetPropertyReq
);
452 REQUEST_SIZE_MATCH(xGetPropertyReq
);
455 win_mode
|= DixSetPropAccess
;
456 prop_mode
|= DixDestroyAccess
;
458 rc
= dixLookupWindow(&pWin
, stuff
->window
, client
, win_mode
);
462 if (!ValidAtom(stuff
->property
)) {
463 client
->errorValue
= stuff
->property
;
466 if ((stuff
->delete != xTrue
) && (stuff
->delete != xFalse
)) {
467 client
->errorValue
= stuff
->delete;
470 if ((stuff
->type
!= AnyPropertyType
) && !ValidAtom(stuff
->type
)) {
471 client
->errorValue
= stuff
->type
;
475 rc
= dixLookupProperty(&pProp
, pWin
, stuff
->property
, client
, prop_mode
);
477 return NullPropertyReply(client
, None
, 0);
478 else if (rc
!= Success
)
481 /* If the request type and actual type don't match. Return the
482 property information, but not the data. */
484 if (((stuff
->type
!= pProp
->type
) && (stuff
->type
!= AnyPropertyType
))
486 reply
= (xGetPropertyReply
) {
488 .sequenceNumber
= client
->sequence
,
489 .bytesAfter
= pProp
->size
,
490 .format
= pProp
->format
,
493 .propertyType
= pProp
->type
495 WriteReplyToClient(client
, sizeof(xGenericReply
), &reply
);
500 * Return type, format, value to client
502 n
= (pProp
->format
/ 8) * pProp
->size
; /* size (bytes) of prop */
503 ind
= stuff
->longOffset
<< 2;
505 /* If longOffset is invalid such that it causes "len" to
506 be negative, it's a value error. */
509 client
->errorValue
= stuff
->longOffset
;
513 len
= min(n
- ind
, 4 * stuff
->longLength
);
515 reply
= (xGetPropertyReply
) {
517 .sequenceNumber
= client
->sequence
,
518 .bytesAfter
= n
- (ind
+ len
),
519 .format
= pProp
->format
,
520 .length
= bytes_to_int32(len
),
521 .nItems
= len
/ (pProp
->format
/ 8),
522 .propertyType
= pProp
->type
525 if (stuff
->delete && (reply
.bytesAfter
== 0))
526 deliverPropertyNotifyEvent(pWin
, PropertyDelete
, pProp
->propertyName
);
528 WriteReplyToClient(client
, sizeof(xGenericReply
), &reply
);
530 switch (reply
.format
) {
532 client
->pSwapReplyFunc
= (ReplySwapPtr
) CopySwap32Write
;
535 client
->pSwapReplyFunc
= (ReplySwapPtr
) CopySwap16Write
;
538 client
->pSwapReplyFunc
= (ReplySwapPtr
) WriteToClient
;
541 WriteSwappedDataToClient(client
, len
, (char *) pProp
->data
+ ind
);
544 if (stuff
->delete && (reply
.bytesAfter
== 0)) {
545 /* Delete the Property */
546 if (pWin
->optional
->userProps
== pProp
) {
547 /* Takes care of head */
548 if (!(pWin
->optional
->userProps
= pProp
->next
))
549 CheckWindowOptionalNeed(pWin
);
552 /* Need to traverse to find the previous element */
553 prevProp
= pWin
->optional
->userProps
;
554 while (prevProp
->next
!= pProp
)
555 prevProp
= prevProp
->next
;
556 prevProp
->next
= pProp
->next
;
560 dixFreeObjectWithPrivates(pProp
, PRIVATE_PROPERTY
);
566 ProcListProperties(ClientPtr client
)
568 Atom
*pAtoms
= NULL
, *temppAtoms
;
569 xListPropertiesReply xlpr
;
570 int rc
, numProps
= 0;
572 PropertyPtr pProp
, realProp
;
574 REQUEST(xResourceReq
);
576 REQUEST_SIZE_MATCH(xResourceReq
);
577 rc
= dixLookupWindow(&pWin
, stuff
->id
, client
, DixListPropAccess
);
581 for (pProp
= wUserProps(pWin
); pProp
; pProp
= pProp
->next
)
584 if (numProps
&& !(pAtoms
= malloc(numProps
* sizeof(Atom
))))
589 for (pProp
= wUserProps(pWin
); pProp
; pProp
= pProp
->next
) {
591 rc
= XaceHookPropertyAccess(client
, pWin
, &realProp
, DixGetAttrAccess
);
592 if (rc
== Success
&& realProp
== pProp
) {
593 *temppAtoms
++ = pProp
->propertyName
;
598 xlpr
= (xListPropertiesReply
) {
600 .sequenceNumber
= client
->sequence
,
601 .length
= bytes_to_int32(numProps
* sizeof(Atom
)),
602 .nProperties
= numProps
604 WriteReplyToClient(client
, sizeof(xGenericReply
), &xlpr
);
606 client
->pSwapReplyFunc
= (ReplySwapPtr
) Swap32Write
;
607 WriteSwappedDataToClient(client
, numProps
* sizeof(Atom
), pAtoms
);
614 ProcDeleteProperty(ClientPtr client
)
618 REQUEST(xDeletePropertyReq
);
621 REQUEST_SIZE_MATCH(xDeletePropertyReq
);
623 result
= dixLookupWindow(&pWin
, stuff
->window
, client
, DixSetPropAccess
);
624 if (result
!= Success
)
626 if (!ValidAtom(stuff
->property
)) {
627 client
->errorValue
= stuff
->property
;
631 return DeleteProperty(client
, pWin
, stuff
->property
);