xiproperty.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  1. /*
  2. * Copyright © 2006 Keith Packard
  3. * Copyright © 2008 Peter Hutterer
  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 WAXIANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WAXIANTIES 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. /* This code is a modified version of randr/rrproperty.c */
  26. #ifdef HAVE_DIX_CONFIG_H
  27. #include <dix-config.h>
  28. #endif
  29. #include "dix.h"
  30. #include "inputstr.h"
  31. #include <X11/extensions/XI.h>
  32. #include <X11/Xatom.h>
  33. #include <X11/extensions/XIproto.h>
  34. #include <X11/extensions/XI2proto.h>
  35. #include "exglobals.h"
  36. #include "exevents.h"
  37. #include "swaprep.h"
  38. #include "xiproperty.h"
  39. #include "xserver-properties.h"
  40. /**
  41. * Properties used or alloced from inside the server.
  42. */
  43. static struct dev_properties {
  44. Atom type;
  45. const char *name;
  46. } dev_properties[] = {
  47. {0, XI_PROP_ENABLED},
  48. {0, XI_PROP_XTEST_DEVICE},
  49. {0, XATOM_FLOAT},
  50. {0, ACCEL_PROP_PROFILE_NUMBER},
  51. {0, ACCEL_PROP_CONSTANT_DECELERATION},
  52. {0, ACCEL_PROP_ADAPTIVE_DECELERATION},
  53. {0, ACCEL_PROP_VELOCITY_SCALING},
  54. {0, AXIS_LABEL_PROP},
  55. {0, AXIS_LABEL_PROP_REL_X},
  56. {0, AXIS_LABEL_PROP_REL_Y},
  57. {0, AXIS_LABEL_PROP_REL_Z},
  58. {0, AXIS_LABEL_PROP_REL_RX},
  59. {0, AXIS_LABEL_PROP_REL_RY},
  60. {0, AXIS_LABEL_PROP_REL_RZ},
  61. {0, AXIS_LABEL_PROP_REL_HWHEEL},
  62. {0, AXIS_LABEL_PROP_REL_DIAL},
  63. {0, AXIS_LABEL_PROP_REL_WHEEL},
  64. {0, AXIS_LABEL_PROP_REL_MISC},
  65. {0, AXIS_LABEL_PROP_REL_VSCROLL},
  66. {0, AXIS_LABEL_PROP_REL_HSCROLL},
  67. {0, AXIS_LABEL_PROP_ABS_X},
  68. {0, AXIS_LABEL_PROP_ABS_Y},
  69. {0, AXIS_LABEL_PROP_ABS_Z},
  70. {0, AXIS_LABEL_PROP_ABS_RX},
  71. {0, AXIS_LABEL_PROP_ABS_RY},
  72. {0, AXIS_LABEL_PROP_ABS_RZ},
  73. {0, AXIS_LABEL_PROP_ABS_THROTTLE},
  74. {0, AXIS_LABEL_PROP_ABS_RUDDER},
  75. {0, AXIS_LABEL_PROP_ABS_WHEEL},
  76. {0, AXIS_LABEL_PROP_ABS_GAS},
  77. {0, AXIS_LABEL_PROP_ABS_BRAKE},
  78. {0, AXIS_LABEL_PROP_ABS_HAT0X},
  79. {0, AXIS_LABEL_PROP_ABS_HAT0Y},
  80. {0, AXIS_LABEL_PROP_ABS_HAT1X},
  81. {0, AXIS_LABEL_PROP_ABS_HAT1Y},
  82. {0, AXIS_LABEL_PROP_ABS_HAT2X},
  83. {0, AXIS_LABEL_PROP_ABS_HAT2Y},
  84. {0, AXIS_LABEL_PROP_ABS_HAT3X},
  85. {0, AXIS_LABEL_PROP_ABS_HAT3Y},
  86. {0, AXIS_LABEL_PROP_ABS_PRESSURE},
  87. {0, AXIS_LABEL_PROP_ABS_DISTANCE},
  88. {0, AXIS_LABEL_PROP_ABS_TILT_X},
  89. {0, AXIS_LABEL_PROP_ABS_TILT_Y},
  90. {0, AXIS_LABEL_PROP_ABS_TOOL_WIDTH},
  91. {0, AXIS_LABEL_PROP_ABS_VOLUME},
  92. {0, AXIS_LABEL_PROP_ABS_MT_TOUCH_MAJOR},
  93. {0, AXIS_LABEL_PROP_ABS_MT_TOUCH_MINOR},
  94. {0, AXIS_LABEL_PROP_ABS_MT_WIDTH_MAJOR},
  95. {0, AXIS_LABEL_PROP_ABS_MT_WIDTH_MINOR},
  96. {0, AXIS_LABEL_PROP_ABS_MT_ORIENTATION},
  97. {0, AXIS_LABEL_PROP_ABS_MT_POSITION_X},
  98. {0, AXIS_LABEL_PROP_ABS_MT_POSITION_Y},
  99. {0, AXIS_LABEL_PROP_ABS_MT_TOOL_TYPE},
  100. {0, AXIS_LABEL_PROP_ABS_MT_BLOB_ID},
  101. {0, AXIS_LABEL_PROP_ABS_MT_TRACKING_ID},
  102. {0, AXIS_LABEL_PROP_ABS_MT_PRESSURE},
  103. {0, AXIS_LABEL_PROP_ABS_MT_DISTANCE},
  104. {0, AXIS_LABEL_PROP_ABS_MT_TOOL_X},
  105. {0, AXIS_LABEL_PROP_ABS_MT_TOOL_Y},
  106. {0, AXIS_LABEL_PROP_ABS_MISC},
  107. {0, BTN_LABEL_PROP},
  108. {0, BTN_LABEL_PROP_BTN_UNKNOWN},
  109. {0, BTN_LABEL_PROP_BTN_WHEEL_UP},
  110. {0, BTN_LABEL_PROP_BTN_WHEEL_DOWN},
  111. {0, BTN_LABEL_PROP_BTN_HWHEEL_LEFT},
  112. {0, BTN_LABEL_PROP_BTN_HWHEEL_RIGHT},
  113. {0, BTN_LABEL_PROP_BTN_0},
  114. {0, BTN_LABEL_PROP_BTN_1},
  115. {0, BTN_LABEL_PROP_BTN_2},
  116. {0, BTN_LABEL_PROP_BTN_3},
  117. {0, BTN_LABEL_PROP_BTN_4},
  118. {0, BTN_LABEL_PROP_BTN_5},
  119. {0, BTN_LABEL_PROP_BTN_6},
  120. {0, BTN_LABEL_PROP_BTN_7},
  121. {0, BTN_LABEL_PROP_BTN_8},
  122. {0, BTN_LABEL_PROP_BTN_9},
  123. {0, BTN_LABEL_PROP_BTN_LEFT},
  124. {0, BTN_LABEL_PROP_BTN_RIGHT},
  125. {0, BTN_LABEL_PROP_BTN_MIDDLE},
  126. {0, BTN_LABEL_PROP_BTN_SIDE},
  127. {0, BTN_LABEL_PROP_BTN_EXTRA},
  128. {0, BTN_LABEL_PROP_BTN_FORWARD},
  129. {0, BTN_LABEL_PROP_BTN_BACK},
  130. {0, BTN_LABEL_PROP_BTN_TASK},
  131. {0, BTN_LABEL_PROP_BTN_TRIGGER},
  132. {0, BTN_LABEL_PROP_BTN_THUMB},
  133. {0, BTN_LABEL_PROP_BTN_THUMB2},
  134. {0, BTN_LABEL_PROP_BTN_TOP},
  135. {0, BTN_LABEL_PROP_BTN_TOP2},
  136. {0, BTN_LABEL_PROP_BTN_PINKIE},
  137. {0, BTN_LABEL_PROP_BTN_BASE},
  138. {0, BTN_LABEL_PROP_BTN_BASE2},
  139. {0, BTN_LABEL_PROP_BTN_BASE3},
  140. {0, BTN_LABEL_PROP_BTN_BASE4},
  141. {0, BTN_LABEL_PROP_BTN_BASE5},
  142. {0, BTN_LABEL_PROP_BTN_BASE6},
  143. {0, BTN_LABEL_PROP_BTN_DEAD},
  144. {0, BTN_LABEL_PROP_BTN_A},
  145. {0, BTN_LABEL_PROP_BTN_B},
  146. {0, BTN_LABEL_PROP_BTN_C},
  147. {0, BTN_LABEL_PROP_BTN_X},
  148. {0, BTN_LABEL_PROP_BTN_Y},
  149. {0, BTN_LABEL_PROP_BTN_Z},
  150. {0, BTN_LABEL_PROP_BTN_TL},
  151. {0, BTN_LABEL_PROP_BTN_TR},
  152. {0, BTN_LABEL_PROP_BTN_TL2},
  153. {0, BTN_LABEL_PROP_BTN_TR2},
  154. {0, BTN_LABEL_PROP_BTN_SELECT},
  155. {0, BTN_LABEL_PROP_BTN_START},
  156. {0, BTN_LABEL_PROP_BTN_MODE},
  157. {0, BTN_LABEL_PROP_BTN_THUMBL},
  158. {0, BTN_LABEL_PROP_BTN_THUMBR},
  159. {0, BTN_LABEL_PROP_BTN_TOOL_PEN},
  160. {0, BTN_LABEL_PROP_BTN_TOOL_RUBBER},
  161. {0, BTN_LABEL_PROP_BTN_TOOL_BRUSH},
  162. {0, BTN_LABEL_PROP_BTN_TOOL_PENCIL},
  163. {0, BTN_LABEL_PROP_BTN_TOOL_AIRBRUSH},
  164. {0, BTN_LABEL_PROP_BTN_TOOL_FINGER},
  165. {0, BTN_LABEL_PROP_BTN_TOOL_MOUSE},
  166. {0, BTN_LABEL_PROP_BTN_TOOL_LENS},
  167. {0, BTN_LABEL_PROP_BTN_TOUCH},
  168. {0, BTN_LABEL_PROP_BTN_STYLUS},
  169. {0, BTN_LABEL_PROP_BTN_STYLUS2},
  170. {0, BTN_LABEL_PROP_BTN_TOOL_DOUBLETAP},
  171. {0, BTN_LABEL_PROP_BTN_TOOL_TRIPLETAP},
  172. {0, BTN_LABEL_PROP_BTN_GEAR_DOWN},
  173. {0, BTN_LABEL_PROP_BTN_GEAR_UP},
  174. {0, XI_PROP_TRANSFORM}
  175. };
  176. static long XIPropHandlerID = 1;
  177. static void
  178. send_property_event(DeviceIntPtr dev, Atom property, int what)
  179. {
  180. int state = (what == XIPropertyDeleted) ? PropertyDelete : PropertyNewValue;
  181. devicePropertyNotify event = {
  182. .type = DevicePropertyNotify,
  183. .deviceid = dev->id,
  184. .state = state,
  185. .atom = property,
  186. .time = currentTime.milliseconds
  187. };
  188. xXIPropertyEvent xi2 = {
  189. .type = GenericEvent,
  190. .extension = IReqCode,
  191. .length = 0,
  192. .evtype = XI_PropertyEvent,
  193. .deviceid = dev->id,
  194. .time = currentTime.milliseconds,
  195. .property = property,
  196. .what = what
  197. };
  198. SendEventToAllWindows(dev, DevicePropertyNotifyMask, (xEvent *) &event, 1);
  199. SendEventToAllWindows(dev, GetEventFilter(dev, (xEvent *) &xi2),
  200. (xEvent *) &xi2, 1);
  201. }
  202. static int
  203. list_atoms(DeviceIntPtr dev, int *natoms, Atom **atoms_return)
  204. {
  205. XIPropertyPtr prop;
  206. Atom *atoms = NULL;
  207. int nprops = 0;
  208. for (prop = dev->properties.properties; prop; prop = prop->next)
  209. nprops++;
  210. if (nprops) {
  211. Atom *a;
  212. atoms = malloc(nprops * sizeof(Atom));
  213. if (!atoms)
  214. return BadAlloc;
  215. a = atoms;
  216. for (prop = dev->properties.properties; prop; prop = prop->next, a++)
  217. *a = prop->propertyName;
  218. }
  219. *natoms = nprops;
  220. *atoms_return = atoms;
  221. return Success;
  222. }
  223. static int
  224. get_property(ClientPtr client, DeviceIntPtr dev, Atom property, Atom type,
  225. BOOL delete, int offset, int length,
  226. int *bytes_after, Atom *type_return, int *format, int *nitems,
  227. int *length_return, char **data)
  228. {
  229. unsigned long n, len, ind;
  230. int rc;
  231. XIPropertyPtr prop;
  232. XIPropertyValuePtr prop_value;
  233. if (!ValidAtom(property)) {
  234. client->errorValue = property;
  235. return BadAtom;
  236. }
  237. if ((delete != xTrue) && (delete != xFalse)) {
  238. client->errorValue = delete;
  239. return BadValue;
  240. }
  241. if ((type != AnyPropertyType) && !ValidAtom(type)) {
  242. client->errorValue = type;
  243. return BadAtom;
  244. }
  245. for (prop = dev->properties.properties; prop; prop = prop->next)
  246. if (prop->propertyName == property)
  247. break;
  248. if (!prop) {
  249. *bytes_after = 0;
  250. *type_return = None;
  251. *format = 0;
  252. *nitems = 0;
  253. *length_return = 0;
  254. return Success;
  255. }
  256. rc = XIGetDeviceProperty(dev, property, &prop_value);
  257. if (rc != Success) {
  258. client->errorValue = property;
  259. return rc;
  260. }
  261. /* If the request type and actual type don't match. Return the
  262. property information, but not the data. */
  263. if (((type != prop_value->type) && (type != AnyPropertyType))) {
  264. *bytes_after = prop_value->size;
  265. *format = prop_value->format;
  266. *length_return = 0;
  267. *nitems = 0;
  268. *type_return = prop_value->type;
  269. return Success;
  270. }
  271. /* Return type, format, value to client */
  272. n = (prop_value->format / 8) * prop_value->size; /* size (bytes) of prop */
  273. ind = offset << 2;
  274. /* If offset is invalid such that it causes "len" to
  275. be negative, it's a value error. */
  276. if (n < ind) {
  277. client->errorValue = offset;
  278. return BadValue;
  279. }
  280. len = min(n - ind, 4 * length);
  281. *bytes_after = n - (ind + len);
  282. *format = prop_value->format;
  283. *length_return = len;
  284. if (prop_value->format)
  285. *nitems = len / (prop_value->format / 8);
  286. else
  287. *nitems = 0;
  288. *type_return = prop_value->type;
  289. *data = (char *) prop_value->data + ind;
  290. return Success;
  291. }
  292. static int
  293. check_change_property(ClientPtr client, Atom property, Atom type, int format,
  294. int mode, int nitems)
  295. {
  296. if ((mode != PropModeReplace) && (mode != PropModeAppend) &&
  297. (mode != PropModePrepend)) {
  298. client->errorValue = mode;
  299. return BadValue;
  300. }
  301. if ((format != 8) && (format != 16) && (format != 32)) {
  302. client->errorValue = format;
  303. return BadValue;
  304. }
  305. if (!ValidAtom(property)) {
  306. client->errorValue = property;
  307. return BadAtom;
  308. }
  309. if (!ValidAtom(type)) {
  310. client->errorValue = type;
  311. return BadAtom;
  312. }
  313. return Success;
  314. }
  315. static int
  316. change_property(ClientPtr client, DeviceIntPtr dev, Atom property, Atom type,
  317. int format, int mode, int len, void *data)
  318. {
  319. int rc = Success;
  320. rc = XIChangeDeviceProperty(dev, property, type, format, mode, len, data,
  321. TRUE);
  322. if (rc != Success)
  323. client->errorValue = property;
  324. return rc;
  325. }
  326. /**
  327. * Return the atom assigned to the specified string or 0 if the atom isn't known
  328. * to the DIX.
  329. *
  330. * If name is NULL, None is returned.
  331. */
  332. Atom
  333. XIGetKnownProperty(const char *name)
  334. {
  335. int i;
  336. if (!name)
  337. return None;
  338. for (i = 0; i < (sizeof(dev_properties) / sizeof(struct dev_properties));
  339. i++) {
  340. if (strcmp(name, dev_properties[i].name) == 0) {
  341. if (dev_properties[i].type == None) {
  342. dev_properties[i].type =
  343. MakeAtom(dev_properties[i].name,
  344. strlen(dev_properties[i].name), TRUE);
  345. }
  346. return dev_properties[i].type;
  347. }
  348. }
  349. return 0;
  350. }
  351. void
  352. XIResetProperties(void)
  353. {
  354. int i;
  355. for (i = 0; i < (sizeof(dev_properties) / sizeof(struct dev_properties));
  356. i++)
  357. dev_properties[i].type = None;
  358. }
  359. /**
  360. * Convert the given property's value(s) into @nelem_return integer values and
  361. * store them in @buf_return. If @nelem_return is larger than the number of
  362. * values in the property, @nelem_return is set to the number of values in the
  363. * property.
  364. *
  365. * If *@buf_return is NULL and @nelem_return is 0, memory is allocated
  366. * automatically and must be freed by the caller.
  367. *
  368. * Possible return codes.
  369. * Success ... No error.
  370. * BadMatch ... Wrong atom type, atom is not XA_INTEGER
  371. * BadAlloc ... NULL passed as buffer and allocation failed.
  372. * BadLength ... @buff is NULL but @nelem_return is non-zero.
  373. *
  374. * @param val The property value
  375. * @param nelem_return The maximum number of elements to return.
  376. * @param buf_return Pointer to an array of at least @nelem_return values.
  377. * @return Success or the error code if an error occured.
  378. */
  379. _X_EXPORT int
  380. XIPropToInt(XIPropertyValuePtr val, int *nelem_return, int **buf_return)
  381. {
  382. int i;
  383. int *buf;
  384. if (val->type != XA_INTEGER)
  385. return BadMatch;
  386. if (!*buf_return && *nelem_return)
  387. return BadLength;
  388. switch (val->format) {
  389. case 8:
  390. case 16:
  391. case 32:
  392. break;
  393. default:
  394. return BadValue;
  395. }
  396. buf = *buf_return;
  397. if (!buf && !(*nelem_return)) {
  398. buf = calloc(val->size, sizeof(int));
  399. if (!buf)
  400. return BadAlloc;
  401. *buf_return = buf;
  402. *nelem_return = val->size;
  403. }
  404. else if (val->size < *nelem_return)
  405. *nelem_return = val->size;
  406. for (i = 0; i < val->size && i < *nelem_return; i++) {
  407. switch (val->format) {
  408. case 8:
  409. buf[i] = ((CARD8 *) val->data)[i];
  410. break;
  411. case 16:
  412. buf[i] = ((CARD16 *) val->data)[i];
  413. break;
  414. case 32:
  415. buf[i] = ((CARD32 *) val->data)[i];
  416. break;
  417. }
  418. }
  419. return Success;
  420. }
  421. /**
  422. * Convert the given property's value(s) into @nelem_return float values and
  423. * store them in @buf_return. If @nelem_return is larger than the number of
  424. * values in the property, @nelem_return is set to the number of values in the
  425. * property.
  426. *
  427. * If *@buf_return is NULL and @nelem_return is 0, memory is allocated
  428. * automatically and must be freed by the caller.
  429. *
  430. * Possible errors returned:
  431. * Success
  432. * BadMatch ... Wrong atom type, atom is not XA_FLOAT
  433. * BadValue ... Wrong format, format is not 32
  434. * BadAlloc ... NULL passed as buffer and allocation failed.
  435. * BadLength ... @buff is NULL but @nelem_return is non-zero.
  436. *
  437. * @param val The property value
  438. * @param nelem_return The maximum number of elements to return.
  439. * @param buf_return Pointer to an array of at least @nelem_return values.
  440. * @return Success or the error code if an error occured.
  441. */
  442. _X_EXPORT int
  443. XIPropToFloat(XIPropertyValuePtr val, int *nelem_return, float **buf_return)
  444. {
  445. int i;
  446. float *buf;
  447. if (!val->type || val->type != XIGetKnownProperty(XATOM_FLOAT))
  448. return BadMatch;
  449. if (val->format != 32)
  450. return BadValue;
  451. if (!*buf_return && *nelem_return)
  452. return BadLength;
  453. buf = *buf_return;
  454. if (!buf && !(*nelem_return)) {
  455. buf = calloc(val->size, sizeof(float));
  456. if (!buf)
  457. return BadAlloc;
  458. *buf_return = buf;
  459. *nelem_return = val->size;
  460. }
  461. else if (val->size < *nelem_return)
  462. *nelem_return = val->size;
  463. for (i = 0; i < val->size && i < *nelem_return; i++)
  464. buf[i] = ((float *) val->data)[i];
  465. return Success;
  466. }
  467. /* Registers a new property handler on the given device and returns a unique
  468. * identifier for this handler. This identifier is required to unregister the
  469. * property handler again.
  470. * @return The handler's identifier or 0 if an error occured.
  471. */
  472. long
  473. XIRegisterPropertyHandler(DeviceIntPtr dev,
  474. int (*SetProperty) (DeviceIntPtr dev,
  475. Atom property,
  476. XIPropertyValuePtr prop,
  477. BOOL checkonly),
  478. int (*GetProperty) (DeviceIntPtr dev,
  479. Atom property),
  480. int (*DeleteProperty) (DeviceIntPtr dev,
  481. Atom property))
  482. {
  483. XIPropertyHandlerPtr new_handler;
  484. new_handler = calloc(1, sizeof(XIPropertyHandler));
  485. if (!new_handler)
  486. return 0;
  487. new_handler->id = XIPropHandlerID++;
  488. new_handler->SetProperty = SetProperty;
  489. new_handler->GetProperty = GetProperty;
  490. new_handler->DeleteProperty = DeleteProperty;
  491. new_handler->next = dev->properties.handlers;
  492. dev->properties.handlers = new_handler;
  493. return new_handler->id;
  494. }
  495. void
  496. XIUnregisterPropertyHandler(DeviceIntPtr dev, long id)
  497. {
  498. XIPropertyHandlerPtr curr, prev = NULL;
  499. curr = dev->properties.handlers;
  500. while (curr && curr->id != id) {
  501. prev = curr;
  502. curr = curr->next;
  503. }
  504. if (!curr)
  505. return;
  506. if (!prev) /* first one */
  507. dev->properties.handlers = curr->next;
  508. else
  509. prev->next = curr->next;
  510. free(curr);
  511. }
  512. static XIPropertyPtr
  513. XICreateDeviceProperty(Atom property)
  514. {
  515. XIPropertyPtr prop;
  516. prop = (XIPropertyPtr) malloc(sizeof(XIPropertyRec));
  517. if (!prop)
  518. return NULL;
  519. prop->next = NULL;
  520. prop->propertyName = property;
  521. prop->value.type = None;
  522. prop->value.format = 0;
  523. prop->value.size = 0;
  524. prop->value.data = NULL;
  525. prop->deletable = TRUE;
  526. return prop;
  527. }
  528. static XIPropertyPtr
  529. XIFetchDeviceProperty(DeviceIntPtr dev, Atom property)
  530. {
  531. XIPropertyPtr prop;
  532. for (prop = dev->properties.properties; prop; prop = prop->next)
  533. if (prop->propertyName == property)
  534. return prop;
  535. return NULL;
  536. }
  537. static void
  538. XIDestroyDeviceProperty(XIPropertyPtr prop)
  539. {
  540. free(prop->value.data);
  541. free(prop);
  542. }
  543. /* This function destroys all of the device's property-related stuff,
  544. * including removing all device handlers.
  545. * DO NOT CALL FROM THE DRIVER.
  546. */
  547. void
  548. XIDeleteAllDeviceProperties(DeviceIntPtr device)
  549. {
  550. XIPropertyPtr prop, next;
  551. XIPropertyHandlerPtr curr_handler, next_handler;
  552. for (prop = device->properties.properties; prop; prop = next) {
  553. next = prop->next;
  554. send_property_event(device, prop->propertyName, XIPropertyDeleted);
  555. XIDestroyDeviceProperty(prop);
  556. }
  557. device->properties.properties = NULL;
  558. /* Now free all handlers */
  559. curr_handler = device->properties.handlers;
  560. while (curr_handler) {
  561. next_handler = curr_handler->next;
  562. free(curr_handler);
  563. curr_handler = next_handler;
  564. }
  565. device->properties.handlers = NULL;
  566. }
  567. int
  568. XIDeleteDeviceProperty(DeviceIntPtr device, Atom property, Bool fromClient)
  569. {
  570. XIPropertyPtr prop, *prev;
  571. int rc = Success;
  572. for (prev = &device->properties.properties; (prop = *prev);
  573. prev = &(prop->next))
  574. if (prop->propertyName == property)
  575. break;
  576. if (!prop)
  577. return Success;
  578. if (fromClient && !prop->deletable)
  579. return BadAccess;
  580. /* Ask handlers if we may delete the property */
  581. if (device->properties.handlers) {
  582. XIPropertyHandlerPtr handler = device->properties.handlers;
  583. while (handler) {
  584. if (handler->DeleteProperty)
  585. rc = handler->DeleteProperty(device, prop->propertyName);
  586. if (rc != Success)
  587. return rc;
  588. handler = handler->next;
  589. }
  590. }
  591. if (prop) {
  592. *prev = prop->next;
  593. send_property_event(device, prop->propertyName, XIPropertyDeleted);
  594. XIDestroyDeviceProperty(prop);
  595. }
  596. return Success;
  597. }
  598. int
  599. XIChangeDeviceProperty(DeviceIntPtr dev, Atom property, Atom type,
  600. int format, int mode, unsigned long len,
  601. const void *value, Bool sendevent)
  602. {
  603. XIPropertyPtr prop;
  604. int size_in_bytes;
  605. int total_size;
  606. unsigned long total_len;
  607. XIPropertyValuePtr prop_value;
  608. XIPropertyValueRec new_value;
  609. Bool add = FALSE;
  610. int rc;
  611. size_in_bytes = format >> 3;
  612. /* first see if property already exists */
  613. prop = XIFetchDeviceProperty(dev, property);
  614. if (!prop) { /* just add to list */
  615. prop = XICreateDeviceProperty(property);
  616. if (!prop)
  617. return BadAlloc;
  618. add = TRUE;
  619. mode = PropModeReplace;
  620. }
  621. prop_value = &prop->value;
  622. /* To append or prepend to a property the request format and type
  623. must match those of the already defined property. The
  624. existing format and type are irrelevant when using the mode
  625. "PropModeReplace" since they will be written over. */
  626. if ((format != prop_value->format) && (mode != PropModeReplace))
  627. return BadMatch;
  628. if ((prop_value->type != type) && (mode != PropModeReplace))
  629. return BadMatch;
  630. new_value = *prop_value;
  631. if (mode == PropModeReplace)
  632. total_len = len;
  633. else
  634. total_len = prop_value->size + len;
  635. if (mode == PropModeReplace || len > 0) {
  636. void *new_data = NULL, *old_data = NULL;
  637. total_size = total_len * size_in_bytes;
  638. new_value.data = (void *) malloc(total_size);
  639. if (!new_value.data && total_size) {
  640. if (add)
  641. XIDestroyDeviceProperty(prop);
  642. return BadAlloc;
  643. }
  644. new_value.size = len;
  645. new_value.type = type;
  646. new_value.format = format;
  647. switch (mode) {
  648. case PropModeReplace:
  649. new_data = new_value.data;
  650. old_data = NULL;
  651. break;
  652. case PropModeAppend:
  653. new_data = (void *) (((char *) new_value.data) +
  654. (prop_value->size * size_in_bytes));
  655. old_data = new_value.data;
  656. break;
  657. case PropModePrepend:
  658. new_data = new_value.data;
  659. old_data = (void *) (((char *) new_value.data) +
  660. (prop_value->size * size_in_bytes));
  661. break;
  662. }
  663. if (new_data)
  664. memcpy((char *) new_data, value, len * size_in_bytes);
  665. if (old_data)
  666. memcpy((char *) old_data, (char *) prop_value->data,
  667. prop_value->size * size_in_bytes);
  668. if (dev->properties.handlers) {
  669. XIPropertyHandlerPtr handler;
  670. BOOL checkonly = TRUE;
  671. /* run through all handlers with checkonly TRUE, then again with
  672. * checkonly FALSE. Handlers MUST return error codes on the
  673. * checkonly run, errors on the second run are ignored */
  674. do {
  675. handler = dev->properties.handlers;
  676. while (handler) {
  677. if (handler->SetProperty) {
  678. rc = handler->SetProperty(dev, prop->propertyName,
  679. &new_value, checkonly);
  680. if (checkonly && rc != Success) {
  681. free(new_value.data);
  682. if (add)
  683. XIDestroyDeviceProperty(prop);
  684. return rc;
  685. }
  686. }
  687. handler = handler->next;
  688. }
  689. checkonly = !checkonly;
  690. } while (!checkonly);
  691. }
  692. free(prop_value->data);
  693. *prop_value = new_value;
  694. }
  695. else if (len == 0) {
  696. /* do nothing */
  697. }
  698. if (add) {
  699. prop->next = dev->properties.properties;
  700. dev->properties.properties = prop;
  701. }
  702. if (sendevent)
  703. send_property_event(dev, prop->propertyName,
  704. (add) ? XIPropertyCreated : XIPropertyModified);
  705. return Success;
  706. }
  707. int
  708. XIGetDeviceProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr *value)
  709. {
  710. XIPropertyPtr prop = XIFetchDeviceProperty(dev, property);
  711. int rc;
  712. if (!prop) {
  713. *value = NULL;
  714. return BadAtom;
  715. }
  716. /* If we can, try to update the property value first */
  717. if (dev->properties.handlers) {
  718. XIPropertyHandlerPtr handler = dev->properties.handlers;
  719. while (handler) {
  720. if (handler->GetProperty) {
  721. rc = handler->GetProperty(dev, prop->propertyName);
  722. if (rc != Success) {
  723. *value = NULL;
  724. return rc;
  725. }
  726. }
  727. handler = handler->next;
  728. }
  729. }
  730. *value = &prop->value;
  731. return Success;
  732. }
  733. int
  734. XISetDevicePropertyDeletable(DeviceIntPtr dev, Atom property, Bool deletable)
  735. {
  736. XIPropertyPtr prop = XIFetchDeviceProperty(dev, property);
  737. if (!prop)
  738. return BadAtom;
  739. prop->deletable = deletable;
  740. return Success;
  741. }
  742. int
  743. ProcXListDeviceProperties(ClientPtr client)
  744. {
  745. Atom *atoms;
  746. xListDevicePropertiesReply rep;
  747. int natoms;
  748. DeviceIntPtr dev;
  749. int rc = Success;
  750. REQUEST(xListDevicePropertiesReq);
  751. REQUEST_SIZE_MATCH(xListDevicePropertiesReq);
  752. rc = dixLookupDevice(&dev, stuff->deviceid, client, DixListPropAccess);
  753. if (rc != Success)
  754. return rc;
  755. rc = list_atoms(dev, &natoms, &atoms);
  756. if (rc != Success)
  757. return rc;
  758. rep = (xListDevicePropertiesReply) {
  759. .repType = X_Reply,
  760. .RepType = X_ListDeviceProperties,
  761. .sequenceNumber = client->sequence,
  762. .length = natoms,
  763. .nAtoms = natoms
  764. };
  765. WriteReplyToClient(client, sizeof(xListDevicePropertiesReply), &rep);
  766. if (natoms) {
  767. client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
  768. WriteSwappedDataToClient(client, natoms * sizeof(Atom), atoms);
  769. free(atoms);
  770. }
  771. return rc;
  772. }
  773. int
  774. ProcXChangeDeviceProperty(ClientPtr client)
  775. {
  776. REQUEST(xChangeDevicePropertyReq);
  777. DeviceIntPtr dev;
  778. unsigned long len;
  779. int totalSize;
  780. int rc;
  781. REQUEST_AT_LEAST_SIZE(xChangeDevicePropertyReq);
  782. UpdateCurrentTime();
  783. rc = dixLookupDevice(&dev, stuff->deviceid, client, DixSetPropAccess);
  784. if (rc != Success)
  785. return rc;
  786. rc = check_change_property(client, stuff->property, stuff->type,
  787. stuff->format, stuff->mode, stuff->nUnits);
  788. len = stuff->nUnits;
  789. if (len > (bytes_to_int32(0xffffffff - sizeof(xChangeDevicePropertyReq))))
  790. return BadLength;
  791. totalSize = len * (stuff->format / 8);
  792. REQUEST_FIXED_SIZE(xChangeDevicePropertyReq, totalSize);
  793. rc = change_property(client, dev, stuff->property, stuff->type,
  794. stuff->format, stuff->mode, len, (void *) &stuff[1]);
  795. return rc;
  796. }
  797. int
  798. ProcXDeleteDeviceProperty(ClientPtr client)
  799. {
  800. REQUEST(xDeleteDevicePropertyReq);
  801. DeviceIntPtr dev;
  802. int rc;
  803. REQUEST_SIZE_MATCH(xDeleteDevicePropertyReq);
  804. UpdateCurrentTime();
  805. rc = dixLookupDevice(&dev, stuff->deviceid, client, DixSetPropAccess);
  806. if (rc != Success)
  807. return rc;
  808. if (!ValidAtom(stuff->property)) {
  809. client->errorValue = stuff->property;
  810. return BadAtom;
  811. }
  812. rc = XIDeleteDeviceProperty(dev, stuff->property, TRUE);
  813. return rc;
  814. }
  815. int
  816. ProcXGetDeviceProperty(ClientPtr client)
  817. {
  818. REQUEST(xGetDevicePropertyReq);
  819. DeviceIntPtr dev;
  820. int length;
  821. int rc, format, nitems, bytes_after;
  822. char *data;
  823. Atom type;
  824. xGetDevicePropertyReply reply;
  825. REQUEST_SIZE_MATCH(xGetDevicePropertyReq);
  826. if (stuff->delete)
  827. UpdateCurrentTime();
  828. rc = dixLookupDevice(&dev, stuff->deviceid, client,
  829. stuff->delete ? DixSetPropAccess : DixGetPropAccess);
  830. if (rc != Success)
  831. return rc;
  832. rc = get_property(client, dev, stuff->property, stuff->type,
  833. stuff->delete, stuff->longOffset, stuff->longLength,
  834. &bytes_after, &type, &format, &nitems, &length, &data);
  835. if (rc != Success)
  836. return rc;
  837. reply = (xGetDevicePropertyReply) {
  838. .repType = X_Reply,
  839. .RepType = X_GetDeviceProperty,
  840. .sequenceNumber = client->sequence,
  841. .length = bytes_to_int32(length),
  842. .propertyType = type,
  843. .bytesAfter = bytes_after,
  844. .nItems = nitems,
  845. .format = format,
  846. .deviceid = dev->id
  847. };
  848. if (stuff->delete && (reply.bytesAfter == 0))
  849. send_property_event(dev, stuff->property, XIPropertyDeleted);
  850. WriteReplyToClient(client, sizeof(xGenericReply), &reply);
  851. if (length) {
  852. switch (reply.format) {
  853. case 32:
  854. client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write;
  855. break;
  856. case 16:
  857. client->pSwapReplyFunc = (ReplySwapPtr) CopySwap16Write;
  858. break;
  859. default:
  860. client->pSwapReplyFunc = (ReplySwapPtr) WriteToClient;
  861. break;
  862. }
  863. WriteSwappedDataToClient(client, length, data);
  864. }
  865. /* delete the Property */
  866. if (stuff->delete && (reply.bytesAfter == 0)) {
  867. XIPropertyPtr prop, *prev;
  868. for (prev = &dev->properties.properties; (prop = *prev);
  869. prev = &prop->next) {
  870. if (prop->propertyName == stuff->property) {
  871. *prev = prop->next;
  872. XIDestroyDeviceProperty(prop);
  873. break;
  874. }
  875. }
  876. }
  877. return Success;
  878. }
  879. int
  880. SProcXListDeviceProperties(ClientPtr client)
  881. {
  882. REQUEST(xListDevicePropertiesReq);
  883. REQUEST_SIZE_MATCH(xListDevicePropertiesReq);
  884. swaps(&stuff->length);
  885. return (ProcXListDeviceProperties(client));
  886. }
  887. int
  888. SProcXChangeDeviceProperty(ClientPtr client)
  889. {
  890. REQUEST(xChangeDevicePropertyReq);
  891. REQUEST_AT_LEAST_SIZE(xChangeDevicePropertyReq);
  892. swaps(&stuff->length);
  893. swapl(&stuff->property);
  894. swapl(&stuff->type);
  895. swapl(&stuff->nUnits);
  896. return (ProcXChangeDeviceProperty(client));
  897. }
  898. int
  899. SProcXDeleteDeviceProperty(ClientPtr client)
  900. {
  901. REQUEST(xDeleteDevicePropertyReq);
  902. REQUEST_SIZE_MATCH(xDeleteDevicePropertyReq);
  903. swaps(&stuff->length);
  904. swapl(&stuff->property);
  905. return (ProcXDeleteDeviceProperty(client));
  906. }
  907. int
  908. SProcXGetDeviceProperty(ClientPtr client)
  909. {
  910. REQUEST(xGetDevicePropertyReq);
  911. REQUEST_SIZE_MATCH(xGetDevicePropertyReq);
  912. swaps(&stuff->length);
  913. swapl(&stuff->property);
  914. swapl(&stuff->type);
  915. swapl(&stuff->longOffset);
  916. swapl(&stuff->longLength);
  917. return (ProcXGetDeviceProperty(client));
  918. }
  919. /* Reply swapping */
  920. void
  921. SRepXListDeviceProperties(ClientPtr client, int size,
  922. xListDevicePropertiesReply * rep)
  923. {
  924. swaps(&rep->sequenceNumber);
  925. swapl(&rep->length);
  926. swaps(&rep->nAtoms);
  927. /* properties will be swapped later, see ProcXListDeviceProperties */
  928. WriteToClient(client, size, rep);
  929. }
  930. void
  931. SRepXGetDeviceProperty(ClientPtr client, int size,
  932. xGetDevicePropertyReply * rep)
  933. {
  934. swaps(&rep->sequenceNumber);
  935. swapl(&rep->length);
  936. swapl(&rep->propertyType);
  937. swapl(&rep->bytesAfter);
  938. swapl(&rep->nItems);
  939. /* data will be swapped, see ProcXGetDeviceProperty */
  940. WriteToClient(client, size, rep);
  941. }
  942. /* XI2 Request/reply handling */
  943. int
  944. ProcXIListProperties(ClientPtr client)
  945. {
  946. Atom *atoms;
  947. xXIListPropertiesReply rep;
  948. int natoms;
  949. DeviceIntPtr dev;
  950. int rc = Success;
  951. REQUEST(xXIListPropertiesReq);
  952. REQUEST_SIZE_MATCH(xXIListPropertiesReq);
  953. rc = dixLookupDevice(&dev, stuff->deviceid, client, DixListPropAccess);
  954. if (rc != Success)
  955. return rc;
  956. rc = list_atoms(dev, &natoms, &atoms);
  957. if (rc != Success)
  958. return rc;
  959. rep = (xXIListPropertiesReply) {
  960. .repType = X_Reply,
  961. .RepType = X_XIListProperties,
  962. .sequenceNumber = client->sequence,
  963. .length = natoms,
  964. .num_properties = natoms
  965. };
  966. WriteReplyToClient(client, sizeof(xXIListPropertiesReply), &rep);
  967. if (natoms) {
  968. client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
  969. WriteSwappedDataToClient(client, natoms * sizeof(Atom), atoms);
  970. free(atoms);
  971. }
  972. return rc;
  973. }
  974. int
  975. ProcXIChangeProperty(ClientPtr client)
  976. {
  977. int rc;
  978. DeviceIntPtr dev;
  979. int totalSize;
  980. unsigned long len;
  981. REQUEST(xXIChangePropertyReq);
  982. REQUEST_AT_LEAST_SIZE(xXIChangePropertyReq);
  983. UpdateCurrentTime();
  984. rc = dixLookupDevice(&dev, stuff->deviceid, client, DixSetPropAccess);
  985. if (rc != Success)
  986. return rc;
  987. rc = check_change_property(client, stuff->property, stuff->type,
  988. stuff->format, stuff->mode, stuff->num_items);
  989. len = stuff->num_items;
  990. if (len > bytes_to_int32(0xffffffff - sizeof(xXIChangePropertyReq)))
  991. return BadLength;
  992. totalSize = len * (stuff->format / 8);
  993. REQUEST_FIXED_SIZE(xXIChangePropertyReq, totalSize);
  994. rc = change_property(client, dev, stuff->property, stuff->type,
  995. stuff->format, stuff->mode, len, (void *) &stuff[1]);
  996. return rc;
  997. }
  998. int
  999. ProcXIDeleteProperty(ClientPtr client)
  1000. {
  1001. DeviceIntPtr dev;
  1002. int rc;
  1003. REQUEST(xXIDeletePropertyReq);
  1004. REQUEST_SIZE_MATCH(xXIDeletePropertyReq);
  1005. UpdateCurrentTime();
  1006. rc = dixLookupDevice(&dev, stuff->deviceid, client, DixSetPropAccess);
  1007. if (rc != Success)
  1008. return rc;
  1009. if (!ValidAtom(stuff->property)) {
  1010. client->errorValue = stuff->property;
  1011. return BadAtom;
  1012. }
  1013. rc = XIDeleteDeviceProperty(dev, stuff->property, TRUE);
  1014. return rc;
  1015. }
  1016. int
  1017. ProcXIGetProperty(ClientPtr client)
  1018. {
  1019. REQUEST(xXIGetPropertyReq);
  1020. DeviceIntPtr dev;
  1021. xXIGetPropertyReply reply;
  1022. int length;
  1023. int rc, format, nitems, bytes_after;
  1024. char *data;
  1025. Atom type;
  1026. REQUEST_SIZE_MATCH(xXIGetPropertyReq);
  1027. if (stuff->delete)
  1028. UpdateCurrentTime();
  1029. rc = dixLookupDevice(&dev, stuff->deviceid, client,
  1030. stuff->delete ? DixSetPropAccess : DixGetPropAccess);
  1031. if (rc != Success)
  1032. return rc;
  1033. rc = get_property(client, dev, stuff->property, stuff->type,
  1034. stuff->delete, stuff->offset, stuff->len,
  1035. &bytes_after, &type, &format, &nitems, &length, &data);
  1036. if (rc != Success)
  1037. return rc;
  1038. reply = (xXIGetPropertyReply) {
  1039. .repType = X_Reply,
  1040. .RepType = X_XIGetProperty,
  1041. .sequenceNumber = client->sequence,
  1042. .length = bytes_to_int32(length),
  1043. .type = type,
  1044. .bytes_after = bytes_after,
  1045. .num_items = nitems,
  1046. .format = format
  1047. };
  1048. if (length && stuff->delete && (reply.bytes_after == 0))
  1049. send_property_event(dev, stuff->property, XIPropertyDeleted);
  1050. WriteReplyToClient(client, sizeof(xXIGetPropertyReply), &reply);
  1051. if (length) {
  1052. switch (reply.format) {
  1053. case 32:
  1054. client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write;
  1055. break;
  1056. case 16:
  1057. client->pSwapReplyFunc = (ReplySwapPtr) CopySwap16Write;
  1058. break;
  1059. default:
  1060. client->pSwapReplyFunc = (ReplySwapPtr) WriteToClient;
  1061. break;
  1062. }
  1063. WriteSwappedDataToClient(client, length, data);
  1064. }
  1065. /* delete the Property */
  1066. if (stuff->delete && (reply.bytes_after == 0)) {
  1067. XIPropertyPtr prop, *prev;
  1068. for (prev = &dev->properties.properties; (prop = *prev);
  1069. prev = &prop->next) {
  1070. if (prop->propertyName == stuff->property) {
  1071. *prev = prop->next;
  1072. XIDestroyDeviceProperty(prop);
  1073. break;
  1074. }
  1075. }
  1076. }
  1077. return Success;
  1078. }
  1079. int
  1080. SProcXIListProperties(ClientPtr client)
  1081. {
  1082. REQUEST(xXIListPropertiesReq);
  1083. REQUEST_SIZE_MATCH(xXIListPropertiesReq);
  1084. swaps(&stuff->length);
  1085. swaps(&stuff->deviceid);
  1086. return (ProcXIListProperties(client));
  1087. }
  1088. int
  1089. SProcXIChangeProperty(ClientPtr client)
  1090. {
  1091. REQUEST(xXIChangePropertyReq);
  1092. REQUEST_AT_LEAST_SIZE(xXIChangePropertyReq);
  1093. swaps(&stuff->length);
  1094. swaps(&stuff->deviceid);
  1095. swapl(&stuff->property);
  1096. swapl(&stuff->type);
  1097. swapl(&stuff->num_items);
  1098. return (ProcXIChangeProperty(client));
  1099. }
  1100. int
  1101. SProcXIDeleteProperty(ClientPtr client)
  1102. {
  1103. REQUEST(xXIDeletePropertyReq);
  1104. REQUEST_SIZE_MATCH(xXIDeletePropertyReq);
  1105. swaps(&stuff->length);
  1106. swaps(&stuff->deviceid);
  1107. swapl(&stuff->property);
  1108. return (ProcXIDeleteProperty(client));
  1109. }
  1110. int
  1111. SProcXIGetProperty(ClientPtr client)
  1112. {
  1113. REQUEST(xXIGetPropertyReq);
  1114. REQUEST_SIZE_MATCH(xXIGetPropertyReq);
  1115. swaps(&stuff->length);
  1116. swaps(&stuff->deviceid);
  1117. swapl(&stuff->property);
  1118. swapl(&stuff->type);
  1119. swapl(&stuff->offset);
  1120. swapl(&stuff->len);
  1121. return (ProcXIGetProperty(client));
  1122. }
  1123. void
  1124. SRepXIListProperties(ClientPtr client, int size, xXIListPropertiesReply * rep)
  1125. {
  1126. swaps(&rep->sequenceNumber);
  1127. swapl(&rep->length);
  1128. swaps(&rep->num_properties);
  1129. /* properties will be swapped later, see ProcXIListProperties */
  1130. WriteToClient(client, size, rep);
  1131. }
  1132. void
  1133. SRepXIGetProperty(ClientPtr client, int size, xXIGetPropertyReply * rep)
  1134. {
  1135. swaps(&rep->sequenceNumber);
  1136. swapl(&rep->length);
  1137. swapl(&rep->type);
  1138. swapl(&rep->bytes_after);
  1139. swapl(&rep->num_items);
  1140. /* data will be swapped, see ProcXIGetProperty */
  1141. WriteToClient(client, size, rep);
  1142. }