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 16 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/maximizability-minimizability-closability-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-utils': minor
---

Added the [`maximizable`, `minimizable`, `closable`] options to the window configuration.
14 changes: 14 additions & 0 deletions .changes/maximizability-minimizability-closability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'api': minor
'tauri': minor
'tauri-runtime-wry': minor
'tauri-runtime': minor
'tauri-utils': minor
---

- Added the [`maximizable`, `minimizable`, `closable`] options to the window builder.
- Exposed the [`set_maximizable`, `set_minimizable`, `set_closable`] setter functions to the window api.
- Exposed the [`is_maximizable`, `is_minimizable`, `is_closable`] getter functions to the window api.
- Exposed the [`setMaximizable`, `setMinimizable`, `setClosable`] setter functions to the typescript window api.
- Exposed the [`isMaximizable`, `isMinimizable`, `isClosable`] getter functions to the typescript window api.
- Added the [`window-set-maximizable`, `window-set-minimizable`, `window-set-closable`] feature flags.
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 @@ -382,6 +385,7 @@
"print": false,
"requestUserAttention": false,
"setAlwaysOnTop": false,
"setClosable": false,
"setContentProtected": false,
"setCursorGrab": false,
"setCursorIcon": false,
Expand All @@ -393,7 +397,9 @@
"setIcon": false,
"setIgnoreCursorEvents": false,
"setMaxSize": false,
"setMaximizable": false,
"setMinSize": false,
"setMinimizable": false,
"setPosition": false,
"setResizable": false,
"setSize": false,
Expand Down Expand Up @@ -603,7 +609,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. Note that this setting is not supported on Linux, iOS and Android.",
"default": true,
"type": "boolean"
},
"minimizable": {
"description": "Whether the window's native minimize button is enabled or not. Note that this setting is not supported on Linux, iOS and Android.",
"default": true,
"type": "boolean"
},
"closable": {
"description": "Whether the window's native close button is enabled or not. Note that this setting is not supported on Linux, iOS and Android.",
"default": true,
"type": "boolean"
},
Expand Down Expand Up @@ -1783,6 +1804,7 @@
"print": false,
"requestUserAttention": false,
"setAlwaysOnTop": false,
"setClosable": false,
"setContentProtected": false,
"setCursorGrab": false,
"setCursorIcon": false,
Expand All @@ -1794,7 +1816,9 @@
"setIcon": false,
"setIgnoreCursorEvents": false,
"setMaxSize": false,
"setMaximizable": false,
"setMinSize": false,
"setMinimizable": false,
"setPosition": false,
"setResizable": false,
"setSize": false,
Expand Down Expand Up @@ -2084,6 +2108,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 @@ -716,6 +716,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 @@ -814,6 +817,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 @@ -1055,6 +1073,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 @@ -1075,6 +1096,9 @@ pub enum WindowMessage {
Center,
RequestUserAttention(Option<UserAttentionTypeWrapper>),
SetResizable(bool),
SetMaximizable(bool),
SetMinimizable(bool),
SetClosable(bool),
SetTitle(String),
Maximize,
Unmaximize,
Expand Down Expand Up @@ -1293,6 +1317,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 @@ -1384,6 +1423,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 @@ -2408,6 +2468,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 @@ -2440,6 +2503,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 by calling into tao.
///
/// ## 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 by calling into tao.
///
/// ## Platform-specific
///
/// - **Linux / iOS / Android:** Unsupported.
fn set_minimizable(&self, minimizable: bool) -> Result<()>;

/// Updates the window's native close button state by calling into tao.
///
/// ## 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
26 changes: 26 additions & 0 deletions core/tauri-runtime/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,35 @@ 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.
///
/// See [`Dispatch::set_maximizable`] for details.
///
/// [`Dispatch::set_maximizable`]: crate::Dispatch::set_maximizable
amrbashir marked this conversation as resolved.
Show resolved Hide resolved
#[must_use]
fn maximizable(self, maximizable: bool) -> Self;

/// Whether the window's native minimize button is enabled or not.
///
/// See [`Dispatch::set_minimizable`] for details.
///
/// [`Dispatch::set_minimizable`]: crate::Dispatch::set_minimizable
#[must_use]
fn minimizable(self, minimizable: bool) -> Self;

/// Whether the window's native close button is enabled or not.
///
/// See [`Dispatch::set_closable`] for details.
///
/// [`Dispatch::set_closable`]: crate::Dispatch::set_closable
#[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