So… This patch seems to work fine here (tested with russian + french layout), but… it makes no sense at all.
Reading XLib source, both XLookupKeysym() and XLookupString() make roughly the same thing to convert a keycode into a keysym (the later being slightly more 'refined' than the former). And yet we get very different results (to summarize, XLookupKeysym() seems to retrieve key_sym matching first defined keymap, while XLookupString() seems to retrieve proper key_sym from current active keymap).
@Sergey Sharybin (sergey), @Campbell Barton (campbellbarton), do you guys have some clue here?