Skip to content

Commit c4d6fb4

Browse files
TDiblikamrbashirlucasfernog
authored
feat(core): Ability to disable minimize/maximize/close native window's buttons, closes #2353 (#6665)
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com> Co-authored-by: Lucas Nogueira <lucas@tauri.studio> Co-authored-by: Lucas Nogueira <lucas@tauri.app>
1 parent 65fd674 commit c4d6fb4

25 files changed

+744
-53
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tauri-apps/api': 'minor:feat'
3+
---
4+
5+
Added the `maximizable`, `minimizable` and `closable` fields on `WindowOptions`.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tauri-apps/api': 'minor:feat'
3+
---
4+
5+
Added the `setMaximizable`, `setMinimizable`, `setClosable`, `isMaximizable`, `isMinimizable` and `isClosable` methods.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-utils': 'minor:feat'
3+
---
4+
5+
Added the `maximizable`, `minimizable` and `closable` options to the window configuration.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri-runtime-wry': 'minor:feat'
3+
'tauri-runtime': 'minor:feat'
4+
---
5+
6+
Added the `maximizable`, `minimizable` and `closable` methods to `WindowBuilder`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri-runtime-wry': 'minor:feat'
3+
'tauri-runtime': 'minor:feat'
4+
---
5+
6+
Added `set_maximizable`, `set_minimizable`, `set_closable`, `is_maximizable`, `is_minimizable` and `is_closable` methods to the `Dispatch` trait.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'minor:feat'
3+
---
4+
5+
Added the `maximizable`, `minimizable` and `closable` options to the window builder.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'minor:feat'
3+
---
4+
5+
Added the `set_maximizable`, `set_minimizable`, `set_closable`, `is_maximizable`, `is_minimizable` and `is_closable` methods on `Window`.

core/tauri-config-schema/schema.json

