Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wayland platform] Less broken display on scaled hosts #3037

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion 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 = pointer_scale * wl_fixed_to_double(x);
auto const descaled_y = pointer_scale * wl_fixed_to_double(y);
pointer_pos = geom::PointF{descaled_x, descaled_y} + pointer_displacement;
pointer_time = std::chrono::milliseconds{time};
}

Expand Down
13 changes: 8 additions & 5 deletions src/platforms/wayland/displayclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class mgw::DisplayClient::Output :

DisplayConfigurationOutput dcout;
geom::Size output_size;
float host_scale{1.0f};

wl_output* const output;
DisplayClient* const owner;
Expand Down Expand Up @@ -280,7 +281,7 @@ void mgw::DisplayClient::Output::mode(uint32_t flags, int32_t width, int32_t hei

void mgw::DisplayClient::Output::scale(int32_t factor)
{
dcout.scale = factor;
host_scale = factor;
}

void mgw::DisplayClient::Output::done()
Expand All @@ -301,7 +302,7 @@ void mgw::DisplayClient::Output::done()
xdg_toplevel_add_listener(shell_toplevel, &shell_toplevel_listener, this);

xdg_toplevel_set_fullscreen(shell_toplevel, output);
wl_surface_set_buffer_scale(surface, round(dcout.scale));
wl_surface_set_buffer_scale(surface, round(host_scale));
wl_surface_commit(surface);

// After the next roundtrip the surface should be configured
Expand All @@ -325,9 +326,9 @@ void mgw::DisplayClient::Output::surface_configure(uint32_t serial)
xdg_surface_ack_configure(shell_surface, serial);
bool const size_is_changed = pending_toplevel_size && (
!dcout.custom_logical_size || dcout.custom_logical_size.value() != pending_toplevel_size.value());
dcout.custom_logical_size = pending_toplevel_size.value();
dcout.custom_logical_size = host_scale*pending_toplevel_size.value();
pending_toplevel_size.reset();
output_size = dcout.extents().size * dcout.scale;
output_size = dcout.extents().size;
if (!has_initialized)
{
egl_window = wl_egl_window_create(surface, output_size.width.as_int(), output_size.height.as_int());
Expand Down Expand Up @@ -718,7 +719,9 @@ void mgw::DisplayClient::pointer_enter(
{
if (surface == out.second->surface)
{
pointer_displacement = out.second->dcout.top_left - geometry::Point{};
// Pointer events are displaced and scaled according to the surface
pointer_displacement = geom::DisplacementF{out.second->dcout.top_left - geometry::Point{}};
pointer_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 pointer_scale{1.0f};

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

Expand Down
Loading