You are not logged in.

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

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 28,362
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: 28,362
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: 28,362
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

Board footer

Powered by FluxBB