Skip to content

Commit

Permalink
fix(windows): Multi-monitor different scaling window size issue (#858)
Browse files Browse the repository at this point in the history
* Fix the issue where the window size is abnormal when dragging between monitors with different scaling settings with the "Show window contents while dragging" option turned off in Windows.

* clean code

* fix code fmt;

* Optimize code

* delete not used mut keyword

* add change file
  • Loading branch information
xiaochen0517 authored Jan 10, 2024
1 parent f0bf850 commit 60bbcac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/windows-drag-window-size-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": "patch"
---

On Windows, fix when the `Show window contents while dragging` setting is turned off in Windows, there is a window size issue when dragging between multi-monitors with different scaling.
18 changes: 18 additions & 0 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,11 @@ unsafe fn public_window_callback_inner<T: 'static>(
false => old_physical_inner_size,
};

// When the "Show window contents while dragging" is turned off, there is no need to adjust the window size.
if !is_show_window_contents_while_dragging_enabled() {
new_physical_inner_size = old_physical_inner_size;
}

subclass_input.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window.0)),
event: ScaleFactorChanged {
Expand Down Expand Up @@ -2191,6 +2196,19 @@ unsafe fn public_window_callback_inner<T: 'static>(
}
}

fn is_show_window_contents_while_dragging_enabled() -> bool {
let mut is_enabled: BOOL = BOOL(0);
let result = unsafe {
SystemParametersInfoW(
SPI_GETDRAGFULLWINDOWS,
0,
Option::from(&mut is_enabled as *mut _ as *mut std::ffi::c_void),
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS(0),
)
};
result.is_ok() && is_enabled.0 != 0
}

unsafe extern "system" fn thread_event_target_callback<T: 'static>(
window: HWND,
msg: u32,
Expand Down

0 comments on commit 60bbcac

Please sign in to comment.