Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shapes example #4

Merged
merged 8 commits into from
Mar 12, 2021
Merged

Shapes example #4

merged 8 commits into from
Mar 12, 2021

Conversation

scrouthtv
Copy link

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
Copy link
Author

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.

Copy link
Owner

@jezek jezek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the libery to fix typos and reword a comment.
I had some difficulties running the example on Ubuntu (see comments near font).

Note: As you can see, I was able to push commit directly to your master branch. This is because you gave me permission to edit your PR. It's better practice to start a PR from a branch, so the maintainer (if granted privileges) can only edit the branch (and not master directly).

examples/shapes/main.go Outdated Show resolved Hide resolved
examples/shapes/main.go Outdated Show resolved Hide resolved
examples/shapes/main.go Outdated Show resolved Hide resolved
examples/shapes/main.go Outdated Show resolved Hide resolved
examples/shapes/main.go Outdated Show resolved Hide resolved
fontname := "-gnu-unifont-*-*-*-*-16-*-*-*-*-*-*-*"
err = xproto.OpenFontChecked(X, font, uint16(len(fontname)), fontname).Check()
if err != nil {
fmt.Println("Failed opening the font:", err)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got an:

Failed opening the font: BadName {NiceName: Name, Sequence: 8, BadValue: 67108870, MinorOpcode: 0, MajorOpcode: 45}

on Ubuntu MATE 20.10

examples/shapes/main.go Outdated Show resolved Hide resolved
examples/shapes/main.go Outdated Show resolved Hide resolved
examples/shapes/main.go Show resolved Hide resolved
examples/shapes/main.go Show resolved Hide resolved
@scrouthtv
Copy link
Author

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
Copy link
Author

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

@jezek
Copy link
Owner

jezek commented Mar 10, 2021

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.

examples/shapes/main.go Outdated Show resolved Hide resolved
@scrouthtv
Copy link
Author

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!

@jezek jezek merged commit 0e0f116 into jezek:master Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants