Skip to content

Commit

Permalink
fix: I find out a smart way to fix scale problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Oct 6, 2024
1 parent 5d69000 commit ce83302
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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
17 changes: 15 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,10 @@ impl WayshotConnection {
));
}
};
let viewporter = self
.globals
.bind::<WpViewporter, _, _>(&qh, 1..=1, ())
.unwrap();

let mut layer_shell_surfaces = Vec::with_capacity(frames.len());

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

0 comments on commit ce83302

Please sign in to comment.