Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Ability to disable minimize/maximize/close native window's buttons, closes #2353 #6665

Merged
merged 30 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
963bae8
feat(core): expose maximizability/minimizability/closability to windo…
TDiblik Apr 8, 2023
6c43a48
feat(utils): ability to set button states from tauri.conf.json
TDiblik Apr 8, 2023
58f60d6
chore: summarize changes
TDiblik Apr 8, 2023
07491f8
chore: docs
TDiblik Apr 8, 2023
3028b5e
chore: add generated schemas
TDiblik Apr 8, 2023
b1371bc
chore: docs
TDiblik Apr 8, 2023
58d0394
chore(core): make comments consistent
TDiblik Apr 11, 2023
45820bc
feat(core/api): Expose new api for typescript and config features
TDiblik Apr 11, 2023
1d72277
chore: docs
TDiblik Apr 11, 2023
3ef3365
chore(core/api): add generated schemas
TDiblik Apr 11, 2023
79e2d56
chore(meta): update changes to reflect current state
TDiblik Apr 11, 2023
dcc5aa1
chore(core/api): add generated files
TDiblik Apr 11, 2023
46f0f56
fix(ci)
TDiblik Apr 14, 2023
1916c96
chore(docs): Add platform specific documentation
TDiblik Apr 14, 2023
e7e9da2
chore(tooling): Rename/Remove params inside docs that don't match fun…
TDiblik Apr 14, 2023
22a2726
chore(core/api) add generated files
TDiblik Apr 14, 2023
e02e195
chore(api): formatting
TDiblik Apr 14, 2023
a3efd51
chore(api): formatting
TDiblik Apr 14, 2023
5cf766d
chore(api): formatting
TDiblik Apr 14, 2023
8c45842
chore(api): formatting
TDiblik Apr 14, 2023
fe8f77f
chore(api): formatting
TDiblik Apr 14, 2023
2f72907
chore(api): formatting
TDiblik Apr 14, 2023
51697f0
docs(core): Insert platform specific comments instead of linking
TDiblik Apr 14, 2023
4801768
docs(core): Insert platform specific comments instead of linking
TDiblik Apr 14, 2023
e4e6bda
chore(tooling): Add more info to configuration docs
TDiblik Apr 16, 2023
1ffdf28
Merge remote-tracking branch 'origin/dev' into feature/2353-set-title…
lucasfernog May 24, 2023
0bab7b6
split change files
lucasfernog May 24, 2023
4e0acca
update docs
lucasfernog May 24, 2023
ff48bbb
fix covector
lucasfernog May 24, 2023
9e8386b
update api example
lucasfernog May 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1802,6 +1823,7 @@
"print": false,
"requestUserAttention": false,
"setAlwaysOnTop": false,
"setClosable": false,
"setContentProtected": false,
"setCursorGrab": false,
"setCursorIcon": false,
Expand All @@ -1813,7 +1835,9 @@
"setIcon": false,
"setIgnoreCursorEvents": false,
"setMaxSize": false,
"setMaximizable": false,
"setMinSize": false,
"setMinimizable": false,
"setPosition": false,
"setResizable": false,
"setSize": false,
Expand Down Expand Up @@ -2110,6 +2134,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