Skip to content

Commit

Permalink
Update to windows-sys 0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
clemenswasser committed Feb 5, 2022
1 parent 77cb0cd commit ec8c469
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 61 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Expand Up @@ -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",
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/windows/dark_mode.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -80,7 +80,7 @@ pub fn try_theme(hwnd: HWND, preferred_theme: Option<Theme>) -> 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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/windows/drop_handler.rs
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/windows/event.rs
Expand Up @@ -119,12 +119,12 @@ pub fn get_pressed_keys() -> impl Iterator<Item = VIRTUAL_KEY> {
}

unsafe fn get_char(keyboard_state: &[u8; 256], v_key: u32, hkl: HKL) -> Option<char> {
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,
Expand Down
34 changes: 16 additions & 18 deletions src/platform_impl/windows/event_loop.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -580,51 +578,51 @@ 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.
// WPARAM contains a Box<Box<dyn FnMut()>> that must be retrieved with `Box::from_raw`,
// 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<Instant>` 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<u16> = util::encode_wide("Winit Thread Event Target");
}
Expand All @@ -637,12 +635,12 @@ fn create_event_target_window<T: 'static>() -> HWND {
lpfnWndProc: Some(thread_event_target_callback::<T>),
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,
};

Expand All @@ -662,17 +660,17 @@ fn create_event_target_window<T: 'static>() -> 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,
0,
0,
0,
0,
GetModuleHandleW(ptr::null_mut()),
ptr::null_mut(),
GetModuleHandleW(ptr::null()),
ptr::null(),
);

super::set_window_long(
Expand Down
14 changes: 7 additions & 7 deletions src/platform_impl/windows/icon.rs
Expand Up @@ -22,11 +22,11 @@ impl Pixel {

impl RgbaIcon {
fn into_windows_icon(self) -> Result<WinIcon, BadIcon> {
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();
Expand Down Expand Up @@ -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()))
Expand All @@ -108,15 +108,15 @@ 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,
height as i32,
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()))
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/windows/monitor.rs
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/windows/raw_input.rs
Expand Up @@ -116,7 +116,7 @@ pub fn get_raw_input_device_name(handle: HANDLE) -> Option<String> {
GetRawInputDeviceInfoW(
handle,
RIDI_DEVICENAME,
name.as_mut_ptr() as _,
name.as_ptr() as _,
&mut minimum_size,
)
};
Expand Down
7 changes: 3 additions & 4 deletions src/platform_impl/windows/util.rs
Expand Up @@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ec8c469

Please sign in to comment.