examples: draw: Add a client-side cursor

pull/63/head
Andri Yngvason 2022-02-06 16:32:30 +00:00
parent 48baf74560
commit c0d1455686
1 changed files with 55 additions and 0 deletions

View File

@ -57,6 +57,55 @@ struct draw {
struct fb_side_data_list fb_side_data_list; struct fb_side_data_list fb_side_data_list;
}; };
static struct nvnc_fb* create_cursor()
{
static char ascii_art[] =
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXX "
"XXXXXXXXXXXXXXXXXXXXXXXXXXXX "
"XXXXXXXXXXXXXXXXXXXXXXXXXXX "
"XXXXXXXXXXXXXXXXXXXXXXXXXX "
"XXXXXXXXXXXXXXXXXXXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXXX "
"XXXXXXX "
"XXXXXX "
"XXXXX "
"XXXX "
"XXX "
"XX "
"X ";
struct nvnc_fb* fb = nvnc_fb_new(32, 32, DRM_FORMAT_RGBA8888, 32);
assert(fb);
uint32_t colour = 0x0000ffff;
uint32_t* pixels = nvnc_fb_get_addr(fb);
for (int i = 0; i < 32 * 32; ++i) {
pixels[i] = ascii_art[i] != ' ' ? colour : 0;
}
return fb;
}
static void fb_side_data_destroy(void* userdata) static void fb_side_data_destroy(void* userdata)
{ {
struct fb_side_data* fb_side_data = userdata; struct fb_side_data* fb_side_data = userdata;
@ -224,6 +273,12 @@ int main(int argc, char* argv[])
nvnc_set_pointer_fn(server, on_pointer_event); nvnc_set_pointer_fn(server, on_pointer_event);
nvnc_set_userdata(server, &draw, NULL); nvnc_set_userdata(server, &draw, NULL);
struct nvnc_fb* cursor = create_cursor();
assert(cursor);
nvnc_set_cursor(server, cursor, 0, 0, NULL);
nvnc_fb_unref(cursor);
struct aml_signal* sig = aml_signal_new(SIGINT, on_sigint, NULL, NULL); struct aml_signal* sig = aml_signal_new(SIGINT, on_sigint, NULL, NULL);
aml_start(aml_get_default(), sig); aml_start(aml_get_default(), sig);
aml_unref(sig); aml_unref(sig);