Detecting keymap changes on X11

How would I detect changes in the keymap/keyboard layout? On Wayland this is rather simple since I can just register a listener by asking the compositor myself. However, as I understand it (I’m still quite a noob when it comes to X11) on X11 that is not possible as the event handling logic is polling-based on X11, with GLFW handling that polling loop.

And before anyone asks the question that’s bound to be asked: No, you won’t get me to use glfwGetKeyName, I have had bad experiences with it in the past, instead I’m using libxkbcommon directly. And no, I’m not going to use this for input handling logic. This is purely for displaying keybinds (and besides, knowing when the keymap changes allows me to invalidate caches more effectively, thus allowing me to cache the FBOs of UI elements that aren’t going to change every frame anyways).

Welcome to the GLFW discourse.

GLFW doesn’t have a callback/query for this, the closest you will get is using glfwGetKeyName.

Then, are there any non-GLFW specific workarounds? Like some way to capture X11 events for a window without touching the X11 event polling loop like some kind of multiplexer?

I suppose I could always fall back to have alternate paths for X11 and Wayland but the extra maintenance burden would be rather extremely especially given that I know that `glfwGetKeyName` is not more viable due to excessive caching of keymaps (although not reliably so for some strange reason - nor have I a clue where it gets the keymaps from - probably not from the compositor, but my initial assumption that it was from env vars is also wrong given that it now works on my end without having touched anything except my system).

I think the implementation of glfwGetKeyName has changed a bit since my initial implementation but the code should be available to see how that works. If there’s an problem you are having with it, then perhaps one solution would be to post an issue to Github and perhaps we can resolve it.