Skip to content

Commit 293c1ed

Browse files
fix: touch scaling bug and initialize display variables as 0 (#4758)
Co-authored-by: Chase Payne <27069224+nonary@users.noreply.github.com>
1 parent f4ebfbb commit 293c1ed

3 files changed

Lines changed: 16 additions & 17 deletions

File tree

src/platform/common.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,7 @@ namespace platf {
485485
*/
486486
using pull_free_image_cb_t = std::function<bool(std::shared_ptr<img_t> &img_out)>;
487487

488-
display_t() noexcept:
489-
offset_x {0},
490-
offset_y {0} {
491-
}
488+
display_t() noexcept = default;
492489

493490
/**
494491
* @brief Capture a frame.
@@ -538,16 +535,16 @@ namespace platf {
538535
virtual ~display_t() = default;
539536

540537
// Offsets for when streaming a specific monitor. By default, they are 0.
541-
int offset_x;
542-
int offset_y;
543-
int env_width;
544-
int env_height;
545-
int env_logical_width;
546-
int env_logical_height;
547-
int width;
548-
int height;
549-
int logical_width;
550-
int logical_height;
538+
int offset_x {0};
539+
int offset_y {0};
540+
int env_width {0};
541+
int env_height {0};
542+
int env_logical_width {0};
543+
int env_logical_height {0};
544+
int width {0};
545+
int height {0};
546+
int logical_width {0};
547+
int logical_height {0};
551548

552549
protected:
553550
// 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
@@ -513,8 +513,10 @@ namespace platf {
513513
// MOUSEEVENTF_VIRTUALDESK maps to the entirety of the desktop rather than the primary desktop
514514
MOUSEEVENTF_VIRTUALDESK;
515515

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

519521
mi.dx = scaled_x;
520522
mi.dy = scaled_y;

src/video.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,7 @@ namespace video {
21392139
float scalar_tpcoords = 1.0f;
21402140
int display_env_logical_width = 0;
21412141
int display_env_logical_height = 0;
2142-
if (display->logical_width && display->logical_height && display->env_logical_width && display->env_logical_height) {
2142+
if (display->logical_width > 0 && display->logical_height > 0 && display->env_logical_width > 0 && display->env_logical_height > 0) {
21432143
float lwd = display->logical_width;
21442144
float lhd = display->logical_height;
21452145
scalar_tpcoords = std::fminf(wd / lwd, hd / lhd);

0 commit comments

Comments
 (0)