Finally, some *visible* result from my #X11 / #xcb experimenting with #freetype and #harfbuzz for font rendering. πŸ₯³

https://github.com/Zirias/xmoji/commit/80e953a98048419124f0a2ef72e9eaefb8812789

There are issues to fix:

* Sometimes, it renders nothing visible. I'm not sure where this indeterminism could come from 🫀
* xcb/render.h offers a struct for color with fields for red, green, bue and alpha (in this order). If I use {0,0,0,1} here, I see nothing on a white background. {1,0,0,0} gives me black text. πŸ€” Now either I'm doing something *completely* wrong, or there's some confusion somewhere whether colors are ARGB or RGBA format. Huh?

There's also an issue that probably doesn't have a fix. #harfbuzz shaping outputs rendering positions in fractional pixels. I *think* XRender only accepts whole pixels, so I have to round the position for every single glyph. I wonder whether this is a reason for many to use #cairo for rendering?

@thomasadam if you can shed some light on one of these issues, that would be awesome, but I guess I'm not exactly "stuck" here, need to do more research πŸ˜…

TextRenderer: Make something render Β· Zirias/xmoji@80e953a

This has still several bugs, but most of the time, it renders "helloworld" using freetype, harfbuzz and XRender.

GitHub

@thomasadam Ha! Adding some color (lol) helped to identify and fix the issues πŸ˜†

There were two different ones. First, the color used was non-deterministic. Tracked that down to sometimes picking the wrong XRender picture format 🀦 (turns out there can be more than one 32bpp format available, you have to check the shift values of the color channels to make sure you got ARGB) ... now the xcb_render_color_t works as expected.

Second, sometimes it rendered nothing at all. Tracked that one down to freeing the rendering data too early, the request has just a pointer and might still be queued by #xcb πŸ™ˆ

Ok, "simple" text rendering: done. βœ…

@thomasadam I start wondering whether "shaping" artifacts from "rounded" #glyph positions can be avoided at all? πŸ€”

If I understand that correctly, you always rasterize one glyph at a time with #freetype. So, it starts at a "whole" pixel position, right? Do I overlook anything?

@zirias Yes, that's correct. Do you have an example of what you're trying?

@thomasadam I'm using #harfbuzz to "shape" my text. It's giving me "advance" values in 1/64th pixels. To have that shaped text rendered "perfectly", you'd have to position the glyphs in that high resolution and rasterize as a whole I guess. Seems that's just not possible with #freetype though.

So, I'm using the info from harfbuzz to position individual glyphs at the nearest whole-pixel position instead. 🀷

Just wondering whether I overlooked something, but I guess that's indeed the way to go...

https://github.com/Zirias/xmoji/blob/1fb2e5e01558a6dd72cbf0048ba4389aaa48d180/src/bin/xmoji/textrenderer.c#L159

xmoji/src/bin/xmoji/textrenderer.c at 1fb2e5e01558a6dd72cbf0048ba4389aaa48d180 Β· Zirias/xmoji

Contribute to Zirias/xmoji development by creating an account on GitHub.

GitHub

@thomasadam Taking it as it is right now (cause I GUESS there's no way to "do better", give me a hint if I'm wrong) and moving on:

I need #widgets now!

This text rendering is currently hardcoded into my "window" which is *meant* to model just some "generic" #X11 window. It should instead contain some generic widget (probably some tree of these) to show "whatever". In some sense, this would be a (tiny) "toolkit" for #xcb then ...

Years ago, I experimented with raw #win32 (but using microsoft's "common controls" lib), and there, every "control" was actually a window. From what I understood so far, you don't do that with #X11, but instead draw on your actual window surface using offset positions ... is this correct? πŸ€”

@zirias Without seeing the design of this’s, you should remember that there’s a difference between providing drawing primitives (widgets), and the behaviour of the window itself which behaves as widgets should.

So, for example β€” by all means provide pre-defined widgets with whatever meds to be in them. If you’re going down the route of providing your own primitives, Fvwm{Form,Script} will be useful to you here. Or you could use a higher-level library like Xt.

As for window behaviour, let’s talk separately about that…

@thomasadam I understand only parts of this I have to admit πŸ˜•

Currently working on "optimizing" my interfacing with #xcb first, I think I finally understood how it works (requests, replies, errors) and now I try to use that fully asynchronously with the least possible overhead (on the socket) while automatically injecting a dummy "sync" request when it's *really* necessary ... commit following soon 😏

But then, yep, widgets is what I will need. I'm thinking about completely ignoring all #X11 drawing primitives and just use #XRender for everything, hoping that's a somewhat sane thing to do πŸ˜…

