chore(deps): update windows to 0.48 (#736)

This commit is contained in:
Amr Bashir
2023-05-22 16:13:50 +03:00
committed by GitHub
parent ec32134107
commit 45bfc49778
9 changed files with 51 additions and 35 deletions

View File

@@ -74,11 +74,11 @@ png = "0.17"
parking_lot = "0.12"
unicode-segmentation = "1.10"
image = { version = "0.24", default-features = false }
windows-implement = "0.44.0"
windows-implement = "0.48.0"
[target."cfg(target_os = \"windows\")".dependencies.windows]
version = "0.44.0"
features = [
[target."cfg(target_os = \"windows\")".dependencies.windows]
version = "0.48.0"
features = [
"implement",
"Win32_Devices_HumanInterfaceDevice",
"Win32_Foundation",

View File

@@ -8,7 +8,7 @@ use std::{ffi::OsStr, os::windows::ffi::OsStrExt, ptr};
use windows::{
core::{PCWSTR, PWSTR},
Win32::{
Foundation::{HANDLE, HWND},
Foundation::{HANDLE, HGLOBAL, HWND},
System::{
DataExchange::{
CloseClipboard, EmptyClipboard, GetClipboardData, OpenClipboard, RegisterClipboardFormatW,
@@ -36,7 +36,7 @@ impl Clipboard {
if handle.is_invalid() {
None
} else {
let unic_str = PWSTR::from_raw(GlobalLock(handle.0) as *mut _);
let unic_str = PWSTR::from_raw(GlobalLock(HGLOBAL(handle.0)) as *mut _);
let mut len = 0;
while *unic_str.0.offset(len) != 0 {
len += 1;
@@ -44,7 +44,7 @@ impl Clipboard {
let utf16_slice = std::slice::from_raw_parts(unic_str.0, len as usize);
let result = String::from_utf16(utf16_slice);
if let Ok(result) = result {
GlobalUnlock(handle.0);
GlobalUnlock(HGLOBAL(handle.0));
return Some(result);
}
@@ -112,17 +112,17 @@ unsafe fn make_handle(format: &ClipboardFormat) -> HANDLE {
HANDLE(if format.identifier == ClipboardFormat::TEXT {
let s: &OsStr = std::str::from_utf8_unchecked(&format.data).as_ref();
let wstr: Vec<u16> = s.encode_wide().chain(Some(0)).collect();
let handle = GlobalAlloc(GMEM_MOVEABLE, wstr.len() * std::mem::size_of::<u16>());
let locked = GlobalLock(handle) as *mut _;
let handle = GlobalAlloc(GMEM_MOVEABLE, wstr.len() * std::mem::size_of::<u16>()).unwrap();
let locked = GlobalLock(HGLOBAL(handle.0)) as *mut _;
ptr::copy_nonoverlapping(wstr.as_ptr(), locked, wstr.len());
GlobalUnlock(handle);
handle
handle.0
} else {
let handle = GlobalAlloc(GMEM_MOVEABLE, format.data.len() * std::mem::size_of::<u8>());
let locked = GlobalLock(handle) as *mut _;
let handle = GlobalAlloc(GMEM_MOVEABLE, format.data.len() * std::mem::size_of::<u8>()).unwrap();
let locked = GlobalLock(HGLOBAL(handle.0)) as *mut _;
ptr::copy_nonoverlapping(format.data.as_ptr(), locked, format.data.len());
GlobalUnlock(handle);
handle
GlobalUnlock(HGLOBAL(handle.0));
handle.0
})
}

View File

@@ -38,7 +38,7 @@ impl FileDropHandler {
}
}
unsafe fn iterate_filenames<F>(data_obj: &Option<IDataObject>, callback: F) -> Option<HDROP>
unsafe fn iterate_filenames<F>(data_obj: Option<&IDataObject>, callback: F) -> Option<HDROP>
where
F: Fn(PathBuf),
{
@@ -57,7 +57,7 @@ impl FileDropHandler {
{
Ok(medium) => {
let hglobal = medium.Anonymous.hGlobal;
let hdrop = HDROP(hglobal);
let hdrop = HDROP(hglobal.0);
// The second parameter (0xFFFFFFFF) instructs the function to return the item count
let mut lpsz_file = [];
@@ -102,7 +102,7 @@ impl FileDropHandler {
impl IDropTarget_Impl for FileDropHandler {
fn DragEnter(
&self,
pDataObj: &Option<IDataObject>,
pDataObj: Option<&IDataObject>,
_grfKeyState: MODIFIERKEYS_FLAGS,
_pt: &POINTL,
pdwEffect: *mut DROPEFFECT,
@@ -153,7 +153,7 @@ impl IDropTarget_Impl for FileDropHandler {
fn Drop(
&self,
pDataObj: &Option<IDataObject>,
pDataObj: Option<&IDataObject>,
_grfKeyState: MODIFIERKEYS_FLAGS,
_pt: &POINTL,
_pdwEffect: *mut DROPEFFECT,

View File

@@ -23,15 +23,12 @@ use windows::{
core::{s, PCWSTR},
Win32::{
Devices::HumanInterfaceDevice::*,
Foundation::{
BOOL, HANDLE, HINSTANCE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_TIMEOUT, WPARAM,
},
Foundation::{BOOL, HANDLE, HMODULE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_TIMEOUT, WPARAM},
Graphics::Gdi::*,
System::{
LibraryLoader::GetModuleHandleW,
Ole::{IDropTarget, RevokeDragDrop},
Threading::GetCurrentThreadId,
WindowsProgramming::INFINITE,
Threading::{GetCurrentThreadId, INFINITE},
},
UI::{
Controls::{self as win32c, HOVER_DEFAULT},
@@ -1763,7 +1760,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
match set_cursor_to {
Some(cursor) => {
if let Ok(cursor) = LoadCursorW(HINSTANCE::default(), cursor.to_windows_cursor()) {
if let Ok(cursor) = LoadCursorW(HMODULE::default(), cursor.to_windows_cursor()) {
SetCursor(cursor);
}
result = ProcResult::Value(LRESULT(0));

View File

@@ -7,7 +7,7 @@ use std::{fmt, io, iter::once, mem, os::windows::ffi::OsStrExt, path::Path, sync
use windows::{
core::PCWSTR,
Win32::{
Foundation::{HINSTANCE, HWND, LPARAM, WPARAM},
Foundation::{HMODULE, HWND, LPARAM, WPARAM},
System::LibraryLoader::*,
UI::WindowsAndMessaging::*,
},
@@ -35,7 +35,7 @@ impl RgbaIcon {
assert_eq!(and_mask.len(), pixel_count);
let handle = unsafe {
CreateIcon(
HINSTANCE::default(),
HMODULE::default(),
self.width as i32,
self.height as i32,
1,
@@ -90,7 +90,7 @@ impl WinIcon {
let handle = unsafe {
LoadImageW(
HINSTANCE::default(),
HMODULE::default(),
PCWSTR::from_raw(wide_path.as_ptr()),
IMAGE_ICON,
width as i32,

View File

@@ -750,7 +750,7 @@ fn is_current_fake(curr_info: &PartialKeyEventInfo, next_msg: MSG, layout: &Layo
}
fn get_location(scancode: ExScancode, hkl: HKL) -> KeyLocation {
const VK_ABNT_C2: VIRTUAL_KEY = VIRTUAL_KEY(win32km::VK_ABNT_C2 as u16);
const VK_ABNT_C2: VIRTUAL_KEY = win32km::VK_ABNT_C2;
let extension = 0xE000;
let extended = (scancode & extension) == extension;

View File

@@ -233,8 +233,13 @@ impl MonitorHandle {
let device_name = PCWSTR::from_raw(monitor_info.szDevice.as_ptr());
let mut mode: DEVMODEW = mem::zeroed();
mode.dmSize = mem::size_of_val(&mode) as u16;
if !EnumDisplaySettingsExW(device_name, ENUM_DISPLAY_SETTINGS_MODE(i), &mut mode, 0)
.as_bool()
if !EnumDisplaySettingsExW(
device_name,
ENUM_DISPLAY_SETTINGS_MODE(i),
&mut mode,
ENUM_DISPLAY_SETTINGS_FLAGS(0),
)
.as_bool()
{
break;
}

View File

@@ -421,3 +421,18 @@ pub unsafe extern "system" fn call_default_window_proc(
) -> LRESULT {
DefWindowProcW(hwnd, msg, wparam, lparam)
}
pub fn get_instance_handle() -> windows::Win32::Foundation::HMODULE {
// Gets the instance handle by taking the address of the
// pseudo-variable created by the microsoft linker:
// https://devblogs.microsoft.com/oldnewthing/20041025-00/?p=37483
// This is preferred over GetModuleHandle(NULL) because it also works in DLLs:
// https://stackoverflow.com/questions/21718027/getmodulehandlenull-vs-hinstance
extern "C" {
static __ImageBase: windows::Win32::System::SystemServices::IMAGE_DOS_HEADER;
}
windows::Win32::Foundation::HMODULE(unsafe { &__ImageBase as *const _ as _ })
}

View File

@@ -22,7 +22,7 @@ use crossbeam_channel as channel;
use windows::{
core::PCWSTR,
Win32::{
Foundation::{self as win32f, HINSTANCE, HWND, LPARAM, LRESULT, POINT, RECT, WPARAM},
Foundation::{self as win32f, HMODULE, HWND, LPARAM, LRESULT, POINT, RECT, WPARAM},
Graphics::{
Dwm::{DwmEnableBlurBehindWindow, DWM_BB_BLURREGION, DWM_BB_ENABLE, DWM_BLURBEHIND},
Gdi::*,
@@ -353,8 +353,8 @@ impl Window {
}
#[inline]
pub fn hinstance(&self) -> HINSTANCE {
HINSTANCE(util::GetWindowLongPtrW(self.hwnd(), GWLP_HINSTANCE))
pub fn hinstance(&self) -> HMODULE {
util::get_instance_handle()
}
#[inline]
@@ -374,8 +374,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(HINSTANCE::default(), cursor.to_windows_cursor()).unwrap_or_default();
let cursor = LoadCursorW(HMODULE::default(), cursor.to_windows_cursor()).unwrap_or_default();
SetCursor(cursor);
});
}