Skip to content

Commit 9eaeb5a

Browse files
refactor: refactor parent APIs on WindowBuilder (#8622)
* refactor: refactor parent APIs on `WindowBuilder` closes #8587 #1643 * fix build * clippy * support parent in JS and config * change files * fix build * clippy * fix doctests * fix linux build * fix doctests * update docs * fix api, update example to use JS API * fix merge * lint * fix tests on windows --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent a2fc3a6 commit 9eaeb5a

File tree

28 files changed

+453
-139
lines changed

28 files changed

+453
-139
lines changed

.changes/api-window-parent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tauri-apps/api': 'patch:feat'
3+
---
4+
5+
Add `parent` option when creating a window.

.changes/tauri-parent-owner.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'patch:feat'
3+
---
4+
5+
Add `WindowBuilder::parent` which is a convenient wrapper around parent functionality for Windows, Linux and macOS. Also added `WindowBuilder::owner` on Windows only. Also added `WindowBuilder::transient_for` and `WindowBuilder::transient_for_raw` on Linux only.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'patch:breaking'
3+
---
4+
5+
Renamed `WindowBuilder::owner_window` to `WindowBuilder::owner_raw` and `WindowBuilder::parent_window` to `WindowBuilder::parent_raw`.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri-runtime': 'patch'
3+
'tauri-runtime-wry': 'patch'
4+
---
5+
6+
Added `WindowBuilder::transient_for` and Renamed `WindowBuilder::owner_window` to `WindowBuilder::owner` and `WindowBuilder::parent_window` to `WindowBuilder::parent`.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-utils': 'patch:feat'
3+
---
4+
5+
Add `parent` option for window config.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'patch:breaking'
3+
---
4+
5+
Changed `WindowBuilder::from_config` to return a `Result<Self>`.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'tauri-runtime': 'patch:breaking'
3+
'tauri-runtime-wry': 'patch:breaking'
4+
---
5+
6+
Changed `WindowBuilder::with_config` to take a reference to a `WindowConfig` instead of an owned value.

core/tauri-config-schema/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,13 @@
565565
"description": "Whether or not the webview should be launched in incognito mode.\n\n## Platform-specific:\n\n- **Android**: Unsupported.",
566566
"default": false,
567567
"type": "boolean"
568+
},
569+
"parent": {
570+
"description": "Sets the window associated with this label to be the parent of the window to be created.\n\n## Platform-specific\n\n- **Windows**: This sets the passed parent as an owner window to the window to be created. From [MSDN owned windows docs](https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#owned-windows): - An owned window is always above its owner in the z-order. - The system automatically destroys an owned window when its owner is destroyed. - An owned window is hidden when its owner is minimized. - **Linux**: This makes the new window transient for parent, see <https://docs.gtk.org/gtk3/method.Window.set_transient_for.html> - **macOS**: This adds the window as a child of parent, see <https://developer.apple.com/documentation/appkit/nswindow/1419152-addchildwindow?language=objc>",
571+
"type": [
572+
"string",
573+
"null"
574+
]
568575
}
569576
},
570577
"additionalProperties": false

core/tauri-runtime-wry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ rust-version = { workspace = true }
1414

1515
[dependencies]
1616
wry = { version = "0.35.2", default-features = false, features = [ "file-drop", "protocol", "os-webview" ] }
17-
tao = { version = "0.24", default-features = false, features = [ "rwh_05", "rwh_06" ] }
17+
tao = { git = "https://github.com/tauri-apps/tao", branch = "dev", default-features = false, features = [ "rwh_05", "rwh_06" ] }
1818
tauri-runtime = { version = "1.0.0-alpha.8", path = "../tauri-runtime" }
1919
tauri-utils = { version = "2.0.0-alpha.13", path = "../tauri-utils" }
2020
raw-window-handle = "0.5"

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl WindowBuilder for WindowBuilderWrapper {
679679
Self::default().focused(true)
680680
}
681681

682-
fn with_config(config: WindowConfig) -> Self {
682+
fn with_config(config: &WindowConfig) -> Self {
683683
let mut window = WindowBuilderWrapper::new();
684684

685685
#[cfg(target_os = "macos")]
@@ -878,20 +878,32 @@ impl WindowBuilder for WindowBuilderWrapper {
878878
}
879879

880880
#[cfg(windows)]
881-
fn parent_window(mut self, parent: HWND) -> Self {
881+
fn owner(mut self, owner: HWND) -> Self {
882+
self.inner = self.inner.with_owner_window(owner.0);
883+
self
884+
}
885+
886+
#[cfg(windows)]
887+
fn parent(mut self, parent: HWND) -> Self {
882888
self.inner = self.inner.with_parent_window(parent.0);
883889
self
884890
}
885891

886892
#[cfg(target_os = "macos")]
887-
fn parent_window(mut self, parent: *mut std::ffi::c_void) -> Self {
893+
fn parent(mut self, parent: *mut std::ffi::c_void) -> Self {
888894
self.inner = self.inner.with_parent_window(parent);
889895
self
890896
}
891897

892-
#[cfg(windows)]
893-
fn owner_window(mut self, owner: HWND) -> Self {
894-
self.inner = self.inner.with_owner_window(owner.0);
898+
#[cfg(any(
899+
target_os = "linux",
900+
target_os = "dragonfly",
901+
target_os = "freebsd",
902+
target_os = "netbsd",
903+
target_os = "openbsd"
904+
))]
905+
fn transient_for(mut self, parent: &impl gtk::glib::IsA<gtk::Window>) -> Self {
906+
self.inner = self.inner.with_transient_for(parent);
895907
self
896908
}
897909

0 commit comments

Comments
 (0)