Skip to content

Commit

Permalink
Fix scaling of wayland platform pointer and touch location
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanGriffiths committed Sep 11, 2023
1 parent 2ed58d2 commit d10aff8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/platforms/wayland/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ void mir::graphics::wayland::Display::pointer_motion(wl_pointer* pointer, uint32
{
{
std::lock_guard lock{sink_mutex};
pointer_pos = geom::PointF{wl_fixed_to_double(x), wl_fixed_to_double(y)} + geom::DisplacementF{pointer_displacement};
auto const descaled_x = host_scale * wl_fixed_to_double(x);
auto const descaled_y = host_scale * wl_fixed_to_double(y);
pointer_pos = geom::PointF{descaled_x, descaled_y} + pointer_displacement;
pointer_time = std::chrono::milliseconds{time};
}

Expand Down Expand Up @@ -449,8 +451,8 @@ void mir::graphics::wayland::Display::touch_down(
touch_time = std::chrono::milliseconds{time};
contact->action = mir_touch_action_down;
contact->position = geom::PointF{
wl_fixed_to_double(x) + touch_displacement.dx.as_int(),
wl_fixed_to_double(y) + touch_displacement.dy.as_int()};
host_scale*wl_fixed_to_double(x) + touch_displacement.dx.as_int(),
host_scale*wl_fixed_to_double(y) + touch_displacement.dy.as_int()};
}
}

Expand Down Expand Up @@ -479,8 +481,8 @@ void mir::graphics::wayland::Display::touch_motion(wl_touch* touch, uint32_t tim
touch_time = std::chrono::milliseconds{time};
contact->action = mir_touch_action_change;
contact->position = geom::PointF{
wl_fixed_to_double(x) + touch_displacement.dx.as_int(),
wl_fixed_to_double(y) + touch_displacement.dy.as_int()};
host_scale*wl_fixed_to_double(x) + touch_displacement.dx.as_int(),
host_scale*wl_fixed_to_double(y) + touch_displacement.dy.as_int()};
}

DisplayClient::touch_motion(touch, time, id, x, y);
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/wayland/displayclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,8 @@ void mgw::DisplayClient::pointer_enter(
{
if (surface == out.second->surface)
{
pointer_displacement = out.second->dcout.top_left - geometry::Point{};
pointer_displacement = geom::DisplacementF{out.second->dcout.top_left - geometry::Point{}};
host_scale = out.second->host_scale;
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/wayland/displayclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ class DisplayClient
xkb_keymap* keyboard_map_ = nullptr;
xkb_state* keyboard_state_ = nullptr;
bool fake_pointer_frame = false;
geometry::Displacement pointer_displacement; // Position of current output
geometry::DisplacementF pointer_displacement; // Position of current output
geometry::Displacement touch_displacement; // Position of current output
float host_scale{1.0f};

std::unique_ptr<wl_registry, decltype(&wl_registry_destroy)> registry;

Expand Down

0 comments on commit d10aff8

Please sign in to comment.