-
-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add reparent function * remove mut * windows and linux impl * update change file * Discard changes to examples/simple.rs * remove ns_window field --------- Co-authored-by: Lucas Nogueira <[email protected]>
- Loading branch information
1 parent
e2542de
commit e50ce47
Showing
6 changed files
with
182 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wry": minor | ||
--- | ||
|
||
Added `WebViewExtMacOS::reparent`,`WebViewExtWindows::reparent` and `WebViewExtUnix::reparent`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright 2020-2023 Tauri Programme within The Commons Conservancy | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-License-Identifier: MIT | ||
|
||
use tao::{ | ||
event::{ElementState, Event, KeyEvent, WindowEvent}, | ||
event_loop::{ControlFlow, EventLoop}, | ||
keyboard::Key, | ||
window::WindowBuilder, | ||
}; | ||
use wry::WebViewBuilder; | ||
|
||
#[cfg(target_os = "macos")] | ||
use {tao::platform::macos::WindowExtMacOS, wry::WebViewExtMacOS}; | ||
#[cfg(target_os = "windows")] | ||
use {tao::platform::windows::WindowExtWindows, wry::WebViewExtWindows}; | ||
|
||
#[cfg(not(any( | ||
target_os = "windows", | ||
target_os = "macos", | ||
target_os = "ios", | ||
target_os = "android" | ||
)))] | ||
#[cfg(not(any( | ||
target_os = "windows", | ||
target_os = "macos", | ||
target_os = "ios", | ||
target_os = "android" | ||
)))] | ||
use { | ||
tao::platform::unix::WindowExtUnix, | ||
wry::{WebViewBuilderExtUnix, WebViewExtUnix}, | ||
}; | ||
|
||
fn main() -> wry::Result<()> { | ||
let event_loop = EventLoop::new(); | ||
let window = WindowBuilder::new().build(&event_loop).unwrap(); | ||
let window2 = WindowBuilder::new().build(&event_loop).unwrap(); | ||
|
||
#[cfg(any( | ||
target_os = "windows", | ||
target_os = "macos", | ||
target_os = "ios", | ||
target_os = "android" | ||
))] | ||
let builder = WebViewBuilder::new(&window); | ||
|
||
#[cfg(not(any( | ||
target_os = "windows", | ||
target_os = "macos", | ||
target_os = "ios", | ||
target_os = "android" | ||
)))] | ||
let builder = { | ||
let vbox = window.default_vbox().unwrap(); | ||
WebViewBuilder::new_gtk(vbox) | ||
}; | ||
|
||
let webview = builder.with_url("https://tauri.app")?.build()?; | ||
|
||
let mut webview_container = window.id(); | ||
|
||
event_loop.run(move |event, _event_loop, control_flow| { | ||
*control_flow = ControlFlow::Wait; | ||
|
||
match event { | ||
Event::WindowEvent { | ||
event: WindowEvent::CloseRequested, | ||
.. | ||
} => *control_flow = ControlFlow::Exit, | ||
|
||
Event::WindowEvent { | ||
event: | ||
WindowEvent::KeyboardInput { | ||
event: | ||
KeyEvent { | ||
logical_key: Key::Character("x"), | ||
state: ElementState::Pressed, | ||
.. | ||
}, | ||
.. | ||
}, | ||
.. | ||
} => { | ||
let new_parent = if webview_container == window.id() { | ||
&window2 | ||
} else { | ||
&window | ||
}; | ||
webview_container = new_parent.id(); | ||
|
||
#[cfg(target_os = "macos")] | ||
webview.reparent(new_parent.ns_window() as cocoa::base::id); | ||
#[cfg(not(any( | ||
target_os = "windows", | ||
target_os = "macos", | ||
target_os = "ios", | ||
target_os = "android" | ||
)))] | ||
webview.reparent(new_parent.default_vbox().unwrap()); | ||
#[cfg(target_os = "windows")] | ||
webview.reparent(new_parent.hwnd()); | ||
} | ||
_ => {} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters