Current State
src/gui/utils.rs::hide_window and src/gui/utils.rs::active_window both organise their per-platform code as two adjacent blocks:
// 1. Windows path written as a standalone #[cfg] block
#[cfg(target_os = "windows")]
if let Ok(window_handle) = HasWindowHandle::window_handle(window)
&& let RawWindowHandle::Win32(win32_handle) = window_handle.as_raw()
{
let hwnd = win32_handle.hwnd.get() as *mut std::ffi::c_void;
unsafe { /* ShowWindow / SetForegroundWindow */ }
}
// 2. macOS / Linux paths written through cfg_select!
cfg_select! {
target_os = "macos" => { /* … */ }
target_os = "linux" => { /* … */ }
_ => {}
}
The split is purely historical: the Windows block was written with a multi-line unsafe body and a local hwnd binding, while the other branches were one-liners that fit naturally into cfg_select!. There is no language reason for the asymmetry — cfg_select! arms accept arbitrary statement blocks, including unsafe { … } and local let bindings.
Target State
Each helper has a single per-platform dispatch site:
cfg_select! {
target_os = "macos" => { /* … */ }
target_os = "windows" => {
if let Ok(window_handle) = HasWindowHandle::window_handle(window)
&& let RawWindowHandle::Win32(win32_handle) = window_handle.as_raw()
{
let hwnd = win32_handle.hwnd.get() as *mut std::ffi::c_void;
unsafe { /* … */ }
}
}
target_os = "linux" => { /* … */ }
_ => {}
}
No platform-specific logic is added or removed. Both the X11 map_window ↔ unmap_window pairing and the Win32 SW_RESTORE ↔ SW_HIDE pairing (see issue #101) are preserved verbatim — they are the project's bridges between its own hide path and GPUI's activation path, and must stay.
Rationale
- Consistency — the same dispatch shape across all three platforms makes the function easier to read at a glance.
- DRY — one cfg dispatch site per function instead of two.
- No behaviour change —
cfg_select! expands to the same compile-time branch selection as #[cfg], so the binary is byte-identical on each target.
- Risk is essentially zero; clippy backstops any unused-import fallout.
Scope
gui (style cleanup inside two helpers in src/gui/utils.rs).
Safety Net
Current State
src/gui/utils.rs::hide_windowandsrc/gui/utils.rs::active_windowboth organise their per-platform code as two adjacent blocks:The split is purely historical: the Windows block was written with a multi-line
unsafebody and a localhwndbinding, while the other branches were one-liners that fit naturally intocfg_select!. There is no language reason for the asymmetry —cfg_select!arms accept arbitrary statement blocks, includingunsafe { … }and localletbindings.Target State
Each helper has a single per-platform dispatch site:
No platform-specific logic is added or removed. Both the X11
map_window↔unmap_windowpairing and the Win32SW_RESTORE↔SW_HIDEpairing (see issue #101) are preserved verbatim — they are the project's bridges between its own hide path and GPUI's activation path, and must stay.Rationale
cfg_select!expands to the same compile-time branch selection as#[cfg], so the binary is byte-identical on each target.Scope
gui(style cleanup inside two helpers insrc/gui/utils.rs).Safety Net