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
)
113 memset(&event
, 0, sizeof(xEvent
));
114 event
.u
.u
.type
= PropertyNotify
;
115 event
.u
.property
.window
= pWin
->drawable
.id
;
116 event
.u
.property
.state
= state
;
117 event
.u
.property
.atom
= atom
;
118 event
.u
.property
.time
= currentTime
.milliseconds
;
119 DeliverEvents(pWin
, &event
, 1, (WindowPtr
) NULL
);
123 ProcRotateProperties(ClientPtr client
)
127 REQUEST(xRotatePropertiesReq
);
130 PropertyPtr
*props
; /* array of pointer */
131 PropertyPtr pProp
, saved
;
133 REQUEST_FIXED_SIZE(xRotatePropertiesReq
, stuff
->nAtoms
<< 2);
135 rc
= dixLookupWindow(&pWin
, stuff
->window
, client
, DixSetPropAccess
);
136 if (rc
!= Success
|| stuff
->nAtoms
<= 0)
139 atoms
= (Atom
*) &stuff
[1];
140 props
= malloc(stuff
->nAtoms
* sizeof(PropertyPtr
));
141 saved
= malloc(stuff
->nAtoms
* sizeof(PropertyRec
));
142 if (!props
|| !saved
) {
147 for (i
= 0; i
< stuff
->nAtoms
; i
++) {
148 if (!ValidAtom(atoms
[i
])) {
150 client
->errorValue
= atoms
[i
];
153 for (j
= i
+ 1; j
< stuff
->nAtoms
; j
++)
154 if (atoms
[j
] == atoms
[i
]) {
159 rc
= dixLookupProperty(&pProp
, pWin
, atoms
[i
], client
,
160 DixReadAccess
| DixWriteAccess
);
167 delta
= stuff
->nPositions
;
169 /* If the rotation is a complete 360 degrees, then moving the properties
170 around and generating PropertyNotify events should be skipped. */
172 if (abs(delta
) % stuff
->nAtoms
) {
173 while (delta
< 0) /* faster if abs value is small */
174 delta
+= stuff
->nAtoms
;
175 for (i
= 0; i
< stuff
->nAtoms
; i
++) {
176 j
= (i
+ delta
) % stuff
->nAtoms
;
177 deliverPropertyNotifyEvent(pWin
, PropertyNewValue
, atoms
[i
]);
179 /* Preserve name and devPrivates */
180 props
[j
]->type
= saved
[i
].type
;
181 props
[j
]->format
= saved
[i
].format
;
182 props
[j
]->size
= saved
[i
].size
;
183 props
[j
]->data
= saved
[i
].data
;
193 ProcChangeProperty(ClientPtr client
)
198 int sizeInBytes
, totalSize
, err
;
200 REQUEST(xChangePropertyReq
);
202 REQUEST_AT_LEAST_SIZE(xChangePropertyReq
);
204 format
= stuff
->format
;
206 if ((mode
!= PropModeReplace
) && (mode
!= PropModeAppend
) &&
207 (mode
!= PropModePrepend
)) {
208 client
->errorValue
= mode
;
211 if ((format
!= 8) && (format
!= 16) && (format
!= 32)) {
212 client
->errorValue
= format
;
216 if (len
> bytes_to_int32(0xffffffff - sizeof(xChangePropertyReq
)))
218 sizeInBytes
= format
>> 3;
219 totalSize
= len
* sizeInBytes
;
220 REQUEST_FIXED_SIZE(xChangePropertyReq
, totalSize
);
222 err
= dixLookupWindow(&pWin
, stuff
->window
, client
, DixSetPropAccess
);
225 if (!ValidAtom(stuff
->property
)) {
226 client
->errorValue
= stuff
->property
;
229 if (!ValidAtom(stuff
->type
)) {
230 client
->errorValue
= stuff
->type
;
234 err
= dixChangeWindowProperty(client
, pWin
, stuff
->property
, stuff
->type
,
235 (int) format
, (int) mode
, len
, &stuff
[1],
244 dixChangeWindowProperty(ClientPtr pClient
, WindowPtr pWin
, Atom property
,
245 Atom type
, int format
, int mode
, unsigned long len
,
246 pointer value
, Bool sendevent
)
249 PropertyRec savedProp
;
250 int sizeInBytes
, totalSize
, rc
;
254 sizeInBytes
= format
>> 3;
255 totalSize
= len
* sizeInBytes
;
256 access_mode
= (mode
== PropModeReplace
) ? DixWriteAccess
: DixBlendAccess
;
258 /* first see if property already exists */
259 rc
= dixLookupProperty(&pProp
, pWin
, property
, pClient
, access_mode
);
261 if (rc
== BadMatch
) { /* just add to list */
262 if (!pWin
->optional
&& !MakeWindowOptional(pWin
))
264 pProp
= dixAllocateObjectWithPrivates(PropertyRec
, PRIVATE_PROPERTY
);
267 data
= malloc(totalSize
);
269 dixFreeObjectWithPrivates(pProp
, PRIVATE_PROPERTY
);
272 memcpy(data
, value
, totalSize
);
273 pProp
->propertyName
= property
;
275 pProp
->format
= format
;
278 rc
= XaceHookPropertyAccess(pClient
, pWin
, &pProp
,
279 DixCreateAccess
| DixWriteAccess
);
282 dixFreeObjectWithPrivates(pProp
, PRIVATE_PROPERTY
);
283 pClient
->errorValue
= property
;
286 pProp
->next
= pWin
->optional
->userProps
;
287 pWin
->optional
->userProps
= pProp
;
289 else if (rc
== Success
) {
290 /* To append or prepend to a property the request format and type
291 must match those of the already defined property. The
292 existing format and type are irrelevant when using the mode
293 "PropModeReplace" since they will be written over. */
295 if ((format
!= pProp
->format
) && (mode
!= PropModeReplace
))
297 if ((pProp
->type
!= type
) && (mode
!= PropModeReplace
))
300 /* save the old values for later */
303 if (mode
== PropModeReplace
) {
304 data
= malloc(totalSize
);
307 memcpy(data
, value
, totalSize
);
311 pProp
->format
= format
;
316 else if (mode
== PropModeAppend
) {
317 data
= malloc((pProp
->size
+ len
) * sizeInBytes
);
320 memcpy(data
, pProp
->data
, pProp
->size
* sizeInBytes
);
321 memcpy(data
+ pProp
->size
* sizeInBytes
, value
, totalSize
);
325 else if (mode
== PropModePrepend
) {
326 data
= malloc(sizeInBytes
* (len
+ pProp
->size
));
329 memcpy(data
+ totalSize
, pProp
->data
, pProp
->size
* sizeInBytes
);
330 memcpy(data
, value
, totalSize
);
335 /* Allow security modules to check the new content */
336 access_mode
|= DixPostAccess
;
337 rc
= XaceHookPropertyAccess(pClient
, pWin
, &pProp
, access_mode
);
339 if (savedProp
.data
!= pProp
->data
)
340 free(savedProp
.data
);
343 if (savedProp
.data
!= pProp
->data
)
353 deliverPropertyNotifyEvent(pWin
, PropertyNewValue
, pProp
->propertyName
);
359 ChangeWindowProperty(WindowPtr pWin
, Atom property
, Atom type
, int format
,
360 int mode
, unsigned long len
, pointer value
, Bool sendevent
)
362 return dixChangeWindowProperty(serverClient
, pWin
, property
, type
, format
,
363 mode
, len
, value
, sendevent
);
367 DeleteProperty(ClientPtr client
, WindowPtr pWin
, Atom propName
)
369 PropertyPtr pProp
, prevProp
;
372 rc
= dixLookupProperty(&pProp
, pWin
, propName
, client
, DixDestroyAccess
);
374 return Success
; /* Succeed if property does not exist */
377 if (pWin
->optional
->userProps
== pProp
) {
378 /* Takes care of head */
379 if (!(pWin
->optional
->userProps
= pProp
->next
))
380 CheckWindowOptionalNeed(pWin
);
383 /* Need to traverse to find the previous element */
384 prevProp
= pWin
->optional
->userProps
;
385 while (prevProp
->next
!= pProp
)
386 prevProp
= prevProp
->next
;
387 prevProp
->next
= pProp
->next
;
390 deliverPropertyNotifyEvent(pWin
, PropertyDelete
, pProp
->propertyName
);
392 dixFreeObjectWithPrivates(pProp
, PRIVATE_PROPERTY
);
398 DeleteAllWindowProperties(WindowPtr pWin
)
400 PropertyPtr pProp
, pNextProp
;
402 pProp
= wUserProps(pWin
);
404 deliverPropertyNotifyEvent(pWin
, PropertyDelete
, pProp
->propertyName
);
405 pNextProp
= pProp
->next
;
407 dixFreeObjectWithPrivates(pProp
, PRIVATE_PROPERTY
);
412 pWin
->optional
->userProps
= NULL
;
416 NullPropertyReply(ClientPtr client
,
417 ATOM propertyType
, int format
, xGetPropertyReply
* reply
)
421 reply
->bytesAfter
= 0;
422 reply
->propertyType
= propertyType
;
423 reply
->format
= format
;
424 WriteReplyToClient(client
, sizeof(xGenericReply
), reply
);
430 * If type Any is specified, returns the property from the specified
431 * window regardless of its type. If a type is specified, returns the
432 * property only if its type equals the specified type.
433 * If delete is True and a property is returned, the property is also
434 * deleted from the window and a PropertyNotify event is generated on the
439 ProcGetProperty(ClientPtr client
)
441 PropertyPtr pProp
, prevProp
;
442 unsigned long n
, len
, ind
;
445 xGetPropertyReply reply
;
446 Mask win_mode
= DixGetPropAccess
, prop_mode
= DixReadAccess
;
448 REQUEST(xGetPropertyReq
);
450 REQUEST_SIZE_MATCH(xGetPropertyReq
);
453 win_mode
|= DixSetPropAccess
;
454 prop_mode
|= DixDestroyAccess
;
456 rc
= dixLookupWindow(&pWin
, stuff
->window
, client
, win_mode
);
460 if (!ValidAtom(stuff
->property
)) {
461 client
->errorValue
= stuff
->property
;
464 if ((stuff
->delete != xTrue
) && (stuff
->delete != xFalse
)) {
465 client
->errorValue
= stuff
->delete;
468 if ((stuff
->type
!= AnyPropertyType
) && !ValidAtom(stuff
->type
)) {
469 client
->errorValue
= stuff
->type
;
473 memset(&reply
, 0, sizeof(xGetPropertyReply
));
474 reply
.type
= X_Reply
;
475 reply
.sequenceNumber
= client
->sequence
;
477 rc
= dixLookupProperty(&pProp
, pWin
, stuff
->property
, client
, prop_mode
);
479 return NullPropertyReply(client
, None
, 0, &reply
);
480 else if (rc
!= Success
)
483 /* If the request type and actual type don't match. Return the
484 property information, but not the data. */
486 if (((stuff
->type
!= pProp
->type
) && (stuff
->type
!= AnyPropertyType
))
488 reply
.bytesAfter
= pProp
->size
;
489 reply
.format
= pProp
->format
;
492 reply
.propertyType
= pProp
->type
;
493 WriteReplyToClient(client
, sizeof(xGenericReply
), &reply
);
498 * Return type, format, value to client
500 n
= (pProp
->format
/ 8) * pProp
->size
; /* size (bytes) of prop */
501 ind
= stuff
->longOffset
<< 2;
503 /* If longOffset is invalid such that it causes "len" to
504 be negative, it's a value error. */
507 client
->errorValue
= stuff
->longOffset
;
511 len
= min(n
- ind
, 4 * stuff
->longLength
);
513 reply
.bytesAfter
= n
- (ind
+ len
);
514 reply
.format
= pProp
->format
;
515 reply
.length
= bytes_to_int32(len
);
516 reply
.nItems
= len
/ (pProp
->format
/ 8);
517 reply
.propertyType
= pProp
->type
;
519 if (stuff
->delete && (reply
.bytesAfter
== 0))
520 deliverPropertyNotifyEvent(pWin
, PropertyDelete
, pProp
->propertyName
);
522 WriteReplyToClient(client
, sizeof(xGenericReply
), &reply
);
524 switch (reply
.format
) {
526 client
->pSwapReplyFunc
= (ReplySwapPtr
) CopySwap32Write
;
529 client
->pSwapReplyFunc
= (ReplySwapPtr
) CopySwap16Write
;
532 client
->pSwapReplyFunc
= (ReplySwapPtr
) WriteToClient
;
535 WriteSwappedDataToClient(client
, len
, (char *) pProp
->data
+ ind
);
538 if (stuff
->delete && (reply
.bytesAfter
== 0)) {
539 /* Delete the Property */
540 if (pWin
->optional
->userProps
== pProp
) {
541 /* Takes care of head */
542 if (!(pWin
->optional
->userProps
= pProp
->next
))
543 CheckWindowOptionalNeed(pWin
);
546 /* Need to traverse to find the previous element */
547 prevProp
= pWin
->optional
->userProps
;
548 while (prevProp
->next
!= pProp
)
549 prevProp
= prevProp
->next
;
550 prevProp
->next
= pProp
->next
;
554 dixFreeObjectWithPrivates(pProp
, PRIVATE_PROPERTY
);
560 ProcListProperties(ClientPtr client
)
562 Atom
*pAtoms
= NULL
, *temppAtoms
;
563 xListPropertiesReply xlpr
;
564 int rc
, numProps
= 0;
566 PropertyPtr pProp
, realProp
;
568 REQUEST(xResourceReq
);
570 REQUEST_SIZE_MATCH(xResourceReq
);
571 rc
= dixLookupWindow(&pWin
, stuff
->id
, client
, DixListPropAccess
);
575 for (pProp
= wUserProps(pWin
); pProp
; pProp
= pProp
->next
)
578 if (numProps
&& !(pAtoms
= malloc(numProps
* sizeof(Atom
))))
583 for (pProp
= wUserProps(pWin
); pProp
; pProp
= pProp
->next
) {
585 rc
= XaceHookPropertyAccess(client
, pWin
, &realProp
, DixGetAttrAccess
);
586 if (rc
== Success
&& realProp
== pProp
) {
587 *temppAtoms
++ = pProp
->propertyName
;
593 xlpr
.nProperties
= numProps
;
594 xlpr
.length
= bytes_to_int32(numProps
* sizeof(Atom
));
595 xlpr
.sequenceNumber
= client
->sequence
;
596 WriteReplyToClient(client
, sizeof(xGenericReply
), &xlpr
);
598 client
->pSwapReplyFunc
= (ReplySwapPtr
) Swap32Write
;
599 WriteSwappedDataToClient(client
, numProps
* sizeof(Atom
), pAtoms
);
606 ProcDeleteProperty(ClientPtr client
)
610 REQUEST(xDeletePropertyReq
);
613 REQUEST_SIZE_MATCH(xDeletePropertyReq
);
615 result
= dixLookupWindow(&pWin
, stuff
->window
, client
, DixSetPropAccess
);
616 if (result
!= Success
)
618 if (!ValidAtom(stuff
->property
)) {
619 client
->errorValue
= stuff
->property
;
623 return DeleteProperty(client
, pWin
, stuff
->property
);