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 Oct 27, 2024
1 parent e01a121 commit de2d6f5
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 12 deletions.
5 changes: 5 additions & 0 deletions examples/gallery/gallery.pot
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ msgctxt "Page"
msgid "Dark Mode"
msgstr ""

#: ui/pages/page.slint:41
msgctxt "Page"
msgid "Full Screen"
msgstr ""

#: ui/pages/about_page.slint:9
msgctxt "AboutPage"
msgid "About"
Expand Down
1 change: 1 addition & 0 deletions examples/gallery/gallery.slint
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export component App inherits Window {
preferred-height: 500px;
title: @tr("Slint Widgets Gallery");
icon: @image-url("../../logo/slint-logo-small-light.png");
full-screen <=> GallerySettings.full-screen;

HorizontalLayout {
side-bar := SideBar {
Expand Down
5 changes: 5 additions & 0 deletions examples/gallery/lang/de/LC_MESSAGES/gallery.po
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ msgctxt "Page"
msgid "Dark Mode"
msgstr ""

#: ui/pages/page.slint:41
msgctxt "Page"
msgid "Full Screen"
msgstr ""

#: ui/pages/about_page.slint:9
msgctxt "AboutPage"
msgid "About"
Expand Down
5 changes: 5 additions & 0 deletions examples/gallery/lang/fr/LC_MESSAGES/gallery.po
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ msgctxt "Page"
msgid "Dark Mode"
msgstr ""

#: ui/pages/page.slint:41
msgctxt "Page"
msgid "Full Screen"
msgstr ""

#: ui/pages/about_page.slint:9
#, fuzzy
msgctxt "AboutPage"
Expand Down
1 change: 1 addition & 0 deletions examples/gallery/ui/gallery_settings.slint
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

export global GallerySettings {
in property <bool> widgets-enabled: true;
in-out property <bool> full-screen: false;
}
9 changes: 8 additions & 1 deletion examples/gallery/ui/pages/page.slint
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ export component Page inherits VerticalBox {
horizontal-stretch: 0;
text: @tr("Dark Mode");
checked: Palette.color-scheme == ColorScheme.dark;
toggled => {
toggled => {
Palette.color-scheme = self.checked ? ColorScheme.dark : ColorScheme.light;
}
}


Switch {
horizontal-stretch: 0;
text: @tr("Full Screen");
checked <=> GallerySettings.full-screen;
}
}

@children
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 @@ -818,6 +818,7 @@ impl WindowAdapter for WinitWindowAdapter {
} else {
winit_window_or_none.set_fullscreen(None);
}
self.fullscreen.set(m);
}

let m = properties.is_maximized();
Expand Down
3 changes: 2 additions & 1 deletion internal/compiler/builtins.slint
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ component WindowItem {
in property <bool> no-frame;
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 Expand Up @@ -418,7 +419,7 @@ export component PopupWindow {
in property <length> anchor_y;
in property <length> anchor_height;
in property <length> anchor_width;*/
in property <bool> close-on-click;
in property <bool> close-on-click;
in property <PopupClosePolicy> close-policy; // constexpr hardcoded in typeregister.rs
//show() is hardcoded in typeregister.rs
}
Expand Down
6 changes: 5 additions & 1 deletion internal/core/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ pub struct WindowItem {
pub no_frame: 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 @@ -961,7 +962,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 @@ -331,7 +331,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 @@ -427,7 +427,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 @@ -483,10 +482,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 @@ -1146,13 +1141,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 de2d6f5

Please sign in to comment.