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

fix: I find out a smart way to fix scale problem #128

Merged
merged 2 commits into from
Oct 10, 2024
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
6 changes: 6 additions & 0 deletions libwayshot/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<ZwlrLayerSurfaceV1, WlOutput> for LayerShellState {
// No need to instrument here, span from lib.rs is automatically used.
Expand Down
21 changes: 19 additions & 2 deletions libwayshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -832,6 +835,12 @@ impl WayshotConnection {
));
}
};
let viewporter = self.globals.bind::<WpViewporter, _, _>(&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());

Expand Down Expand Up @@ -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));
Expand Down
Loading