diff options
author | Ran Benita <ran234@gmail.com> | 2012-10-10 09:47:31 +0200 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2012-10-10 10:10:45 +0200 |
commit | 2f4db8a95b9326e4bd5dbc0facb28fbb6d4e718a (patch) | |
tree | 91a042542521f0058bcfdec86527058a48113b46 /src/keymap.c | |
parent | 9179fed76bd46eb1edcb3edd0c9c515f5a7e2b31 (diff) | |
download | xorg-lib-libxkbcommon-2f4db8a95b9326e4bd5dbc0facb28fbb6d4e718a.tar.gz |
keymap, state: don't assume led index < xkb_keymap_num_leds
xkb_keymap_num_leds() returns the number of leds that have any
possibility of being set. Even if a led is defined but can not be set in
any way, it is not counted.
In a few places currently we assume that led indexes are smaller than
this number, which is wrong both for the above reason and for the fact
that the xkb format actually allows explicitly setting the indicator
index, which means that the indexes might be non-consecutive.
We don't really have good API to iterate on leds, now, because
xkb_keymap_num_leds is pretty useless. To work around that we use
sizeof(xkb_led_mask_t) * 8.
This makes the "Group 2" led work (try switching to a layout other than
the first in test/interactive).
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/keymap.c')
-rw-r--r-- | src/keymap.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/keymap.c b/src/keymap.c index a54169a..fb63639 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -253,7 +253,7 @@ xkb_keymap_num_leds(struct xkb_keymap *keymap) XKB_EXPORT const char * xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx) { - if (idx >= xkb_keymap_num_leds(keymap)) + if (idx >= XKB_NUM_INDICATORS) return NULL; return xkb_atom_text(keymap->ctx, keymap->indicators[idx].name); @@ -265,14 +265,13 @@ xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx) XKB_EXPORT xkb_layout_index_t xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name) { - xkb_led_index_t num_leds = xkb_keymap_num_leds(keymap); xkb_atom_t atom = xkb_atom_lookup(keymap->ctx, name); xkb_led_index_t i; if (atom == XKB_ATOM_NONE) return XKB_LED_INVALID; - for (i = 0; i < num_leds; i++) + for (i = 0; i < XKB_NUM_INDICATORS; i++) if (keymap->indicators[i].name == atom) return i; |