libwind/README.md
2024-03-31 13:08:01 +02:00

85 lines
3.1 KiB
Markdown

# libwind
A standalone implementation of the [wind](https://git.cloudapio.eu/apio/Luna/src/branch/main/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](https://git.cloudapio.eu/apio/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);
```
## License
libwind is free and open-source software under the [BSD-2-Clause License](LICENSE).