+40-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"print": false,
106106
"requestUserAttention": false,
107107
"setAlwaysOnTop": false,
108+
"setClosable": false,
108109
"setContentProtected": false,
109110
"setCursorGrab": false,
110111
"setCursorIcon": false,
@@ -116,7 +117,9 @@
116117
"setIcon": false,
117118
"setIgnoreCursorEvents": false,
118119
"setMaxSize": false,
120+
"setMaximizable": false,
119121
"setMinSize": false,
122+
"setMinimizable": false,
120123
"setPosition": false,
121124
"setResizable": false,
122125
"setSize": false,
@@ -383,6 +386,7 @@
383386
"print": false,
384387
"requestUserAttention": false,
385388
"setAlwaysOnTop": false,
389+
"setClosable": false,
386390
"setContentProtected": false,
387391
"setCursorGrab": false,
388392
"setCursorIcon": false,
@@ -394,7 +398,9 @@
394398
"setIcon": false,
395399
"setIgnoreCursorEvents": false,
396400
"setMaxSize": false,
401+
"setMaximizable": false,
397402
"setMinSize": false,
403+
"setMinimizable": false,
398404
"setPosition": false,
399405
"setResizable": false,
400406
"setSize": false,
@@ -605,7 +611,22 @@
605611
"format": "double"
606612
},
607613
"resizable": {
608-
"description": "Whether the window is resizable or not.",
614+
"description": "Whether the window is resizable or not. When resizable is set to false, native window's maximize button is automatically disabled.",
615+
"default": true,
616+
"type": "boolean"
617+
},
618+
"maximizable": {
619+
"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.",
620+
"default": true,
621+
"type": "boolean"
622+
},
623+
"minimizable": {
624+
"description": "Whether the window's native minimize button is enabled or not.\n\n## Platform-specific\n\n- **Linux / iOS / Android:** Unsupported.",
625+
"default": true,
626+
"type": "boolean"
627+
},
628+
"closable": {
629+
"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.",
609630
"default": true,
610631
"type": "boolean"
611632
},
@@ -1809,6 +1830,7 @@
18091830
"print": false,
18101831
"requestUserAttention": false,
18111832
"setAlwaysOnTop": false,
1833+
"setClosable": false,
18121834
"setContentProtected": false,
18131835
"setCursorGrab": false,
18141836
"setCursorIcon": false,
@@ -1820,7 +1842,9 @@
18201842
"setIcon": false,
18211843
"setIgnoreCursorEvents": false,
18221844
"setMaxSize": false,
1845+
"setMaximizable": false,
18231846
"setMinSize": false,
1847+
"setMinimizable": false,
18241848
"setPosition": false,
18251849
"setResizable": false,
18261850
"setSize": false,
@@ -2117,6 +2141,21 @@
21172141
"default": false,
21182142
"type": "boolean"
21192143
},
2144+
"setMaximizable": {
2145+
"description": "Allows setting whether the window's native maximize button is enabled or not.",
2146+
"default": false,
2147+
"type": "boolean"
2148+
},
2149+
"setMinimizable": {
2150+
"description": "Allows setting whether the window's native minimize button is enabled or not.",
2151+
"default": false,
2152+
"type": "boolean"
2153+
},
2154+
"setClosable": {
2155+
"description": "Allows setting whether the window's native close button is enabled or not.",
2156+
"default": false,
2157+
"type": "boolean"
2158+
},
21202159
"setTitle": {
21212160
"description": "Allows changing the window title.",
21222161
"default": false,

core/tauri-runtime-wry/src/lib.rs

+66
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,9 @@ impl WindowBuilder for WindowBuilderWrapper {
717717
.inner_size(config.width, config.height)
718718
.visible(config.visible)
719719
.resizable(config.resizable)
720+
.maximizable(config.maximizable)
721+
.minimizable(config.minimizable)
722+
.closable(config.closable)
720723
.fullscreen(config.fullscreen)
721724
.decorations(config.decorations)
722725
.maximized(config.maximized)
@@ -815,6 +818,21 @@ impl WindowBuilder for WindowBuilderWrapper {
815818
self
816819
}
817820

821+
fn maximizable(mut self, maximizable: bool) -> Self {
822+
self.inner = self.inner.with_maximizable(maximizable);
823+
self
824+
}
825+
826+
fn minimizable(mut self, minimizable: bool) -> Self {
827+
self.inner = self.inner.with_minimizable(minimizable);
828+
self
829+
}
830+
831+
fn closable(mut self, closable: bool) -> Self {
832+
self.inner = self.inner.with_closable(closable);
833+
self
834+
}
835+
818836
fn title<S: Into<String>>(mut self, title: S) -> Self {
819837
self.inner = self.inner.with_title(title.into());
820838
self
@@ -1056,6 +1074,9 @@ pub enum WindowMessage {
10561074
IsMaximized(Sender<bool>),
10571075
IsDecorated(Sender<bool>),
10581076
IsResizable(Sender<bool>),
1077+
IsMaximizable(Sender<bool>),
1078+
IsMinimizable(Sender<bool>),
1079+
IsClosable(Sender<bool>),
10591080
IsVisible(Sender<bool>),
10601081
Title(Sender<String>),
10611082
IsMenuVisible(Sender<bool>),
@@ -1076,6 +1097,9 @@ pub enum WindowMessage {
10761097
Center,
10771098
RequestUserAttention(Option<UserAttentionTypeWrapper>),
10781099
SetResizable(bool),
1100+
SetMaximizable(bool),
1101+
SetMinimizable(bool),
1102+
SetClosable(bool),
10791103
SetTitle(String),
10801104
Maximize,
10811105
Unmaximize,
@@ -1294,6 +1318,21 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
12941318
window_getter!(self, WindowMessage::IsResizable)
12951319
}
12961320

1321+
/// Gets the current native window's maximize button state
1322+
fn is_maximizable(&self) -> Result<bool> {
1323+
window_getter!(self, WindowMessage::IsMaximizable)
1324+
}
1325+
1326+
/// Gets the current native window's minimize button state
1327+
fn is_minimizable(&self) -> Result<bool> {
1328+
window_getter!(self, WindowMessage::IsMinimizable)
1329+
}
1330+
1331+
/// Gets the current native window's close button state
1332+
fn is_closable(&self) -> Result<bool> {
1333+
window_getter!(self, WindowMessage::IsClosable)
1334+
}
1335+
12971336
fn is_visible(&self) -> Result<bool> {
12981337
window_getter!(self, WindowMessage::IsVisible)
12991338
}
@@ -1385,6 +1424,27 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
13851424
)
13861425
}
13871426

1427+
fn set_maximizable(&self, maximizable: bool) -> Result<()> {
1428+
send_user_message(
1429+
&self.context,
1430+
Message::Window(self.window_id, WindowMessage::SetMaximizable(maximizable)),
1431+
)
1432+
}
1433+
1434+
fn set_minimizable(&self, minimizable: bool) -> Result<()> {
1435+
send_user_message(
1436+
&self.context,
1437+
Message::Window(self.window_id, WindowMessage::SetMinimizable(minimizable)),
1438+
)
1439+
}
1440+
1441+
fn set_closable(&self, closable: bool) -> Result<()> {
1442+
send_user_message(
1443+
&self.context,
1444+
Message::Window(self.window_id, WindowMessage::SetClosable(closable)),
1445+
)
1446+
}
1447+
13881448
fn set_title<S: Into<String>>(&self, title: S) -> Result<()> {
13891449
send_user_message(
13901450
&self.context,
@@ -2409,6 +2469,9 @@ fn handle_user_message<T: UserEvent>(
24092469
WindowMessage::IsMaximized(tx) => tx.send(window.is_maximized()).unwrap(),
24102470
WindowMessage::IsDecorated(tx) => tx.send(window.is_decorated()).unwrap(),
24112471
WindowMessage::IsResizable(tx) => tx.send(window.is_resizable()).unwrap(),
2472+
WindowMessage::IsMaximizable(tx) => tx.send(window.is_maximizable()).unwrap(),
2473+
WindowMessage::IsMinimizable(tx) => tx.send(window.is_minimizable()).unwrap(),
2474+
WindowMessage::IsClosable(tx) => tx.send(window.is_closable()).unwrap(),
24122475
WindowMessage::IsVisible(tx) => tx.send(window.is_visible()).unwrap(),
24132476
WindowMessage::Title(tx) => tx.send(window.title()).unwrap(),
24142477
WindowMessage::IsMenuVisible(tx) => tx.send(window.is_menu_visible()).unwrap(),
@@ -2441,6 +2504,9 @@ fn handle_user_message<T: UserEvent>(
24412504
window.request_user_attention(request_type.map(|r| r.0));
24422505
}
24432506
WindowMessage::SetResizable(resizable) => window.set_resizable(resizable),
2507+
WindowMessage::SetMaximizable(maximizable) => window.set_maximizable(maximizable),
2508+
WindowMessage::SetMinimizable(minimizable) => window.set_minimizable(minimizable),
2509+
WindowMessage::SetClosable(closable) => window.set_closable(closable),
24442510
WindowMessage::SetTitle(title) => window.set_title(&title),
24452511
WindowMessage::Maximize => window.set_maximized(true),
24462512
WindowMessage::Unmaximize => window.set_maximized(false),

core/tauri-runtime/src/lib.rs

+45
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,27 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
582582
/// Gets the window’s current resizable state.
583583
fn is_resizable(&self) -> Result<bool>;
584584

585+
/// Gets the window's native maximize button state.
586+
///
587+
/// ## Platform-specific
588+
///
589+
/// - **Linux / iOS / Android:** Unsupported.
590+
fn is_maximizable(&self) -> Result<bool>;
591+
592+
/// Gets the window's native minize button state.
593+
///
594+
/// ## Platform-specific
595+
///
596+
/// - **Linux / iOS / Android:** Unsupported.
597+
fn is_minimizable(&self) -> Result<bool>;
598+
599+
/// Gets the window's native close button state.
600+
///
601+
/// ## Platform-specific
602+
///
603+
/// - **iOS / Android:** Unsupported.
604+
fn is_closable(&self) -> Result<bool>;
605+
585606
/// Gets the window's current visibility state.
586607
fn is_visible(&self) -> Result<bool>;
587608
/// Gets the window's current title.
@@ -640,6 +661,30 @@ pub trait Dispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'static
640661
/// Updates the window resizable flag.
641662
fn set_resizable(&self, resizable: bool) -> Result<()>;
642663

664+
/// Updates the window's native maximize button state.
665+
///
666+
/// ## Platform-specific
667+
///
668+
/// - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
669+
/// - **Linux / iOS / Android:** Unsupported.
670+
fn set_maximizable(&self, maximizable: bool) -> Result<()>;
671+
672+
/// Updates the window's native minimize button state.
673+
///
674+
/// ## Platform-specific
675+
///
676+
/// - **Linux / iOS / Android:** Unsupported.
677+
fn set_minimizable(&self, minimizable: bool) -> Result<()>;
678+
679+
/// Updates the window's native close button state.
680+
///
681+
/// ## Platform-specific
682+
///
683+
/// - **Linux:** "GTK+ will do its best to convince the window manager not to show a close button.
684+
/// Depending on the system, this function may not have any effect when called on a window that is already visible"
685+
/// - **iOS / Android:** Unsupported.
686+
fn set_closable(&self, closable: bool) -> Result<()>;
687+
643688
/// Updates the window title.
644689
fn set_title<S: Into<String>>(&self, title: S) -> Result<()>;
645690

core/tauri-runtime/src/webview.rs

+29
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,38 @@ pub trait WindowBuilder: WindowBuilderBase {
157157
fn max_inner_size(self, max_width: f64, max_height: f64) -> Self;
158158

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

164+
/// Whether the window's native maximize button is enabled or not.
165+
/// If resizable is set to false, this setting is ignored.
166+
///
167+
/// ## Platform-specific
168+
///
169+
/// - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
170+
/// - **Linux / iOS / Android:** Unsupported.
171+
#[must_use]
172+
fn maximizable(self, maximizable: bool) -> Self;
173+
174+
/// Whether the window's native minimize button is enabled or not.
175+
///
176+
/// ## Platform-specific
177+
///
178+
/// - **Linux / iOS / Android:** Unsupported.
179+
#[must_use]
180+
fn minimizable(self, minimizable: bool) -> Self;
181+
182+
/// Whether the window's native close button is enabled or not.
183+
///
184+
/// ## Platform-specific
185+
///
186+
/// - **Linux:** "GTK+ will do its best to convince the window manager not to show a close button.
187+
/// Depending on the system, this function may not have any effect when called on a window that is already visible"
188+
/// - **iOS / Android:** Unsupported.
189+
#[must_use]
190+
fn closable(self, closable: bool) -> Self;
191+
163192
/// The title of the window in the title bar.
164193
#[must_use]
165194
fn title<S: Into<String>>(self, title: S) -> Self;

0 commit comments

Comments
 (0)