jezek / xgb

The X Go Binding is a low-level API to communicate with the X server. It is modeled on XCB and supports many X extensions.
Other
130 stars 13 forks source link

Shapes example #4

Closed scrouthtv closed 3 years ago

scrouthtv commented 3 years ago

TLDR: How to create a window and draw / fill things using xproto: image (the white border outside the black border is generated by my WM, should not be there for you)

A bit of backstory: I originally got into xgb because I was working on a go implementation of the xwd (x window dump) file format and I needed to create small windows with randomly colored pixels, something like this: image So I got into 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).

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

scrouthtv commented 3 years ago

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.

scrouthtv commented 3 years ago

Could you kindly try the font spec -*-*-*-*-*-*-14-*-*-*-*-*-iso10646-1

jezek commented 3 years ago

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. shapes 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). shapes iso10646 jp

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.

scrouthtv commented 3 years ago

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!