@thomasadam So, I guess *this* is done:
https://github.com/Zirias/xmoji/commit/cd0a2db4f871f3d6a44dcfce6d0c76a4df93c850

The core of my fully async #xcb wrapping API are two macros I finally documented (necessary because otherwise, I'll forget myself, and some _Generic() magic isn't exactly readable πŸ™ˆ):
https://github.com/Zirias/xmoji/blob/cd0a2db4f871f3d6a44dcfce6d0c76a4df93c850/src/bin/xmoji/x11adapter.h#L35

It does what I want, requests are minimized, this debug log shows the result after triggering redraws by resizing the window and minimizing/restoring it πŸ₯³

(No excuse left now to tackle a widgets concept πŸ˜…)

X11Adapter: Rework async X11 handling Β· Zirias/xmoji@cd0a2db

Add CHECK() macro for only checking for errors. Provide overloads for either calling a specific callback or just log something and optionally fire a generic event on a given id. Document usage of ...

GitHub

@zirias Again, just eyeballing this far too quickly than I’d like to right now, things looks good to me.

Will look thoroughly when I’ve more time.

@thomasadam I might be sidetracked again: I guess I found a viable solution for my "glyph positioning issue".

It seems #freetype can use an offset when rasterizing a glyph:
https://freetype.org/freetype2/docs/reference/ft2-outline_processing.html#ft_outline_translate
Should be possible to use that for rasterizing 4 variants of the same glyph, shifted by quarter pixels.

A truetype font will have a maximum of 2^16 glyphs, an #XRender glyphset can contain up to 2^32 glyphs ... just adding two bits here for somewhat sane render quality seems like a good idea.

I'll try to implement that first before testing something else πŸ™ƒ

Outline Processing - FreeType-2.13.2 API Reference

API Reference Documentation for FreeType-2.13.2

@thomasadam Awesome, this is the solution πŸ₯³: Reserve two bits of the #glyph id in the #XRender glyphset to indicate one of 4 horizontal shift positions for the same glyph. Result looks nice IMHO.

Screenshots:
1. New rendering
2. Old rendering 8x zoom
3. New rendering 8x zoom

https://github.com/Zirias/xmoji/commit/bbc9cd2b5baa79d5a948a1169e1384a0eba5d793

Font/TextRenderer: X positioning to quarter pixels Β· Zirias/xmoji@bbc9cd2

Add two more bits to glyphids to allow 4 variants of the same glyph for 4 different X positions, so the positions obtained from harfbuzz shaping can be approximated a lot better.

GitHub

@thomasadam Made the subpixel resolution configurable.

https://github.com/Zirias/xmoji/commit/8b0f0c8cdc52452afa63de9bdf439e53940d0223

Here's a render test with all possible values (0 to 6 bits subpixel precision).

Only whole pixels is barely acceptable, the kerning is just broken (see the huge gap between the two lowercase L). Two bits for subpixels already looks pretty good, more don't seem to improve the result here further although I can spot a minimal difference up to 4 bits πŸ™‚. Seems a "sane" value should be 2 or 3 bits for this.

#XRender #xcb #text #rendering #freetype #harfbuzz

Font/TextRenderer: Configurable subpixel precision Β· Zirias/xmoji@8b0f0c8

* Add Font constructor parameter to specify number of subpixel bits in the range 0-6 * Calculate valid XRender glyphid range from this and the number of glyphs in the font * Use this info in Te...

GitHub

@thomasadam So far, work on #xcb-based #widgets seems pretty straight-forward.

My widget base class already does a few things, like maintain size and minimum size, padding, alignment, an inherited color-set, optionally draw a background, etc....

