You are not logged in.

#1 2022-03-08 01:03:49

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

nkk: simple wayland client library (cairo/pango or opengl on wayland)

I've been frustrated for quite some time that it was really not practical to write wayland clients that do not rely on a major toolkit (qt5/6 or gtk3).  Those toolkits are drastic overkill if all one needs to do is some drawing (e.g., with cairo or gl) or draw some text (e.g., with pango).  But writing a basic wayland client from scratch is a pain.  And after making a couple of them, it was clear that an exceedingly vast amount of the code was shared boilerplate.  I was frustrated that there was no library to take care of the basic setup of a wayland surface and the wayland protocol implementation to receive events, etc.  So I wrote one: nkk.

The name comes from the distance between cairo and wayland (both named after cities roughly 9 thousand km apart).  That's quite a lot of distance to cover, but nkk does it well.  The library was initially called 9kk, but as that is not valid as an identifier in C (for variable/function prefixes) all the in-code prefixes were "nkk" - so I decided that may as well be the library name too.

Nkk is currently still a bit experimental.  There is no guarantee of API stability for any versions with a soname ending with so.0.  But there will not likely be drastic API changes - as the API is quite simple, all the gruesome work is behind the scenes.

The source repo contains a number of tiny examples that show basic usage of nkk for creating and drawing on windows, presenting formatted text, and creating layer-shell windows for backgrounds or docks/task-bars in wayland*.  I've also recently added the ability to create egl windows for open-gl drawing.  I have almost no gl experience, so feedback on how to make this more useful to those who would prefer gl drawing would be most welcome.

Feedback is most welcome.  Bugs are expected.  Nkk is available from the aur

edit: *layer-shell requires compositor support which is currently widespread including from KDE and any QCompositor based compositors and Sway or most wlroots based compositors, but not Gnome/Mutter.

Last edited by Trilby (2023-05-04 14:54:06)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#2 2023-05-04 13:12:32

AhmadRaniri
Member
Registered: 2020-07-14
Posts: 36

Re: nkk: simple wayland client library (cairo/pango or opengl on wayland)

Great !

Offline

#3 2023-05-04 15:03:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: nkk: simple wayland client library (cairo/pango or opengl on wayland)

Thanks for the positive feedback.  If you are using nkk I'd love to hear how and if there are any hurdles you've faced with it.

Side note: the nkk_printf module is on the chopping block so I'd advise against getting too attached to that.  At the time I wrote it I was not familiar with pango's built in markup language which itself is pretty impressive.  I plan on dropping nkk_printf in favor of a few simple helper functions for using pango-markup directly (and perhaps extending it to use a simple markdown formating such as from the md4c library).

At the moment, though my coding time is mostly focused on a new project with similar goals as nkk, but rather than a c library it will allow users to create wayland surfaces/windows in wren script.

Last edited by Trilby (2023-05-04 15:06:08)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2023-05-05 06:58:21

AhmadRaniri
Member
Registered: 2020-07-14
Posts: 36

Re: nkk: simple wayland client library (cairo/pango or opengl on wayland)

I'm looking for a simple cairo implementation on wayland, I'm tinkering tinywl (a simple wayland compositor) and want to add wallpaper / background image feature. I will look at NKK later.

Offline

#5 2023-05-05 12:37:09

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: nkk: simple wayland client library (cairo/pango or opengl on wayland)

Nkk makes creating a background / wallpaper trivially easy and comes with a fully functional example (for png images) of this in 40 lines of C code.  however the background setting will not work on tinywl.  No background setting will work on tinywl as tinywl does not implement the layer-shell protocol.

Dwl may be the lightest compositor that does include the layer-shell protocol.

You can create a fullscreen xdg window in tinywl with a fullsize image on it with nkk (in less than 40 lines of code), but this would not be kept on a background layer (as tinywl has no concept of layers).

Last edited by Trilby (2023-05-05 12:42:29)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2024-01-21 16:07:40

HMN
Member
Registered: 2024-01-21
Posts: 2

Re: nkk: simple wayland client library (cairo/pango or opengl on wayland)

I want to make an audio visualizer layer and nkk seems like an easy way to do something like that, but I can't even compile the examples.
I am getting the following error
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/libnkk.so: undefined reference to `wl_egl_window_destroy'
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/libnkk.so: undefined reference to `wl_egl_window_create'
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/libnkk.so: undefined reference to `wl_egl_window_resize'
collect2: error: ld returned 1 exit status

Offline

#7 2024-01-21 18:11:46

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: nkk: simple wayland client library (cairo/pango or opengl on wayland)

I'm not able to replicate that error - please post the complete output from the build attempt so I can see what linker command is actually used.

EDIT: wait - this is while attempting to build the examples, but you seem to be using an nkk library that has not been installed.  So how exactly are you trying to build these?  If the package isn't built and installed you will not have the .pc file in a location where pkgconf will find it - that will result in errors much like this if you don't set LDLIBS properly yourself.  Specifically you'd need to add -lwayland-egl to address this error - but if you are not using pkgconf, there are a number of other libs that will need to be specified as well.

Last edited by Trilby (2024-01-21 18:22:45)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2024-01-21 20:58:15

HMN
Member
Registered: 2024-01-21
Posts: 2

Re: nkk: simple wayland client library (cairo/pango or opengl on wayland)

Thanks for the reply, I missed the -lwayland-egl flag.
I used the makefile that came with the examples and it doesn't have it.

Offline

#9 2024-01-21 21:37:06

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: nkk: simple wayland client library (cairo/pango or opengl on wayland)

No, the makefile doesn't list the lib flags explicitly, but no Makefile should: it uses pkgconf.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB