From 80a272c909db1fc41723d8bfadf78a28b9bfcffa Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 21 Feb 2026 22:06:57 -0500 Subject: [PATCH] fix: touch scaling bug and initialize display variables as 0 Initialize additional display_t members (env_width/env_height/env_logical_width/env_logical_height/width/height/logical_width/logical_height) in the constructor to ensure consistent defaults. Fix touch input scaling on Windows by removing a redundant addition of display offsets (preventing double-offsetting for multi-monitor setups) and adding a clarifying comment. Tighten the video coordinate check to use explicit >0 comparisons for logical/env sizes before computing scaling factors. Co-Authored-By: Chase Payne <27069224+nonary@users.noreply.github.com> --- src/platform/common.h | 23 +++++++++++++---------- src/platform/windows/input.cpp | 6 ++++-- src/video.cpp | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/platform/common.h b/src/platform/common.h index 274bbbdc8d1..2fdb383396a 100644 --- a/src/platform/common.h +++ b/src/platform/common.h @@ -481,10 +481,7 @@ namespace platf { */ using pull_free_image_cb_t = std::function &img_out)>; - display_t() noexcept: - offset_x {0}, - offset_y {0} { - } + display_t() noexcept = default; /** * @brief Capture a frame. @@ -534,12 +531,18 @@ namespace platf { virtual ~display_t() = default; // Offsets for when streaming a specific monitor. By default, they are 0. - int offset_x, offset_y; - int env_width, env_height; - int env_logical_width, env_logical_height; - - int width, height; - int logical_width, logical_height; + int offset_x {0}; + int offset_y {0}; + + int env_width {0}; + int env_height {0}; + int env_logical_width {0}; + int env_logical_height {0}; + + int width {0}; + int height {0}; + int logical_width {0}; + int logical_height {0}; protected: // collect capture timing data (at loglevel debug) diff --git a/src/platform/windows/input.cpp b/src/platform/windows/input.cpp index 533e3790013..e708beab03c 100644 --- a/src/platform/windows/input.cpp +++ b/src/platform/windows/input.cpp @@ -511,8 +511,10 @@ namespace platf { // MOUSEEVENTF_VIRTUALDESK maps to the entirety of the desktop rather than the primary desktop MOUSEEVENTF_VIRTUALDESK; - auto scaled_x = std::lround((x + touch_port.offset_x) * ((float) target_touch_port.width / (float) touch_port.width)); - auto scaled_y = std::lround((y + touch_port.offset_y) * ((float) target_touch_port.height / (float) touch_port.height)); + // Note: x and y already include the display offset (offset_x/offset_y) from client_to_touchport(), + // so we must not add offset_x/offset_y again here to avoid double-offsetting on multi-monitor setups. + auto scaled_x = std::lround(x * ((float) target_touch_port.width / (float) touch_port.width)); + auto scaled_y = std::lround(y * ((float) target_touch_port.height / (float) touch_port.height)); mi.dx = scaled_x; mi.dy = scaled_y; diff --git a/src/video.cpp b/src/video.cpp index 7487e1278e6..5542b9ccd97 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -2063,7 +2063,7 @@ namespace video { float scalar_tpcoords = 1.0f; int display_env_logical_width = 0; int display_env_logical_height = 0; - if (display->logical_width && display->logical_height && display->env_logical_width && display->env_logical_height) { + if (display->logical_width > 0 && display->logical_height > 0 && display->env_logical_width > 0 && display->env_logical_height > 0) { float lwd = display->logical_width; float lhd = display->logical_height; scalar_tpcoords = std::fminf(wd / lwd, hd / lhd);