T48: round 2 fix: at a new DPI her corner follows once the move that brought it is done, and only where her box would lie mostly on a display of that DPI; else Windows' rect stands, since between two displays side by side a corner kept always set her DPI back and forth; the tests move beside the module
CI / platforms (windows-latest) (push) Successful in 1m55s
CI / platforms (ubuntu-24.04) (push) Successful in 2m27s
CI / macos (push) Successful in 16m13s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-18 13:16:13 -04:00
1 parent 8ddf470f73
commit f7e5563a71
5 files changed
+357 -211

No files matched your search

+1 -1
View File
@@ -107,4 +107,4 @@ ELYTerminal. A terminal on GPUI and Ely components. `PRD.md` says what it does;
- 2026-10-17: a session posts system notifications through gpui's, which the owner asked for. At start `set_app_identity` names the app: on Windows that sets the process's AppUserModelID, which the taskbar groups its windows by too, so a pin made before may show apart, and the first notification writes the app's name under `HKCU\Software\Classes\AppUserModelId`, as gpui needs for an app without a package; on macOS gpui posts only from the app bundle, asks for leave at the first, and logs once, under the `gpui_macos` target, that it posts nothing outside one; on Linux it posts over D-Bus through notify-rust. Each terminal view posts its own, in the order its output asks, so OSC 99's answers keep their place before a DA1 sent after them: when its row's mark turns to waiting, done or error, at each turn, as the row's waiting mark is set, the hover's line for the record its body; when a command C started ends, `Command finished`, or `Command exited with N`, so a prompt drawn again, as macOS's bash 3.2 draws one with its D at a resize, posts nothing, and bash 3.2, which sends no C, posts no command's end, as Ghostty's integration, which skips it, posts none; and when a program asks through OSC 9, 777 or 99, its title and body the body, each line shown as text. It posts only while its window is not active or it is not the session shown, which the workspace tells it, one every 3 seconds at most, a later one logged and dropped; the title is the program's title, else the app's name, as the row names the session, which the tap reads in the output's order, so a title set before a notification in the same output names it. The session's own share a tag, so a new one takes the old one's place where the system allows, as an OSC 99 id does; OSC 9, 777 and OSC 99 without an id each take their own; a session keeps its last 64. A press goes to the window whose session posted it: it shows the window and the session, unless OSC 99 said `a=-focus`, and tells a program that asked `a=report`, `OSC 99 ; i=ID ;`; a press whose record went, a twin Linux stacked and pressed before or one past the 64 kept, still shows its session and tells no program. macOS brings the app forward at any press, `a=-focus` or not, and on Wayland gpui asks for the window with a serial the compositor likely refuses, so KWin and Mutter mark it as asking for attention instead. gpui hears of no close on any system, so `c=1` hears `p=close;untracked` once posted, and alive lists the ids posted and not yet pressed, closed or expired. On macOS and Windows a close takes the notification back, and `w` over 0 takes it back once it runs out, its session gone or not, unless a later post holds its tag; gpui on Linux closes and replaces none, so there a close and `w` pass by, logged, a closed one stays alive, and an update posts beside the old one. `o` passes by: each notification posts only while unseen, which is kitty's invisible, so the query answers `a=focus,report:o=invisible:p=title,body,close,?,alive:w=1`, on Linux `a=focus,report:o=invisible:p=title,body,?,alive`, never with the `c` that close events would need. Windows' toasts are silent, as macOS's are; on Linux the notification daemon decides, and reads the body as markup, so its `&`, `<` and `>` go as entities.
- 2026-10-18: herdr's shortcuts, which a user found dead, as kitty and Ghostty send them. herdr 0.9.5 asks for kitty's disambiguate, events and alternates on macOS and Linux, and takes `cmd+shift+ctrl+[` as `[` with Shift, Ctrl and Super, `CSI 91;14u`, the symbol as its alternate, `CSI 91:123;14u`, as Ghostty sends it; gpui named the key `{` and cleared Shift, so ELYTerminal sent `CSI 123;13u`, which herdr matches only to `cmd+ctrl+{`. Under kitty's flags a key Shift made a symbol of now goes as its own character with Shift, the symbol its alternate; legacy keys keep fixterms' symbol without Shift, as Ghostty's do. On macOS the key's own character comes from `UCKeyTranslate` on the event's key code, in the layout gpui reads: Command's while Command is down or while the plain one types no ASCII; AppKit's `charactersByApplyingModifiers:` ignores the layout for events built in-process. On Windows herdr asks for no kitty flags and reads the console's key records, and ConPTY asks every terminal for win32-input-mode, `CSI ? 9001 h`; so, as Windows Terminal does, each key that types no text goes as `CSI Vk ; Sc ; Uc ; Kd ; Cs ; Rc _`: the virtual key from gpui's name and the layout (`VkKeyScanW`), its scan code, what Windows types for it (`ToUnicode`, a dead key left as it is), down or up, and the modifier keys, locks and enhanced block from `GetKeyState`. kitty's flags go first, as in Windows Terminal; text stays text, so a repeat or a release goes as a record where its press did, a repeat that types after its modifiers came up too, and a release goes so only there; a full reset ends the mode, as Windows Terminal's does. A key that is down is known by its code, AppKit's key code on macOS and the virtual key on Windows, since gpui names a release by the modifiers left down: a release after Shift came up still goes out. Linux has only gpui's name. A console record holds no Windows key, so no Windows terminal passes herdr a `cmd` binding, and a keypad key goes as its main key, since gpui names it so. On Linux gpui keeps neither the key code nor its xkb state, and names a non-ASCII key by its place on a US keyboard, so a key's own character cannot be found: Shift with a symbol and Ctrl, Alt or Super goes as the symbol without Shift, which herdr matches to a binding on the symbol, `ctrl+{`.
- 2026-10-18: inside herdr, herdr opens its panes' links, as the owner's Cmd-press and Ctrl-press ask. herdr 0.9.5 wraps a long URL at its pane's edge with no wrap flag and writes its panes' OSC 8 links to the terminal without their targets, so ELYTerminal's own finder opened a cut URL or nothing; herdr itself opens the link under a Ctrl-press, whole from its own pane, a wrapped URL or an OSC 8 target, and underlines it while Ctrl is held. So while herdr's client leads the session and tracks the mouse, every link press goes to herdr as the mouse report it is, and on macOS herdr hears Cmd as Ctrl, the wheel aside. herdr's rules come with it, by its design: while it takes the mouse it keeps its panes' OSC 8 targets from the terminal, so that it alone answers Ctrl-press, and it opens only `http` and `https` links; a `file://` link inside herdr stays shut, since the text the terminal sees may be the label of another link. Shift with the press, which takes the mouse back from a program, is the way past herdr its docs name: the terminal then opens what it sees, a `file://` link too. With herdr's mouse capture off, herdr writes its links' targets out and the terminal opens them itself. Elsewhere ELYTerminal opens the link itself, as before.
- 2026-10-18: Ely peeks over the main window's top edge, which the owner asked for after the 0.1.3 film, her head and fingers drawn from the icon's own paths and cut at the edge she holds, in a transparent window of her own, 112 by 107 points with 16 above her for her hops, 140 in from the pane's left edge, less on a pane too narrow for that, so she holds its edge at any width, and the main window seems to hide the rest of her. Her window never takes the keys from the terminal: on macOS her panel becomes key only if needed, which gpui's view never asks; on Windows her window answers a press's activation with none, every other message passed on to gpui's own procedure; on X11 and Wayland a press moves no focus. gpui moves no window and places its popups only on Wayland, so each platform keeps her there its own way: on macOS gpui's popup panel is made the main window's child, at its level and in its Spaces, without a shadow, so AppKit moves it and hides it with the window; on Windows gpui's popup is owned by the main window and loses the topmost place gpui gives it, so it stays just above the main window and hides with it; gpui makes it an overlapped window, which Windows gives a caption and a frame, and opens it as large as the display when the middle of the box asked for lies off every display, as hers does over a window near the screen's top: in 0.1.4 a user found her at the bottom of a framed window the display's size, which took the clicks meant for the windows behind; so it becomes a bare popup, without caption, frame, corners or shadow, and the glue sets its size, from its own DPI, with its place on the pane's top edge as the main window moves, posting both to her window, since Windows sends a new size at once and gpui hears it only outside its own updates, as gpui defers its own resize; her height is her own DPI's and her bottom the pane's top, whatever the two windows' DPI, and when a move takes her to a display of another DPI, gpui takes the rect Windows suggests and she keeps her bottom left corner where it stood; on X11 gpui's popup, which no window manager places, is moved onto the pane, stacked just above the window manager's frame as the window moves or comes forward, and unmapped while it hides; on Wayland she is gpui's anchored popup, an xdg_popup on the pane's top edge, which the compositor keeps there; gpui moves a popup's anchor never, so a new width that moves her place opens her again. She opens with the sessions' mood, and her face follows the most pressing of their marks: a program that waits surprises her, with a mark and two hops; an error worries her, with a shake; a finish cheers her for 4 s, with a hop; work keeps her eyes on the terminal; calm, she blinks and glances, and dozes after 5 minutes; a press winks at you. Each face is an SVG drawn once, at three times her size so Retina draws her sharp, and she draws again only when her face changes. Settings › Terminal › Ely turns her off; she is on by default.
- 2026-10-18: Ely peeks over the main window's top edge, which the owner asked for after the 0.1.3 film, her head and fingers drawn from the icon's own paths and cut at the edge she holds, in a transparent window of her own, 112 by 107 points with 16 above her for her hops, 140 in from the pane's left edge, less on a pane too narrow for that, so she holds its edge at any width, and the main window seems to hide the rest of her. Her window never takes the keys from the terminal: on macOS her panel becomes key only if needed, which gpui's view never asks; on Windows her window answers a press's activation with none, every other message passed on to gpui's own procedure; on X11 and Wayland a press moves no focus. gpui moves no window and places its popups only on Wayland, so each platform keeps her there its own way: on macOS gpui's popup panel is made the main window's child, at its level and in its Spaces, without a shadow, so AppKit moves it and hides it with the window; on Windows gpui's popup is owned by the main window and loses the topmost place gpui gives it, so it stays just above the main window and hides with it; gpui makes it an overlapped window, which Windows gives a caption and a frame, and opens it as large as the display when the middle of the box asked for lies off every display, as hers does over a window near the screen's top: in 0.1.4 a user found her at the bottom of a framed window the display's size, which took the clicks meant for the windows behind; so it becomes a bare popup, without caption, frame, corners or shadow, and the glue sets its size, from its own DPI, with its place on the pane's top edge as the main window moves, posting both to her window, since Windows sends a new size at once and gpui hears it only outside its own updates, as gpui defers its own resize; her height is her own DPI's and her bottom the pane's top, whatever the two windows' DPI; at a new DPI gpui takes the rect Windows suggests, and once the move that brought it is done she takes her box at that DPI on the corner her last place gave her, if it lies mostly on a display of that DPI, as Windows reckons a window's display, else Windows' rect stands: between two displays a corner kept always would set her DPI back, and back again; on X11 gpui's popup, which no window manager places, is moved onto the pane, stacked just above the window manager's frame as the window moves or comes forward, and unmapped while it hides; on Wayland she is gpui's anchored popup, an xdg_popup on the pane's top edge, which the compositor keeps there; gpui moves a popup's anchor never, so a new width that moves her place opens her again. She opens with the sessions' mood, and her face follows the most pressing of their marks: a program that waits surprises her, with a mark and two hops; an error worries her, with a shake; a finish cheers her for 4 s, with a hop; work keeps her eyes on the terminal; calm, she blinks and glances, and dozes after 5 minutes; a press winks at you. Each face is an SVG drawn once, at three times her size so Retina draws her sharp, and she draws again only when her face changes. Settings › Terminal › Ely turns her off; she is on by default.
+1 -1
View File
@@ -61,7 +61,7 @@ image = { version = "0.25", default-features = false, features = ["png"] }
[target.'cfg(windows)'.dependencies]
raw-window-handle = "0.6"
sysinfo = { version = "0.39", default-features = false, features = ["system"] }
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_Console", "Win32_System_Diagnostics_ToolHelp", "Win32_System_Pipes", "Win32_UI_HiDpi", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_WindowsAndMessaging"] }
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Graphics_Gdi", "Win32_Storage_FileSystem", "Win32_System_Console", "Win32_System_Diagnostics_ToolHelp", "Win32_System_Pipes", "Win32_UI_HiDpi", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_WindowsAndMessaging"] }
[target.'cfg(windows)'.dev-dependencies]
windows-sys = { version = "0.61", features = ["Win32_Security", "Win32_System_IO"] }
+102 -208
View File
@@ -1,31 +1,45 @@
//! Ely's window on Windows: a bare popup owned by the main window, so it stays above it and hides with it, sized and moved as it moves.
use std::sync::atomic::{AtomicIsize, Ordering};
use std::{
cell::Cell,
sync::atomic::{AtomicIsize, Ordering},
};
use anyhow::bail;
use gpui::{Bounds, Pixels, Window};
use raw_window_handle::{HasWindowHandle, RawWindowHandle};
use windows_sys::Win32::{
Foundation::{HWND, LPARAM, LRESULT, RECT, WPARAM},
Graphics::Gdi::{MONITOR_DEFAULTTONEAREST, MonitorFromRect},
UI::{
HiDpi::GetDpiForWindow,
HiDpi::{GetDpiForMonitor, GetDpiForWindow, MDT_EFFECTIVE_DPI},
WindowsAndMessaging::{
CallWindowProcW, GWL_STYLE, GWLP_HWNDPARENT, GWLP_WNDPROC, GetWindowInfo,
GetWindowLongPtrW, GetWindowRect, HWND_NOTOPMOST, MA_NOACTIVATE, PostMessageW,
SWP_FRAMECHANGED, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOSIZE, SWP_NOZORDER,
SetWindowLongPtrW, SetWindowPos, USER_DEFAULT_SCREEN_DPI, WINDOWINFO, WM_APP,
WM_DPICHANGED, WM_MOUSEACTIVATE, WNDPROC, WS_CAPTION, WS_POPUP,
GetWindowLongPtrW, HWND_NOTOPMOST, MA_NOACTIVATE, PostMessageW, SWP_FRAMECHANGED,
SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOSIZE, SWP_NOZORDER, SetWindowLongPtrW, SetWindowPos,
USER_DEFAULT_SCREEN_DPI, WINDOWINFO, WM_APP, WM_DPICHANGED, WM_MOUSEACTIVATE, WNDPROC,
WS_CAPTION, WS_POPUP,
},
},
};
use super::{HEAD, ROOM, WIDTH, left, pane};
/// gpui's window procedure, which hers passes every message on to but a press's activation and her place.
#[cfg(test)]
mod tests;
/// gpui's window procedure, which hers passes every message on to but a press's activation and her places.
static GPUI: AtomicIsize = AtomicIsize::new(0);
thread_local! {
/// The bottom left corner her last place gave her, on the thread her window lives on.
static CORNER: Cell<Option<(i32, i32)>> = const { Cell::new(None) };
}
/// Her place, posted to her window: Windows sends a new size at once, which gpui hears only outside its own updates.
const PLACE: u32 = WM_APP;
/// Her corner at a new DPI, posted so it follows the whole move that brought the change.
const KEEP: u32 = WM_APP + 1;
const _: () = assert!(
size_of::<WPARAM>() == 8,
"a place packs two i32 into a word"
@@ -91,10 +105,7 @@ impl Glue {
/// Her box at `own` scale, its bottom on `pane` at `scale` over the main window's `client` rect: its place and size in pixels.
fn stand(client: RECT, scale: f32, own: f32, pane: Bounds<Pixels>) -> ((i32, i32), (i32, i32)) {
let size = (
(WIDTH * own).round() as i32,
((HEAD + ROOM) * own).round() as i32,
);
let size = sized(own);
let (x, y) = (f32::from(pane.origin.x), f32::from(pane.origin.y));
let at = (
client.left + ((x + left(pane.size.width)) * scale).round() as i32,
@@ -103,7 +114,15 @@ fn stand(client: RECT, scale: f32, own: f32, pane: Bounds<Pixels>) -> ((i32, i32
(at, size)
}
/// Her window's procedure: a press does not activate her window, she takes her place, and at a new DPI keeps her corner; all else is gpui's.
/// Her box's size in pixels at `own` scale.
fn sized(own: f32) -> (i32, i32) {
(
(WIDTH * own).round() as i32,
((HEAD + ROOM) * own).round() as i32,
)
}
/// Her window's procedure: a press does not activate her window, she takes her places, and all else is gpui's.
unsafe extern "system" fn inactive(
window: HWND,
message: u32,
@@ -115,40 +134,88 @@ unsafe extern "system" fn inactive(
WM_MOUSEACTIVATE => MA_NOACTIVATE as LRESULT,
PLACE => {
let ((x, y), (width, height)) = (unpack(wparam), unpack(lparam as WPARAM));
let flags = SWP_NOZORDER | SWP_NOACTIVATE;
let null = std::ptr::null_mut();
if unsafe { SetWindowPos(window, null, x, y, width, height, flags) } == 0 {
log::error!("pet: her window does not move to {x},{y}");
}
CORNER.set(Some((x, y + height)));
let rect = RECT {
left: x,
top: y,
right: x + width,
bottom: y + height,
};
move_to(window, rect);
0
}
WM_DPICHANGED => {
// gpui takes the rect Windows suggests, as a move to another display brings.
let (mut before, mut after) = (RECT::default(), RECT::default());
let read = unsafe { GetWindowRect(window, &mut before) };
// gpui takes the rect Windows suggests; her corner follows once the move is done.
let answer = unsafe { CallWindowProcW(gpui, window, message, wparam, lparam) };
if read == 0 || unsafe { GetWindowRect(window, &mut after) } == 0 {
log::error!("pet: her window's place does not read at a new DPI");
return answer;
}
let top = before.bottom - (after.bottom - after.top);
let flags = SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE;
let null = std::ptr::null_mut();
if unsafe { SetWindowPos(window, null, before.left, top, 0, 0, flags) } == 0 {
log::error!("pet: her window does not keep its corner at a new DPI");
} else {
log::debug!(
"pet: at a new DPI Ely keeps her corner at {},{}",
before.left,
before.bottom
);
if unsafe { PostMessageW(window, KEEP, wparam & 0xFFFF, 0) } == 0 {
log::error!("pet: her corner does not post at a new DPI");
}
answer
}
KEEP => {
let dpi = wparam as u32;
let Some(corner) = CORNER.get() else {
log::debug!("pet: at {dpi} DPI Ely has no place to keep yet");
return 0;
};
match keeping(corner, dpi, display_dpi) {
Ok(Some(kept)) => {
move_to(window, kept);
log::debug!("pet: at {dpi} DPI Ely keeps her corner at {corner:?}");
}
Ok(None) => log::debug!(
"pet: at {dpi} DPI Ely stands where Windows suggests, as on her corner she would lie on a display of another"
),
Err(error) => log::error!("{error:#}"),
}
0
}
_ => unsafe { CallWindowProcW(gpui, window, message, wparam, lparam) },
}
}
/// Moves her window to `rect`.
fn move_to(window: HWND, rect: RECT) {
let (width, height) = (rect.right - rect.left, rect.bottom - rect.top);
let flags = SWP_NOZORDER | SWP_NOACTIVATE;
let null = std::ptr::null_mut();
if unsafe { SetWindowPos(window, null, rect.left, rect.top, width, height, flags) } == 0 {
log::error!(
"pet: her window does not move to {},{}",
rect.left,
rect.top
);
}
}
/// Her box at `dpi` on the bottom left `corner` her place gave her, if it lies mostly on a display of that DPI, as `dpi_of` reads it; else none, and Windows' rect stands, which sets off no other change.
fn keeping(
(left, bottom): (i32, i32),
dpi: u32,
dpi_of: impl Fn(&RECT) -> anyhow::Result<u32>,
) -> anyhow::Result<Option<RECT>> {
let (width, height) = sized(dpi as f32 / USER_DEFAULT_SCREEN_DPI as f32);
let kept = RECT {
left,
top: bottom - height,
right: left + width,
bottom,
};
Ok((dpi_of(&kept)? == dpi).then_some(kept))
}
/// The DPI of the display under most of `rect`, which Windows gives a window there.
fn display_dpi(rect: &RECT) -> anyhow::Result<u32> {
let monitor = unsafe { MonitorFromRect(rect, MONITOR_DEFAULTTONEAREST) };
let (mut x, mut y) = (0, 0);
let read = unsafe { GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &mut x, &mut y) };
anyhow::ensure!(
read == 0,
"pet: the display under her box gives no DPI: {read:#x}"
);
Ok(x)
}
fn pack((low, high): (i32, i32)) -> WPARAM {
low as u32 as WPARAM | (high as u32 as WPARAM) << 32
}
@@ -166,176 +233,3 @@ fn native(window: &Window) -> anyhow::Result<HWND> {
};
Ok(win32.hwnd.get() as HWND)
}
#[cfg(test)]
mod tests {
use gpui::{point, px, size};
use windows_sys::{
Win32::UI::WindowsAndMessaging::{
CW_USEDEFAULT, CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW, MSG,
PM_REMOVE, PeekMessageW, SendMessageW, WS_EX_TOOLWINDOW, WS_EX_TOPMOST,
WS_OVERLAPPEDWINDOW,
},
w,
};
use super::*;
/// A hidden window of `style`, at the size Windows picks, as gpui asks for its windows.
fn window(style: u32, extended: u32) -> HWND {
let window = unsafe {
CreateWindowExW(
extended,
w!("STATIC"),
w!(""),
style,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
std::ptr::null_mut(),
std::ptr::null_mut(),
std::ptr::null_mut(),
std::ptr::null(),
)
};
assert!(!window.is_null(), "a test window");
window
}
fn info(window: HWND) -> WINDOWINFO {
let mut info = WINDOWINFO {
cbSize: size_of::<WINDOWINFO>() as u32,
..Default::default()
};
assert_ne!(unsafe { GetWindowInfo(window, &mut info) }, 0, "its info");
info
}
/// gpui's procedure as far as these tests need it: at a new DPI it takes the rect Windows suggests.
unsafe extern "system" fn standin(
window: HWND,
message: u32,
wparam: WPARAM,
lparam: LPARAM,
) -> LRESULT {
if message == WM_DPICHANGED {
let rect = unsafe { *(lparam as *const RECT) };
let (width, height) = (rect.right - rect.left, rect.bottom - rect.top);
let flags = SWP_NOZORDER | SWP_NOACTIVATE;
let null = std::ptr::null_mut();
unsafe { SetWindowPos(window, null, rect.left, rect.top, width, height, flags) };
return 0;
}
unsafe { DefWindowProcW(window, message, wparam, lparam) }
}
#[test]
fn her_bottom_stands_on_the_panes_top_edge_whatever_the_two_windows_dpi() {
let client = RECT {
left: 100,
top: 20,
right: 1300,
bottom: 900,
};
let pane = Bounds::new(point(px(10.), px(8.)), size(px(800.), px(600.)));
for (scale, own) in [(1.0, 1.0), (1.0, 1.5), (1.5, 1.0), (2.0, 1.25)] {
let ((x, y), (width, height)) = stand(client, scale, own, pane);
let own_box = (
(WIDTH * own).round() as i32,
((HEAD + ROOM) * own).round() as i32,
);
let corner = (
100 + ((10.0 + left(px(800.))) * scale).round() as i32,
20 + (8.0 * scale).round() as i32,
);
assert_eq!(
((width, height), (x, y + height)),
(own_box, corner),
"the main window at {scale}, hers at {own}"
);
}
}
#[test]
fn the_large_framed_popup_gpui_makes_stands_bare_in_her_box_on_the_panes_top_edge() {
let main = window(WS_OVERLAPPEDWINDOW, 0);
// gpui's popup: style 0, an overlapped window, which Windows gives a caption.
let pet = window(0, WS_EX_TOOLWINDOW | WS_EX_TOPMOST);
assert_eq!(
info(pet).dwStyle & WS_CAPTION,
WS_CAPTION,
"framed as gpui makes it"
);
unsafe { SetWindowLongPtrW(pet, GWLP_WNDPROC, standin as *const () as isize) };
let glue = Glue::hold(pet, main).expect("held");
let pane = Bounds::new(point(px(0.), px(0.)), size(px(380.), px(280.)));
glue.put(1.0, pane).expect("placed");
let made = info(pet).rcWindow;
let mut message = MSG::default();
while unsafe { PeekMessageW(&mut message, pet, 0, 0, PM_REMOVE) } != 0 {
unsafe { DispatchMessageW(&message) };
}
let (her, under) = (info(pet), info(main));
let own = unsafe { GetDpiForWindow(pet) } as f32 / 96.0;
// A new DPI, whose rect Windows suggests 30 and 40 pixels off, 100 by 60.
let at = her.rcWindow;
let suggested = RECT {
left: at.left + 30,
top: at.top + 40,
right: at.left + 130,
bottom: at.top + 100,
};
let pointer = &suggested as *const RECT as LPARAM;
unsafe { SendMessageW(pet, WM_DPICHANGED, 144 | 144 << 16, pointer) };
let later = info(pet).rcWindow;
unsafe {
DestroyWindow(pet);
DestroyWindow(main);
}
let (outer, inner) = (her.rcWindow, her.rcClient);
let frame = (
inner.left - outer.left,
inner.top - outer.top,
outer.right - inner.right,
outer.bottom - inner.bottom,
);
let drawn = (outer.right - outer.left, outer.bottom - outer.top);
let own_box = (
(WIDTH * own).round() as i32,
((HEAD + ROOM) * own).round() as i32,
);
let edge = (
under.rcClient.left + left(px(380.)).round() as i32,
under.rcClient.top,
);
let kept = (
later.left,
later.bottom,
later.right - later.left,
later.bottom - later.top,
);
assert_eq!(
(
her.dwStyle & WS_CAPTION,
frame,
drawn,
(outer.left, outer.bottom),
kept
),
(
0,
(0, 0, 0, 0),
own_box,
edge,
(outer.left, outer.bottom, 100, 60)
),
"bare, in her own box, her bottom on the pane's top edge, kept there at a new DPI"
);
assert_ne!(
(made.right - made.left, made.bottom - made.top),
own_box,
"no size until her window takes the posted place"
);
}
}
+252
View File
@@ -0,0 +1,252 @@
use gpui::{point, px, size};
use windows_sys::{
Win32::UI::WindowsAndMessaging::{
CW_USEDEFAULT, CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW, MSG,
PM_REMOVE, PeekMessageW, SendMessageW, WS_EX_TOOLWINDOW, WS_EX_TOPMOST,
WS_OVERLAPPEDWINDOW,
},
w,
};
use super::*;
/// A hidden window of `style`, at the size Windows picks, as gpui asks for its windows.
fn window(style: u32, extended: u32) -> HWND {
let window = unsafe {
CreateWindowExW(
extended,
w!("STATIC"),
w!(""),
style,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
std::ptr::null_mut(),
std::ptr::null_mut(),
std::ptr::null_mut(),
std::ptr::null(),
)
};
assert!(!window.is_null(), "a test window");
window
}
/// Hands her window the messages posted to it, as the message loop does.
fn deliver(window: HWND) {
let mut message = MSG::default();
while unsafe { PeekMessageW(&mut message, window, 0, 0, PM_REMOVE) } != 0 {
unsafe { DispatchMessageW(&message) };
}
}
fn info(window: HWND) -> WINDOWINFO {
let mut info = WINDOWINFO {
cbSize: size_of::<WINDOWINFO>() as u32,
..Default::default()
};
assert_ne!(unsafe { GetWindowInfo(window, &mut info) }, 0, "its info");
info
}
/// gpui's procedure as far as these tests need it: at a new DPI it takes the rect Windows suggests.
unsafe extern "system" fn standin(
window: HWND,
message: u32,
wparam: WPARAM,
lparam: LPARAM,
) -> LRESULT {
if message == WM_DPICHANGED {
let rect = unsafe { *(lparam as *const RECT) };
let (width, height) = (rect.right - rect.left, rect.bottom - rect.top);
let flags = SWP_NOZORDER | SWP_NOACTIVATE;
let null = std::ptr::null_mut();
unsafe { SetWindowPos(window, null, rect.left, rect.top, width, height, flags) };
return 0;
}
unsafe { DefWindowProcW(window, message, wparam, lparam) }
}
#[test]
fn her_bottom_stands_on_the_panes_top_edge_whatever_the_two_windows_dpi() {
let client = RECT {
left: 100,
top: 20,
right: 1300,
bottom: 900,
};
let pane = Bounds::new(point(px(10.), px(8.)), size(px(800.), px(600.)));
for (scale, own) in [(1.0, 1.0), (1.0, 1.5), (1.5, 1.0), (2.0, 1.25)] {
let ((x, y), (width, height)) = stand(client, scale, own, pane);
let own_box = (
(WIDTH * own).round() as i32,
((HEAD + ROOM) * own).round() as i32,
);
let corner = (
100 + ((10.0 + left(px(800.))) * scale).round() as i32,
20 + (8.0 * scale).round() as i32,
);
assert_eq!(
((width, height), (x, y + height)),
(own_box, corner),
"the main window at {scale}, hers at {own}"
);
}
}
/// Two displays split at 0, 144 DPI before and 96 after, across or down, giving a box the DPI of the one under most of it, as Windows does.
fn displays(down: bool) -> impl Fn(&RECT) -> anyhow::Result<u32> {
move |rect: &RECT| {
let (from, to) = if down {
(rect.top, rect.bottom)
} else {
(rect.left, rect.right)
};
Ok(if to.min(0) - from > to - from.max(0) {
144
} else {
96
})
}
}
/// Placing her box `rect` at `dpi` on `displays`, Windows' rect at each change scaled about its middle, which lands on the new display: the box she settles in and how many changes it took.
fn settle(mut rect: RECT, mut dpi: u32, down: bool) -> (RECT, usize) {
let dpi_of = displays(down);
let corner = (rect.left, rect.bottom);
for changes in 0..8 {
let now = dpi_of(&rect).expect("a display");
if now == dpi {
return (rect, changes);
}
let grow = |from: i32, to: i32| {
let length = ((to - from) as f64 * now as f64 / dpi as f64).round() as i32;
let start = (from + to - length).div_euclid(2);
(start, start + length)
};
let ((left, right), (top, bottom)) =
(grow(rect.left, rect.right), grow(rect.top, rect.bottom));
let after = RECT {
left,
top,
right,
bottom,
};
rect = keeping(corner, now, &dpi_of)
.expect("a display")
.unwrap_or(after);
dpi = now;
}
panic!("her DPI goes back and forth");
}
#[test]
fn placing_her_across_two_displays_of_two_dpis_settles_after_one_change() {
// 168 by 185 at 144 DPI, 70 pixels on the first display and 98 on the second.
let across = RECT {
left: -70,
top: 315,
right: 98,
bottom: 500,
};
let (rect, changes) = settle(across, 144, false);
assert_eq!(
changes, 1,
"Windows' rect stands where her corner would set her DPI back"
);
assert_eq!(displays(false)(&rect).expect("a display"), 96);
// 112 by 123 at 96 DPI, her bottom 50 pixels down the second display.
let down = RECT {
left: 200,
top: -73,
right: 312,
bottom: 50,
};
let (rect, changes) = settle(down, 96, true);
assert_eq!(
(changes, rect.left, rect.bottom),
(1, 200, 50),
"her corner kept on the edge"
);
assert_eq!(rect.bottom - rect.top, 185);
}
#[test]
fn the_large_framed_popup_gpui_makes_stands_bare_in_her_box_on_the_panes_top_edge() {
let main = window(WS_OVERLAPPEDWINDOW, 0);
// gpui's popup: style 0, an overlapped window, which Windows gives a caption.
let pet = window(0, WS_EX_TOOLWINDOW | WS_EX_TOPMOST);
assert_eq!(
info(pet).dwStyle & WS_CAPTION,
WS_CAPTION,
"framed as gpui makes it"
);
unsafe { SetWindowLongPtrW(pet, GWLP_WNDPROC, standin as *const () as isize) };
let glue = Glue::hold(pet, main).expect("held");
let pane = Bounds::new(point(px(0.), px(0.)), size(px(380.), px(280.)));
glue.put(1.0, pane).expect("placed");
let made = info(pet).rcWindow;
deliver(pet);
let (her, under) = (info(pet), info(main));
let own = unsafe { GetDpiForWindow(pet) } as f32 / 96.0;
// New DPIs, each with a rect Windows suggests 30 and 40 pixels off, 100 by 60.
let display = display_dpi(&her.rcWindow).expect("the display under her");
let change = |dpi: u32| {
let at = info(pet).rcWindow;
let suggested = RECT {
left: at.left + 30,
top: at.top + 40,
right: at.left + 130,
bottom: at.top + 100,
};
let pointer = &suggested as *const RECT as LPARAM;
unsafe { SendMessageW(pet, WM_DPICHANGED, (dpi | dpi << 16) as WPARAM, pointer) };
let taken = info(pet).rcWindow;
deliver(pet);
(suggested, taken, info(pet).rcWindow)
};
let (_, _, kept) = change(display);
let (suggested, taken, stood) = change(display + 48);
unsafe {
DestroyWindow(pet);
DestroyWindow(main);
}
let (outer, inner) = (her.rcWindow, her.rcClient);
let frame = (
inner.left - outer.left,
inner.top - outer.top,
outer.right - inner.right,
outer.bottom - inner.bottom,
);
let drawn = (outer.right - outer.left, outer.bottom - outer.top);
let own_box = (
(WIDTH * own).round() as i32,
((HEAD + ROOM) * own).round() as i32,
);
let edge = (
under.rcClient.left + left(px(380.)).round() as i32,
under.rcClient.top,
);
let rect = |rect: RECT| (rect.left, rect.top, rect.right, rect.bottom);
assert_eq!(
(
her.dwStyle & WS_CAPTION,
frame,
drawn,
(outer.left, outer.bottom),
rect(kept)
),
(0, (0, 0, 0, 0), own_box, edge, rect(outer)),
"bare, in her own box, her bottom on the pane's top edge, kept there at her display's DPI"
);
assert_eq!(
(rect(taken), rect(stood)),
(rect(suggested), rect(suggested)),
"gpui takes Windows' rect, which stands where her corner lies on a display of another DPI"
);
assert_ne!(
(made.right - made.left, made.bottom - made.top),
own_box,
"no size until her window takes the posted place"
);
}
+1 -1
View File
@@ -84,7 +84,7 @@ What no check reached: no real KWin drew the blur; of Wayland desktops, only Hyp
| The pointer over the terminal is the arrow | T26 | the terminal sets no pointer, so gpui's arrow shows; on X11 with the pointer over the grid, gpui asked for no I-beam ("text"), which it had asked for, and failed to load under Xvfb, before | Pass |
| The title bar is transparent | T11, T19 | T19 review | Pass |
| Every title bar control takes its press, Ely's window buttons on Windows and Linux too | T26 | Ely `cdc5ce8`: `window_controls_occlude_what_lies_under` (each style; before, the box under Windows' caption buttons took the press), `a_wobbling_press_on_a_slot_moves_no_window` (before, the window moved), `a_wobbling_press_on_a_column_title_moves_the_window`; on the owner's PC, window messages asked the app for Windows' hit test along the title bar: v0.1.0 answered caption from end to end, T26's build answers client over the toggles and +, caption over the titles, min, max and close over Ely's buttons, and a press on close closed the app; the owner, given v0.1.1's build and these controls to click, reported it works on Windows | Pass |
| Ely peeks over the window's top edge from behind it; her face follows the sessions; a press pets her | T46, T48 | `pet::look` tests: the most pressing mark sets her mood, calm blinks, glances and dozes, a finish cheers for 4 s, waiting and errors hold; `pet::faces` tests: every face parses at three times her box and shows its marks; `pet::x11` test under Xvfb: her window stands on the pane, just above the window manager's frame, and unmaps and maps with the main window; on macOS `shot` found her the main window's child, 112 by 124 points on its top edge 140 in, a capture of the screen showed her over the edge, and OSC 7501 reports gave her surprise, worry, eyes down and a cheer; a press on her window left the main window key and every key typed before and after it reached the program; switched off and on during an error she came back worried; on a 100-point window she stood at its left edge, and moved, resized and minimized she followed it; on Windows the `pet::windows` test, red before T48, finds the framed popup Windows makes, 1898 by 1481, bare in her own box, 168 by 185 at 150%, on the pane's top edge, and no size until her window takes the place posted to it; `pet::windows` tests, red before T48's second round: with the main window at 1, 1.5 or 2 and hers at 1, 1.25 or 1.5, her height is her own and her bottom the pane's top, where it fell 62 pixels into the terminal, and at a new DPI she keeps her bottom left corner as gpui takes the rect Windows suggests; on a Windows 11 VM at 150%, with the main window 49 pixels from the screen's top, 0.1.4 opened her 2326 by 1654 with a caption, drawn at its bottom over the terminal, and a press inside the terminal went to her; T48's build opened her 168 by 185 without one, on the edge, the press went to the terminal, one beside her box to the program behind, and one on her to her; with the window mid-screen she showed whole on its edge; Wayland's popup is gpui's own | Pass |
| Ely peeks over the window's top edge from behind it; her face follows the sessions; a press pets her | T46, T48 | `pet::look` tests: the most pressing mark sets her mood, calm blinks, glances and dozes, a finish cheers for 4 s, waiting and errors hold; `pet::faces` tests: every face parses at three times her box and shows its marks; `pet::x11` test under Xvfb: her window stands on the pane, just above the window manager's frame, and unmaps and maps with the main window; on macOS `shot` found her the main window's child, 112 by 124 points on its top edge 140 in, a capture of the screen showed her over the edge, and OSC 7501 reports gave her surprise, worry, eyes down and a cheer; a press on her window left the main window key and every key typed before and after it reached the program; switched off and on during an error she came back worried; on a 100-point window she stood at its left edge, and moved, resized and minimized she followed it; on Windows the `pet::windows` test, red before T48, finds the framed popup Windows makes, 1898 by 1481, bare in her own box, 168 by 185 at 150%, on the pane's top edge, and no size until her window takes the place posted to it; `pet::windows` tests, red before T48's second round: with the main window at 1, 1.5 or 2 and hers at 1, 1.25 or 1.5, her height is her own and her bottom the pane's top, where it fell 62 pixels into the terminal, and at a new DPI gpui takes the rect Windows suggests, then her box comes back on her corner, or Windows' rect stands where that box would lie on a display of another DPI; two displays side by side at 144 and 96 DPI, simulated, settle her after one change, where a corner kept always, red before T48's third round, changed her DPI back and forth; on a Windows 11 VM at 150%, with the main window 49 pixels from the screen's top, 0.1.4 opened her 2326 by 1654 with a caption, drawn at its bottom over the terminal, and a press inside the terminal went to her; T48's build opened her 168 by 185 without one, on the edge, the press went to the terminal, one beside her box to the program behind, and one on her to her; with the window mid-screen she showed whole on its edge; Wayland's popup is gpui's own | Pass |
## 7. Sessions panel