Skip to content

Commit

Permalink
chore(deps): update windows to 0.59 (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master authored Jan 14, 2025
1 parent cdfba4e commit 543e117
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 121 deletions.
5 changes: 5 additions & 0 deletions .changes/windows-0.59.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
tao: patch
---

Update `windows` to 0.59
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ softbuffer = "0.4"
parking_lot = "0.12"
unicode-segmentation = "1.11"
windows-version = "0.1"
windows-core = "0.58"
windows-core = "0.59"

[target."cfg(target_os = \"windows\")".dependencies.windows]
version = "0.58"
version = "0.59"
features = [
"implement",
"Win32_Devices_HumanInterfaceDevice",
"Win32_Foundation",
"Win32_Globalization",
Expand Down
12 changes: 6 additions & 6 deletions src/platform_impl/windows/dark_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use once_cell::sync::Lazy;
use windows::{
core::{s, w, PCSTR, PSTR},
Win32::{
Foundation::{BOOL, HANDLE, HMODULE, HWND, WPARAM},
Foundation::{BOOL, HANDLE, HMODULE, HWND, LPARAM, WPARAM},
Graphics::Dwm::{DwmSetWindowAttribute, DWMWINDOWATTRIBUTE},
System::LibraryLoader::*,
UI::{Accessibility::*, Input::KeyboardAndMouse::GetActiveWindow, WindowsAndMessaging::*},
Expand Down Expand Up @@ -175,7 +175,7 @@ fn refresh_titlebar_theme_color(hwnd: HWND, is_dark_mode: bool, redraw_title_bar
let _ = SetPropW(
hwnd,
w!("UseImmersiveDarkModeColors"),
HANDLE(&mut is_dark_mode_bigbool as *mut _ as _),
Some(HANDLE(&mut is_dark_mode_bigbool as *mut _ as _)),
);
}
} else {
Expand All @@ -195,11 +195,11 @@ fn refresh_titlebar_theme_color(hwnd: HWND, is_dark_mode: bool, redraw_title_bar
);
if redraw_title_bar {
if GetActiveWindow() == hwnd {
DefWindowProcW(hwnd, WM_NCACTIVATE, None, None);
DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None);
DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM::default(), LPARAM::default());
DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), LPARAM::default());
} else {
DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None);
DefWindowProcW(hwnd, WM_NCACTIVATE, None, None);
DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), LPARAM::default());
DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM::default(), LPARAM::default());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/windows/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn dpi_to_scale_factor(dpi: u32) -> f64 {
}

pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 {
let hdc = GetDC(hwnd);
let hdc = GetDC(Some(hwnd));
if hdc.is_invalid() {
panic!("[tao] `GetDC` returned null!");
}
Expand Down Expand Up @@ -99,7 +99,7 @@ pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 {
if IsProcessDPIAware().as_bool() {
// If the process is DPI aware, then scaling must be handled by the application using
// this DPI value.
GetDeviceCaps(hdc, LOGPIXELSX) as u32
GetDeviceCaps(Some(hdc), LOGPIXELSX) as u32
} else {
// If the process is DPI unaware, then scaling is performed by the OS; we thus return
// 96 (scale factor 1.0) to prevent the window from being re-scaled by both the
Expand Down
9 changes: 6 additions & 3 deletions src/platform_impl/windows/drop_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ impl FileDropHandler {
}
}

unsafe fn iterate_filenames<F>(data_obj: Option<&IDataObject>, callback: F) -> Option<HDROP>
unsafe fn iterate_filenames<F>(
data_obj: windows_core::Ref<'_, IDataObject>,
callback: F,
) -> Option<HDROP>
where
F: Fn(PathBuf),
{
Expand Down Expand Up @@ -105,7 +108,7 @@ impl FileDropHandler {
impl IDropTarget_Impl for FileDropHandler_Impl {
fn DragEnter(
&self,
pDataObj: Option<&IDataObject>,
pDataObj: windows_core::Ref<'_, IDataObject>,
_grfKeyState: MODIFIERKEYS_FLAGS,
_pt: &POINTL,
pdwEffect: *mut DROPEFFECT,
Expand Down Expand Up @@ -156,7 +159,7 @@ impl IDropTarget_Impl for FileDropHandler_Impl {

fn Drop(
&self,
pDataObj: Option<&IDataObject>,
pDataObj: windows_core::Ref<'_, IDataObject>,
_grfKeyState: MODIFIERKEYS_FLAGS,
_pt: &POINTL,
_pdwEffect: *mut DROPEFFECT,
Expand Down
75 changes: 41 additions & 34 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use windows::{
core::{s, PCWSTR},
Win32::{
Foundation::{
BOOL, HANDLE, HINSTANCE, HMODULE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_TIMEOUT, WPARAM,
BOOL, HANDLE, HINSTANCE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_TIMEOUT, WPARAM,
},
Graphics::Gdi::*,
System::{
Expand Down Expand Up @@ -245,7 +245,7 @@ impl<T: 'static> EventLoop<T> {

runner.poll();
'main: loop {
if !GetMessageW(&mut msg, HWND::default(), 0, 0).as_bool() {
if !GetMessageW(&mut msg, None, 0, 0).as_bool() {
break 'main 0;
}

Expand Down Expand Up @@ -335,7 +335,7 @@ impl<T> EventLoopWindowTarget<T> {
pub fn set_theme(&self, theme: Option<Theme>) {
*self.preferred_theme.lock() = theme;
self.runner_shared.owned_windows(|window| {
let _ = unsafe { SendMessageW(window, *CHANGE_THEME_MSG_ID, WPARAM(0), LPARAM(0)) };
let _ = unsafe { SendMessageW(window, *CHANGE_THEME_MSG_ID, None, None) };
});
}
}
Expand All @@ -360,7 +360,7 @@ fn get_wait_thread_id() -> u32 {
let mut msg = MSG::default();
let result = GetMessageW(
&mut msg,
HWND::default(),
None,
*SEND_WAIT_THREAD_ID_MSG_ID,
*SEND_WAIT_THREAD_ID_MSG_ID,
);
Expand Down Expand Up @@ -393,11 +393,11 @@ fn wait_thread(parent_thread_id: u32, msg_window_id: HWND) {
msg = MSG::default();

if wait_until_opt.is_some() {
if PeekMessageW(&mut msg, HWND::default(), 0, 0, PM_REMOVE).as_bool() {
if PeekMessageW(&mut msg, None, 0, 0, PM_REMOVE).as_bool() {
let _ = TranslateMessage(&msg);
DispatchMessageW(&msg);
}
} else if !GetMessageW(&mut msg, HWND::default(), 0, 0).as_bool() {
} else if !GetMessageW(&mut msg, None, 0, 0).as_bool() {
break 'main;
} else {
let _ = TranslateMessage(&msg);
Expand All @@ -424,7 +424,7 @@ fn wait_thread(parent_thread_id: u32, msg_window_id: HWND) {
);
if resume_reason == WAIT_TIMEOUT {
let _ = PostMessageW(
msg_window_id,
Some(msg_window_id),
*PROCESS_NEW_EVENTS_MSG_ID,
WPARAM(0),
LPARAM(0),
Expand All @@ -433,7 +433,7 @@ fn wait_thread(parent_thread_id: u32, msg_window_id: HWND) {
}
} else {
let _ = PostMessageW(
msg_window_id,
Some(msg_window_id),
*PROCESS_NEW_EVENTS_MSG_ID,
WPARAM(0),
LPARAM(0),
Expand Down Expand Up @@ -526,7 +526,7 @@ impl EventLoopThreadExecutor {
let raw = Box::into_raw(boxed2);

let res = PostMessageW(
self.target_window,
Some(self.target_window),
*EXEC_MSG_ID,
WPARAM(raw as _),
LPARAM(0),
Expand Down Expand Up @@ -561,7 +561,14 @@ impl<T: 'static> Clone for EventLoopProxy<T> {
impl<T: 'static> EventLoopProxy<T> {
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
unsafe {
if PostMessageW(self.target_window, *USER_EVENT_MSG_ID, WPARAM(0), LPARAM(0)).is_ok() {
if PostMessageW(
Some(self.target_window),
*USER_EVENT_MSG_ID,
WPARAM(0),
LPARAM(0),
)
.is_ok()
{
self.event_send.send(event).ok();
Ok(())
} else {
Expand Down Expand Up @@ -677,9 +684,9 @@ fn create_event_target_window() -> HWND {
0,
0,
0,
HWND::default(),
HMENU::default(),
GetModuleHandleW(PCWSTR::null()).unwrap_or_default(),
None,
None,
GetModuleHandleW(PCWSTR::null()).map(Into::into).ok(),
None,
)
};
Expand Down Expand Up @@ -814,7 +821,7 @@ unsafe fn flush_paint_messages<T: 'static>(

if !PeekMessageW(
&mut msg,
redraw_window,
Some(redraw_window),
WM_PAINT,
WM_PAINT,
PM_REMOVE | PM_QS_PAINT,
Expand All @@ -837,7 +844,7 @@ unsafe fn process_control_flow<T: 'static>(runner: &EventLoopRunner<T>) {
match runner.control_flow() {
ControlFlow::Poll => {
let _ = PostMessageW(
runner.thread_msg_target(),
Some(runner.thread_msg_target()),
*PROCESS_NEW_EVENTS_MSG_ID,
WPARAM(0),
LPARAM(0),
Expand Down Expand Up @@ -955,9 +962,9 @@ unsafe fn public_window_callback_inner<T: 'static>(
subclass_input: &SubclassInput<T>,
) -> LRESULT {
let _ = RedrawWindow(
subclass_input.event_loop_runner.thread_msg_target(),
Some(subclass_input.event_loop_runner.thread_msg_target()),
None,
None,
HRGN::default(),
RDW_INTERNALPAINT,
);

Expand Down Expand Up @@ -1049,7 +1056,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
let mut state = subclass_input.window_state.lock();
if state.dragging {
state.dragging = false;
let _ = unsafe { PostMessageW(window, WM_LBUTTONUP, WPARAM::default(), lparam) };
let _ = unsafe { PostMessageW(Some(window), WM_LBUTTONUP, WPARAM::default(), lparam) };
}
state.set_window_flags_in_place(|f| f.remove(WindowFlags::MARKER_IN_SIZE_MOVE));
result = ProcResult::Value(LRESULT(0));
Expand All @@ -1060,7 +1067,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
}
win32wm::WM_NCLBUTTONDOWN => {
if wparam.0 == HTCAPTION as _ {
let _ = PostMessageW(window, WM_MOUSEMOVE, WPARAM(0), lparam);
let _ = PostMessageW(Some(window), WM_MOUSEMOVE, WPARAM(0), lparam);
}

use crate::event::WindowEvent::DecorationsClick;
Expand Down Expand Up @@ -1100,7 +1107,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
if subclass_input.event_loop_runner.should_buffer() {
// this branch can happen in response to `UpdateWindow`, if win32 decides to
// redraw the window outside the normal flow of the event loop.
let _ = RedrawWindow(window, None, HRGN::default(), RDW_INTERNALPAINT);
let _ = RedrawWindow(Some(window), None, None, RDW_INTERNALPAINT);
} else {
let managing_redraw = flush_paint_messages(Some(window), &subclass_input.event_loop_runner);
subclass_input.send_event(Event::RedrawRequested(RootWindowId(WindowId(
Expand All @@ -1121,7 +1128,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
if GetClientRect(window, &mut rc).is_ok() {
let brush = CreateSolidBrush(util::RGB(color.0, color.1, color.2));
FillRect(hdc, &rc, brush);
let _ = DeleteObject(brush);
let _ = DeleteObject(brush.into());

result = ProcResult::Value(LRESULT(1));
} else {
Expand Down Expand Up @@ -1807,8 +1814,8 @@ unsafe fn public_window_callback_inner<T: 'static>(

match set_cursor_to {
Some(cursor) => {
if let Ok(cursor) = LoadCursorW(HMODULE::default(), cursor.to_windows_cursor()) {
SetCursor(cursor);
if let Ok(cursor) = LoadCursorW(None, cursor.to_windows_cursor()) {
SetCursor(Some(cursor));
}
result = ProcResult::Value(LRESULT(0));
}
Expand Down Expand Up @@ -2084,7 +2091,7 @@ unsafe fn public_window_callback_inner<T: 'static>(

let _ = SetWindowPos(
window,
HWND::default(),
None,
new_outer_rect.left,
new_outer_rect.top,
new_outer_rect.right - new_outer_rect.left,
Expand Down Expand Up @@ -2287,21 +2294,21 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
win32wm::WM_NCDESTROY => {
remove_event_target_window_subclass::<T>(window);
subclass_removed = true;
let _ = RedrawWindow(window, None, HRGN::default(), RDW_INTERNALPAINT);
let _ = RedrawWindow(Some(window), None, None, RDW_INTERNALPAINT);
LRESULT(0)
}
// Because WM_PAINT comes after all other messages, we use it during modal loops to detect
// when the event queue has been emptied. See `process_event` for more details.
win32wm::WM_PAINT => {
let _ = ValidateRect(window, None);
let _ = ValidateRect(Some(window), None);
// If the WM_PAINT handler in `public_window_callback` has already flushed the redraw
// events, `handling_events` will return false and we won't emit a second
// `RedrawEventsCleared` event.
if subclass_input.event_loop_runner.handling_events() {
if subclass_input.event_loop_runner.should_buffer() {
// This branch can be triggered when a nested win32 event loop is triggered
// inside of the `event_handler` callback.
let _ = RedrawWindow(window, None, HRGN::default(), RDW_INTERNALPAINT);
let _ = RedrawWindow(Some(window), None, None, RDW_INTERNALPAINT);
} else {
// This WM_PAINT handler will never be re-entrant because `flush_paint_messages`
// doesn't call WM_PAINT for the thread event target (i.e. this window).
Expand Down Expand Up @@ -2329,15 +2336,15 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
device_id: wrap_device_id(lparam.0),
event,
});
let _ = RedrawWindow(window, None, HRGN::default(), RDW_INTERNALPAINT);
let _ = RedrawWindow(Some(window), None, None, RDW_INTERNALPAINT);

LRESULT(0)
}

win32wm::WM_INPUT => {
if let Some(data) = raw_input::get_raw_input_data(HRAWINPUT(lparam.0 as _)) {
handle_raw_input(&subclass_input, data);
let _ = RedrawWindow(window, None, HRGN::default(), RDW_INTERNALPAINT);
let _ = RedrawWindow(Some(window), None, None, RDW_INTERNALPAINT);
}

DefSubclassProc(window, msg, wparam, lparam)
Expand All @@ -2347,13 +2354,13 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
if let Ok(event) = subclass_input.user_event_receiver.recv() {
subclass_input.send_event(Event::UserEvent(event));
}
let _ = RedrawWindow(window, None, HRGN::default(), RDW_INTERNALPAINT);
let _ = RedrawWindow(Some(window), None, None, RDW_INTERNALPAINT);
LRESULT(0)
}
_ if msg == *EXEC_MSG_ID => {
let mut function: ThreadExecFn = Box::from_raw(wparam.0 as *mut _);
function();
let _ = RedrawWindow(window, None, HRGN::default(), RDW_INTERNALPAINT);
let _ = RedrawWindow(Some(window), None, None, RDW_INTERNALPAINT);
LRESULT(0)
}
_ if msg == *PROCESS_NEW_EVENTS_MSG_ID => {
Expand All @@ -2369,7 +2376,7 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
if let ControlFlow::WaitUntil(wait_until) = subclass_input.event_loop_runner.control_flow() {
let mut msg = MSG::default();
while Instant::now() < wait_until {
if PeekMessageW(&mut msg, HWND::default(), 0, 0, PM_NOREMOVE).as_bool() {
if PeekMessageW(&mut msg, None, 0, 0, PM_NOREMOVE).as_bool() {
// This works around a "feature" in PeekMessageW. If the message PeekMessageW
// gets is a WM_PAINT message that had RDW_INTERNALPAINT set (i.e. doesn't
// have an update region), PeekMessageW will remove that window from the
Expand All @@ -2379,7 +2386,7 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
if msg.message == WM_PAINT {
let mut rect = RECT::default();
if !GetUpdateRect(msg.hwnd, Some(&mut rect), false).as_bool() {
let _ = RedrawWindow(msg.hwnd, None, HRGN::default(), RDW_INTERNALPAINT);
let _ = RedrawWindow(Some(msg.hwnd), None, None, RDW_INTERNALPAINT);
}
}

Expand All @@ -2388,7 +2395,7 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
}
}
subclass_input.event_loop_runner.poll();
let _ = RedrawWindow(window, None, HRGN::default(), RDW_INTERNALPAINT);
let _ = RedrawWindow(Some(window), None, None, RDW_INTERNALPAINT);
LRESULT(0)
}
_ => DefSubclassProc(window, msg, wparam, lparam),
Expand Down
Loading

0 comments on commit 543e117

Please sign in to comment.