Skip to content

Commit 23011c6

Browse files
authored
Update to windows-sys 0.59 (#4098)
1 parent 3a39a6d commit 23011c6

17 files changed

+166
-137
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ objc2-ui-kit = { version = "0.3.0", default-features = false, features = [
242242
# Windows
243243
[target.'cfg(target_os = "windows")'.dependencies]
244244
unicode-segmentation = "1.7.1"
245-
windows-sys = { version = "0.52.0", features = [
245+
windows-sys = { version = "0.59.0", features = [
246246
"Win32_Devices_HumanInterfaceDevice",
247247
"Win32_Foundation",
248248
"Win32_Globalization",

src/changelog/unreleased.md

+3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ changelog entry.
182182
whilst files are being dragged over the window. It doesn't contain any file paths, just the
183183
pointer position.
184184
- Updated `objc2` to `v0.6`.
185+
- Updated `windows-sys` to `v0.59`.
186+
- To match the corresponding changes in `windows-sys`, the `HWND`, `HMONITOR`, and `HMENU` types
187+
now alias to `*mut c_void` instead of `isize`.
185188

186189
### Removed
187190

src/platform/windows.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ use crate::monitor::MonitorHandle;
1919
use crate::window::{BadIcon, Icon, Window, WindowAttributes};
2020

2121
/// Window Handle type used by Win32 API
22-
pub type HWND = isize;
22+
pub type HWND = *mut c_void;
2323
/// Menu Handle type used by Win32 API
24-
pub type HMENU = isize;
24+
pub type HMENU = *mut c_void;
2525
/// Monitor Handle type used by Win32 API
26-
pub type HMONITOR = isize;
26+
pub type HMONITOR = *mut c_void;
2727

2828
/// Describes a system-drawn backdrop material of a window.
2929
///

src/platform_impl/windows/dark_mode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn should_apps_use_dark_mode() -> bool {
133133

134134
let module = LoadLibraryA("uxtheme.dll\0".as_ptr());
135135

136-
if module == 0 {
136+
if module.is_null() {
137137
return None;
138138
}
139139

src/platform_impl/windows/definitions.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33

44
use std::ffi::c_void;
55

6-
use windows_sys::core::{IUnknown, GUID, HRESULT};
6+
use windows_sys::core::{GUID, HRESULT};
77
use windows_sys::Win32::Foundation::{BOOL, HWND, POINTL};
8-
use windows_sys::Win32::System::Com::{
9-
IAdviseSink, IDataObject, IEnumFORMATETC, IEnumSTATDATA, FORMATETC, STGMEDIUM,
10-
};
8+
use windows_sys::Win32::System::Com::{FORMATETC, STGMEDIUM};
9+
10+
pub type IUnknown = *mut c_void;
11+
pub type IAdviseSink = *mut c_void;
12+
pub type IDataObject = *mut c_void;
13+
pub type IEnumFORMATETC = *mut c_void;
14+
pub type IEnumSTATDATA = *mut c_void;
1115

1216
#[repr(C)]
1317
pub struct IUnknownVtbl {

src/platform_impl/windows/dpi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn dpi_to_scale_factor(dpi: u32) -> f64 {
7373

7474
pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 {
7575
let hdc = unsafe { GetDC(hwnd) };
76-
if hdc == 0 {
76+
if hdc.is_null() {
7777
panic!("[winit] `GetDC` returned null!");
7878
}
7979
if let Some(GetDpiForWindow) = *GET_DPI_FOR_WINDOW {
@@ -85,7 +85,7 @@ pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 {
8585
} else if let Some(GetDpiForMonitor) = *GET_DPI_FOR_MONITOR {
8686
// We are on Windows 8.1 or later.
8787
let monitor = unsafe { MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST) };
88-
if monitor == 0 {
88+
if monitor.is_null() {
8989
return BASE_DPI;
9090
}
9191

src/platform_impl/windows/drop_handler.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ use std::ptr;
55
use std::sync::atomic::{AtomicUsize, Ordering};
66

77
use tracing::debug;
8-
use windows_sys::core::{IUnknown, GUID, HRESULT};
8+
use windows_sys::core::{GUID, HRESULT};
99
use windows_sys::Win32::Foundation::{DV_E_FORMATETC, HWND, POINT, POINTL, S_OK};
1010
use windows_sys::Win32::Graphics::Gdi::ScreenToClient;
11-
use windows_sys::Win32::System::Com::{IDataObject, DVASPECT_CONTENT, FORMATETC, TYMED_HGLOBAL};
11+
use windows_sys::Win32::System::Com::{DVASPECT_CONTENT, FORMATETC, TYMED_HGLOBAL};
1212
use windows_sys::Win32::System::Ole::{CF_HDROP, DROPEFFECT_COPY, DROPEFFECT_NONE};
1313
use windows_sys::Win32::UI::Shell::{DragFinish, DragQueryFileW, HDROP};
1414

1515
use crate::dpi::PhysicalPosition;
1616
use crate::event::{Event, WindowEvent};
1717
use crate::platform_impl::platform::definitions::{
18-
IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknownVtbl,
18+
IDataObject, IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknown, IUnknownVtbl,
1919
};
2020
use crate::window::WindowId;
2121

src/platform_impl/windows/event_loop.rs

+22-20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::time::{Duration, Instant};
1212
use std::{mem, panic, ptr};
1313

1414
use runner::EventLoopRunner;
15-
use windows_sys::Win32::Devices::HumanInterfaceDevice::MOUSE_MOVE_RELATIVE;
1615
use windows_sys::Win32::Foundation::{
1716
GetLastError, FALSE, HANDLE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_FAILED, WPARAM,
1817
};
@@ -37,7 +36,9 @@ use windows_sys::Win32::UI::Input::Touch::{
3736
CloseTouchInputHandle, GetTouchInputInfo, TOUCHEVENTF_DOWN, TOUCHEVENTF_MOVE,
3837
TOUCHEVENTF_PRIMARY, TOUCHEVENTF_UP, TOUCHINPUT,
3938
};
40-
use windows_sys::Win32::UI::Input::{RAWINPUT, RIM_TYPEKEYBOARD, RIM_TYPEMOUSE};
39+
use windows_sys::Win32::UI::Input::{
40+
MOUSE_MOVE_RELATIVE, RAWINPUT, RIM_TYPEKEYBOARD, RIM_TYPEMOUSE,
41+
};
4142
use windows_sys::Win32::UI::WindowsAndMessaging::{
4243
CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW, GetClientRect, GetCursorPos,
4344
GetMenu, LoadCursorW, MsgWaitForMultipleObjectsEx, PeekMessageW, PostMessageW,
@@ -402,7 +403,7 @@ impl EventLoop {
402403

403404
loop {
404405
unsafe {
405-
if PeekMessageW(&mut msg, 0, 0, 0, PM_REMOVE) == false.into() {
406+
if PeekMessageW(&mut msg, ptr::null_mut(), 0, 0, PM_REMOVE) == false.into() {
406407
break;
407408
}
408409

@@ -634,10 +635,10 @@ fn create_high_resolution_timer() -> Option<OwnedHandle> {
634635
// CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is supported only after
635636
// Win10 1803 but it is already default option for rustc
636637
// (std uses it to implement `std::thread::sleep`).
637-
if handle == 0 {
638+
if handle.is_null() {
638639
None
639640
} else {
640-
Some(OwnedHandle::from_raw_handle(handle as *mut c_void))
641+
Some(OwnedHandle::from_raw_handle(handle))
641642
}
642643
}
643644
}
@@ -807,6 +808,7 @@ pub struct EventLoopProxy {
807808
}
808809

809810
unsafe impl Send for EventLoopProxy {}
811+
unsafe impl Sync for EventLoopProxy {}
810812

811813
impl EventLoopProxyProvider for EventLoopProxy {
812814
fn wake_up(&self) {
@@ -894,12 +896,12 @@ fn create_event_target_window() -> HWND {
894896
cbClsExtra: 0,
895897
cbWndExtra: 0,
896898
hInstance: util::get_instance_handle(),
897-
hIcon: 0,
898-
hCursor: 0, // must be null in order for cursor state to work properly
899-
hbrBackground: 0,
899+
hIcon: ptr::null_mut(),
900+
hCursor: ptr::null_mut(), // must be null in order for cursor state to work properly
901+
hbrBackground: ptr::null_mut(),
900902
lpszMenuName: ptr::null(),
901903
lpszClassName: THREAD_EVENT_TARGET_WINDOW_CLASS.as_ptr(),
902-
hIconSm: 0,
904+
hIconSm: ptr::null_mut(),
903905
};
904906

905907
RegisterClassExW(&class);
@@ -922,8 +924,8 @@ fn create_event_target_window() -> HWND {
922924
0,
923925
0,
924926
0,
925-
0,
926-
0,
927+
ptr::null_mut(),
928+
ptr::null_mut(),
927929
util::get_instance_handle(),
928930
ptr::null(),
929931
);
@@ -1245,7 +1247,7 @@ unsafe fn public_window_callback_inner(
12451247
// after marking `WM_PAINT` as handled.
12461248
result = ProcResult::Value(unsafe { DefWindowProcW(window, msg, wparam, lparam) });
12471249
if std::mem::take(&mut userdata.window_state_lock().redraw_requested) {
1248-
unsafe { RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT) };
1250+
unsafe { RedrawWindow(window, ptr::null(), ptr::null_mut(), RDW_INTERNALPAINT) };
12491251
}
12501252
},
12511253
WM_WINDOWPOSCHANGING => {
@@ -1294,7 +1296,7 @@ unsafe fn public_window_callback_inner(
12941296
let new_monitor = unsafe { MonitorFromRect(&new_rect, MONITOR_DEFAULTTONULL) };
12951297
match fullscreen {
12961298
Fullscreen::Borderless(ref mut fullscreen_monitor) => {
1297-
if new_monitor != 0
1299+
if !new_monitor.is_null()
12981300
&& fullscreen_monitor
12991301
.as_ref()
13001302
.map(|monitor| new_monitor != monitor.hmonitor())
@@ -1741,7 +1743,7 @@ unsafe fn public_window_callback_inner(
17411743
},
17421744

17431745
WM_KEYUP | WM_SYSKEYUP => {
1744-
if msg == WM_SYSKEYUP && unsafe { GetMenu(window) != 0 } {
1746+
if msg == WM_SYSKEYUP && unsafe { !GetMenu(window).is_null() } {
17451747
// let Windows handle event if the window has a native menu, a modal event loop
17461748
// is started here on Alt key up.
17471749
result = ProcResult::DefWindowProc(wparam);
@@ -1973,7 +1975,7 @@ unsafe fn public_window_callback_inner(
19731975
// If it is the same as our window, then we're essentially retaining the capture. This
19741976
// can happen if `SetCapture` is called on our window when it already has the mouse
19751977
// capture.
1976-
if lparam != window {
1978+
if lparam != window as isize {
19771979
userdata.window_state_lock().mouse.capture_count = 0;
19781980
}
19791981
result = ProcResult::Value(0);
@@ -1986,7 +1988,7 @@ unsafe fn public_window_callback_inner(
19861988

19871989
let pcount = super::loword(wparam as u32) as usize;
19881990
let mut inputs = Vec::with_capacity(pcount);
1989-
let htouch = lparam;
1991+
let htouch = lparam as *mut _;
19901992
if unsafe {
19911993
GetTouchInputInfo(
19921994
htouch,
@@ -2309,7 +2311,7 @@ unsafe fn public_window_callback_inner(
23092311
Some(selected_cursor) => {
23102312
let hcursor = match selected_cursor {
23112313
SelectedCursor::Named(cursor_icon) => unsafe {
2312-
LoadCursorW(0, util::to_windows_cursor(cursor_icon))
2314+
LoadCursorW(ptr::null_mut(), util::to_windows_cursor(cursor_icon))
23132315
},
23142316
SelectedCursor::Custom(cursor) => cursor.as_raw_handle(),
23152317
};
@@ -2541,7 +2543,7 @@ unsafe fn public_window_callback_inner(
25412543
unsafe {
25422544
SetWindowPos(
25432545
window,
2544-
0,
2546+
ptr::null_mut(),
25452547
new_outer_rect.left,
25462548
new_outer_rect.top,
25472549
new_outer_rect.right - new_outer_rect.left,
@@ -2621,7 +2623,7 @@ unsafe extern "system" fn thread_event_target_callback(
26212623
let userdata = unsafe { Box::from_raw(userdata_ptr) };
26222624

26232625
if msg != WM_PAINT {
2624-
unsafe { RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT) };
2626+
unsafe { RedrawWindow(window, ptr::null(), ptr::null_mut(), RDW_INTERNALPAINT) };
26252627
}
26262628

26272629
let mut userdata_removed = false;
@@ -2685,7 +2687,7 @@ unsafe fn handle_raw_input(userdata: &ThreadMsgTargetData, data: RAWINPUT) {
26852687
if data.header.dwType == RIM_TYPEMOUSE {
26862688
let mouse = unsafe { data.data.mouse };
26872689

2688-
if util::has_flag(mouse.usFlags as u32, MOUSE_MOVE_RELATIVE) {
2690+
if util::has_flag(mouse.usFlags, MOUSE_MOVE_RELATIVE) {
26892691
let x = mouse.lLastX as f64;
26902692
let y = mouse.lLastY as f64;
26912693

src/platform_impl/windows/icon.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::c_void;
22
use std::path::Path;
33
use std::sync::Arc;
4-
use std::{fmt, io, mem};
4+
use std::{fmt, io, mem, ptr};
55

66
use cursor_icon::CursorIcon;
77
use windows_sys::core::PCWSTR;
@@ -40,7 +40,7 @@ impl RgbaIcon {
4040
assert_eq!(and_mask.len(), pixel_count);
4141
let handle = unsafe {
4242
CreateIcon(
43-
0,
43+
ptr::null_mut(),
4444
self.width as i32,
4545
self.height as i32,
4646
1,
@@ -49,7 +49,7 @@ impl RgbaIcon {
4949
rgba.as_ptr(),
5050
)
5151
};
52-
if handle != 0 {
52+
if !handle.is_null() {
5353
Ok(WinIcon::from_handle(handle))
5454
} else {
5555
Err(BadIcon::OsError(io::Error::last_os_error()))
@@ -68,6 +68,9 @@ struct RaiiIcon {
6868
handle: HICON,
6969
}
7070

71+
unsafe impl Send for RaiiIcon {}
72+
unsafe impl Sync for RaiiIcon {}
73+
7174
#[derive(Clone, PartialEq, Eq, Hash)]
7275
pub struct WinIcon {
7376
inner: Arc<RaiiIcon>,
@@ -91,15 +94,15 @@ impl WinIcon {
9194

9295
let handle = unsafe {
9396
LoadImageW(
94-
0,
97+
ptr::null_mut(),
9598
wide_path.as_ptr(),
9699
IMAGE_ICON,
97100
width,
98101
height,
99102
LR_DEFAULTSIZE | LR_LOADFROMFILE,
100103
)
101104
};
102-
if handle != 0 {
105+
if !handle.is_null() {
103106
Ok(WinIcon::from_handle(handle as HICON))
104107
} else {
105108
Err(BadIcon::OsError(io::Error::last_os_error()))
@@ -122,7 +125,7 @@ impl WinIcon {
122125
LR_DEFAULTSIZE,
123126
)
124127
};
125-
if handle != 0 {
128+
if !handle.is_null() {
126129
Ok(WinIcon::from_handle(handle as HICON))
127130
} else {
128131
Err(BadIcon::OsError(io::Error::last_os_error()))
@@ -136,7 +139,7 @@ impl WinIcon {
136139

137140
pub fn set_for_window(&self, hwnd: HWND, icon_type: IconType) {
138141
unsafe {
139-
SendMessageW(hwnd, WM_SETICON, icon_type as usize, self.as_raw_handle());
142+
SendMessageW(hwnd, WM_SETICON, icon_type as usize, self.as_raw_handle() as isize);
140143
}
141144
}
142145

@@ -187,13 +190,13 @@ impl WinCursor {
187190
let h = image.height as i32;
188191

189192
unsafe {
190-
let hdc_screen = GetDC(0);
191-
if hdc_screen == 0 {
193+
let hdc_screen = GetDC(ptr::null_mut());
194+
if hdc_screen.is_null() {
192195
return Err(os_error!(io::Error::last_os_error()).into());
193196
}
194197
let hbm_color = CreateCompatibleBitmap(hdc_screen, w, h);
195-
ReleaseDC(0, hdc_screen);
196-
if hbm_color == 0 {
198+
ReleaseDC(ptr::null_mut(), hdc_screen);
199+
if hbm_color.is_null() {
197200
return Err(os_error!(io::Error::last_os_error()).into());
198201
}
199202
if SetBitmapBits(hbm_color, bgra.len() as u32, bgra.as_ptr() as *const c_void) == 0 {
@@ -204,7 +207,7 @@ impl WinCursor {
204207
// Mask created according to https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmap#parameters
205208
let mask_bits: Vec<u8> = vec![0xff; ((((w + 15) >> 4) << 1) * h) as usize];
206209
let hbm_mask = CreateBitmap(w, h, 1, 1, mask_bits.as_ptr() as *const _);
207-
if hbm_mask == 0 {
210+
if hbm_mask.is_null() {
208211
DeleteObject(hbm_color);
209212
return Err(os_error!(io::Error::last_os_error()).into());
210213
}
@@ -220,7 +223,7 @@ impl WinCursor {
220223
let handle = CreateIconIndirect(&icon_info as *const _);
221224
DeleteObject(hbm_color);
222225
DeleteObject(hbm_mask);
223-
if handle == 0 {
226+
if handle.is_null() {
224227
return Err(os_error!(io::Error::last_os_error()).into());
225228
}
226229

@@ -234,6 +237,9 @@ pub struct RaiiCursor {
234237
handle: HCURSOR,
235238
}
236239

240+
unsafe impl Send for RaiiCursor {}
241+
unsafe impl Sync for RaiiCursor {}
242+
237243
impl Drop for RaiiCursor {
238244
fn drop(&mut self) {
239245
unsafe { DestroyCursor(self.handle) };

0 commit comments

Comments
 (0)