macaroon: wrong key sent when multiple keyboard layouts are configured
@fherrera
Submitted by Fernando Herrera de las Heras Link to original bug (#643970)
Description
Currently macaroon does this to figure out the level/keycode to send during playback:
key_code, group, level = utils.keymap.get_entries_for_keyval(keyval)[0]
However, when multiple keyboard layouts are configured (and you can switch them on-the-fly using the applet or keybinding) get_entries_for_keyval returns a list with all the key_code, group, level combinations on every configured layout.
Using the first one is wrong. To pick the right one, we need to look at the group, however, getting the active group is tricky, as it can be per-window, so we need to peek the window we want to send the key with XGetWindowProperty.
this is how xklavier gets it:
if ((XGetWindowProperty
(xkl_engine_get_display(engine), toplevel_win,
xkl_engine_priv(engine, atoms)[XKLAVIER_STATE], 0L,
XKLAVIER_STATE_PROP_LENGTH, False, XA_INTEGER, &type_ret,
&format_ret, &nitems, &rest,
(unsigned char **) (void *) &prop) == Success)
&& (type_ret == XA_INTEGER) && (format_ret == 32)) {
grp = prop[0];
if (grp >= xkl_engine_get_num_groups(engine) || grp < 0)
grp = 0;
inds = prop[1];
if (state_out != NULL) {
state_out->group = grp;
state_out->indicators = inds;
}
if (prop != NULL)
XFree(prop);
ret = TRUE;
}