use crate::ModsWindow;
use slint::{ComponentHandle, winit_030::WinitWindowAccessor};
pub fn bind(app: &ModsWindow) {
app.set_native_move_on_press(cfg!(any(target_os = "linux", target_os = "macos")));
#[cfg(any(target_os = "linux", target_os = "macos"))]
let mut previous_press: Option<(std::time::Instant, f32, f32)> = None;
let weak = app.as_weak();
app.on_window_drag(move |_x, _y| {
if let Some(app) = weak.upgrade() {
// Wayland's move grab and macOS's performWindowDrag loop can consume the release.
// Recognize a second nearby press without relying on Slint's pressed state.
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
let now = std::time::Instant::now();
if previous_press.take().is_some_and(|(time, x, y)| {
now.duration_since(time) < std::time::Duration::from_millis(400)
&& (_x - x).abs() + (_y - y).abs() < 8.0
}) {
app.window().set_maximized(!app.window().is_maximized());
return;
}
previous_press = Some((now, _x, _y));
}
app.window().with_winit_window(|w| {
let _ = w.drag_window();
});
}
});
let weak = app.as_weak();
app.on_window_minimize(move || {
if let Some(app) = weak.upgrade() {
app.window().set_minimized(true);
}
});
let weak = app.as_weak();
app.on_window_maximize(move || {
if let Some(app) = weak.upgrade() {
app.window().set_maximized(!app.window().is_maximized());
}
});
let weak = app.as_weak();
app.on_window_close(move || {
if let Some(app) = weak.upgrade() {
if app.get_batch_busy() {
return;
}
app.set_show_changelog(false);
app.set_show_portal_changelog(false);
app.invoke_request_close();
}
});
}