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.
This commit is contained in:
Jeremy Soller 2024-02-12 09:53:59 -07:00 committed by GitHub
parent 072a3d5ca0
commit 02cee1d805
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 36 deletions

2
iced

@ -1 +1 @@
Subproject commit 8b7b0bf54516c4b28cc38d328a01946b3800eec7
Subproject commit 268e21076e1cb06af9142aa193dcc8647bf0eb60

View file

@ -33,8 +33,11 @@ pub fn drag<M: Send + 'static>(id: Option<window::Id>) -> iced::Command<Message<
crate::command::drag(id).map(Message::Cosmic)
}
pub fn fullscreen<M: Send + 'static>(id: Option<window::Id>) -> iced::Command<Message<M>> {
crate::command::fullscreen(id).map(Message::Cosmic)
pub fn maximize<M: Send + 'static>(
id: Option<window::Id>,
maximized: bool,
) -> iced::Command<Message<M>> {
crate::command::maximize(id, maximized).map(Message::Cosmic)
}
pub fn minimize<M: Send + 'static>(id: Option<window::Id>) -> iced::Command<Message<M>> {
@ -60,6 +63,6 @@ pub fn set_windowed<M: Send + 'static>(id: Option<window::Id>) -> iced::Command<
crate::command::set_windowed(id).map(Message::Cosmic)
}
pub fn toggle_fullscreen<M: Send + 'static>(id: Option<window::Id>) -> iced::Command<Message<M>> {
crate::command::toggle_fullscreen(id).map(Message::Cosmic)
pub fn toggle_maximize<M: Send + 'static>(id: Option<window::Id>) -> iced::Command<Message<M>> {
crate::command::toggle_maximize(id).map(Message::Cosmic)
}

View file

@ -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,

View file

@ -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<T: Application> Cosmic<T> {
#[allow(clippy::too_many_lines)]
fn cosmic_update(&mut self, message: Message) -> iced::Command<super::Message<T::Message>> {
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<T: Application> Cosmic<T> {
}
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<T: Application> Cosmic<T> {
#[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<T: Application> Cosmic<T> {
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<T: Application> Cosmic<T> {
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);

View file

@ -529,8 +529,8 @@ pub trait ApplicationExt: Application {
/// Initiates a window drag.
fn drag(&mut self) -> iced::Command<Message<Self::Message>>;
/// Fullscreens the window.
fn fullscreen(&mut self) -> iced::Command<Message<Self::Message>>;
/// Maximizes the window.
fn maximize(&mut self) -> iced::Command<Message<Self::Message>>;
/// Minimizes the window.
fn minimize(&mut self) -> iced::Command<Message<Self::Message>>;
@ -574,8 +574,8 @@ impl<App: Application> ApplicationExt for App {
command::drag(Some(window::Id::MAIN))
}
fn fullscreen(&mut self) -> iced::Command<Message<Self::Message>> {
command::fullscreen(Some(window::Id::MAIN))
fn maximize(&mut self) -> iced::Command<Message<Self::Message>> {
command::maximize(Some(window::Id::MAIN), true)
}
fn minimize(&mut self) -> iced::Command<Message<Self::Message>> {

View file

@ -42,16 +42,16 @@ pub fn drag<M>(id: Option<window::Id>) -> Command<M> {
iced_runtime::window::drag(id.unwrap_or(window::Id::MAIN))
}
/// Fullscreens the window.
/// Maximizes the window.
#[cfg(feature = "wayland")]
pub fn fullscreen<M>(id: Option<window::Id>) -> Command<M> {
iced_sctk::commands::window::set_mode_window(id.unwrap_or(window::Id::MAIN), Mode::Fullscreen)
pub fn maximize<M>(id: Option<window::Id>, maximized: bool) -> Command<M> {
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<M>(id: Option<window::Id>) -> Command<M> {
iced_runtime::window::change_mode(id.unwrap_or(window::Id::MAIN), Mode::Fullscreen)
pub fn maximize<M>(id: Option<window::Id>, maximized: bool) -> Command<M> {
iced_runtime::window::maximize(id.unwrap_or(window::Id::MAIN), maximized)
}
/// Minimizes the window.
@ -94,17 +94,15 @@ pub fn set_windowed<M>(id: Option<window::Id>) -> Command<M> {
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<M>(id: Option<window::Id>) -> Command<M> {
window_action(WindowAction::ToggleFullscreen {
id: id.unwrap_or(window::Id::MAIN),
})
pub fn toggle_maximize<M>(id: Option<window::Id>) -> Command<M> {
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<M>(id: Option<window::Id>) -> Command<M> {
pub fn toggle_maximize<M>(id: Option<window::Id>) -> Command<M> {
iced_runtime::window::toggle_maximize(id.unwrap_or(window::Id::MAIN))
}