diff --git a/docs/reference/src/language/builtins/elements.md b/docs/reference/src/language/builtins/elements.md index fb4340a24b9..1c11fb167ba 100644 --- a/docs/reference/src/language/builtins/elements.md +++ b/docs/reference/src/language/builtins/elements.md @@ -1056,6 +1056,7 @@ or smaller. The initial width can be controlled with the `preferred-width` prope ### Properties - **`always-on-top`** (_in_ _bool_): Whether the window should be placed above all other windows on window managers supporting it. +- **`skip-taskbar`** (_in_ _bool_): Whether the window should be shown in the taskbar or not. - **`background`** (_in_ _brush_): The background brush of the `Window`. (default value: depends on the style) - **`default-font-family`** (_in_ _string_): The font family to use as default in text elements inside this window, that don't have their `font-family` property set. - **`default-font-size`** (_in-out_ _length_): The font size to use as default in text elements inside this window, that don't have their `font-size` property set. The value of this property also forms the basis for relative font sizes. @@ -1064,3 +1065,4 @@ or smaller. The initial width can be controlled with the `preferred-width` prope - **`no-frame`** (_in_ _bool_): Whether the window should be borderless/frameless or not. - **`resize-border-width`** (_in_ _length_): Size of the resize border in borderless/frameless windows (winit only for now). - **`title`** (_in_ _string_): The window title that is shown in the title bar. +- **`disabled`** (_out_ _bool_): Disables the window from being interacted with. This is useful for dialog windows. diff --git a/internal/backends/winit/winitwindowadapter.rs b/internal/backends/winit/winitwindowadapter.rs index 19b56c6f91b..f912a3a2308 100644 --- a/internal/backends/winit/winitwindowadapter.rs +++ b/internal/backends/winit/winitwindowadapter.rs @@ -153,6 +153,26 @@ impl WinitWindowOrNone { } } + fn set_window_disabled(&self, _disabled: bool) { + match self { + Self::HasWindow(_window) => { + #[cfg(target_family = "windows")] + _window.set_enable(!_disabled); + } + Self::None(..) => { /* Winit doesn't have an attribute for this. */ } + } + } + + fn set_skip_taskbar(&self, _disabled: bool) { + match self { + Self::HasWindow(_window) => { + #[cfg(target_family = "windows")] + _window.set_skip_taskbar(_disabled); + } + Self::None(..) => { /* Winit doesn't have an attribute for this. */ } + } + } + fn set_decorations(&self, decorations: bool) { match self { Self::HasWindow(window) => window.set_decorations(decorations), @@ -764,6 +784,12 @@ impl WindowAdapter for WinitWindowAdapter { winit_window_or_none.set_window_level(new_window_level); } + let is_window_disabled = properties.disabled(); + winit_window_or_none.set_window_disabled(is_window_disabled); + + let is_skip_taskbar = window_item.skip_taskbar(); + winit_window_or_none.set_skip_taskbar(is_skip_taskbar); + // Use our scale factor instead of winit's logical size to take a scale factor override into account. let sf = self.window().scale_factor(); diff --git a/internal/compiler/builtins.slint b/internal/compiler/builtins.slint index fdec4a5453b..fdb3b4df91c 100644 --- a/internal/compiler/builtins.slint +++ b/internal/compiler/builtins.slint @@ -196,6 +196,7 @@ component WindowItem { in-out property default-font-size; // <=> StyleMetrics.default-font-size set in apply_default_properties_from_style in property default-font-weight; in property icon; + in property skip-taskbar; } export component Window inherits WindowItem { } diff --git a/internal/core/api.rs b/internal/core/api.rs index 1cf79f6b43c..f849b55349c 100644 --- a/internal/core/api.rs +++ b/internal/core/api.rs @@ -577,6 +577,12 @@ impl Window { self.0.set_minimized(minimized); } + /// Enables or disables the window interactions.\ + /// When disabled, the window will not accept any user input. + pub fn set_disabled(&self, disabled: bool) { + self.0.set_disabled(disabled); + } + /// Dispatch a window event to the scene. /// /// Use this when you're implementing your own backend and want to forward user input events. diff --git a/internal/core/items.rs b/internal/core/items.rs index 21b16cc4233..bbd1d4f01cf 100644 --- a/internal/core/items.rs +++ b/internal/core/items.rs @@ -958,6 +958,7 @@ pub struct WindowItem { pub default_font_size: Property, pub default_font_weight: Property, pub cached_rendering_data: CachedRenderingData, + pub skip_taskbar: Property, } impl Item for WindowItem { diff --git a/internal/core/window.rs b/internal/core/window.rs index dfb3a4f45e0..5411397fd8d 100644 --- a/internal/core/window.rs +++ b/internal/core/window.rs @@ -344,6 +344,11 @@ impl<'a> WindowProperties<'a> { pub fn is_minimized(&self) -> bool { self.0.minimized.get() } + + /// Gets the disabled state of the window + pub fn disabled(&self) -> bool { + self.0.disabled.get() + } } struct WindowPropertiesTracker { @@ -432,6 +437,8 @@ pub struct WindowInner { maximized: Cell, minimized: Cell, + disabled: Cell, + /// Stack of currently active popups active_popups: RefCell>, had_popup_on_press: Cell, @@ -491,6 +498,7 @@ impl WindowInner { fullscreen: Cell::new(false), maximized: Cell::new(false), minimized: Cell::new(false), + disabled: Cell::new(false), focus_item: Default::default(), last_ime_text: Default::default(), cursor_blinker: Default::default(), @@ -1203,6 +1211,12 @@ impl WindowInner { self.update_window_properties() } + /// Enables or disables the window + pub fn set_disabled(&self, disabled: bool) { + self.disabled.set(disabled); + self.update_window_properties() + } + /// Returns the upgraded window adapter pub fn window_adapter(&self) -> Rc { self.window_adapter_weak.upgrade().unwrap()