Skip to content

Commit

Permalink
feat(core): Ability to disable minimize/maximize/close native window'…
Browse files Browse the repository at this point in the history
…s buttons, closes #2353 (#6665)

Co-authored-by: Amr Bashir <[email protected]>
Co-authored-by: Lucas Nogueira <[email protected]>
Co-authored-by: Lucas Nogueira <[email protected]>
  • Loading branch information
4 people authored May 24, 2023
1 parent 65fd674 commit c4d6fb4
Show file tree
Hide file tree
Showing 25 changed files with 744 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .changes/disable-window-controls-api-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tauri-apps/api': 'minor:feat'
---

Added the `maximizable`, `minimizable` and `closable` fields on `WindowOptions`.
5 changes: 5 additions & 0 deletions .changes/disable-window-controls-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tauri-apps/api': 'minor:feat'
---

Added the `setMaximizable`, `setMinimizable`, `setClosable`, `isMaximizable`, `isMinimizable` and `isClosable` methods.
5 changes: 5 additions & 0 deletions .changes/disable-window-controls-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-utils': 'minor:feat'
---

Added the `maximizable`, `minimizable` and `closable` options to the window configuration.
6 changes: 6 additions & 0 deletions .changes/disable-window-controls-runtime-builder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-runtime-wry': 'minor:feat'
'tauri-runtime': 'minor:feat'
---

Added the `maximizable`, `minimizable` and `closable` methods to `WindowBuilder`.
6 changes: 6 additions & 0 deletions .changes/disable-window-controls-runtime-window.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-runtime-wry': 'minor:feat'
'tauri-runtime': 'minor:feat'
---

Added `set_maximizable`, `set_minimizable`, `set_closable`, `is_maximizable`, `is_minimizable` and `is_closable` methods to the `Dispatch` trait.
5 changes: 5 additions & 0 deletions .changes/disable-window-controls-window-builder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'minor:feat'
---

Added the `maximizable`, `minimizable` and `closable` options to the window builder.
5 changes: 5 additions & 0 deletions .changes/disable-window-controls-window.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'minor:feat'
---

