feat: Add support for window layers and pledges

Recently added in the upstream API.
This commit is contained in:
apio 2024-12-13 23:59:55 +01:00
parent 9cd8883850
commit c8a30d2580
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 62 additions and 11 deletions

View File

@ -80,6 +80,31 @@ wind_set_handler(&client, event_handler, NULL);
wind_check_for_messages(&client); 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 ## License
libwind is free and open-source software under the [BSD-2-Clause License](LICENSE). libwind is free and open-source software under the [BSD-2-Clause License](LICENSE).

View File

@ -256,13 +256,22 @@ int wind_get_screen_dimensions(wind_client_t* client, struct wind_rect* rect)
return result; return result;
} }
int wind_set_special_window_attributes(wind_client_t* client, wind_window_t* window, int wind_set_window_layer(wind_client_t* client, wind_window_t* window,
enum wind_window_attributes attributes) enum wind_layer layer)
{ {
struct wind_set_special_window_attributes_request request = { struct wind_set_window_layer_request request = {
.window = window->id, .window = window->id,
.attributes = attributes, .layer = layer,
}; };
return wind_send_request(client, wind_SetSpecialWindowAttributes, &request, sizeof request); return wind_send_request(client, wind_SetWindowLayer, &request, sizeof request);
}
int wind_pledge(wind_client_t* client, int16_t pledges)
{
struct wind_update_pledge_request request = {
.pledges = pledges,
};
return wind_send_request(client, wind_UpdatePledge, &request, sizeof request);
} }

View File

@ -43,7 +43,8 @@ enum wind_server_message
wind_CloseWindow, wind_CloseWindow,
wind_GetScreenRect, wind_GetScreenRect,
wind_SetTitlebarHeight, wind_SetTitlebarHeight,
wind_SetSpecialWindowAttributes, wind_SetWindowLayer,
wind_UpdatePledge,
}; };
enum wind_client_message enum wind_client_message
@ -95,15 +96,29 @@ struct wind_set_titlebar_height_request
int height; int height;
}; };
enum wind_window_attributes enum wind_layer
{ {
wind_UNFOCUSEABLE = 1, wind_Background,
wind_Global,
wind_GlobalTop,
wind_System,
wind_Lock,
}; };
struct wind_set_special_window_attributes_request struct wind_set_window_layer_request
{ {
int window; int window;
enum wind_window_attributes attributes; uint8_t layer; // enum wind_layer
};
enum wind_pledge
{
wind_ExtendedLayers = 1,
};
struct wind_update_pledge_request
{
int16_t pledges;
}; };
struct wind_create_window_response struct wind_create_window_response
@ -291,6 +306,7 @@ struct wind_key_event_request
}; };
#define WIND_SOCKET_PATH "/tmp/wind.sock" #define WIND_SOCKET_PATH "/tmp/wind.sock"
#define WIND_SYSTEM_SOCKET_PATH "/tmp/wsys.sock"
int wind_connect(wind_client_t* client, const char* path, int blocking); int wind_connect(wind_client_t* client, const char* path, int blocking);
int wind_send_request(wind_client_t* client, uint8_t request_id, const void* request, size_t request_size); int wind_send_request(wind_client_t* client, uint8_t request_id, const void* request, size_t request_size);
@ -312,6 +328,7 @@ int wind_set_titlebar_height(wind_client_t* client, wind_window_t* window, int h
int wind_get_screen_dimensions(wind_client_t* client, struct wind_rect* rect); int wind_get_screen_dimensions(wind_client_t* client, struct wind_rect* rect);
int wind_set_special_window_attributes(wind_client_t* client, wind_window_t* window, enum wind_window_attributes attributes); int wind_set_window_layer(wind_client_t* client, wind_window_t* window, enum wind_layer layer);
int wind_pledge(wind_client_t* client, int16_t pledges);
#endif #endif