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.4 2002/10/16 02:19:22 dawes Exp $ */
31
#include <X11/Xlibint.h>
32
#include <X11/Xutil.h>
33
#include "region.h" /* in Xlib sources */
34
#include <X11/extensions/Xext.h>
35
#include <X11/extensions/extutil.h>
36
#include <X11/extensions/shapestr.h>
38
static XExtensionInfo _shape_info_data;
39
static XExtensionInfo *shape_info = &_shape_info_data;
40
static /* const */ char *shape_extension_name = SHAPENAME;
42
#define ShapeCheckExtension(dpy,i,val) \
43
XextCheckExtension (dpy, i, shape_extension_name, val)
44
#define ShapeSimpleCheckExtension(dpy,i) \
45
XextSimpleCheckExtension (dpy, i, shape_extension_name)
48
/*****************************************************************************
50
* private utility routines *
52
*****************************************************************************/
54
static int close_display(Display *dpy, XExtCodes *codes);
55
static Bool wire_to_event (Display *dpy, XEvent *re, xEvent *event);
56
static Status event_to_wire (Display *dpy, XEvent *re, xEvent *event);
57
static /* const */ XExtensionHooks shape_extension_hooks = {
62
NULL, /* create_font */
64
close_display, /* close_display */
65
wire_to_event, /* wire_to_event */
66
event_to_wire, /* event_to_wire */
68
NULL, /* error_string */
71
static XEXT_GENERATE_FIND_DISPLAY (find_display, shape_info,
73
&shape_extension_hooks,
74
ShapeNumberEvents, NULL)
76
static XEXT_GENERATE_CLOSE_DISPLAY (close_display, shape_info)
80
wire_to_event (Display *dpy, XEvent *re, xEvent *event)
82
XExtDisplayInfo *info = find_display (dpy);
84
xShapeNotifyEvent *sevent;
86
ShapeCheckExtension (dpy, info, False);
88
switch ((event->u.u.type & 0x7f) - info->codes->first_event) {
90
se = (XShapeEvent *) re;
91
sevent = (xShapeNotifyEvent *) event;
92
se->type = sevent->type & 0x7f;
93
se->serial = _XSetLastRequestRead(dpy,(xGenericReply *) event);
94
se->send_event = (sevent->type & 0x80) != 0;
96
se->window = sevent->window;
97
se->kind = sevent->kind;
98
se->x = cvtINT16toInt (sevent->x);
99
se->y = cvtINT16toInt (sevent->y);
100
se->width = sevent->width;
101
se->height = sevent->height;
102
se->time = sevent->time;
104
if (sevent->shaped == xFalse)
112
event_to_wire (Display *dpy, XEvent *re, xEvent *event)
114
XExtDisplayInfo *info = find_display (dpy);
116
xShapeNotifyEvent *sevent;
118
ShapeCheckExtension (dpy, info, 0);
120
switch ((re->type & 0x7f) - info->codes->first_event) {
122
se = (XShapeEvent *) re;
123
sevent = (xShapeNotifyEvent *) event;
124
sevent->type = se->type | (se->send_event ? 0x80 : 0);
125
sevent->sequenceNumber = se->serial & 0xffff;
126
sevent->window = se->window;
127
sevent->kind = se->kind;
130
sevent->width = se->width;
131
sevent->height = se->height;
132
sevent->time = se->time;
139
/****************************************************************************
141
* Shape public interfaces *
143
****************************************************************************/
145
Bool XShapeQueryExtension (dpy, event_basep, error_basep)
147
int *event_basep, *error_basep;
149
XExtDisplayInfo *info = find_display (dpy);
151
if (XextHasExtension(info)) {
152
*event_basep = info->codes->first_event;
153
*error_basep = info->codes->first_error;
161
Status XShapeQueryVersion(dpy, major_versionp, minor_versionp)
163
int *major_versionp, *minor_versionp;
165
XExtDisplayInfo *info = find_display (dpy);
166
xShapeQueryVersionReply rep;
167
register xShapeQueryVersionReq *req;
169
ShapeCheckExtension (dpy, info, 0);
172
GetReq (ShapeQueryVersion, req);
173
req->reqType = info->codes->major_opcode;
174
req->shapeReqType = X_ShapeQueryVersion;
175
if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
180
*major_versionp = rep.majorVersion;
181
*minor_versionp = rep.minorVersion;
187
void XShapeCombineRegion(dpy, dest, destKind, xOff, yOff, r, op)
188
register Display *dpy;
190
int destKind, op, xOff, yOff;
193
XExtDisplayInfo *info = find_display (dpy);
194
register xShapeRectanglesReq *req;
195
register long nbytes;
197
register XRectangle *xr, *pr;
200
ShapeSimpleCheckExtension (dpy, info);
203
GetReq(ShapeRectangles, req);
205
_XAllocScratch(dpy, (unsigned long)(r->numRects * sizeof (XRectangle)));
206
for (pr = xr, pb = r->rects, i = r->numRects; --i >= 0; pr++, pb++) {
209
pr->width = pb->x2 - pb->x1;
210
pr->height = pb->y2 - pb->y1;
212
req->reqType = info->codes->major_opcode;
213
req->shapeReqType = X_ShapeRectangles;
215
req->ordering = YXBanded;
216
req->destKind = destKind;
221
/* SIZEOF(xRectangle) will be a multiple of 4 */
222
req->length += r->numRects * (SIZEOF(xRectangle) / 4);
224
nbytes = r->numRects * sizeof(xRectangle);
226
Data16 (dpy, (short *) xr, nbytes);
232
void XShapeCombineRectangles (dpy, dest, destKind, xOff, yOff,
233
rects, n_rects, op, ordering)
234
register Display *dpy;
236
int destKind, op, xOff, yOff, ordering;
240
XExtDisplayInfo *info = find_display (dpy);
241
register xShapeRectanglesReq *req;
242
register long nbytes;
244
ShapeSimpleCheckExtension (dpy, info);
247
GetReq(ShapeRectangles, req);
248
req->reqType = info->codes->major_opcode;
249
req->shapeReqType = X_ShapeRectangles;
251
req->ordering = ordering;
252
req->destKind = destKind;
257
/* SIZEOF(xRectangle) will be a multiple of 4 */
258
req->length += n_rects * (SIZEOF(xRectangle) / 4);
260
nbytes = n_rects * sizeof(xRectangle);
262
Data16 (dpy, (short *) rects, nbytes);
268
void XShapeCombineMask (dpy, dest, destKind, xOff, yOff, src, op)
269
register Display *dpy;
275
XExtDisplayInfo *info = find_display (dpy);
276
register xShapeMaskReq *req;
278
ShapeSimpleCheckExtension (dpy, info);
281
GetReq(ShapeMask, req);
282
req->reqType = info->codes->major_opcode;
283
req->shapeReqType = X_ShapeMask;
285
req->destKind = destKind;
294
void XShapeCombineShape (dpy, dest, destKind, xOff, yOff, src, srcKind, op)
295
register Display *dpy;
302
XExtDisplayInfo *info = find_display (dpy);
303
register xShapeCombineReq *req;
305
ShapeSimpleCheckExtension (dpy, info);
308
GetReq(ShapeCombine, req);
309
req->reqType = info->codes->major_opcode;
310
req->shapeReqType = X_ShapeCombine;
312
req->destKind = destKind;
313
req->srcKind = srcKind;
322
void XShapeOffsetShape (dpy, dest, destKind, xOff, yOff)
323
register Display *dpy;
328
XExtDisplayInfo *info = find_display (dpy);
329
register xShapeOffsetReq *req;
331
ShapeSimpleCheckExtension (dpy, info);
334
GetReq(ShapeOffset, req);
335
req->reqType = info->codes->major_opcode;
336
req->shapeReqType = X_ShapeOffset;
337
req->destKind = destKind;
345
Status XShapeQueryExtents (dpy, window,
346
bShaped, xbs, ybs, wbs, hbs,
347
cShaped, xcs, ycs, wcs, hcs)
348
register Display *dpy;
350
int *bShaped, *cShaped; /* RETURN */
351
int *xbs, *ybs, *xcs, *ycs; /* RETURN */
352
unsigned int *wbs, *hbs, *wcs, *hcs; /* RETURN */
354
XExtDisplayInfo *info = find_display (dpy);
355
xShapeQueryExtentsReply rep;
356
register xShapeQueryExtentsReq *req;
358
ShapeCheckExtension (dpy, info, 0);
361
GetReq (ShapeQueryExtents, req);
362
req->reqType = info->codes->major_opcode;
363
req->shapeReqType = X_ShapeQueryExtents;
364
req->window = window;
365
if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
370
*bShaped = rep.boundingShaped;
371
*cShaped = rep.clipShaped;
372
*xbs = cvtINT16toInt (rep.xBoundingShape);
373
*ybs = cvtINT16toInt (rep.yBoundingShape);
374
*wbs = rep.widthBoundingShape;
375
*hbs = rep.heightBoundingShape;
376
*xcs = cvtINT16toInt (rep.xClipShape);
377
*ycs = cvtINT16toInt (rep.yClipShape);
378
*wcs = rep.widthClipShape;
379
*hcs = rep.heightClipShape;
386
void XShapeSelectInput (dpy, window, mask)
387
register Display *dpy;
391
XExtDisplayInfo *info = find_display (dpy);
392
register xShapeSelectInputReq *req;
394
ShapeSimpleCheckExtension (dpy, info);
397
GetReq (ShapeSelectInput, req);
398
req->reqType = info->codes->major_opcode;
399
req->shapeReqType = X_ShapeSelectInput;
400
req->window = window;
401
if (mask & ShapeNotifyMask)
404
req->enable = xFalse;
409
unsigned long XShapeInputSelected (dpy, window)
410
register Display *dpy;
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 (dpy, window, kind, count, ordering)
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;