fix(app): toast windows resize cleanly on hover
GPUI drops the resize report that SetWindowPos triggers while the app is borrowed, so a hovered toast drew at its old size: white area below, action row cut off, hover never ended. Report the new bounds after each placement. Windows also adds a caption frame to GPUI's style-0 popups, which ate 16 px width and 8 px height. Toast windows are WS_POPUP now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -35,6 +35,16 @@ struct OpenWindow {
35
35
mention: bool,
36
36
}
37
37
38
impl OpenWindow {
39
fn place(&self, native: NativeHandle, slot: Slot, x: i32, cx: &mut App) {
40
platform::place(native, x, slot.y, slot.width, slot.height);
41
// WM_SIZE arrives while the app is borrowed, so GPUI drops its own resize report.
42
self.handle
43
.update(cx, |_, window, cx| window.bounds_changed(cx))
44
.ok();
45
}
46
}
47
38
48
pub struct NotificationCenter {
39
49
app: Entity<AppState>,
40
50
main_window: AnyWindowHandle,
@@ -322,7 +332,7 @@ impl NotificationCenter {
322
332
if let Some(window) = self.windows.get_mut(&id)
323
333
&& let Some(native) = window.native
324
334
{
325
platform::place(native, slot.x + offset, slot.y, slot.width, slot.height);
335
window.place(native, slot, slot.x + offset, cx);
326
336
if window.mention != mention {
327
337
window.mention = mention;
328
338
platform::set_border_color(native, border_color(mention));
@@ -382,8 +392,10 @@ impl NotificationCenter {
382
392
},
383
393
);
384
394
}
385
if let Some(native) = self.pill.as_ref().and_then(|pill| pill.native) {
386
platform::place(native, slot.x, slot.y, slot.width, slot.height);
395
if let Some(pill) = self.pill.as_ref()
396
&& let Some(native) = pill.native
397
{
398
pill.place(native, slot, slot.x, cx);
387
399
}
388
400
}
389
401
@@ -35,6 +35,16 @@ struct OpenWindow {35
mention: bool,35
mention: bool,36
}36
}37
37
38
impl OpenWindow {39
fn place(&self, native: NativeHandle, slot: Slot, x: i32, cx: &mut App) {40
platform::place(native, x, slot.y, slot.width, slot.height);41
// WM_SIZE arrives while the app is borrowed, so GPUI drops its own resize report.42
self.handle43
.update(cx, |_, window, cx| window.bounds_changed(cx))44
.ok();45
}46
}47
38
pub struct NotificationCenter {48
pub struct NotificationCenter {39
app: Entity<AppState>,49
app: Entity<AppState>,40
main_window: AnyWindowHandle,50
main_window: AnyWindowHandle,@@ -322,7 +332,7 @@ impl NotificationCenter {322
if let Some(window) = self.windows.get_mut(&id)332
if let Some(window) = self.windows.get_mut(&id)323
&& let Some(native) = window.native333
&& let Some(native) = window.native324
{334
{325
platform::place(native, slot.x + offset, slot.y, slot.width, slot.height);335
window.place(native, slot, slot.x + offset, cx);326
if window.mention != mention {336
if window.mention != mention {327
window.mention = mention;337
window.mention = mention;328
platform::set_border_color(native, border_color(mention));338
platform::set_border_color(native, border_color(mention));@@ -382,8 +392,10 @@ impl NotificationCenter {382
},392
},383
);393
);384
}394
}385
if let Some(native) = self.pill.as_ref().and_then(|pill| pill.native) {395
if let Some(pill) = self.pill.as_ref()386
platform::place(native, slot.x, slot.y, slot.width, slot.height);396
&& let Some(native) = pill.native397
{398
pill.place(native, slot, slot.x, cx);387
}399
}388
}400
}389
401
@@ -20,9 +20,10 @@ use windows::Win32::UI::Shell::{
20
20
SHQueryUserNotificationState, TaskbarList,
21
21
};
22
22
use windows::Win32::UI::WindowsAndMessaging::{
23
CreateIconIndirect, DestroyIcon, FLASHW_ALL, FLASHWINFO, FlashWindowEx, GWL_EXSTYLE,
23
CreateIconIndirect, DestroyIcon, FLASHW_ALL, FLASHWINFO, FlashWindowEx, GWL_EXSTYLE, GWL_STYLE,
24
24
GetWindowLongPtrW, HICON, HWND_TOPMOST, ICONINFO, IsIconic, SW_HIDE, SW_RESTORE, SW_SHOW, SWP_NOACTIVATE,
25
SPI_GETCLIENTAREAANIMATION, SWP_NOOWNERZORDER, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow,
25
SPI_GETCLIENTAREAANIMATION, SWP_FRAMECHANGED, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,
26
SWP_NOZORDER, WS_CAPTION, WS_POPUP, WS_THICKFRAME, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow,
26
27
SetWindowLongPtrW, SetWindowPos, ShowWindow, SystemParametersInfoW,
27
28
WS_EX_NOACTIVATE,
28
29
};
@@ -51,6 +52,23 @@ pub fn native_handle(window: &Window) -> Option<NativeHandle> {
51
52
52
53
pub fn prepare_toast_window(handle: NativeHandle) {
53
54
unsafe {
55
// GPUI creates popups with style 0, and Windows adds a caption frame to that on its own.
56
let frame = (WS_CAPTION | WS_THICKFRAME).0 as isize;
57
let style = GetWindowLongPtrW(hwnd(handle), GWL_STYLE);
58
SetWindowLongPtrW(
59
hwnd(handle),
60
GWL_STYLE,
61
(style & !frame) | WS_POPUP.0 as isize,
62
);
63
let _ = SetWindowPos(
64
hwnd(handle),
65
None,
66
0,
67
0,
68
0,
69
0,
70
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE,
71
);
54
72
let style = GetWindowLongPtrW(hwnd(handle), GWL_EXSTYLE);
55
73
SetWindowLongPtrW(
56
74
hwnd(handle),
@@ -20,9 +20,10 @@ use windows::Win32::UI::Shell::{20
SHQueryUserNotificationState, TaskbarList,20
SHQueryUserNotificationState, TaskbarList,21
};21
};22
use windows::Win32::UI::WindowsAndMessaging::{22
use windows::Win32::UI::WindowsAndMessaging::{23
CreateIconIndirect, DestroyIcon, FLASHW_ALL, FLASHWINFO, FlashWindowEx, GWL_EXSTYLE,23
CreateIconIndirect, DestroyIcon, FLASHW_ALL, FLASHWINFO, FlashWindowEx, GWL_EXSTYLE, GWL_STYLE,24
GetWindowLongPtrW, HICON, HWND_TOPMOST, ICONINFO, IsIconic, SW_HIDE, SW_RESTORE, SW_SHOW, SWP_NOACTIVATE,24
GetWindowLongPtrW, HICON, HWND_TOPMOST, ICONINFO, IsIconic, SW_HIDE, SW_RESTORE, SW_SHOW, SWP_NOACTIVATE,25
SPI_GETCLIENTAREAANIMATION, SWP_NOOWNERZORDER, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow,25
SPI_GETCLIENTAREAANIMATION, SWP_FRAMECHANGED, SWP_NOMOVE, SWP_NOOWNERZORDER, SWP_NOSIZE,26
SWP_NOZORDER, WS_CAPTION, WS_POPUP, WS_THICKFRAME, SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS, SetForegroundWindow,26
SetWindowLongPtrW, SetWindowPos, ShowWindow, SystemParametersInfoW,27
SetWindowLongPtrW, SetWindowPos, ShowWindow, SystemParametersInfoW,27
WS_EX_NOACTIVATE,28
WS_EX_NOACTIVATE,28
};29
};@@ -51,6 +52,23 @@ pub fn native_handle(window: &Window) -> Option<NativeHandle> {51
52
52
pub fn prepare_toast_window(handle: NativeHandle) {53
pub fn prepare_toast_window(handle: NativeHandle) {53
unsafe {54
unsafe {55
// GPUI creates popups with style 0, and Windows adds a caption frame to that on its own.56
let frame = (WS_CAPTION | WS_THICKFRAME).0 as isize;57
let style = GetWindowLongPtrW(hwnd(handle), GWL_STYLE);58
SetWindowLongPtrW(59
hwnd(handle),60
GWL_STYLE,61
(style & !frame) | WS_POPUP.0 as isize,62
);63
let _ = SetWindowPos(64
hwnd(handle),65
None,66
0,67
0,68
0,69
0,70
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE,71
);54
let style = GetWindowLongPtrW(hwnd(handle), GWL_EXSTYLE);72
let style = GetWindowLongPtrW(hwnd(handle), GWL_EXSTYLE);55
SetWindowLongPtrW(73
SetWindowLongPtrW(56
hwnd(handle),74
hwnd(handle),