Closed scrouthtv closed 3 years ago
When I first was trying to use xproto
, I couldn't figure out how I'd get the drawable that was needed for drawing.
I wanted one of the core aspects of this example to be demonstrating that the drawable is (for very basic use cases) the window itself.
What are we going to do about the missing font issue?
The example font that is often used is simply fixed
(which is afaik installed by X).
However, I also want to demonstrate writing UTF8 characters (the ö), but fixed
does only have a very limited character set.
I tried finding a font that would be preinstalled on many systems, looks like that didn't work out.
It is possible to see the available fonts using xfontsel
.
xproto
can also list available fonts to the developer using ListFonts()
.
However, I don't know how to determine which of these support unicode characters.
Could you kindly try the font spec
-*-*-*-*-*-*-14-*-*-*-*-*-iso10646-1
However, I also want to demonstrate writing UTF8 characters (the ö), but
fixed
does only have a very limited character set.
I don't have a problem with fixed
.
But with unicode and fonts it's a little bit tricky (I think). If I wanted "more unicode" demonstration, I would pick a text like Hellö 世界!
, where the fixed
font will fail like the -*-*-*-*-*-*-14-*-*-*-*-*-iso10646-1
font (and maybe the -gnu-unifont-*-*-*-*-16-*-*-*-*-*-*-*
too).
I'm a little bit in the dark, how to handle this, there is no easy solution (If there is, I would like to know). Few thing come into my mind, like bundle font with app and/or use enviroment variables, input flags or some config file to let the user choose desired font. But for simplicity of this example, I would go with fixed
and leave a comment about some possible drawbacks.
I don't have a problem with
fixed
.
I just tried again, and now it's working for me too. I guess I just had something wrong during my first tries.
-*-*-*-*-*-*-14-*-*-*-*-*-iso10646-1
This simply selectes any font that is iso10646-1 encoded, which is basically the character encoding of Unicode. So any of these fonts should have at least a basic set of extended latin characters.
But for simplicity of this example, I would go with fixed and leave a comment about some possible drawbacks.
Sounds good!
TLDR: How to create a window and draw / fill things using
(the white border outside the black border is generated by my WM, should not be there for you)
xproto
:A bit of backstory: I originally got into
So I got into
xgb
because I was working on a go implementation of thexwd
(x window dump) file format and I needed to create small windows with randomly colored pixels, something like this:xproto
and how to create images and such.I cloned this example originally from Alex Kesling's testing which is basically a Go copy of an example in the
xcb
documentation.I adapted some things to go nicer along the
create-window
example, added commentary and some more things (e. g. drawing text and filling a rectangle).