Skip to content

Commit

Permalink
handle top edge as well
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Feb 8, 2025
1 parent b0dad9d commit d9ee4a7
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use windows::{
},
UI::{
Controls::{self as win32c, HOVER_DEFAULT},
HiDpi::GetSystemMetricsForDpi,
Input::{KeyboardAndMouse::*, Pointer::*, Touch::*, *},
Shell::{
DefSubclassProc, RemoveWindowSubclass, SHAppBarMessage, SetWindowSubclass, ABE_BOTTOM,
Expand Down Expand Up @@ -66,6 +67,8 @@ use crate::{
};
use runner::{EventLoopRunner, EventLoopRunnerShared};

use super::dpi::hwnd_dpi;

type GetPointerFrameInfoHistory = unsafe extern "system" fn(
pointerId: u32,
entriesCount: *mut u32,
Expand Down Expand Up @@ -2167,9 +2170,8 @@ unsafe fn public_window_callback_inner<T: 'static>(
let window_state = subclass_input.window_state.lock();
let window_flags = window_state.window_flags();

// Allow resizing unmaximized non-fullscreen undecorated window without shadows
// Allow resizing unmaximized non-fullscreen undecorated window
if !window_flags.contains(WindowFlags::MARKER_DECORATIONS)
&& !window_flags.contains(WindowFlags::MARKER_UNDECORATED_SHADOW)
&& window_flags.contains(WindowFlags::RESIZABLE)
&& window_state.fullscreen.is_none()
&& !util::is_maximized(window).unwrap_or(false)
Expand All @@ -2180,25 +2182,38 @@ unsafe fn public_window_callback_inner<T: 'static>(
util::GET_Y_LPARAM(lparam) as i32,
);

let mut rect = RECT::default();
let _ = GetWindowRect(window, &mut rect);

let padded_border = GetSystemMetrics(SM_CXPADDEDBORDER);
let border_x = GetSystemMetrics(SM_CXFRAME) + padded_border;
let border_y = GetSystemMetrics(SM_CYFRAME) + padded_border;

let hit_result = crate::window::hit_test(
(rect.left, rect.top, rect.right, rect.bottom),
cx,
cy,
border_x,
border_y,
)
.map(|d| d.to_win32());
let dpi = hwnd_dpi(window);
let border_y = GetSystemMetricsForDpi(SM_CYFRAME, dpi);

result = hit_result
.map(|r| ProcResult::Value(LRESULT(r as _)))
.unwrap_or(ProcResult::DefSubclassProc);
// if we have undecorated shadows, we only need to handle the top edge
if window_flags.contains(WindowFlags::MARKER_UNDECORATED_SHADOW) {
let mut cursor_pt = POINT { x: cx, y: cy };
if ScreenToClient(window, &mut cursor_pt).as_bool()
&& cursor_pt.y >= 0
&& cursor_pt.y <= border_y
{
result = ProcResult::Value(LRESULT(HTTOP as _));
}
} else {
//otherwise do full hit testing
let border_x = GetSystemMetricsForDpi(SM_CXFRAME, dpi);

let mut rect = RECT::default();
let _ = GetWindowRect(window, &mut rect);

let hit_result = crate::window::hit_test(
(rect.left, rect.top, rect.right, rect.bottom),
cx,
cy,
border_x,
border_y,
)
.map(|d| d.to_win32());

result = hit_result
.map(|r| ProcResult::Value(LRESULT(r as _)))
.unwrap_or(ProcResult::DefSubclassProc);
}
} else {
result = ProcResult::DefSubclassProc;
}
Expand Down

0 comments on commit d9ee4a7

Please sign in to comment.