From d224a6199133558d6f50c78fde2bb92ccbb4a1a9 Mon Sep 17 00:00:00 2001 From: Benny Sjoestrand Date: Sun, 27 Oct 2024 09:18:53 +0100 Subject: [PATCH] Implement full-screen property for slint Window item Make it possible to programatically to switch to full-screen mode via a new property in the Windows item. The SLINT_FULLSCREEN environment variable will default set this property to true. However settings this property in the slint code will override the SLINT_FULLSCREEN. Fixes #6665 --- .../content/docs/reference/window/window.mdx | 5 +++++ internal/backends/winit/winitwindowadapter.rs | 1 + internal/compiler/builtins.slint | 1 + internal/core/items.rs | 6 +++++- internal/core/window.rs | 19 ++++++++++--------- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/docs/src/content/docs/reference/window/window.mdx b/docs/src/content/docs/reference/window/window.mdx index 7ba11e47c98..c4a3d378825 100644 --- a/docs/src/content/docs/reference/window/window.mdx +++ b/docs/src/content/docs/reference/window/window.mdx @@ -18,6 +18,11 @@ or smaller. The initial width can be controlled with the `preferred-width` prope Whether the window should be placed above all other windows on window managers supporting it. +### full-screen + +Whether to display the Window in full-screen mode. In full-screen mode the Window will occupy the entire screen, it will not be resizable, and it will not display the title bar. + + ### background The background brush of the `Window`. diff --git a/internal/backends/winit/winitwindowadapter.rs b/internal/backends/winit/winitwindowadapter.rs index 28c5304b8fb..f9aa296c046 100644 --- a/internal/backends/winit/winitwindowadapter.rs +++ b/internal/backends/winit/winitwindowadapter.rs @@ -885,6 +885,7 @@ impl WindowAdapter for WinitWindowAdapter { } else { winit_window_or_none.set_fullscreen(None); } + self.fullscreen.set(m); } let m = properties.is_maximized(); diff --git a/internal/compiler/builtins.slint b/internal/compiler/builtins.slint index 1cb3bfa2537..6f9d2941294 100644 --- a/internal/compiler/builtins.slint +++ b/internal/compiler/builtins.slint @@ -218,6 +218,7 @@ component WindowItem { in property skip-taskbar; in property resize-border-width; in property always-on-top; + in-out property full-screen; in property default-font-family; in-out property default-font-size; // <=> StyleMetrics.default-font-size set in apply_default_properties_from_style in property default-font-weight; diff --git a/internal/core/items.rs b/internal/core/items.rs index 678c9f50e65..60ae2bcadc6 100644 --- a/internal/core/items.rs +++ b/internal/core/items.rs @@ -956,6 +956,7 @@ pub struct WindowItem { pub skip_taskbar: Property, pub resize_border_width: Property, pub always_on_top: Property, + pub full_screen: Property, pub icon: Property, pub default_font_family: Property, pub default_font_size: Property, @@ -964,7 +965,10 @@ pub struct WindowItem { } impl Item for WindowItem { - fn init(self: Pin<&Self>, _self_rc: &ItemRc) {} + fn init(self: Pin<&Self>, _self_rc: &ItemRc) { + #[cfg(feature = "std")] + self.full_screen.set(std::env::var("SLINT_FULLSCREEN").is_ok()); + } fn layout_info( self: Pin<&Self>, diff --git a/internal/core/window.rs b/internal/core/window.rs index 6912981d01c..71b553a863b 100644 --- a/internal/core/window.rs +++ b/internal/core/window.rs @@ -332,7 +332,7 @@ impl<'a> WindowProperties<'a> { /// Returns true if the window should be shown fullscreen; false otherwise. pub fn is_fullscreen(&self) -> bool { - self.0.fullscreen.get() + self.0.is_fullscreen() } /// true if the window is in a maximized state, otherwise false @@ -430,7 +430,6 @@ pub struct WindowInner { cursor_blinker: RefCell>, pinned_fields: Pin>, - fullscreen: Cell, maximized: Cell, minimized: Cell, @@ -488,10 +487,6 @@ impl WindowInner { "i_slint_core::Window::text_input_focused", ), }), - #[cfg(feature = "std")] - fullscreen: Cell::new(std::env::var("SLINT_FULLSCREEN").is_ok()), - #[cfg(not(feature = "std"))] - fullscreen: Cell::new(false), maximized: Cell::new(false), minimized: Cell::new(false), focus_item: Default::default(), @@ -1218,13 +1213,19 @@ impl WindowInner { /// Returns if the window is currently maximized pub fn is_fullscreen(&self) -> bool { - self.fullscreen.get() + if let Some(window_item) = self.window_item() { + window_item.as_pin_ref().full_screen() + } else { + false + } } /// Set or unset the window to display fullscreen. pub fn set_fullscreen(&self, enabled: bool) { - self.fullscreen.set(enabled); - self.update_window_properties() + if let Some(window_item) = self.window_item() { + window_item.as_pin_ref().full_screen.set(enabled); + self.update_window_properties() + } } /// Returns if the window is currently maximized