Added the `set_maximizable`, `set_minimizable`, `set_closable`, `is_maximizable`, `is_minimizable` and `is_closable` methods on `Window`.
41 changes: 40 additions & 1 deletion core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"print": false,
"requestUserAttention": false,
"setAlwaysOnTop": false,
"setClosable": false,
"setContentProtected": false,
"setCursorGrab": false,
"setCursorIcon": false,
Expand All @@ -116,7 +117,9 @@
"setIcon": false,
"setIgnoreCursorEvents": false,
"setMaxSize": false,
"setMaximizable": false,
"setMinSize": false,
"setMinimizable": false,
"setPosition": false,
"setResizable": false,
"setSize": false,
Expand Down Expand Up @@ -383,6 +386,7 @@
"print": false,
"requestUserAttention": false,
"setAlwaysOnTop": false,
"setClosable": false,
"setContentProtected": false,
"setCursorGrab": false,
"setCursorIcon": false,
Expand All @@ -394,7 +398,9 @@
"setIcon": false,
"setIgnoreCursorEvents": false,
"setMaxSize": false,
"setMaximizable": false,
"setMinSize": false,
"setMinimizable": false,
"setPosition": false,
"setResizable": false,
"setSize": false,
Expand Down Expand Up @@ -605,7 +611,22 @@
"format": "double"
},
"resizable": {
"description": "Whether the window is resizable or not.",
"description": "Whether the window is resizable or not. When resizable is set to false, native window's maximize button is automatically disabled.",
"default": true,
"type": "boolean"
},
"maximizable": {
"description": "Whether the window's native maximize button is enabled or not. If resizable is set to false, this setting is ignored.\n\n## Platform-specific\n\n- **macOS:** Disables the \"zoom\" button in the window titlebar, which is also used to enter fullscreen mode. - **Linux / iOS / Android:** Unsupported.",
"default": true,
"type": "boolean"
},
"minimizable": {
"description": "Whether the window's native minimize button is enabled or not.\n\n## Platform-specific\n\n- **Linux / iOS / Android:** Unsupported.",
"default": true,
"type": "boolean"
},
"closable": {
"description": "Whether the window's native close button is enabled or not.\n\n## Platform-specific\n\n- **Linux:** \"GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible\" - **iOS / Android:** Unsupported.",
"default": true,
"type": "boolean"
},
Expand Down Expand Up @@ -1809,6 +1830,7 @@
"print": false,
"requestUserAttention": false,
"setAlwaysOnTop": false,
"setClosable": false,
"setContentProtected": false,
"setCursorGrab": false,
"setCursorIcon": false,
Expand All @@ -1820,7 +1842,9 @@
"setIcon": false,
"setIgnoreCursorEvents": false,
"setMaxSize": false,
"setMaximizable": false,
"setMinSize": false,
"setMinimizable": false,
"setPosition": false,
"setResizable": false,
"setSize": false,
Expand Down Expand Up @@ -2117,6 +2141,21 @@
"default": false,
"type": "boolean"
},
"setMaximizable": {
"description": "Allows setting whether the window's native maximize button is enabled or not.",
"default": false,
"type": "boolean"
},
"setMinimizable": {
"description": "Allows setting whether the window's native minimize button is enabled or not.",
"default": false,
"type": "boolean"
},
"setClosable": {
"description": "Allows setting whether the window's native close button is enabled or not.",
"default": false,
"type": "boolean"
},
"setTitle": {
"description": "Allows changing the window title.",
"default": false,
Expand Down
66 changes: 66 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,9 @@ impl WindowBuilder for WindowBuilderWrapper {
.inner_size(config.width, config.height)
.visible(config.visible)
.resizable(config.resizable)
.maximizable(config.maximizable)
.minimizable(config.minimizable)
.closable(config.closable)
.fullscreen(config.fullscreen)
.decorations(config.decorations)
.maximized(config.maximized)
Expand Down Expand Up @@ -815,6 +818,21 @@ impl WindowBuilder for WindowBuilderWrapper {
self
}

fn maximizable(mut self, maximizable: bool) -> Self {
self.inner = self.inner.with_maximizable(maximizable);
self
}

fn minimizable(mut self, minimizable: bool) -> Self {
self.inner = self.inner.with_minimizable(minimizable);
self
}

fn closable(mut self, closable: bool) -> Self {
self.inner = self.inner.with_closable(closable);
self
}

fn title<S: Into<String>>(mut self, title: S) -> Self {
self.inner = self.inner.with_title(title.into());
self
Expand Down Expand Up @@ -1056,6 +1074,9 @@ pub enum WindowMessage {
IsMaximized(Sender<bool>),
IsDecorated(Sender<bool>),
IsResizable(Sender<bool>),
IsMaximizable(Sender<bool>),
IsMinimizable(Sender<bool>),
IsClosable(Sender<bool>),
IsVisible(Sender<bool>),
Title(Sender<String>),
IsMenuVisible(Sender<bool>),
Expand All @@ -1076,6 +1097,9 @@ pub enum WindowMessage {
Center,
RequestUserAttention(Option<UserAttentionTypeWrapper>),
SetResizable(bool),
SetMaximizable(bool),
SetMinimizable(bool),
SetClosable(bool),
SetTitle(String),
Maximize,
Unmaximize,
Expand Down Expand Up @@ -1294,6 +1318,21 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
window_getter!(self, WindowMessage::IsResizable)
}

/// Gets the current native window's maximize button state
fn is_maximizable(&self) -> Result<bool> {
window_getter!(self, WindowMessage::IsMaximizable)
}

/// Gets the current native window's minimize button state
fn is_minimizable(&self) -> Result<bool> {
window_getter!(self, WindowMessage::IsMinimizable)
}

/// Gets the current native window's close button state
fn is_closable(&self) -> Result<bool> {
window_getter!(self, WindowMessage::IsClosable)
}

fn is_visible(&self) -> Result<bool> {
window_getter!(self, WindowMessage::IsVisible)
}
Expand Down Expand Up @@ -1385,6 +1424,27 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
)
}

fn set_maximizable(&self, maximizable: bool) -> Result<()> {
send_user_message(
&self.context,
Message::Window(self.window_id, WindowMessage::SetMaximizable(maximizable)),
)
}

fn set_minimizable(&self, minimizable: bool) -> Result<()> {
send_user_message(
&self.context,
Message::Window(self.window_id, WindowMessage::SetMinimizable(minimizable)),
)
}

fn set_closable(&self, closable: bool) -> Result<()> {
send_user_message(
&self.context,
Message::Window(self.window_id, WindowMessage::SetClosable(closable)),
)
}

fn set_title<S: Into<String>>(&self, title: S) -> Result<()> {
send_user_message(
&self.context,
Expand Down Expand Up @@ -2409,6 +2469,9 @@ fn handle_user_message<T: UserEvent>(
WindowMessage::IsMaximized(tx) => tx.send(window.is_maximized()).unwrap(),
WindowMessage::IsDecorated(tx) => tx.send(window.is_decorated()).unwrap(),
WindowMessage::IsResizable(tx) => tx.send(window.is_resizable()).unwrap(),
WindowMessage::IsMaximizable(tx) => tx.send(window.is_maximizable()).unwrap(),
WindowMessage::IsMinimizable(tx) => tx.send(window.is_minimizable()).unwrap(),
WindowMessage::IsClosable(tx) => tx.send(window.is_closable()).unwrap(),
WindowMessage::IsVisible(tx) => tx.send(window.is_visible()).unwrap(),
WindowMessage::Title(tx) => tx.send(window.title()).unwrap(),
WindowMessage::IsMenuVisible(tx) => tx.send(window.is_menu_visible()).unwrap(),
Expand Down Expand Up @@ -2441,6 +2504,9 @@ fn handle_user_message<T: UserEvent>(
window.request_user_attention(request_type.map(|r| r.0));
}
WindowMessage::SetResizable(resizable) => window.set_resizable(resizable),
WindowMessage::SetMaximizable(maximizable) => window.set_maximizable(maximizable),
WindowMessage::SetMinimizable(minimizable) => window.set_minimizable(minimizable),
WindowMessage::SetClosable(closable) => window.set_closable(closable),
WindowMessage::SetTitle(title) => window.set_title(&title),
WindowMessage::Maximize => window.set_maximized(true),
WindowMessage::Unmaximize => window.set_maximized(false),
Expand Down
45 changes: 45 additions & 0 deletions core/tauri-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,27 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
/// Gets the window’s current resizable state.
fn is_resizable(&self) -> Result<bool>;

/// Gets the window's native maximize button state.
///
/// ## Platform-specific
///
/// - **Linux / iOS / Android:** Unsupported.
fn is_maximizable(&self) -> Result<bool>;

/// Gets the window's native minize button state.
///
/// ## Platform-specific
///
/// - **Linux / iOS / Android:** Unsupported.
fn is_minimizable(&self) -> Result<bool>;

/// Gets the window's native close button state.
///
/// ## Platform-specific
///
/// - **iOS / Android:** Unsupported.
fn is_closable(&self) -> Result<bool>;

/// Gets the window's current visibility state.
fn is_visible(&self) -> Result<bool>;
/// Gets the window's current title.
Expand Down Expand Up @@ -640,6 +661,30 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
/// Updates the window resizable flag.
fn set_resizable(&self, resizable: bool) -> Result<()>;

/// Updates the window's native maximize button state.
///
/// ## Platform-specific
///
/// - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
/// - **Linux / iOS / Android:** Unsupported.
fn set_maximizable(&self, maximizable: bool) -> Result<()>;

/// Updates the window's native minimize button state.
///
/// ## Platform-specific
///
/// - **Linux / iOS / Android:** Unsupported.
fn set_minimizable(&self, minimizable: bool) -> Result<()>;

/// Updates the window's native close button state.
///
/// ## Platform-specific
///
/// - **Linux:** "GTK+ will do its best to convince the window manager not to show a close button.
/// Depending on the system, this function may not have any effect when called on a window that is already visible"
/// - **iOS / Android:** Unsupported.
fn set_closable(&self, closable: bool) -> Result<()>;

/// Updates the window title.
fn set_title<S: Into<String>>(&self, title: S) -> Result<()>;

Expand Down
29 changes: 29 additions & 0 deletions core/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,38 @@ pub trait WindowBuilder: WindowBuilderBase {
fn max_inner_size(self, max_width: f64, max_height: f64) -> Self;

/// Whether the window is resizable or not.
/// When resizable is set to false, native window's maximize button is automatically disabled.
#[must_use]
fn resizable(self, resizable: bool) -> Self;

/// Whether the window's native maximize button is enabled or not.
/// If resizable is set to false, this setting is ignored.
///
/// ## Platform-specific
///
/// - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
/// - **Linux / iOS / Android:** Unsupported.
#[must_use]
fn maximizable(self, maximizable: bool) -> Self;

/// Whether the window's native minimize button is enabled or not.
///
/// ## Platform-specific
///
/// - **Linux / iOS / Android:** Unsupported.
#[must_use]
fn minimizable(self, minimizable: bool) -> Self;

/// Whether the window's native close button is enabled or not.
///
/// ## Platform-specific
///
/// - **Linux:** "GTK+ will do its best to convince the window manager not to show a close button.
/// Depending on the system, this function may not have any effect when called on a window that is already visible"
/// - **iOS / Android:** Unsupported.
#[must_use]
fn closable(self, closable: bool) -> Self;

/// The title of the window in the title bar.
#[must_use]
fn title<S: Into<String>>(self, title: S) -> Self;
Expand Down
Loading

0 comments on commit c4d6fb4

Please sign in to comment.