Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows: Fix incorrect titlebar behavior with a scale factor greater than 1.0 #9438

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions crates/gpui/src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl WindowsWindowInner {
}

fn get_titlebar_rect(&self) -> anyhow::Result<RECT> {
let top_and_bottom_borders = 2;
const TOP_BOTTOM_BORDERS: i32 = 2;
let theme = unsafe { OpenThemeData(self.hwnd, w!("WINDOW")) };
let title_bar_size = unsafe {
GetThemePartSize(
Expand All @@ -139,12 +139,15 @@ impl WindowsWindowInner {
}?;
unsafe { CloseThemeData(theme) }?;

let mut height =
(title_bar_size.cy as f32 * self.scale_factor).round() as i32 + top_and_bottom_borders;
// let mut height =
// (title_bar_size.cy as f32 * self.scale_factor).round() as i32 + TOP_BOTTOM_BORDERS;
let mut height = title_bar_size.cy + TOP_BOTTOM_BORDERS;

if self.is_maximized() {
let dpi = unsafe { GetDpiForWindow(self.hwnd) };
height += unsafe { (GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi) * 2) as i32 };
// let dpi = unsafe { GetDpiForWindow(self.hwnd) };
height += unsafe {
(GetSystemMetricsForDpi(SM_CXPADDEDBORDER, USER_DEFAULT_SCREEN_DPI) * 2) as i32
};
}

let mut rect = RECT::default();
Expand Down Expand Up @@ -751,11 +754,10 @@ impl WindowsWindowInner {
return unsafe { DefWindowProcW(self.hwnd, msg, wparam, lparam) };
}

let dpi = unsafe { GetDpiForWindow(self.hwnd) };

let frame_x = unsafe { GetSystemMetricsForDpi(SM_CXFRAME, dpi) };
let frame_y = unsafe { GetSystemMetricsForDpi(SM_CYFRAME, dpi) };
let padding = unsafe { GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi) };
// let dpi = unsafe { GetDpiForWindow(self.hwnd) };
let frame_x = unsafe { GetSystemMetricsForDpi(SM_CXFRAME, USER_DEFAULT_SCREEN_DPI) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to go to using USER_DEFAULT_SCREEN_API here and instead use these values in the platform titlebar which are existing TODOs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done here. #9449
@JunkuiZhang give it a try!

let frame_y = unsafe { GetSystemMetricsForDpi(SM_CYFRAME, USER_DEFAULT_SCREEN_DPI) };
let padding = unsafe { GetSystemMetricsForDpi(SM_CXPADDEDBORDER, USER_DEFAULT_SCREEN_DPI) };

// wparam is TRUE so lparam points to an NCCALCSIZE_PARAMS structure
let mut params = lparam.0 as *mut NCCALCSIZE_PARAMS;
Expand Down Expand Up @@ -825,9 +827,9 @@ impl WindowsWindowInner {
return hit;
}

let dpi = unsafe { GetDpiForWindow(self.hwnd) };
let frame_y = unsafe { GetSystemMetricsForDpi(SM_CYFRAME, dpi) };
let padding = unsafe { GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi) };
// let dpi = unsafe { GetDpiForWindow(self.hwnd) };
let frame_y = unsafe { GetSystemMetricsForDpi(SM_CYFRAME, USER_DEFAULT_SCREEN_DPI) };
let padding = unsafe { GetSystemMetricsForDpi(SM_CXPADDEDBORDER, USER_DEFAULT_SCREEN_DPI) };

let mut cursor_point = POINT {
x: lparam.signed_loword().into(),
Expand All @@ -841,7 +843,8 @@ impl WindowsWindowInner {
let titlebar_rect = self.get_titlebar_rect();
if let Ok(titlebar_rect) = titlebar_rect {
if cursor_point.y < titlebar_rect.bottom {
let caption_btn_width = unsafe { GetSystemMetricsForDpi(SM_CXSIZE, dpi) };
let caption_btn_width =
unsafe { GetSystemMetricsForDpi(SM_CXSIZE, USER_DEFAULT_SCREEN_DPI) };
if cursor_point.x >= titlebar_rect.right - caption_btn_width {
return LRESULT(HTCLOSE as _);
} else if cursor_point.x >= titlebar_rect.right - caption_btn_width * 2 {
Expand Down
Loading