extinit.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  1. /************************************************************
  2. Copyright 1989, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Hewlett-Packard not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. ********************************************************/
  36. /********************************************************************
  37. *
  38. * Dispatch routines and initialization routines for the X input extension.
  39. *
  40. */
  41. #define NUMTYPES 15
  42. #ifdef HAVE_DIX_CONFIG_H
  43. #include <dix-config.h>
  44. #endif
  45. #include "inputstr.h"
  46. #include "gcstruct.h" /* pointer for extnsionst.h */
  47. #include "extnsionst.h" /* extension entry */
  48. #include <X11/extensions/XI.h>
  49. #include <X11/extensions/XIproto.h>
  50. #include <X11/extensions/XI2proto.h>
  51. #include <X11/extensions/geproto.h>
  52. #include "geext.h" /* extension interfaces for ge */
  53. #include "dixevents.h"
  54. #include "exevents.h"
  55. #include "extinit.h"
  56. #include "exglobals.h"
  57. #include "swaprep.h"
  58. #include "privates.h"
  59. #include "protocol-versions.h"
  60. /* modules local to Xi */
  61. #include "allowev.h"
  62. #include "chgdctl.h"
  63. #include "chgfctl.h"
  64. #include "chgkbd.h"
  65. #include "chgprop.h"
  66. #include "chgptr.h"
  67. #include "closedev.h"
  68. #include "devbell.h"
  69. #include "getbmap.h"
  70. #include "getdctl.h"
  71. #include "getfctl.h"
  72. #include "getfocus.h"
  73. #include "getkmap.h"
  74. #include "getmmap.h"
  75. #include "getprop.h"
  76. #include "getselev.h"
  77. #include "getvers.h"
  78. #include "grabdev.h"
  79. #include "grabdevb.h"
  80. #include "grabdevk.h"
  81. #include "gtmotion.h"
  82. #include "listdev.h"
  83. #include "opendev.h"
  84. #include "queryst.h"
  85. #include "selectev.h"
  86. #include "sendexev.h"
  87. #include "chgkmap.h"
  88. #include "setbmap.h"
  89. #include "setdval.h"
  90. #include "setfocus.h"
  91. #include "setmmap.h"
  92. #include "setmode.h"
  93. #include "ungrdev.h"
  94. #include "ungrdevb.h"
  95. #include "ungrdevk.h"
  96. #include "xiallowev.h"
  97. #include "xiselectev.h"
  98. #include "xigrabdev.h"
  99. #include "xipassivegrab.h"
  100. #include "xisetdevfocus.h"
  101. #include "xiproperty.h"
  102. #include "xichangecursor.h"
  103. #include "xichangehierarchy.h"
  104. #include "xigetclientpointer.h"
  105. #include "xiquerydevice.h"
  106. #include "xiquerypointer.h"
  107. #include "xiqueryversion.h"
  108. #include "xisetclientpointer.h"
  109. #include "xiwarppointer.h"
  110. #include "xibarriers.h"
  111. /* Masks for XI events have to be aligned with core event (partially anyway).
  112. * If DeviceButtonMotionMask is != ButtonMotionMask, event delivery
  113. * breaks down. The device needs the dev->button->motionMask. If DBMM is
  114. * the same as BMM, we can ensure that both core and device events can be
  115. * delivered, without the need for extra structures in the DeviceIntRec. */
  116. const Mask DeviceKeyPressMask = KeyPressMask;
  117. const Mask DeviceKeyReleaseMask = KeyReleaseMask;
  118. const Mask DeviceButtonPressMask = ButtonPressMask;
  119. const Mask DeviceButtonReleaseMask = ButtonReleaseMask;
  120. const Mask DeviceProximityMask = (1L << 4);
  121. const Mask DeviceStateNotifyMask = (1L << 5);
  122. const Mask DevicePointerMotionMask = PointerMotionMask;
  123. const Mask DevicePointerMotionHintMask = PointerMotionHintMask;
  124. const Mask DeviceButton1MotionMask = Button1MotionMask;
  125. const Mask DeviceButton2MotionMask = Button2MotionMask;
  126. const Mask DeviceButton3MotionMask = Button3MotionMask;
  127. const Mask DeviceButton4MotionMask = Button4MotionMask;
  128. const Mask DeviceButton5MotionMask = Button5MotionMask;
  129. const Mask DeviceButtonMotionMask = ButtonMotionMask;
  130. const Mask DeviceFocusChangeMask = (1L << 14);
  131. const Mask DeviceMappingNotifyMask = (1L << 15);
  132. const Mask ChangeDeviceNotifyMask = (1L << 16);
  133. const Mask DeviceButtonGrabMask = (1L << 17);
  134. const Mask DeviceOwnerGrabButtonMask = (1L << 17);
  135. const Mask DevicePresenceNotifyMask = (1L << 18);
  136. const Mask DevicePropertyNotifyMask = (1L << 19);
  137. const Mask XIAllMasks = (1L << 20) - 1;
  138. int ExtEventIndex;
  139. Mask ExtExclusiveMasks[EMASKSIZE];
  140. static struct dev_type {
  141. Atom type;
  142. const char *name;
  143. } dev_type[] = {
  144. {0, XI_KEYBOARD},
  145. {0, XI_MOUSE},
  146. {0, XI_TABLET},
  147. {0, XI_TOUCHSCREEN},
  148. {0, XI_TOUCHPAD},
  149. {0, XI_BARCODE},
  150. {0, XI_BUTTONBOX},
  151. {0, XI_KNOB_BOX},
  152. {0, XI_ONE_KNOB},
  153. {0, XI_NINE_KNOB},
  154. {0, XI_TRACKBALL},
  155. {0, XI_QUADRATURE},
  156. {0, XI_ID_MODULE},
  157. {0, XI_SPACEBALL},
  158. {0, XI_DATAGLOVE},
  159. {0, XI_EYETRACKER},
  160. {0, XI_CURSORKEYS},
  161. {0, XI_FOOTMOUSE}
  162. };
  163. CARD8 event_base[numInputClasses];
  164. XExtEventInfo EventInfo[32];
  165. static DeviceIntRec xi_all_devices;
  166. static DeviceIntRec xi_all_master_devices;
  167. /**
  168. * Dispatch vector. Functions defined in here will be called when the matching
  169. * request arrives.
  170. */
  171. static int (*ProcIVector[]) (ClientPtr) = {
  172. NULL, /* 0 */
  173. ProcXGetExtensionVersion, /* 1 */
  174. ProcXListInputDevices, /* 2 */
  175. ProcXOpenDevice, /* 3 */
  176. ProcXCloseDevice, /* 4 */
  177. ProcXSetDeviceMode, /* 5 */
  178. ProcXSelectExtensionEvent, /* 6 */
  179. ProcXGetSelectedExtensionEvents, /* 7 */
  180. ProcXChangeDeviceDontPropagateList, /* 8 */
  181. ProcXGetDeviceDontPropagateList, /* 9 */
  182. ProcXGetDeviceMotionEvents, /* 10 */
  183. ProcXChangeKeyboardDevice, /* 11 */
  184. ProcXChangePointerDevice, /* 12 */
  185. ProcXGrabDevice, /* 13 */
  186. ProcXUngrabDevice, /* 14 */
  187. ProcXGrabDeviceKey, /* 15 */
  188. ProcXUngrabDeviceKey, /* 16 */
  189. ProcXGrabDeviceButton, /* 17 */
  190. ProcXUngrabDeviceButton, /* 18 */
  191. ProcXAllowDeviceEvents, /* 19 */
  192. ProcXGetDeviceFocus, /* 20 */
  193. ProcXSetDeviceFocus, /* 21 */
  194. ProcXGetFeedbackControl, /* 22 */
  195. ProcXChangeFeedbackControl, /* 23 */
  196. ProcXGetDeviceKeyMapping, /* 24 */
  197. ProcXChangeDeviceKeyMapping, /* 25 */
  198. ProcXGetDeviceModifierMapping, /* 26 */
  199. ProcXSetDeviceModifierMapping, /* 27 */
  200. ProcXGetDeviceButtonMapping, /* 28 */
  201. ProcXSetDeviceButtonMapping, /* 29 */
  202. ProcXQueryDeviceState, /* 30 */
  203. ProcXSendExtensionEvent, /* 31 */
  204. ProcXDeviceBell, /* 32 */
  205. ProcXSetDeviceValuators, /* 33 */
  206. ProcXGetDeviceControl, /* 34 */
  207. ProcXChangeDeviceControl, /* 35 */
  208. /* XI 1.5 */
  209. ProcXListDeviceProperties, /* 36 */
  210. ProcXChangeDeviceProperty, /* 37 */
  211. ProcXDeleteDeviceProperty, /* 38 */
  212. ProcXGetDeviceProperty, /* 39 */
  213. /* XI 2 */
  214. ProcXIQueryPointer, /* 40 */
  215. ProcXIWarpPointer, /* 41 */
  216. ProcXIChangeCursor, /* 42 */
  217. ProcXIChangeHierarchy, /* 43 */
  218. ProcXISetClientPointer, /* 44 */
  219. ProcXIGetClientPointer, /* 45 */
  220. ProcXISelectEvents, /* 46 */
  221. ProcXIQueryVersion, /* 47 */
  222. ProcXIQueryDevice, /* 48 */
  223. ProcXISetFocus, /* 49 */
  224. ProcXIGetFocus, /* 50 */
  225. ProcXIGrabDevice, /* 51 */
  226. ProcXIUngrabDevice, /* 52 */
  227. ProcXIAllowEvents, /* 53 */
  228. ProcXIPassiveGrabDevice, /* 54 */
  229. ProcXIPassiveUngrabDevice, /* 55 */
  230. ProcXIListProperties, /* 56 */
  231. ProcXIChangeProperty, /* 57 */
  232. ProcXIDeleteProperty, /* 58 */
  233. ProcXIGetProperty, /* 59 */
  234. ProcXIGetSelectedEvents, /* 60 */
  235. ProcXIBarrierReleasePointer /* 61 */
  236. };
  237. /* For swapped clients */
  238. static int (*SProcIVector[]) (ClientPtr) = {
  239. NULL, /* 0 */
  240. SProcXGetExtensionVersion, /* 1 */
  241. SProcXListInputDevices, /* 2 */
  242. SProcXOpenDevice, /* 3 */
  243. SProcXCloseDevice, /* 4 */
  244. SProcXSetDeviceMode, /* 5 */
  245. SProcXSelectExtensionEvent, /* 6 */
  246. SProcXGetSelectedExtensionEvents, /* 7 */
  247. SProcXChangeDeviceDontPropagateList, /* 8 */
  248. SProcXGetDeviceDontPropagateList, /* 9 */
  249. SProcXGetDeviceMotionEvents, /* 10 */
  250. SProcXChangeKeyboardDevice, /* 11 */
  251. SProcXChangePointerDevice, /* 12 */
  252. SProcXGrabDevice, /* 13 */
  253. SProcXUngrabDevice, /* 14 */
  254. SProcXGrabDeviceKey, /* 15 */
  255. SProcXUngrabDeviceKey, /* 16 */
  256. SProcXGrabDeviceButton, /* 17 */
  257. SProcXUngrabDeviceButton, /* 18 */
  258. SProcXAllowDeviceEvents, /* 19 */
  259. SProcXGetDeviceFocus, /* 20 */
  260. SProcXSetDeviceFocus, /* 21 */
  261. SProcXGetFeedbackControl, /* 22 */
  262. SProcXChangeFeedbackControl, /* 23 */
  263. SProcXGetDeviceKeyMapping, /* 24 */
  264. SProcXChangeDeviceKeyMapping, /* 25 */
  265. SProcXGetDeviceModifierMapping, /* 26 */
  266. SProcXSetDeviceModifierMapping, /* 27 */
  267. SProcXGetDeviceButtonMapping, /* 28 */
  268. SProcXSetDeviceButtonMapping, /* 29 */
  269. SProcXQueryDeviceState, /* 30 */
  270. SProcXSendExtensionEvent, /* 31 */
  271. SProcXDeviceBell, /* 32 */
  272. SProcXSetDeviceValuators, /* 33 */
  273. SProcXGetDeviceControl, /* 34 */
  274. SProcXChangeDeviceControl, /* 35 */
  275. SProcXListDeviceProperties, /* 36 */
  276. SProcXChangeDeviceProperty, /* 37 */
  277. SProcXDeleteDeviceProperty, /* 38 */
  278. SProcXGetDeviceProperty, /* 39 */
  279. SProcXIQueryPointer, /* 40 */
  280. SProcXIWarpPointer, /* 41 */
  281. SProcXIChangeCursor, /* 42 */
  282. SProcXIChangeHierarchy, /* 43 */
  283. SProcXISetClientPointer, /* 44 */
  284. SProcXIGetClientPointer, /* 45 */
  285. SProcXISelectEvents, /* 46 */
  286. SProcXIQueryVersion, /* 47 */
  287. SProcXIQueryDevice, /* 48 */
  288. SProcXISetFocus, /* 49 */
  289. SProcXIGetFocus, /* 50 */
  290. SProcXIGrabDevice, /* 51 */
  291. SProcXIUngrabDevice, /* 52 */
  292. SProcXIAllowEvents, /* 53 */
  293. SProcXIPassiveGrabDevice, /* 54 */
  294. SProcXIPassiveUngrabDevice, /* 55 */
  295. SProcXIListProperties, /* 56 */
  296. SProcXIChangeProperty, /* 57 */
  297. SProcXIDeleteProperty, /* 58 */
  298. SProcXIGetProperty, /* 59 */
  299. SProcXIGetSelectedEvents, /* 60 */
  300. SProcXIBarrierReleasePointer /* 61 */
  301. };
  302. /*****************************************************************
  303. *
  304. * Globals referenced elsewhere in the server.
  305. *
  306. */
  307. int IReqCode = 0;
  308. int IEventBase = 0;
  309. int BadDevice = 0;
  310. static int BadEvent = 1;
  311. int BadMode = 2;
  312. int DeviceBusy = 3;
  313. int BadClass = 4;
  314. int DeviceValuator;
  315. int DeviceKeyPress;
  316. int DeviceKeyRelease;
  317. int DeviceButtonPress;
  318. int DeviceButtonRelease;
  319. int DeviceMotionNotify;
  320. int DeviceFocusIn;
  321. int DeviceFocusOut;
  322. int ProximityIn;
  323. int ProximityOut;
  324. int DeviceStateNotify;
  325. int DeviceKeyStateNotify;
  326. int DeviceButtonStateNotify;
  327. int DeviceMappingNotify;
  328. int ChangeDeviceNotify;
  329. int DevicePresenceNotify;
  330. int DevicePropertyNotify;
  331. RESTYPE RT_INPUTCLIENT;
  332. /*****************************************************************
  333. *
  334. * Externs defined elsewhere in the X server.
  335. *
  336. */
  337. extern XExtensionVersion XIVersion;
  338. Mask PropagateMask[EMASKSIZE];
  339. /*****************************************************************
  340. *
  341. * Versioning support
  342. *
  343. */
  344. DevPrivateKeyRec XIClientPrivateKeyRec;
  345. /*****************************************************************
  346. *
  347. * Declarations of local routines.
  348. *
  349. */
  350. static void
  351. XIClientCallback(CallbackListPtr *list, void *closure, void *data)
  352. {
  353. NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
  354. ClientPtr pClient = clientinfo->client;
  355. XIClientPtr pXIClient;
  356. pXIClient = dixLookupPrivate(&pClient->devPrivates, XIClientPrivateKey);
  357. pXIClient->major_version = 0;
  358. pXIClient->minor_version = 0;
  359. }
  360. /*************************************************************************
  361. *
  362. * ProcIDispatch - main dispatch routine for requests to this extension.
  363. * This routine is used if server and client have the same byte ordering.
  364. *
  365. */
  366. static int
  367. ProcIDispatch(ClientPtr client)
  368. {
  369. REQUEST(xReq);
  370. if (stuff->data >= ARRAY_SIZE(ProcIVector) || !ProcIVector[stuff->data])
  371. return BadRequest;
  372. return (*ProcIVector[stuff->data]) (client);
  373. }
  374. /*******************************************************************************
  375. *
  376. * SProcXDispatch
  377. *
  378. * Main swapped dispatch routine for requests to this extension.
  379. * This routine is used if server and client do not have the same byte ordering.
  380. *
  381. */
  382. static int
  383. SProcIDispatch(ClientPtr client)
  384. {
  385. REQUEST(xReq);
  386. if (stuff->data >= ARRAY_SIZE(SProcIVector) || !SProcIVector[stuff->data])
  387. return BadRequest;
  388. return (*SProcIVector[stuff->data]) (client);
  389. }
  390. /**********************************************************************
  391. *
  392. * SReplyIDispatch
  393. * Swap any replies defined in this extension.
  394. *
  395. */
  396. static void
  397. SReplyIDispatch(ClientPtr client, int len, xGrabDeviceReply * rep)
  398. {
  399. /* All we look at is the type field */
  400. /* This is common to all replies */
  401. if (rep->RepType == X_GetExtensionVersion)
  402. SRepXGetExtensionVersion(client, len,
  403. (xGetExtensionVersionReply *) rep);
  404. else if (rep->RepType == X_ListInputDevices)
  405. SRepXListInputDevices(client, len, (xListInputDevicesReply *) rep);
  406. else if (rep->RepType == X_OpenDevice)
  407. SRepXOpenDevice(client, len, (xOpenDeviceReply *) rep);
  408. else if (rep->RepType == X_SetDeviceMode)
  409. SRepXSetDeviceMode(client, len, (xSetDeviceModeReply *) rep);
  410. else if (rep->RepType == X_GetSelectedExtensionEvents)
  411. SRepXGetSelectedExtensionEvents(client, len,
  412. (xGetSelectedExtensionEventsReply *)
  413. rep);
  414. else if (rep->RepType == X_GetDeviceDontPropagateList)
  415. SRepXGetDeviceDontPropagateList(client, len,
  416. (xGetDeviceDontPropagateListReply *)
  417. rep);
  418. else if (rep->RepType == X_GetDeviceMotionEvents)
  419. SRepXGetDeviceMotionEvents(client, len,
  420. (xGetDeviceMotionEventsReply *) rep);
  421. else if (rep->RepType == X_GrabDevice)
  422. SRepXGrabDevice(client, len, (xGrabDeviceReply *) rep);
  423. else if (rep->RepType == X_GetDeviceFocus)
  424. SRepXGetDeviceFocus(client, len, (xGetDeviceFocusReply *) rep);
  425. else if (rep->RepType == X_GetFeedbackControl)
  426. SRepXGetFeedbackControl(client, len, (xGetFeedbackControlReply *) rep);
  427. else if (rep->RepType == X_GetDeviceKeyMapping)
  428. SRepXGetDeviceKeyMapping(client, len,
  429. (xGetDeviceKeyMappingReply *) rep);
  430. else if (rep->RepType == X_GetDeviceModifierMapping)
  431. SRepXGetDeviceModifierMapping(client, len,
  432. (xGetDeviceModifierMappingReply *) rep);
  433. else if (rep->RepType == X_SetDeviceModifierMapping)
  434. SRepXSetDeviceModifierMapping(client, len,
  435. (xSetDeviceModifierMappingReply *) rep);
  436. else if (rep->RepType == X_GetDeviceButtonMapping)
  437. SRepXGetDeviceButtonMapping(client, len,
  438. (xGetDeviceButtonMappingReply *) rep);
  439. else if (rep->RepType == X_SetDeviceButtonMapping)
  440. SRepXSetDeviceButtonMapping(client, len,
  441. (xSetDeviceButtonMappingReply *) rep);
  442. else if (rep->RepType == X_QueryDeviceState)
  443. SRepXQueryDeviceState(client, len, (xQueryDeviceStateReply *) rep);
  444. else if (rep->RepType == X_SetDeviceValuators)
  445. SRepXSetDeviceValuators(client, len, (xSetDeviceValuatorsReply *) rep);
  446. else if (rep->RepType == X_GetDeviceControl)
  447. SRepXGetDeviceControl(client, len, (xGetDeviceControlReply *) rep);
  448. else if (rep->RepType == X_ChangeDeviceControl)
  449. SRepXChangeDeviceControl(client, len,
  450. (xChangeDeviceControlReply *) rep);
  451. else if (rep->RepType == X_ListDeviceProperties)
  452. SRepXListDeviceProperties(client, len,
  453. (xListDevicePropertiesReply *) rep);
  454. else if (rep->RepType == X_GetDeviceProperty)
  455. SRepXGetDeviceProperty(client, len, (xGetDevicePropertyReply *) rep);
  456. else if (rep->RepType == X_XIQueryPointer)
  457. SRepXIQueryPointer(client, len, (xXIQueryPointerReply *) rep);
  458. else if (rep->RepType == X_XIGetClientPointer)
  459. SRepXIGetClientPointer(client, len, (xXIGetClientPointerReply *) rep);
  460. else if (rep->RepType == X_XIQueryVersion)
  461. SRepXIQueryVersion(client, len, (xXIQueryVersionReply *) rep);
  462. else if (rep->RepType == X_XIQueryDevice)
  463. SRepXIQueryDevice(client, len, (xXIQueryDeviceReply *) rep);
  464. else if (rep->RepType == X_XIGrabDevice)
  465. SRepXIGrabDevice(client, len, (xXIGrabDeviceReply *) rep);
  466. else if (rep->RepType == X_XIPassiveGrabDevice)
  467. SRepXIPassiveGrabDevice(client, len, (xXIPassiveGrabDeviceReply *) rep);
  468. else if (rep->RepType == X_XIListProperties)
  469. SRepXIListProperties(client, len, (xXIListPropertiesReply *) rep);
  470. else if (rep->RepType == X_XIGetProperty)
  471. SRepXIGetProperty(client, len, (xXIGetPropertyReply *) rep);
  472. else if (rep->RepType == X_XIGetSelectedEvents)
  473. SRepXIGetSelectedEvents(client, len, (xXIGetSelectedEventsReply *) rep);
  474. else if (rep->RepType == X_XIGetFocus)
  475. SRepXIGetFocus(client, len, (xXIGetFocusReply *) rep);
  476. else {
  477. FatalError("XINPUT confused sending swapped reply");
  478. }
  479. }
  480. /************************************************************************
  481. *
  482. * This function swaps the DeviceValuator event.
  483. *
  484. */
  485. static void
  486. SEventDeviceValuator(deviceValuator * from, deviceValuator * to)
  487. {
  488. int i;
  489. INT32 *ip B32;
  490. *to = *from;
  491. swaps(&to->sequenceNumber);
  492. swaps(&to->device_state);
  493. ip = &to->valuator0;
  494. for (i = 0; i < 6; i++) {
  495. swapl(ip + i);
  496. }
  497. }
  498. static void
  499. SEventFocus(deviceFocus * from, deviceFocus * to)
  500. {
  501. *to = *from;
  502. swaps(&to->sequenceNumber);
  503. swapl(&to->time);
  504. swapl(&to->window);
  505. }
  506. static void
  507. SDeviceStateNotifyEvent(deviceStateNotify * from, deviceStateNotify * to)
  508. {
  509. int i;
  510. INT32 *ip B32;
  511. *to = *from;
  512. swaps(&to->sequenceNumber);
  513. swapl(&to->time);
  514. ip = &to->valuator0;
  515. for (i = 0; i < 3; i++) {
  516. swapl(ip + i);
  517. }
  518. }
  519. static void
  520. SDeviceKeyStateNotifyEvent(deviceKeyStateNotify * from,
  521. deviceKeyStateNotify * to)
  522. {
  523. *to = *from;
  524. swaps(&to->sequenceNumber);
  525. }
  526. static void
  527. SDeviceButtonStateNotifyEvent(deviceButtonStateNotify * from,
  528. deviceButtonStateNotify * to)
  529. {
  530. *to = *from;
  531. swaps(&to->sequenceNumber);
  532. }
  533. static void
  534. SChangeDeviceNotifyEvent(changeDeviceNotify * from, changeDeviceNotify * to)
  535. {
  536. *to = *from;
  537. swaps(&to->sequenceNumber);
  538. swapl(&to->time);
  539. }
  540. static void
  541. SDeviceMappingNotifyEvent(deviceMappingNotify * from, deviceMappingNotify * to)
  542. {
  543. *to = *from;
  544. swaps(&to->sequenceNumber);
  545. swapl(&to->time);
  546. }
  547. static void
  548. SDevicePresenceNotifyEvent(devicePresenceNotify * from,
  549. devicePresenceNotify * to)
  550. {
  551. *to = *from;
  552. swaps(&to->sequenceNumber);
  553. swapl(&to->time);
  554. swaps(&to->control);
  555. }
  556. static void
  557. SDevicePropertyNotifyEvent(devicePropertyNotify * from,
  558. devicePropertyNotify * to)
  559. {
  560. *to = *from;
  561. swaps(&to->sequenceNumber);
  562. swapl(&to->time);
  563. swapl(&to->atom);
  564. }
  565. static void
  566. SDeviceLeaveNotifyEvent(xXILeaveEvent * from, xXILeaveEvent * to)
  567. {
  568. *to = *from;
  569. swaps(&to->sequenceNumber);
  570. swapl(&to->length);
  571. swaps(&to->evtype);
  572. swaps(&to->deviceid);
  573. swapl(&to->time);
  574. swapl(&to->root);
  575. swapl(&to->event);
  576. swapl(&to->child);
  577. swapl(&to->root_x);
  578. swapl(&to->root_y);
  579. swapl(&to->event_x);
  580. swapl(&to->event_y);
  581. swaps(&to->sourceid);
  582. swaps(&to->buttons_len);
  583. swapl(&to->mods.base_mods);
  584. swapl(&to->mods.latched_mods);
  585. swapl(&to->mods.locked_mods);
  586. }
  587. static void
  588. SDeviceChangedEvent(xXIDeviceChangedEvent * from, xXIDeviceChangedEvent * to)
  589. {
  590. int i, j;
  591. xXIAnyInfo *any;
  592. *to = *from;
  593. memcpy(&to[1], &from[1], from->length * 4);
  594. any = (xXIAnyInfo *) &to[1];
  595. for (i = 0; i < to->num_classes; i++) {
  596. int length = any->length;
  597. switch (any->type) {
  598. case KeyClass:
  599. {
  600. xXIKeyInfo *ki = (xXIKeyInfo *) any;
  601. uint32_t *key = (uint32_t *) &ki[1];
  602. for (j = 0; j < ki->num_keycodes; j++, key++)
  603. swapl(key);
  604. swaps(&ki->num_keycodes);
  605. }
  606. break;
  607. case ButtonClass:
  608. {
  609. xXIButtonInfo *bi = (xXIButtonInfo *) any;
  610. Atom *labels = (Atom *) ((char *) bi + sizeof(xXIButtonInfo) +
  611. pad_to_int32(bits_to_bytes
  612. (bi->num_buttons)));
  613. for (j = 0; j < bi->num_buttons; j++)
  614. swapl(&labels[j]);
  615. swaps(&bi->num_buttons);
  616. }
  617. break;
  618. case ValuatorClass:
  619. {
  620. xXIValuatorInfo *ai = (xXIValuatorInfo *) any;
  621. swapl(&ai->label);
  622. swapl(&ai->min.integral);
  623. swapl(&ai->min.frac);
  624. swapl(&ai->max.integral);
  625. swapl(&ai->max.frac);
  626. swapl(&ai->resolution);
  627. swaps(&ai->number);
  628. }
  629. break;
  630. }
  631. swaps(&any->type);
  632. swaps(&any->length);
  633. swaps(&any->sourceid);
  634. any = (xXIAnyInfo *) ((char *) any + length * 4);
  635. }
  636. swaps(&to->sequenceNumber);
  637. swapl(&to->length);
  638. swaps(&to->evtype);
  639. swaps(&to->deviceid);
  640. swapl(&to->time);
  641. swaps(&to->num_classes);
  642. swaps(&to->sourceid);
  643. }
  644. static void
  645. SDeviceEvent(xXIDeviceEvent * from, xXIDeviceEvent * to)
  646. {
  647. int i;
  648. char *ptr;
  649. char *vmask;
  650. memcpy(to, from, sizeof(xEvent) + from->length * 4);
  651. swaps(&to->sequenceNumber);
  652. swapl(&to->length);
  653. swaps(&to->evtype);
  654. swaps(&to->deviceid);
  655. swapl(&to->time);
  656. swapl(&to->detail);
  657. swapl(&to->root);
  658. swapl(&to->event);
  659. swapl(&to->child);
  660. swapl(&to->root_x);
  661. swapl(&to->root_y);
  662. swapl(&to->event_x);
  663. swapl(&to->event_y);
  664. swaps(&to->buttons_len);
  665. swaps(&to->valuators_len);
  666. swaps(&to->sourceid);
  667. swapl(&to->mods.base_mods);
  668. swapl(&to->mods.latched_mods);
  669. swapl(&to->mods.locked_mods);
  670. swapl(&to->mods.effective_mods);
  671. swapl(&to->flags);
  672. ptr = (char *) (&to[1]);
  673. ptr += from->buttons_len * 4;
  674. vmask = ptr; /* valuator mask */
  675. ptr += from->valuators_len * 4;
  676. for (i = 0; i < from->valuators_len * 32; i++) {
  677. if (BitIsOn(vmask, i)) {
  678. swapl(((uint32_t *) ptr));
  679. ptr += 4;
  680. swapl(((uint32_t *) ptr));
  681. ptr += 4;
  682. }
  683. }
  684. }
  685. static void
  686. SDeviceHierarchyEvent(xXIHierarchyEvent * from, xXIHierarchyEvent * to)
  687. {
  688. int i;
  689. xXIHierarchyInfo *info;
  690. *to = *from;
  691. memcpy(&to[1], &from[1], from->length * 4);
  692. swaps(&to->sequenceNumber);
  693. swapl(&to->length);
  694. swaps(&to->evtype);
  695. swaps(&to->deviceid);
  696. swapl(&to->time);
  697. swapl(&to->flags);
  698. swaps(&to->num_info);
  699. info = (xXIHierarchyInfo *) &to[1];
  700. for (i = 0; i < from->num_info; i++) {
  701. swaps(&info->deviceid);
  702. swaps(&info->attachment);
  703. info++;
  704. }
  705. }
  706. static void
  707. SXIPropertyEvent(xXIPropertyEvent * from, xXIPropertyEvent * to)
  708. {
  709. *to = *from;
  710. swaps(&to->sequenceNumber);
  711. swapl(&to->length);
  712. swaps(&to->evtype);
  713. swaps(&to->deviceid);
  714. swapl(&to->property);
  715. }
  716. static void
  717. SRawEvent(xXIRawEvent * from, xXIRawEvent * to)
  718. {
  719. int i;
  720. FP3232 *values;
  721. unsigned char *mask;
  722. memcpy(to, from, sizeof(xEvent) + from->length * 4);
  723. swaps(&to->sequenceNumber);
  724. swapl(&to->length);
  725. swaps(&to->evtype);
  726. swaps(&to->deviceid);
  727. swapl(&to->time);
  728. swapl(&to->detail);
  729. mask = (unsigned char *) &to[1];
  730. values = (FP3232 *) (mask + from->valuators_len * 4);
  731. for (i = 0; i < from->valuators_len * 4 * 8; i++) {
  732. if (BitIsOn(mask, i)) {
  733. /* for each bit set there are two FP3232 values on the wire, in
  734. * the order abcABC for data and data_raw. Here we swap as if
  735. * they were in aAbBcC order because it's easier and really
  736. * doesn't matter.
  737. */
  738. swapl(&values->integral);
  739. swapl(&values->frac);
  740. values++;
  741. swapl(&values->integral);
  742. swapl(&values->frac);
  743. values++;
  744. }
  745. }
  746. swaps(&to->valuators_len);
  747. }
  748. static void
  749. STouchOwnershipEvent(xXITouchOwnershipEvent * from, xXITouchOwnershipEvent * to)
  750. {
  751. *to = *from;
  752. swaps(&to->sequenceNumber);
  753. swapl(&to->length);
  754. swaps(&to->evtype);
  755. swaps(&to->deviceid);
  756. swapl(&to->time);
  757. swaps(&to->sourceid);
  758. swapl(&to->touchid);
  759. swapl(&to->flags);
  760. swapl(&to->root);
  761. swapl(&to->event);
  762. swapl(&to->child);
  763. }
  764. static void
  765. SBarrierEvent(xXIBarrierEvent * from,
  766. xXIBarrierEvent * to) {
  767. *to = *from;
  768. swaps(&to->sequenceNumber);
  769. swapl(&to->length);
  770. swaps(&to->evtype);
  771. swapl(&to->time);
  772. swaps(&to->deviceid);
  773. swaps(&to->sourceid);
  774. swapl(&to->event);
  775. swapl(&to->root);
  776. swapl(&to->root_x);
  777. swapl(&to->root_y);
  778. swapl(&to->dx.integral);
  779. swapl(&to->dx.frac);
  780. swapl(&to->dy.integral);
  781. swapl(&to->dy.frac);
  782. swapl(&to->dtime);
  783. swapl(&to->barrier);
  784. swapl(&to->eventid);
  785. }
  786. /** Event swapping function for XI2 events. */
  787. void
  788. XI2EventSwap(xGenericEvent *from, xGenericEvent *to)
  789. {
  790. switch (from->evtype) {
  791. case XI_Enter:
  792. case XI_Leave:
  793. case XI_FocusIn:
  794. case XI_FocusOut:
  795. SDeviceLeaveNotifyEvent((xXILeaveEvent *) from, (xXILeaveEvent *) to);
  796. break;
  797. case XI_DeviceChanged:
  798. SDeviceChangedEvent((xXIDeviceChangedEvent *) from,
  799. (xXIDeviceChangedEvent *) to);
  800. break;
  801. case XI_HierarchyChanged:
  802. SDeviceHierarchyEvent((xXIHierarchyEvent *) from,
  803. (xXIHierarchyEvent *) to);
  804. break;
  805. case XI_PropertyEvent:
  806. SXIPropertyEvent((xXIPropertyEvent *) from, (xXIPropertyEvent *) to);
  807. break;
  808. case XI_Motion:
  809. case XI_KeyPress:
  810. case XI_KeyRelease:
  811. case XI_ButtonPress:
  812. case XI_ButtonRelease:
  813. case XI_TouchBegin:
  814. case XI_TouchUpdate:
  815. case XI_TouchEnd:
  816. SDeviceEvent((xXIDeviceEvent *) from, (xXIDeviceEvent *) to);
  817. break;
  818. case XI_TouchOwnership:
  819. STouchOwnershipEvent((xXITouchOwnershipEvent *) from,
  820. (xXITouchOwnershipEvent *) to);
  821. break;
  822. case XI_RawMotion:
  823. case XI_RawKeyPress:
  824. case XI_RawKeyRelease:
  825. case XI_RawButtonPress:
  826. case XI_RawButtonRelease:
  827. case XI_RawTouchBegin:
  828. case XI_RawTouchUpdate:
  829. case XI_RawTouchEnd:
  830. SRawEvent((xXIRawEvent *) from, (xXIRawEvent *) to);
  831. break;
  832. case XI_BarrierHit:
  833. case XI_BarrierLeave:
  834. SBarrierEvent((xXIBarrierEvent *) from,
  835. (xXIBarrierEvent *) to);
  836. break;
  837. default:
  838. ErrorF("[Xi] Unknown event type to swap. This is a bug.\n");
  839. break;
  840. }
  841. }
  842. /**************************************************************************
  843. *
  844. * Allow the specified event to have its propagation suppressed.
  845. * The default is to not allow suppression of propagation.
  846. *
  847. */
  848. static void
  849. AllowPropagateSuppress(Mask mask)
  850. {
  851. int i;
  852. for (i = 0; i < MAXDEVICES; i++)
  853. PropagateMask[i] |= mask;
  854. }
  855. /**************************************************************************
  856. *
  857. * Record an event mask where there is no unique corresponding event type.
  858. * We can't call SetMaskForEvent, since that would clobber the existing
  859. * mask for that event. MotionHint and ButtonMotion are examples.
  860. *
  861. * Since extension event types will never be less than 64, we can use
  862. * 0-63 in the EventInfo array as the "type" to be used to look up this
  863. * mask. This means that the corresponding macros such as
  864. * DevicePointerMotionHint must have access to the same constants.
  865. *
  866. */
  867. static void
  868. SetEventInfo(Mask mask, int constant)
  869. {
  870. EventInfo[ExtEventIndex].mask = mask;
  871. EventInfo[ExtEventIndex++].type = constant;
  872. }
  873. /**************************************************************************
  874. *
  875. * Allow the specified event to be restricted to being selected by one
  876. * client at a time.
  877. * The default is to allow more than one client to select the event.
  878. *
  879. */
  880. static void
  881. SetExclusiveAccess(Mask mask)
  882. {
  883. int i;
  884. for (i = 0; i < MAXDEVICES; i++)
  885. ExtExclusiveMasks[i] |= mask;
  886. }
  887. /**************************************************************************
  888. *
  889. * Assign the specified mask to the specified event.
  890. *
  891. */
  892. static void
  893. SetMaskForExtEvent(Mask mask, int event)
  894. {
  895. int i;
  896. EventInfo[ExtEventIndex].mask = mask;
  897. EventInfo[ExtEventIndex++].type = event;
  898. if ((event < LASTEvent) || (event >= 128))
  899. FatalError("MaskForExtensionEvent: bogus event number");
  900. for (i = 0; i < MAXDEVICES; i++)
  901. SetMaskForEvent(i, mask, event);
  902. }
  903. /************************************************************************
  904. *
  905. * This function sets up extension event types and masks.
  906. *
  907. */
  908. static void
  909. FixExtensionEvents(ExtensionEntry * extEntry)
  910. {
  911. DeviceValuator = extEntry->eventBase;
  912. DeviceKeyPress = DeviceValuator + 1;
  913. DeviceKeyRelease = DeviceKeyPress + 1;
  914. DeviceButtonPress = DeviceKeyRelease + 1;
  915. DeviceButtonRelease = DeviceButtonPress + 1;
  916. DeviceMotionNotify = DeviceButtonRelease + 1;
  917. DeviceFocusIn = DeviceMotionNotify + 1;
  918. DeviceFocusOut = DeviceFocusIn + 1;
  919. ProximityIn = DeviceFocusOut + 1;
  920. ProximityOut = ProximityIn + 1;
  921. DeviceStateNotify = ProximityOut + 1;
  922. DeviceMappingNotify = DeviceStateNotify + 1;
  923. ChangeDeviceNotify = DeviceMappingNotify + 1;
  924. DeviceKeyStateNotify = ChangeDeviceNotify + 1;
  925. DeviceButtonStateNotify = DeviceKeyStateNotify + 1;
  926. DevicePresenceNotify = DeviceButtonStateNotify + 1;
  927. DevicePropertyNotify = DevicePresenceNotify + 1;
  928. event_base[KeyClass] = DeviceKeyPress;
  929. event_base[ButtonClass] = DeviceButtonPress;
  930. event_base[ValuatorClass] = DeviceMotionNotify;
  931. event_base[ProximityClass] = ProximityIn;
  932. event_base[FocusClass] = DeviceFocusIn;
  933. event_base[OtherClass] = DeviceStateNotify;
  934. BadDevice += extEntry->errorBase;
  935. BadEvent += extEntry->errorBase;
  936. BadMode += extEntry->errorBase;
  937. DeviceBusy += extEntry->errorBase;
  938. BadClass += extEntry->errorBase;
  939. SetMaskForExtEvent(DeviceKeyPressMask, DeviceKeyPress);
  940. AllowPropagateSuppress(DeviceKeyPressMask);
  941. SetCriticalEvent(DeviceKeyPress);
  942. SetMaskForExtEvent(DeviceKeyReleaseMask, DeviceKeyRelease);
  943. AllowPropagateSuppress(DeviceKeyReleaseMask);
  944. SetCriticalEvent(DeviceKeyRelease);
  945. SetMaskForExtEvent(DeviceButtonPressMask, DeviceButtonPress);
  946. AllowPropagateSuppress(DeviceButtonPressMask);
  947. SetCriticalEvent(DeviceButtonPress);
  948. SetMaskForExtEvent(DeviceButtonReleaseMask, DeviceButtonRelease);
  949. AllowPropagateSuppress(DeviceButtonReleaseMask);
  950. SetCriticalEvent(DeviceButtonRelease);
  951. SetMaskForExtEvent(DeviceProximityMask, ProximityIn);
  952. SetMaskForExtEvent(DeviceProximityMask, ProximityOut);
  953. SetMaskForExtEvent(DeviceStateNotifyMask, DeviceStateNotify);
  954. SetMaskForExtEvent(DevicePointerMotionMask, DeviceMotionNotify);
  955. AllowPropagateSuppress(DevicePointerMotionMask);
  956. SetCriticalEvent(DeviceMotionNotify);
  957. SetEventInfo(DevicePointerMotionHintMask, _devicePointerMotionHint);
  958. SetEventInfo(DeviceButton1MotionMask, _deviceButton1Motion);
  959. SetEventInfo(DeviceButton2MotionMask, _deviceButton2Motion);
  960. SetEventInfo(DeviceButton3MotionMask, _deviceButton3Motion);
  961. SetEventInfo(DeviceButton4MotionMask, _deviceButton4Motion);
  962. SetEventInfo(DeviceButton5MotionMask, _deviceButton5Motion);
  963. SetEventInfo(DeviceButtonMotionMask, _deviceButtonMotion);
  964. SetMaskForExtEvent(DeviceFocusChangeMask, DeviceFocusIn);
  965. SetMaskForExtEvent(DeviceFocusChangeMask, DeviceFocusOut);
  966. SetMaskForExtEvent(DeviceMappingNotifyMask, DeviceMappingNotify);
  967. SetMaskForExtEvent(ChangeDeviceNotifyMask, ChangeDeviceNotify);
  968. SetEventInfo(DeviceButtonGrabMask, _deviceButtonGrab);
  969. SetExclusiveAccess(DeviceButtonGrabMask);
  970. SetEventInfo(DeviceOwnerGrabButtonMask, _deviceOwnerGrabButton);
  971. SetEventInfo(DevicePresenceNotifyMask, _devicePresence);
  972. SetMaskForExtEvent(DevicePropertyNotifyMask, DevicePropertyNotify);
  973. SetEventInfo(0, _noExtensionEvent);
  974. }
  975. /************************************************************************
  976. *
  977. * This function restores extension event types and masks to their
  978. * initial state.
  979. *
  980. */
  981. static void
  982. RestoreExtensionEvents(void)
  983. {
  984. int i, j;
  985. IReqCode = 0;
  986. IEventBase = 0;
  987. for (i = 0; i < ExtEventIndex - 1; i++) {
  988. if ((EventInfo[i].type >= LASTEvent) && (EventInfo[i].type < 128)) {
  989. for (j = 0; j < MAXDEVICES; j++)
  990. SetMaskForEvent(j, 0, EventInfo[i].type);
  991. }
  992. EventInfo[i].mask = 0;
  993. EventInfo[i].type = 0;
  994. }
  995. ExtEventIndex = 0;
  996. DeviceValuator = 0;
  997. DeviceKeyPress = 1;
  998. DeviceKeyRelease = 2;
  999. DeviceButtonPress = 3;
  1000. DeviceButtonRelease = 4;
  1001. DeviceMotionNotify = 5;
  1002. DeviceFocusIn = 6;
  1003. DeviceFocusOut = 7;
  1004. ProximityIn = 8;
  1005. ProximityOut = 9;
  1006. DeviceStateNotify = 10;
  1007. DeviceMappingNotify = 11;
  1008. ChangeDeviceNotify = 12;
  1009. DeviceKeyStateNotify = 13;
  1010. DeviceButtonStateNotify = 13;
  1011. DevicePresenceNotify = 14;
  1012. DevicePropertyNotify = 15;
  1013. BadDevice = 0;
  1014. BadEvent = 1;
  1015. BadMode = 2;
  1016. DeviceBusy = 3;
  1017. BadClass = 4;
  1018. }
  1019. /***********************************************************************
  1020. *
  1021. * IResetProc.
  1022. * Remove reply-swapping routine.
  1023. * Remove event-swapping routine.
  1024. *
  1025. */
  1026. static void
  1027. IResetProc(ExtensionEntry * unused)
  1028. {
  1029. ReplySwapVector[IReqCode] = ReplyNotSwappd;
  1030. EventSwapVector[DeviceValuator] = NotImplemented;
  1031. EventSwapVector[DeviceKeyPress] = NotImplemented;
  1032. EventSwapVector[DeviceKeyRelease] = NotImplemented;
  1033. EventSwapVector[DeviceButtonPress] = NotImplemented;
  1034. EventSwapVector[DeviceButtonRelease] = NotImplemented;
  1035. EventSwapVector[DeviceMotionNotify] = NotImplemented;
  1036. EventSwapVector[DeviceFocusIn] = NotImplemented;
  1037. EventSwapVector[DeviceFocusOut] = NotImplemented;
  1038. EventSwapVector[ProximityIn] = NotImplemented;
  1039. EventSwapVector[ProximityOut] = NotImplemented;
  1040. EventSwapVector[DeviceStateNotify] = NotImplemented;
  1041. EventSwapVector[DeviceKeyStateNotify] = NotImplemented;
  1042. EventSwapVector[DeviceButtonStateNotify] = NotImplemented;
  1043. EventSwapVector[DeviceMappingNotify] = NotImplemented;
  1044. EventSwapVector[ChangeDeviceNotify] = NotImplemented;
  1045. EventSwapVector[DevicePresenceNotify] = NotImplemented;
  1046. EventSwapVector[DevicePropertyNotify] = NotImplemented;
  1047. RestoreExtensionEvents();
  1048. free(xi_all_devices.name);
  1049. free(xi_all_master_devices.name);
  1050. XIBarrierReset();
  1051. }
  1052. /***********************************************************************
  1053. *
  1054. * Assign an id and type to an input device.
  1055. *
  1056. */
  1057. void
  1058. AssignTypeAndName(DeviceIntPtr dev, Atom type, const char *name)
  1059. {
  1060. dev->xinput_type = type;
  1061. dev->name = strdup(name);
  1062. }
  1063. /***********************************************************************
  1064. *
  1065. * Make device type atoms.
  1066. *
  1067. */
  1068. static void
  1069. MakeDeviceTypeAtoms(void)
  1070. {
  1071. int i;
  1072. for (i = 0; i < NUMTYPES; i++)
  1073. dev_type[i].type =
  1074. MakeAtom(dev_type[i].name, strlen(dev_type[i].name), 1);
  1075. }
  1076. /*****************************************************************************
  1077. *
  1078. * SEventIDispatch
  1079. *
  1080. * Swap any events defined in this extension.
  1081. */
  1082. #define DO_SWAP(func,type) func ((type *)from, (type *)to)
  1083. static void
  1084. SEventIDispatch(xEvent *from, xEvent *to)
  1085. {
  1086. int type = from->u.u.type & 0177;
  1087. if (type == DeviceValuator)
  1088. DO_SWAP(SEventDeviceValuator, deviceValuator);
  1089. else if (type == DeviceKeyPress) {
  1090. SKeyButtonPtrEvent(from, to);
  1091. to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
  1092. }
  1093. else if (type == DeviceKeyRelease) {
  1094. SKeyButtonPtrEvent(from, to);
  1095. to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
  1096. }
  1097. else if (type == DeviceButtonPress) {
  1098. SKeyButtonPtrEvent(from, to);
  1099. to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
  1100. }
  1101. else if (type == DeviceButtonRelease) {
  1102. SKeyButtonPtrEvent(from, to);
  1103. to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
  1104. }
  1105. else if (type == DeviceMotionNotify) {
  1106. SKeyButtonPtrEvent(from, to);
  1107. to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
  1108. }
  1109. else if (type == DeviceFocusIn)
  1110. DO_SWAP(SEventFocus, deviceFocus);
  1111. else if (type == DeviceFocusOut)
  1112. DO_SWAP(SEventFocus, deviceFocus);
  1113. else if (type == ProximityIn) {
  1114. SKeyButtonPtrEvent(from, to);
  1115. to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
  1116. }
  1117. else if (type == ProximityOut) {
  1118. SKeyButtonPtrEvent(from, to);
  1119. to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
  1120. }
  1121. else if (type == DeviceStateNotify)
  1122. DO_SWAP(SDeviceStateNotifyEvent, deviceStateNotify);
  1123. else if (type == DeviceKeyStateNotify)
  1124. DO_SWAP(SDeviceKeyStateNotifyEvent, deviceKeyStateNotify);
  1125. else if (type == DeviceButtonStateNotify)
  1126. DO_SWAP(SDeviceButtonStateNotifyEvent, deviceButtonStateNotify);
  1127. else if (type == DeviceMappingNotify)
  1128. DO_SWAP(SDeviceMappingNotifyEvent, deviceMappingNotify);
  1129. else if (type == ChangeDeviceNotify)
  1130. DO_SWAP(SChangeDeviceNotifyEvent, changeDeviceNotify);
  1131. else if (type == DevicePresenceNotify)
  1132. DO_SWAP(SDevicePresenceNotifyEvent, devicePresenceNotify);
  1133. else if (type == DevicePropertyNotify)
  1134. DO_SWAP(SDevicePropertyNotifyEvent, devicePropertyNotify);
  1135. else {
  1136. FatalError("XInputExtension: Impossible event!\n");
  1137. }
  1138. }
  1139. /**********************************************************************
  1140. *
  1141. * IExtensionInit - initialize the input extension.
  1142. *
  1143. * Called from InitExtensions in main() or from QueryExtension() if the
  1144. * extension is dynamically loaded.
  1145. *
  1146. * This extension has several events and errors.
  1147. *
  1148. * XI is mandatory nowadays, so if we fail to init XI, we die.
  1149. */
  1150. void
  1151. XInputExtensionInit(void)
  1152. {
  1153. ExtensionEntry *extEntry;
  1154. XExtensionVersion thisversion = { XI_Present,
  1155. SERVER_XI_MAJOR_VERSION,
  1156. SERVER_XI_MINOR_VERSION,
  1157. };
  1158. if (!dixRegisterPrivateKey
  1159. (&XIClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(XIClientRec)))
  1160. FatalError("Cannot request private for XI.\n");
  1161. if (!AddCallback(&ClientStateCallback, XIClientCallback, 0))
  1162. FatalError("Failed to add callback to XI.\n");
  1163. if (!XIBarrierInit())
  1164. FatalError("Could not initialize barriers.\n");
  1165. extEntry = AddExtension(INAME, IEVENTS, IERRORS, ProcIDispatch,
  1166. SProcIDispatch, IResetProc, StandardMinorOpcode);
  1167. if (extEntry) {
  1168. IReqCode = extEntry->base;
  1169. IEventBase = extEntry->eventBase;
  1170. XIVersion = thisversion;
  1171. MakeDeviceTypeAtoms();
  1172. RT_INPUTCLIENT = CreateNewResourceType((DeleteType) InputClientGone,
  1173. "INPUTCLIENT");
  1174. if (!RT_INPUTCLIENT)
  1175. FatalError("Failed to add resource type for XI.\n");
  1176. FixExtensionEvents(extEntry);
  1177. ReplySwapVector[IReqCode] = (ReplySwapPtr) SReplyIDispatch;
  1178. EventSwapVector[DeviceValuator] = SEventIDispatch;
  1179. EventSwapVector[DeviceKeyPress] = SEventIDispatch;
  1180. EventSwapVector[DeviceKeyRelease] = SEventIDispatch;
  1181. EventSwapVector[DeviceButtonPress] = SEventIDispatch;
  1182. EventSwapVector[DeviceButtonRelease] = SEventIDispatch;
  1183. EventSwapVector[DeviceMotionNotify] = SEventIDispatch;
  1184. EventSwapVector[DeviceFocusIn] = SEventIDispatch;
  1185. EventSwapVector[DeviceFocusOut] = SEventIDispatch;
  1186. EventSwapVector[ProximityIn] = SEventIDispatch;
  1187. EventSwapVector[ProximityOut] = SEventIDispatch;
  1188. EventSwapVector[DeviceStateNotify] = SEventIDispatch;
  1189. EventSwapVector[DeviceKeyStateNotify] = SEventIDispatch;
  1190. EventSwapVector[DeviceButtonStateNotify] = SEventIDispatch;
  1191. EventSwapVector[DeviceMappingNotify] = SEventIDispatch;
  1192. EventSwapVector[ChangeDeviceNotify] = SEventIDispatch;
  1193. EventSwapVector[DevicePresenceNotify] = SEventIDispatch;
  1194. GERegisterExtension(IReqCode, XI2EventSwap);
  1195. memset(&xi_all_devices, 0, sizeof(xi_all_devices));
  1196. memset(&xi_all_master_devices, 0, sizeof(xi_all_master_devices));
  1197. xi_all_devices.id = XIAllDevices;
  1198. xi_all_devices.name = strdup("XIAllDevices");
  1199. xi_all_master_devices.id = XIAllMasterDevices;
  1200. xi_all_master_devices.name = strdup("XIAllMasterDevices");
  1201. inputInfo.all_devices = &xi_all_devices;
  1202. inputInfo.all_master_devices = &xi_all_master_devices;
  1203. XIResetProperties();
  1204. }
  1205. else {
  1206. FatalError("IExtensionInit: AddExtensions failed\n");
  1207. }
  1208. }