Skip to content

Commit f242ef3

Browse files
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>
1 parent 00a52bb commit f242ef3

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/platform/common.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,7 @@ namespace platf {
481481
*/
482482
using pull_free_image_cb_t = std::function<bool(std::shared_ptr<img_t> &img_out)>;
483483

484-
display_t() noexcept:
485-
offset_x {0},
486-
offset_y {0} {
487-
}
484+
display_t() noexcept = default;
488485

489486
/**
490487
* @brief Capture a frame.
@@ -534,12 +531,18 @@ namespace platf {
534531
virtual ~display_t() = default;
535532

536533
// Offsets for when streaming a specific monitor. By default, they are 0.
537-
int offset_x, offset_y;
538-
int env_width, env_height;
539-
int env_logical_width, env_logical_height;
540-
541-
int width, height;
542-
int logical_width, logical_height;
534+
int offset_x {0};
535+
int offset_y {0};
536+
537+
int env_width {0};
538+
int env_height {0};
539+
int env_logical_width {0};
540+
int env_logical_height {0};
541+
542+
int width {0};
543+
int height {0};
544+
int logical_width {0};
545+
int logical_height {0};
543546

544547
protected:
545548
// collect capture timing data (at loglevel debug)

src/platform/windows/input.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,10 @@ namespace platf {
511511
// MOUSEEVENTF_VIRTUALDESK maps to the entirety of the desktop rather than the primary desktop
512512
MOUSEEVENTF_VIRTUALDESK;
513513

514-
auto scaled_x = std::lround((x + touch_port.offset_x) * ((float) target_touch_port.width / (float) touch_port.width));
515-
auto scaled_y = std::lround((y + touch_port.offset_y) * ((float) target_touch_port.height / (float) touch_port.height));
514+
// Note: x and y already include the display offset (offset_x/offset_y) from client_to_touchport(),
515+
// so we must not add offset_x/offset_y again here to avoid double-offsetting on multi-monitor setups.
516+
auto scaled_x = std::lround(x * ((float) target_touch_port.width / (float) touch_port.width));
517+
auto scaled_y = std::lround(y * ((float) target_touch_port.height / (float) touch_port.height));
516518

517519
mi.dx = scaled_x;
518520
mi.dy = scaled_y;

src/video.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ namespace video {
20632063
float scalar_tpcoords = 1.0f;
20642064
int display_env_logical_width = 0;
20652065
int display_env_logical_height = 0;
2066-
if (display->logical_width && display->logical_height && display->env_logical_width && display->env_logical_height) {
2066+
if (display->logical_width > 0 && display->logical_height > 0 && display->env_logical_width > 0 && display->env_logical_height > 0) {
20672067
float lwd = display->logical_width;
20682068
float lhd = display->logical_height;
20692069
scalar_tpcoords = std::fminf(wd / lwd, hd / lhd);

0 commit comments

Comments
 (0)