A standalone implementation of the wind client protocol in C
Go to file
apio c8a30d2580
feat: Add support for window layers and pledges
Recently added in the upstream API.
2024-12-13 23:59:55 +01:00
src feat: Add support for window layers and pledges 2024-12-13 23:59:55 +01:00
.clang-format Ready. Set. Go! 2024-03-31 12:56:50 +02:00
.gitignore Ready. Set. Go! 2024-03-31 12:56:50 +02:00
LICENSE Ready. Set. Go! 2024-03-31 12:56:50 +02:00
Makefile Ready. Set. Go! 2024-03-31 12:56:50 +02:00
README.md feat: Add support for window layers and pledges 2024-12-13 23:59:55 +01:00

libwind

A standalone implementation of the wind client protocol in C

Why?

wind is the windowing system for the Luna operating system. While Luna already has a native library that implements the wind client protocol (libui), reimplementing this protocol in a standalone library has a number of advantages, especially for third-party programs:

  • Increased compatibility: libui is written in highly customized C++, while this library is written in POSIX C. This makes it easier to use in C programs, and wrappers for other languages such as Rust are easier to make.

  • Unintrusive: libui assumes that your application is written around it. This is great for native Luna programs, as they can take advantage of libui's EventLoop and other nice features, but it's not so nice when you have to rewrite other programs to structure them around an EventLoop. This library does not do that: one call to wind_connect in one function, another to wind_create_window, and you're good to go!

Building

To build, simply run make. This will create a static library called libwind.a.

To install, run make install. This will install the header (wind.h) and the library (libwind.a) into the system include and library directories, or into whatever DESTDIR is set to.

To build programs using libwind, include wind.h and link with libwind: -lwind.

Compatibility

As the wind client protocol is still in the early stages of development, it is subject to change at any time. This library should be updated as soon as possible whenever that happens, so make sure to always have both the latest version of the Luna repository as well as this one.

Examples

Connecting to the wind server:

wind_client_t client;
wind_connect(&client, WIND_SOCKET_PATH, 0);

Creating a new window:

wind_window_t window;
struct wind_rect rect = {
    .pos = {0, 0},
    .width = 640,
    .height = 320
};

wind_create_window(&client, &window, rect);

Drawing to a window:

memset(window.canvas, 0xff, window.rect.width*window.rect.height*4);
wind_invalidate(&client, &window);

Handling events:

int event_handler(wind_client_t*, uint8_t event, void* arg)
{
    switch (event)
    {
        case wind_MouseEvent: {
            struct wind_mouse_event_request event_data;
            wind_read_response(&client, event, &event_data, sizeof event_data);
            // Do something
            break;
        }
        case wind_MouseLeave: {
            struct wind_mouse_leave_request event_data;
            wind_read_response(&client, event, &event_data, sizeof event_data);
            // Do something
            break;
        }
        case wind_KeyEvent: {
            struct wind_key_event_request event_data;
            wind_read_response(&client, event, &event_data, sizeof event_data);
            // Do something
            break;
        }
    }
}

wind_set_handler(&client, event_handler, NULL);
wind_check_for_messages(&client);

Using special system features:

wind_client_t client;
// Use WIND_SYSTEM_SOCKET_PATH instead of WIND_SOCKET_PATH (the calling process needs to be in the wsys group).
wind_connect(&client, WIND_SYSTEM_SOCKET_PATH, 0);

// You must pledge the functionality you're going to use.
wind_pledge(&client, wind_ExtendedLayers);

wind_window_t window;
struct wind_rect rect = {
    .pos = {0, 0},
    .width = 640,
    .height = 320
};

wind_create_window(&client, &window, rect);
// Using the ExtendedLayers system functionality, move this window to the "System" layer (above all other windows).
wind_set_layer(&client, &window, wind_System);

// Now that we're done, relinquish the pledges.
wind_pledge(&client, 0);

License

libwind is free and open-source software under the BSD-2-Clause License.