File: c_test.c

package info (click to toggle)
libhyprcursor 0.1.13-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 284 kB
  • sloc: cpp: 1,546; ansic: 130; makefile: 16
file content (79 lines) | stat: -rw-r--r-- 2,068 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
    hyprlang-test in C.
    Renders a cursor shape to /tmp at 48px

    For better explanations, see the cpp tests.
*/

#include <hyprcursor/hyprcursor.h>
#include <stdio.h>
#include <stdlib.h>

void logFunction(enum eHyprcursorLogLevel level, char* message) {
    printf("[hc] %s\n", message);
}

int main(int argc, char** argv) {
    struct hyprcursor_manager_t* mgr = hyprcursor_manager_create_with_logger(NULL, logFunction);

    if (!mgr) {
        printf("mgr null\n");
        return 1;
    }

    if (!hyprcursor_manager_valid(mgr)) {
        printf("mgr is invalid\n");
        return 1;
    }

    hyprcursor_cursor_raw_shape_data* shapeData = hyprcursor_get_raw_shape_data(mgr, "left_ptr");
    if (!shapeData) {
        printf("failed querying left_ptr\n");
        return 1;
    }

    if (shapeData->overridenBy) {
        hyprcursor_cursor_raw_shape_data* ov = hyprcursor_get_raw_shape_data(mgr, shapeData->overridenBy);
        hyprcursor_raw_shape_data_free(shapeData);
        shapeData = ov;
    }

    if (!shapeData || shapeData->len <= 0) {
        printf("left_ptr has no images\n");
        return 1;
    }

    printf("left_ptr images: %ld\n", shapeData->len);

    for (size_t i = 0; i < shapeData->len; ++i) {
        printf("left_ptr image size: %ld\n", shapeData->images[i].len);
    }

    hyprcursor_raw_shape_data_free(shapeData);
    shapeData = NULL;

    struct hyprcursor_cursor_style_info info = {.size = 48};
    if (!hyprcursor_load_theme_style(mgr, info)) {
        printf("load failed\n");
        return 1;
    }

    int                            dataSize = 0;
    hyprcursor_cursor_image_data** data     = hyprcursor_get_cursor_image_data(mgr, "left_ptr", info, &dataSize);
    if (data == NULL) {
        printf("data failed\n");
        return 1;
    }

    int ret = cairo_surface_write_to_png(data[0]->surface, "/tmp/arrowC.png");

    hyprcursor_cursor_image_data_free(data, dataSize);
    hyprcursor_style_done(mgr, info);

    if (ret) {
        printf("cairo failed\n");
        return 1;
    }

    return 0;
}