2 * $Xorg: XShape.c,v 1.4 2001/02/09 02:03:49 xorgcvs Exp $
4 Copyright 1989, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
26 * Author: Keith Packard, MIT X Consortium
28 /* $XFree86: xc/lib/Xext/XShape.c,v 1.3 2002/10/16 00:37:27 dawes Exp $ */
34 #include <X11/Xlibint.h>
35 #include <X11/Xutil.h>
36 #include <X11/Xregion.h>
37 #include <X11/extensions/Xext.h>
38 #include <X11/extensions/extutil.h>
39 #include <X11/extensions/shapestr.h>
41 static XExtensionInfo _shape_info_data
;
42 static XExtensionInfo
*shape_info
= &_shape_info_data
;
43 static /* const */ char *shape_extension_name
= SHAPENAME
;
45 #define ShapeCheckExtension(dpy,i,val) \
46 XextCheckExtension (dpy, i, shape_extension_name, val)
47 #define ShapeSimpleCheckExtension(dpy,i) \
48 XextSimpleCheckExtension (dpy, i, shape_extension_name)
51 /*****************************************************************************
53 * private utility routines *
55 *****************************************************************************/
57 static int close_display(Display
*dpy
, XExtCodes
*codes
);
58 static Bool
wire_to_event (Display
*dpy
, XEvent
*re
, xEvent
*event
);
59 static Status
event_to_wire (Display
*dpy
, XEvent
*re
, xEvent
*event
);
60 static /* const */ XExtensionHooks shape_extension_hooks
= {
65 NULL
, /* create_font */
67 close_display
, /* close_display */
68 wire_to_event
, /* wire_to_event */
69 event_to_wire
, /* event_to_wire */
71 NULL
, /* error_string */
74 static XEXT_GENERATE_FIND_DISPLAY (find_display
, shape_info
,
76 &shape_extension_hooks
,
77 ShapeNumberEvents
, NULL
)
79 static XEXT_GENERATE_CLOSE_DISPLAY (close_display
, shape_info
)
83 wire_to_event (Display
*dpy
, XEvent
*re
, xEvent
*event
)
85 XExtDisplayInfo
*info
= find_display (dpy
);
87 xShapeNotifyEvent
*sevent
;
89 ShapeCheckExtension (dpy
, info
, False
);
91 switch ((event
->u
.u
.type
& 0x7f) - info
->codes
->first_event
) {
93 se
= (XShapeEvent
*) re
;
94 sevent
= (xShapeNotifyEvent
*) event
;
95 se
->type
= sevent
->type
& 0x7f;
96 se
->serial
= _XSetLastRequestRead(dpy
,(xGenericReply
*) event
);
97 se
->send_event
= (sevent
->type
& 0x80) != 0;
99 se
->window
= sevent
->window
;
100 se
->kind
= sevent
->kind
;
101 se
->x
= cvtINT16toInt (sevent
->x
);
102 se
->y
= cvtINT16toInt (sevent
->y
);
103 se
->width
= sevent
->width
;
104 se
->height
= sevent
->height
;
105 se
->time
= sevent
->time
;
107 if (sevent
->shaped
== xFalse
)
115 event_to_wire (Display
*dpy
, XEvent
*re
, xEvent
*event
)
117 XExtDisplayInfo
*info
= find_display (dpy
);
119 xShapeNotifyEvent
*sevent
;
121 ShapeCheckExtension (dpy
, info
, 0);
123 switch ((re
->type
& 0x7f) - info
->codes
->first_event
) {
125 se
= (XShapeEvent
*) re
;
126 sevent
= (xShapeNotifyEvent
*) event
;
127 sevent
->type
= se
->type
| (se
->send_event
? 0x80 : 0);
128 sevent
->sequenceNumber
= se
->serial
& 0xffff;
129 sevent
->window
= se
->window
;
130 sevent
->kind
= se
->kind
;
133 sevent
->width
= se
->width
;
134 sevent
->height
= se
->height
;
135 sevent
->time
= se
->time
;
142 /****************************************************************************
144 * Shape public interfaces *
146 ****************************************************************************/
148 Bool
XShapeQueryExtension (Display
*dpy
, int *event_basep
, int *error_basep
)
150 XExtDisplayInfo
*info
= find_display (dpy
);
152 if (XextHasExtension(info
)) {
153 *event_basep
= info
->codes
->first_event
;
154 *error_basep
= info
->codes
->first_error
;
162 Status
XShapeQueryVersion(
167 XExtDisplayInfo
*info
= find_display (dpy
);
168 xShapeQueryVersionReply rep
;
169 register xShapeQueryVersionReq
*req
;
171 ShapeCheckExtension (dpy
, info
, 0);
174 GetReq (ShapeQueryVersion
, req
);
175 req
->reqType
= info
->codes
->major_opcode
;
176 req
->shapeReqType
= X_ShapeQueryVersion
;
177 if (!_XReply (dpy
, (xReply
*) &rep
, 0, xTrue
)) {
182 *major_versionp
= rep
.majorVersion
;
183 *minor_versionp
= rep
.minorVersion
;
189 void XShapeCombineRegion(
190 register Display
*dpy
,
192 int destKind
, int xOff
, int yOff
,
196 XExtDisplayInfo
*info
= find_display (dpy
);
197 register xShapeRectanglesReq
*req
;
198 register long nbytes
;
200 register XRectangle
*xr
, *pr
;
203 ShapeSimpleCheckExtension (dpy
, info
);
206 GetReq(ShapeRectangles
, req
);
208 _XAllocScratch(dpy
, (unsigned long)(r
->numRects
* sizeof (XRectangle
)));
209 for (pr
= xr
, pb
= r
->rects
, i
= r
->numRects
; --i
>= 0; pr
++, pb
++) {
212 pr
->width
= pb
->x2
- pb
->x1
;
213 pr
->height
= pb
->y2
- pb
->y1
;
215 req
->reqType
= info
->codes
->major_opcode
;
216 req
->shapeReqType
= X_ShapeRectangles
;
218 req
->ordering
= YXBanded
;
219 req
->destKind
= destKind
;
224 /* SIZEOF(xRectangle) will be a multiple of 4 */
225 req
->length
+= r
->numRects
* (SIZEOF(xRectangle
) / 4);
227 nbytes
= r
->numRects
* sizeof(xRectangle
);
229 Data16 (dpy
, (short *) xr
, nbytes
);
235 void XShapeCombineRectangles (
236 register Display
*dpy
,
238 int destKind
, int xOff
, int yOff
,
241 int op
, int ordering
)
243 XExtDisplayInfo
*info
= find_display (dpy
);
244 register xShapeRectanglesReq
*req
;
245 register long nbytes
;
247 ShapeSimpleCheckExtension (dpy
, info
);
250 GetReq(ShapeRectangles
, req
);
251 req
->reqType
= info
->codes
->major_opcode
;
252 req
->shapeReqType
= X_ShapeRectangles
;
254 req
->ordering
= ordering
;
255 req
->destKind
= destKind
;
260 /* SIZEOF(xRectangle) will be a multiple of 4 */
261 req
->length
+= n_rects
* (SIZEOF(xRectangle
) / 4);
263 nbytes
= n_rects
* sizeof(xRectangle
);
265 Data16 (dpy
, (short *) rects
, nbytes
);
271 void XShapeCombineMask (
272 register Display
*dpy
,
279 XExtDisplayInfo
*info
= find_display (dpy
);
280 register xShapeMaskReq
*req
;
282 ShapeSimpleCheckExtension (dpy
, info
);
285 GetReq(ShapeMask
, req
);
286 req
->reqType
= info
->codes
->major_opcode
;
287 req
->shapeReqType
= X_ShapeMask
;
289 req
->destKind
= destKind
;
298 void XShapeCombineShape (
299 register Display
*dpy
,
307 XExtDisplayInfo
*info
= find_display (dpy
);
308 register xShapeCombineReq
*req
;
310 ShapeSimpleCheckExtension (dpy
, info
);
313 GetReq(ShapeCombine
, req
);
314 req
->reqType
= info
->codes
->major_opcode
;
315 req
->shapeReqType
= X_ShapeCombine
;
317 req
->destKind
= destKind
;
318 req
->srcKind
= srcKind
;
327 void XShapeOffsetShape (
328 register Display
*dpy
,
333 XExtDisplayInfo
*info
= find_display (dpy
);
334 register xShapeOffsetReq
*req
;
336 ShapeSimpleCheckExtension (dpy
, info
);
339 GetReq(ShapeOffset
, req
);
340 req
->reqType
= info
->codes
->major_opcode
;
341 req
->shapeReqType
= X_ShapeOffset
;
342 req
->destKind
= destKind
;
350 Status
XShapeQueryExtents (
351 register Display
*dpy
,
353 int *bShaped
, int *xbs
, int *ybs
, unsigned int *wbs
, unsigned int *hbs
, /* RETURN */
354 int *cShaped
, int *xcs
, int *ycs
, unsigned int *wcs
, unsigned int *hcs
/* RETURN */)
356 XExtDisplayInfo
*info
= find_display (dpy
);
357 xShapeQueryExtentsReply rep
;
358 register xShapeQueryExtentsReq
*req
;
360 ShapeCheckExtension (dpy
, info
, 0);
363 GetReq (ShapeQueryExtents
, req
);
364 req
->reqType
= info
->codes
->major_opcode
;
365 req
->shapeReqType
= X_ShapeQueryExtents
;
366 req
->window
= window
;
367 if (!_XReply (dpy
, (xReply
*) &rep
, 0, xTrue
)) {
372 *bShaped
= rep
.boundingShaped
;
373 *cShaped
= rep
.clipShaped
;
374 *xbs
= cvtINT16toInt (rep
.xBoundingShape
);
375 *ybs
= cvtINT16toInt (rep
.yBoundingShape
);
376 *wbs
= rep
.widthBoundingShape
;
377 *hbs
= rep
.heightBoundingShape
;
378 *xcs
= cvtINT16toInt (rep
.xClipShape
);
379 *ycs
= cvtINT16toInt (rep
.yClipShape
);
380 *wcs
= rep
.widthClipShape
;
381 *hcs
= rep
.heightClipShape
;
388 void XShapeSelectInput (
389 register Display
*dpy
,
393 XExtDisplayInfo
*info
= find_display (dpy
);
394 register xShapeSelectInputReq
*req
;
396 ShapeSimpleCheckExtension (dpy
, info
);
399 GetReq (ShapeSelectInput
, req
);
400 req
->reqType
= info
->codes
->major_opcode
;
401 req
->shapeReqType
= X_ShapeSelectInput
;
402 req
->window
= window
;
403 if (mask
& ShapeNotifyMask
)
406 req
->enable
= xFalse
;
411 unsigned long XShapeInputSelected (register Display
*dpy
, Window window
)
413 XExtDisplayInfo
*info
= find_display (dpy
);
414 register xShapeInputSelectedReq
*req
;
415 xShapeInputSelectedReply rep
;
417 ShapeCheckExtension (dpy
, info
, False
);
420 GetReq (ShapeInputSelected
, req
);
421 req
->reqType
= info
->codes
->major_opcode
;
422 req
->shapeReqType
= X_ShapeInputSelected
;
423 req
->window
= window
;
424 if (!_XReply (dpy
, (xReply
*) &rep
, 0, xFalse
)) {
431 return rep
.enabled
? ShapeNotifyMask
: 0L;
435 XRectangle
*XShapeGetRectangles (
436 register Display
*dpy
,
439 int *count
, /* RETURN */
440 int *ordering
/* RETURN */)
442 XExtDisplayInfo
*info
= find_display (dpy
);
443 register xShapeGetRectanglesReq
*req
;
444 xShapeGetRectanglesReply rep
;
449 ShapeCheckExtension (dpy
, info
, (XRectangle
*)NULL
);
452 GetReq (ShapeGetRectangles
, req
);
453 req
->reqType
= info
->codes
->major_opcode
;
454 req
->shapeReqType
= X_ShapeGetRectangles
;
455 req
->window
= window
;
457 if (!_XReply (dpy
, (xReply
*) &rep
, 0, xFalse
)) {
460 return (XRectangle
*)NULL
;
463 *ordering
= rep
.ordering
;
466 xrects
= (xRectangle
*) Xmalloc (*count
* sizeof (xRectangle
));
467 rects
= (XRectangle
*) Xmalloc (*count
* sizeof (XRectangle
));
468 if (!xrects
|| !rects
) {
473 _XEatData (dpy
, *count
* sizeof (xRectangle
));
477 _XRead (dpy
, (char *) xrects
, *count
* sizeof (xRectangle
));
478 for (i
= 0; i
< *count
; i
++) {
479 rects
[i
].x
= (short) cvtINT16toInt (xrects
[i
].x
);
480 rects
[i
].y
= (short) cvtINT16toInt (xrects
[i
].y
);
481 rects
[i
].width
= xrects
[i
].width
;
482 rects
[i
].height
= xrects
[i
].height
;