Only one concrete widget so far, a simple text label (at least it accepts multi-line text and calculates the line positions from the line height #freetype reports).

Here's the code constructing this super-simple window content:
https://github.com/Zirias/xmoji/blob/852788c97965bd97ea4e7e2e4461deb686ec7b4b/src/bin/xmoji/xmoji.c#L36

xmoji/src/bin/xmoji/xmoji.c at 852788c97965bd97ea4e7e2e4461deb686ec7b4b Β· Zirias/xmoji

Contribute to Zirias/xmoji development by creating an account on GitHub.

GitHub

@thomasadam Let's see what we have so far (#X11 properties). Looks mostly sane I'd say?

But what's _NET_WM_ICON_VISIBLE_NAME, who is setting that, and how does it end up so garbled? 😦

For the window name, so far I only set _NET_WM_NAME (utf8) and WM_NAME (converted to latin1)....

@zirias Do you have an icon name specified for the window? Is WM_ICON_NAME set? If you do -- certainly in fvwm's case -- it will also set _NET_WM_ICON_VISIBLE_NAME to match _NET_WM_VISIBLE_NAME
@thomasadam No, should I set an icon name? I'll try that and see whether something changes πŸ˜‰

@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 πŸ™„

#x11 #xcb #programming

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

Any #X11 or #xcb experts here? πŸ˜…

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 ... πŸ˜…

#X11 #xcb #XRender #scaling #bitmap #font

src/xftglyphs.c Β· master Β· xorg / lib / libXft Β· GitLab

X FreeType library

GitLab

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 πŸ˜…

Font: Use filter matrix for downscaling Β· Zirias/xmoji@79aab88

Contribute to Zirias/xmoji development by creating an account on GitHub.

GitHub

played a bit more with the shape of my filter matrix and now I'm really happy πŸ₯³

rendering a scaled color #bitmap font with "pure" #X11 (with #XRender) using #xcb: done! βœ…

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.

Font: Add SVG support via nanosvg Β· Zirias/xmoji@05ceefb

Contribute to Zirias/xmoji development by creating an account on GitHub.

GitHub

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.

#xcb #X11 #programming

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

#xcb #x11 #programming

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

xmoji/src/bin/xmoji/unistr.h at master Β· Zirias/xmoji

Contribute to Zirias/xmoji development by creating an account on GitHub.

GitHub

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 πŸ˜‰

@zirias I’m no expert. But the short answer is yes, #xkb is the way to go.

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

X11Adapter: Add basic XKB support Β· Zirias/xmoji@86f4744

Use xkbcommon to preprocess keypress events, adding the key symbol and a set of currently effective modifiers. Add test code to Window just generating debug output from this.

GitHub

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 πŸ™ˆ

#X11 #xcb #programming

Ok, my #textbox #widget now has complete support for line editing using the keyboard ... and a blinking cursor πŸ₯³

Still missing: Selections and any sort of mouse support πŸ˜‰

#X11 #xcb #programming

Selections: done. Rendered using a pre-colored src picture using #XRender #composite #glyphs (Still only keyboard input, mouse will be next)

#xcb #x11 #programming #textbox

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

TextRenderer: Add glitch mode for compositeglyphs Β· Zirias/xmoji@b77a9e5

At least with CompositeGlyphs XRender requests, and at least on my Radeon R600 when using Glamor instead of EXA, the origin for the src picture is wrong. This can be "fixed" by adding a p...

GitHub
A commandline flag to enable a workaround really isn't suitable ... so it was time to finally support #XResources. I wasn't happy with the xcb utility lib I found, so I did it from scratch πŸ™ˆ
https://github.com/Zirias/xmoji/commit/95f0ac04e62d46ac02e2e2c24275789fa4a841c9
#X11 #xcb #programming
XRdb: Database parsing and matching X resources Β· Zirias/xmoji@95f0ac0

Contribute to Zirias/xmoji development by creating an account on GitHub.

GitHub

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 … πŸ˜…

#X11 #xcb #programming

Widget/ColorSet: Load colors from X resources Β· Zirias/xmoji@54e8fe0

Give each widget an optional name, so resources can be specified both by class and instance name.

GitHub

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 just had an idea myself: #XPresent would be needed for vsync, but maybe this isn't even the problem and just keeping an offscreen pixmap for the window would already be enough ... πŸ€”

@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. πŸ˜…

#X11 #xcb #programming

@zirias Nice work! You’re an expert now. πŸ™‚

@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 πŸ˜‰

#fvwm3 in #Xephyr is great for testing stuff! 😎

#X11 #xcb #programming

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 😎

#X11 #xcb #programming

Looking at this again, I just noticed the child widget should really expand when more space is available 🀦 ... fixed now moving one single line of code πŸ™ˆ
https://github.com/Zirias/xmoji/commit/7ff0c28083229bab19d5a421ea55bdc9d27c27b9
ScrollBox: Expand child to available height Β· Zirias/xmoji@7ff0c28

Contribute to Zirias/xmoji development by creating an account on GitHub.

GitHub

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 πŸ€ͺ

https://github.com/Zirias/xmoji/blob/e342bd7612b9ce953849e2e8b374591d61c22d5b/src/bin/xmoji/colorset.c#L224

xmoji/src/bin/xmoji/colorset.c at e342bd7612b9ce953849e2e8b374591d61c22d5b Β· Zirias/xmoji

Contribute to Zirias/xmoji development by creating an account on GitHub.

GitHub
@zirias +1 re: #Xephyr! I use it quite heavily for testing #MLVWM & mlvwmrc.

@morgant I see it's even more important for testing a window manager πŸ˜‰

But even for a "normal" client, it's a nice way to test with separate #Xresources, different window managers and configurations etc without fiddling with your main X session config πŸ‘

@zirias You can also use it to somewhat sandbox X11 applications to mitigate input monitoring. See https://github.com/morgant/Xsunaba?tab=readme-ov-file as an example implementation, though slightly #OpenBSD specific. Sadly, the original article I based it on seems to be down.
GitHub - morgant/Xsunaba: Sandbox X11 applications on OpenBSD

Sandbox X11 applications on OpenBSD. Contribute to morgant/Xsunaba development by creating an account on GitHub.

GitHub
@zirias @thomasadam
Did you try to build it on #OpenBSD yet?
I can sure give it a go
@jhx @thomasadam I only build/test it on my #FreeBSD desktop so far ... but as it really just uses basic POSIX APIs, xcb and a few very common support libs (fontconfig, freetype, harfbuzz, xkbcommon), I'd be very surprised to find portability issues at this stage πŸ˜‰ but well, who knows ... 🀷
@zirias @jhx If you do, let me know. I can help.
@zirias @thomasadam
Wrote it onto the todo list for tomorrow. Got a bare metal OpenBSD install here to try it on
@jhx OpenBSD most likely doesn't offer a port for my own lib I'm using here, so you'd have to build that one first (and maybe fiddle with PKG_CONFIG_PATH so it's found) πŸ˜‰
https://zirias.github.io/poser/
poser – a C framework for POsix SERvices

