Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the ability to disable/enable window interactions #6694

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions docs/reference/src/language/builtins/elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
26 changes: 26 additions & 0 deletions internal/backends/winit/winitwindowadapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions internal/compiler/builtins.slint
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ component WindowItem {
in-out property <length> default-font-size; // <=> StyleMetrics.default-font-size set in apply_default_properties_from_style
in property <int> default-font-weight;
in property <image> icon;
in property <bool> skip-taskbar;
}

export component Window inherits WindowItem { }
Expand Down
6 changes: 6 additions & 0 deletions internal/core/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions internal/core/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ pub struct WindowItem {
pub default_font_size: Property<LogicalLength>,
pub default_font_weight: Property<i32>,
pub cached_rendering_data: CachedRenderingData,
pub skip_taskbar: Property<bool>,
}

impl Item for WindowItem {
Expand Down
14 changes: 14 additions & 0 deletions internal/core/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -432,6 +437,8 @@ pub struct WindowInner {
maximized: Cell<bool>,
minimized: Cell<bool>,

disabled: Cell<bool>,

/// Stack of currently active popups
active_popups: RefCell<Vec<PopupWindow>>,
had_popup_on_press: Cell<bool>,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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<dyn WindowAdapter> {
self.window_adapter_weak.upgrade().unwrap()
Expand Down
Loading