Skip to content

Commit 4b8ba83

Browse files
authored
Merge pull request #825 from tarkah/feat/window-visibility
add window visibility
2 parents 3ea2c45 + 84c0c9b commit 4b8ba83

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

src/application.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ where
277277
match self.0.mode() {
278278
window::Mode::Windowed => iced_winit::Mode::Windowed,
279279
window::Mode::Fullscreen => iced_winit::Mode::Fullscreen,
280+
window::Mode::Hidden => iced_winit::Mode::Hidden,
280281
}
281282
}
282283

src/window/mode.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ pub enum Mode {
66

77
/// The application takes the whole screen of its current monitor.
88
Fullscreen,
9+
10+
/// The application is hidden
11+
Hidden,
912
}

winit/src/application/state.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ impl<A: Application> State<A> {
182182
new_mode,
183183
));
184184

185+
window.set_visible(conversion::visible(new_mode));
186+
185187
self.mode = new_mode;
186188
}
187189

winit/src/conversion.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,21 @@ pub fn fullscreen(
141141
mode: Mode,
142142
) -> Option<winit::window::Fullscreen> {
143143
match mode {
144-
Mode::Windowed => None,
144+
Mode::Windowed | Mode::Hidden => None,
145145
Mode::Fullscreen => {
146146
Some(winit::window::Fullscreen::Borderless(monitor))
147147
}
148148
}
149149
}
150150

151+
/// Converts a [`Mode`] to a visibility flag.
152+
pub fn visible(mode: Mode) -> bool {
153+
match mode {
154+
Mode::Windowed | Mode::Fullscreen => true,
155+
Mode::Hidden => false,
156+
}
157+
}
158+
151159
/// Converts a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon.
152160
///
153161
/// [`winit`]: https://github.com/rust-windowing/winit

winit/src/mode.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ pub enum Mode {
66

77
/// The application takes the whole screen of its current monitor.
88
Fullscreen,
9+
10+
/// The application is hidden
11+
Hidden,
912
}

winit/src/settings.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ impl Window {
8080
.with_transparent(self.transparent)
8181
.with_window_icon(self.icon)
8282
.with_always_on_top(self.always_on_top)
83-
.with_fullscreen(conversion::fullscreen(primary_monitor, mode));
83+
.with_fullscreen(conversion::fullscreen(primary_monitor, mode))
84+
.with_visible(conversion::visible(mode));
8485

8586
if let Some((width, height)) = self.min_size {
8687
window_builder = window_builder

0 commit comments

Comments
 (0)