From 9c02e6afafc7d1e0b1a17c2ba9ced9a7795464db Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 20 Feb 2022 14:48:24 +0000 Subject: [PATCH] Implement hiding cursors --- src/cursor.c | 8 ++++++-- src/server.c | 36 +++++++++++++----------------------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/cursor.c b/src/cursor.c index c330224..e6458da 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -36,6 +36,10 @@ int cursor_encode(struct vec* dst, struct rfb_pixel_format* pixfmt, int rc = -1; + // Empty cursor + if (!image) + return encode_rect_head(dst, RFB_ENCODING_CURSOR, 0, 0, 0, 0); + assert(width <= image->width); assert(height <= image->height); @@ -65,7 +69,7 @@ int cursor_encode(struct vec* dst, struct rfb_pixel_format* pixfmt, if((int32_t)width == image->stride) { pixel32_to_cpixel(dstdata, pixfmt, image->addr, &srcfmt, bpp, size); } else { - for (int y = 0; y < height; ++y) { + for (uint32_t y = 0; y < height; ++y) { pixel32_to_cpixel(dstdata + y * bpp * width, pixfmt, (uint32_t*)image->addr + y * image->stride, &srcfmt, bpp, width); @@ -76,7 +80,7 @@ int cursor_encode(struct vec* dst, struct rfb_pixel_format* pixfmt, dstdata = dst->data; dstdata += dst->len; - for (int y = 0; y < height; ++y) { + for (uint32_t y = 0; y < height; ++y) { if (!extract_alpha_mask(dstdata + y * UDIV_UP(width, 8), (uint32_t*)image->addr + y * image->stride, image->fourcc_format, width)) diff --git a/src/server.c b/src/server.c index b576424..d7ff0af 100644 --- a/src/server.c +++ b/src/server.c @@ -467,9 +467,6 @@ static int on_client_set_pixel_format(struct nvnc_client* client) memcpy(&client->pixfmt, fmt, sizeof(client->pixfmt)); - if (client->has_pixfmt && client->cursor_seq) - client->cursor_seq--; - client->has_pixfmt = true; return 4 + sizeof(struct rfb_pixel_format); @@ -526,12 +523,6 @@ static void send_cursor_update(struct nvnc_client* client) { struct nvnc* server = client->server; - if (!server->cursor.buffer) { - // TODO: Empty buffer means that no cursor should be visible - client->cursor_seq = server->cursor_seq; - return; - } - struct vec payload; vec_init(&payload, 4096); @@ -1591,27 +1582,26 @@ void nvnc_set_cursor(struct nvnc* self, struct nvnc_fb* fb, uint16_t width, } self->cursor.buffer = fb; - if (!fb) { + if (fb) { + // TODO: Hash cursors to check if they actually changed? + nvnc_fb_ref(fb); + nvnc_fb_hold(fb); + + self->cursor.width = width; + self->cursor.height = height; + self->cursor.hotspot_x = hotspot_x; + self->cursor.hotspot_y = hotspot_y; + + } else { + self->cursor.width = width; + self->cursor.height = height; self->cursor.hotspot_x = 0; self->cursor.hotspot_y = 0; - return; } - // TODO: Hash cursors to check if they actually changed? - - nvnc_fb_ref(fb); - nvnc_fb_hold(fb); - - self->cursor.width = width; - self->cursor.height = height; - self->cursor.hotspot_x = hotspot_x; - self->cursor.hotspot_y = hotspot_y; - self->cursor_seq++; struct nvnc_client* client; LIST_FOREACH(client, &self->clients, link) process_fb_update_requests(client); - - log_debug("Setting cursor\n"); }