- * mapping_notify once (we do not receive any other XKB
- * events anyway). */
- while (XPending(xkbdpy))
- XNextEvent(xkbdpy, &ev);
+ * mapping_notify once. */
+ bool mapping_changed = false;
+ while (XPending(xkbdpy)) {
+ XNextEvent(xkbdpy, (XEvent*)&ev);
+ /* While we should never receive a non-XKB event,
+ * better do sanity checking */
+ if (ev.type != xkb_event_base)
+ continue;
+
+ if (ev.any.xkb_type == XkbMapNotify) {
+ mapping_changed = true;
+ continue;
+ }
+
+ if (ev.any.xkb_type != XkbStateNotify) {
+ ELOG("Unknown XKB event received (type %d)\n", ev.any.xkb_type);
+ continue;
+ }
+
+ /* See The XKB Extension: Library Specification, section 14.1 */
+ /* We check if the current group (each group contains
+ * two levels) has been changed. Mode_switch activates
+ * group XkbGroup2Index */
+ if (xkb_current_group == ev.state.group)
+ continue;
+
+ xkb_current_group = ev.state.group;