LSP Window Subsystem Library

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
User avatar
Established Member
Posts: 753
Joined: Mon Sep 28, 2015 9:03 pm

LSP Window Subsystem Library

Post by sadko4u »

This library provides abstraction layer for working with window subsystem of the target software platform.

This library does not provide or use any global variables and can be easily used with other versions of itself. Factroy function should be used to build most suitable display instance.

Curently only X11 window subsystem is supported.

It provides:
  • Common event format definition and constants.
  • Factory for building most suitable display.
  • ws::IDisplay interface for accessing the graphics display.
  • ws::IWindow interface for accessing windows.
  • ws::IR3DBackend for accessing accelerated 3D rendering backends.
  • Asynchronous data flow primitives:
    • IDataSource as a data source.
    • IDataSink as a data collector.
    • IEventHandler for handling events.
  • Drawing primitives:
    • ws::Font to manage font properties.
    • ws::IGradient to manage gradients.
    • ws::ISurface to use drawing surfaces.
Example usage:

Code: Select all

#include <>

using namespace lsp;

// Event handler class for window events
class Handler: public ws::IEventHandler
        ws::IWindow    *pWnd;

        inline Handler(ws::IWindow *wnd)
            pWnd        = wnd;

        virtual status_t handle_event(const ws::event_t *ev)
            // Triggered redraw request, just fill the window with some color
            if (ev->nType == ws::UIE_REDRAW)
                Color c(0.0f, 0.5f, 0.75f);
                ws::ISurface *s = pWnd->get_surface();
                if (s != NULL)

                return STATUS_OK;
            // Triggered close request, force display to quit main loop
            if (ev->nType == ws::UIE_CLOSE)
            // Call parent handler (can be omitted since 
            // IEventHandler::handle_event is just a stub method)
            return IEventHandler::handle_event(ev);

int main(int argc, const char **argv)
	// Create display
    ws::IDisplay *dpy = ws::lsp_create_display(argc, &argv[1]);
    // Create window and initialize
    ws::IWindow *wnd = dpy->create_window();
    wnd->set_caption("Test window", "Test window");
    wnd->set_window_actions(ws::WA_MOVE | ws::WA_RESIZE | ws::WA_CLOSE);
    wnd->resize(320, 200);
    wnd->set_size_constraints(160, 100, 640, 400)

    // Show the window at the center of the screen
    ssize_t sw, sh;
    size_t screen = wnd->screen();
    dpy->screen_size(screen, &sw, &sh);
    wnd->move((sw - wnd->width()) / 2, (sh - wnd->height()) / 2);

	// Setup handler for the window
    Handler h(wnd);

    // Enter the main event loop

    // Destroy window and display
    delete wnd;
URL to GitHub:
LSP (Linux Studio Plugins) Developer and Maintainer.

Post Reply