Match presenter zoom preview to presentation output aspect ratio
This commit is contained in:
parent
a12f75a7d9
commit
0948f3b890
|
|
@ -2245,7 +2245,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pdf-presenter"
|
||||
version = "0.1.59"
|
||||
version = "0.1.60"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.59"
|
||||
version = "0.1.60"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter"
|
||||
|
|
|
|||
|
|
@ -780,6 +780,11 @@ impl App {
|
|||
}
|
||||
if let Some(output) = &self.output {
|
||||
while let Ok(ack) = output.rx.try_recv() {
|
||||
if let Some(viewport) = ack.viewport {
|
||||
let before = s.presentation_viewport();
|
||||
s.output_viewport = Some(viewport);
|
||||
repaint |= before != s.presentation_viewport();
|
||||
}
|
||||
if let Some(zoom) = ack.zoom {
|
||||
if ack.generation == s.buffer_generation() && ack.page == Some(s.requested)
|
||||
{
|
||||
|
|
@ -1221,7 +1226,21 @@ impl ApplicationHandler for App {
|
|||
let shown = !host.state.blanked
|
||||
&& !self.windows.is_empty()
|
||||
&& host.presented.len() >= self.windows.len();
|
||||
let viewport = host.state.monitors.iter().find_map(|id| {
|
||||
self.windows
|
||||
.iter()
|
||||
.find(|w| w.role == Role::Presentation && &w.monitor == id)
|
||||
.map(|w| {
|
||||
let size = w.window.inner_size();
|
||||
crate::output::OutputViewport {
|
||||
monitor: id.clone(),
|
||||
size: [size.width, size.height],
|
||||
fullscreen: host.state.fullscreen,
|
||||
}
|
||||
})
|
||||
});
|
||||
let _ = host.acks.try_send(Ack {
|
||||
viewport,
|
||||
sequence: host.state.sequence,
|
||||
generation: host.state.generation,
|
||||
buffered: host
|
||||
|
|
|
|||
|
|
@ -46,8 +46,17 @@ pub struct HostState {
|
|||
pub blanked: bool,
|
||||
pub quit: bool,
|
||||
}
|
||||
/// Actual size of the reference presentation window, never presenter content.
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct OutputViewport {
|
||||
pub monitor: String,
|
||||
pub size: [u32; 2],
|
||||
pub fullscreen: bool,
|
||||
}
|
||||
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
|
||||
pub struct Ack {
|
||||
#[serde(default)]
|
||||
pub viewport: Option<OutputViewport>,
|
||||
#[serde(default)]
|
||||
pub zoom: Option<crate::zoom::Sync>,
|
||||
#[serde(default)]
|
||||
|
|
|
|||
|
|
@ -838,6 +838,11 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
|
|||
if let Some(page) = page {
|
||||
let area = Rect::from_min_max(rect.min + Vec2::new(0., 24.), rect.max);
|
||||
if index == 1 && s.settings.zoom_enabled {
|
||||
// Mirror the output aspect, not the independently sized presenter pane.
|
||||
// This makes the shared zoom/center produce the same visible page crop.
|
||||
let area = s
|
||||
.presentation_viewport()
|
||||
.map_or(area, |dimensions| fitted_slide(area, dimensions));
|
||||
native.image_view(ui, s, page, area, s.zoom.view);
|
||||
if s.route_trial.is_none()
|
||||
&& let Some(frame) = s.frame(page)
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ pub struct Studio {
|
|||
pub privacy_hold: bool,
|
||||
pub output_sequence: u64,
|
||||
pub zoom: crate::zoom::Sync,
|
||||
pub output_viewport: Option<crate::output::OutputViewport>,
|
||||
pub new_zoom: bool,
|
||||
pub zoom_warning: bool,
|
||||
pub zoom_warning_dismissed: bool,
|
||||
|
|
@ -229,6 +230,7 @@ impl Studio {
|
|||
privacy_hold: false,
|
||||
output_sequence: 0,
|
||||
zoom: Default::default(),
|
||||
output_viewport: None,
|
||||
new_zoom: false,
|
||||
zoom_warning: false,
|
||||
zoom_warning_dismissed: false,
|
||||
|
|
@ -1117,6 +1119,22 @@ impl Studio {
|
|||
pub fn buffer_generation(&self) -> u64 {
|
||||
(self.generation << 32) | u64::from(self.target_edge)
|
||||
}
|
||||
/// Use the first connected presentation route as the preview reference.
|
||||
pub fn presentation_viewport(&self) -> Option<[u32; 2]> {
|
||||
let monitor = self
|
||||
.routes
|
||||
.presentation
|
||||
.iter()
|
||||
.find_map(|id| self.monitors.iter().find(|m| &m.id == id))?;
|
||||
if let Some(viewport) = &self.output_viewport
|
||||
&& viewport.monitor == monitor.id
|
||||
&& viewport.fullscreen == self.presentation_fullscreen()
|
||||
&& viewport.size.iter().all(|v| *v > 0)
|
||||
{
|
||||
return Some(viewport.size);
|
||||
}
|
||||
Some([monitor.size.0.max(1), monitor.size.1.max(1)])
|
||||
}
|
||||
pub fn set_zoom(&mut self, view: crate::zoom::View) {
|
||||
self.zoom.keep_fitted_area = self.settings.zoom_keep_fitted_area;
|
||||
self.zoom.set(self.settings.zoom_enabled, view);
|
||||
|
|
|
|||
|
|
@ -1202,3 +1202,58 @@ fn zoom_is_opt_in_resets_on_slide_change_and_does_not_blank_output() {
|
|||
assert!(!s.zoom_warning);
|
||||
assert!(!s.blanked);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zoom_preview_matches_reference_output_crop_and_tracks_window_shape() {
|
||||
use pdf_presenter::{output::OutputViewport, zoom::View};
|
||||
let mut s = studio();
|
||||
s.settings.zoom_enabled = true;
|
||||
s.set_zoom(View {
|
||||
scale: 2.,
|
||||
center: [0.4, 0.6],
|
||||
});
|
||||
assert_eq!(s.presentation_viewport(), Some([1920, 1080]));
|
||||
let ctx = Context::default();
|
||||
let mut native = UiState::default();
|
||||
for size in [[1920, 1080], [900, 1200]] {
|
||||
s.output_viewport = Some(OutputViewport {
|
||||
monitor: "two".into(),
|
||||
size,
|
||||
fullscreen: s.presentation_fullscreen(),
|
||||
});
|
||||
assert_eq!(s.presentation_viewport(), Some(size));
|
||||
let output = ctx.run_ui(input(Vec2::new(1280., 900.)), |ui| {
|
||||
presenter_ui::presenter(ui, &mut s, &mut native);
|
||||
});
|
||||
let texture = native.textures.values().next().unwrap().id();
|
||||
let mut actual = Rect::NOTHING;
|
||||
for primitive in ctx.tessellate(output.shapes, output.pixels_per_point) {
|
||||
if let egui::epaint::Primitive::Mesh(mesh) = primitive.primitive
|
||||
&& mesh.texture_id == texture
|
||||
{
|
||||
for vertex in mesh.vertices {
|
||||
actual.extend_with(vertex.uv);
|
||||
}
|
||||
}
|
||||
}
|
||||
let output_rect =
|
||||
Rect::from_min_size(Pos2::ZERO, Vec2::new(size[0] as f32, size[1] as f32));
|
||||
let (_, expected) = presenter_ui::zoom_geometry(output_rect, [64, 36], s.zoom.view, false);
|
||||
assert!(
|
||||
(actual.min - expected.min).length() < 0.0001,
|
||||
"{actual:?} vs {expected:?}"
|
||||
);
|
||||
assert!((actual.max - expected.max).length() < 0.0001);
|
||||
}
|
||||
// Stale route/fullscreen reports and minimized windows cannot distort the preview.
|
||||
s.output_viewport.as_mut().unwrap().fullscreen = !s.presentation_fullscreen();
|
||||
assert_eq!(s.presentation_viewport(), Some([1920, 1080]));
|
||||
s.output_viewport.as_mut().unwrap().fullscreen = s.presentation_fullscreen();
|
||||
s.output_viewport.as_mut().unwrap().size = [0, 0];
|
||||
assert_eq!(s.presentation_viewport(), Some([1920, 1080]));
|
||||
s.routes.presentation = vec!["missing".into(), "one".into()];
|
||||
s.monitors[0].size = (1280, 1024);
|
||||
assert_eq!(s.presentation_viewport(), Some([1280, 1024]));
|
||||
s.routes.presentation.clear();
|
||||
assert_eq!(s.presentation_viewport(), None);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -655,3 +655,25 @@ fn double_click_fits_width_then_resets_without_stretching() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fit_width_uses_output_shape_even_with_a_narrow_presenter_pane() {
|
||||
use pdf_presenter::presenter_ui::{fitted_slide, zoom_geometry};
|
||||
let output = Rect::from_min_size(Pos2::ZERO, Vec2::new(1920., 1080.));
|
||||
let pane = Rect::from_min_size(Pos2::ZERO, Vec2::new(300., 600.));
|
||||
let preview = fitted_slide(pane, [1920, 1080]);
|
||||
let scale = preview.width() / fitted_slide(preview, [210, 297]).width();
|
||||
let view = View {
|
||||
scale,
|
||||
center: [0.5; 2],
|
||||
};
|
||||
let (preview_draw, preview_uv) = zoom_geometry(preview, [210, 297], view, false);
|
||||
let (output_draw, output_uv) = zoom_geometry(output, [210, 297], view, false);
|
||||
assert!((preview_draw.width() - preview.width()).abs() < 0.001);
|
||||
assert!(
|
||||
(output_draw.width() - output.width()).abs() < 0.001,
|
||||
"output retained side borders"
|
||||
);
|
||||
assert!((preview_uv.min - output_uv.min).length() < 0.0001);
|
||||
assert!((preview_uv.max - output_uv.max).length() < 0.0001);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,17 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### 0.1.60
|
||||
|
||||
- Match the zoom-enabled current preview to the first connected presentation
|
||||
output's aspect ratio. Fit-width, wheel zoom and panning now show the same crop
|
||||
in that preview and output, rather than fitting independently to the preview pane.
|
||||
Report actual output-window dimensions for windowed/resized output; use monitor
|
||||
dimensions until reported. No image copies or PDF rendering are added.
|
||||
Linux checks pass with 86.35% coverage, including actual preview-mesh crop
|
||||
comparisons and portrait-page fit-width regression checks. Physical display
|
||||
acceptance remains separate.
|
||||
|
||||
### 0.1.59
|
||||
|
||||
- Increase the Menu dropdown height from 520 to 720 logical pixels so Quit stays
|
||||
|
|
|
|||
|
|
@ -170,3 +170,12 @@ absent. No zoom state is persisted except the opt-in boolean in settings.
|
|||
The performance watcher counts three consecutive zoomed window draws above 33 ms,
|
||||
including software drawing/presentation. The presenter shows the warning locally;
|
||||
output hosts report only a boolean. It does not alter visibility or navigation.
|
||||
|
||||
|
||||
Since 0.1.60, output heartbeats may include `viewport {monitor, size, fullscreen}`.
|
||||
`size` is the actual reference output window’s physical client size `[width, height]`.
|
||||
The reference is the first connected presentation route. This transient metadata
|
||||
lets the current preview use that aspect ratio, without transferring image data.
|
||||
Missing/zero dimensions or a route/fullscreen mismatch fall back to the connected
|
||||
monitor size. Reports are refreshed by the existing one-second heartbeat, and are
|
||||
not persisted. Outputs with different aspect ratios still use their own viewport.
|
||||
|
|
|
|||
|
|
@ -335,13 +335,16 @@ the visible area, not the cached image resolution.
|
|||
to zoom in/out (1×–8×). The point under the mouse stays anchored when possible.
|
||||
- Hold the left mouse button and drag to move the enlarged image. Movement stops
|
||||
at the page edges. When viewing the whole page, **double-click to fit its width**
|
||||
to the screen or current-preview area you clicked (up to 8×). Double-click again
|
||||
to the presentation screen (up to 8×). Double-click again
|
||||
while zoomed to reset to the complete fitted page. Pages already filling the
|
||||
width stay unchanged. The optional fixed page area still applies if enabled.
|
||||
- **Menu → Page zoom** also has a zoom slider and **Reset zoom** button. If the
|
||||
current preview is hidden, show it in Layout to pan from the presenter.
|
||||
- All mirrored presenter/current previews and presentation outputs share zoom and
|
||||
page center; different screen shapes can show different amounts of the page.
|
||||
page center. With zoom enabled, the current preview matches the first connected
|
||||
presentation output’s proportions, so its crop and fit-width level agree with
|
||||
that screen. Resizing the output updates the preview within about a second.
|
||||
Other mirrored outputs with different shapes can show different amounts of the page.
|
||||
Previous/next previews, All slides thumbnails and browser previews stay unzoomed.
|
||||
Moving to another slide or opening another presentation resets zoom. Display
|
||||
swaps/fullscreen changes preserve it. Zoom gestures pause during display trials.
|
||||
|
|
|
|||
Loading…
Reference in New Issue