ch06.xml revision e9fcaa8a
1<chapter id='complete_keyboard_description'>
2<title>Complete Keyboard Description</title>
3
4<para>
5The complete Xkb description for a keyboard device is accessed using a single
6structure containing pointers to major Xkb components. This chapter describes
7this single structure and provides references to other sections of this
8document that discuss the major Xkb components in detail.
9</para>
10
11<sect1 id='the_xkbdescrec_structure'>
12<title>The XkbDescRec Structure</title>
13
14<para>
15The complete description of an Xkb keyboard is given by an <emphasis>
16XkbDescRec</emphasis>
17. The component structures in the <emphasis>
18XkbDescRec</emphasis>
19 represent the major Xkb components outlined in Figure 1.1. <!-- xref -->
20</para>
21
22<para><programlisting>
23typedef struct {
24      struct _XDisplay *                  display;            /* connection to
25X server */
26      unsigned short                  flags;            /* private to Xkb, do
27not modify */
28      unsigned short                  device_spec;            /* device of
29interest */
30      KeyCode                  min_key_code;            /* minimum keycode for
31device */
32      KeyCode                  max_key_code;            /* maximum keycode for
33device */
34      XkbControlsPtr                  ctrls;            /* controls */
35      XkbServerMapPtr                  server;            /* server keymap */
36      XkbClientMapPtr                  map;            /* client keymap */
37      XkbIndicatorPtr                  indicators;            /* indicator map
38*/
39      XkbNamesPtr                  names;            /* names for all
40components */
41      XkbCompatMapPtr                  compat;            /* compatibility map
42*/
43      XkbGeometryPtr                  geom;            /* physical geometry of
44keyboard */
45} <emphasis>
46XkbDescRec</emphasis>
47, *XkbDescPtr;
48</programlisting></para>
49
50<para>
51The <emphasis>
52display</emphasis>
53 field points to an X display structure. The <emphasis>
54flags</emphasis>
55 field is private to the library: modifying <emphasis>
56flags</emphasis>
57 may yield unpredictable results. The <emphasis>
58device_spec</emphasis>
59 field specifies the device identifier of the keyboard input device, or
60<emphasis>
61XkbUseCoreKeyboard</emphasis>
62, which specifies the core keyboard device. The <emphasis>
63min_key_code</emphasis>
64 and <emphasis>
65max_key_code</emphasis>
66 fields specify the least and greatest keycode that can be returned by the
67keyboard.
68</para>
69
70
71<para>
72The other fields specify structure components of the keyboard description and
73are described in detail in other sections of this document. Table 6.1
74identifies the subsequent sections of this document that discuss the individual
75components of the <emphasis>
76XkbDescRec</emphasis>
77.
78</para>
79
80<table frame='none'>
81<title>XkbDescRec Component References</title>
82<tgroup cols='2'>
83<colspec colsep='0'/>
84<colspec colsep='0'/>
85<thead>
86<row rowsep='0'>
87  <entry>XkbDescRec Field</entry>
88  <entry>For more info</entry>
89</row>
90</thead>
91<tbody>
92<row rowsep='0'>
93    <entry>ctrls</entry>
94    <entry>Chapter 10</entry>
95</row>
96<row rowsep='0'>
97    <entry>server</entry>
98    <entry>Chapter 16</entry>
99</row>
100<row rowsep='0'>
101    <entry>map</entry>
102    <entry>Chapter 15</entry>
103</row>
104<row rowsep='0'>
105    <entry>indicators</entry>
106    <entry>Chapter 8</entry>
107</row>
108<row rowsep='0'>
109    <entry>names</entry>
110    <entry>Chapter 18</entry>
111</row>
112<row rowsep='0'>
113    <entry>compat</entry>
114    <entry>Chapter 17</entry>
115</row>
116<row rowsep='0'>
117    <entry>geom</entry>
118    <entry>Chapter 13</entry>
119  </row>
120</tbody>
121</tgroup>
122</table>
123
124<para>
125Each structure component has a corresponding mask bit that is used in function
126calls to indicate that the structure should be manipulated in some manner, such
127as allocating it or freeing it. These masks and their relationships to the
128fields in the <emphasis>
129XkbDescRec</emphasis>
130 are shown in Table 6.2. <!-- xref -->
131</para>
132
133<table frame='none'>
134<title>Mask Bits for XkbDescRec</title>
135<tgroup cols='3'>
136<colspec colsep='0'/>
137<colspec colsep='0'/>
138<colspec colsep='0'/>
139<thead>
140<row rowsep='0'>
141  <entry>Mask Bit</entry>
142  <entry>XkbDescRec Field</entry>
143  <entry>Value</entry>
144</row>
145</thead>
146<tbody>
147<row rowsep='0'>
148    <entry>XkbControlsMask</entry>
149    <entry>ctrls</entry>
150    <entry>(1L&lt;&lt;0)</entry>
151</row>
152<row rowsep='0'>
153    <entry>XkbServerMapMask</entry>
154    <entry>server</entry>
155    <entry>(1L&lt;&lt;1)</entry>
156</row>
157<row rowsep='0'>
158    <entry>XkbIClientMapMask</entry>
159    <entry>map</entry>
160    <entry>(1L&lt;&lt;2)</entry>
161</row>
162<row rowsep='0'>
163    <entry>XkbIndicatorMapMask</entry>
164    <entry>indicators</entry>
165    <entry>(1L&lt;&lt;3)</entry>
166</row>
167<row rowsep='0'>
168    <entry>XkbNamesMask</entry>
169    <entry>names</entry>
170    <entry>(1L&lt;&lt;4)</entry>
171</row>
172<row rowsep='0'>
173    <entry>XkbCompatMapMask</entry>
174    <entry>compat</entry>
175    <entry>(1L&lt;&lt;5)</entry>
176</row>
177<row rowsep='0'>
178    <entry>XkbGeometryMask</entry>
179    <entry>geom</entry>
180    <entry>(1L&lt;&lt;6)</entry>
181</row>
182<row rowsep='0'>
183    <entry>XkbAllComponentsMask</entry>
184    <entry>All Fields</entry>
185    <entry>(0x7f)</entry>
186  </row>
187</tbody>
188</tgroup>
189</table>
190
191</sect1>
192<sect1 id='obtaining_a_keyboard_description_from_the_server'>
193<title>Obtaining a Keyboard Description from the Server</title>
194
195<para>
196To retrieve one or more components of a keyboard device description, use
197<emphasis>
198XkbGetKeyboard</emphasis>
199 (see also <emphasis>
200XkbGetKeyboardbyName</emphasis>
201).
202</para>
203
204<informaltable frame='none'>
205<tgroup cols='1'>
206<colspec colsep='0'/>
207<tbody>
208  <row rowsep='0'>
209    <entry role='functiondecl'>
210XkbDescPtr <emphasis>
211XkbGetKeyboard</emphasis>
212(<emphasis>
213display, which, device_spec</emphasis>
214)
215    </entry>
216  </row>
217  <row rowsep='0'>
218    <entry role='functionargdecl'>
219Display * <emphasis>
220      display</emphasis>
221;            /* connection to X server */
222    </entry>
223  </row>
224  <row rowsep='0'>
225    <entry role='functionargdecl'>
226unsigned int      <emphasis>
227which</emphasis>
228;            /* mask indicating components to return */
229    </entry>
230  </row>
231  <row rowsep='0'>
232    <entry role='functionargdecl'>
233unsigned int<emphasis>
234      device_spec</emphasis>
235;            /* device for which to fetch description, or <emphasis>
236XkbUseCoreKbd</emphasis>
237 */
238    </entry>
239</row>
240</tbody>
241</tgroup>
242</informaltable>
243
244<para>
245<emphasis>
246XkbGetKeyboard </emphasis>
247allocates and returns a pointer to a keyboard description. It queries the
248server for those components specified in the <emphasis>
249which</emphasis>
250 parameter for device <emphasis>
251device_spec</emphasis>
252 and copies the results to the <emphasis>
253XkbDescRec</emphasis>
254 it allocated. The remaining fields in the keyboard description are set to
255<emphasis>
256NULL</emphasis>
257. The valid masks for <emphasis>
258which</emphasis>
259 are those listed in Table 6.2. <!-- xref -->
260</para>
261
262
263<para>
264<emphasis>
265XkbGetKeyboard</emphasis>
266 can generate <emphasis>
267BadAlloc</emphasis>
268 protocol errors.
269</para>
270
271
272<para>
273To free the returned keyboard description, use <emphasis>
274XkbFreeKeyboard</emphasis>
275 (see section 6.4). <!-- xref -->
276</para>
277
278
279</sect1>
280<sect1 id='tracking_changes_to_the_keyboard_description_in_the_server'>
281<title>Tracking Changes to the Keyboard Description in the Server</title>
282
283<para>
284The server can generate events whenever its copy of the keyboard description
285for a device changes. Refer to section 14.4 for detailed information on  <!-- xref -->
286tracking changes to the keyboard description.
287</para>
288
289
290</sect1>
291<sect1 id='allocating_and_freeing_a_keyboard_description'>
292<title>Allocating and Freeing a Keyboard Description</title>
293
294<para>
295Applications seldom need to directly allocate a keyboard description; calling
296<emphasis>
297XkbGetKeyboard</emphasis>
298 usually suffices. In the event you need to create a keyboard description from
299scratch, however, use <emphasis>
300XkbAllocKeyboard</emphasis>
301 rather than directly calling <emphasis>
302malloc </emphasis>
303or <emphasis>
304Xmalloc</emphasis>
305.
306</para>
307
308<informaltable frame='none'>
309<tgroup cols='1'>
310<colspec colsep='0'/>
311<tbody>
312  <row rowsep='0'>
313    <entry role='functiondecl'>
314XkbDescRec * <emphasis>
315XkbAllocKeyboard</emphasis>
316(void)
317    </entry>
318  </row>
319</tbody>
320</tgroup>
321</informaltable>
322
323<para>
324If <emphasis>
325XkbAllocKeyboard</emphasis>
326 fails to allocate the keyboard description, it returns <emphasis>
327NULL</emphasis>
328. Otherwise, it returns a pointer to an empty keyboard description structure.
329The <emphasis>
330device_spec</emphasis>
331 field will have been initialized to <emphasis>
332XkbUseCoreKbd</emphasis>
333. You may then either fill in the structure components or use Xkb functions to
334obtain values for the structure components from a keyboard device.
335</para>
336
337
338<para>
339To destroy either an entire an <emphasis>
340XkbDescRec</emphasis>
341 or just some of its members, use <emphasis>
342XkbFreeKeyboard.</emphasis>
343</para>
344
345
346<informaltable frame='none'>
347<tgroup cols='1'>
348<colspec colsep='0'/>
349<tbody>
350  <row rowsep='0'>
351    <entry role='functiondecl'>
352void <emphasis>
353XkbFreeKeyboard</emphasis>
354<emphasis>
355(xkb, which, free_all</emphasis>
356)
357    </entry>
358  </row>
359  <row rowsep='0'>
360    <entry role='functionargdecl'>
361XkbDescPtr <emphasis>
362            xkb</emphasis>
363;            /* keyboard description with components to free */
364    </entry>
365  </row>
366  <row rowsep='0'>
367    <entry role='functionargdecl'>
368unsigned int      <emphasis>
369      which</emphasis>
370;            /* mask selecting components to free */
371    </entry>
372  </row>
373  <row rowsep='0'>
374    <entry role='functionargdecl'>
375Bool <emphasis>
376            free_all</emphasis>
377;            /* <emphasis>
378True</emphasis>
379 =&gt; free all components and <emphasis>
380xkb</emphasis>
381 */
382    </entry>
383</row>
384</tbody>
385</tgroup>
386</informaltable>
387
388<para>
389<emphasis>
390XkbFreeKeyboard</emphasis>
391 frees the components of <emphasis>
392xkb</emphasis>
393 specified by <emphasis>
394which</emphasis>
395 and sets the corresponding values to <emphasis>
396NULL</emphasis>
397. If <emphasis>
398free_all</emphasis>
399 is <emphasis>
400True</emphasis>
401, <emphasis>
402XkbFreeKeyboard</emphasis>
403 frees every non-<emphasis>
404NULL</emphasis>
405 component of <emphasis>
406xkb</emphasis>
407 and then frees the <emphasis>
408xkb</emphasis>
409 structure itself.
410</para>
411
412</sect1>
413</chapter>
414