From 61ee63bfeceffc3d3a1006c785f8f87f73b7df89 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Mon, 7 Oct 2024 01:23:37 +0900 Subject: [PATCH] fix: I find out a smart way to fix scale problem --- 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..d9bba7e1 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!( + "Your wm does not support wp_viewporter, so the scale may come out with some problems" + ); + } 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));