From b52532afb1890b4288fcc41714d248554fbe12fc Mon Sep 17 00:00:00 2001 From: Access Date: Thu, 10 Oct 2024 17:02:20 +0900 Subject: [PATCH] fix: I find out a smart way to fix scale problem (#128) * fix: I find out a smart way to fix scale problem * Update libwayshot/src/lib.rs Co-authored-by: Aakash Sen Sharma <60808802+Shinyzenith@users.noreply.github.com> --------- Co-authored-by: Aakash Sen Sharma <60808802+Shinyzenith@users.noreply.github.com> --- libwayshot/src/dispatch.rs | 6 ++++++ libwayshot/src/lib.rs | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libwayshot/src/dispatch.rs b/libwayshot/src/dispatch.rs index e171cd1b..9c35fbc8 100644 --- a/libwayshot/src/dispatch.rs +++ b/libwayshot/src/dispatch.rs @@ -37,6 +37,10 @@ use wayland_protocols_wlr::screencopy::v1::client::{ zwlr_screencopy_manager_v1::ZwlrScreencopyManagerV1, }; +use wayland_protocols::wp::viewporter::client::{ + wp_viewport::WpViewport, wp_viewporter::WpViewporter, +}; + use crate::{ output::OutputInfo, region::{LogicalRegion, Position, Size}, @@ -299,6 +303,8 @@ delegate_noop!(LayerShellState: ignore WlShmPool); delegate_noop!(LayerShellState: ignore WlBuffer); delegate_noop!(LayerShellState: ignore ZwlrLayerShellV1); delegate_noop!(LayerShellState: ignore WlSurface); +delegate_noop!(LayerShellState: ignore WpViewport); +delegate_noop!(LayerShellState: ignore WpViewporter); impl wayland_client::Dispatch for LayerShellState { // No need to instrument here, span from lib.rs is automatically used. diff --git a/libwayshot/src/lib.rs b/libwayshot/src/lib.rs index 04b3438d..dfe9bbdd 100644 --- a/libwayshot/src/lib.rs +++ b/libwayshot/src/lib.rs @@ -37,8 +37,11 @@ use wayland_client::{ Connection, EventQueue, Proxy, }; use wayland_protocols::{ - wp::linux_dmabuf::zv1::client::{ - zwp_linux_buffer_params_v1, zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1, + wp::{ + linux_dmabuf::zv1::client::{ + zwp_linux_buffer_params_v1, zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1, + }, + viewporter::client::wp_viewporter::WpViewporter, }, xdg::xdg_output::zv1::client::{ zxdg_output_manager_v1::ZxdgOutputManagerV1, zxdg_output_v1::ZxdgOutputV1, @@ -832,6 +835,12 @@ impl WayshotConnection { )); } }; + let viewporter = self.globals.bind::(&qh, 1..=1, ()).ok(); + if viewporter.is_none() { + tracing::info!( + "Compositor does not support wp_viewporter, display scaling may be inaccurate." + ); + } let mut layer_shell_surfaces = Vec::with_capacity(frames.len()); @@ -872,6 +881,14 @@ impl WayshotConnection { // surface.set_buffer_scale(output_info.scale()); surface.attach(Some(&frame_guard.buffer), 0, 0); + if let Some(viewporter) = viewporter.as_ref() { + let viewport = viewporter.get_viewport(&surface, &qh, ()); + viewport.set_destination( + output_info.logical_region.inner.size.width as i32, + output_info.logical_region.inner.size.height as i32, + ); + } + debug!("Committing surface with attached buffer."); surface.commit(); layer_shell_surfaces.push((surface, layer_surface));