From ec8c469d1bb7e4d1942516b3fb460302bc93ec5d Mon Sep 17 00:00:00 2001 From: Clemens Wasser Date: Fri, 4 Feb 2022 21:54:10 +0100 Subject: [PATCH] Update to windows-sys 0.32 --- Cargo.toml | 6 ++-- src/platform_impl/windows/dark_mode.rs | 8 +++--- src/platform_impl/windows/drop_handler.rs | 6 ++-- src/platform_impl/windows/event.rs | 4 +-- src/platform_impl/windows/event_loop.rs | 34 +++++++++++------------ src/platform_impl/windows/icon.rs | 14 +++++----- src/platform_impl/windows/monitor.rs | 4 +-- src/platform_impl/windows/raw_input.rs | 2 +- src/platform_impl/windows/util.rs | 7 ++--- src/platform_impl/windows/window.rs | 33 +++++++++++----------- 10 files changed, 57 insertions(+), 61 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c00f1a367d..d19ded7c39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,10 +55,10 @@ default_features = false features = ["display_link"] [target.'cfg(target_os = "windows")'.dependencies] -parking_lot = "0.11" +parking_lot = "0.12" [target.'cfg(target_os = "windows")'.dependencies.windows-sys] -version = "0.29" +version = "0.32" features = [ "Win32_Devices_HumanInterfaceDevice", "Win32_Foundation", @@ -93,7 +93,7 @@ sctk = { package = "smithay-client-toolkit", version = "0.15.1", default_feature mio = { version = "0.8", features = ["os-ext"], optional = true } x11-dl = { version = "2.18.5", optional = true } percent-encoding = { version = "2.0", optional = true } -parking_lot = { version = "0.11.0", optional = true } +parking_lot = { version = "0.12.0", optional = true } libc = "0.2.64" [target.'cfg(target_arch = "wasm32")'.dependencies.web_sys] diff --git a/src/platform_impl/windows/dark_mode.rs b/src/platform_impl/windows/dark_mode.rs index 07c496f776..ebbd516bdf 100644 --- a/src/platform_impl/windows/dark_mode.rs +++ b/src/platform_impl/windows/dark_mode.rs @@ -3,7 +3,7 @@ use std::{ffi::c_void, ptr}; use windows_sys::Win32::{ - Foundation::{BOOL, HWND, NTSTATUS, PSTR, PWSTR, S_OK}, + Foundation::{BOOL, HWND, NTSTATUS, PSTR, S_OK}, System::{ LibraryLoader::{GetProcAddress, LoadLibraryA}, SystemInformation::OSVERSIONINFOW, @@ -80,7 +80,7 @@ pub fn try_theme(hwnd: HWND, preferred_theme: Option) -> Theme { Theme::Light => LIGHT_THEME_NAME.as_ptr(), }; - let status = unsafe { SetWindowTheme(hwnd, theme_name as PWSTR, ptr::null_mut()) }; + let status = unsafe { SetWindowTheme(hwnd, theme_name, ptr::null()) }; if status == S_OK && set_dark_mode_for_window(hwnd, is_dark_mode) { return theme; @@ -146,7 +146,7 @@ fn should_apps_use_dark_mode() -> bool { unsafe { const UXTHEME_SHOULDAPPSUSEDARKMODE_ORDINAL: PSTR = 132 as PSTR; - let module = LoadLibraryA("uxtheme.dll\0".as_ptr() as PSTR); + let module = LoadLibraryA("uxtheme.dll\0".as_ptr()); if module == 0 { return None; @@ -168,7 +168,7 @@ fn is_high_contrast() -> bool { let mut hc = HIGHCONTRASTA { cbSize: 0, dwFlags: 0, - lpszDefaultScheme: ptr::null_mut(), + lpszDefaultScheme: ptr::null(), }; let ok = unsafe { diff --git a/src/platform_impl/windows/drop_handler.rs b/src/platform_impl/windows/drop_handler.rs index fc048c8622..cd36309955 100644 --- a/src/platform_impl/windows/drop_handler.rs +++ b/src/platform_impl/windows/drop_handler.rs @@ -180,18 +180,18 @@ impl FileDropHandler { let hdrop = medium.Anonymous.hGlobal; // The second parameter (0xFFFFFFFF) instructs the function to return the item count - let item_count = DragQueryFileW(hdrop, 0xFFFFFFFF, ptr::null_mut(), 0); + let item_count = DragQueryFileW(hdrop, 0xFFFFFFFF, ptr::null(), 0); for i in 0..item_count { // Get the length of the path string NOT including the terminating null character. // Previously, this was using a fixed size array of MAX_PATH length, but the // Windows API allows longer paths under certain circumstances. - let character_count = DragQueryFileW(hdrop, i, ptr::null_mut(), 0) as usize; + let character_count = DragQueryFileW(hdrop, i, ptr::null(), 0) as usize; let str_len = character_count + 1; // Fill path_buf with the null-terminated file name let mut path_buf = Vec::with_capacity(str_len); - DragQueryFileW(hdrop, i, path_buf.as_mut_ptr(), str_len as u32); + DragQueryFileW(hdrop, i, path_buf.as_ptr(), str_len as u32); path_buf.set_len(str_len); callback(OsString::from_wide(&path_buf[0..character_count]).into()); diff --git a/src/platform_impl/windows/event.rs b/src/platform_impl/windows/event.rs index fba3d5ae4c..2f5e2be4e2 100644 --- a/src/platform_impl/windows/event.rs +++ b/src/platform_impl/windows/event.rs @@ -119,12 +119,12 @@ pub fn get_pressed_keys() -> impl Iterator { } unsafe fn get_char(keyboard_state: &[u8; 256], v_key: u32, hkl: HKL) -> Option { - let mut unicode_bytes = [0u16; 5]; + let unicode_bytes = [0u16; 5]; let len = ToUnicodeEx( v_key, 0, keyboard_state.as_ptr(), - unicode_bytes.as_mut_ptr(), + unicode_bytes.as_ptr(), unicode_bytes.len() as _, 0, hkl, diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 90b68e003a..90f363c0e9 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -19,9 +19,7 @@ use std::{ use windows_sys::Win32::{ Devices::HumanInterfaceDevice::MOUSE_MOVE_RELATIVE, - Foundation::{ - BOOL, HANDLE, HWND, LPARAM, LRESULT, POINT, PSTR, PWSTR, RECT, WAIT_TIMEOUT, WPARAM, - }, + Foundation::{BOOL, HANDLE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_TIMEOUT, WPARAM}, Graphics::Gdi::{ ClientToScreen, GetMonitorInfoW, GetUpdateRect, MonitorFromRect, MonitorFromWindow, RedrawWindow, ScreenToClient, ValidateRect, MONITORINFO, MONITOR_DEFAULTTONULL, @@ -580,7 +578,7 @@ lazy_static! { // WPARAM and LPARAM are unused. static ref USER_EVENT_MSG_ID: u32 = { unsafe { - RegisterWindowMessageA("Winit::WakeupMsg\0".as_ptr() as PSTR) + RegisterWindowMessageA("Winit::WakeupMsg\0".as_ptr()) } }; // Message sent when we want to execute a closure in the thread. @@ -588,43 +586,43 @@ lazy_static! { // and LPARAM is unused. static ref EXEC_MSG_ID: u32 = { unsafe { - RegisterWindowMessageA("Winit::ExecMsg\0".as_ptr() as PSTR) + RegisterWindowMessageA("Winit::ExecMsg\0".as_ptr()) } }; static ref PROCESS_NEW_EVENTS_MSG_ID: u32 = { unsafe { - RegisterWindowMessageA("Winit::ProcessNewEvents\0".as_ptr() as PSTR) + RegisterWindowMessageA("Winit::ProcessNewEvents\0".as_ptr()) } }; /// lparam is the wait thread's message id. static ref SEND_WAIT_THREAD_ID_MSG_ID: u32 = { unsafe { - RegisterWindowMessageA("Winit::SendWaitThreadId\0".as_ptr() as PSTR) + RegisterWindowMessageA("Winit::SendWaitThreadId\0".as_ptr()) } }; /// lparam points to a `Box` signifying the time `PROCESS_NEW_EVENTS_MSG_ID` should /// be sent. static ref WAIT_UNTIL_MSG_ID: u32 = { unsafe { - RegisterWindowMessageA("Winit::WaitUntil\0".as_ptr() as PSTR) + RegisterWindowMessageA("Winit::WaitUntil\0".as_ptr()) } }; static ref CANCEL_WAIT_UNTIL_MSG_ID: u32 = { unsafe { - RegisterWindowMessageA("Winit::CancelWaitUntil\0".as_ptr() as PSTR) + RegisterWindowMessageA("Winit::CancelWaitUntil\0".as_ptr()) } }; // Message sent by a `Window` when it wants to be destroyed by the main thread. // WPARAM and LPARAM are unused. pub static ref DESTROY_MSG_ID: u32 = { unsafe { - RegisterWindowMessageA("Winit::DestroyMsg\0".as_ptr() as PSTR) + RegisterWindowMessageA("Winit::DestroyMsg\0".as_ptr()) } }; // WPARAM is a bool specifying the `WindowFlags::MARKER_RETAIN_STATE_ON_SIZE` flag. See the // documentation in the `window_state` module for more information. pub static ref SET_RETAIN_STATE_ON_SIZE_MSG_ID: u32 = unsafe { - RegisterWindowMessageA("Winit::SetRetainMaximized\0".as_ptr() as PSTR) + RegisterWindowMessageA("Winit::SetRetainMaximized\0".as_ptr()) }; static ref THREAD_EVENT_TARGET_WINDOW_CLASS: Vec = util::encode_wide("Winit Thread Event Target"); } @@ -637,12 +635,12 @@ fn create_event_target_window() -> HWND { lpfnWndProc: Some(thread_event_target_callback::), cbClsExtra: 0, cbWndExtra: 0, - hInstance: GetModuleHandleW(ptr::null_mut()), + hInstance: GetModuleHandleW(ptr::null()), hIcon: 0, hCursor: 0, // must be null in order for cursor state to work properly hbrBackground: 0, - lpszMenuName: ptr::null_mut(), - lpszClassName: THREAD_EVENT_TARGET_WINDOW_CLASS.as_ptr() as PWSTR, + lpszMenuName: ptr::null(), + lpszClassName: THREAD_EVENT_TARGET_WINDOW_CLASS.as_ptr(), hIconSm: 0, }; @@ -662,8 +660,8 @@ fn create_event_target_window() -> HWND { // `explorer.exe` and then starting the process back up. // It is unclear why the bug is triggered by waiting for several hours. | WS_EX_TOOLWINDOW, - THREAD_EVENT_TARGET_WINDOW_CLASS.as_ptr() as PWSTR, - ptr::null_mut(), + THREAD_EVENT_TARGET_WINDOW_CLASS.as_ptr(), + ptr::null(), WS_OVERLAPPED, 0, 0, @@ -671,8 +669,8 @@ fn create_event_target_window() -> HWND { 0, 0, 0, - GetModuleHandleW(ptr::null_mut()), - ptr::null_mut(), + GetModuleHandleW(ptr::null()), + ptr::null(), ); super::set_window_long( diff --git a/src/platform_impl/windows/icon.rs b/src/platform_impl/windows/icon.rs index 387f44aff4..2c65e835b8 100644 --- a/src/platform_impl/windows/icon.rs +++ b/src/platform_impl/windows/icon.rs @@ -22,11 +22,11 @@ impl Pixel { impl RgbaIcon { fn into_windows_icon(self) -> Result { - let mut rgba = self.rgba; + let rgba = self.rgba; let pixel_count = rgba.len() / PIXEL_SIZE; let mut and_mask = Vec::with_capacity(pixel_count); let pixels = - unsafe { std::slice::from_raw_parts_mut(rgba.as_mut_ptr() as *mut Pixel, pixel_count) }; + unsafe { std::slice::from_raw_parts_mut(rgba.as_ptr() as *mut Pixel, pixel_count) }; for pixel in pixels { and_mask.push(pixel.a.wrapping_sub(std::u8::MAX)); // invert alpha channel pixel.to_bgra(); @@ -81,19 +81,19 @@ impl WinIcon { // width / height of 0 along with LR_DEFAULTSIZE tells windows to load the default icon size let (width, height) = size.map(Into::into).unwrap_or((0, 0)); - let mut wide_path = util::encode_wide(path.as_ref()); + let wide_path = util::encode_wide(path.as_ref()); let handle = unsafe { LoadImageW( 0, - wide_path.as_mut_ptr(), + wide_path.as_ptr(), IMAGE_ICON, width as i32, height as i32, LR_DEFAULTSIZE | LR_LOADFROMFILE, ) }; - if !handle.is_null() { + if handle != 0 { Ok(WinIcon::from_handle(handle as HICON)) } else { Err(BadIcon::OsError(io::Error::last_os_error())) @@ -108,7 +108,7 @@ impl WinIcon { let (width, height) = size.map(Into::into).unwrap_or((0, 0)); let handle = unsafe { LoadImageW( - GetModuleHandleW(ptr::null_mut()), + GetModuleHandleW(ptr::null()), resource_id as PWSTR, IMAGE_ICON, width as i32, @@ -116,7 +116,7 @@ impl WinIcon { LR_DEFAULTSIZE, ) }; - if !handle.is_null() { + if handle != 0 { Ok(WinIcon::from_handle(handle as HICON)) } else { Err(BadIcon::OsError(io::Error::last_os_error())) diff --git a/src/platform_impl/windows/monitor.rs b/src/platform_impl/windows/monitor.rs index 1b76128e29..1aacd58305 100644 --- a/src/platform_impl/windows/monitor.rs +++ b/src/platform_impl/windows/monitor.rs @@ -217,8 +217,8 @@ impl MonitorHandle { loop { unsafe { - let mut monitor_info = get_monitor_info(self.0).unwrap(); - let device_name = monitor_info.szDevice.as_mut_ptr(); + let monitor_info = get_monitor_info(self.0).unwrap(); + let device_name = monitor_info.szDevice.as_ptr(); let mut mode: DEVMODEW = mem::zeroed(); mode.dmSize = mem::size_of_val(&mode) as u16; if EnumDisplaySettingsExW(device_name, i, &mut mode, 0) == false.into() { diff --git a/src/platform_impl/windows/raw_input.rs b/src/platform_impl/windows/raw_input.rs index 5f2ffb9fc4..46a6683044 100644 --- a/src/platform_impl/windows/raw_input.rs +++ b/src/platform_impl/windows/raw_input.rs @@ -116,7 +116,7 @@ pub fn get_raw_input_device_name(handle: HANDLE) -> Option { GetRawInputDeviceInfoW( handle, RIDI_DEVICENAME, - name.as_mut_ptr() as _, + name.as_ptr() as _, &mut minimum_size, ) }; diff --git a/src/platform_impl/windows/util.rs b/src/platform_impl/windows/util.rs index 362292f31c..d24ce4a3ee 100644 --- a/src/platform_impl/windows/util.rs +++ b/src/platform_impl/windows/util.rs @@ -12,7 +12,7 @@ use std::{ use windows_sys::{ core::HRESULT, Win32::{ - Foundation::{BOOL, HWND, PSTR, PWSTR, RECT}, + Foundation::{BOOL, HWND, PWSTR, RECT}, Graphics::Gdi::{ClientToScreen, InvalidateRgn, HMONITOR}, System::LibraryLoader::{GetProcAddress, LoadLibraryA}, UI::{ @@ -233,13 +233,12 @@ pub(super) fn get_function_impl(library: &str, function: &str) -> Option<*const assert_eq!(function.chars().last(), Some('\0')); // Library names we will use are ASCII so we can use the A version to avoid string conversion. - let module = unsafe { LoadLibraryA(library.as_ptr() as PSTR) }; + let module = unsafe { LoadLibraryA(library.as_ptr()) }; if module == 0 { return None; } - unsafe { GetProcAddress(module, function.as_ptr() as PSTR) } - .map(|function_ptr| function_ptr as _) + unsafe { GetProcAddress(module, function.as_ptr()) }.map(|function_ptr| function_ptr as _) } macro_rules! get_function { diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index f0aa226ca5..002471b0a1 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -101,9 +101,9 @@ impl Window { } pub fn set_title(&self, text: &str) { - let mut wide_text = util::encode_wide(text); + let wide_text = util::encode_wide(text); unsafe { - SetWindowTextW(self.hwnd(), wide_text.as_mut_ptr()); + SetWindowTextW(self.hwnd(), wide_text.as_ptr()); } } @@ -428,7 +428,7 @@ impl Window { &native_video_mode, 0, CDS_FULLSCREEN, - ptr::null_mut(), + ptr::null(), ) }; @@ -442,11 +442,11 @@ impl Window { | (&Some(Fullscreen::Exclusive(_)), &Some(Fullscreen::Borderless(_))) => { let res = unsafe { ChangeDisplaySettingsExW( - ptr::null_mut(), - ptr::null_mut(), + ptr::null(), + ptr::null(), 0, CDS_FULLSCREEN, - ptr::null_mut(), + ptr::null(), ) }; @@ -862,10 +862,9 @@ unsafe fn init( where T: 'static, { - let mut title = util::encode_wide(&attributes.title); + let title = util::encode_wide(&attributes.title); - let mut class_name = - register_window_class::(&attributes.window_icon, &pl_attribs.taskbar_icon); + let class_name = register_window_class::(&attributes.window_icon, &pl_attribs.taskbar_icon); let mut window_flags = WindowFlags::empty(); window_flags.set(WindowFlags::DECORATIONS, attributes.decorations); @@ -907,8 +906,8 @@ where let (style, ex_style) = window_flags.to_window_styles(); let handle = CreateWindowExW( ex_style, - class_name.as_mut_ptr(), - title.as_mut_ptr(), + class_name.as_ptr(), + title.as_ptr(), style, CW_USEDEFAULT, CW_USEDEFAULT, @@ -916,7 +915,7 @@ where CW_USEDEFAULT, parent.unwrap_or(0), pl_attribs.menu.unwrap_or(0), - GetModuleHandleW(ptr::null_mut()), + GetModuleHandleW(ptr::null()), &mut initdata as *mut _ as *mut _, ); @@ -938,7 +937,7 @@ unsafe fn register_window_class( window_icon: &Option, taskbar_icon: &Option, ) -> Vec { - let mut class_name = util::encode_wide("Window Class"); + let class_name = util::encode_wide("Window Class"); let h_icon = taskbar_icon .as_ref() @@ -955,12 +954,12 @@ unsafe fn register_window_class( lpfnWndProc: Some(super::event_loop::public_window_callback::), cbClsExtra: 0, cbWndExtra: 0, - hInstance: GetModuleHandleW(ptr::null_mut()), + hInstance: GetModuleHandleW(ptr::null()), hIcon: h_icon, hCursor: 0, // must be null in order for cursor state to work properly hbrBackground: 0, - lpszMenuName: ptr::null_mut(), - lpszClassName: class_name.as_mut_ptr(), + lpszMenuName: ptr::null(), + lpszClassName: class_name.as_ptr(), hIconSm: h_icon_small, }; @@ -983,7 +982,7 @@ impl Drop for ComInitialized { thread_local! { static COM_INITIALIZED: ComInitialized = { unsafe { - CoInitializeEx(ptr::null_mut(), COINIT_APARTMENTTHREADED); + CoInitializeEx(ptr::null(), COINIT_APARTMENTTHREADED); ComInitialized(ptr::null_mut()) } };