Adds the ability to disable/enable window interactions
This allows the user to enable/disable interactions with the window. This is useful for displaying a dialog box that. This is useful in conjunction with always-on-top and PR #6675.
Example Slint:
mod dialog {
slint::slint! {
export component MyDialog inherits Window {
skip-taskbar: true;
width: 200px;
height: 200px;
}
}
}
slint::slint! {
import { Button } from "std-widgets.slint";
export component AppWindow inherits Window {
callback show-dialog;
min-width: 200px;
min-height: 200px;
Button {
text: "Click me!";
clicked => {
root.show-dialog();
// root.disabled = true;
}
}
}
}
Example Rust (Might be overkill 😃)
use std::sync::Arc;
pub fn main() -> Result<(), slint::PlatformError> {
let app_window = AppWindow::new()?;
let app = Arc::new(app_window);
let window_ref = app.clone();
app.clone().on_show_dialog(move || {
let dialog = dialog::MyDialog::new().unwrap();
window_ref.clone().window().set_disabled(true);
let window_ref = window_ref.clone();
dialog.window().on_close_requested(move || {
window_ref.clone().window().set_disabled(false);
slint::CloseRequestResponse::HideWindow
});
let _ = dialog.show();
});
app.clone().run()?;
Ok(())
}
I'm wondering if that's really the right API to create modal dialog. We might need a more complex API in rust/C++ to create modal dialog that prevent interaction on their parent. I think this is the typical usecase.
With wayland + portals we will also need a way to register external windows as "modal windows" on top of application windows. So maybe we can pass in a optional (os-) window handle or something instead of a bool?
E.g. file selection in a program using a portal can pop up a file dialog that logically belongs to the application asking for a file, but is actually a different process providing the window. That needs to be handled properly to make sure the right windows get selected when switching between applications.
Kai-Uwe blogged about KDE doing this recently: https://blog.broulik.de/2024/11/little-wayland-things/