From 543e1177ee0cba01af0109806e8e7468497ab913 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:53:51 +0800 Subject: [PATCH] chore(deps): update windows to 0.59 (#1044) --- .changes/windows-0.59.md | 5 ++ Cargo.toml | 5 +- src/platform_impl/windows/dark_mode.rs | 12 +-- src/platform_impl/windows/dpi.rs | 4 +- src/platform_impl/windows/drop_handler.rs | 9 ++- src/platform_impl/windows/event_loop.rs | 75 ++++++++++--------- .../windows/event_loop/runner.rs | 9 +-- src/platform_impl/windows/icon.rs | 19 +++-- src/platform_impl/windows/keyboard.rs | 17 +++-- src/platform_impl/windows/keyboard_layout.rs | 11 +-- src/platform_impl/windows/minimal_ime.rs | 2 +- src/platform_impl/windows/monitor.rs | 2 +- src/platform_impl/windows/raw_input.rs | 7 +- src/platform_impl/windows/util.rs | 12 +-- src/platform_impl/windows/window.rs | 43 ++++++----- src/platform_impl/windows/window_state.rs | 34 +++++---- 16 files changed, 145 insertions(+), 121 deletions(-) create mode 100644 .changes/windows-0.59.md diff --git a/.changes/windows-0.59.md b/.changes/windows-0.59.md new file mode 100644 index 000000000..cebcfcba2 --- /dev/null +++ b/.changes/windows-0.59.md @@ -0,0 +1,5 @@ +--- +tao: patch +--- + +Update `windows` to 0.59 diff --git a/Cargo.toml b/Cargo.toml index 995cdaf76..75728cac6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", diff --git a/src/platform_impl/windows/dark_mode.rs b/src/platform_impl/windows/dark_mode.rs index 633a89385..0f147b651 100644 --- a/src/platform_impl/windows/dark_mode.rs +++ b/src/platform_impl/windows/dark_mode.rs @@ -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::*}, @@ -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 { @@ -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()); } } } diff --git a/src/platform_impl/windows/dpi.rs b/src/platform_impl/windows/dpi.rs index 7b185ac90..2a8ee77eb 100644 --- a/src/platform_impl/windows/dpi.rs +++ b/src/platform_impl/windows/dpi.rs @@ -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!"); } @@ -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 diff --git a/src/platform_impl/windows/drop_handler.rs b/src/platform_impl/windows/drop_handler.rs index 3cfa04192..efbe8297e 100644 --- a/src/platform_impl/windows/drop_handler.rs +++ b/src/platform_impl/windows/drop_handler.rs @@ -41,7 +41,10 @@ impl FileDropHandler { } } - unsafe fn iterate_filenames(data_obj: Option<&IDataObject>, callback: F) -> Option + unsafe fn iterate_filenames( + data_obj: windows_core::Ref<'_, IDataObject>, + callback: F, + ) -> Option where F: Fn(PathBuf), { @@ -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, @@ -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, diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index cc8d22384..88d133253 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -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::{ @@ -245,7 +245,7 @@ impl EventLoop { 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; } @@ -335,7 +335,7 @@ impl EventLoopWindowTarget { pub fn set_theme(&self, theme: Option) { *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) }; }); } } @@ -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, ); @@ -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); @@ -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), @@ -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), @@ -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), @@ -561,7 +561,14 @@ impl Clone for EventLoopProxy { impl EventLoopProxy { pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> { 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 { @@ -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, ) }; @@ -814,7 +821,7 @@ unsafe fn flush_paint_messages( if !PeekMessageW( &mut msg, - redraw_window, + Some(redraw_window), WM_PAINT, WM_PAINT, PM_REMOVE | PM_QS_PAINT, @@ -837,7 +844,7 @@ unsafe fn process_control_flow(runner: &EventLoopRunner) { 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), @@ -955,9 +962,9 @@ unsafe fn public_window_callback_inner( subclass_input: &SubclassInput, ) -> 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, ); @@ -1049,7 +1056,7 @@ unsafe fn public_window_callback_inner( 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)); @@ -1060,7 +1067,7 @@ unsafe fn public_window_callback_inner( } 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; @@ -1100,7 +1107,7 @@ unsafe fn public_window_callback_inner( 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( @@ -1121,7 +1128,7 @@ unsafe fn public_window_callback_inner( 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 { @@ -1807,8 +1814,8 @@ unsafe fn public_window_callback_inner( 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)); } @@ -2084,7 +2091,7 @@ unsafe fn public_window_callback_inner( let _ = SetWindowPos( window, - HWND::default(), + None, new_outer_rect.left, new_outer_rect.top, new_outer_rect.right - new_outer_rect.left, @@ -2287,13 +2294,13 @@ unsafe extern "system" fn thread_event_target_callback( win32wm::WM_NCDESTROY => { remove_event_target_window_subclass::(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. @@ -2301,7 +2308,7 @@ unsafe extern "system" fn thread_event_target_callback( 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). @@ -2329,7 +2336,7 @@ unsafe extern "system" fn thread_event_target_callback( 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) } @@ -2337,7 +2344,7 @@ unsafe extern "system" fn thread_event_target_callback( 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) @@ -2347,13 +2354,13 @@ unsafe extern "system" fn thread_event_target_callback( 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 => { @@ -2369,7 +2376,7 @@ unsafe extern "system" fn thread_event_target_callback( 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 @@ -2379,7 +2386,7 @@ unsafe extern "system" fn thread_event_target_callback( 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); } } @@ -2388,7 +2395,7 @@ unsafe extern "system" fn thread_event_target_callback( } } 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), diff --git a/src/platform_impl/windows/event_loop/runner.rs b/src/platform_impl/windows/event_loop/runner.rs index 6a7c45138..fcfe2beac 100644 --- a/src/platform_impl/windows/event_loop/runner.rs +++ b/src/platform_impl/windows/event_loop/runner.rs @@ -13,7 +13,7 @@ use std::{ use windows::Win32::{ Foundation::HWND, - Graphics::Gdi::{RedrawWindow, HRGN, RDW_INTERNALPAINT}, + Graphics::Gdi::{RedrawWindow, RDW_INTERNALPAINT}, }; use crate::{ @@ -395,12 +395,7 @@ impl EventLoopRunner { }; self.call_event_handler(Event::NewEvents(start_cause)); self.dispatch_buffered_events(); - let _ = RedrawWindow( - self.thread_msg_target, - None, - HRGN::default(), - RDW_INTERNALPAINT, - ); + let _ = RedrawWindow(Some(self.thread_msg_target), None, None, RDW_INTERNALPAINT); } unsafe fn call_redraw_events_cleared(&self) { diff --git a/src/platform_impl/windows/icon.rs b/src/platform_impl/windows/icon.rs index 5ceab0554..bc281aebc 100644 --- a/src/platform_impl/windows/icon.rs +++ b/src/platform_impl/windows/icon.rs @@ -7,7 +7,7 @@ use std::{fmt, io, iter::once, mem, os::windows::ffi::OsStrExt, path::Path, sync use windows::{ core::PCWSTR, Win32::{ - Foundation::{HMODULE, HWND, LPARAM, WPARAM}, + Foundation::{HWND, LPARAM, WPARAM}, System::LibraryLoader::*, UI::WindowsAndMessaging::*, }, @@ -35,7 +35,7 @@ impl RgbaIcon { assert_eq!(and_mask.len(), pixel_count); let handle = unsafe { CreateIcon( - HMODULE::default(), + None, self.width as i32, self.height as i32, 1, @@ -90,7 +90,7 @@ impl WinIcon { let handle = unsafe { LoadImageW( - HMODULE::default(), + None, PCWSTR::from_raw(wide_path.as_ptr()), IMAGE_ICON, width as i32, @@ -109,7 +109,7 @@ impl WinIcon { let (width, height) = size.map(Into::into).unwrap_or((0, 0)); let handle = unsafe { LoadImageW( - GetModuleHandleW(PCWSTR::null()).unwrap_or_default(), + GetModuleHandleW(PCWSTR::null()).map(Into::into).ok(), PCWSTR::from_raw(resource_id as usize as *const u16), IMAGE_ICON, width as i32, @@ -133,8 +133,8 @@ impl WinIcon { SendMessageW( hwnd, WM_SETICON, - WPARAM(icon_type as _), - LPARAM(self.as_raw_handle().0 as _), + Some(WPARAM(icon_type as _)), + Some(LPARAM(self.as_raw_handle().0 as _)), ); } } @@ -160,6 +160,11 @@ impl fmt::Debug for WinIcon { pub fn unset_for_window(hwnd: HWND, icon_type: IconType) { unsafe { - SendMessageW(hwnd, WM_SETICON, WPARAM(icon_type as _), LPARAM(0)); + SendMessageW( + hwnd, + WM_SETICON, + Some(WPARAM(icon_type as _)), + Some(LPARAM(0)), + ); } } diff --git a/src/platform_impl/windows/keyboard.rs b/src/platform_impl/windows/keyboard.rs index d8cf81386..be565ce5d 100644 --- a/src/platform_impl/windows/keyboard.rs +++ b/src/platform_impl/windows/keyboard.rs @@ -122,7 +122,7 @@ impl KeyEventBuilder { let peek_retval = unsafe { PeekMessageW( next_msg.as_mut_ptr(), - hwnd, + Some(hwnd), WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE, @@ -187,7 +187,7 @@ impl KeyEventBuilder { let mut next_msg = MaybeUninit::uninit(); let has_message = PeekMessageW( next_msg.as_mut_ptr(), - hwnd, + Some(hwnd), WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE, @@ -281,7 +281,7 @@ impl KeyEventBuilder { let peek_retval = unsafe { PeekMessageW( next_msg.as_mut_ptr(), - hwnd, + Some(hwnd), WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE, @@ -439,7 +439,8 @@ impl KeyEventBuilder { locale_id: HKL, layouts: &mut MutexGuard<'_, LayoutCache>, ) -> Option { - let scancode = unsafe { MapVirtualKeyExW(u32::from(vk.0), MAPVK_VK_TO_VSC_EX, locale_id) }; + let scancode = + unsafe { MapVirtualKeyExW(u32::from(vk.0), MAPVK_VK_TO_VSC_EX, Some(locale_id)) }; if scancode == 0 { return None; } @@ -533,7 +534,11 @@ impl PartialKeyEventInfo { // In some cases (often with media keys) the device reports a scancode of 0 but a // valid virtual key. In these cases we obtain the scancode from the virtual key. unsafe { - MapVirtualKeyExW(u32::from(vkey.0), MAPVK_VK_TO_VSC_EX, HKL(layout.hkl as _)) as u16 + MapVirtualKeyExW( + u32::from(vkey.0), + MAPVK_VK_TO_VSC_EX, + Some(HKL(layout.hkl as _)), + ) as u16 } } else { new_ex_scancode(lparam_struct.scancode, lparam_struct.extended) @@ -761,7 +766,7 @@ fn get_location(scancode: ExScancode, hkl: HKL) -> KeyLocation { let extension = 0xE000; let extended = (scancode & extension) == extension; let vkey = - VIRTUAL_KEY(unsafe { MapVirtualKeyExW(scancode as u32, MAPVK_VSC_TO_VK_EX, hkl) } as u16); + VIRTUAL_KEY(unsafe { MapVirtualKeyExW(scancode as u32, MAPVK_VSC_TO_VK_EX, Some(hkl)) } as u16); // Use the native VKEY and the extended flag to cover most cases // This is taken from the `druid` GUI library, specifically diff --git a/src/platform_impl/windows/keyboard_layout.rs b/src/platform_impl/windows/keyboard_layout.rs index 5118f98f8..ec42c4bf5 100644 --- a/src/platform_impl/windows/keyboard_layout.rs +++ b/src/platform_impl/windows/keyboard_layout.rs @@ -298,7 +298,7 @@ impl LayoutCache { layout.numlock_off_keys.reserve(NUMPAD_KEYCODES.len()); for vk in 0_u16..256 { let scancode = - unsafe { MapVirtualKeyExW(u32::from(vk), MAPVK_VK_TO_VSC_EX, locale_id as HKL) }; + unsafe { MapVirtualKeyExW(u32::from(vk), MAPVK_VK_TO_VSC_EX, Some(locale_id as HKL)) }; if scancode == 0 { continue; } @@ -321,7 +321,7 @@ impl LayoutCache { layout.numlock_on_keys.reserve(NUMPAD_VKEYS.len()); for vk in NUMPAD_VKEYS.iter() { let scancode = - unsafe { MapVirtualKeyExW(u32::from(vk.0), MAPVK_VK_TO_VSC_EX, locale_id as HKL) }; + unsafe { MapVirtualKeyExW(u32::from(vk.0), MAPVK_VK_TO_VSC_EX, Some(locale_id as HKL)) }; let unicode = Self::to_unicode_string(&key_state, *vk, scancode, locale_id); if let ToUnicodeResult::Str(s) = unicode { let static_str = get_or_insert_str(strings, s); @@ -344,7 +344,8 @@ impl LayoutCache { // elements. This array is allowed to be indexed by virtual key values // giving the key state for the virtual key used for indexing. for vk in 0_u16..256 { - let scancode = unsafe { MapVirtualKeyExW(u32::from(vk), MAPVK_VK_TO_VSC_EX, locale_id) }; + let scancode = + unsafe { MapVirtualKeyExW(u32::from(vk), MAPVK_VK_TO_VSC_EX, Some(locale_id)) }; if scancode == 0 { continue; } @@ -439,7 +440,7 @@ impl LayoutCache { key_state, &mut label_wide, 0, - locale_id, + Some(locale_id), ); if wide_len < 0 { // If it's dead, we run `ToUnicode` again to consume the dead-key @@ -449,7 +450,7 @@ impl LayoutCache { key_state, &mut label_wide, 0, - locale_id, + Some(locale_id), ); if wide_len > 0 { let os_string = OsString::from_wide(&label_wide[0..wide_len as usize]); diff --git a/src/platform_impl/windows/minimal_ime.rs b/src/platform_impl/windows/minimal_ime.rs index 05055f14d..0e0f1d218 100644 --- a/src/platform_impl/windows/minimal_ime.rs +++ b/src/platform_impl/windows/minimal_ime.rs @@ -57,7 +57,7 @@ impl MinimalIme { let mut next_msg = MaybeUninit::uninit(); let has_message = PeekMessageW( next_msg.as_mut_ptr(), - hwnd, + Some(hwnd), WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE, diff --git a/src/platform_impl/windows/monitor.rs b/src/platform_impl/windows/monitor.rs index e209df746..c69a1390a 100644 --- a/src/platform_impl/windows/monitor.rs +++ b/src/platform_impl/windows/monitor.rs @@ -103,7 +103,7 @@ pub fn available_monitors() -> VecDeque { let mut monitors: VecDeque = VecDeque::new(); unsafe { let _ = EnumDisplayMonitors( - HDC::default(), + None, None, Some(monitor_enum_proc), LPARAM(&mut monitors as *mut _ as _), diff --git a/src/platform_impl/windows/raw_input.rs b/src/platform_impl/windows/raw_input.rs index fe71edeb4..28d43d579 100644 --- a/src/platform_impl/windows/raw_input.rs +++ b/src/platform_impl/windows/raw_input.rs @@ -73,7 +73,7 @@ pub fn get_raw_input_device_info(handle: HANDLE) -> Option { let mut minimum_size = 0; let status = unsafe { GetRawInputDeviceInfoW( - handle, + Some(handle), RIDI_DEVICEINFO, Some(&mut info as *mut _ as _), &mut minimum_size, @@ -91,7 +91,8 @@ pub fn get_raw_input_device_info(handle: HANDLE) -> Option { pub fn get_raw_input_device_name(handle: HANDLE) -> Option { let mut minimum_size = 0; - let status = unsafe { GetRawInputDeviceInfoW(handle, RIDI_DEVICENAME, None, &mut minimum_size) }; + let status = + unsafe { GetRawInputDeviceInfoW(Some(handle), RIDI_DEVICENAME, None, &mut minimum_size) }; if status != 0 { return None; @@ -101,7 +102,7 @@ pub fn get_raw_input_device_name(handle: HANDLE) -> Option { let status = unsafe { GetRawInputDeviceInfoW( - handle, + Some(handle), RIDI_DEVICENAME, Some(name.as_ptr() as _), &mut minimum_size, diff --git a/src/platform_impl/windows/util.rs b/src/platform_impl/windows/util.rs index e24504b2d..54f365c0d 100644 --- a/src/platform_impl/windows/util.rs +++ b/src/platform_impl/windows/util.rs @@ -22,7 +22,7 @@ use windows::{ Win32::{ Foundation::{BOOL, COLORREF, FARPROC, HWND, LPARAM, LRESULT, POINT, RECT, WPARAM}, Globalization::lstrlenW, - Graphics::Gdi::{ClientToScreen, InvalidateRgn, HMONITOR, HRGN}, + Graphics::Gdi::{ClientToScreen, InvalidateRgn, HMONITOR}, System::LibraryLoader::*, UI::{ HiDpi::*, @@ -113,14 +113,14 @@ pub(crate) fn set_inner_size_physical(window: HWND, x: i32, y: i32, is_decorated let outer_y = (rect.top - rect.bottom).abs(); let _ = SetWindowPos( window, - HWND::default(), + None, 0, 0, outer_x, outer_y, SWP_ASYNCWINDOWPOS | SWP_NOZORDER | SWP_NOREPOSITION | SWP_NOMOVE | SWP_NOACTIVATE, ); - let _ = InvalidateRgn(window, HRGN::default(), BOOL::default()); + let _ = InvalidateRgn(window, None, false); } } @@ -145,13 +145,15 @@ pub fn adjust_window_rect_with_styles( style_ex: WINDOW_EX_STYLE, mut rect: RECT, ) -> Option { - let b_menu: BOOL = (!unsafe { GetMenu(hwnd) }.is_invalid()).into(); + let b_menu = !unsafe { GetMenu(hwnd) }.is_invalid(); if let (Some(get_dpi_for_window), Some(adjust_window_rect_ex_for_dpi)) = (*GET_DPI_FOR_WINDOW, *ADJUST_WINDOW_RECT_EX_FOR_DPI) { let dpi = unsafe { get_dpi_for_window(hwnd) }; - if unsafe { adjust_window_rect_ex_for_dpi(&mut rect, style, b_menu, style_ex, dpi) }.as_bool() { + if unsafe { adjust_window_rect_ex_for_dpi(&mut rect, style, b_menu.into(), style_ex, dpi) } + .as_bool() + { Some(rect) } else { None diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index e53837387..648fcd2c7 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -193,7 +193,7 @@ impl Window { #[inline] pub fn request_redraw(&self) { unsafe { - let _ = RedrawWindow(self.window.0, None, HRGN::default(), RDW_INTERNALPAINT); + let _ = RedrawWindow(Some(self.window.0), None, None, RDW_INTERNALPAINT); } } @@ -228,14 +228,14 @@ impl Window { unsafe { let _ = SetWindowPos( self.window.0, - HWND::default(), + None, x, y, 0, 0, SWP_ASYNCWINDOWPOS | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE, ); - let _ = InvalidateRgn(self.window.0, HRGN::default(), false); + let _ = InvalidateRgn(self.window.0, None, false); } } @@ -474,7 +474,7 @@ impl Window { pub fn set_cursor_icon(&self, cursor: CursorIcon) { self.window_state.lock().mouse.cursor = cursor; self.thread_executor.execute_in_thread(move || unsafe { - let cursor = LoadCursorW(HMODULE::default(), cursor.to_windows_cursor()).unwrap_or_default(); + let cursor = LoadCursorW(None, cursor.to_windows_cursor()).ok(); SetCursor(cursor); }); } @@ -556,7 +556,7 @@ impl Window { unsafe { PostMessageW( - self.hwnd(), + Some(self.hwnd()), WM_NCLBUTTONDOWN, wparam, LPARAM(&points as *const _ as _), @@ -733,7 +733,7 @@ impl Window { ChangeDisplaySettingsExW( PCWSTR::from_raw(display_name.as_ptr()), Some(&native_video_mode), - HWND::default(), + None, CDS_FULLSCREEN, None, ) @@ -747,9 +747,8 @@ impl Window { } (&Some(Fullscreen::Exclusive(_)), &None) | (&Some(Fullscreen::Exclusive(_)), &Some(Fullscreen::Borderless(_))) => { - let res = unsafe { - ChangeDisplaySettingsExW(PCWSTR::null(), None, HWND::default(), CDS_FULLSCREEN, None) - }; + let res = + unsafe { ChangeDisplaySettingsExW(PCWSTR::null(), None, None, CDS_FULLSCREEN, None) }; debug_assert!(res != DISP_CHANGE_BADFLAGS); debug_assert!(res != DISP_CHANGE_BADMODE); @@ -770,7 +769,7 @@ impl Window { // fine, taking control back from the DWM and ensuring that the `SetWindowPos` call // below goes through. let mut msg = MSG::default(); - let _ = PeekMessageW(&mut msg, HWND::default(), 0, 0, PM_NOREMOVE); + let _ = PeekMessageW(&mut msg, None, 0, 0, PM_NOREMOVE); } // Update window style @@ -811,14 +810,14 @@ impl Window { unsafe { let _ = SetWindowPos( hwnd, - HWND::default(), + None, position.0, position.1, size.0 as i32, size.1 as i32, SWP_ASYNCWINDOWPOS | SWP_NOZORDER, ); - let _ = InvalidateRgn(hwnd, HRGN::default(), false); + let _ = InvalidateRgn(hwnd, None, false); } } None => { @@ -827,7 +826,7 @@ impl Window { drop(window_state_lock); unsafe { let _ = SetWindowPlacement(hwnd, &placement); - let _ = InvalidateRgn(hwnd, HRGN::default(), false); + let _ = InvalidateRgn(hwnd, None, false); } } } @@ -986,7 +985,7 @@ impl Window { } window_state.preferred_theme = theme; } - unsafe { SendMessageW(self.hwnd(), *CHANGE_THEME_MSG_ID, WPARAM(0), LPARAM(0)) }; + unsafe { SendMessageW(self.hwnd(), *CHANGE_THEME_MSG_ID, None, None) }; } #[inline] @@ -1015,7 +1014,7 @@ impl Window { let l_param = util::MAKELPARAM(x as i16, y as i16); let _ = ReleaseCapture(); - let _ = PostMessageW(self.hwnd(), button, w_param, l_param); + let _ = PostMessageW(Some(self.hwnd()), button, w_param, l_param); } } @@ -1030,7 +1029,7 @@ impl Window { self.window_state.lock().background_color = color; unsafe { - let _ = InvalidateRect(self.hwnd(), None, true); + let _ = InvalidateRect(Some(self.hwnd()), None, true); let _ = UpdateWindow(self.hwnd()); } } @@ -1116,7 +1115,7 @@ impl Drop for Window { unsafe { // The window must be destroyed from the same thread that created it, so we send a // custom message to be handled by our callback to do the actual work. - let _ = PostMessageW(self.window.0, *DESTROY_MSG_ID, WPARAM(0), LPARAM(0)); + let _ = PostMessageW(Some(self.window.0), *DESTROY_MSG_ID, WPARAM(0), LPARAM(0)); } } } @@ -1248,13 +1247,13 @@ unsafe fn init( position.1, adjusted_size.0, adjusted_size.1, - parent.unwrap_or_default(), - pl_attribs.menu.unwrap_or_default(), - GetModuleHandleW(PCWSTR::null()).unwrap_or_default(), + parent, + pl_attribs.menu, + GetModuleHandleW(PCWSTR::null()).map(Into::into).ok(), Some(Box::into_raw(Box::new(window_flags)) as _), )?; - if !IsWindow(handle).as_bool() { + if !IsWindow(Some(handle)).as_bool() { return Err(os_error!(OsError::IoError(io::Error::last_os_error()))); } @@ -1287,7 +1286,7 @@ unsafe fn init( }; let _ = DwmEnableBlurBehindWindow(real_window.0, &bb); - let _ = DeleteObject(region); + let _ = DeleteObject(region.into()); } // If the system theme is dark, we need to set the window theme now diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index 2e14348eb..b179ef388 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -13,7 +13,7 @@ use parking_lot::MutexGuard; use std::io; use windows::Win32::{ Foundation::{HWND, LPARAM, RECT, WPARAM}, - Graphics::Gdi::{InvalidateRgn, HRGN}, + Graphics::Gdi::InvalidateRgn, UI::WindowsAndMessaging::*, }; @@ -335,17 +335,18 @@ impl WindowFlags { unsafe { let _ = SetWindowPos( window, - match new.contains(WindowFlags::ALWAYS_ON_TOP) { - true => HWND_TOPMOST, - false => HWND_NOTOPMOST, - }, + Some(if new.contains(WindowFlags::ALWAYS_ON_TOP) { + HWND_TOPMOST + } else { + HWND_NOTOPMOST + }), 0, 0, 0, 0, SWP_ASYNCWINDOWPOS | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE, ); - let _ = InvalidateRgn(window, HRGN::default(), false); + let _ = InvalidateRgn(window, None, false); } } @@ -353,17 +354,18 @@ impl WindowFlags { unsafe { let _ = SetWindowPos( window, - match new.contains(WindowFlags::ALWAYS_ON_BOTTOM) { - true => HWND_BOTTOM, - false => HWND_NOTOPMOST, - }, + Some(if new.contains(WindowFlags::ALWAYS_ON_BOTTOM) { + HWND_BOTTOM + } else { + HWND_NOTOPMOST + }), 0, 0, 0, 0, SWP_ASYNCWINDOWPOS | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE, ); - let _ = InvalidateRgn(window, HRGN::default(), false); + let _ = InvalidateRgn(window, None, false); } } @@ -423,8 +425,8 @@ impl WindowFlags { SendMessageW( window, *event_loop::SET_RETAIN_STATE_ON_SIZE_MSG_ID, - WPARAM(1), - LPARAM(0), + Some(WPARAM(1)), + Some(LPARAM(0)), ); // This condition is necessary to avoid having an unrestorable window @@ -445,12 +447,12 @@ impl WindowFlags { } // Refresh the window frame - let _ = SetWindowPos(window, HWND::default(), 0, 0, 0, 0, flags); + let _ = SetWindowPos(window, None, 0, 0, 0, 0, flags); SendMessageW( window, *event_loop::SET_RETAIN_STATE_ON_SIZE_MSG_ID, - WPARAM(0), - LPARAM(0), + Some(WPARAM(0)), + Some(LPARAM(0)), ); } }