# Detecting keymap changes on X11

**URL:** https://discourse.glfw.org/t/detecting-keymap-changes-on-x11/3022
**Category:** support
**Created:** [September 5, 2026, 7:20pm UTC](https://discourse.glfw.org/t/detecting-keymap-changes-on-x11/3022 "2026-09-05T19:20:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Geolykt](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/geolykt/32/1087_2.png) [@Geolykt](https://discourse.glfw.org/u/Geolykt)
#### Post date: [September 5, 2026, 7:20pm UTC](https://discourse.glfw.org/t/detecting-keymap-changes-on-x11/3022/1 "2026-09-05T19:20:15Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)
#### Post date: [September 6, 2026, 6:19pm UTC](https://discourse.glfw.org/t/detecting-keymap-changes-on-x11/3022/2 "2026-09-06T18:19:44Z")

</div>

Welcome to the GLFW discourse.

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

---

<div class="post-metadata">

### Author: ![Geolykt](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/geolykt/32/1087_2.png) [@Geolykt](https://discourse.glfw.org/u/Geolykt)
#### Post date: [September 6, 2026, 10:45pm UTC](https://discourse.glfw.org/t/detecting-keymap-changes-on-x11/3022/3 "2026-09-06T22:45:13Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)
#### Post date: [September 7, 2026, 8:15am UTC](https://discourse.glfw.org/t/detecting-keymap-changes-on-x11/3022/4 "2026-09-07T08:15:00Z")

</div>

I think the implementation of `glfwGetKeyName` has changed a bit since [my initial implementation](https://github.com/glfw/glfw/pull/117) 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.
