Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Post by tramp »

For creating LV2 UI's I end up more and more writing the same code, so I decided to wrote a Layer for it.
It's supposed to create, manage, draw, and destroy X11 widgets with a cairo surface to draw.
Additional to subscribe to and handle events.

I decided to put it in the Public Domain, so everyone could do what ever he /she want's with it.
Image

Now, here is the usual "hello world":

Code: Select all

#include "xputty.h"

static void draw_window(void *w_, void* user_data) {
    Widget_t *w = (Widget_t*)w_;
    cairo_push_group (w->cr);
    cairo_set_source_rgb (w->cr, 1, 1, 1);
    cairo_paint (w->cr);
    cairo_pop_group_to_source (w->cr);
    cairo_paint (w->cr);
}

int main (int argc, char ** argv)
{
    Display *dpy = XOpenDisplay(0);
    XContext context =  XUniqueContext();
    Widget_t *w;

    w = create_window(dpy, DefaultRootWindow(dpy), context, 0, 0, 300, 200);
    XStoreName(dpy, w->widget, "Xputty Hello world");
    w->func.expose_callback = draw_window;
    bool run = true;
    loop(w,context,&run);
    destroy_widget( w, context);
    XCloseDisplay(dpy);
    return 0;
}
producing this window:
Image

The repository contain a example folder showing some of the features supported by the layer.
It's a tiny, but powerful abstraction of the X11 low level API to easier the process to create nice GUI's.
Documentation is included in the source code, it's a single header and a single c file.
All together just 654 lines, were most lines taken by documentation.

So, here you go:
https://github.com/brummer10/Xputty
On the road again.
User avatar
sadko4u
Established Member
Posts: 986
Joined: Mon Sep 28, 2015 9:03 pm
Has thanked: 2 times
Been thanked: 359 times

Re: Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Post by sadko4u »

Good start. Exploring your latest plugins, I wondered why you haven't done it already previously.
LSP (Linux Studio Plugins) Developer and Maintainer.
tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Re: Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Post by tramp »

Up to the MatchEQ all GxPlugins just use a single window, all the rest is done with a bit of maths and a lot of cairo. :)
I used to use a generator for the GUI's, so the source may look like copy and past, but nope, they are simply generated from a skeleton bundle package. Some small edit's afterwards, and done. That's why I never had the pressure to do a real widget toolkit.
Now, with the MatchEQ that has changed, there I need dynamic menu's, button's, text-input boxes, well, the usual widget stuff.
As I long wanted to port the guitarix plugis as well to X11, I've now started to do the frame work.
On the road again.
tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Re: Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Post by tramp »

Nearly there, most of the base is set up now, I guess one or two day's more, and the fun begins. :twisted:
On the road again.
tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Re: Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Post by tramp »

. . and now the first widget's been implemented, like buttons, sliders and knob. Also a theming engine is in place.
A example for how to use it is in the examples folder.
On the road again.
folderol
Established Member
Posts: 2072
Joined: Mon Sep 28, 2015 8:06 pm
Location: Here, of course!
Has thanked: 224 times
Been thanked: 400 times
Contact:

Re: Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Post by folderol »

Looks interesting
The Yoshimi guy {apparently now an 'elderly'}
tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Re: Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Post by tramp »

. . slowly growing, now have menus, check and radio menus, and a png to binary link in and read out struct.
On the road again.
tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Re: Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Post by tramp »

. . . and now have a example LV2 plugin which shows how to use Xputty to create LV2 plugin UI's.
On the road again.
tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Re: Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Post by tramp »

. . . and that's how it looks now.

Image
On the road again.
tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Re: Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Post by tramp »

And that's how the first ported guitarix LV2 plug looks with xputty:
Image
On the road again.
User avatar
Loki Harfagr
Established Member
Posts: 268
Joined: Thu Aug 02, 2018 1:28 pm
Has thanked: 151 times
Been thanked: 53 times

Re: Xputty - damn tiny abstraction Layer to create X11 window/widgets with cairo surfaces

Post by Loki Harfagr »

tramp wrote: Sat Mar 07, 2020 2:10 pm And that's how the first ported guitarix LV2 plug looks with xputty:
Image
Wow! Really nice!
Post Reply