From 02cee1d8051f504860d9b961245919fde1542355 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 12 Feb 2024 09:53:59 -0700 Subject: [PATCH] fix: maximize instead of fullscreen This fixes interactions with the window manager including dodging exclusive zones, correctly sharpening corners when the window manager sets the maximized mode, and correctly toggling the maximized state when either F11 or the maximize button are clicked. --- iced | 2 +- src/app/command.rs | 11 +++++++---- src/app/core.rs | 2 -- src/app/cosmic.rs | 28 ++++++++++++++++------------ src/app/mod.rs | 8 ++++---- src/command/mod.rs | 24 +++++++++++------------- 6 files changed, 39 insertions(+), 36 deletions(-) diff --git a/iced b/iced index 8b7b0bf5451..268e21076e1 160000 --- a/iced +++ b/iced @@ -1 +1 @@ -Subproject commit 8b7b0bf54516c4b28cc38d328a01946b3800eec7 +Subproject commit 268e21076e1cb06af9142aa193dcc8647bf0eb60 diff --git a/src/app/command.rs b/src/app/command.rs index 788708dc5c1..80682d1175b 100644 --- a/src/app/command.rs +++ b/src/app/command.rs @@ -33,8 +33,11 @@ pub fn drag(id: Option) -> iced::Command(id: Option) -> iced::Command> { - crate::command::fullscreen(id).map(Message::Cosmic) +pub fn maximize( + id: Option, + maximized: bool, +) -> iced::Command> { + crate::command::maximize(id, maximized).map(Message::Cosmic) } pub fn minimize(id: Option) -> iced::Command> { @@ -60,6 +63,6 @@ pub fn set_windowed(id: Option) -> iced::Command< crate::command::set_windowed(id).map(Message::Cosmic) } -pub fn toggle_fullscreen(id: Option) -> iced::Command> { - crate::command::toggle_fullscreen(id).map(Message::Cosmic) +pub fn toggle_maximize(id: Option) -> iced::Command> { + crate::command::toggle_maximize(id).map(Message::Cosmic) } diff --git a/src/app/core.rs b/src/app/core.rs index 3ae740b6084..940e1636984 100644 --- a/src/app/core.rs +++ b/src/app/core.rs @@ -27,7 +27,6 @@ pub struct Window { pub header_title: String, pub use_template: bool, pub content_container: bool, - pub can_fullscreen: bool, pub sharp_corners: bool, pub show_context: bool, pub show_headerbar: bool, @@ -103,7 +102,6 @@ impl Default for Core { header_title: String::new(), use_template: true, content_container: true, - can_fullscreen: false, sharp_corners: false, show_context: false, show_headerbar: true, diff --git a/src/app/cosmic.rs b/src/app/cosmic.rs index 8deb160e14e..3dec2191f13 100644 --- a/src/app/cosmic.rs +++ b/src/app/cosmic.rs @@ -56,6 +56,8 @@ pub enum Message { SystemThemeChange(Theme), /// Notification of system theme mode changes. SystemThemeModeChange(ThemeMode), + /// Updates the window maximized state + WindowMaximized(window::Id, bool), /// Updates the tracked window geometry. WindowResize(window::Id, u32, u32), /// Tracks updates to window state. @@ -257,6 +259,12 @@ impl Cosmic { #[allow(clippy::too_many_lines)] fn cosmic_update(&mut self, message: Message) -> iced::Command> { match message { + Message::WindowMaximized(id, maximized) => { + if window::Id::MAIN == id { + self.app.core_mut().window.sharp_corners = maximized; + } + } + Message::WindowResize(id, width, height) => { if window::Id::MAIN == id { self.app.core_mut().set_window_width(width); @@ -264,6 +272,12 @@ impl Cosmic { } self.app.on_window_resize(id, width, height); + + //TODO: more efficient test of maximized (winit has no event for maximize if set by the OS) + #[cfg(not(feature = "wayland"))] + return iced::window::fetch_maximized(id, move |maximized| { + super::Message::Cosmic(Message::WindowMaximized(id, maximized)) + }); } #[cfg(feature = "wayland")] @@ -284,8 +298,6 @@ impl Cosmic { #[cfg(feature = "wayland")] Message::WmCapabilities(id, capabilities) => { if window::Id::MAIN == id { - self.app.core_mut().window.can_fullscreen = - capabilities.contains(WindowManagerCapabilities::FULLSCREEN); self.app.core_mut().window.show_maximize = capabilities.contains(WindowManagerCapabilities::MAXIMIZE); self.app.core_mut().window.show_minimize = @@ -308,7 +320,7 @@ impl Cosmic { keyboard_nav::Message::Escape => return self.app.on_escape(), keyboard_nav::Message::Search => return self.app.on_search(), - keyboard_nav::Message::Fullscreen => return command::toggle_fullscreen(None), + keyboard_nav::Message::Fullscreen => return command::toggle_maximize(None), }, Message::ContextDrawer(show) => { @@ -320,15 +332,7 @@ impl Cosmic { Message::Minimize => return command::minimize(None), - Message::Maximize => { - if self.app.core().window.sharp_corners { - self.app.core_mut().window.sharp_corners = false; - return command::set_windowed(None); - } - - self.app.core_mut().window.sharp_corners = true; - return command::fullscreen(None); - } + Message::Maximize => return command::toggle_maximize(None), Message::NavBar(key) => { self.app.core_mut().nav_bar_set_toggled_condensed(false); diff --git a/src/app/mod.rs b/src/app/mod.rs index baffac8482e..b2bb3f4e5d3 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -529,8 +529,8 @@ pub trait ApplicationExt: Application { /// Initiates a window drag. fn drag(&mut self) -> iced::Command>; - /// Fullscreens the window. - fn fullscreen(&mut self) -> iced::Command>; + /// Maximizes the window. + fn maximize(&mut self) -> iced::Command>; /// Minimizes the window. fn minimize(&mut self) -> iced::Command>; @@ -574,8 +574,8 @@ impl ApplicationExt for App { command::drag(Some(window::Id::MAIN)) } - fn fullscreen(&mut self) -> iced::Command> { - command::fullscreen(Some(window::Id::MAIN)) + fn maximize(&mut self) -> iced::Command> { + command::maximize(Some(window::Id::MAIN), true) } fn minimize(&mut self) -> iced::Command> { diff --git a/src/command/mod.rs b/src/command/mod.rs index 3a918a30d7f..24776e43d59 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -42,16 +42,16 @@ pub fn drag(id: Option) -> Command { iced_runtime::window::drag(id.unwrap_or(window::Id::MAIN)) } -/// Fullscreens the window. +/// Maximizes the window. #[cfg(feature = "wayland")] -pub fn fullscreen(id: Option) -> Command { - iced_sctk::commands::window::set_mode_window(id.unwrap_or(window::Id::MAIN), Mode::Fullscreen) +pub fn maximize(id: Option, maximized: bool) -> Command { + iced_sctk::commands::window::maximize(id.unwrap_or(window::Id::MAIN), maximized) } -/// Fullscreens the window. +/// Maximizes the window. #[cfg(not(feature = "wayland"))] -pub fn fullscreen(id: Option) -> Command { - iced_runtime::window::change_mode(id.unwrap_or(window::Id::MAIN), Mode::Fullscreen) +pub fn maximize(id: Option, maximized: bool) -> Command { + iced_runtime::window::maximize(id.unwrap_or(window::Id::MAIN), maximized) } /// Minimizes the window. @@ -94,17 +94,15 @@ pub fn set_windowed(id: Option) -> Command { iced_runtime::window::change_mode(id.unwrap_or(window::Id::MAIN), Mode::Windowed) } -/// Toggles the windows' maximization state. +/// Toggles the windows' maximize state. #[cfg(feature = "wayland")] -pub fn toggle_fullscreen(id: Option) -> Command { - window_action(WindowAction::ToggleFullscreen { - id: id.unwrap_or(window::Id::MAIN), - }) +pub fn toggle_maximize(id: Option) -> Command { + iced_sctk::commands::window::toggle_maximize(id.unwrap_or(window::Id::MAIN)) } -/// Toggles the windows' maximization state. +/// Toggles the windows' maximize state. #[cfg(not(feature = "wayland"))] -pub fn toggle_fullscreen(id: Option) -> Command { +pub fn toggle_maximize(id: Option) -> Command { iced_runtime::window::toggle_maximize(id.unwrap_or(window::Id::MAIN)) }