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

Reduce WM_PAINT messages of thread target window #2371

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On Windows, added `WindowExtWindows::set_skip_taskbar` and `WindowBuilderExtWindows::with_skip_taskbar`.
- On Windows, added `EventLoopBuilderExtWindows::with_msg_hook`.
- On Windows, remove internally unique DC per window.
- On Windows, reduce `WM_PAINT` messages of thread target window by calling `RedrawWindow` only when it needs to process the message.
- On macOS, remove the need to call `set_ime_position` after moving the window.
- Added `Window::is_visible`.
- Added `Window::is_resizable`.
Expand Down
10 changes: 6 additions & 4 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2175,17 +2175,14 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
}
let userdata = Box::from_raw(userdata_ptr);

if msg != WM_PAINT {
RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT);
}

let mut userdata_removed = false;

// I decided to bind the closure to `callback` and pass it to catch_unwind rather than passing
// the closure to catch_unwind directly so that the match body indendation wouldn't change and
// the git blame and history would be preserved.
let callback = || match msg {
WM_NCDESTROY => {
RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT);
super::set_window_long(window, GWL_USERDATA, 0);
userdata_removed = true;
0
Expand Down Expand Up @@ -2216,6 +2213,7 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
}

WM_INPUT_DEVICE_CHANGE => {
RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT);
let event = match wparam as u32 {
GIDC_ARRIVAL => DeviceEvent::Added,
GIDC_REMOVAL => DeviceEvent::Removed,
Expand All @@ -2236,6 +2234,7 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
ElementState::{Pressed, Released},
MouseScrollDelta::LineDelta,
};
RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT);

if let Some(data) = raw_input::get_raw_input_data(lparam) {
let device_id = wrap_device_id(data.header.hDevice as u32);
Expand Down Expand Up @@ -2334,17 +2333,20 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
}

_ if msg == *USER_EVENT_MSG_ID => {
RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT);
if let Ok(event) = userdata.user_event_receiver.recv() {
userdata.send_event(Event::UserEvent(event));
}
0
}
_ if msg == *EXEC_MSG_ID => {
RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT);
let mut function: ThreadExecFn = Box::from_raw(wparam as usize as *mut _);
function();
0
}
_ if msg == *PROCESS_NEW_EVENTS_MSG_ID => {
RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT);
PostThreadMessageW(
userdata.event_loop_runner.wait_thread_id(),
*CANCEL_WAIT_UNTIL_MSG_ID,
Expand Down