@zirias
I can try that for sure
@zirias
I can try at least!

@jhx Now I'm curious, although I assume it *should* work.

Just finished support for simple (text-only) PRIMARY selection, btw πŸ˜‰

While testing/debugging this with some extra debug logging, I found "funny" behavior in #chromium. It's asking my window like 10 times(!) for TARGETS (used to learn the list of data types I can offer, which I always answer with just "UTF8_STRING, TEXT, STRING") before *finally* just asking for UTF8_STRING 🀯

@zirias
Gotta try it tomorrow - currently doing some fiddling here in the lab πŸ˜‚

That is kinda strange from chromium indeed πŸ˜†

@jhx Yeah, really wonder what kind of bug *this* is. It's certainly a bug (of the weird kind, I mean, how do you manage that? Have every thread ask the same thing at once or what?). It doesn't *break* anything, so probably nobody cares, but it certainly wastes resources big time πŸ˜‚

Meanwhile, I'll probably have to completely redesign my own "X11 selection" code. It works, but it's completely non-compliant, ignoring maximum request sizes, "alloc" errors from writing over-sized properties, INCR transfer method for transferring selections in chunks, etc ... #ICCCM is really a complex beast 🀯

@jhx Testing my current state in #Xephyr, without any #Xresources loaded, running #fvwm3 with no configuration ....

I guess my "ColorSet" class needs a few more values. Only one flavor of "background color" for the default state (not selected/inactive/hovered) doesn't cut it, e.g. a #TextBox should always stick out ... πŸ€”

#X11 #xcb #programming

@zirias
Finding more things to take a look at from what I gather πŸ˜‚

The joy of coding 😎

@jhx First step done, moved the #X11 #selection handling to an own class: https://github.com/Zirias/xmoji/blob/master/src/bin/xmoji/xselection.c

Suddenly doesn't look that complex any more, so I can work on it to achieve ICCCM compliance πŸ˜‰

xmoji/src/bin/xmoji/xselection.c at master Β· Zirias/xmoji

Contribute to Zirias/xmoji development by creating an account on GitHub.

GitHub

@zirias
So that step is done πŸ˜‰

ICCCM compliance on the table now πŸ™‚
(Hope that goes smooth)

@jhx Well then, #ICCCM compliance status of my #X11 #selections implementation: "I think so" πŸ™ˆ

Only supports text content so far (without support for this weird/ancient COMPOUND_TEXT encoding, but I guess that's not strictly required?), but in theory extensible for other data formats. Almost 1000 lines of C source πŸ€ͺ

https://github.com/Zirias/xmoji/blob/master/src/bin/xmoji/xselection.c

xmoji/src/bin/xmoji/xselection.c at master Β· Zirias/xmoji

Contribute to Zirias/xmoji development by creating an account on GitHub.

GitHub

@jhx Also needed to add this little new class:
https://github.com/Zirias/xmoji/blob/master/src/bin/xmoji/timer.c

For a correct #X11 #selection implementation, you *do* need timeouts, cause you never know whether your communication peer might misbehave, freeze or crash πŸ˜…. There's only one "real time" setitimer() per process (which I already use to drive a blinking cursor btw), but #POSIX interval timers came to the rescue. 😎

I really have no use for their nanosecond(!) precision ... but then, didn't find any other good option either. 🀷

xmoji/src/bin/xmoji/timer.c at master Β· Zirias/xmoji

Contribute to Zirias/xmoji development by creating an account on GitHub.

GitHub