From 85054b1b6d0e9756501fc791f650bd836fb3c89e Mon Sep 17 00:00:00 2001 From: Alan Griffiths Date: Wed, 25 Oct 2023 12:40:35 +0100 Subject: [PATCH 1/3] Untangle the logic handling window size and scaling --- src/platforms/wayland/displayclient.cpp | 49 ++++++++++++++++--------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/platforms/wayland/displayclient.cpp b/src/platforms/wayland/displayclient.cpp index ccf96dbaa54..7b2669316c9 100644 --- a/src/platforms/wayland/displayclient.cpp +++ b/src/platforms/wayland/displayclient.cpp @@ -56,6 +56,7 @@ class mgw::DisplayClient::Output : DisplayConfigurationOutput dcout; geom::Size output_size; + int32_t pending_scale_factor{0}; float host_scale{1.0f}; wl_output* const output; @@ -255,7 +256,7 @@ void mgw::DisplayClient::Output::mode(uint32_t flags, int32_t width, int32_t hei void mgw::DisplayClient::Output::scale(int32_t factor) { - host_scale = factor; + pending_scale_factor = factor; } void mgw::DisplayClient::Output::done() @@ -276,7 +277,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(host_scale)); + wl_surface_set_buffer_scale(surface, pending_scale_factor ? pending_scale_factor : round(host_scale)); wl_surface_commit(surface); // After the next roundtrip the surface should be configured @@ -292,30 +293,42 @@ void mgw::DisplayClient::Output::done() void mgw::DisplayClient::Output::toplevel_configure(int32_t width, int32_t height, wl_array* states) { (void)states; - pending_toplevel_size = geometry::Size{ - width ? width : 1280, - height ? height : 1024}; + + if (width > 0 && height > 0) + { + pending_toplevel_size = geometry::Size{host_scale*width, host_scale*height}; + } } 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 = host_scale*pending_toplevel_size.value(); - pending_toplevel_size.reset(); - output_size = dcout.extents().size; - if (!has_initialized) + + if (pending_scale_factor) { - has_initialized = true; - provider = std::make_shared(*owner_->provider, surface, output_size); + host_scale = pending_scale_factor; + pending_scale_factor = 0; } - else if (size_is_changed) + + if (pending_toplevel_size) { - /* TODO: We should, again, handle this by storing the pending size, raising a hardware-changed - * notification, and then letting the `configure()` system tear down everything and bring it back - * up at the new size. - */ + bool const size_is_changed = !dcout.custom_logical_size || + dcout.custom_logical_size.value() != pending_toplevel_size.value(); + dcout.custom_logical_size = pending_toplevel_size.value(); + pending_toplevel_size.reset(); + output_size = dcout.extents().size; + if (!has_initialized) + { + has_initialized = true; + provider = std::make_shared(*owner_->provider, surface, output_size); + } + else if (size_is_changed) + { + /* TODO: We should, again, handle this by storing the pending size, raising a hardware-changed + * notification, and then letting the `configure()` system tear down everything and bring it back + * up at the new size. + */ + } } } From b7fdd1ae7d9e62e6da1314e735524ad4b9f1e854 Mon Sep 17 00:00:00 2001 From: Alan Griffiths Date: Wed, 25 Oct 2023 14:35:02 +0100 Subject: [PATCH 2/3] We don't need non-integer host scaling (yet) --- src/platforms/wayland/displayclient.cpp | 4 ++-- src/platforms/wayland/displayclient.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platforms/wayland/displayclient.cpp b/src/platforms/wayland/displayclient.cpp index 7b2669316c9..67b7a91d7a1 100644 --- a/src/platforms/wayland/displayclient.cpp +++ b/src/platforms/wayland/displayclient.cpp @@ -57,7 +57,7 @@ class mgw::DisplayClient::Output : DisplayConfigurationOutput dcout; geom::Size output_size; int32_t pending_scale_factor{0}; - float host_scale{1.0f}; + int32_t host_scale{1}; wl_output* const output; DisplayClient* const owner_; @@ -277,7 +277,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, pending_scale_factor ? pending_scale_factor : round(host_scale)); + wl_surface_set_buffer_scale(surface, pending_scale_factor ? pending_scale_factor : host_scale); wl_surface_commit(surface); // After the next roundtrip the surface should be configured diff --git a/src/platforms/wayland/displayclient.h b/src/platforms/wayland/displayclient.h index b1ad98a999e..b8dc83badc6 100644 --- a/src/platforms/wayland/displayclient.h +++ b/src/platforms/wayland/displayclient.h @@ -164,7 +164,7 @@ class DisplayClient bool fake_pointer_frame = false; geometry::DisplacementF pointer_displacement; // Position of current output geometry::Displacement touch_displacement; // Position of current output - float pointer_scale{1.0f}; + int32_t pointer_scale{1}; std::unique_ptr registry; From b89038db8c7ac2a0ffbfea74a0e9e28a03c9da7c Mon Sep 17 00:00:00 2001 From: Alan Griffiths Date: Thu, 26 Oct 2023 10:00:36 +0100 Subject: [PATCH 3/3] No need to track a pending size --- src/platforms/wayland/displayclient.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/platforms/wayland/displayclient.cpp b/src/platforms/wayland/displayclient.cpp index 67b7a91d7a1..7c12fc06062 100644 --- a/src/platforms/wayland/displayclient.cpp +++ b/src/platforms/wayland/displayclient.cpp @@ -56,7 +56,6 @@ class mgw::DisplayClient::Output : DisplayConfigurationOutput dcout; geom::Size output_size; - int32_t pending_scale_factor{0}; int32_t host_scale{1}; wl_output* const output; @@ -256,7 +255,7 @@ void mgw::DisplayClient::Output::mode(uint32_t flags, int32_t width, int32_t hei void mgw::DisplayClient::Output::scale(int32_t factor) { - pending_scale_factor = factor; + host_scale = factor; } void mgw::DisplayClient::Output::done() @@ -277,17 +276,11 @@ 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, pending_scale_factor ? pending_scale_factor : host_scale); + wl_surface_set_buffer_scale(surface, host_scale); wl_surface_commit(surface); // After the next roundtrip the surface should be configured } - else - { - /* TODO: We should handle this by raising a hardware-changed notification and reconfiguring in - * the subsequent `configure()` call. - */ - } } void mgw::DisplayClient::Output::toplevel_configure(int32_t width, int32_t height, wl_array* states) @@ -304,12 +297,6 @@ void mgw::DisplayClient::Output::surface_configure(uint32_t serial) { xdg_surface_ack_configure(shell_surface, serial); - if (pending_scale_factor) - { - host_scale = pending_scale_factor; - pending_scale_factor = 0; - } - if (pending_toplevel_size) { bool const size_is_changed = !dcout.custom_logical_size ||