hyprcursor/tests/test.c

66 lines
1.7 KiB
C
Raw Normal View History

2024-03-07 17:36:26 +01:00
#include <hyprcursor/hyprcursor.h>
2024-03-07 16:10:45 +01:00
#include <stdio.h>
#include <stdlib.h>
2024-03-24 21:37:31 +01:00
void logFunction(enum eHyprcursorLogLevel level, char* message) {
printf("[hc] %s\n", message);
}
2024-03-25 02:45:46 +01:00
/*
hyprlang-test in C.
Renders a cursor shape to /tmp at 48px
*/
2024-03-07 16:10:45 +01:00
int main(int argc, char** argv) {
2024-03-24 21:37:31 +01:00
struct hyprcursor_manager_t* mgr = hyprcursor_manager_create_with_logger(NULL, logFunction);
2024-03-07 16:10:45 +01:00
if (!mgr) {
printf("mgr null\n");
return 1;
}
2024-03-24 21:37:31 +01:00
if (!hyprcursor_manager_valid(mgr)) {
printf("mgr is invalid\n");
return 1;
}
2024-03-07 16:10:45 +01:00
2024-04-05 17:49:17 +02:00
hyprcursor_cursor_raw_shape_data* shapeData = hyprcursor_get_raw_shape_data(mgr, "left_ptr");
if (!shapeData || shapeData->len <= 0) {
printf("failed querying left_ptr\n");
return 1;
}
printf("left_ptr images: %d\n", shapeData->len);
for (size_t i = 0; i < shapeData->len; ++i) {
printf("left_ptr image size: %d\n", shapeData->images[i].len);
}
hyprcursor_raw_shape_data_free(shapeData);
shapeData = NULL;
2024-03-07 16:10:45 +01:00
struct hyprcursor_cursor_style_info info = {.size = 48};
if (!hyprcursor_load_theme_style(mgr, info)) {
printf("load failed\n");
return 1;
}
2024-03-07 17:36:26 +01:00
int dataSize = 0;
hyprcursor_cursor_image_data** data = hyprcursor_get_cursor_image_data(mgr, "left_ptr", info, &dataSize);
2024-03-07 17:01:45 +01:00
if (data == NULL) {
printf("data failed\n");
2024-03-07 16:10:45 +01:00
return 1;
}
2024-03-07 17:01:45 +01:00
int ret = cairo_surface_write_to_png(data[0]->surface, "/tmp/arrowC.png");
hyprcursor_cursor_image_data_free(data, dataSize);
2024-03-11 22:06:13 +01:00
hyprcursor_style_done(mgr, info);
2024-03-07 16:10:45 +01:00
if (ret) {
printf("cairo failed\n");
return 1;
}
return 0;
}