Skip to content

Commit

Permalink
fix: scale borderless resizing inset based on scale_factor, closes #376
Browse files Browse the repository at this point in the history
… (#379)
  • Loading branch information
amrbashir authored May 1, 2022
1 parent 634116f commit 8701f64
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/scaled-resize-borderless.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

On Windows and Linux, increase the resizing area for borderless windows based on scale factor.
10 changes: 6 additions & 4 deletions src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,13 @@ pub fn hit_test(window: &gdk::Window, cx: f64, cy: f64) -> WindowEdge {
const BOTTOMLEFT: i32 = BOTTOM | LEFT;
const BOTTOMRIGHT: i32 = BOTTOM | RIGHT;

let inset = BORDERLESS_RESIZE_INSET * window.scale_factor();
#[rustfmt::skip]
let result = (LEFT * (if cx < (left + BORDERLESS_RESIZE_INSET) { 1 } else { 0 }))
| (RIGHT * (if cx >= (right - BORDERLESS_RESIZE_INSET) { 1 } else { 0 }))
| (TOP * (if cy < (top + BORDERLESS_RESIZE_INSET) { 1 } else { 0 }))
| (BOTTOM * (if cy >= (bottom - BORDERLESS_RESIZE_INSET) { 1 } else { 0 }));
let result =
(LEFT * (if cx < (left + inset) { 1 } else { 0 }))
| (RIGHT * (if cx >= (right - inset) { 1 } else { 0 }))
| (TOP * (if cy < (top + inset) { 1 } else { 0 }))
| (BOTTOM * (if cy >= (bottom - inset) { 1 } else { 0 }));

match result {
LEFT => WindowEdge::West,
Expand Down
13 changes: 9 additions & 4 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,11 +1163,16 @@ pub fn hit_test(hwnd: HWND, cx: i32, cy: i32) -> LRESULT {
top,
} = window_rect;

let dpi = hwnd_dpi(hwnd);
let scale_factor = dpi_to_scale_factor(dpi);
let inset = (BORDERLESS_RESIZE_INSET as f64 * scale_factor) as i32;

#[rustfmt::skip]
let result = (LEFT * (if cx < (left + BORDERLESS_RESIZE_INSET) { 1 } else { 0 }))
| (RIGHT * (if cx >= (right - BORDERLESS_RESIZE_INSET) { 1 } else { 0 }))
| (TOP * (if cy < (top + BORDERLESS_RESIZE_INSET) { 1 } else { 0 }))
| (BOTTOM * (if cy >= (bottom - BORDERLESS_RESIZE_INSET) { 1 } else { 0 }));
let result =
(LEFT * (if cx < (left + inset) { 1 } else { 0 }))
| (RIGHT * (if cx >= (right - inset) { 1 } else { 0 }))
| (TOP * (if cy < (top + inset) { 1 } else { 0 }))
| (BOTTOM * (if cy >= (bottom - inset) { 1 } else { 0 }));

LRESULT(match result {
CLIENT => HTCLIENT,
Expand Down
1 change: 1 addition & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,4 +1061,5 @@ impl Default for UserAttentionType {
}

/// A constant used to determine how much inside the window, the resize handler should appear (only used in Linux(gtk) and Windows).
/// You probably need to scale it by the scale_factor of the window.
pub const BORDERLESS_RESIZE_INSET: i32 = 5;

0 comments on commit 8701f64

Please sign in to comment.