Skip to content

Commit

Permalink
fix: maximize instead of fullscreen
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jackpot51 authored Feb 12, 2024
1 parent 072a3d5 commit 02cee1d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 36 deletions.
2 changes: 1 addition & 1 deletion iced
11 changes: 7 additions & 4 deletions src/app/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>> {
Expand All @@ -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)
}
2 changes: 0 additions & 2 deletions src/app/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
28 changes: 16 additions & 12 deletions src/app/cosmic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -257,13 +259,25 @@ 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);
self.app.core_mut().set_window_height(height);
}

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")]
Expand All @@ -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 =
Expand All @@ -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) => {
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>;
Expand Down Expand Up @@ -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>> {
Expand Down
24 changes: 11 additions & 13 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
}

Expand Down

0 comments on commit 02cee1d

Please sign in to comment.