@thomasadam Yes, when I set an icon name (WM_ICON_NAME and _NET_WM_ICON_NAME), the property just reflects that.
So I guess in absence of an icon name, fvwm tries to use the window name for it and reflects that in _NET_WM_ICON_VISIBLE_NAME?
Could the garbled encoding be a bug in fvwm? 🤔
@thomasadam And another "interesting" issue that only happens sometimes ... I just added lots of debug output to analyze why my Window sometimes draws when it should close, and here's the proof: that's triggered by a bogus(?) expose event (that's only sometimes received). The preceding ClientMessage is the WM_DESTROY one. Any idea what could cause this and whether I can somehow stop it from happening? 🧐
A workaround should be simple though, just stop processing expose events for a window that already requested unmapping 🙄
@thomasadam Adventures in #X11 #programming using #xcb ... I think I discovered some strange (and, undocumented?) behavior in #Xorg.
Getting more seemingly(!) "stray" Expose events, I finally discovered what's happening. I already decoupled my drawing logic from handling Expose, and instead maintain information in a widget whether it's visible and invalidated (with invalidation triggered by whatever, e.g. an Expose event). Only after processing a batch of input from the X server, I check whether a widget is both visible and invalidated, and if yes, draw it. So far a common pattern to avoid excessive drawing.
Now, setting the "root" widget (the window) visible as soon as a MapNotify is received, this *could* lead to start drawing before receiving the first Expose. Drawing still works perfectly fine, but this somehow delays the Expose event until something else "happens" to the window (like moving it), then you suddenly receive this Expose ... 🤯
Solution: Only set the window "visble" after the first Expose event is received...
I guess it would be impossible to trigger this with #Xlib because its API makes you wait for the response to every request... 😉
@zirias Yeah. That’s probably not the best approach.
Not sure if you’d be up for it, but I’d be more than happy to spend some time with you on IRC or Jitsi to go through this with you, if that’s helpful?
@thomasadam Thanks, I just asked over there (libera) 😉
Meanwhile it *seems* to all work, so the next "big thing" would be to find a way to #render #SVG (and maybe #PNG) #glyphs for "color emojis". I hope to avoid librsvg for that (would pull in rust and cairo ...), so, will test alternatives...
Weird, I remember reading something somewhere on the noto fonts github that seemed to suggest the emoji font used SVG graphics. But peeking into freetype's face and glyph structures with lldb, it looks more like it's plain RGBA bitmap data ...
Well then, just need to figure out a good way to scale that.
I wonder whether it's possible to do #XRender #CompositeGlyphs requests with a scaling transformation applied? This would certainly be the simplest solution.
Had an idea, pure genius 🙈: Just check how #Xft is doing it.
Well, turns out it's literally "just doing it":
https://gitlab.freedesktop.org/xorg/lib/libxft/-/blob/master/src/xftglyphs.c?ref_type=heads#L327
Maybe I should just do it ... 😅
Rendering a color #glyph with #XRender was the first issue, finally solved. It's surprisingly complicated, because with XRender, a glyph is always an alpha mask, and if it has 4 channels, the actual alpha channel is ignored and the color channels are interpreted as per-component alpha.
To get a sane rendering, I had to create two(!) glyphsets for colorfonts, one ARGB, one alpha only. First render the ARGB one to a temporary pixmap. Then use this pixmap as the source for rendering the alpha glyphset to the real target. Oh, wow 😅
Now, time to improve scaling, just did a stupid "nearest neighbor" for the first poc ... (screenshot looks good because it's unscaled)
Replaced the super-stupid "nearest neighbor" with some still pretty naive averaging, and yes, that's slightly better, but I guess I won't be happy with that ...
probably time to dig deeper into "good" #scaling (#resampling) algorithms
Aha! A simple filter matrix improves it a lot:
https://github.com/Zirias/xmoji/commit/79aab888be379303ad8cafdd27f34f91b276275f
I guess that'll do for my purposes. Far from perfect, but IMHO acceptable 😅
Code for testing emoji rendering ... containing emojis ... naturally! 😁
Coding in C is still the most fun.
More progress exploring #X11 #programming with #xcb 🥳
Added a first "container #widget", a vertical box, allowing me to display two "text labels" at the same time!
Screenshots:
1. No arguments (which will just ask #fontconfig for "sans" and "emoji" to get the respective system defaults)
2. '-font Cambria-18 -emojifont emoji-24'
3. '-font Calibri-18 -emojifont "Twitter Color Emoji-24" -- this one shows there's work left to do, obviously the twitter emoji font uses #SVG for color glyphs ... (so I'm getting the uncolored outlines instead)
#xcb #X11 #programming adventure continued... I managed to add SVG support! 🥳
https://github.com/Zirias/xmoji/commit/05ceefbec24364f42173dadf0bb6bbdcb2653843
Thanks to #nanosvg, I could avoid the dependency "monster" librsvg (pulling in rust and cairo). As long as such nice "just do the thing as simple as possible" #opensource projects exist, good software engineering isn't dead yet!
https://github.com/memononen/nanosvg
Connecting this to #freetype wasn't that hard, except for the "calculate font metrics" part, which I almost certainly got horribly wrong, i just did trial&error until the #Twitter #emoji font looked somewhat sane. 🙈
Here's a screenshot using these SVG emojis in 56pt ... and for comparison Google's "Noto" emojis (scaled by my own bitmap-scaling code) in the same size.
Fixed the #metrics calculations for #SVG #glyphs, replacing most of the floating-point calculations by fixed-point arithmetic using the same formats (26.6 numbers with 16.16 factors) like #freetype. 😎
I'm pretty sure they're really correct finally, I could remove some band-aid extra downscaling that previously hid imprecisions.
IMHO not so nice, but this seems to be a property of the Twitter Emoji font: There's absolutely NO spacing between most of the glyphs 🧐
I tried to fiddle with the 3 different "advance" metrics present in freetype structures, but that doesn't have *any* effect on the glyph positions returned by #harfbuzz (anyone have any idea why? 🤨)
Screenshot shows emojis in 65pt size, below for comparison using the bitmap "Noto Color Emoji" font.
Next thing is working on a #TextBox #widget. This will require, among other things, translating between pixel coordinates and string positions (for selections and drawing a cursor at the correct position).
Of course, #harfbuzz operates on #Unicode codepoints, stored as 32bit unsigned integers. So, yesterday, I started implementing a string class holding the value in both #utf8 and #utf32 and converting between these.
Now I realized this wasn't all to helpful, so I'll start over. What I want is some immutable string class using char32_t internally and offering functions to create mutated clones...
Ok, I now have my immutable string class, featuring static const initialization and, for dynamically allocated instances, reference counting:
https://github.com/Zirias/xmoji/blob/master/src/bin/xmoji/unistr.h
... plus a mutable variation the intended #TextBox #widget should operate on, offering a "view" on its internal data to optimize passing temporaries:
https://github.com/Zirias/xmoji/blob/master/src/bin/xmoji/unistrbuilder.h
Now, I still can't start implementing this widget. First I have to implement getting #keyboard #input with #xcb. I figured I probably won't need #xkb for my purposes, processing core #X11 events should be enough. Of course this involves holding the keyboard mapping state myself 🤨
I can't use any "xcb-util" stuff as this would interfer with my async model integrating xcb with a generic event loop ... but at least I can read this code to figure out how things are supposed to work:
https://gitlab.freedesktop.org/xorg/lib/libxcb-keysyms/-/blob/master/keysyms/keysyms.c?ref_type=heads
Digging a bit deeper, I now figured core #X11 won't help me getting compose-key sequences right? I guess I will need #xkb for this?
Asking experts again to correct me if I'm wrong please ... @thomasadam 😂
Well if that's the case, #xcb offers xkb of course, but it's a damn complex thing. I guess I'll accept yet another dependency instead: #xkbcommon 😉
@thomasadam #xkbcommon is really helpful. Was quite easy to integrate so I can fire my own "keypress" events "enriched" with the correct #X11 keysym (minus control translation, which IMHO isn't all too helpful anyways) plus a set of currently effective modifiers.
https://github.com/Zirias/xmoji/commit/86f47445186114dae3a41e2d9078f0bd104d1234
No compose processing yet, I assume this should better be done per window... (?)
A potential issue I see is that xkbcommon uses #xcb reply functions in some places. It won't break my scheme as long as I only call xkbcommon functions from within my own event/reply handling code, but it *could* in the worst case block for a short time 😕 (possibly when the keyboard mapping is changed)
That'll be a lot of work 😎
Started implementing a #TextBox widget. So far only appends what's typed and draws a (non-blinking) cursor at the end 🙈
Selections: done. Rendered using a pre-colored src picture using #XRender #composite #glyphs (Still only keyboard input, mouse will be next)
Adventures in #X11 #programming with #xcb and #XRender: THE UGLY ...
Took me hours(!) to figure out what's going on here. 🤬 Once I discovered this rendering bug goes away when I force DRI2 with EXA (instead of DRI3 with Glamor), I was finally sure there's a bug outside my code. Never seen it in any other X11 application, but I guess XRender isn't used that much nowadays.
Well, for now, added a "glitch flag" to enable a workaround:
https://github.com/Zirias/xmoji/commit/b77a9e53397907d253f26715a6a5d1d79c49971b
Added color configuration via #XResources, using Widget names and class names … this is pretty nice, a shame so few applications nowadays use this!
https://github.com/Zirias/xmoji/commit/54e8fe063a4f441d4cd5dd2d99d97e0261c74dd2
Found and fixed a few bugs on the way as well … 😅
Next step completed, my #TextBox widget now supports mouse input: click, doubleclick and drag 🥳.
Not so nice: With overall more drawing operations, I see #flicker happening more often 😒. Did some research already, it seems with #XRender, the only way to avoid it would be to render to some #pixmap (instead of the window directly) and use #XPresent to get it on the screen? @thomasadam do you know an "easier" way? 🙈
@thomasadam YES! 🍻🕺
The occassional flicker was *only* caused by several #XRender requests accidentally hitting different frames. Easily solved using a "backing store" pixmap, so a single render request is enough for every (rectangular) update. No need to fiddle with vsync or anything. 😅
@thomasadam That would be (slightly! 😂) exaggerated 😉 but yep, it really starts to work out, I guess it should actually be possible to reach my goal, re-implement my #X11 #emoji #keyboard *without* a "GUI toolkit".
Still lots of things to build. Currently thinking about how to interface with X11 selections (PRIMARY/CLIPBOARD). Next step might be a "scroll-area" widget.
@thomasadam Didn't expect #ICCCM #X11 selection handling to be *that* complex 🤯
I just finished implementing the MULTIPLE method, and have no idea how to ever test that 🫤 ... then still missing: Accepting INCR transfers (sending is done), and also no idea how to test (sending was easy, just pretend a very tiny maximum request size) …
Meanwhile >700 lines of C for handling these selections 😅
@zirias Yeah — it’s horrendous what you have to do to support this. I’ll try and take a look at what you’ve done this evening…
Well done for getting this far! :)
@thomasadam Meanwhile I think my implementation is "complete" regarding the ICCCM minimum requirements. It doesn't support COMPOUND_TEXT, but from what I understand, that isn't a strict requirement. It only supports transferring text data so far, but is theoretically extensible ... 😉
I could test receiving INCR by just running two instances with artificially limited request size. Still no idea how to ever test serving MULTIPLE requests correctly (short of writing my own test program for that, but I'm too lazy to do that right now …) 🤨
I now moved to the "scrolling" topic.
Added a #ScrollBox #widget, and it works! 🥳 It just wraps one other widget and updates its origin according to the scroll position.
So far, scrolling only works with the mouse wheel, but adding handlers for left-clicks and "drags" should be relatively simple 😉
Mouse control of my scroll bar is complete 🍻 (wheel, click above or below, drag). The "ScrollBox" widget still needs configurable properties (scroll step, min height), then it's "done".
Next thing needed: a tab container 😎
I got sidetracked working on #XResources support ... it all started from the wish that a child #widget should used its container's font when it doesn't have its own font configured (will be helpful e.g. for tooltips...)
Now I also integrated command-line overrides for resources in my XRdb resource database implementation, which is very cool. Actually, this system slightly reminds of CSS ... I can configure the looks of my #X11 application very flexibly!
Last thing I added was support for more formats to specify colors, plus querying the X server for named colors 😎.
#TIL: #XLib has some "color management" code and can parse and convert color specifications in different color spaces. 🤯 Ok, I don't want to link XLib (only #xcb), and I won't implement *this* myself, #RGB and #RGBA (together with "well-known" X11 color names) should really be all you ever need 🤪