ch18.xml revision e9fcaa8a
1<chapter id='symbolic_names'>
2<title>Symbolic Names</title>
3
4<para>
5The core protocol does not provide any information to clients other than that
6actually used to interpret events. This makes it difficult to write an
7application that presents the keyboard to a user in an easy-to-understand way.
8Such applications have to examine the vendor string and keycodes to determine
9the type of keyboard connected to the server and then examine keysyms and
10modifier mappings to determine the effects of most modifiers (the <emphasis>
11Shift</emphasis>
12, <emphasis>
13Lock</emphasis>
14 and <emphasis>
15Control</emphasis>
16 modifiers are defined by the core protocol but no semantics are implied for
17any other modifiers).
18</para>
19
20
21<para>
22To make it easier for applications to present a keyboard to the user, Xkb
23supports symbolic names for most components of the keyboard extension. Most of
24these symbolic names are grouped into the <emphasis>
25names</emphasis>
26 component of the keyboard description.
27</para>
28
29<sect1 id='the_xkbnamesrec_structure'>
30<title>The XkbNamesRec Structure</title>
31
32<para>
33The names component of the keyboard description is defined as follows:
34</para>
35
36<para><programlisting>
37#define      XkbKeyNameLength      4
38#define      XkbKeyNumVirtualMods  16
39#define      XkbKeyNumIndicators   32
40#define      XkbKeyNumKbdGroups    4
41#define      XkbMaxRadioGroups     32
42</programlisting></para>
43
44<para><programlisting>
45typedef struct {
46      char      name[XkbKeyNameLength];      /* symbolic key names */
47} <emphasis>XkbKeyNameRec</emphasis>,*XkbKeyNamePtr;
48</programlisting></para>
49
50<para><programlisting>
51typedef struct {
52      char      real[XkbKeyNameLength];
53                /* this key name must be in the keys array */
54      char      alias[XkbKeyNameLength];
55                /* symbolic key name as alias for the key */
56} <emphasis>XkbKeyAliasRec</emphasis>,*XkbKeyAliasPtr;
57</programlisting></para>
58
59<para><programlisting>
60typedef struct _XkbNamesRec {
61      Atom      keycodes;      /* identifies range and meaning of keycodes */
62      Atom      geometry;      /* identifies physical location, size, and shape of keys */
63      Atom      symbols;       /* identifies the symbols logically bound to the keys */
64      Atom      types;         /* identifies the set of key types */
65      Atom      compat;        /* identifies actions for keys using core protocol */
66      Atom      vmods[XkbNumVirtualMods]; /* symbolic names for virtual modifiers */
67      Atom      indicators[XkbNumIndicators];   /* symbolic names for indicators */
68      Atom      groups[XkbNumKbdGroups]; /* symbolic names for keyboard groups */
69      XkbKeyNamePtr      keys;         /* symbolic key name array */
70      XkbKeyAliasPtr     key_aliases;  /* real/alias symbolic name pairs array */
71      Atom *    radio_groups;      /* radio group name array */
72      Atom      phys_symbols;      /* identifies the symbols engraved on the keyboard */
73      unsigned char      num_keys; /* number of keys in the <emphasis> keys</emphasis> array */
74      unsigned char      num_key_aliases;  /* number of keys in the
75                                              <emphasis> key_aliases</emphasis> array */
76      unsigned short     num_rg;      /* number of radio groups */
77} <emphasis>XkbNamesRec</emphasis>,*XkbNamesPtr;      /*
78</programlisting></para>
79
80<para>
81The <emphasis>
82keycodes</emphasis>
83 name identifies the range and meaning of the keycodes returned by the keyboard
84in question. The <emphasis>
85geometry</emphasis>
86 name, on the other hand, identifies the physical location, size and shape of
87the various keys on the keyboard. As an example to distinguish between these
88two names, consider function keys on PC-compatible keyboards. Function keys are
89sometimes above the main keyboard and sometimes to the left of the main
90keyboard, but the same keycode is used for the key that is logically F1
91regardless of physical position. Thus, all PC-compatible keyboards share a
92similar keycodes name but may have different geometry names.
93</para>
94
95<note><para>The keycodes name is intended to be a very general description of
96the keycodes returned by a keyboard; a single keycodes name might cover
97keyboards with differing numbers of keys provided all keys have the same
98semantics when present. For example, 101 and 102 key PC keyboards might use the
99same name. In these cases, applications can use the keyboard <emphasis>
100geometry</emphasis>
101 name to determine which subset of the named keycodes is in use.</para></note>
102
103<para>
104The <emphasis>
105symbols</emphasis>
106 name identifies the symbols logically bound to the keys. The symbols name is a
107human or application-readable description of the intended locale or usage of
108the keyboard with these symbols. The <emphasis>
109phys_symbols</emphasis>
110 name, on the other hand, identifies the symbols actually engraved on the
111keyboard. Given this, the <emphasis>
112symbols</emphasis>
113 name and <emphasis>
114phys_symbols</emphasis>
115 names might be different. For example, the description for a keyboard that has
116English US engravings, but that is using Swiss German symbols might have a
117<emphasis>
118phys_symbols</emphasis>
119 name of "en_US" and a <emphasis>
120symbols</emphasis>
121 name of "de_CH."
122</para>
123
124
125<para>
126The <emphasis>
127types</emphasis>
128 name provides some information about the set of key types (see section 15.2)
129that can be associated with the keyboard. In addition, each key type can have a
130name, and each shift level of a type can have a name. Although these names are
131stored in the map description with each of the types, they are accessed using
132the same methods as the other symbolic names.
133</para>
134
135
136<para>
137The <emphasis>
138compat</emphasis>
139 name provides some information about the rules used to bind actions to keys
140that are changed using core protocol requests.
141</para>
142
143
144<para>
145Xkb provides symbolic names for each of the 4 keyboard groups, 16 virtual
146modifiers, 32 keyboard indicators, and 4 keyboard groups. These names are held
147in the <emphasis>
148vmods</emphasis>
149, <emphasis>
150indicators</emphasis>
151, and <emphasis>
152groups</emphasis>
153 fixed-length arrays.
154</para>
155
156
157<para>
158Each key has a four-byte symbolic name. All of the symbolic key names are held
159in the <emphasis>
160keys</emphasis>
161 array, and <emphasis>
162num_keys</emphasis>
163 reports the number of entries that are in the keys array. For each key, the
164key name links keys with similar functions or in similar positions on keyboards
165that report different keycodes. For example, the <emphasis>
166F1</emphasis>
167 key may emit keycode 23 on one keyboard and keycode 86 on another. By naming
168this key "FK01" on both keyboards, the keyboard layout designer can reuse parts
169of keyboard descriptions for different keyboards.
170</para>
171
172
173<para>
174Key aliases allow the keyboard layout designer to assign multiple key names to
175a single key. This allows the keyboard layout designer to refer to keys using
176either their position or their "function." For example, a keyboard layout
177designer may wish to refer to the left arrow key on a PC keyboard using the
178ISO9995-5 positional specification of A31 or using the functional specification
179of LEFT. The <emphasis>
180key_aliases</emphasis>
181 field holds a variable-length array of real and alias key name pairs, and the
182total number of entries in the <emphasis>
183key_aliases</emphasis>
184 array is held in <emphasis>
185num_key_aliases</emphasis>
186. For each real and alias key name pair, the <emphasis>
187real</emphasis>
188 field refers to the a name in the keys array, and the <emphasis>
189alias</emphasis>
190 field refers to the alias for that key. Using the previous example, the
191keyboard designer may use the name A31 in the keys array, but also define the
192name LEFT as an alias for A31 in the <emphasis>
193key_aliases</emphasis>
194 array.
195</para>
196
197<note><para>Key aliases defined in the geometry component of a keyboard mapping
198(see Chapter 13) override those defined in the keycodes component of the server
199database, which are stored in the <emphasis>
200XkbNamesRec</emphasis>
201 (<emphasis>
202xkb-&gt;names</emphasis>
203). Therefore, consider the key aliases defined by the geometry before
204considering key aliases supplied by the <emphasis>
205XkbNamesRec</emphasis>
206.</para></note>
207
208<para>
209A radio group is a set of keys whose behavior simulates a set of radio buttons.
210Once a key in a radio group is pressed, it stays logically depressed until
211another key in the group is pressed, at which point the previously depressed
212key is logically released. Consequently, at most one key in a radio group can
213be logically depressed at one time.
214</para>
215
216
217<para>
218Each radio group in the keyboard description can have a name. These names are
219held in the variable-length array <emphasis>
220radio_groups</emphasis>
221, and <emphasis>
222num_rg</emphasis>
223 tells how many elements are in the <emphasis>
224radio_groups</emphasis>
225 array.
226</para>
227
228
229</sect1>
230<sect1 id='symbolic_names_masks'>
231<title>Symbolic Names Masks</title>
232
233<para>
234Xkb provides several functions that work with symbolic names. Each of these
235functions uses a mask to specify individual fields of the structures described
236above. These masks and their relationships to the fields in a keyboard
237description are shown in Table 18.1.
238</para>
239
240<table frame='none'>
241<title>Symbolic Names Masks</title>
242<tgroup cols='4'>
243<colspec colsep='0'/>
244<colspec colsep='0'/>
245<colspec colsep='0'/>
246<colspec colsep='0'/>
247<thead>
248<row rowsep='0'>
249  <entry>Mask Bit</entry>
250  <entry>Value</entry>
251  <entry>Keyboard Component</entry>
252  <entry>Field</entry>
253</row>
254</thead>
255<tbody>
256<row rowsep='0'>
257    <entry>XkbKeycodesNameMask</entry>
258    <entry>(1&lt;&lt;0)</entry>
259    <entry>Xkb-&gt;names</entry>
260    <entry>keycodes</entry>
261</row>
262<row rowsep='0'>
263    <entry>XkbGeometryNameMask</entry>
264    <entry>(1&lt;&lt;1)</entry>
265    <entry>Xkb-&gt;names</entry>
266    <entry>geometry</entry>
267</row>
268<row rowsep='0'>
269    <entry>XkbSymbolsNameMask</entry>
270    <entry>(1&lt;&lt;2)</entry>
271    <entry>Xkb-&gt;names</entry>
272    <entry>symbols</entry>
273</row>
274<row rowsep='0'>
275    <entry>XkbPhysSymbolsNameMask</entry>
276    <entry>(1&lt;&lt;3)</entry>
277    <entry>Xkb-&gt;names</entry>
278    <entry>phys_symbols</entry>
279</row>
280<row rowsep='0'>
281    <entry>XkbTypesNameMask</entry>
282    <entry>(1&lt;&lt;4)</entry>
283    <entry>Xkb-&gt;names</entry>
284    <entry>type</entry>
285</row>
286<row rowsep='0'>
287    <entry>XkbCompatNameMask</entry>
288    <entry>(1&lt;&lt;5)</entry>
289    <entry>Xkb-&gt;names</entry>
290    <entry>compat</entry>
291</row>
292<row rowsep='0'>
293    <entry>XkbKeyTypeNamesMask</entry>
294    <entry>(1&lt;&lt;6)</entry>
295    <entry>Xkb-&gt;map</entry>
296    <entry>type[*].name</entry>
297</row>
298<row rowsep='0'>
299    <entry>XkbKTLevelNamesMask</entry>
300    <entry>(1&lt;&lt;7)</entry>
301    <entry>Xkb-&gt;map</entry>
302    <entry>type[*].lvl_names[*]</entry>
303</row>
304<row rowsep='0'>
305    <entry>XkbIndicatorNamesMask</entry>
306    <entry>(1&lt;&lt;8)</entry>
307    <entry>Xkb-&gt;names</entry>
308    <entry>indicators[*]</entry>
309</row>
310<row rowsep='0'>
311    <entry>XkbKeyNamesMask</entry>
312    <entry>(1&lt;&lt;9)</entry>
313    <entry>Xkb-&gt;names</entry>
314    <entry>keys[*], num_keys</entry>
315</row>
316<row rowsep='0'>
317    <entry>XkbKeyAliasesMask</entry>
318    <entry>(1&lt;&lt;10)</entry>
319    <entry>Xkb-&gt;names</entry>
320    <entry>key_aliases[*], num_key_aliases</entry>
321</row>
322<row rowsep='0'>
323    <entry>XkbVirtualModNamesMask</entry>
324    <entry>(1&lt;&lt;11)</entry>
325    <entry>Xkb-&gt;names</entry>
326    <entry>vmods[*]</entry>
327</row>
328<row rowsep='0'>
329    <entry>XkbGroupNamesMask</entry>
330    <entry>(1&lt;&lt;12)</entry>
331    <entry>Xkb-&gt;names</entry>
332    <entry>groups[*]</entry>
333</row>
334<row rowsep='0'>
335    <entry>XkbRGNamesMask</entry>
336    <entry>(1&lt;&lt;13)</entry>
337    <entry>Xkb-&gt;names</entry>
338    <entry>radio_groups[*], num_rg</entry>
339</row>
340<row rowsep='0'>
341    <entry>XkbComponentNamesMask</entry>
342    <entry>(0x3f)</entry>
343    <entry>Xkb-&gt;names</entry>
344    <entry>
345<para>keycodes,</para>
346<para>geometry,</para>
347<para>symbols,</para>
348<para>physical symbols,</para>
349<para>types, and</para>
350<para>compatibility map</para>
351    </entry>
352</row>
353<row rowsep='0'>
354    <entry>XkbAllNamesMask</entry>
355    <entry>(0x3fff)</entry>
356    <entry>Xkb-&gt;names</entry>
357    <entry>all name components</entry>
358  </row>
359</tbody>
360</tgroup>
361</table>
362
363</sect1>
364<sect1 id='getting_symbolic_names_from_the_server'>
365<title>Getting Symbolic Names From the Server</title>
366
367<para>
368To obtain symbolic names from the server, use <emphasis>
369XkbGetNames</emphasis>
370.
371</para>
372
373<informaltable frame='none'>
374<tgroup cols='1'>
375<colspec colsep='0'/>
376<tbody>
377  <row rowsep='0'>
378    <entry role='functiondecl'>
379Status <emphasis>
380XkbGetNames</emphasis>
381(<emphasis>
382dpy, which, Xkb</emphasis>
383)
384    </entry>
385  </row>
386  <row rowsep='0'>
387    <entry role='functionargdecl'>
388Display *      <emphasis>
389dpy</emphasis>
390;      /* connection to the X server */
391    </entry>
392  </row>
393  <row rowsep='0'>
394    <entry role='functionargdecl'>
395unsigned int      <emphasis>
396which</emphasis>
397;      /* mask of names or map components to be updated */
398    </entry>
399  </row>
400  <row rowsep='0'>
401    <entry role='functionargdecl'>
402XkbDescPtr      <emphasis>
403xkb</emphasis>
404      /* keyboard description to be updated */
405    </entry>
406</row>
407</tbody>
408</tgroup>
409</informaltable>
410
411<para>
412<emphasis>
413XkbGetNames</emphasis>
414 retrieves symbolic names for the components of the keyboard extension from the
415X server. The <emphasis>
416which</emphasis>
417 parameter specifies the name components to be updated in the <emphasis>
418xkb</emphasis>
419 parameter, and is the bitwise inclusive OR of the valid names mask bits
420defined in Table 18.1.
421</para>
422
423
424<para>
425If the <emphasis>
426names</emphasis>
427 field of the keyboard description <emphasis>
428xkb</emphasis>
429 is <emphasis>
430NULL</emphasis>
431, <emphasis>
432XkbGetNames</emphasis>
433 allocates and initializes the <emphasis>
434names</emphasis>
435 component of the keyboard description before obtaining the values specified by
436<emphasis>
437which</emphasis>
438. If the <emphasis>
439names</emphasis>
440 field of <emphasis>
441xkb</emphasis>
442 is not <emphasis>
443NULL</emphasis>
444, <emphasis>
445XkbGetNames</emphasis>
446 obtains the values specified by <emphasis>
447which</emphasis>
448 and copies them into the keyboard description <emphasis>
449Xkb</emphasis>
450.
451</para>
452
453
454<para>
455If the <emphasis>
456map</emphasis>
457 component of the <emphasis>
458xkb</emphasis>
459 parameter is <emphasis>
460NULL</emphasis>
461, <emphasis>
462XkbGetNames</emphasis>
463 does not retrieve type or shift level names, even if <emphasis>
464XkbKeyTypeNamesMask</emphasis>
465 or <emphasis>
466XkbKTLevelNamesMask</emphasis>
467 are set in <emphasis>
468which</emphasis>
469.
470</para>
471
472
473<para>
474<emphasis>
475XkbGetNames</emphasis>
476 can return <emphasis>
477Success</emphasis>
478, or <emphasis>
479BadAlloc</emphasis>
480, <emphasis>
481BadLength</emphasis>
482, <emphasis>
483BadMatch</emphasis>
484, and <emphasis>
485BadImplementation</emphasis>
486 errors.
487</para>
488
489
490<para>
491To free symbolic names, use <emphasis>
492XkbFreeNames</emphasis>
493 (see section 18.6)
494</para>
495
496
497</sect1>
498<sect1 id='changing_symbolic_names_on_the_server'>
499<title>Changing Symbolic Names on the Server</title>
500
501<para>
502To change the symbolic names in the server, first modify a local copy of the
503keyboard description and then use either <emphasis>
504XkbSetNames,</emphasis>
505 or, to save network traffic, use a <emphasis>
506XkbNameChangesRec</emphasis>
507structure and call <emphasis>
508XkbChangeNames</emphasis>
509 to download the changes to the server. <emphasis>
510XkbSetNames</emphasis>
511 and <emphasis>
512XkbChangeNames</emphasis>
513 can generate <emphasis>
514BadAlloc</emphasis>
515, <emphasis>
516BadAtom</emphasis>
517, <emphasis>
518BadLength</emphasis>
519, <emphasis>
520BadMatch,</emphasis>
521 and <emphasis>
522BadImplementation</emphasis>
523 errors.
524</para>
525
526<informaltable frame='none'>
527<tgroup cols='1'>
528<colspec colsep='0'/>
529<tbody>
530  <row rowsep='0'>
531    <entry role='functiondecl'>
532Bool <emphasis>
533XkbSetNames</emphasis>
534(<emphasis>
535dpy, which, first_type, num_types, xkb</emphasis>
536)
537    </entry>
538  </row>
539  <row rowsep='0'>
540    <entry role='functionargdecl'>
541Display *      <emphasis>
542dpy</emphasis>
543;            /* connection to the X server */
544    </entry>
545  </row>
546  <row rowsep='0'>
547    <entry role='functionargdecl'>
548unsigned int      <emphasis>
549which</emphasis>
550;            /* mask of names or map components to be changed */
551    </entry>
552  </row>
553  <row rowsep='0'>
554    <entry role='functionargdecl'>
555unsigned int      <emphasis>
556first_type</emphasis>
557      ;      /* first type whose name is to be changed */
558    </entry>
559  </row>
560  <row rowsep='0'>
561    <entry role='functionargdecl'>
562unsigned int      <emphasis>
563num_types</emphasis>
564;            /* number of types for which names are to be changed */
565    </entry>
566  </row>
567  <row rowsep='0'>
568    <entry role='functionargdecl'>
569XkbDescPtr      <emphasis>
570xkb</emphasis>
571;            /* keyboard description from which names are to be taken */
572    </entry>
573</row>
574</tbody>
575</tgroup>
576</informaltable>
577
578<para>
579Use<emphasis>
580 XkbSetNames</emphasis>
581 to change many names at the same time. For each bit set in <emphasis>
582which</emphasis>
583, <emphasis>
584XkbSetNames</emphasis>
585 takes the corresponding value (or values in the case of arrays) from the
586keyboard description <emphasis>
587xkb</emphasis>
588 and sends it to the server.
589</para>
590
591
592<para>
593The <emphasis>
594first_type</emphasis>
595 and <emphasis>
596num_types</emphasis>
597 arguments are used only if <emphasis>
598XkbKeyTypeNamesMask</emphasis>
599 or <emphasis>
600XkbKTLevelNamesMask</emphasis>
601 is set in <emphasis>
602which</emphasis>
603 and specify a subset of the types for which the corresponding names are to be
604changed. If either or both of these mask bits are set but the specified types
605are illegal, <emphasis>
606XkbSetNames</emphasis>
607 returns <emphasis>
608False</emphasis>
609 and does not update any of the names specified in <emphasis>
610which</emphasis>
611. The specified types are illegal if <emphasis>
612xkb</emphasis>
613 does not include a map component or if <emphasis>
614first_type</emphasis>
615 and <emphasis>
616num_types</emphasis>
617 specify types that are not defined in the keyboard description.
618</para>
619
620
621<sect2>
622<title/>
623
624<sect3 id='the_xkbnamechangesrec_structure'>
625<title>The XkbNameChangesRec Structure</title>
626
627<para>
628The <emphasis>
629XkbNameChangesRec</emphasis>
630 allows applications to identify small modifications to the symbolic names and
631effectively reduces the amount of traffic sent to the server:
632</para>
633
634<para><programlisting>
635typedef struct _XkbNameChanges {
636      unsigned int      changed;            /* name components that have
637                                               changed */
638      unsigned char      first_type;        /* first key type with a new
639                                               name */
640      unsigned char      num_types;         /* number of types with new
641                                               names */
642      unsigned char      first_lvl;         /* first key type with new level
643                                               names */
644      unsigned char      num_lvls;          /* number of key types with new
645                                               level names */
646      unsigned char      num_aliases;       /* if key aliases changed,
647                                               total number of key aliases */
648      unsigned char      num_rg;            /* if radio groups changed, total
649                                               number of radio groups */
650      unsigned char      first_key;         /* first key with a new name */
651      unsigned char      num_keys;          /* number of keys with new names
652                                               */
653      unsigned short      changed_vmods;    /* mask of virtual
654                                               modifiers for which names have changed */
655      unsigned long      changed_indicators;  /* mask of indicators
656                                                 for which names were changed */
657      unsigned char       changed_groups;   /* mask of groups for
658                                               which names were changed */
659} <emphasis>XkbNameChangesRec</emphasis>, *XkbNameChangesPtr
660</programlisting></para>
661
662<para>
663The <emphasis>
664changed</emphasis>
665 field specifies the name components that have changed and is the bitwise
666inclusive OR of the valid names mask bits defined in Table 18.1. The rest of
667the fields in the structure specify the ranges that have changed for the
668various kinds of symbolic names, as shown in Table 18.2.
669</para>
670
671<table frame='none'>
672<title>XkbNameChanges Fields</title>
673<tgroup cols='4'>
674<colspec colsep='0'/>
675<colspec colsep='0'/>
676<colspec colsep='0'/>
677<colspec colsep='0'/>
678<thead>
679<row rowsep='0'>
680  <entry>Mask</entry>
681  <entry>Fields</entry>
682  <entry>Component</entry>
683  <entry>Field</entry>
684</row>
685</thead>
686<tbody>
687<row rowsep='0'>
688    <entry>XkbKeyTypeNamesMask</entry>
689    <entry>
690<para>first_type,</para>
691<para>num_types</para>
692    </entry>
693    <entry>Xkb-&gt;map</entry>
694    <entry>type[*].name</entry>
695</row>
696<row rowsep='0'>
697    <entry>XkbKTLevelNamesMask</entry>
698    <entry>
699<para>first_lvl,</para>
700<para>num_lvls</para>
701    </entry>
702    <entry>Xkb-&gt;map</entry>
703    <entry>type[*].lvl_names[*]</entry>
704</row>
705<row rowsep='0'>
706    <entry>XkbKeyAliasesMask</entry>
707    <entry>num_aliases</entry>
708    <entry>Xkb-&gt;names</entry>
709    <entry>key_aliases[*]</entry>
710</row>
711<row rowsep='0'>
712    <entry>XkbRGNamesMask</entry>
713    <entry>num_rg</entry>
714    <entry>Xkb-&gt;names</entry>
715    <entry>radio_groups[*]</entry>
716</row>
717<row rowsep='0'>
718    <entry>XkbKeyNamesMask</entry>
719    <entry>
720<para>first_key,</para>
721<para>num_keys</para>
722    </entry>
723    <entry>Xkb-&gt;names</entry>
724    <entry>keys[*]</entry>
725</row>
726<row rowsep='0'>
727    <entry>XkbVirtualModNamesMask</entry>
728    <entry>changed_vmods</entry>
729    <entry>Xkb-&gt;names</entry>
730    <entry>vmods[*]</entry>
731</row>
732<row rowsep='0'>
733    <entry>XkbIndicatorNamesMask</entry>
734    <entry>changed_indicators</entry>
735    <entry>Xkb-&gt;names</entry>
736    <entry>indicators[*]</entry>
737</row>
738<row rowsep='0'>
739    <entry>XkbGroupNamesMask</entry>
740    <entry>changed_groups</entry>
741    <entry>Xkb-&gt;names</entry>
742    <entry>groups[*]</entry>
743  </row>
744</tbody>
745</tgroup>
746</table>
747
748<para>
749<emphasis>
750XkbChangeNames</emphasis>
751 provides a more flexible method for changing symbolic names than <emphasis>
752XkbSetNames</emphasis>
753 and requires the use of an <emphasis>
754XkbNameChangesRec</emphasis>
755 structure.
756</para>
757
758<informaltable frame='none'>
759<tgroup cols='1'>
760<colspec colsep='0'/>
761<tbody>
762  <row rowsep='0'>
763    <entry role='functiondecl'>
764Bool <emphasis>
765XkbChangeNames</emphasis>
766(<emphasis>
767dpy, xkb, changes</emphasis>
768)
769    </entry>
770  </row>
771  <row rowsep='0'>
772    <entry role='functionargdecl'>
773Display *            <emphasis>
774dpy</emphasis>
775;            /* connection to the X server */
776    </entry>
777  </row>
778  <row rowsep='0'>
779    <entry role='functionargdecl'>
780XkbDescPtr      <emphasis>
781      xkb</emphasis>
782;            /* keyboard description from which names are to be taken */
783    </entry>
784  </row>
785  <row rowsep='0'>
786    <entry role='functionargdecl'>
787XkbNameChangesPtr      <emphasis>
788      changes</emphasis>
789;            /* names map components to be updated on the server */
790    </entry>
791</row>
792</tbody>
793</tgroup>
794</informaltable>
795
796<para>
797<emphasis>
798XkbChangeNames</emphasis>
799 copies any names specified by <emphasis>
800changes</emphasis>
801 from the keyboard description, <emphasis>
802xkb</emphasis>
803, to the X server specified by <emphasis>
804dpy</emphasis>
805.<emphasis>
806 XkbChangeNames</emphasis>
807 aborts and returns <emphasis>
808False</emphasis>
809 if any illegal type names or type shift level names are specified by <emphasis>
810changes</emphasis>
811.
812</para>
813
814</sect3>
815</sect2>
816</sect1>
817<sect1 id='tracking_name_changes'>
818<title>Tracking Name Changes</title>
819
820<para>
821Whenever a symbolic name changes in the server’s keyboard description, the
822server sends a <emphasis>
823XkbNamesNotify</emphasis>
824 event to all interested clients. To receive name notify events, use <emphasis>
825XkbSelectEvents</emphasis>
826 (see section 4.3) with <emphasis>
827XkbNamesNotifyMask</emphasis>
828 in both the <emphasis>
829bits_to_change</emphasis>
830 and <emphasis>
831values_for_bits</emphasis>
832 parameters.
833</para>
834
835
836<para>
837To receive events for only specific names, use <emphasis>
838XkbSelectEventDetails</emphasis>
839. Set the <emphasis>
840event_type</emphasis>
841 parameter to <emphasis>
842XkbNamesNotify</emphasis>
843, and set both the <emphasis>
844bits_to_change </emphasis>
845and<emphasis>
846 values_for_bits</emphasis>
847 detail parameter to a mask composed of a bitwise OR of masks in Table 18.1.
848</para>
849
850
851<para>
852The structure for the <emphasis>
853XkbNamesNotify</emphasis>
854 event is defined as follows:
855</para>
856
857<para><programlisting>
858typedef struct {
859      int      type;                  /* Xkb extension base event code */
860      unsigned long      serial;      /* X server serial number for
861                                         event */
862      Bool      send_event;           /* <emphasis>True</emphasis>
863                                         =&gt; synthetically generated */
864      Display *      display;         /* server connection where event
865                                         generated */
866      Time      time;                 /* server time when event generated */
867      int      xkb_type;              /* <emphasis>XkbNamesNotify</emphasis> */
868      int      device;                /* Xkb device ID, will not be
869                                         <emphasis>XkbUseCoreKbd</emphasis> */
870      unsigned int      changed;      /* mask of name components
871that have changed */
872      int      first_type;            /* first key type with a new name */
873      int      num_types;             /* number of types with new names */
874      int      first_lvl;             /* first key type with new level names */
875      int      num_lvls;              /* number of key types with new level names */
876      int      num_aliases;           /* if key aliases changed, total number
877                                         of key aliases */
878      int      num_radio_groups;      /* if radio groups changed,
879                                         total number of radio groups */
880      unsigned int      changed_vmods;  /* mask of virtual modifiers for
881                                           which names have changed */
882      unsigned int      changed_groups; /* mask of groups for
883                                           which names were changed */
884      unsigned int      changed_indicators;  /* mask of indicators for which
885                                                names were changed */
886      int      first_key;             /* first key with a new name */
887      int      num_keys;              /* number of keys with new names */
888} <emphasis>XkbNamesNotifyEvent</emphasis>;
889</programlisting></para>
890
891<para>
892The <emphasis>
893changed</emphasis>
894 field specifies the name components that have changed and is the bitwise
895inclusive OR of the valid names mask bits defined in Table 18.1. The other
896fields in this event are interpreted as the like-named fields in an <emphasis>
897XkbNameChangesRec</emphasis> , as previously defined.
898</para>
899
900
901<para>
902When your application receives a X<emphasis>
903kbNamesNotify</emphasis>
904 event, you can note the changed names in a changes structure using <emphasis>
905XkbNoteNameChanges</emphasis>
906.
907</para>
908
909<informaltable frame='none'>
910<tgroup cols='1'>
911<colspec colsep='0'/>
912<tbody>
913  <row rowsep='0'>
914    <entry role='functiondecl'>
915void <emphasis>
916XkbNoteNameChanges</emphasis>
917(<emphasis>
918old</emphasis>
919,<emphasis>
920 new</emphasis>
921,<emphasis>
922 wanted</emphasis>
923)
924    </entry>
925  </row>
926  <row rowsep='0'>
927    <entry role='functionargdecl'>
928XkbNameChangesPtr            <emphasis>
929old</emphasis>
930;            /* <emphasis>
931XkbNameChanges</emphasis>
932 structure to be updated */
933    </entry>
934  </row>
935  <row rowsep='0'>
936    <entry role='functionargdecl'>
937XkbNamesNotifyEvent *            <emphasis>
938new</emphasis>
939;            /* event from which changes are to be copied */
940    </entry>
941  </row>
942  <row rowsep='0'>
943    <entry role='functionargdecl'>
944unsigned int            <emphasis>
945wanted</emphasis>
946;            /* types of names for which changes are to be noted */
947    </entry>
948</row>
949</tbody>
950</tgroup>
951</informaltable>
952
953<para>
954The <emphasis>
955wanted</emphasis>
956 parameter is the bitwise inclusive OR of the valid names mask bits shown in
957Table 18.1. <emphasis>
958XkbNoteNameChanges</emphasis>
959 copies any changes that are reported in <emphasis>
960new</emphasis>
961 and specified in <emphasis>
962wanted</emphasis>
963 into the changes record specified by <emphasis>
964old</emphasis>
965.
966</para>
967
968
969<para>
970To update the local copy of the keyboard description with the actual values,
971pass to <emphasis>
972XkbGetNameChanges</emphasis>
973 the results of one or more calls to <emphasis>
974XkbNoteNameChanges</emphasis>
975.
976</para>
977
978
979<informaltable frame='none'>
980<tgroup cols='1'>
981<colspec colsep='0'/>
982<tbody>
983  <row rowsep='0'>
984    <entry role='functiondecl'>
985Status <emphasis>
986XkbGetNameChanges</emphasis>
987(<emphasis>
988dpy</emphasis>
989,<emphasis>
990 xkb</emphasis>
991,<emphasis>
992 changes</emphasis>
993)
994    </entry>
995  </row>
996  <row rowsep='0'>
997    <entry role='functionargdecl'>
998Display *            <emphasis>
999dpy</emphasis>
1000;            /* connection to the X server */
1001    </entry>
1002  </row>
1003  <row rowsep='0'>
1004    <entry role='functionargdecl'>
1005XkbDescPtr            <emphasis>
1006xkb</emphasis>
1007;            /* keyboard description to which names are copied */
1008    </entry>
1009  </row>
1010  <row rowsep='0'>
1011    <entry role='functionargdecl'>
1012XkbNameChangesPtr            <emphasis>
1013changes</emphasis>
1014;            /* names components to be obtained from the server */
1015    </entry>
1016</row>
1017</tbody>
1018</tgroup>
1019</informaltable>
1020
1021<para>
1022<emphasis>
1023XkbGetNameChanges</emphasis>
1024 examines the <emphasis>
1025changes</emphasis>
1026 parameter, retrieves the necessary information from the server, and places the
1027results into the <emphasis>
1028xkb</emphasis>
1029 keyboard description.
1030</para>
1031
1032
1033<para>
1034<emphasis>
1035XkbGetNamesChanges</emphasis>
1036 can generate <emphasis>
1037BadAlloc</emphasis>
1038, <emphasis>
1039BadImplementation,</emphasis>
1040 and <emphasis>
1041BadMatch</emphasis>
1042 errors.
1043</para>
1044
1045
1046</sect1>
1047<sect1 id='allocating_and_freeing_symbolic_names'>
1048<title>Allocating and Freeing Symbolic Names</title>
1049
1050<para>
1051Most applications do not need to directly allocate symbolic names structures.
1052Do not allocate a names structure directly using <emphasis>
1053malloc</emphasis>
1054 or <emphasis>
1055Xmalloc</emphasis>
1056 if your application changes the number of key aliases or radio groups or
1057constructs a symbolic names structure without loading the necessary components
1058from the X server. Instead use <emphasis>
1059XkbAllocNames</emphasis>
1060.
1061</para>
1062
1063<informaltable frame='none'>
1064<tgroup cols='1'>
1065<colspec colsep='0'/>
1066<tbody>
1067  <row rowsep='0'>
1068    <entry role='functiondecl'>
1069Status <emphasis>
1070XkbAllocNames</emphasis>
1071(<emphasis>
1072xkb, which, num_rg, num_key_aliases)</emphasis>
1073    </entry>
1074  </row>
1075  <row rowsep='0'>
1076    <entry role='functionargdecl'>
1077XkbDescPtr      <emphasis>
1078xkb;</emphasis>
1079      /* keyboard description for which names are to be allocated */
1080    </entry>
1081  </row>
1082  <row rowsep='0'>
1083    <entry role='functionargdecl'>
1084unsigned int      <emphasis>
1085which;</emphasis>
1086      /* mask of names to be allocated */
1087    </entry>
1088  </row>
1089  <row rowsep='0'>
1090    <entry role='functionargdecl'>
1091int      <emphasis>
1092num_rg;</emphasis>
1093      /* total number of radio group names needed */
1094    </entry>
1095  </row>
1096  <row rowsep='0'>
1097    <entry role='functionargdecl'>
1098int      <emphasis>
1099num_key_aliases;</emphasis>
1100      /* total number of key aliases needed */
1101    </entry>
1102</row>
1103</tbody>
1104</tgroup>
1105</informaltable>
1106
1107<para>
1108<emphasis>
1109XkbAllocNames</emphasis>
1110 can return <emphasis>
1111BadAlloc</emphasis>
1112, <emphasis>
1113BadMatch,</emphasis>
1114 and <emphasis>
1115BadValue</emphasis>
1116 errors.<emphasis>
1117 </emphasis>
1118The <emphasis>
1119which</emphasis>
1120 parameter is the bitwise inclusive OR of the valid names mask bits defined in
1121Table 18.1.
1122</para>
1123
1124
1125<para>
1126Do not free symbolic names structures directly using <emphasis>
1127free</emphasis>
1128 or <emphasis>
1129XFree</emphasis>
1130. Use <emphasis>
1131XkbFreeNames</emphasis>
1132 instead.
1133</para>
1134
1135
1136<informaltable frame='none'>
1137<tgroup cols='1'>
1138<colspec colsep='0'/>
1139<tbody>
1140  <row rowsep='0'>
1141    <entry role='functiondecl'>
1142void <emphasis>
1143XkbFreeNames</emphasis>
1144(<emphasis>
1145xkb, which, free_map)</emphasis>
1146    </entry>
1147  </row>
1148  <row rowsep='0'>
1149    <entry role='functionargdecl'>
1150XkbDescPtr      <emphasis>
1151xkb</emphasis>
1152;      /* keyboard description for which names are to be freed */
1153    </entry>
1154  </row>
1155  <row rowsep='0'>
1156    <entry role='functionargdecl'>
1157unsigned int      <emphasis>
1158which</emphasis>
1159;      /* mask of names components to be freed */
1160    </entry>
1161  </row>
1162  <row rowsep='0'>
1163    <entry role='functionargdecl'>
1164Bool      <emphasis>
1165free_map</emphasis>
1166;      /* <emphasis>
1167True</emphasis>
1168 =&gt; XkbNamesRec structure itself should be freed */
1169    </entry>
1170</row>
1171</tbody>
1172</tgroup>
1173</informaltable>
1174
1175<para>
1176The <emphasis>
1177which</emphasis>
1178 parameter is the bitwise inclusive OR of the valid names mask bits defined in
1179Table 18.1.
1180</para>
1181</sect1>
1182</chapter>
1183