I managed to improve my xkbgrowl program a bit this week-end, the icon on the program sending the event is now converted to a growl icon within the program and not round-tripped via the file-system. Using the file-system has the advantage that I could use existing APIs: X11 knows how to export files in the x-bitmap format, a format that strangely enough, OS X still can read. Safari on OS X is one of the last browsers that supports that strange format (don’t bother checking for buffer overflows, I already did).
Doing the conversion explicitly in the program required some API archeology, I used XLib a bit when I was in the university, but I have largely forgotten what I did then, and I was mostly concerned in pushing pixels out, her the goal is to read some structures provided by the window manager.
I managed to get something that kind of works, which basically mimics the behaviour of XWriteBitmapFile
, resolving the pixels using XGetPixel
. This means I can get the same black/white images I already had, but instead of pushing to a file, I write the data into a buffer which I give the Core Image, which I used to scale the image and serialise it for Growl.
The frustrating part is that XGetPixel
does not return information in RGB
format, instead I get a reference in some colour table. From the documentation, I should call XQueryColor
to resolve the colour into RGB, but when I do so, the whole program crashes with an illegal access. So I’m stuck with OK images for basic programs like xlogo
and broken ones for things link xterm
.
It is interesting to consider the two graphic APIs I’m trying to connect: their designs are a quarter century apart the first one handles colours as precious resources that are named and allocated and associated with a screen, you cannot simply work with an unattached image buffer. The other is all about buffers and transformations, memory is not the main constraint, but structuring the data-flow in a way that is understandable for the GPU is.
Anyhow, the new version is available in the releases section of github.