mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-25 10:39:01 -06:00
* Issue #324: vendor winit 0.30.13 as published The crate as released on crates.io, without its asset files (docs/res/*.svg and examples/data/*.png, AGENTS.md §1). Not used yet: the next commit patches it and adds it to [patch.crates-io]. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Issue #324: on Windows 11, a window dragged to another monitor takes its scale winit 0.30.13 handles WM_DPICHANGED by checking that the new window rect is on the monitor `MonitorFromWindow` names. During a drag that is still the monitor being left, so winit nudged the window back onto it, which sent another WM_DPICHANGED: the window grew and stayed on the wrong monitor at the wrong scale. From Windows 11 (build 22000) on, apply the rect Windows suggests, as winit master does since 488c036a (rust-windowing/winit#4341); no 0.30 release has it. Windows 10 keeps the old adjustment, as on winit master. The vendored copy goes in [patch.crates-io]; a test fails if winit resolves from crates.io again or the vendored copy loses the patch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
3.3 KiB
Rust
100 lines
3.3 KiB
Rust
#![allow(clippy::single_match)]
|
|
|
|
// Limit this example to only compatible platforms.
|
|
#[cfg(any(windows_platform, macos_platform, x11_platform, wayland_platform,))]
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
use std::time::Duration;
|
|
|
|
use winit::application::ApplicationHandler;
|
|
use winit::event::WindowEvent;
|
|
use winit::event_loop::{ActiveEventLoop, EventLoop};
|
|
use winit::platform::run_on_demand::EventLoopExtRunOnDemand;
|
|
use winit::window::{Window, WindowId};
|
|
|
|
#[path = "util/fill.rs"]
|
|
mod fill;
|
|
|
|
#[derive(Default)]
|
|
struct App {
|
|
idx: usize,
|
|
window_id: Option<WindowId>,
|
|
window: Option<Window>,
|
|
}
|
|
|
|
impl ApplicationHandler for App {
|
|
fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {
|
|
if let Some(window) = self.window.as_ref() {
|
|
window.request_redraw();
|
|
}
|
|
}
|
|
|
|
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
|
let window_attributes = Window::default_attributes()
|
|
.with_title("Fantastic window number one!")
|
|
.with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0));
|
|
let window = event_loop.create_window(window_attributes).unwrap();
|
|
self.window_id = Some(window.id());
|
|
self.window = Some(window);
|
|
}
|
|
|
|
fn window_event(
|
|
&mut self,
|
|
event_loop: &ActiveEventLoop,
|
|
window_id: WindowId,
|
|
event: WindowEvent,
|
|
) {
|
|
if event == WindowEvent::Destroyed && self.window_id == Some(window_id) {
|
|
println!(
|
|
"--------------------------------------------------------- Window {} Destroyed",
|
|
self.idx
|
|
);
|
|
self.window_id = None;
|
|
event_loop.exit();
|
|
return;
|
|
}
|
|
|
|
let window = match self.window.as_mut() {
|
|
Some(window) => window,
|
|
None => return,
|
|
};
|
|
|
|
match event {
|
|
WindowEvent::CloseRequested => {
|
|
println!(
|
|
"--------------------------------------------------------- Window {} \
|
|
CloseRequested",
|
|
self.idx
|
|
);
|
|
fill::cleanup_window(window);
|
|
self.window = None;
|
|
},
|
|
WindowEvent::RedrawRequested => {
|
|
fill::fill_window(window);
|
|
},
|
|
_ => (),
|
|
}
|
|
}
|
|
}
|
|
|
|
tracing_subscriber::fmt::init();
|
|
|
|
let mut event_loop = EventLoop::new().unwrap();
|
|
|
|
let mut app = App { idx: 1, ..Default::default() };
|
|
event_loop.run_app_on_demand(&mut app)?;
|
|
|
|
println!("--------------------------------------------------------- Finished first loop");
|
|
println!("--------------------------------------------------------- Waiting 5 seconds");
|
|
std::thread::sleep(Duration::from_secs(5));
|
|
|
|
app.idx += 1;
|
|
event_loop.run_app_on_demand(&mut app)?;
|
|
println!("--------------------------------------------------------- Finished second loop");
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(not(any(windows_platform, macos_platform, x11_platform, wayland_platform,)))]
|
|
fn main() {
|
|
println!("This example is not supported on this platform");
|
|
}
|