Fix documentation bugs with mod/group state API
[platform/upstream/libxkbcommon.git] / include / xkbcommon / xkbcommon.h
1 /*
2 Copyright 1985, 1987, 1990, 1998  The Open Group
3 Copyright 2008  Dan Nicholson
4
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the "Software"),
7 to deal in the Software without restriction, including without limitation
8 the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 and/or sell copies of the Software, and to permit persons to whom the
10 Software is furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 Except as contained in this notice, the names of the authors or their
23 institutions shall not be used in advertising or otherwise to promote the
24 sale, use or other dealings in this Software without prior written
25 authorization from the authors.
26 */
27
28 /************************************************************
29 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
30
31 Permission to use, copy, modify, and distribute this
32 software and its documentation for any purpose and without
33 fee is hereby granted, provided that the above copyright
34 notice appear in all copies and that both that copyright
35 notice and this permission notice appear in supporting
36 documentation, and that the name of Silicon Graphics not be
37 used in advertising or publicity pertaining to distribution
38 of the software without specific prior written permission.
39 Silicon Graphics makes no representation about the suitability
40 of this software for any purpose. It is provided "as is"
41 without any express or implied warranty.
42
43 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
44 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
45 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
46 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
47 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
48 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
49 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
50 THE USE OR PERFORMANCE OF THIS SOFTWARE.
51
52 ********************************************************/
53
54
55 #ifndef _XKBCOMMON_H_
56 #define _XKBCOMMON_H_
57
58 #include <stdint.h>
59 #include <stdio.h>
60 #include <X11/Xfuncproto.h>
61 #include <X11/extensions/XKB.h>
62
63 typedef uint32_t xkb_keycode_t;
64 typedef uint32_t xkb_keysym_t;
65 typedef uint32_t xkb_mod_index_t;
66 typedef uint32_t xkb_group_index_t;
67
68 #define XKB_MOD_INVALID                 (0xffffffff)
69 #define XKB_GROUP_INVALID               (0xffffffff)
70 #define XKB_KEYCODE_INVALID             (0xffffffff)
71
72 #define XKB_KEYCODE_MAX                 (0xffffffff - 1)
73 #define xkb_keycode_is_legal_ext(kc)    (kc <= XKB_KEYCODE_MAX)
74 #define xkb_keycode_is_legal_x11(kc)    (kc <= XKB_KEYCODE_MAX)
75 #define xkb_keymap_keycode_range_is_legal(xkb) \
76     (xkb->max_key_code > 0 && \
77      xkb->max_key_code > xkb->min_key_code && \
78      xkb_keycode_is_legal_ext(xkb->min_key_code) && \
79      xkb_keycode_is_legal_ext(xkb->max_key_code))
80
81 /* Duplicate the modifier mask defines so libxkcommon can be used
82  * without X.h */
83 #define XKB_COMMON_SHIFT_MASK           (1 << 0)
84 #define XKB_COMMON_LOCK_MASK            (1 << 1)
85 #define XKB_COMMON_CONTROL_MASK         (1 << 2)
86 #define XKB_COMMON_MOD1_MASK            (1 << 3)
87 #define XKB_COMMON_MOD2_MASK            (1 << 4)
88 #define XKB_COMMON_MOD3_MASK            (1 << 5)
89 #define XKB_COMMON_MOD4_MASK            (1 << 6)
90 #define XKB_COMMON_MOD5_MASK            (1 << 7)
91
92
93 struct xkb_rule_names {
94     const char *  rules;
95     const char *  model;
96     const char *  layout;
97     const char *  variant;
98     const char *  options;
99 };
100
101 struct xkb_any_action {
102     uint8_t   type;
103     uint8_t   data[7];
104 };
105
106 struct xkb_mod_action {
107     uint8_t         type;
108     uint8_t         flags;
109     uint8_t         mask;
110     uint8_t         real_mods;
111     uint16_t        vmods;
112 };
113
114 struct xkb_group_action {
115     uint8_t         type;
116     uint8_t         flags;
117     int16_t         group;
118 };
119
120 struct xkb_iso_action {
121     uint8_t         type;
122     uint8_t         flags;
123     uint8_t         mask;
124     uint8_t         real_mods;
125     uint8_t         group;
126     uint8_t         affect;
127     uint16_t        vmods;
128 };
129
130 struct xkb_controls_action {
131     uint8_t         type;
132     uint8_t         flags;
133     uint32_t        ctrls;
134 };
135
136 struct xkb_device_button_action {
137     uint8_t         type;
138     uint8_t         flags;
139     uint8_t         count;
140     uint8_t         button;
141     uint8_t         device;
142 };
143
144 struct xkb_device_valuator_action {
145     uint8_t         type;
146     uint8_t         device;
147     uint8_t         v1_what;
148     uint8_t         v1_index;
149     uint8_t         v1_value;
150     uint8_t         v2_what;
151     uint8_t         v2_index;
152     uint8_t         v2_value;
153 };
154
155 struct xkb_pointer_default_action {
156     uint8_t         type;
157     uint8_t         flags;
158     uint8_t         affect;
159     uint8_t         value;
160 };
161
162 struct xkb_switch_screen_action {
163     uint8_t         type;
164     uint8_t         flags;
165     uint8_t         screen;
166 };
167
168 struct xkb_redirect_key_action {
169     uint8_t             type;
170     xkb_keycode_t       new_key;
171     uint8_t             mods_mask;
172     uint8_t             mods;
173     uint16_t            vmods_mask;
174     uint16_t            vmods;
175 };
176
177 struct xkb_pointer_action {
178     uint8_t     type;
179     uint8_t     flags;
180     uint16_t    x;
181     uint16_t    y;
182 };
183
184 struct xkb_message_action {
185     uint8_t     type;
186     uint8_t     flags;
187     uint8_t     message[6];
188 };
189
190 struct xkb_pointer_button_action {
191     uint8_t     type;
192     uint8_t     flags;
193     uint8_t     count;
194     uint8_t     button;
195 };
196
197 union xkb_action {
198     struct xkb_any_action             any;
199     struct xkb_mod_action             mods;
200     struct xkb_group_action           group;
201     struct xkb_iso_action             iso;
202     struct xkb_controls_action        ctrls;
203     struct xkb_device_button_action   devbtn;
204     struct xkb_device_valuator_action devval;
205     struct xkb_pointer_default_action dflt;
206     struct xkb_switch_screen_action   screen;
207     struct xkb_redirect_key_action    redirect; /* XXX wholly unnecessary? */
208     struct xkb_pointer_action         ptr; /* XXX delete for DeviceValuator */
209     struct xkb_pointer_button_action  btn; /* XXX delete for DeviceBtn */
210     struct xkb_message_action         msg; /* XXX just delete */
211     unsigned char                     type;
212 };
213
214 struct xkb_mods {
215         uint32_t        mask;   /* effective mods */
216         uint32_t        vmods;
217         uint8_t         real_mods;
218 };
219
220 struct xkb_kt_map_entry {
221         int            active;
222         uint16_t        level;
223         struct xkb_mods     mods;
224 };
225
226 struct xkb_key_type {
227     struct xkb_mods             mods;
228     uint16_t                num_levels;
229     unsigned char           map_count;
230     struct xkb_kt_map_entry *       map;
231     struct xkb_mods *             preserve;
232     const char              *name;
233     const char              **level_names;
234 };
235
236 struct xkb_sym_interpret {
237     xkb_keysym_t    sym;
238     unsigned char   flags;
239     unsigned char   match;
240     uint8_t         mods;
241     uint32_t        virtual_mod;
242     union xkb_action act;
243 };
244
245 struct xkb_compat_map {
246     struct xkb_sym_interpret *      sym_interpret;
247     struct xkb_mods              groups[XkbNumKbdGroups];
248     unsigned short           num_si;
249     unsigned short           size_si;
250 };
251
252 struct xkb_sym_map {
253         unsigned char    kt_index[XkbNumKbdGroups];
254         unsigned char    group_info;
255         unsigned char    width;
256         unsigned short   offset;
257 };
258
259 #define XkbNumGroups(g)                 ((g)&0x0f)
260 #define XkbOutOfRangeGroupInfo(g)       ((g)&0xf0)
261 #define XkbOutOfRangeGroupAction(g)     ((g)&0xc0)
262 #define XkbOutOfRangeGroupNumber(g)     (((g)&0x30)>>4)
263 #define XkbSetGroupInfo(g,w,n)  (((w)&0xc0)|(((n)&3)<<4)|((g)&0x0f))
264 #define XkbSetNumGroups(g,n)    (((g)&0xf0)|((n)&0x0f))
265
266 struct xkb_client_map {
267     unsigned char            size_types;
268     unsigned char            num_types;
269     struct xkb_key_type *           types;
270
271     uint32_t                 size_syms;
272     uint32_t                 num_syms;
273     xkb_keysym_t             *syms;
274     struct xkb_sym_map *             key_sym_map;
275
276     unsigned char           *modmap;
277 };
278
279 struct xkb_behavior {
280         unsigned char   type;
281         unsigned char   data;
282 };
283
284 struct xkb_server_map {
285     unsigned short      num_acts;
286     unsigned short      size_acts;
287
288 #if defined(__cplusplus) || defined(c_plusplus)
289     /* explicit is a C++ reserved word */
290     unsigned char *     c_explicit;
291 #else
292     unsigned char *     explicit;
293 #endif
294
295     union xkb_action          *acts;
296     struct xkb_behavior         *behaviors;
297     unsigned short      *key_acts;
298     unsigned char       *explicits;
299     uint32_t            vmods[XkbNumVirtualMods]; /* vmod -> mod mapping */
300     uint32_t            *vmodmap; /* key -> vmod mapping */
301 };
302
303
304 struct xkb_indicator_map {
305         unsigned char   flags;
306         unsigned char   which_groups;
307         unsigned char   groups;
308         unsigned char   which_mods;
309         struct xkb_mods mods;
310         unsigned int    ctrls;
311 };
312
313 struct xkb_indicator {
314         unsigned long           phys_indicators;
315         struct xkb_indicator_map        maps[XkbNumIndicators];
316 };
317
318 struct xkb_key_name {
319         char    name[XkbKeyNameLength];
320 };
321
322 struct xkb_key_alias {
323         char    real[XkbKeyNameLength];
324         char    alias[XkbKeyNameLength];
325 };
326
327 struct xkb_names {
328     const char            *vmods[XkbNumVirtualMods];
329     const char            *indicators[XkbNumIndicators];
330     const char            *groups[XkbNumKbdGroups];
331     struct xkb_key_name *     keys;
332     struct xkb_key_alias *    key_aliases;
333
334     xkb_keycode_t     num_keys;
335     xkb_keycode_t     num_key_aliases;
336 };
337
338 struct xkb_controls {
339         unsigned char   num_groups;
340         unsigned char   groups_wrap;
341         struct xkb_mods internal;
342         struct xkb_mods ignore_lock;
343         unsigned int    enabled_ctrls;
344         unsigned short  repeat_delay;
345         unsigned short  repeat_interval;
346         unsigned short  slow_keys_delay;
347         unsigned short  debounce_delay;
348         unsigned short  ax_options;
349         unsigned short  ax_timeout;
350         unsigned short  axt_opts_mask;
351         unsigned short  axt_opts_values;
352         unsigned int    axt_ctrls_mask;
353         unsigned int    axt_ctrls_values;
354         unsigned char   *per_key_repeat;
355 };
356
357 /* Common keyboard description structure */
358 struct xkb_desc {
359     unsigned int        defined;
360     unsigned short      flags;
361     unsigned short      device_spec;
362     xkb_keycode_t       min_key_code;
363     xkb_keycode_t       max_key_code;
364
365     struct xkb_controls *      ctrls;
366     struct xkb_server_map *    server;
367     struct xkb_client_map *    map;
368     struct xkb_indicator *     indicators;
369     struct xkb_names *        names;
370     struct xkb_compat_map *    compat;
371 };
372
373
374 #define XkbKeyGroupInfo(d,k)    ((d)->map->key_sym_map[k].group_info)
375 #define XkbKeyNumGroups(d,k)    (XkbNumGroups((d)->map->key_sym_map[k].group_info))
376 #define XkbKeyGroupWidth(d,k,g) (XkbKeyType(d,k,g)->num_levels)
377 #define XkbKeyGroupsWidth(d,k)  ((d)->map->key_sym_map[k].width)
378 #define XkbKeyTypeIndex(d,k,g)  ((d)->map->key_sym_map[k].kt_index[g&0x3])
379 #define XkbKeyType(d,k,g)       (&(d)->map->types[XkbKeyTypeIndex(d,k,g)])
380 #define XkbKeyNumSyms(d,k)      (XkbKeyGroupsWidth(d,k)*XkbKeyNumGroups(d,k))
381 #define XkbKeySymsOffset(d,k)   ((d)->map->key_sym_map[k].offset)
382 #define XkbKeySymsPtr(d,k)      (&(d)->map->syms[XkbKeySymsOffset(d,k)])
383 #define XkbKeySym(d,k,n)        (XkbKeySymsPtr(d,k)[n])
384 #define XkbKeySymEntry(d,k,sl,g) \
385         (XkbKeySym(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))))
386 #define XkbKeyHasActions(d,k)   ((d)->server->key_acts[k]!=0)
387 #define XkbKeyNumActions(d,k)   (XkbKeyHasActions(d,k)?XkbKeyNumSyms(d,k):1)
388 #define XkbKeyActionsPtr(d,k)   (&(d)->server->acts[(d)->server->key_acts[k]])
389 #define XkbKeyAction(d,k,n) \
390         (XkbKeyHasActions(d,k)?&XkbKeyActionsPtr(d,k)[n]:NULL)
391 #define XkbKeyActionEntry(d,k,sl,g) \
392         (XkbKeyHasActions(d,k)?\
393                 XkbKeyAction(d,k,((XkbKeyGroupsWidth(d,k)*(g))+(sl))):NULL)
394
395 #define XkbKeycodeInRange(d,k)  (((k)>=(d)->min_key_code)&&\
396                                  ((k)<=(d)->max_key_code))
397 #define XkbNumKeys(d)           ((d)->max_key_code-(d)->min_key_code+1)
398
399 struct xkb_map_changes {
400         unsigned short           changed;
401         xkb_keycode_t            min_key_code;
402         xkb_keycode_t            max_key_code;
403         unsigned char            first_type;
404         unsigned char            num_types;
405         xkb_keycode_t            first_key_sym;
406         xkb_keycode_t            num_key_syms;
407         xkb_keycode_t            first_key_act;
408         xkb_keycode_t            num_key_acts;
409         xkb_keycode_t            first_key_behavior;
410         xkb_keycode_t            num_key_behaviors;
411         xkb_keycode_t            first_key_explicit;
412         xkb_keycode_t            num_key_explicit;
413         xkb_keycode_t            first_modmap_key;
414         xkb_keycode_t            num_modmap_keys;
415         xkb_keycode_t            first_vmodmap_key;
416         xkb_keycode_t            num_vmodmap_keys;
417         unsigned short           vmods;
418 };
419
420 struct xkb_controls_changes {
421         unsigned int             changed_ctrls;
422         unsigned int             enabled_ctrls_changes;
423         int                      num_groups_changed;
424 };
425
426 struct xkb_indicator_changes {
427         unsigned int             state_changes;
428         unsigned int             map_changes;
429 };
430
431 struct xkb_name_changes {
432         unsigned int            changed;
433         unsigned char           first_type;
434         unsigned char           num_types;
435         unsigned char           first_lvl;
436         unsigned char           num_lvls;
437         xkb_keycode_t           num_aliases;
438         xkb_keycode_t           first_key;
439         xkb_keycode_t           num_keys;
440         unsigned short          changed_vmods;
441         unsigned long           changed_indicators;
442         unsigned char           changed_groups;
443 };
444
445 struct xkb_compat_changes {
446         unsigned char           changed_groups;
447         unsigned short          first_si;
448         unsigned short          num_si;
449 };
450
451 struct xkb_changes {
452         unsigned short           device_spec;
453         unsigned short           state_changes;
454         struct xkb_map_changes   map;
455         struct xkb_controls_changes      ctrls;
456         struct xkb_indicator_changes     indicators;
457         struct xkb_name_changes  names;
458         struct xkb_compat_changes        compat;
459 };
460
461 struct xkb_component_names {
462         char *                   keymap;
463         char *                   keycodes;
464         char *                   types;
465         char *                   compat;
466         char *                   symbols;
467 };
468
469 struct xkb_component_name {
470         unsigned short          flags;
471         char *                  name;
472 };
473
474 struct xkb_state {
475         unsigned char   group; /* base + latched + locked */
476         /* FIXME: Why are base + latched short and not char?? */
477         unsigned short  base_group; /* physically ... down? */
478         unsigned short  latched_group;
479         unsigned char   locked_group;
480
481         unsigned char   mods; /* base + latched + locked */
482         unsigned char   base_mods; /* physically down */
483         unsigned char   latched_mods;
484         unsigned char   locked_mods;
485
486         unsigned char   compat_state; /* mods + group for core state */
487
488         /* grab mods = all depressed and latched mods, _not_ locked mods */
489         unsigned char   grab_mods; /* grab mods minus internal mods */
490         unsigned char   compat_grab_mods; /* grab mods + group for core state,
491                                              but not locked groups if
492                                              IgnoreGroupLocks set */
493
494         /* effective mods = all mods (depressed, latched, locked) */
495         unsigned char   lookup_mods; /* effective mods minus internal mods */
496         unsigned char   compat_lookup_mods; /* effective mods + group */
497
498         unsigned short  ptr_buttons; /* core pointer buttons */
499
500         int refcnt;
501         void *filters;
502         int num_filters;
503         struct xkb_desc *xkb;
504 };
505
506 #define XkbStateFieldFromRec(s) XkbBuildCoreState((s)->lookup_mods,(s)->group)
507 #define XkbGrabStateFromRec(s)  XkbBuildCoreState((s)->grab_mods,(s)->group)
508
509 #define XkbNumGroups(g)                 ((g)&0x0f)
510 #define XkbOutOfRangeGroupInfo(g)       ((g)&0xf0)
511 #define XkbOutOfRangeGroupAction(g)     ((g)&0xc0)
512 #define XkbOutOfRangeGroupNumber(g)     (((g)&0x30)>>4)
513 #define XkbSetNumGroups(g,n)    (((g)&0xf0)|((n)&0x0f))
514
515 _XFUNCPROTOBEGIN
516
517 _X_EXPORT extern struct xkb_desc *
518 xkb_compile_keymap_from_rules(const struct xkb_rule_names *rules);
519
520 _X_EXPORT extern struct xkb_desc *
521 xkb_compile_keymap_from_components(const struct xkb_component_names * ktcsg);
522
523 _X_EXPORT extern struct xkb_desc *
524 xkb_compile_keymap_from_file(FILE *inputFile, const char *mapName);
525
526 _X_EXPORT extern struct xkb_desc *
527 xkb_compile_keymap_from_string(const char *string, const char *mapName);
528
529 _X_EXPORT extern void
530 xkb_free_keymap(struct xkb_desc *xkb);
531
532 /*
533  * Canonicalises component names by prepending the relevant component from
534  * 'old' to the one in 'names' when the latter has a leading '+' or '|', and
535  * by replacing a '%' with the relevant component, e.g.:
536  *
537  * names        old           output
538  * ------------------------------------------
539  * +bar         foo           foo+bar
540  * |quux        baz           baz|quux
541  * foo+%|baz    bar           foo+bar|baz
542  *
543  * If a component in names needs to be modified, the existing value will be
544  * free()d, and a new one allocated with malloc().
545  */
546 _X_EXPORT extern void
547 xkb_canonicalise_components(struct xkb_component_names * names,
548                            const struct xkb_component_names * old);
549
550 /*
551  * Converts a keysym to a string; will return unknown Unicode codepoints
552  * as "Ua1b2", and other unknown keysyms as "0xabcd1234".
553  */
554 _X_EXPORT extern void
555 xkb_keysym_to_string(xkb_keysym_t ks, char *buffer, size_t size);
556
557 /*
558  * See xkb_keysym_to_string comments: this function will accept any string
559  * from that function.
560  */
561 _X_EXPORT extern xkb_keysym_t
562 xkb_string_to_keysym(const char *s);
563
564 _X_EXPORT unsigned int
565 xkb_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
566                  xkb_keysym_t **syms_out);
567
568 /**
569  * @defgroup components XKB state components
570  * Allows enumeration of state components such as modifiers and groups within
571  * the current keymap.
572  *
573  * @{
574  */
575
576 /**
577  * Returns the number of modifiers active in the keymap.
578  */
579 _X_EXPORT xkb_mod_index_t
580 xkb_map_num_mods(struct xkb_desc *xkb);
581
582 /**
583  * Returns the name of the modifier specified by 'idx', or NULL if invalid.
584  */
585 _X_EXPORT const char *
586 xkb_map_mod_get_name(struct xkb_desc *xkb, xkb_mod_index_t idx);
587
588 /**
589  * Returns the index of the modifier specified by 'name', or XKB_MOD_INVALID.
590  */
591 _X_EXPORT xkb_mod_index_t
592 xkb_map_mod_get_index(struct xkb_desc *xkb, const char *name);
593
594 /**
595  * Returns the number of groups active in the keymap.
596  */
597 _X_EXPORT xkb_group_index_t
598 xkb_map_num_groups(struct xkb_desc *xkb);
599
600 /**
601  * Returns the name of the group specified by 'idx', or NULL if invalid.
602  */
603 _X_EXPORT const char *
604 xkb_map_group_get_name(struct xkb_desc *xkb, xkb_group_index_t idx);
605
606 /**
607  * Returns the index of the group specified by 'name', or XKB_GROUP_INVALID.
608  */
609 _X_EXPORT xkb_group_index_t
610 xkb_map_group_get_index(struct xkb_desc *xkb, const char *name);
611
612 /**
613  * Returns the number of groups active for the specified key.
614  */
615 _X_EXPORT xkb_group_index_t
616 xkb_key_num_groups(struct xkb_desc *xkb, xkb_keycode_t key);
617
618 /** @} */
619
620 /**
621  * @defgroup state XKB state objects
622  * Creation, destruction and manipulation of keyboard state objects,
623  * representing modifier and group state.
624  *
625  * @{
626  */
627
628 /**
629  * Allocates a new XKB state object for use with the given keymap.
630  */
631 _X_EXPORT struct xkb_state *
632 xkb_state_new(struct xkb_desc *xkb);
633
634 /**
635  * Adds a reference to a state object, so it will not be freed until unref.
636  */
637 _X_EXPORT void
638 xkb_state_ref(struct xkb_state *state);
639
640 /**
641  * Unrefs and potentially deallocates a state object; the caller must not
642  * use the state object after calling this.
643  */
644 _X_EXPORT void
645 xkb_state_unref(struct xkb_state *state);
646
647 /**
648  * Updates a state object to reflect the given key being pressed or released.
649  */
650 _X_EXPORT void
651 xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key, int down);
652
653 /**
654  * Modifier and group types for state objects.  This enum is bitmaskable,
655  * e.g. (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED) is valid to exclude
656  * locked modifiers.
657  */
658 enum xkb_state_component {
659     XKB_STATE_DEPRESSED = (1 << 0),
660         /**< A key holding this modifier or group is currently physically
661          *   depressed; also known as 'base'. */
662     XKB_STATE_LATCHED = (1 << 1),
663         /**< Modifier or group is latched, i.e. will be unset after the next
664          *   non-modifier key press. */
665     XKB_STATE_LOCKED = (1 << 2),
666         /**< Modifier or group is locked, i.e. will be unset after the key
667          *   provoking the lock has been pressed again. */
668     XKB_STATE_EFFECTIVE =
669         (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED | XKB_STATE_LOCKED),
670         /**< Combinatination of depressed, latched, and locked. */
671 };
672
673 /**
674  * Returns 1 if the modifier specified by 'name' is active in the manner
675  * specified by 'type', 0 if it is unset, or -1 if the modifier does not
676  * exist in the current map.
677  */
678 _X_EXPORT int
679 xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
680                              enum xkb_state_component type);
681
682 /**
683  * Returns 1 if the modifier specified by 'idx' is active in the manner
684  * specified by 'type', 0 if it is unset, or -1 if the modifier does not
685  * exist in the current map.
686  */
687 _X_EXPORT int
688 xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
689                               enum xkb_state_component type);
690
691 /**
692  * Returns 1 if the group specified by 'name' is active in the manner
693  * specified by 'type', 0 if it is unset, or -1 if the group does not
694  * exist in the current map.
695  */
696 _X_EXPORT int
697 xkb_state_group_name_is_active(struct xkb_state *state, const char *name,
698                                enum xkb_state_component type);
699
700 /**
701  * Returns 1 if the group specified by 'idx' is active in the manner
702  * specified by 'type', 0 if it is unset, or -1 if the group does not
703  * exist in the current map.
704  */
705 _X_EXPORT int
706 xkb_state_group_index_is_active(struct xkb_state *state, xkb_group_index_t idx,
707                                 enum xkb_state_component type);
708
709 /** @} */
710
711 _XFUNCPROTOEND
712
713 #endif /* _XKBCOMMON_H_ */