ch05.xml revision e9fcaa8a
1<chapter id='keyboard_state'>
2<title>Keyboard State</title>
3
4<para>
5Keyboard state encompasses all of the transitory information necessary to map a physical key press or release to an appropriate event. The Xkb keyboard state consists of primitive components and additional derived components that are maintained for efficiency reasons. Figure 5.1 shows the components of Xkb keyboard state and their relationships.
6</para>
7
8<mediaobject>
9<!-- <title>Keyboard State Description</title> -->
10 <imageobject> <imagedata format="SVG" fileref="XKBlib-2.svg"/>
11 </imageobject>
12<caption>Xkb State</caption>
13</mediaobject>
14
15
16<sect1 id='keyboard_state_description'>
17<title>Keyboard State Description</title>
18<para>
19The Xkb keyboard state is comprised of the state of all keyboard modifiers, the keyboard group, and the state of the pointer buttons. These are grouped into the following components:
20</para>
21
22<itemizedlist>
23<listitem>
24  <para>
25The locked group and locked modifiers
26  </para>
27</listitem>
28<listitem>
29  <para>
30The latched group and latched modifiers
31  </para>
32</listitem>
33<listitem>
34  <para>
35The base group and base modifiers
36  </para>
37</listitem>
38<listitem>
39  <para>
40The effective group and effective modifiers
41  </para>
42</listitem>
43<listitem>
44  <para>
45The state of the core pointer buttons
46  </para>
47</listitem>
48</itemizedlist>
49
50<para>
51The <emphasis>
52modifiers</emphasis>
53 are <emphasis>
54Shift</emphasis>
55, <emphasis>
56Lock</emphasis>
57, <emphasis>
58Control</emphasis>
59, and <emphasis>
60Mod1</emphasis>
61-<emphasis>
62Mod5</emphasis>
63, as defined by the core protocol. A modifier can be thought of as a toggle that is either set or unset. All modifiers are initially unset. When a modifier is locked, it is set and remains set for all future key events, until it is explicitly unset. A latched modifier is set, but automatically unsets after the next key event that does not change the keyboard state. Locked and latched modifier state can be changed by keyboard activity or via Xkb extension library functions.
64</para>
65
66
67<para>
68The Xkb extension provides support for <emphasis>
69keysym</emphasis>
70 <emphasis>
71groups</emphasis>
72, as defined by ISO9995:
73</para>
74
75
76<variablelist>
77  <varlistentry>
78    <term>Group</term>
79    <listitem>
80      <para>
81A logical state of a keyboard providing access to a collection of characters.
82A group usually contains a set of characters that logically belong together
83and that may be arranged on several shift levels within that group.
84      </para>
85    </listitem>
86  </varlistentry>
87</variablelist>
88
89
90
91<para>
92The Xkb extension supports up to four keysym groups. Groups are named beginning with one and indexed beginning with zero. All group states are indicated using the group index. At any point in time, there is zero or one locked group, zero or one latched group, and one base group. When a group is locked, it supersedes any previous locked group and remains the locked group for all future key events, until a new group is locked. A latched group applies only to the next key event that does not change the keyboard state. The locked and latched group can be changed by keyboard activity or via Xkb extension library functions.
93</para>
94
95
96<para>
97Changing to a different group changes the keyboard state to produce characters from a different group. Groups are typically used to switch between keysyms of different languages and locales.
98</para>
99
100
101<para>
102The <emphasis>
103pointer buttons</emphasis>
104 are <emphasis>
105Button1</emphasis>
106 - <emphasis>
107Button5</emphasis>
108, as defined by the core protocol.
109</para>
110
111
112<para>
113The <emphasis>
114base group</emphasis>
115 and <emphasis>
116base modifiers</emphasis>
117 represent keys that are physically or logically down. These
118and the pointer buttons can be changed by keyboard activity and
119not by Xkb requests. It is possible for a key to be logically
120down, but not physically down, and neither latched nor locked.
121<footnote><para>
122Keys may be logically down when they are physically up because
123of their electrical properties or because of the keyboard extension
124in the X server having filtered the key release, for esoteric reasons.
125</para></footnote>
126
127</para>
128
129
130<para>
131The <emphasis>
132effective modifiers</emphasis>
133 are the bitwise union of the locked, latched, and the base modifiers.
134</para>
135
136
137<para>
138The <emphasis>
139effective group</emphasis>
140 is the arithmetic sum of the group indices of the latched group, locked group, and base group, which is then normalized by some function. The result is a meaningful group index.
141</para>
142
143<simplelist type='vert' columns='1'>
144<member>
145n = number of keyboard groups, 1&lt;= n &lt;= 4
146</member>
147
148<member>
1490 &lt;= any of locked, latched, or base group &lt; n
150</member>
151
152<member>
153effective group = f(locked group + latched group + base group)
154</member>
155</simplelist>
156
157<para>
158The function f ensures that the effective group is within range. The precise function is specified for the keyboard and can be retrieved through the keyboard description. It may wrap around, clamp down, or default. Few applications will actually examine the effective group, and far fewer still will examine the locked, latched, and base groups.
159</para>
160
161
162<para>
163There are two circumstances under which groups are normalized:
164</para>
165
166<orderedlist>
167  <listitem><para>
168The global locked or effective group changes. In this case, the changed group is normalized into range according to the settings of the <emphasis>
169groups_wrap</emphasis>
170 field of the <emphasis>
171XkbControlsRec</emphasis>
172 structure for the keyboard (see section 10.7.1). <!-- xref -->
173  </para></listitem>
174  <listitem><para>
175
176The Xkb library is interpreting an event with an effective group that is legal for the keyboard as a whole, but not for the key in question. In this case, the group to use for this event only is determined using the <emphasis>
177group_info</emphasis>
178 field of the key symbol mapping (<emphasis>
179XkbSymMapRec</emphasis>
180) for the event key.
181  </para></listitem>
182</orderedlist>
183
184<para>
185Each nonmodifier key on a keyboard has zero or more symbols, or keysyms, associated with it. These are the logical symbols that the key can generate when it is pressed. The set of all possible keysyms for a keyboard is divided into groups. Each key is associated with zero or more groups; each group contains one or more symbols. When a key is pressed, the determination of which symbol for the key is selected is based on the effective group and the shift level, which is determined by which modifiers are set.
186</para>
187
188
189<para>
190A client that does not explicitly call Xkb functions, but that otherwise makes use of an X library containing the Xkb extension, will have keyboard state represented in bits 0 - 14 of the state field of events that report modifier and button state. Such a client is said to be <emphasis>
191Xkb-capable</emphasis>
192. A client that does explicitly call Xkb functions is an <emphasis>
193Xkb-aware</emphasis>
194 client. The Xkb keyboard state includes information derived from the effective state and from two server parameters that can be set through the keyboard extension. The following components of keyboard state pertain to Xkb-capable and Xkb-aware clients:
195</para>
196
197<itemizedlist>
198<listitem>
199  <para>
200lookup state: lookup group and lookup modifiers
201  </para>
202</listitem>
203<listitem>
204  <para>
205grab state: grab group and grab modifiers
206  </para>
207</listitem>
208</itemizedlist>
209
210<para>
211The <emphasis>
212lookup modifiers</emphasis>
213 and <emphasis>
214lookup group</emphasis>
215 are represented in the state field of core X events. The modifier state and keycode of a key event are used to determine the symbols associated with the event. For <emphasis>
216KeyPress</emphasis>
217 and <emphasis>
218KeyRelease</emphasis>
219 events, the lookup modifiers are computed as:
220</para>
221
222<literallayout>
223   ((base | latched | locked) &amp; ~<emphasis> server_internal_modifiers</emphasis>)
224</literallayout>
225
226<para>
227Otherwise the lookup modifiers are computed as:
228</para>
229
230<literallayout>
231(((base | latched | (locked &amp; ~<emphasis> ignore_locks</emphasis>)) &amp; ~<emphasis> server_internal_modifiers</emphasis>)
232</literallayout>
233
234<para>
235The lookup group is the same as the effective group.
236</para>
237
238
239<para>
240When an Xkb-capable or Xkb-aware client wishes to map a keycode to a keysym, it should use the <emphasis>
241lookup state</emphasis>
242 — the lookup group and the lookup modifiers.
243</para>
244
245
246<para>
247The <emphasis>
248grab state</emphasis>
249 is the state used when matching events to passive grabs. If the event activates a grab, the <emphasis>
250grab modifiers</emphasis>
251 and <emphasis>
252grab group</emphasis>
253 are represented in the state field of core X events; otherwise, the lookup state is used. The grab modifiers are computed as:
254</para>
255
256<literallayout>
257(((base | latched | (locked &amp; ~ignore_locks)) &amp; ~server_internal_modifiers)
258</literallayout>
259
260<para>
261If the server’s <emphasis>
262IgnoreGroupLock</emphasis>
263 control (see section 10.7.3) is not set, the grab group is the same as the effective group. Otherwise, the grab group is computed from the base group and latched group, ignoring the locked group.
264</para>
265
266
267<para>
268The final three components of Xkb state are applicable to clients that are not linked with an Xlib containing the X keyboard extension library and therefore are not aware of the keyboard extension (<emphasis>
269Xkb-unaware </emphasis>
270clients):
271</para>
272
273<itemizedlist>
274<listitem>
275  <para>
276The compatibility modifier state
277  </para>
278</listitem>
279<listitem>
280  <para>
281The compatibility lookup modifier state
282  </para>
283</listitem>
284<listitem>
285  <para>
286The compatibility grab modifier state
287  </para>
288</listitem>
289</itemizedlist>
290
291<para>
292The X11 protocol interpretation of modifiers does not include direct support for multiple groups. When an Xkb-extended X server connects to an Xkb-unaware client, the compatibility states remap the keyboard group into a core modifier whenever possible. The compatibility state corresponds to the effective modifier and effective group state, with the group remapped to a modifier. The compatibility lookup and grab states correspond to the lookup and grab states, respectively, with the group remapped to a modifier. The compatibility lookup state is reported in events that do not trigger passive grabs; otherwise, the compatibility grab state is reported.
293</para>
294
295
296</sect1>
297<sect1 id='changing_the_keyboard_state'>
298<title>Changing the Keyboard State</title>
299
300<sect2 id='changing_modifiers'>
301<title>Changing Modifiers</title>
302
303<para>
304The functions in this section that change the use of modifiers use a mask in the parameter <emphasis>
305affect</emphasis>
306. It is a bitwise inclusive OR of the legal modifier masks:
307</para>
308
309<table frame='none'>
310<title>Real Modifier Masks</title>
311<tgroup cols='1'>
312<colspec colsep='0'/>
313<tbody>
314  <row rowsep='1'>
315    <entry>Mask</entry>
316  </row>
317  <row rowsep='0'>
318    <entry>ShiftMask</entry>
319  </row>
320  <row rowsep='0'>
321    <entry>LockMask</entry>
322  </row>
323  <row rowsep='0'>
324    <entry>ControlMask</entry>
325  </row>
326  <row rowsep='0'>
327    <entry>Mod1Mask</entry>
328  </row>
329  <row rowsep='0'>
330    <entry>Mod2Mask</entry>
331  </row>
332  <row rowsep='0'>
333    <entry>Mod3Mask</entry>
334  </row>
335  <row rowsep='0'>
336    <entry>Mod4Mask</entry>
337  </row>
338  <row rowsep='0'>
339    <entry>Mod5Mask</entry>
340  </row>
341</tbody>
342</tgroup>
343</table>
344
345<para>
346To lock and unlock any of the eight real keyboard modifiers, use <emphasis>
347XkbLockModifiers:</emphasis>
348</para>
349
350<informaltable frame='none'>
351<tgroup cols='1'>
352<colspec colsep='0'/>
353<tbody>
354  <row rowsep='0'>
355    <entry role='functiondecl'>
356Bool <emphasis> XkbLockModifiers</emphasis>
357(<emphasis>
358display, device_spec, affect, values</emphasis>
359)
360    </entry>
361  </row>
362  <row rowsep='0'>
363    <entry role='functionargdecl'>
364Display *      <emphasis>
365display</emphasis>
366;            /* connection to the X server */
367    </entry>
368  </row>
369  <row rowsep='0'>
370    <entry role='functionargdecl'>
371unsigned int      <emphasis>
372device_spec</emphasis>
373;            /* device ID, or <emphasis>
374XkbUseCoreKbd</emphasis>
375 */
376    </entry>
377  </row>
378  <row rowsep='0'>
379    <entry role='functionargdecl'>
380unsigned int<emphasis>
381      affect</emphasis>
382;            /* mask of real modifiers whose lock state is to change */
383    </entry>
384  </row>
385  <row rowsep='0'>
386    <entry role='functionargdecl'>
387unsigned int      <emphasis>
388values</emphasis>
389;            /* 1 =&gt; lock, 0 =&gt; unlock; only for modifiers selected by <emphasis>
390affect</emphasis>
391 */
392    </entry>
393</row>
394</tbody>
395</tgroup>
396</informaltable>
397
398<para>
399<emphasis>
400XkbLockModifiers</emphasis>
401 sends a request to the server to lock the real modifiers selected by both <emphasis>
402affect</emphasis>
403 and <emphasis>
404values</emphasis>
405 and to unlock the real modifiers selected by <emphasis>
406affect</emphasis>
407 but not selected by <emphasis>
408values</emphasis>
409. <emphasis>
410XkbLockModifiers</emphasis>
411 does not wait for a reply from the server. It returns <emphasis>
412True</emphasis>
413 if the request was sent, and <emphasis>
414False</emphasis>
415 otherwise.
416</para>
417
418
419<para>
420To latch and unlatch any of the eight real keyboard modifiers, use <emphasis>
421XkbLatchModifiers:</emphasis>
422</para>
423
424
425<informaltable frame='none'>
426<tgroup cols='1'>
427<colspec colsep='0'/>
428<tbody>
429  <row rowsep='0'>
430    <entry role='functiondecl'>
431Bool <emphasis>
432XkbLatchModifiers</emphasis>
433(d<emphasis>
434isplay, device_spec, affect, values</emphasis>
435)
436    </entry>
437  </row>
438  <row rowsep='0'>
439    <entry role='functionargdecl'>
440Display *      <emphasis>
441display</emphasis>
442;            /* connection to the X server */
443    </entry>
444  </row>
445  <row rowsep='0'>
446    <entry role='functionargdecl'>
447unsigned int      <emphasis>
448device_spec</emphasis>
449;            /* device ID, or <emphasis>
450XkbUseCoreKbd</emphasis>
451 */
452    </entry>
453  </row>
454  <row rowsep='0'>
455    <entry role='functionargdecl'>
456unsigned int<emphasis>
457      affect</emphasis>
458;            /* mask of modifiers whose latch state is to change */
459    </entry>
460  </row>
461  <row rowsep='0'>
462    <entry role='functionargdecl'>
463unsigned int <emphasis>values</emphasis>;
464/* 1 =&gt; latch, 0 =&gt; unlatch; only for mods selected by <emphasis>
465affect</emphasis>
466 */
467    </entry>
468</row>
469</tbody>
470</tgroup>
471</informaltable>
472
473<para>
474<emphasis>
475XkbLatchModifiers</emphasis>
476 sends a request to the server to latch the real modifiers selected by both <emphasis>
477affect</emphasis>
478 and <emphasis>
479values</emphasis>
480 and to unlatch the real modifiers selected by <emphasis>
481affect</emphasis>
482 but not selected by <emphasis>
483values</emphasis>
484. <emphasis>
485XkbLatchModifiers</emphasis>
486 does not wait for a reply from the server. It returns <emphasis>
487True</emphasis>
488 if the request was sent, and <emphasis>
489False</emphasis>
490 otherwise.
491</para>
492
493
494</sect2>
495<sect2 id='changing_groups'>
496<title>Changing Groups</title>
497
498<para>
499Reference the keysym group indices with these symbolic constants:
500</para>
501
502<table frame='none'>
503<title>Symbolic Group Names</title>
504<tgroup cols='2'>
505<colspec colsep='0'/>
506<tbody>
507  <row rowsep='0'>
508    <entry>Symbolic Name</entry>
509    <entry>Value</entry>
510  </row>
511  <row rowsep='0'>
512    <entry>XkbGroup1Index</entry>
513    <entry>0</entry>
514  </row>
515  <row rowsep='0'>
516    <entry>XkbGroup2Index</entry>
517    <entry>1</entry>
518  </row>
519  <row rowsep='0'>
520    <entry>XkbGroup3Index</entry>
521    <entry>2</entry>
522  </row>
523  <row rowsep='0'>
524    <entry>XkbGroup4Index</entry>
525    <entry>3</entry>
526  </row>
527</tbody>
528</tgroup>
529</table>
530
531<para>
532To lock the keysym group, use <emphasis>
533XkbLockGroup. </emphasis>
534</para>
535
536<informaltable frame='none'>
537<tgroup cols='1'>
538<colspec colsep='0'/>
539<tbody>
540  <row rowsep='0'>
541    <entry role='functiondecl'>
542Bool <emphasis>
543XkbLockGroup</emphasis>
544(<emphasis>
545display, device_spec, group</emphasis>
546)
547    </entry>
548  </row>
549  <row rowsep='0'>
550    <entry role='functionargdecl'>
551Display *      <emphasis>
552display</emphasis>
553;            /* connection to the X server */
554    </entry>
555  </row>
556  <row rowsep='0'>
557    <entry role='functionargdecl'>
558unsigned int      <emphasis>
559device_spec</emphasis>
560;            /* device ID, or <emphasis>
561XkbUseCoreKbd</emphasis>
562 */
563    </entry>
564  </row>
565  <row rowsep='0'>
566    <entry role='functionargdecl'>
567unsigned int      <emphasis>
568group</emphasis>
569;            /* index of the keysym group to lock */
570    </entry>
571</row>
572</tbody>
573</tgroup>
574</informaltable>
575
576<para>
577<emphasis>
578XkbLockGroup</emphasis>
579 sends a request to the server to lock the specified <emphasis>
580group </emphasis>
581and does not wait for a reply. It returns <emphasis>
582True</emphasis>
583 if the request was sent and <emphasis>
584False</emphasis>
585 otherwise.
586</para>
587
588
589<para>
590To latch the keysym group, use <emphasis>
591XkbLatchGroup.</emphasis>
592</para>
593
594
595<informaltable frame='none'>
596<tgroup cols='1'>
597<colspec colsep='0'/>
598<tbody>
599  <row rowsep='0'>
600    <entry role='functiondecl'>
601Bool <emphasis>
602XkbLatchGroup</emphasis>
603(<emphasis>
604display, device_spec, group</emphasis>
605)
606    </entry>
607  </row>
608  <row rowsep='0'>
609    <entry role='functionargdecl'>
610Display *      <emphasis>
611display</emphasis>
612;            /* connection to the X server */
613    </entry>
614  </row>
615  <row rowsep='0'>
616    <entry role='functionargdecl'>
617unsigned int<emphasis>
618      device_spec</emphasis>
619;            /* device ID, or <emphasis>
620XkbUseCoreKbd</emphasis>
621 */
622    </entry>
623  </row>
624  <row rowsep='0'>
625    <entry role='functionargdecl'>
626unsigned int<emphasis>
627      group</emphasis>
628;            /* index of the keysym group to latch */
629    </entry>
630</row>
631</tbody>
632</tgroup>
633</informaltable>
634
635<para>
636<emphasis>
637XkbLatchGroup</emphasis>
638 sends a request to the server to latch the specified group and does not wait for a reply. It returns <emphasis>
639True</emphasis>
640 if the request was sent and <emphasis>
641False</emphasis>
642 otherwise.
643</para>
644
645
646</sect2>
647</sect1>
648<sect1 id='determining_keyboard_state'>
649<title>Determining Keyboard State</title>
650
651<para>
652Xkb keyboard state may be represented in an <emphasis>
653XkbStateRec</emphasis>
654 structure:
655</para>
656
657<para><programlisting>
658typedef struct {
659      unsigned char            group;                /* effective group index */
660      unsigned char            base_group;           /* base group index */
661      unsigned char            latched_group;        /* latched group index */
662      unsigned char            locked_group;         /* locked group index */
663      unsigned char            mods;                 /* effective modifiers */
664      unsigned char            base_mods;            /* base modifiers */
665      unsigned char            latched_mods;         /* latched modifiers */
666      unsigned char            locked_mods;          /* locked modifiers */
667      unsigned char            compat_state;         /* effective group =&gt; modifiers */
668      unsigned char            grab_mods;            /* modifiers used for grabs */
669      unsigned char            compat_grab_mods;     /* mods used for compatibility mode grabs */
670      unsigned char            lookup_mods;          /* modifiers used to lookup symbols */
671      unsigned char            compat_lookup_mods;   /* mods used for compatibility lookup */
672      unsigned short            ptr_buttons;         /* 1 bit =&gt; corresponding pointer btn is down */
673} <emphasis>
674XkbStateRec</emphasis>
675,*XkbStatePtr;
676</programlisting></para>
677
678<para>
679To obtain the keyboard state, use <emphasis>
680XkbGetState.</emphasis>
681</para>
682
683<informaltable frame='none'>
684<tgroup cols='1'>
685<colspec colsep='0'/>
686<tbody>
687  <row rowsep='0'>
688    <entry role='functiondecl'>
689Status <emphasis>
690XkbGetState</emphasis>
691(<emphasis>
692display</emphasis>
693, <emphasis>
694device_spec</emphasis>
695, <emphasis>
696state_return</emphasis>
697)
698    </entry>
699  </row>
700  <row rowsep='0'>
701    <entry role='functionargdecl'>
702Display *            <emphasis>
703display</emphasis>
704;            /* connection to the X server */
705    </entry>
706  </row>
707  <row rowsep='0'>
708    <entry role='functionargdecl'>
709unsigned int            <emphasis>
710device_spec</emphasis>
711;            /* device ID, or <emphasis>
712XkbUseCoreKbd</emphasis>
713 */
714    </entry>
715  </row>
716  <row rowsep='0'>
717    <entry role='functionargdecl'>
718XkbStatePtr            <emphasis>
719state_return</emphasis>
720;            /* backfilled with Xkb state */
721    </entry>
722</row>
723</tbody>
724</tgroup>
725</informaltable>
726
727<para>
728The <emphasis>
729XkbGetState </emphasis>
730function queries the server for the current keyboard state, waits for a reply, and then backfills <emphasis>
731state_return</emphasis>
732 with the results.
733</para>
734
735
736<para>
737All group values are expressed as group indices in the range [0..3]. Modifiers and the compatibility modifier state values are expressed as the bitwise union of the core X11 modifier masks. The pointer button state is reported as in the core X11 protocol.
738</para>
739
740
741</sect1>
742<sect1 id='tracking_keyboard_state'>
743<title>Tracking Keyboard State</title>
744
745<para>
746The Xkb extension reports <emphasis>
747XkbStateNotify </emphasis>
748events to clients wanting notification whenever the Xkb state changes. The changes reported include changes to any aspect of the keyboard state: when a modifier is set or unset, when the current group changes, or when a pointer button is pressed or released. As with all Xkb events, <emphasis>
749XkbStateNotify</emphasis>
750 events are reported to all interested clients without regard to the current keyboard input focus or grab state.
751</para>
752
753
754<para>
755There are many different types of Xkb state changes. Xkb defines an event detail mask corresponding to each type of change. The event detail masks are listed in Table 5.3.
756</para>
757
758<table frame='none'>
759<title>XkbStateNotify Event Detail Masks</title>
760<tgroup cols='2'>
761<colspec colsep='0'/>
762<thead>
763  <row rowsep='0'>
764    <entry>Mask</entry>
765    <entry>Value</entry>
766  </row>
767</thead>
768<tbody>
769  <row rowsep='0'>
770    <entry>XkbModifierStateMask</entry>
771    <entry>(1L &lt;&lt; 0)</entry>
772  </row>
773  <row rowsep='0'>
774    <entry>XkbModifierBaseMask</entry>
775    <entry>(1L &lt;&lt; 1)</entry>
776  </row>
777  <row rowsep='0'>
778    <entry>XkbModifierLatchMask</entry>
779    <entry>(1L &lt;&lt; 2)</entry>
780  </row>
781  <row rowsep='0'>
782    <entry>XkbModifierLockMask</entry>
783    <entry>(1L &lt;&lt; 3)</entry>
784  </row>
785  <row rowsep='0'>
786    <entry>XkbGroupStateMask</entry>
787    <entry>(1L &lt;&lt; 4)</entry>
788  </row>
789  <row rowsep='0'>
790    <entry>XkbGroupBaseMask</entry>
791    <entry>(1L &lt;&lt; 5)</entry>
792  </row>
793  <row rowsep='0'>
794    <entry>XkbGroupLatchMask</entry>
795    <entry>(1L &lt;&lt; 6)</entry>
796  </row>
797  <row rowsep='0'>
798    <entry>XkbGroupLockMask</entry>
799    <entry>(1L &lt;&lt; 7)</entry>
800  </row>
801  <row rowsep='0'>
802    <entry>XkbCompatStateMask</entry>
803    <entry>(1L &lt;&lt; 8)</entry>
804  </row>
805  <row rowsep='0'>
806    <entry>XkbGrabModsMask</entry>
807    <entry>(1L &lt;&lt; 9)</entry>
808  </row>
809  <row rowsep='0'>
810    <entry>XkbCompatGrabModsMask</entry>
811    <entry>(1L &lt;&lt; 10)</entry>
812  </row>
813  <row rowsep='0'>
814    <entry>XkbLookupModsMask</entry>
815    <entry>(1L &lt;&lt; 11)</entry>
816  </row>
817  <row rowsep='0'>
818    <entry>XkbCompatLookupModsMask</entry>
819    <entry>(1L &lt;&lt; 12)</entry>
820  </row>
821  <row rowsep='0'>
822    <entry>XkbPointerButtonMask</entry>
823    <entry>(1L &lt;&lt; 13)</entry>
824  </row>
825  <row rowsep='0'>
826    <entry>XkbAllStateComponentsMask</entry>
827    <entry>(0x3fff)</entry>
828  </row>
829</tbody>
830</tgroup>
831</table>
832
833<para>
834To track changes in the keyboard state for a particular device, select to receive <emphasis>
835XkbStateNotify</emphasis>
836 events by calling either <emphasis>
837XkbSelectEvents</emphasis>
838 or <emphasis>
839XkbSelectEventDetails</emphasis>
840 (see section 4.3). <!-- xref -->
841</para>
842
843
844<para>
845To receive <emphasis>
846XkbStateNotify</emphasis>
847 events under all possible conditions, use <emphasis>
848XkbSelectEvents</emphasis>
849 and pass <emphasis>
850XkbStateNotifyMask</emphasis>
851 in both <emphasis>
852bits_to_change</emphasis>
853 and <emphasis>
854values_for_bits</emphasis>
855.
856</para>
857
858
859<para>
860To receive <emphasis>
861XkbStateNotify</emphasis>
862 events only under certain conditions, use <emphasis>
863XkbSelectEventDetails</emphasis>
864 using <emphasis>
865XkbStateNotify</emphasis>
866 as the <emphasis>
867event_type</emphasis>
868 and specifying the desired state changes in <emphasis>
869bits_to_change</emphasis>
870 and <emphasis>
871values_for_bits</emphasis>
872 using mask bits from Table 5.3. <!-- xref -->
873</para>
874
875
876<para>
877The structure for <emphasis>
878XkbStateNotify</emphasis>
879 events is:
880</para>
881
882<para><programlisting>
883typedef struct {
884      int            type;            /* Xkb extension base event code */
885      unsigned long  serial;          /* X server serial number for event */
886      Bool           send_event;      /* <emphasis> True</emphasis> =&gt; synthetically generated */
887      Display *      display;         /* server connection where event generated */
888      Time           time;            /* server time when event generated */
889      int            xkb_type;        /* <emphasis> XkbStateNotify</emphasis> */
890      int            device;          /* Xkb device ID, will not be <emphasis> XkbUseCoreKbd</emphasis> */
891      unsigned int   changed;         /* bits indicating what has changed */
892      int            group;           /* group index of effective group */
893      int            base_group;      /* group index of base group */
894      int            latched_group;   /* group index of latched group */
895      int            locked_group;    /* group index of locked group */
896      unsigned int   mods;            /* effective modifiers */
897      unsigned int   base_mods;       /* base modifiers */
898      unsigned int   latched_mods;    /* latched modifiers */
899      unsigned int   locked_mods;     /* locked modifiers */
900      int            compat_state;    /* computed compatibility state */
901      unsigned char  grab_mods;       /* modifiers used for grabs */
902      unsigned char  compat_grab_mods;  /* modifiers used for compatibility grabs */
903      unsigned char  lookup_mods;     /* modifiers used to lookup symbols */
904      unsigned char  compat_lookup_mods;                  /* mods used for compatibility look up */
905      int            ptr_buttons;     /* core pointer buttons */
906      KeyCode        keycode;         /* keycode causing event, 0 if programmatic */
907      char           event_type;      /* core event if <emphasis> req_major</emphasis> or
908                                         <emphasis> req_minor</emphasis> non zero */
909      char           req_major;       /* major request code if program trigger, else 0 */
910      char           req_minor;       /* minor request code if program trigger, else 0 */
911} <emphasis>XkbStateNotifyEvent</emphasis>
912;
913</programlisting></para>
914
915<para>
916When you receive an <emphasis>
917XkbStateNotify</emphasis>
918 event, the <emphasis>
919changed</emphasis>
920 field indicates which elements of keyboard state have changed.
921This will be the bitwise inclusive OR of one or more of the <emphasis>
922XkbStateNotify</emphasis>
923 event detail masks shown in Table 5.3. All fields reported in  <!-- xref -->
924the event are valid, but only those indicated in <emphasis>
925changed</emphasis>
926 have changed values.
927</para>
928
929
930<para>
931The <emphasis>
932group</emphasis>
933 field is the group index of the effective keysym group. The <emphasis>
934base_group</emphasis>
935, <emphasis>
936latched_group</emphasis>
937, and <emphasis>
938locked_group</emphasis>
939 fields are set to a group index value representing the base group,
940the latched group, and the locked group, respectively. The X
941server can set the modifier and compatibility state fields to
942a union of the core modifier mask bits; this union represents the
943corresponding modifier states. The <emphasis>ptr_button</emphasis>
944 field gives the state of the core pointer buttons as a
945mask composed of an inclusive OR of zero or more of the
946core pointer button masks.
947</para>
948
949
950<para>
951Xkb state changes can occur either in response to keyboard
952activity or under application control. If a key event
953caused the state change, the <emphasis>
954keycode</emphasis>
955 field gives the keycode of the key event, and the <emphasis>
956event_type</emphasis>
957 field is set to either <emphasis>KeyPress</emphasis>
958 or <emphasis>
959KeyRelease</emphasis>
960. If a pointer button event caused the state change, the <emphasis>
961keycode</emphasis>
962 field is zero, and the <emphasis>event_type</emphasis>
963 field is set to either <emphasis>ButtonPress</emphasis>
964 or <emphasis>ButtonRelease</emphasis>
965. Otherwise, the major and minor codes of the request that caused the
966state change are given in the <emphasis>
967req_major</emphasis>
968 and <emphasis>
969req_minor</emphasis>
970 fields, and the <emphasis>
971keycode</emphasis>
972 field is zero. The <emphasis>
973req_major</emphasis>
974 value is the same as the major extension opcode.
975</para>
976</sect1>
977</chapter>
978