From ce8330220a7ad5c8bddbb323e0b9711f98e7731c 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 | 17 +++++++++++++++-- 2 files changed, 21 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..50f2f25c 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,10 @@ impl WayshotConnection { )); } }; + let viewporter = self + .globals + .bind::(&qh, 1..=1, ()) + .unwrap(); let mut layer_shell_surfaces = Vec::with_capacity(frames.len()); @@ -872,6 +879,12 @@ impl WayshotConnection { // surface.set_buffer_scale(output_info.scale()); surface.attach(Some(&frame_guard.buffer), 0, 0); + 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));