Xinput.xml revision 1b5d61b8
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]>
6
7<!-- lifted from troff+ms+XMan by doclifter -->
8<book id="porting">
9
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>
22
23<legalnotice>
24
25
26<para>
27Permission to use, copy, modify, and distribute this documentation for any purpose and without fee is
28hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
29Hewlett-Packard makes no representations about the suitability for any purpose of the information in this
30document. It is provided "as is" without express or implied warranty. This document is only a draft stan-
31dard of the X Consortium and is therefore subject to change.
32</para>
33</legalnotice>
34
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>
39
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>
41
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>
43
44<para>X Window System is a trademark of The Open Group.</para>
45</legalnotice>
46
47</bookinfo>
48
49<chapter id="x11_input_extension_porting_document">
50<title>X11 Input Extension Porting Document</title>
51
52<para>
53This document is intended to aid the process of integrating the 
54X11 Input Extension into an X server.
55</para>
56<para>
57<!-- .LP -->
58Most of the functionality provided by the input extension is 
59device- and implementation-independent, and should require no changes.  
60The functionality is implemented by
61routines that typically reside in the server source tree directory 
62extensions/server/xinput.
63This extension includes functions to enable and disable input extension devices,
64select input, grab and focus those devices, query and change key
65and button mappings, and others.  The only input extension requirements 
66for the device-dependent part of X are that the input devices be 
67correctly initialized and input events from those devices be correctly
68generated.  Device-dependent X is responsible for reading input data from 
69the input device hardware and if necessary, reformatting it into X events.
70</para>
71<para>
72<!-- .LP -->
73The process of initializing input extension devices is similar to that used 
74for the core devices, and is described in the following sections.  When
75multiple input devices are attached to X server, the choice of which devices
76to initially use as the core X pointer and keyboard is left 
77implementation-dependent.  It is also up to each implementation to decide
78whether all input devices will be opened by the server during its 
79initialization and kept open for the life of the server.  The alternative is
80to open only the X keyboard and X pointer during server initialization, and
81open other input devices only when requested by a client to do so.  Either
82type of implementation is supported by the input extension.
83</para>
84<para>
85<!-- .LP -->
86Input extension events generated by the X server use the same 32-byte xEvent
87wire event as do core input events.  However, additional information must be
88sent for input extension devices, requiring that multiple xEvents be generated
89each time data is received from an input extension device.  These xEvents are
90combined into a single client XEvent by the input extension library.  A later
91section of this document describes the format and generation of input extension
92events.
93</para>
94<sect1 id="Initializing_Extension_Devices">
95<title>Initializing Extension Devices</title>
96<para>
97<!-- .LP -->
98Extension input devices are initialized in the same manner as the core 
99X input devices.  Device-Independent X provides functions that can be 
100called from DDX to initialize these devices.  Which functions are called
101and when will vary by implementation, and will depend on whether the 
102implementation opens all the input devices available to X when X is initialized,
103or waits until a client requests that a device be opened.
104In the simplest case, DDX will open all input devices as part of its
105initialization, 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">
112Device-Independent X       |  Device-Dependent X
113--------------------       |  -------------------             
114                           |                                        
115InitInput --------------&gt;  |  - do device-specific initialization
116                           |                                        
117                           |  - call AddInputDevice  (deviceProc,AutoStart)
118AddInputDevice             |   
119  - creates DeviceIntRec   |
120  - records deviceProc     |
121  - adds new device to     | 
122    list of off_devices.   |
123sets 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                           |                                        
133InitAndStartDevices -----&gt; |  - calls deviceProc with parameters
134                           |    (DEVICE_INIT, AutoStart)
135sets 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                           |                                        
160for 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                           |                                        
167If 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 -->
179InitInput is the first DDX input entry point called during X server startup.
180This routine is responsible for
181device- and implementation- specific initialization, and for calling
182AddInputDevice to create and initialize the DeviceIntRec structure for each
183input device.  AddInputDevice is passed the address of a procedure to be called
184by the DIX routine InitAndStartDevices when input devices are enabled.
185This procedure is expected to perform X initialization for the input device.
186</para>
187<para>
188<!-- .LP -->
189If the device is to be used as the X pointer, DDX should then call
190RegisterPointerDevice, passing the DeviceIntRec pointer,
191to initialize the device as the X pointer.
192</para>
193<para>
194<!-- .LP -->
195If the device is to be used as the X keyboard, DDX should instead call
196RegisterKeyboardDevice to initialize the device as the X keyboard.
197</para>
198<para>
199<!-- .LP -->
200If the device is to be used as an extension device, DDX should instead
201call RegisterOtherDevice, passing the DeviceIntPtr returned by
202AddInputDevice.
203</para>
204<para>
205<!-- .LP -->
206A sample InitInput implementation is shown below.
207</para>
208<para>
209<!-- .LP -->
210<literallayout class="monospaced">
211InitInput(argc,argv)
212    {
213    int i, numdevs;
214    DeviceIntPtr dev;
215    LocalDevice localdevs[LOCAL_MAX_DEVS];
216    DeviceProc kbdproc, ptrproc, extproc;
217
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     ***************************************************************/
223
224    open_input_devices (&amp;numdevs, localdevs);
225
226    /**************************************************************
227     * Register the input devices with DIX.
228     ***************************************************************/
229
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 -->
258After InitInput has returned,
259InitAndStartDevices is the DIX routine that is called to enable input devices. 
260It calls the device control routine that was passed to AddInputDevice,
261with a mode value of DEVICE_INIT.  The action taken by the device control
262routine depends on how the device is to be used.  If the device is to be
263the X pointer, the device control routine should call
264InitPointerDeviceStruct to initialize it.  If the device is to be the
265X keyboard, the device control routine should call
266InitKeyboardDeviceStruct.  Since input extension devices may support various
267combinations of keys, buttons, valuators, and feedbacks,
268each class of input that it supports must be initialized.
269Entry points are defined by DIX to initialize each of the supported classes of
270input, and are described in the following sections.
271</para>
272<para>
273<!-- .LP -->
274A sample device control routine called from InitAndStartDevices is 
275shown below.
276</para>
277<para>
278<!-- .LP -->
279<literallayout class="monospaced">
280Bool extproc (dev, mode)
281    DeviceIntPtr dev;
282    int mode;
283    {
284    LocalDevice *localdev = (LocalDevice *) dev-&gt;devicePrivate;
285
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                 ****************************************************/
297
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                 ****************************************************/
313
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                 ****************************************************/
324
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 -->
352The device control routine is called with a mode value of DEVICE_ON
353by the DIX routine EnableDevice, which is called from InitAndStartDevices.  
354When called with this mode, it should call AddEnabledDevice to cause the 
355server to begin checking for available input from this device.
356</para>
357<para>
358<!-- .LP -->
359From InitAndStartDevices, EnableDevice is called for all devices that have
360the "inited" and "startup" fields in the DeviceIntRec set to TRUE.  The
361"inited" field is set by InitAndStartDevices to the value returned by
362the deviceproc when called with a mode value of DEVICE_INIT.  The "startup"
363field is set by AddInputDevice to value of the second parameter (autoStart).
364</para>
365<para>
366<!-- .LP -->
367When the server is first initialized, it should only be checking for input
368from the core X keyboard and pointer.  One way to accomplish this is to
369call AddInputDevice for the core X keyboard and pointer with an
370autoStart value equal to TRUE, while calling AddInputDevice for 
371input extension devices with an autoStart value equal to FALSE.  If this is 
372done, EnableDevice will skip all input extension devices during server
373initialization.  In this case,
374the OpenInputDevice routine should set the "startup" field to TRUE
375when called for input extension devices.  This will cause ProcXOpenInputDevice
376to call EnableDevice for those devices when a client first does an
377XOpenDevice 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 -->
384DIX routines are defined to initialize each of the defined input classes.
385The defined classes are:
386<!-- .RS -->
387<!-- .in +5n -->
388</para>
389<itemizedlist>
390  <listitem>
391    <para>
392KeyClass - the device has keys.
393    </para>
394  </listitem>
395  <listitem>
396    <para>
397ButtonClass - the device has buttons.
398    </para>
399  </listitem>
400  <listitem>
401    <para>
402ValuatorClass - the device reports motion data or positional data.
403    </para>
404  </listitem>
405  <listitem>
406    <para>
407Proximitylass - the device reports proximity information.
408    </para>
409  </listitem>
410  <listitem>
411    <para>
412FocusClass - the device can be focused.
413    </para>
414  </listitem>
415  <listitem>
416    <para>
417FeedbackClass - the device supports some kind of feedback.
418<!-- .in -5n -->
419<!-- .RE -->
420    </para>
421  </listitem>
422</itemizedlist>
423<para>
424<!-- .LP -->
425DIX routines are provided to initialize the X pointer and keyboard, as in
426previous releases of X.  During X initialization, InitPointerDeviceStruct 
427is called to initialize the X pointer, and InitKeyboardDeviceStruct is
428called to initialize the X keyboard.  There is no
429corresponding routine for extension input devices, since they do not all
430support the same classes of input.  Instead, DDX is responsible for the 
431initialization of the input classes supported by extension devices.  
432A description of the routines provided by DIX to perform that initialization
433follows.
434</para>
435<sect3 id="InitKeyClassDeviceStruct">
436<title>InitKeyClassDeviceStruct</title>
437<para>
438<!-- .LP -->
439This function is provided to allocate and initialize a KeyClassRec, and 
440should be called for extension devices that have keys.  It is passed a pointer
441to the device, and pointers to arrays of keysyms and modifiers reported by
442the device.  It returns FALSE if the KeyClassRec could not be allocated,
443or if the maps for the keysyms and modifiers could not be allocated.
444Its parameters are:
445</para>
446<para>
447<!-- .LP -->
448<literallayout class="monospaced">
449Bool
450InitKeyClassDeviceStruct(dev, pKeySyms, pModifiers)
451    DeviceIntPtr dev;
452    KeySymsPtr pKeySyms;
453    CARD8 pModifiers[];
454</literallayout>
455</para>
456<para>
457<!-- .LP -->
458The DIX entry point InitKeyboardDeviceStruct calls this routine for the
459core X keyboard.  It must be called explicitly for extension devices
460that have keys.
461</para>
462</sect3>
463<sect3 id="InitButtonClassDeviceStruct">
464<title>InitButtonClassDeviceStruct</title>
465<para>
466<!-- .LP -->
467This function is provided to allocate and initialize a ButtonClassRec, and 
468should be called for extension devices that have buttons.  It is passed a 
469pointer to the device, the number of buttons supported, and a map of the 
470reported button codes.  It returns FALSE if the ButtonClassRec could not be 
471allocated.  Its parameters are:
472</para>
473<para>
474<!-- .LP -->
475<literallayout class="monospaced">
476Bool
477InitButtonClassDeviceStruct(dev, numButtons, map)
478    register DeviceIntPtr dev;
479    int numButtons;
480    CARD8 *map;
481</literallayout>
482</para>
483<para>
484<!-- .LP -->
485The DIX entry point InitPointerDeviceStruct calls this routine for the
486core X pointer.  It must be called explicitly for extension devices that
487have buttons.
488</para>
489</sect3>
490<sect3 id="InitValuatorClassDeviceStruct">
491<title>InitValuatorClassDeviceStruct</title>
492<para>
493<!-- .LP -->
494This function is provided to allocate and initialize a ValuatorClassRec, and 
495should be called for extension devices that have valuators.  It is passed the
496number of axes of motion reported by the device, the address of the motion
497history procedure for the device, the size of the motion history buffer,
498and the mode (Absolute or Relative) of the device.  It returns FALSE if 
499the ValuatorClassRec could not be allocated.  Its parameters are:
500</para>
501<para>
502<!-- .LP -->
503<literallayout class="monospaced">
504Bool
505InitValuatorClassDeviceStruct(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 -->
515The DIX entry point InitPointerDeviceStruct calls this routine for the
516core X pointer.  It must be called explicitly for extension devices that
517report motion.
518</para>
519</sect3>
520<sect3 id="InitValuatorAxisStruct">
521<title>InitValuatorAxisStruct</title>
522<para>
523<!-- .LP -->
524This function is provided to initialize an XAxisInfoRec, and 
525should be called for core and extension devices that have valuators.  
526The space for the XAxisInfoRec is allocated by 
527the InitValuatorClassDeviceStruct function, but is not initialized.
528</para>
529<para>
530<!-- .LP -->
531InitValuatorAxisStruct should be called once for each axis of motion 
532reported by the device.  Each
533invocation should be passed the axis number (starting with 0), the
534minimum value for that axis, the maximum value for that axis, and the
535resolution of the device in counts per meter.  If the device reports
536relative motion, 0 should be reported as the minimum and maximum values.
537InitValuatorAxisStruct has the following parameters:
538<literallayout class="monospaced">
539InitValuatorAxisStruct(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 -->
549This routine is not called by InitPointerDeviceStruct for the
550core X pointer.  It must be called explicitly for core and extension devices 
551that report motion.
552</para>
553</sect3>
554<sect3 id="InitFocusClassDeviceStruct">
555<title>InitFocusClassDeviceStruct</title>
556<para>
557<!-- .LP -->
558This function is provided to allocate and initialize a FocusClassRec, and 
559should be called for extension devices that can be focused.  It is passed a
560pointer to the device, and returns FALSE if the allocation fails.
561It has the following parameter:
562<literallayout class="monospaced">
563Bool
564InitFocusClassDeviceStruct(dev)
565    DeviceIntPtr dev;
566</literallayout>
567</para>
568<para>
569<!-- .LP -->
570The DIX entry point InitKeyboardDeviceStruct calls this routine for the
571core X keyboard.  It must be called explicitly for extension devices
572that can be focused.  Whether or not a particular device can be focused
573is left implementation-dependent.
574</para>
575</sect3>
576<sect3 id="InitProximityClassDeviceStruct">
577<title>InitProximityClassDeviceStruct</title>
578<para>
579<!-- .LP -->
580This function is provided to allocate and initialize a ProximityClassRec, and 
581should be called for extension absolute pointing devices that report proximity.
582It is passed a pointer to the device, and returns FALSE if the allocation fails.
583It has the following parameter:
584<literallayout class="monospaced">
585Bool
586InitProximityClassDeviceStruct(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 -->
600This function is provided to allocate and initialize a KbdFeedbackClassRec, and 
601may be called for extension devices that support some or all of the 
602feedbacks that the core keyboard supports.  It is passed a
603pointer to the device, a pointer to the procedure that sounds the bell,
604and a pointer to the device control procedure.
605It returns FALSE if the allocation fails, and has the following parameters:
606<literallayout class="monospaced">
607Bool
608InitKbdFeedbackClassDeviceStruct(dev, bellProc, controlProc)
609    DeviceIntPtr dev;
610    void (*bellProc)();
611    void (*controlProc)();
612</literallayout>
613The DIX entry point InitKeyboardDeviceStruct calls this routine for the
614core X keyboard.  It must be called explicitly for extension devices
615that have the same feedbacks as a keyboard.  Some feedbacks, such as LEDs and
616bell, can be supported either with a KbdFeedbackClass or with BellFeedbackClass
617and LedFeedbackClass feedbacks.
618</para>
619</sect4>
620<sect4 id="InitPtrFeedbackClassDeviceStruct">
621<title>InitPtrFeedbackClassDeviceStruct</title>
622<para>
623<!-- .LP -->
624This function is provided to allocate and initialize a PtrFeedbackClassRec, and 
625should be called for extension devices that allow the setting of acceleration
626and threshold.  It is passed a pointer to the device,
627and a pointer to the device control procedure.
628It returns FALSE if the allocation fails, and has the following parameters:
629<literallayout class="monospaced">
630Bool
631InitPtrFeedbackClassDeviceStruct(dev, controlProc)
632    DeviceIntPtr dev;
633    void (*controlProc)();
634</literallayout>
635</para>
636<para>
637<!-- .LP -->
638The DIX entry point InitPointerDeviceStruct calls this routine for the
639core X pointer.  It must be called explicitly for extension devices
640that support the setting of acceleration and threshold.
641</para>
642</sect4>
643<sect4 id="InitLedFeedbackClassDeviceStruct">
644<title>InitLedFeedbackClassDeviceStruct</title>
645<para>
646<!-- .LP -->
647This function is provided to allocate and initialize a LedFeedbackClassRec, and 
648should be called for extension devices that have LEDs.
649It is passed a pointer to the device,
650and a pointer to the device control procedure.
651It returns FALSE if the allocation fails, and has the following parameters:
652<literallayout class="monospaced">
653Bool
654InitLedFeedbackClassDeviceStruct(dev, controlProc)
655    DeviceIntPtr dev;
656    void (*controlProc)();
657</literallayout>
658</para>
659<para>
660<!-- .LP -->
661Up to 32 LEDs per feedback can be supported, and a device may have 
662multiple feedbacks of the same type.
663</para>
664</sect4>
665<sect4 id="InitBellFeedbackClassDeviceStruct">
666<title>InitBellFeedbackClassDeviceStruct</title>
667<para>
668<!-- .LP -->
669This function is provided to allocate and initialize a BellFeedbackClassRec, 
670and should be called for extension devices that have a bell.
671It is passed a pointer to the device,
672and a pointer to the device control procedure.
673It returns FALSE if the allocation fails, and has the following parameters:
674<literallayout class="monospaced">
675Bool
676InitBellFeedbackClassDeviceStruct(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 -->
687This function is provided to allocate and initialize a StringFeedbackClassRec, 
688and should be called for extension devices that have a display upon which a 
689string can be displayed.
690It is passed a pointer to the device,
691and a pointer to the device control procedure.
692It returns FALSE if the allocation fails, and has the following parameters:
693<literallayout class="monospaced">
694Bool
695InitStringFeedbackClassDeviceStruct(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 -->
709This function is provided to allocate and initialize an 
710IntegerFeedbackClassRec, 
711and should be called for extension devices that have a display upon which an
712integer can be displayed.
713It is passed a pointer to the device,
714and a pointer to the device control procedure.
715It returns FALSE if the allocation fails, and has the following parameters:
716<literallayout class="monospaced">
717Bool
718InitIntegerFeedbackClassDeviceStruct(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 -->
730The device name and type can be initialized by calling AssignTypeAndName
731with the following parameters:
732<literallayout class="monospaced">
733void
734AssignTypeAndName(dev, type, name)
735    DeviceIntPtr dev;
736    Atom type;
737    char *name;
738</literallayout>
739</para>
740<para>
741<!-- .LP -->
742This will allocate space for the device name and copy the name that was passed.
743The device type can be obtained by calling MakeAtom with one of the names
744defined for input devices.  MakeAtom has the following parameters:
745<literallayout class="monospaced">
746Atom
747MakeAtom(name, len, makeit)
748    char *name;
749    int len;
750    Bool makeit;
751</literallayout>
752</para>
753<para>
754<!-- .LP -->
755Since the atom was already made when the input extension was initialized, the
756value 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 -->
764The DisableDevice entry point is provided by DIX to disable input devices.
765It calls the device control routine for the specified
766device with a mode value of DEVICE_OFF.  The device control routine should
767call RemoveEnabledDevice to stop the server from checking for input from
768that device.
769</para>
770<para>
771<!-- .LP -->
772DisableDevice is not called by any input extension routines.  It can be 
773called from the CloseInputDevice routine, which is called by
774ProcXCloseDevice when a client makes an XCloseDevice request.  If
775DisableDevice is called, it should only be called when the last client
776using 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 -->
783Several input extension protocol requests have 
784implementation-dependent  entry points.  Default routines
785are defined for these entry points and contained in the source
786file extensions/server/xinput/xstubs.c.  Some implementations may
787be able to use the default routines without change.
788The following sections describe each of these routines.
789</para>
790<sect2 id="AddOtherInputDevices">
791<title>AddOtherInputDevices</title>
792<para>
793<!-- .LP -->
794AddOtherInputDevice is called from ProcXListInputDevices as a result of 
795an XListInputDevices protocol request.  It may be needed by
796implementations that do not open extension input devices until requested
797to do so by some client.  These implementations may not initialize
798all devices when the X server starts up, because some of those devices
799may be in use.  Since the XListInputDevices
800function only lists those devices that have been initialized,
801AddOtherInputDevices is called to give DDX a chance to 
802initialize any previously unavailable input devices.
803</para>
804<para>
805<!-- .LP -->
806A sample AddOtherInputDevices routine might look like the following:
807<literallayout class="monospaced">
808void
809AddOtherInputDevices ()
810    {
811    DeviceIntPtr dev;
812    int i;
813
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 -->
829The default AddOtherInputDevices routine in xstubs.c does nothing.
830If all input extension devices are initialized when the server 
831starts 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 -->
838Some X server implementations open all input devices when the server
839is initialized and never close them.  Other implementations may open only
840the X pointer and keyboard devices during server initialization,
841and open other input devices only when some client makes an
842XOpenDevice request.  This entry point is for the latter type of 
843implementation.
844</para>
845<para>
846<!-- .LP -->
847If the physical device is not already open, it can be done in this routine.  
848In this case, the server must keep track of the fact that one or more clients 
849have the device open, and physically close it when the last client that has
850it open makes an XCloseDevice request.
851</para>
852<para>
853<!-- .LP -->
854The default implementation is to do nothing (assume all input devices
855are opened during X server initialization and kept open).
856</para>
857</sect2>
858<sect2 id="CloseInputDevice">
859<title>CloseInputDevice</title>
860<para>
861<!-- .LP -->
862Some implementations may close an input device when the last client
863using that device requests that it be closed, or terminates.
864CloseInputDevice is called from ProcXCloseDevice when a client
865makes an XCloseDevice protocol request.
866</para>
867<para>
868<!-- .LP -->
869The default implementation is to do nothing (assume all input devices
870are opened during X server initialization and kept open).
871</para>
872</sect2>
873<sect2 id="SetDeviceMode">
874<title>SetDeviceMode</title>
875<para>
876<!-- .LP -->
877Some implementations support input devices that can report 
878either absolute positional data or relative motion.  The XSetDeviceMode
879protocol request is provided to allow DDX to change the current mode of 
880such a device.
881</para>
882<para>
883<!-- .LP -->
884The default implementation is to always return a BadMatch error.  If the
885implementation does not support any input devices that are capable of 
886reporting both relative motion and absolute position information, the
887default implementation may be left unchanged.
888</para>
889</sect2>
890<sect2 id="SetDeviceValuators">
891<title>SetDeviceValuators</title>
892<para>
893<!-- .LP -->
894Some implementations support input devices that allow their valuators to be 
895set to an initial value.  The XSetDeviceValuators 
896protocol request is provided to allow DDX to set the valuators of
897such a device.
898</para>
899<para>
900<!-- .LP -->
901The default implementation is to always return a BadMatch error.  If the
902implementation does not support any input devices that allow their
903valuators 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 -->
910The XChangePointerDevice protocol request is provided to change which device is
911used as the X pointer.  Some implementations may maintain information
912specific to the X pointer in the private data structure pointed to by
913the DeviceIntRec.  ChangePointerDevice is called to allow such 
914implementations to move that information to the new pointer device.
915The current location of the X cursor is an example of the type of 
916information that might be affected.
917</para>
918<para>
919<!-- .LP -->
920The DeviceIntRec structure that describes the X pointer device does not 
921contain a FocusRec.  If the device that has been made into the new X pointer 
922was previously a device that could be focused, ProcXChangePointerDevice will 
923free the FocusRec associated with that device.
924</para>
925<para>
926<!-- .LP -->
927If the server implementation desires to allow clients to focus the old pointer 
928device (which is now accessible through the input extension), it should call
929InitFocusClassDeviceStruct for the old pointer device.
930</para>
931<para>
932<!-- .LP -->
933The XChangePointerDevice protocol request also allows the client
934to choose which axes of the new pointer device are used to move 
935the X cursor in the X- and Y- directions.  If the axes are different
936than the default ones, the server implementation should record that fact.
937</para>
938<para>
939<!-- .LP -->
940If the server implementation supports input devices with valuators that 
941are not allowed to be used as the X pointer, they should be screened out
942by this routine and a  BadDevice error returned.
943</para>
944<para>
945<!-- .LP -->
946The default implementation is to do nothing. 
947</para>
948</sect2>
949<sect2 id="ChangeKeyboardDevice">
950<title>ChangeKeyboardDevice</title>
951<para>
952<!-- .LP -->
953The XChangeKeyboardDevice protocol request is provided to change which device is
954used as the X keyboard.  Some implementations may maintain information
955specific to the X keyboard in the private data structure pointed to by
956the DeviceIntRec.  ChangeKeyboardDevice is called to allow such 
957implementations to move that information to the new keyboard device.
958</para>
959<para>
960<!-- .LP -->
961The X keyboard device can be focused, and the DeviceIntRec that describes
962that device has a FocusRec.  If the device that has been made into the new X 
963keyboard did not previously have a FocusRec, 
964ProcXChangeKeyboardDevice will allocate one for it.
965</para>
966<para>
967<!-- .LP -->
968If the implementation does not want clients to be able to focus the old X 
969keyboard (which has now become available as an input extension device)
970it should call DeleteFocusClassDeviceStruct to free the FocusRec.
971</para>
972<para>
973<!-- .LP -->
974If the implementation supports input devices with keys that are not allowed
975to be used as the X keyboard, they should be checked for here, and a
976BadDevice error returned.
977</para>
978<para>
979<!-- .LP -->
980The 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 -->
988Events accessed through the input extension are analogous to the core input
989events, 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>.
993These event types are not constants.  Instead, they are external integers 
994defined by the input extension.  Their actual values will depend on which
995extensions are supported by a server, and the order in which they are
996initialized.
997</para>
998<para>
999<!-- .LP -->
1000The data structures that describe these
1001events are defined in the file <function>extensions/include/XIproto.h</function>.  Other
1002input extension constants needed by DDX are defined in the file
1003<function>extensions/include/XI.h</function>.
1004</para>
1005<para>
1006<!-- .LP -->
1007Some events defined by the input extension contain more information than can
1008be contained in the 32-byte xEvent data structure.  To send this information
1009to clients, DDX must generate two or more 32-byte wire events.  The following
1010sections 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
1017a 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>
1027deviceid - the identifier of the device that generated the event.
1028    </para>
1029  </listitem>
1030  <listitem>
1031    <para>
1032device_state - the state of any modifiers on the device that generated the event.
1033    </para>
1034  </listitem>
1035  <listitem>
1036    <para>
1037num_valuators - the number of valuators reported in this event.
1038    </para>
1039  </listitem>
1040  <listitem>
1041    <para>
1042first_valuator - the first valuator reported in this event.
1043    </para>
1044  </listitem>
1045  <listitem>
1046    <para>
1047valuator0 through valuator5 - the values of the valuators.
1048<!-- .in -5n -->
1049<!-- .RE -->
1050    </para>
1051  </listitem>
1052</itemizedlist>
1053<para>
1054<!-- .LP -->
1055In order to pass this information to the input extension library, two 32-byte
1056wire 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 -->
1061The 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;
1074
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 */
1080
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    /******************************************************************/
1089
1090    xev-&gt;deviceid = dev-&gt;id | MORE_EVENTS;     /* sending more than 1 */
1091
1092    /******************************************************************/
1093    /* Fields in the second 32-byte wire event:                       */
1094    /******************************************************************/
1095
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
1109a 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
1118a core motion event, and also additional valuator information.  At least
1119two wire events are required to contain this information.
1120The 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;
1133
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 */
1139
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    /******************************************************************/
1148
1149    xev-&gt;deviceid = dev-&gt;id | MORE_EVENTS;     /* sending more than 1 */
1150
1151    /******************************************************************/
1152    /* Fields in the second 32-byte wire event:                       */
1153    /******************************************************************/
1154
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 -->
1167Up to six axes can be reported in the deviceValuator event.  If the device
1168is reporting more than 6 axes, additional pairs of DeviceMotionNotify and
1169DeviceValuator events should be sent,  with the first_valuator field
1170set correctly.
1171</para>
1172</sect2>
1173<sect2 id="Device_Proximity_Events">
1174<title>Device Proximity Events</title>
1175<para>
1176<!-- .LP -->
1177Some input devices that report absolute positional information, such as 
1178graphics tablets and touchscreens, may report proximity events.  
1179<function>ProximityIn</function>
1180events are generated when a pointing device like a stylus, or in the case
1181of a touchscreen, the user's finger, comes into close proximity with the
1182surface of the input device.  <function>ProximityOut</function> events are generated when
1183the 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.
1188The event type is <function>ProximityIn</function> or <function>ProximityOut</function>, and there is no
1189detail information.
1190<!-- .bp -->
1191<!-- .\" .TC -->
1192
1193</para>
1194</sect2>
1195</sect1>
1196</chapter>
1197</book>
1198