Skip to content

Commit

Permalink
Implement full-screen property for slint Window item
Browse files Browse the repository at this point in the history
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 slint-ui#6665
  • Loading branch information
bennysj committed Dec 3, 2024
1 parent 901afde commit fc9f6a3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions docs/src/content/docs/reference/window/window.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
</SlintProperty>

### full-screen
<SlintProperty propName="full-screen" typeName="brush" defaultValue="true if 'SLINT_FULLSCREEN' enviroment variable is set, otherwise false ">
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.
</SlintProperty>

### background
<SlintProperty propName="background" typeName="brush" defaultValue="depends on the style">
The background brush of the `Window`.
Expand Down
1 change: 1 addition & 0 deletions internal/backends/winit/winitwindowadapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/builtins.slint
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ component WindowItem {
in property <bool> skip-taskbar;
in property <length> resize-border-width;
in property <bool> always-on-top;
in-out property <bool> full-screen;
in property <string> default-font-family;
in-out property <length> default-font-size; // <=> StyleMetrics.default-font-size set in apply_default_properties_from_style
in property <int> default-font-weight;
Expand Down
6 changes: 5 additions & 1 deletion internal/core/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ pub struct WindowItem {
pub skip_taskbar: Property<bool>,
pub resize_border_width: Property<LogicalLength>,
pub always_on_top: Property<bool>,
pub full_screen: Property<bool>,
pub icon: Property<crate::graphics::Image>,
pub default_font_family: Property<SharedString>,
pub default_font_size: Property<LogicalLength>,
Expand All @@ -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>,
Expand Down
19 changes: 10 additions & 9 deletions internal/core/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -430,7 +430,6 @@ pub struct WindowInner {
cursor_blinker: RefCell<pin_weak::rc::PinWeak<crate::input::TextCursorBlinker>>,

pinned_fields: Pin<Box<WindowPinnedFields>>,
fullscreen: Cell<bool>,
maximized: Cell<bool>,
minimized: Cell<bool>,

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fc9f6a3

Please sign in to comment.