emoon / rust_minifb

Cross platfrom window and framebuffer crate for Rust
MIT License
1k stars 95 forks source link

[X11] Fix window names not supporting UTF-8 #295

Closed edgarogh closed 2 years ago

edgarogh commented 2 years ago

Currently, UTF-8 characters don't render correctly in window titles (c.f. screenshots below). This is likely due to the fact that the X11 driver only uses XStoreName, which sets a name in a way that's not really intended for the user to see. This PR fixes that, making it possible to use UTF-8 characters (I tested diacritics and emojis) in the window title.

How ?

In addition to the existing XStoreName call, I also call XChangeProperty to set the _NET_WM_NAME/UTF8_STRING property. This adds one possible point of failure: XChangeProperty takes an int nelements as its last parameter, and the actual length of the string could be bigger than what a c_int can store. In the unlikely event that this happens, a specific error message is returned.

Screenshots (context: I replaced a dash - with an em dash in the fractal example)

Before: fractal After: fractal2


Feel free to ask me to change a few things if needed, this PR is spontaneous, and I've never got to discuss the issue before.

emoon commented 2 years ago

Great! Thanks :)