| 1 |
/* |
| 2 |
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. |
| 3 |
* Copyright 2011 Red Hat, Inc. |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
* copy of this software and associated documentation files (the "Software"), |
| 7 |
* to deal in the Software without restriction, including without limitation |
| 8 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice (including the next |
| 13 |
* paragraph) shall be included in all copies or substantial portions of the |
| 14 |
* Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 |
* DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
/* |
| 25 |
* Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc. |
| 26 |
* |
| 27 |
* Permission to use, copy, modify, distribute, and sell this software and its |
| 28 |
* documentation for any purpose is hereby granted without fee, provided that |
| 29 |
* the above copyright notice appear in all copies and that both that |
| 30 |
* copyright notice and this permission notice appear in supporting |
| 31 |
* documentation, and that the name of Keith Packard not be used in |
| 32 |
* advertising or publicity pertaining to distribution of the software without |
| 33 |
* specific, written prior permission. Keith Packard makes no |
| 34 |
* representations about the suitability of this software for any purpose. It |
| 35 |
* is provided "as is" without express or implied warranty. |
| 36 |
* |
| 37 |
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 38 |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 39 |
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 40 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 41 |
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 42 |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 43 |
* PERFORMANCE OF THIS SOFTWARE. |
| 44 |
*/ |
| 45 |
|
| 46 |
#ifdef HAVE_CONFIG_H |
| 47 |
#include <config.h> |
| 48 |
#endif |
| 49 |
#include "Xfixesint.h" |
| 50 |
#include <limits.h> |
| 51 |
|
| 52 |
void |
| 53 |
XFixesSelectCursorInput (Display *dpy, |
| 54 |
Window win, |
| 55 |
unsigned long eventMask) |
| 56 |
{ |
| 57 |
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy); |
| 58 |
xXFixesSelectCursorInputReq *req; |
| 59 |
|
| 60 |
XFixesSimpleCheckExtension (dpy, info); |
| 61 |
|
| 62 |
LockDisplay (dpy); |
| 63 |
GetReq (XFixesSelectCursorInput, req); |
| 64 |
req->reqType = info->codes->major_opcode; |
| 65 |
req->xfixesReqType = X_XFixesSelectCursorInput; |
| 66 |
req->window = win; |
| 67 |
req->eventMask = eventMask; |
| 68 |
UnlockDisplay (dpy); |
| 69 |
SyncHandle (); |
| 70 |
} |
| 71 |
|
| 72 |
XFixesCursorImage * |
| 73 |
XFixesGetCursorImage (Display *dpy) |
| 74 |
{ |
| 75 |
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy); |
| 76 |
xXFixesGetCursorImageAndNameReq *req; |
| 77 |
xXFixesGetCursorImageAndNameReply rep; |
| 78 |
size_t npixels; |
| 79 |
size_t nbytes_name; |
| 80 |
size_t nbytes, nread, rlength; |
| 81 |
XFixesCursorImage *image; |
| 82 |
char *name; |
| 83 |
|
| 84 |
XFixesCheckExtension (dpy, info, NULL); |
| 85 |
LockDisplay (dpy); |
| 86 |
GetReq (XFixesGetCursorImageAndName, req); |
| 87 |
req->reqType = info->codes->major_opcode; |
| 88 |
if (info->major_version >= 2) |
| 89 |
req->xfixesReqType = X_XFixesGetCursorImageAndName; |
| 90 |
else |
| 91 |
req->xfixesReqType = X_XFixesGetCursorImage; |
| 92 |
if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) |
| 93 |
{ |
| 94 |
UnlockDisplay (dpy); |
| 95 |
SyncHandle (); |
| 96 |
return NULL; |
| 97 |
} |
| 98 |
if (info->major_version < 2) |
| 99 |
{ |
| 100 |
rep.cursorName = None; |
| 101 |
rep.nbytes = 0; |
| 102 |
} |
| 103 |
npixels = rep.width * rep.height; |
| 104 |
nbytes_name = rep.nbytes; |
| 105 |
if ((rep.length < (INT_MAX >> 2)) && |
| 106 |
npixels < (((INT_MAX >> 3) - sizeof (XFixesCursorImage) - 1) |
| 107 |
- nbytes_name)) { |
| 108 |
/* reply data length */ |
| 109 |
nbytes = (size_t) rep.length << 2; |
| 110 |
/* bytes of actual data in the reply */ |
| 111 |
nread = (npixels << 2) + nbytes_name; |
| 112 |
/* size of data returned to application */ |
| 113 |
rlength = (sizeof (XFixesCursorImage) + |
| 114 |
npixels * sizeof (unsigned long) + |
| 115 |
nbytes_name + 1); |
| 116 |
|
| 117 |
image = Xmalloc (rlength); |
| 118 |
} else |
| 119 |
image = NULL; |
| 120 |
if (!image) |
| 121 |
{ |
| 122 |
_XEatDataWords(dpy, rep.length); |
| 123 |
UnlockDisplay (dpy); |
| 124 |
SyncHandle (); |
| 125 |
return NULL; |
| 126 |
} |
| 127 |
image->x = rep.x; |
| 128 |
image->y = rep.y; |
| 129 |
image->width = rep.width; |
| 130 |
image->height = rep.height; |
| 131 |
image->xhot = rep.xhot; |
| 132 |
image->yhot = rep.yhot; |
| 133 |
image->cursor_serial = rep.cursorSerial; |
| 134 |
image->pixels = (unsigned long *) (image + 1); |
| 135 |
image->atom = rep.cursorName; |
| 136 |
name = (char *) (image->pixels + npixels); |
| 137 |
image->name = name; |
| 138 |
_XRead32 (dpy, (long *) image->pixels, npixels << 2); |
| 139 |
_XRead (dpy, name, nbytes_name); |
| 140 |
name[nbytes_name] = '\0'; /* null-terminate */ |
| 141 |
/* skip any padding */ |
| 142 |
if(nbytes > nread) |
| 143 |
{ |
| 144 |
_XEatData (dpy, (unsigned long) (nbytes - nread)); |
| 145 |
} |
| 146 |
UnlockDisplay (dpy); |
| 147 |
SyncHandle (); |
| 148 |
return image; |
| 149 |
} |
| 150 |
|
| 151 |
void |
| 152 |
XFixesSetCursorName (Display *dpy, Cursor cursor, const char *name) |
| 153 |
{ |
| 154 |
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy); |
| 155 |
xXFixesSetCursorNameReq *req; |
| 156 |
int nbytes = strlen (name); |
| 157 |
|
| 158 |
XFixesSimpleCheckExtension (dpy, info); |
| 159 |
if (info->major_version < 2) |
| 160 |
return; |
| 161 |
LockDisplay (dpy); |
| 162 |
GetReq (XFixesSetCursorName, req); |
| 163 |
req->reqType = info->codes->major_opcode; |
| 164 |
req->xfixesReqType = X_XFixesSetCursorName; |
| 165 |
req->cursor = cursor; |
| 166 |
req->nbytes = nbytes; |
| 167 |
req->length += (nbytes + 3) >> 2; |
| 168 |
Data (dpy, name, nbytes); |
| 169 |
UnlockDisplay (dpy); |
| 170 |
SyncHandle (); |
| 171 |
} |
| 172 |
|
| 173 |
const char * |
| 174 |
XFixesGetCursorName (Display *dpy, Cursor cursor, Atom *atom) |
| 175 |
{ |
| 176 |
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy); |
| 177 |
xXFixesGetCursorNameReq *req; |
| 178 |
xXFixesGetCursorNameReply rep; |
| 179 |
char *name; |
| 180 |
|
| 181 |
XFixesCheckExtension (dpy, info, NULL); |
| 182 |
if (info->major_version < 2) |
| 183 |
return NULL; |
| 184 |
LockDisplay (dpy); |
| 185 |
GetReq (XFixesGetCursorName, req); |
| 186 |
req->reqType = info->codes->major_opcode; |
| 187 |
req->xfixesReqType = X_XFixesGetCursorName; |
| 188 |
req->cursor = cursor; |
| 189 |
if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) |
| 190 |
{ |
| 191 |
UnlockDisplay (dpy); |
| 192 |
SyncHandle (); |
| 193 |
return NULL; |
| 194 |
} |
| 195 |
*atom = rep.atom; |
| 196 |
if ((name = (char *) Xmalloc(rep.nbytes+1))) { |
| 197 |
_XReadPad(dpy, name, (long)rep.nbytes); |
| 198 |
name[rep.nbytes] = '\0'; |
| 199 |
} else { |
| 200 |
_XEatDataWords(dpy, rep.length); |
| 201 |
name = (char *) NULL; |
| 202 |
} |
| 203 |
UnlockDisplay(dpy); |
| 204 |
SyncHandle(); |
| 205 |
return(name); |
| 206 |
} |
| 207 |
|
| 208 |
void |
| 209 |
XFixesChangeCursor (Display *dpy, Cursor source, Cursor destination) |
| 210 |
{ |
| 211 |
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy); |
| 212 |
xXFixesChangeCursorReq *req; |
| 213 |
|
| 214 |
XFixesSimpleCheckExtension (dpy, info); |
| 215 |
if (info->major_version < 2) |
| 216 |
return; |
| 217 |
LockDisplay (dpy); |
| 218 |
GetReq (XFixesChangeCursor, req); |
| 219 |
req->reqType = info->codes->major_opcode; |
| 220 |
req->xfixesReqType = X_XFixesChangeCursor; |
| 221 |
req->source = source; |
| 222 |
req->destination = destination; |
| 223 |
UnlockDisplay(dpy); |
| 224 |
SyncHandle(); |
| 225 |
} |
| 226 |
|
| 227 |
void |
| 228 |
XFixesChangeCursorByName (Display *dpy, Cursor source, const char *name) |
| 229 |
{ |
| 230 |
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy); |
| 231 |
xXFixesChangeCursorByNameReq *req; |
| 232 |
int nbytes = strlen (name); |
| 233 |
|
| 234 |
XFixesSimpleCheckExtension (dpy, info); |
| 235 |
if (info->major_version < 2) |
| 236 |
return; |
| 237 |
LockDisplay (dpy); |
| 238 |
GetReq (XFixesChangeCursorByName, req); |
| 239 |
req->reqType = info->codes->major_opcode; |
| 240 |
req->xfixesReqType = X_XFixesChangeCursorByName; |
| 241 |
req->source = source; |
| 242 |
req->nbytes = nbytes; |
| 243 |
req->length += (nbytes + 3) >> 2; |
| 244 |
Data (dpy, name, nbytes); |
| 245 |
UnlockDisplay(dpy); |
| 246 |
SyncHandle(); |
| 247 |
} |
| 248 |
|
| 249 |
void |
| 250 |
XFixesHideCursor (Display *dpy, Window win) |
| 251 |
{ |
| 252 |
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy); |
| 253 |
xXFixesHideCursorReq *req; |
| 254 |
|
| 255 |
XFixesSimpleCheckExtension (dpy, info); |
| 256 |
if (info->major_version < 4) |
| 257 |
return; |
| 258 |
LockDisplay (dpy); |
| 259 |
GetReq (XFixesHideCursor, req); |
| 260 |
req->reqType = info->codes->major_opcode; |
| 261 |
req->xfixesReqType = X_XFixesHideCursor; |
| 262 |
req->window = win; |
| 263 |
UnlockDisplay (dpy); |
| 264 |
SyncHandle (); |
| 265 |
} |
| 266 |
|
| 267 |
void |
| 268 |
XFixesShowCursor (Display *dpy, Window win) |
| 269 |
{ |
| 270 |
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy); |
| 271 |
xXFixesShowCursorReq *req; |
| 272 |
|
| 273 |
XFixesSimpleCheckExtension (dpy, info); |
| 274 |
if (info->major_version < 4) |
| 275 |
return; |
| 276 |
LockDisplay (dpy); |
| 277 |
GetReq (XFixesShowCursor, req); |
| 278 |
req->reqType = info->codes->major_opcode; |
| 279 |
req->xfixesReqType = X_XFixesShowCursor; |
| 280 |
req->window = win; |
| 281 |
UnlockDisplay (dpy); |
| 282 |
SyncHandle (); |
| 283 |
} |
| 284 |
|
| 285 |
PointerBarrier |
| 286 |
XFixesCreatePointerBarrier(Display *dpy, Window w, int x1, int y1, |
| 287 |
int x2, int y2, int directions, |
| 288 |
int num_devices, int *devices) |
| 289 |
{ |
| 290 |
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy); |
| 291 |
xXFixesCreatePointerBarrierReq *req; |
| 292 |
PointerBarrier barrier; |
| 293 |
int extra = 0; |
| 294 |
|
| 295 |
XFixesCheckExtension (dpy, info, 0); |
| 296 |
if (info->major_version < 5) |
| 297 |
return 0; |
| 298 |
|
| 299 |
if (num_devices) |
| 300 |
extra = (((2 * num_devices) + 3) / 4) * 4; |
| 301 |
|
| 302 |
LockDisplay (dpy); |
| 303 |
GetReqExtra (XFixesCreatePointerBarrier, extra, req); |
| 304 |
req->reqType = info->codes->major_opcode; |
| 305 |
req->xfixesReqType = X_XFixesCreatePointerBarrier; |
| 306 |
barrier = req->barrier = XAllocID (dpy); |
| 307 |
req->window = w; |
| 308 |
req->x1 = x1; |
| 309 |
req->y1 = y1; |
| 310 |
req->x2 = x2; |
| 311 |
req->y2 = y2; |
| 312 |
req->directions = directions; |
| 313 |
if ((req->num_devices = num_devices)) { |
| 314 |
int i; |
| 315 |
CARD16 *devs = (CARD16 *)(req + 1); |
| 316 |
for (i = 0; i < num_devices; i++) |
| 317 |
devs[i] = (CARD16)(devices[i]); |
| 318 |
} |
| 319 |
|
| 320 |
UnlockDisplay (dpy); |
| 321 |
SyncHandle(); |
| 322 |
return barrier; |
| 323 |
} |
| 324 |
|
| 325 |
void |
| 326 |
XFixesDestroyPointerBarrier(Display *dpy, PointerBarrier b) |
| 327 |
{ |
| 328 |
XFixesExtDisplayInfo *info = XFixesFindDisplay (dpy); |
| 329 |
xXFixesDestroyPointerBarrierReq *req; |
| 330 |
|
| 331 |
XFixesSimpleCheckExtension (dpy, info); |
| 332 |
if (info->major_version < 5) |
| 333 |
return; |
| 334 |
|
| 335 |
LockDisplay (dpy); |
| 336 |
GetReq (XFixesDestroyPointerBarrier, req); |
| 337 |
req->reqType = info->codes->major_opcode; |
| 338 |
req->xfixesReqType = X_XFixesDestroyPointerBarrier; |
| 339 |
req->barrier = b; |
| 340 |
UnlockDisplay (dpy); |
| 341 |
SyncHandle(); |
| 342 |
} |