From 68b5ea4e606acd3ca94b0d0fe3548191705d8ce2 Mon Sep 17 00:00:00 2001 From: Matin Aniss <76515905+MatinAniss@users.noreply.github.com> Date: Wed, 10 Jul 2024 05:15:15 +1000 Subject: [PATCH] windows: Fix and simplify title bar padding (#13420) This PR fixes the off by one pixel of the top client rect when not maximized due to the added border. It also simplifies and properly fixes the title bar padding problem when maximized, it is now properly taken care of in GPUI rather then adding the padding in the UI. Release Notes: - N/A --- crates/gpui/src/platform/windows/events.rs | 11 ++++++++-- crates/title_bar/src/title_bar.rs | 25 +--------------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/crates/gpui/src/platform/windows/events.rs b/crates/gpui/src/platform/windows/events.rs index 7c5a973614..dc6183e399 100644 --- a/crates/gpui/src/platform/windows/events.rs +++ b/crates/gpui/src/platform/windows/events.rs @@ -659,6 +659,13 @@ fn handle_calc_client_size( requested_client_rect[0].left += frame_x + padding; requested_client_rect[0].bottom -= frame_y + padding; + if state_ptr.state.borrow().is_maximized() { + requested_client_rect[0].top += frame_y + padding; + } else { + // Magic number that calculates the width of the border + requested_client_rect[0].top += frame_y - 3; + } + Some(0) } @@ -821,14 +828,14 @@ fn handle_hit_test_msg( let dpi = unsafe { GetDpiForWindow(handle) }; let frame_y = unsafe { GetSystemMetricsForDpi(SM_CYFRAME, dpi) }; - let padding = unsafe { GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi) }; let mut cursor_point = POINT { x: lparam.signed_loword().into(), y: lparam.signed_hiword().into(), }; unsafe { ScreenToClient(handle, &mut cursor_point).ok().log_err() }; - if cursor_point.y > 0 && cursor_point.y < frame_y + padding { + if !state_ptr.state.borrow().is_maximized() && cursor_point.y >= 0 && cursor_point.y <= frame_y + { return Some(HTTOP as _); } diff --git a/crates/title_bar/src/title_bar.rs b/crates/title_bar/src/title_bar.rs index 02e6390c2d..e2cd45b1c4 100644 --- a/crates/title_bar/src/title_bar.rs +++ b/crates/title_bar/src/title_bar.rs @@ -77,8 +77,7 @@ impl Render for TitleBar { h_flex() .id("titlebar") .w_full() - .pt(Self::top_padding(cx)) - .h(height + Self::top_padding(cx)) + .h(height) .map(|this| { if cx.is_fullscreen() { this.pl_2() @@ -235,28 +234,6 @@ impl TitleBar { px(32.) } - #[cfg(not(target_os = "windows"))] - fn top_padding(_cx: &WindowContext) -> Pixels { - px(0.) - } - - #[cfg(target_os = "windows")] - fn top_padding(cx: &WindowContext) -> Pixels { - use windows::Win32::UI::{ - HiDpi::GetSystemMetricsForDpi, - WindowsAndMessaging::{SM_CXPADDEDBORDER, USER_DEFAULT_SCREEN_DPI}, - }; - - // This top padding is not dependent on the title bar style and is instead a quirk of maximized windows on Windows: - // https://devblogs.microsoft.com/oldnewthing/20150304-00/?p=44543 - let padding = unsafe { GetSystemMetricsForDpi(SM_CXPADDEDBORDER, USER_DEFAULT_SCREEN_DPI) }; - if cx.is_maximized() { - px((padding * 2) as f32) - } else { - px(0.) - } - } - /// Sets the platform style. pub fn platform_style(mut self, style: PlatformStyle) -> Self { self.platform_style = style;