Xext: geext: simplify dispatcher
[xserver.git] / doc / Xinput.xml
blob0e7fbda722f1cb71658fc8b7730f4e93ca79c50e
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3                    "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"[
4  <!ENTITY % defs SYSTEM "/xserver/doc/xml/xserver.ent"> %defs;
5 ]>
7 <!-- lifted from troff+ms+XMan by doclifter -->
8 <book id="porting">
10 <bookinfo>
11    <title>X11 Input Extension Porting Document</title>
12    <authorgroup>
13       <author>
14          <firstname>George</firstname><surname>Sachs</surname>
15          <affiliation><orgname>Hewlett-Packard</orgname></affiliation>
16       </author>
17    </authorgroup>
18    <releaseinfo>X Server Version &xserver.version;</releaseinfo>
19    <copyright><year>1989</year><year>1990</year><year>1991</year>
20      <holder>Hewlett-Packard Company</holder>
21    </copyright>
23 <legalnotice>
26 <para>
27 Permission to use, copy, modify, and distribute this documentation for any purpose and without fee is
28 hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
29 Hewlett-Packard makes no representations about the suitability for any purpose of the information in this
30 document. It is provided "as is" without express or implied warranty. This document is only a draft stan-
31 dard of the X Consortium and is therefore subject to change.
32 </para>
33 </legalnotice>
35 <legalnotice>
36 <para role="multiLicensing">Copyright © 1989, 1990, 1991 X Consortium</para>
37 <para>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &ldquo;Software&rdquo;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</para>
38 <para>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</para>
40 <para>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</para>
42 <para>Except as contained in this notice, the name of the X Consortium shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the X Consortium.</para>
44 <para>X Window System is a trademark of The Open Group.</para>
45 </legalnotice>
47 </bookinfo>
49 <chapter id="x11_input_extension_porting_document">
50 <title>X11 Input Extension Porting Document</title>
52 <para>
53 This document is intended to aid the process of integrating the 
54 X11 Input Extension into an X server.
55 </para>
56 <para>
57 <!-- .LP -->
58 Most of the functionality provided by the input extension is 
59 device- and implementation-independent, and should require no changes.  
60 The functionality is implemented by
61 routines that typically reside in the server source tree directory 
62 extensions/server/xinput.
63 This extension includes functions to enable and disable input extension devices,
64 select input, grab and focus those devices, query and change key
65 and button mappings, and others.  The only input extension requirements 
66 for the device-dependent part of X are that the input devices be 
67 correctly initialized and input events from those devices be correctly
68 generated.  Device-dependent X is responsible for reading input data from 
69 the input device hardware and if necessary, reformatting it into X events.
70 </para>
71 <para>
72 <!-- .LP -->
73 The process of initializing input extension devices is similar to that used 
74 for the core devices, and is described in the following sections.  When
75 multiple input devices are attached to X server, the choice of which devices
76 to initially use as the core X pointer and keyboard is left 
77 implementation-dependent.  It is also up to each implementation to decide
78 whether all input devices will be opened by the server during its 
79 initialization and kept open for the life of the server.  The alternative is
80 to open only the X keyboard and X pointer during server initialization, and
81 open other input devices only when requested by a client to do so.  Either
82 type of implementation is supported by the input extension.
83 </para>
84 <para>
85 <!-- .LP -->
86 Input extension events generated by the X server use the same 32-byte xEvent
87 wire event as do core input events.  However, additional information must be
88 sent for input extension devices, requiring that multiple xEvents be generated
89 each time data is received from an input extension device.  These xEvents are
90 combined into a single client XEvent by the input extension library.  A later
91 section of this document describes the format and generation of input extension
92 events.
93 </para>
94 <sect1 id="Initializing_Extension_Devices">
95 <title>Initializing Extension Devices</title>
96 <para>
97 <!-- .LP -->
98 Extension input devices are initialized in the same manner as the core 
99 X input devices.  Device-Independent X provides functions that can be 
100 called from DDX to initialize these devices.  Which functions are called
101 and when will vary by implementation, and will depend on whether the 
102 implementation opens all the input devices available to X when X is initialized,
103 or waits until a client requests that a device be opened.
104 In the simplest case, DDX will open all input devices as part of its
105 initialization, when the InitInput routine is called.
106 </para>
107 <sect2 id="Summary_of_Calling_Sequence">
108 <title>Summary of Calling Sequence</title>
109 <para>
110 <!-- .LP -->
111 <literallayout class="monospaced">
112 Device-Independent X       |  Device-Dependent X
113 --------------------       |  -------------------             
114                            |                                        
115 InitInput --------------&gt;  |  - do device-specific initialization
116                            |                                        
117                            |  - call AddInputDevice  (deviceProc,AutoStart)
118 AddInputDevice             |   
119   - creates DeviceIntRec   |
120   - records deviceProc     |
121   - adds new device to     | 
122     list of off_devices.   |
123 sets dev-&gt;startup=AutoStart|           
124                            |  - call one of:                       
125                            |    - RegisterPointerDevice (X pointer)
126                            |      - processInputProc = ProcessPointerEvents
127                            |    - RegisterKeyboardDevice (X keyboard)
128                            |      - processInputProc = ProcessKeyboardEvents
129                            |    - RegisterOtherDevice  (extension device)
130                            |      - processInputProc = ProcessOtherEvents
131                            |                                        
132                            |                                        
133 InitAndStartDevices -----&gt; |  - calls deviceProc with parameters
134                            |    (DEVICE_INIT, AutoStart)
135 sets dev-&gt;inited = return  |
136   value from deviceProc    |    
137                            |                                        
138                            |  - in deviceProc, do one of:                       
139                            |    - call InitPointerDeviceStruct (X pointer)
140                            |    - call InitKeyboardDeviceStruct (X keybd)
141                            |    - init extension device by calling some of:
142                            |      - InitKeyClassDeviceStruct
143                            |      - InitButtonClassDeviceStruct
144                            |      - InitValuatorClassDeviceStruct
145                            |      - InitValuatorAxisStruct
146                            |      - InitFocusClassDeviceStruct
147                            |      - InitProximityClassDeviceStruct
148                            |      - InitKbdFeedbackClassDeviceStruct
149                            |      - InitPtrFeedbackClassDeviceStruct
150                            |      - InitLedFeedbackClassDeviceStruct
151                            |      - InitStringFeedbackClassDeviceStruct
152                            |      - InitIntegerFeedbackClassDeviceStruct
153                            |      - InitBellFeedbackClassDeviceStruct
154                            |    - init device name and type by:
155                            |      - calling MakeAtom with one of the 
156                            |        predefined names
157                            |      - calling AssignTypeAndName
158                            |                                        
159                            |                                        
160 for each device added      |                                        
161     by AddInputDevice,     |                                        
162     InitAndStartDevices    |                                        
163     calls EnableDevice if  |  - EnableDevice calls deviceProc with 
164     dev-&gt;startup &amp;         |    (DEVICE_ON, AutoStart)
165     dev-&gt;inited            |  
166                            |                                        
167 If deviceProc returns      |  - core devices are now enabled, extension
168     Success, EnableDevice  |    devices are now available to be accessed
169     move the device from   |    through the input extension protocol
170     inputInfo.off_devices  |    requests.                           
171     to inputInfo.devices   |                                        
172 </literallayout>
173 </para>
174 </sect2>
175 <sect2 id="Initialization_Called_From_InitInput">
176 <title>Initialization Called From InitInput</title>
177 <para>
178 <!-- .LP -->
179 InitInput is the first DDX input entry point called during X server startup.
180 This routine is responsible for
181 device- and implementation- specific initialization, and for calling
182 AddInputDevice to create and initialize the DeviceIntRec structure for each
183 input device.  AddInputDevice is passed the address of a procedure to be called
184 by the DIX routine InitAndStartDevices when input devices are enabled.
185 This procedure is expected to perform X initialization for the input device.
186 </para>
187 <para>
188 <!-- .LP -->
189 If the device is to be used as the X pointer, DDX should then call
190 RegisterPointerDevice, passing the DeviceIntRec pointer,
191 to initialize the device as the X pointer.
192 </para>
193 <para>
194 <!-- .LP -->
195 If the device is to be used as the X keyboard, DDX should instead call
196 RegisterKeyboardDevice to initialize the device as the X keyboard.
197 </para>
198 <para>
199 <!-- .LP -->
200 If the device is to be used as an extension device, DDX should instead
201 call RegisterOtherDevice, passing the DeviceIntPtr returned by
202 AddInputDevice.
203 </para>
204 <para>
205 <!-- .LP -->
206 A sample InitInput implementation is shown below.
207 </para>
208 <para>
209 <!-- .LP -->
210 <literallayout class="monospaced">
211 InitInput(argc,argv)
212     {
213     int i, numdevs;
214     DeviceIntPtr dev;
215     LocalDevice localdevs[LOCAL_MAX_DEVS];
216     DeviceProc kbdproc, ptrproc, extproc;
218     /**************************************************************
219      * Open the appropriate input devices, determine which are 
220      * available, and choose an X pointer and X keyboard device
221      * in some implementation-dependent manner.
222      ***************************************************************/
224     open_input_devices (&amp;numdevs, localdevs);
226     /**************************************************************
227      * Register the input devices with DIX.
228      ***************************************************************/
230     for (i=0; i&lt;numdevs; i++)
231         {
232         if (localdevs[i].use == IsXKeyboard)
233             {
234             dev = AddInputDevice (kbdproc, TRUE);
235             RegisterKeyboardDevice (dev);
236             }
237         else if (localdevs[i].use == IsXPointer)
238             {
239             dev = AddInputDevice (ptrproc, TRUE);
240             RegisterPointerDevice (dev);
241             }
242         else 
243             {
244             dev = AddInputDevice (extproc, FALSE);
245             RegisterOtherDevice (dev);
246             }
247         if (dev == NULL)
248             FatalError ("Too many input devices.");
249         dev-&gt;devicePrivate = (pointer) &amp;localdevs[i];
250         }
251 </literallayout>
252 </para>
253 </sect2>
254 <sect2 id="Initialization_Called_From_InitAndStartDevices">
255 <title>Initialization Called From InitAndStartDevices</title>
256 <para>
257 <!-- .LP -->
258 After InitInput has returned,
259 InitAndStartDevices is the DIX routine that is called to enable input devices. 
260 It calls the device control routine that was passed to AddInputDevice,
261 with a mode value of DEVICE_INIT.  The action taken by the device control
262 routine depends on how the device is to be used.  If the device is to be
263 the X pointer, the device control routine should call
264 InitPointerDeviceStruct to initialize it.  If the device is to be the
265 X keyboard, the device control routine should call
266 InitKeyboardDeviceStruct.  Since input extension devices may support various
267 combinations of keys, buttons, valuators, and feedbacks,
268 each class of input that it supports must be initialized.
269 Entry points are defined by DIX to initialize each of the supported classes of
270 input, and are described in the following sections.
271 </para>
272 <para>
273 <!-- .LP -->
274 A sample device control routine called from InitAndStartDevices is 
275 shown below.
276 </para>
277 <para>
278 <!-- .LP -->
279 <literallayout class="monospaced">
280 Bool extproc (dev, mode)
281     DeviceIntPtr dev;
282     int mode;
283     {
284     LocalDevice *localdev = (LocalDevice *) dev-&gt;devicePrivate;
286     switch (mode)
287         {
288         case DEVICE_INIT:
289             if (strcmp(localdev-&gt;name, XI_TABLET) == 0)
290                 {
291                 /****************************************************
292                  * This device reports proximity, has buttons,
293                  * reports two axes of motion, and can be focused.
294                  * It also supports the same feedbacks as the X pointer
295                  * (acceleration and threshold can be set).
296                  ****************************************************/
298                 InitButtonClassDeviceStruct (dev, button_count, button_map);
299                 InitValuatorClassDeviceStruct (dev, localdev-&gt;n_axes,);
300                     motionproc, MOTION_BUF_SIZE, Absolute);
301                 for (i=0; i&lt;localdev-&gt;n_axes; i++)
302                     InitValuatorAxisStruct (dev, i, min_val, max_val, 
303                         resolution);
304                 InitFocusClassDeviceStruct (dev);
305                 InitProximityClassDeviceStruct (dev);
306                 InitPtrFeedbackClassDeviceStruct (dev, p_controlproc);
307                 }
308             else if (strcmp(localdev-&gt;name, XI_BUTTONBOX) == 0)
309                 {
310                 /****************************************************
311                  * This device has keys and LEDs, and can be focused.
312                  ****************************************************/
314                 InitKeyClassDeviceStruct (dev, syms, modmap);
315                 InitFocusClassDeviceStruct (dev);
316                 InitLedFeedbackClassDeviceStruct (dev, ledcontrol);
317                 }
318             else if (strcmp(localdev-&gt;name, XI_KNOBBOX) == 0)
319                 {
320                 /****************************************************
321                  * This device reports motion.
322                  * It can be focused.
323                  ****************************************************/
325                 InitValuatorClassDeviceStruct (dev, localdev-&gt;n_axes,);
326                     motionproc, MOTION_BUF_SIZE, Absolute);
327                 for (i=0; i&lt;localdev-&gt;n_axes; i++)
328                     InitValuatorAxisStruct (dev, i, min_val, max_val, 
329                         resolution);
330                 InitFocusClassDeviceStruct (dev);
331                 }
332             localdev-&gt;atom = 
333                 MakeAtom(localdev-&gt;name, strlen(localdev-&gt;name), FALSE);
334             AssignTypeAndName (dev, localdev-&gt;atom, localdev-&gt;name);
335             break;
336         case DEVICE_ON:
337             AddEnabledDevice (localdev-&gt;file_ds);
338             dev-&gt;on = TRUE;
339             break;
340         case DEVICE_OFF:
341             dev-&gt;on = FALSE;
342             RemoveEnabledDevice (localdev-&gt;file_ds);
343             break;
344         case DEVICE_CLOSE:
345             break;
346         }
347     }
348 </literallayout>
349 </para>
350 <para>
351 <!-- .LP -->
352 The device control routine is called with a mode value of DEVICE_ON
353 by the DIX routine EnableDevice, which is called from InitAndStartDevices.  
354 When called with this mode, it should call AddEnabledDevice to cause the 
355 server to begin checking for available input from this device.
356 </para>
357 <para>
358 <!-- .LP -->
359 From InitAndStartDevices, EnableDevice is called for all devices that have
360 the "inited" and "startup" fields in the DeviceIntRec set to TRUE.  The
361 "inited" field is set by InitAndStartDevices to the value returned by
362 the deviceproc when called with a mode value of DEVICE_INIT.  The "startup"
363 field is set by AddInputDevice to value of the second parameter (autoStart).
364 </para>
365 <para>
366 <!-- .LP -->
367 When the server is first initialized, it should only be checking for input
368 from the core X keyboard and pointer.  One way to accomplish this is to
369 call AddInputDevice for the core X keyboard and pointer with an
370 autoStart value equal to TRUE, while calling AddInputDevice for 
371 input extension devices with an autoStart value equal to FALSE.  If this is 
372 done, EnableDevice will skip all input extension devices during server
373 initialization.  In this case,
374 the OpenInputDevice routine should set the "startup" field to TRUE
375 when called for input extension devices.  This will cause ProcXOpenInputDevice
376 to call EnableDevice for those devices when a client first does an
377 XOpenDevice request.
378 </para>
379 </sect2>
380 <sect2 id="DIX_Input_Class_Initialization_Routines">
381 <title>DIX Input Class Initialization Routines</title>
382 <para>
383 <!-- .LP -->
384 DIX routines are defined to initialize each of the defined input classes.
385 The defined classes are:
386 <!-- .RS -->
387 <!-- .in +5n -->
388 </para>
389 <itemizedlist>
390   <listitem>
391     <para>
392 KeyClass - the device has keys.
393     </para>
394   </listitem>
395   <listitem>
396     <para>
397 ButtonClass - the device has buttons.
398     </para>
399   </listitem>
400   <listitem>
401     <para>
402 ValuatorClass - the device reports motion data or positional data.
403     </para>
404   </listitem>
405   <listitem>
406     <para>
407 Proximitylass - the device reports proximity information.
408     </para>
409   </listitem>
410   <listitem>
411     <para>
412 FocusClass - the device can be focused.
413     </para>
414   </listitem>
415   <listitem>
416     <para>
417 FeedbackClass - the device supports some kind of feedback.
418 <!-- .in -5n -->
419 <!-- .RE -->
420     </para>
421   </listitem>
422 </itemizedlist>
423 <para>
424 <!-- .LP -->
425 DIX routines are provided to initialize the X pointer and keyboard, as in
426 previous releases of X.  During X initialization, InitPointerDeviceStruct 
427 is called to initialize the X pointer, and InitKeyboardDeviceStruct is
428 called to initialize the X keyboard.  There is no
429 corresponding routine for extension input devices, since they do not all
430 support the same classes of input.  Instead, DDX is responsible for the 
431 initialization of the input classes supported by extension devices.  
432 A description of the routines provided by DIX to perform that initialization
433 follows.
434 </para>
435 <sect3 id="InitKeyClassDeviceStruct">
436 <title>InitKeyClassDeviceStruct</title>
437 <para>
438 <!-- .LP -->
439 This function is provided to allocate and initialize a KeyClassRec, and 
440 should be called for extension devices that have keys.  It is passed a pointer
441 to the device, and pointers to arrays of keysyms and modifiers reported by
442 the device.  It returns FALSE if the KeyClassRec could not be allocated,
443 or if the maps for the keysyms and modifiers could not be allocated.
444 Its parameters are:
445 </para>
446 <para>
447 <!-- .LP -->
448 <literallayout class="monospaced">
449 Bool
450 InitKeyClassDeviceStruct(dev, pKeySyms, pModifiers)
451     DeviceIntPtr dev;
452     KeySymsPtr pKeySyms;
453     CARD8 pModifiers[];
454 </literallayout>
455 </para>
456 <para>
457 <!-- .LP -->
458 The DIX entry point InitKeyboardDeviceStruct calls this routine for the
459 core X keyboard.  It must be called explicitly for extension devices
460 that have keys.
461 </para>
462 </sect3>
463 <sect3 id="InitButtonClassDeviceStruct">
464 <title>InitButtonClassDeviceStruct</title>
465 <para>
466 <!-- .LP -->
467 This function is provided to allocate and initialize a ButtonClassRec, and 
468 should be called for extension devices that have buttons.  It is passed a 
469 pointer to the device, the number of buttons supported, and a map of the 
470 reported button codes.  It returns FALSE if the ButtonClassRec could not be 
471 allocated.  Its parameters are:
472 </para>
473 <para>
474 <!-- .LP -->
475 <literallayout class="monospaced">
476 Bool
477 InitButtonClassDeviceStruct(dev, numButtons, map)
478     register DeviceIntPtr dev;
479     int numButtons;
480     CARD8 *map;
481 </literallayout>
482 </para>
483 <para>
484 <!-- .LP -->
485 The DIX entry point InitPointerDeviceStruct calls this routine for the
486 core X pointer.  It must be called explicitly for extension devices that
487 have buttons.
488 </para>
489 </sect3>
490 <sect3 id="InitValuatorClassDeviceStruct">
491 <title>InitValuatorClassDeviceStruct</title>
492 <para>
493 <!-- .LP -->
494 This function is provided to allocate and initialize a ValuatorClassRec, and 
495 should be called for extension devices that have valuators.  It is passed the
496 number of axes of motion reported by the device, the address of the motion
497 history procedure for the device, the size of the motion history buffer,
498 and the mode (Absolute or Relative) of the device.  It returns FALSE if 
499 the ValuatorClassRec could not be allocated.  Its parameters are:
500 </para>
501 <para>
502 <!-- .LP -->
503 <literallayout class="monospaced">
504 Bool
505 InitValuatorClassDeviceStruct(dev, numAxes, motionProc, numMotionEvents, mode)
506     DeviceIntPtr dev;
507     int (*motionProc)();
508     int numAxes;
509     int numMotionEvents;
510     int mode;
511 </literallayout>
512 </para>
513 <para>
514 <!-- .LP -->
515 The DIX entry point InitPointerDeviceStruct calls this routine for the
516 core X pointer.  It must be called explicitly for extension devices that
517 report motion.
518 </para>
519 </sect3>
520 <sect3 id="InitValuatorAxisStruct">
521 <title>InitValuatorAxisStruct</title>
522 <para>
523 <!-- .LP -->
524 This function is provided to initialize an XAxisInfoRec, and 
525 should be called for core and extension devices that have valuators.  
526 The space for the XAxisInfoRec is allocated by 
527 the InitValuatorClassDeviceStruct function, but is not initialized.
528 </para>
529 <para>
530 <!-- .LP -->
531 InitValuatorAxisStruct should be called once for each axis of motion 
532 reported by the device.  Each
533 invocation should be passed the axis number (starting with 0), the
534 minimum value for that axis, the maximum value for that axis, and the
535 resolution of the device in counts per meter.  If the device reports
536 relative motion, 0 should be reported as the minimum and maximum values.
537 InitValuatorAxisStruct has the following parameters:
538 <literallayout class="monospaced">
539 InitValuatorAxisStruct(dev, axnum, minval, maxval, resolution)
540     DeviceIntPtr dev;
541     int axnum;
542     int minval;
543     int maxval;
544     int resolution;
545 </literallayout>
546 </para>
547 <para>
548 <!-- .LP -->
549 This routine is not called by InitPointerDeviceStruct for the
550 core X pointer.  It must be called explicitly for core and extension devices 
551 that report motion.
552 </para>
553 </sect3>
554 <sect3 id="InitFocusClassDeviceStruct">
555 <title>InitFocusClassDeviceStruct</title>
556 <para>
557 <!-- .LP -->
558 This function is provided to allocate and initialize a FocusClassRec, and 
559 should be called for extension devices that can be focused.  It is passed a
560 pointer to the device, and returns FALSE if the allocation fails.
561 It has the following parameter:
562 <literallayout class="monospaced">
563 Bool
564 InitFocusClassDeviceStruct(dev)
565     DeviceIntPtr dev;
566 </literallayout>
567 </para>
568 <para>
569 <!-- .LP -->
570 The DIX entry point InitKeyboardDeviceStruct calls this routine for the
571 core X keyboard.  It must be called explicitly for extension devices
572 that can be focused.  Whether or not a particular device can be focused
573 is left implementation-dependent.
574 </para>
575 </sect3>
576 <sect3 id="InitProximityClassDeviceStruct">
577 <title>InitProximityClassDeviceStruct</title>
578 <para>
579 <!-- .LP -->
580 This function is provided to allocate and initialize a ProximityClassRec, and 
581 should be called for extension absolute pointing devices that report proximity.
582 It is passed a pointer to the device, and returns FALSE if the allocation fails.
583 It has the following parameter:
584 <literallayout class="monospaced">
585 Bool
586 InitProximityClassDeviceStruct(dev)
587     DeviceIntPtr dev;
588 </literallayout>
589 </para>
590 </sect3>
591 <sect3 id="Initializing_Feedbacks">
592 <title>Initializing Feedbacks</title>
593 <para>
594 <!-- .LP -->
595 </para>
596 <sect4 id="InitKbdFeedbackClassDeviceStruct">
597 <title>InitKbdFeedbackClassDeviceStruct</title>
598 <para>
599 <!-- .LP -->
600 This function is provided to allocate and initialize a KbdFeedbackClassRec, and 
601 may be called for extension devices that support some or all of the 
602 feedbacks that the core keyboard supports.  It is passed a
603 pointer to the device, a pointer to the procedure that sounds the bell,
604 and a pointer to the device control procedure.
605 It returns FALSE if the allocation fails, and has the following parameters:
606 <literallayout class="monospaced">
607 Bool
608 InitKbdFeedbackClassDeviceStruct(dev, bellProc, controlProc)
609     DeviceIntPtr dev;
610     void (*bellProc)();
611     void (*controlProc)();
612 </literallayout>
613 The DIX entry point InitKeyboardDeviceStruct calls this routine for the
614 core X keyboard.  It must be called explicitly for extension devices
615 that have the same feedbacks as a keyboard.  Some feedbacks, such as LEDs and
616 bell, can be supported either with a KbdFeedbackClass or with BellFeedbackClass
617 and LedFeedbackClass feedbacks.
618 </para>
619 </sect4>
620 <sect4 id="InitPtrFeedbackClassDeviceStruct">
621 <title>InitPtrFeedbackClassDeviceStruct</title>
622 <para>
623 <!-- .LP -->
624 This function is provided to allocate and initialize a PtrFeedbackClassRec, and 
625 should be called for extension devices that allow the setting of acceleration
626 and threshold.  It is passed a pointer to the device,
627 and a pointer to the device control procedure.
628 It returns FALSE if the allocation fails, and has the following parameters:
629 <literallayout class="monospaced">
630 Bool
631 InitPtrFeedbackClassDeviceStruct(dev, controlProc)
632     DeviceIntPtr dev;
633     void (*controlProc)();
634 </literallayout>
635 </para>
636 <para>
637 <!-- .LP -->
638 The DIX entry point InitPointerDeviceStruct calls this routine for the
639 core X pointer.  It must be called explicitly for extension devices
640 that support the setting of acceleration and threshold.
641 </para>
642 </sect4>
643 <sect4 id="InitLedFeedbackClassDeviceStruct">
644 <title>InitLedFeedbackClassDeviceStruct</title>
645 <para>
646 <!-- .LP -->
647 This function is provided to allocate and initialize a LedFeedbackClassRec, and 
648 should be called for extension devices that have LEDs.
649 It is passed a pointer to the device,
650 and a pointer to the device control procedure.
651 It returns FALSE if the allocation fails, and has the following parameters:
652 <literallayout class="monospaced">
653 Bool
654 InitLedFeedbackClassDeviceStruct(dev, controlProc)
655     DeviceIntPtr dev;
656     void (*controlProc)();
657 </literallayout>
658 </para>
659 <para>
660 <!-- .LP -->
661 Up to 32 LEDs per feedback can be supported, and a device may have 
662 multiple feedbacks of the same type.
663 </para>
664 </sect4>
665 <sect4 id="InitBellFeedbackClassDeviceStruct">
666 <title>InitBellFeedbackClassDeviceStruct</title>
667 <para>
668 <!-- .LP -->
669 This function is provided to allocate and initialize a BellFeedbackClassRec, 
670 and should be called for extension devices that have a bell.
671 It is passed a pointer to the device,
672 and a pointer to the device control procedure.
673 It returns FALSE if the allocation fails, and has the following parameters:
674 <literallayout class="monospaced">
675 Bool
676 InitBellFeedbackClassDeviceStruct(dev, bellProc, controlProc)
677     DeviceIntPtr dev;
678     void (*bellProc)();
679     void (*controlProc)();
680 </literallayout>
681 </para>
682 </sect4>
683 <sect4 id="InitStringFeedbackClassDeviceStruct">
684 <title>InitStringFeedbackClassDeviceStruct</title>
685 <para>
686 <!-- .LP -->
687 This function is provided to allocate and initialize a StringFeedbackClassRec, 
688 and should be called for extension devices that have a display upon which a 
689 string can be displayed.
690 It is passed a pointer to the device,
691 and a pointer to the device control procedure.
692 It returns FALSE if the allocation fails, and has the following parameters:
693 <literallayout class="monospaced">
694 Bool
695 InitStringFeedbackClassDeviceStruct(dev, controlProc, max_symbols, 
696         num_symbols_supported, symbols)
697     DeviceIntPtr dev;
698     void (*controlProc)();
699     int max_symbols;
700     int num_symbols_supported;
701     KeySym *symbols;
702 </literallayout>
703 </para>
704 </sect4>
705 <sect4 id="InitIntegerFeedbackClassDeviceStruct">
706 <title>InitIntegerFeedbackClassDeviceStruct</title>
707 <para>
708 <!-- .LP -->
709 This function is provided to allocate and initialize an 
710 IntegerFeedbackClassRec, 
711 and should be called for extension devices that have a display upon which an
712 integer can be displayed.
713 It is passed a pointer to the device,
714 and a pointer to the device control procedure.
715 It returns FALSE if the allocation fails, and has the following parameters:
716 <literallayout class="monospaced">
717 Bool
718 InitIntegerFeedbackClassDeviceStruct(dev, controlProc)
719     DeviceIntPtr dev;
720     void (*controlProc)();
721 </literallayout>
722 </para>
723 </sect4>
724 </sect3>
725 </sect2>
726 <sect2 id="Initializing_The_Device_Name_And_Type">
727 <title>Initializing The Device Name And Type</title>
728 <para>
729 <!-- .LP -->
730 The device name and type can be initialized by calling AssignTypeAndName
731 with the following parameters:
732 <literallayout class="monospaced">
733 void
734 AssignTypeAndName(dev, type, name)
735     DeviceIntPtr dev;
736     Atom type;
737     char *name;
738 </literallayout>
739 </para>
740 <para>
741 <!-- .LP -->
742 This will allocate space for the device name and copy the name that was passed.
743 The device type can be obtained by calling MakeAtom with one of the names
744 defined for input devices.  MakeAtom has the following parameters:
745 <literallayout class="monospaced">
746 Atom
747 MakeAtom(name, len, makeit)
748     char *name;
749     int len;
750     Bool makeit;
751 </literallayout>
752 </para>
753 <para>
754 <!-- .LP -->
755 Since the atom was already made when the input extension was initialized, the
756 value of makeit should be FALSE;
757 </para>
758 </sect2>
759 </sect1>
760 <sect1 id="Closing_Extension_Devices">
761 <title>Closing Extension Devices</title>
762 <para>
763 <!-- .LP -->
764 The DisableDevice entry point is provided by DIX to disable input devices.
765 It calls the device control routine for the specified
766 device with a mode value of DEVICE_OFF.  The device control routine should
767 call RemoveEnabledDevice to stop the server from checking for input from
768 that device.
769 </para>
770 <para>
771 <!-- .LP -->
772 DisableDevice is not called by any input extension routines.  It can be 
773 called from the CloseInputDevice routine, which is called by
774 ProcXCloseDevice when a client makes an XCloseDevice request.  If
775 DisableDevice is called, it should only be called when the last client
776 using the extension device has terminated or called XCloseDevice.
777 </para>
778 </sect1>
779 <sect1 id="Implementation_Dependent_Routines">
780 <title>Implementation-Dependent Routines</title>
781 <para>
782 <!-- .LP -->
783 Several input extension protocol requests have 
784 implementation-dependent  entry points.  Default routines
785 are defined for these entry points and contained in the source
786 file extensions/server/xinput/xstubs.c.  Some implementations may
787 be able to use the default routines without change.
788 The following sections describe each of these routines.
789 </para>
790 <sect2 id="AddOtherInputDevices">
791 <title>AddOtherInputDevices</title>
792 <para>
793 <!-- .LP -->
794 AddOtherInputDevice is called from ProcXListInputDevices as a result of 
795 an XListInputDevices protocol request.  It may be needed by
796 implementations that do not open extension input devices until requested
797 to do so by some client.  These implementations may not initialize
798 all devices when the X server starts up, because some of those devices
799 may be in use.  Since the XListInputDevices
800 function only lists those devices that have been initialized,
801 AddOtherInputDevices is called to give DDX a chance to 
802 initialize any previously unavailable input devices.
803 </para>
804 <para>
805 <!-- .LP -->
806 A sample AddOtherInputDevices routine might look like the following:
807 <literallayout class="monospaced">
808 void
809 AddOtherInputDevices ()
810     {
811     DeviceIntPtr dev;
812     int i;
814     for (i=0; i&lt;MAX_DEVICES; i++) 
815         {
816         if (!local_dev[i].initialized &amp;&amp; available(local_dev[i]))
817             {
818             dev = (DeviceIntPtr) AddInputDevice (local_dev[i].deviceProc, TRUE);
819             dev-&gt;public.devicePrivate = local_dev[i];
820             RegisterOtherDevice (dev);
821             dev-&gt;inited = ((*dev-&gt;deviceProc)(dev, DEVICE_INIT) == Success);
822             }
823         }
824     }
825 </literallayout>
826 </para>
827 <para>
828 <!-- .LP -->
829 The default AddOtherInputDevices routine in xstubs.c does nothing.
830 If all input extension devices are initialized when the server 
831 starts up, it can be left as a null routine.
832 </para>
833 </sect2>
834 <sect2 id="OpenInputDevice">
835 <title>OpenInputDevice</title>
836 <para>
837 <!-- .LP -->
838 Some X server implementations open all input devices when the server
839 is initialized and never close them.  Other implementations may open only
840 the X pointer and keyboard devices during server initialization,
841 and open other input devices only when some client makes an
842 XOpenDevice request.  This entry point is for the latter type of 
843 implementation.
844 </para>
845 <para>
846 <!-- .LP -->
847 If the physical device is not already open, it can be done in this routine.  
848 In this case, the server must keep track of the fact that one or more clients 
849 have the device open, and physically close it when the last client that has
850 it open makes an XCloseDevice request.
851 </para>
852 <para>
853 <!-- .LP -->
854 The default implementation is to do nothing (assume all input devices
855 are opened during X server initialization and kept open).
856 </para>
857 </sect2>
858 <sect2 id="CloseInputDevice">
859 <title>CloseInputDevice</title>
860 <para>
861 <!-- .LP -->
862 Some implementations may close an input device when the last client
863 using that device requests that it be closed, or terminates.
864 CloseInputDevice is called from ProcXCloseDevice when a client
865 makes an XCloseDevice protocol request.
866 </para>
867 <para>
868 <!-- .LP -->
869 The default implementation is to do nothing (assume all input devices
870 are opened during X server initialization and kept open).
871 </para>
872 </sect2>
873 <sect2 id="SetDeviceMode">
874 <title>SetDeviceMode</title>
875 <para>
876 <!-- .LP -->
877 Some implementations support input devices that can report 
878 either absolute positional data or relative motion.  The XSetDeviceMode
879 protocol request is provided to allow DDX to change the current mode of 
880 such a device.
881 </para>
882 <para>
883 <!-- .LP -->
884 The default implementation is to always return a BadMatch error.  If the
885 implementation does not support any input devices that are capable of 
886 reporting both relative motion and absolute position information, the
887 default implementation may be left unchanged.
888 </para>
889 </sect2>
890 <sect2 id="SetDeviceValuators">
891 <title>SetDeviceValuators</title>
892 <para>
893 <!-- .LP -->
894 Some implementations support input devices that allow their valuators to be 
895 set to an initial value.  The XSetDeviceValuators 
896 protocol request is provided to allow DDX to set the valuators of
897 such a device.
898 </para>
899 <para>
900 <!-- .LP -->
901 The default implementation is to always return a BadMatch error.  If the
902 implementation does not support any input devices that allow their
903 valuators to be set, the default implementation may be left unchanged.
904 </para>
905 </sect2>
906 <sect2 id="ChangePointerDevice">
907 <title>ChangePointerDevice</title>
908 <para>
909 <!-- .LP -->
910 The XChangePointerDevice protocol request is provided to change which device is
911 used as the X pointer.  Some implementations may maintain information
912 specific to the X pointer in the private data structure pointed to by
913 the DeviceIntRec.  ChangePointerDevice is called to allow such 
914 implementations to move that information to the new pointer device.
915 The current location of the X cursor is an example of the type of 
916 information that might be affected.
917 </para>
918 <para>
919 <!-- .LP -->
920 The DeviceIntRec structure that describes the X pointer device does not 
921 contain a FocusRec.  If the device that has been made into the new X pointer 
922 was previously a device that could be focused, ProcXChangePointerDevice will 
923 free the FocusRec associated with that device.
924 </para>
925 <para>
926 <!-- .LP -->
927 If the server implementation desires to allow clients to focus the old pointer 
928 device (which is now accessible through the input extension), it should call
929 InitFocusClassDeviceStruct for the old pointer device.
930 </para>
931 <para>
932 <!-- .LP -->
933 The XChangePointerDevice protocol request also allows the client
934 to choose which axes of the new pointer device are used to move 
935 the X cursor in the X- and Y- directions.  If the axes are different
936 than the default ones, the server implementation should record that fact.
937 </para>
938 <para>
939 <!-- .LP -->
940 If the server implementation supports input devices with valuators that 
941 are not allowed to be used as the X pointer, they should be screened out
942 by this routine and a  BadDevice error returned.
943 </para>
944 <para>
945 <!-- .LP -->
946 The default implementation is to do nothing. 
947 </para>
948 </sect2>
949 <sect2 id="ChangeKeyboardDevice">
950 <title>ChangeKeyboardDevice</title>
951 <para>
952 <!-- .LP -->
953 The XChangeKeyboardDevice protocol request is provided to change which device is
954 used as the X keyboard.  Some implementations may maintain information
955 specific to the X keyboard in the private data structure pointed to by
956 the DeviceIntRec.  ChangeKeyboardDevice is called to allow such 
957 implementations to move that information to the new keyboard device.
958 </para>
959 <para>
960 <!-- .LP -->
961 The X keyboard device can be focused, and the DeviceIntRec that describes
962 that device has a FocusRec.  If the device that has been made into the new X 
963 keyboard did not previously have a FocusRec, 
964 ProcXChangeKeyboardDevice will allocate one for it.
965 </para>
966 <para>
967 <!-- .LP -->
968 If the implementation does not want clients to be able to focus the old X 
969 keyboard (which has now become available as an input extension device)
970 it should call DeleteFocusClassDeviceStruct to free the FocusRec.
971 </para>
972 <para>
973 <!-- .LP -->
974 If the implementation supports input devices with keys that are not allowed
975 to be used as the X keyboard, they should be checked for here, and a
976 BadDevice error returned.
977 </para>
978 <para>
979 <!-- .LP -->
980 The default implementation is to do nothing. 
981 </para>
982 </sect2>
983 </sect1>
984 <sect1 id="Input_Extension_Events">
985 <title>Input Extension Events</title>
986 <para>
987 <!-- .LP -->
988 Events accessed through the input extension are analogous to the core input
989 events, but have different event types.  They are of types 
990 <function>DeviceKeyPress</function>, <function>DeviceKeyRelease</function>, <function>DeviceButtonPress</function>,
991 <function>DeviceButtonRelease</function>, <function>DeviceDeviceMotionNotify</function>,
992 <function>DeviceProximityIn</function>, <function>DeviceProximityOut</function>, and <function>DeviceValuator</function>.
993 These event types are not constants.  Instead, they are external integers 
994 defined by the input extension.  Their actual values will depend on which
995 extensions are supported by a server, and the order in which they are
996 initialized.
997 </para>
998 <para>
999 <!-- .LP -->
1000 The data structures that describe these
1001 events are defined in the file <function>extensions/include/XIproto.h</function>.  Other
1002 input extension constants needed by DDX are defined in the file
1003 <function>extensions/include/XI.h</function>.
1004 </para>
1005 <para>
1006 <!-- .LP -->
1007 Some events defined by the input extension contain more information than can
1008 be contained in the 32-byte xEvent data structure.  To send this information
1009 to clients, DDX must generate two or more 32-byte wire events.  The following
1010 sections describe the contents of these events. 
1011 </para>
1012 <sect2 id="Device_Key_Events">
1013 <title>Device Key Events</title>
1014 <para>
1015 <!-- .LP -->
1016 <function>DeviceKeyPresss</function> events contain all the information that is contained in
1017 a core <function>KeyPress</function> event, and also the following additional information:
1018 </para>
1019 <para>
1020 <!-- .LP -->
1021 <!-- .RS -->
1022 <!-- .in +5n -->
1023 </para>
1024 <itemizedlist>
1025   <listitem>
1026     <para>
1027 deviceid - the identifier of the device that generated the event.
1028     </para>
1029   </listitem>
1030   <listitem>
1031     <para>
1032 device_state - the state of any modifiers on the device that generated the event.
1033     </para>
1034   </listitem>
1035   <listitem>
1036     <para>
1037 num_valuators - the number of valuators reported in this event.
1038     </para>
1039   </listitem>
1040   <listitem>
1041     <para>
1042 first_valuator - the first valuator reported in this event.
1043     </para>
1044   </listitem>
1045   <listitem>
1046     <para>
1047 valuator0 through valuator5 - the values of the valuators.
1048 <!-- .in -5n -->
1049 <!-- .RE -->
1050     </para>
1051   </listitem>
1052 </itemizedlist>
1053 <para>
1054 <!-- .LP -->
1055 In order to pass this information to the input extension library, two 32-byte
1056 wire events must be generated by DDX.  The first has an event type of 
1057 <function>DeviceKeyPress</function>, and the second has an event type of <function>DeviceValuator</function>.
1058 </para>
1059 <para>
1060 <!-- .LP -->
1061 The following code fragment shows how the two wire events could be initialized:
1062 </para>
1063 <para>
1064 <!-- .LP -->
1065 <literallayout class="monospaced">
1066     extern int DeviceKeyPress;
1067     DeviceIntPtr dev;
1068     xEvent xE[2];
1069     CARD8 id, num_valuators;
1070     INT16 x, y, pointerx, pointery;
1071     Time timestamp;
1072     deviceKeyButtonPointer *xev = (deviceKeyButtonPointer *) xE;
1073     deviceValuator *xv;
1075     xev-&gt;type = DeviceKeyPress;         /* defined by input extension */
1076     xev-&gt;detail = keycode;              /* key pressed on this device */
1077     xev-&gt;time = timestamp;              /* same as for core events    */
1078     xev-&gt;rootX = pointerx;              /* x location of core pointer */
1079     xev-&gt;rootY = pointery;              /* y location of core pointer */
1081     /******************************************************************/
1082     /*                                                                */
1083     /* The following field does not exist for core input events.      */
1084     /* It contains the device id for the device that generated the    */
1085     /* event, and also indicates whether more than one 32-byte wire   */
1086     /* event is being sent.                                           */
1087     /*                                                                */
1088     /******************************************************************/
1090     xev-&gt;deviceid = dev-&gt;id | MORE_EVENTS;     /* sending more than 1 */
1092     /******************************************************************/
1093     /* Fields in the second 32-byte wire event:                       */
1094     /******************************************************************/
1096     xv = (deviceValuator *) ++xev;
1097     xv-&gt;type = DeviceValuator;          /* event type of second event */
1098     xv-&gt;deviceid = dev-&gt;id;             /* id of this device          */
1099     xv-&gt;num_valuators = 0;              /* no valuators being sent    */
1100     xv-&gt;device_state  = 0;              /* will be filled in by DIX   */
1101 </literallayout>
1102 </para>
1103 </sect2>
1104 <sect2 id="Device_Button_Events">
1105 <title>Device Button Events</title>
1106 <para>
1107 <!-- .LP -->
1108 <function>DeviceButton</function> events contain all the information that is contained in
1109 a core button event, and also the same additional information that a 
1110 <function>DeviceKey</function> event contains.
1111 </para>
1112 </sect2>
1113 <sect2 id="Device_Motion_Events">
1114 <title>Device Motion Events</title>
1115 <para>
1116 <!-- .LP -->
1117 <function>DeviceMotion</function> events contain all the information that is contained in
1118 a core motion event, and also additional valuator information.  At least
1119 two wire events are required to contain this information.
1120 The following code fragment shows how the two wire events could be initialized:
1121 </para>
1122 <para>
1123 <!-- .LP -->
1124 <literallayout class="monospaced">
1125     extern int DeviceMotionNotify;
1126     DeviceIntPtr dev;
1127     xEvent xE[2];
1128     CARD8 id, num_valuators;
1129     INT16 x, y, pointerx, pointery;
1130     Time timestamp;
1131     deviceKeyButtonPointer *xev = (deviceKeyButtonPointer *) xE;
1132     deviceValuator *xv;
1134     xev-&gt;type = DeviceMotionNotify;     /* defined by input extension */
1135     xev-&gt;detail = keycode;              /* key pressed on this device */
1136     xev-&gt;time = timestamp;              /* same as for core events    */
1137     xev-&gt;rootX = pointerx;              /* x location of core pointer */
1138     xev-&gt;rootY = pointery;              /* y location of core pointer */
1140     /******************************************************************/
1141     /*                                                                */
1142     /* The following field does not exist for core input events.      */
1143     /* It contains the device id for the device that generated the    */
1144     /* event, and also indicates whether more than one 32-byte wire   */
1145     /* event is being sent.                                           */
1146     /*                                                                */
1147     /******************************************************************/
1149     xev-&gt;deviceid = dev-&gt;id | MORE_EVENTS;     /* sending more than 1 */
1151     /******************************************************************/
1152     /* Fields in the second 32-byte wire event:                       */
1153     /******************************************************************/
1155     xv = (deviceValuator *) ++xev;
1156     xv-&gt;type = DeviceValuator;          /* event type of second event */
1157     xv-&gt;deviceid = dev-&gt;id;             /* id of this device          */
1158     xv-&gt;num_valuators = 2;              /* 2 valuators being sent     */
1159     xv-&gt;first_valuator = 0;             /* first valuator being sent  */
1160     xv-&gt;device_state  = 0;              /* will be filled in by DIX   */
1161     xv-&gt;valuator0 = x;                  /* first axis of this device  */
1162     xv-&gt;valuator1 = y;                  /* second axis of this device */
1163 </literallayout>
1164 </para>
1165 <para>
1166 <!-- .LP -->
1167 Up to six axes can be reported in the deviceValuator event.  If the device
1168 is reporting more than 6 axes, additional pairs of DeviceMotionNotify and
1169 DeviceValuator events should be sent,  with the first_valuator field
1170 set correctly.
1171 </para>
1172 </sect2>
1173 <sect2 id="Device_Proximity_Events">
1174 <title>Device Proximity Events</title>
1175 <para>
1176 <!-- .LP -->
1177 Some input devices that report absolute positional information, such as 
1178 graphics tablets and touchscreens, may report proximity events.  
1179 <function>ProximityIn</function>
1180 events are generated when a pointing device like a stylus, or in the case
1181 of a touchscreen, the user's finger, comes into close proximity with the
1182 surface of the input device.  <function>ProximityOut</function> events are generated when
1183 the stylus or finger leaves the proximity of the input devices surface.
1184 </para>
1185 <para>
1186 <!-- .LP -->
1187 <function>Proximity</function> events contain almost the same information as button events.
1188 The event type is <function>ProximityIn</function> or <function>ProximityOut</function>, and there is no
1189 detail information.
1190 <!-- .bp -->
1191 <!-- .\" .TC -->
1193 </para>
1194 </sect2>
1195 </sect1>
1196 </chapter>
1197 </book>