Skip to content

Commit

Permalink
fix(win,linux): disable resizing maximized borderless windows (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Mar 30, 2022
1 parent ef06c50 commit 13c5c99
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changes/disable-maximized-resize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": "patch"
---

On Windows and Linux, disable resizing maximized borderless windows.
4 changes: 2 additions & 2 deletions src/platform_impl/linux/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ impl<T: 'static> EventLoop<T> {
| EventMask::FOCUS_CHANGE_MASK,
);

// Resizing `decorations: false` aka borderless
// Allow resizing unmaximized borderless window
window.connect_motion_notify_event(|window, event| {
if !window.is_decorated() && window.is_resizable() {
if !window.is_decorated() && window.is_resizable() && !window.is_maximized() {
if let Some(window) = window.window() {
let (cx, cy) = event.root();
let edge = hit_test(&window, cx, cy);
Expand Down
32 changes: 17 additions & 15 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1936,28 +1936,30 @@ unsafe fn public_window_callback_inner<T: 'static>(
params.rgrc[0] = monitor_info.monitorInfo.rcWork;
}
}
result = ProcResult::Value(LRESULT(0)); // return 0 here to make the windowo borderless
result = ProcResult::Value(LRESULT(0)); // return 0 here to make the window borderless
} else {
result = ProcResult::DefSubclassProc;
}
}

win32wm::WM_NCHITTEST => {
if let Some(state) = subclass_input.window_state.try_lock() {
let win_flags = state.window_flags();

// Only apply this hit test for borderless windows that wants to be resizable
if !win_flags.contains(WindowFlags::DECORATIONS) {
// cursor location
let (cx, cy) = (
i32::from(util::GET_X_LPARAM(lparam)),
i32::from(util::GET_Y_LPARAM(lparam)),
);
// Allow resizing unmaximized borderless window
if !util::is_maximized(window)
&& !subclass_input
.window_state
.lock()
.window_flags()
.contains(WindowFlags::DECORATIONS)
{
// cursor location
let (cx, cy) = (
i32::from(util::GET_X_LPARAM(lparam)),
i32::from(util::GET_Y_LPARAM(lparam)),
);

result = ProcResult::Value(crate::platform_impl::hit_test(window, cx, cy));
} else {
result = ProcResult::DefSubclassProc;
}
result = ProcResult::Value(crate::platform_impl::hit_test(window, cx, cy));
} else {
result = ProcResult::DefSubclassProc;
}
}

Expand Down

0 comments on commit 13c5c99

Please sign in to comment.