From e539b159ee10dd0c04025e66e3a5be48190e5545 Mon Sep 17 00:00:00 2001 From: loki Date: Thu, 12 Dec 2019 18:54:26 +0100 Subject: [PATCH] Overlay the mouse on the frame on the correct x/y coordinates --- sunshine/platform/linux.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sunshine/platform/linux.cpp b/sunshine/platform/linux.cpp index 07b454d3..a5376e9b 100644 --- a/sunshine/platform/linux.cpp +++ b/sunshine/platform/linux.cpp @@ -119,20 +119,25 @@ img_t snapshot(display_t &display_void) { }; XFixesCursorImage *overlay = XFixesGetCursorImage(display.display); + overlay->x -= overlay->xhot; + overlay->y -= overlay->yhot; + + overlay->x = std::max((short)0, overlay->x); + overlay->y = std::max((short)0, overlay->y); auto pixels = (int*)img->data; auto screen_height = display.attr.height; auto screen_width = display.attr.width; - auto delta_height = std::min(overlay->height, std::abs(overlay->y - screen_height)); - auto delta_width = std::min(overlay->width, std::abs(overlay->x - screen_width)); + auto delta_height = std::min(overlay->height, std::max(0, screen_height - overlay->y)); + auto delta_width = std::min(overlay->width, std::max(0, screen_width - overlay->x)); for(auto y = 0; y < delta_height; ++y) { auto overlay_begin = &overlay->pixels[y * overlay->width]; auto overlay_end = &overlay->pixels[y * overlay->width + delta_width]; - auto pixels_begin = &pixels[(y + overlay->y - 1) * screen_width + overlay->x - 1]; + auto pixels_begin = &pixels[(y + overlay->y) * screen_width + overlay->x]; std::for_each(overlay_begin, overlay_end, [&](long pixel) { int *pixel_p = (int*)&pixel;