Skip to content

Commit f29b788

Browse files
authored
fix(core/wry): implement resizing natively on Windows (#9862)
closes #7388 closes #9510 closes #9464 ref #9268 ref #9053 ref #8770 ref #8750 ref #4012
1 parent fafc238 commit f29b788

File tree

3 files changed

+313
-154
lines changed

3 files changed

+313
-154
lines changed

.changes/undecorated-resizing.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"tauri": "patch:bug"
3+
"tauri-runtime-wry": "patch:bug"
4+
---
5+
6+
On Windows, handle resizing undecorated windows natively which improves performance and fixes a couple of annoyances with previous JS implementation:
7+
- No more cursor flickering when moving the cursor across an edge.
8+
- Can resize from top even when `data-tauri-drag-region` element exists there.
9+
- Upon starting rezing, clicks don't go through elements behind it so no longer accidental clicks.
10+

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

+20-34
Original file line numberDiff line numberDiff line change
@@ -1988,8 +1988,6 @@ pub struct WindowWrapper {
19881988
webviews: Vec<WebviewWrapper>,
19891989
window_event_listeners: WindowEventListeners,
19901990
#[cfg(windows)]
1991-
is_window_fullscreen: bool,
1992-
#[cfg(windows)]
19931991
is_window_transparent: bool,
19941992
#[cfg(windows)]
19951993
surface: Option<softbuffer::Surface<Arc<Window>, Arc<Window>>>,
@@ -2773,7 +2771,15 @@ fn handle_user_message<T: UserEvent>(
27732771
WindowMessage::Destroy => {
27742772
panic!("cannot handle `WindowMessage::Destroy` on the main thread")
27752773
}
2776-
WindowMessage::SetDecorations(decorations) => window.set_decorations(decorations),
2774+
WindowMessage::SetDecorations(decorations) => {
2775+
window.set_decorations(decorations);
2776+
#[cfg(windows)]
2777+
if decorations {
2778+
undecorated_resizing::detach_resize_handler(window.hwnd());
2779+
} else {
2780+
undecorated_resizing::attach_resize_handler(window.hwnd());
2781+
}
2782+
}
27772783
WindowMessage::SetShadow(_enable) => {
27782784
#[cfg(windows)]
27792785
window.set_undecorated_shadow(_enable);
@@ -2806,10 +2812,6 @@ fn handle_user_message<T: UserEvent>(
28062812
} else {
28072813
window.set_fullscreen(None)
28082814
}
2809-
#[cfg(windows)]
2810-
if let Some(w) = windows.0.borrow_mut().get_mut(&id) {
2811-
w.is_window_fullscreen = fullscreen;
2812-
}
28132815
}
28142816
WindowMessage::SetFocus => {
28152817
window.set_focus();
@@ -3197,8 +3199,6 @@ fn handle_user_message<T: UserEvent>(
31973199
Message::CreateRawWindow(window_id, handler, sender) => {
31983200
let (label, builder) = handler();
31993201

3200-
#[cfg(windows)]
3201-
let is_window_fullscreen = builder.window.fullscreen.is_some();
32023202
#[cfg(windows)]
32033203
let is_window_transparent = builder.window.transparent;
32043204

@@ -3232,8 +3232,6 @@ fn handle_user_message<T: UserEvent>(
32323232
window_event_listeners: Default::default(),
32333233
webviews: Vec::new(),
32343234
#[cfg(windows)]
3235-
is_window_fullscreen,
3236-
#[cfg(windows)]
32373235
is_window_transparent,
32383236
#[cfg(windows)]
32393237
surface,
@@ -3577,8 +3575,6 @@ fn create_window<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(
35773575

35783576
#[cfg(windows)]
35793577
let is_window_transparent = window_builder.inner.window.transparent;
3580-
#[cfg(windows)]
3581-
let is_window_fullscreen = window_builder.inner.window.fullscreen.is_some();
35823578

35833579
#[cfg(target_os = "macos")]
35843580
{
@@ -3727,8 +3723,6 @@ fn create_window<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(
37273723
webviews,
37283724
window_event_listeners,
37293725
#[cfg(windows)]
3730-
is_window_fullscreen,
3731-
#[cfg(windows)]
37323726
is_window_transparent,
37333727
#[cfg(windows)]
37343728
surface,
@@ -3818,11 +3812,6 @@ fn create_webview<T: UserEvent>(
38183812
.with_accept_first_mouse(webview_attributes.accept_first_mouse)
38193813
.with_hotkeys_zoom(webview_attributes.zoom_hotkeys_enabled);
38203814

3821-
#[cfg(windows)]
3822-
if kind == WebviewKind::WindowContent {
3823-
webview_builder = webview_builder.with_initialization_script(undecorated_resizing::SCRIPT);
3824-
}
3825-
38263815
if webview_attributes.drag_drop_handler_enabled {
38273816
let proxy = context.proxy.clone();
38283817
let window_id_ = window_id.clone();
@@ -4054,15 +4043,19 @@ fn create_webview<T: UserEvent>(
40544043
.build()
40554044
.map_err(|e| Error::CreateWebview(Box::new(e)))?;
40564045

4057-
#[cfg(any(
4058-
target_os = "linux",
4059-
target_os = "dragonfly",
4060-
target_os = "freebsd",
4061-
target_os = "netbsd",
4062-
target_os = "openbsd"
4063-
))]
40644046
if kind == WebviewKind::WindowContent {
4047+
#[cfg(any(
4048+
target_os = "linux",
4049+
target_os = "dragonfly",
4050+
target_os = "freebsd",
4051+
target_os = "netbsd",
4052+
target_os = "openbsd"
4053+
))]
40654054
undecorated_resizing::attach_resize_handler(&webview);
4055+
#[cfg(windows)]
4056+
if window.is_resizable() && !window.is_decorated() {
4057+
undecorated_resizing::attach_resize_handler(window.hwnd());
4058+
}
40664059
}
40674060

40684061
#[cfg(windows)]
@@ -4127,13 +4120,6 @@ fn create_ipc_handler<T: UserEvent>(
41274120
ipc_handler: Option<WebviewIpcHandler<T, Wry<T>>>,
41284121
) -> Box<IpcHandler> {
41294122
Box::new(move |request| {
4130-
#[cfg(windows)]
4131-
if _kind == WebviewKind::WindowContent
4132-
&& undecorated_resizing::handle_request(context.clone(), *window_id.lock().unwrap(), &request)
4133-
{
4134-
return;
4135-
}
4136-
41374123
if let Some(handler) = &ipc_handler {
41384124
handler(
41394125
DetachedWebview {

0 commit comments

Comments
 (0)