Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update windows crate to 0.29.0 #266

Merged
merged 2 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/windows-0.29.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Update the `windows` crate to 0.29.0.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ cc = "1"
[target."cfg(target_os = \"windows\")".dependencies]
parking_lot = "0.11"
unicode-segmentation = "1.8.0"
windows_macros = "0.29.0"

[target."cfg(target_os = \"windows\")".dependencies.windows]
version = "0.25.0"
version = "0.29.0"
features = [
"build",
"alloc",
"Win32_Devices_HumanInterfaceDevice",
"Win32_Foundation",
"Win32_Globalization",
Expand Down
2 changes: 1 addition & 1 deletion examples/parentwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {
#[cfg(target_os = "macos")]
let parent_window = main_window.ns_window();
#[cfg(target_os = "windows")]
let parent_window = HWND(main_window.hwnd() as _);
let parent_window = main_window.hwnd() as HWND;

let child_window = WindowBuilder::new()
.with_parent_window(parent_window)
Expand Down
6 changes: 3 additions & 3 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ pub trait WindowExtWindows {
impl WindowExtWindows for Window {
#[inline]
fn hinstance(&self) -> *mut libc::c_void {
self.window.hinstance().0 as _
self.window.hinstance() as _
}

#[inline]
fn hwnd(&self) -> *mut libc::c_void {
self.window.hwnd().0 as _
self.window.hwnd() as _
}

#[inline]
Expand Down Expand Up @@ -281,7 +281,7 @@ impl MonitorHandleExtWindows for MonitorHandle {

#[inline]
fn hmonitor(&self) -> *mut libc::c_void {
self.inner.hmonitor().0 as _
self.inner.hmonitor() as _
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/windows/accelerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ impl AccelTable {
fn new(accel: &[ACCEL]) -> AccelTable {
let accel = unsafe { CreateAcceleratorTableW(accel as *const _ as *mut _, accel.len() as i32) };
AccelTable {
accel: AccelHandle(accel.0),
accel: AccelHandle(accel),
}
}

pub(crate) fn handle(&self) -> HACCEL {
HACCEL(self.accel.0)
self.accel.0
}
}

pub(crate) fn register_accel(hwnd: HWND, accel: &[ACCEL]) {
let mut table = ACCEL_TABLES.lock().unwrap();
table.insert(WindowHandle(hwnd.0), Arc::new(AccelTable::new(accel)));
table.insert(WindowHandle(hwnd), Arc::new(AccelTable::new(accel)));
}

impl Drop for AccelTable {
Expand All @@ -63,5 +63,5 @@ impl Drop for AccelTable {

pub(crate) fn find_accels(hwnd: HWND) -> Option<Arc<AccelTable>> {
let table = ACCEL_TABLES.lock().unwrap();
table.get(&WindowHandle(hwnd.0)).cloned()
table.get(&WindowHandle(hwnd)).cloned()
}
8 changes: 4 additions & 4 deletions src/platform_impl/windows/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Clipboard {

pub(crate) fn read_text(&self) -> Option<String> {
with_clipboard(|| unsafe {
let handle = GetClipboardData(CF_UNICODETEXT.0);
let handle = GetClipboardData(CF_UNICODETEXT);
if handle.0 == 0 {
None
} else {
Expand Down Expand Up @@ -67,7 +67,7 @@ impl Clipboard {
println!(
"failed to set clipboard for fmt {}, error: {}",
&format.identifier,
windows::runtime::Error::from_win32().code().0
windows::core::Error::from_win32().code().0
);
}
}
Expand All @@ -80,7 +80,7 @@ fn get_format_id(format: FormatId) -> Option<u32> {
return Some(*id);
}
match format {
ClipboardFormat::TEXT => Some(CF_UNICODETEXT.0),
ClipboardFormat::TEXT => Some(CF_UNICODETEXT),
other => register_identifier(other),
}
}
Expand All @@ -89,7 +89,7 @@ fn register_identifier(ident: &str) -> Option<u32> {
unsafe {
let pb_format = RegisterClipboardFormatA(ident);
if pb_format == 0 {
let err = windows::runtime::Error::from_win32().code().0;
let err = windows::core::Error::from_win32().code().0;
println!(
"failed to register clipboard format '{}'; error {}.",
ident, err
Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/windows/dark_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn should_apps_use_dark_mode() -> bool {

let module = LoadLibraryA("uxtheme.dll");

if module.0 == 0 {
if module == 0 {
return None;
}

Expand All @@ -182,7 +182,7 @@ const HCF_HIGHCONTRASTON: u32 = 1;
fn is_high_contrast() -> bool {
let mut hc = HIGHCONTRASTA {
cbSize: 0,
dwFlags: HIGHCONTRASTW_FLAGS(0),
dwFlags: 0,
lpszDefaultScheme: PSTR::default(),
};

Expand All @@ -191,9 +191,9 @@ fn is_high_contrast() -> bool {
SPI_GETHIGHCONTRAST,
std::mem::size_of_val(&hc) as _,
&mut hc as *mut _ as _,
SYSTEM_PARAMETERS_INFO_UPDATE_FLAGS(0),
0,
)
};

ok.as_bool() && (HIGHCONTRASTW_FLAGS(HCF_HIGHCONTRASTON) & hc.dwFlags).0 != 0
ok.as_bool() && (HCF_HIGHCONTRASTON & hc.dwFlags) != 0
}
4 changes: 2 additions & 2 deletions src/platform_impl/windows/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
if hdc.0 == 0 {
if hdc == 0 {
panic!("[tao] `GetDC` returned null!");
}
if let Some(GetDpiForWindow) = *GET_DPI_FOR_WINDOW {
Expand All @@ -82,7 +82,7 @@ pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 {
} else if let Some(GetDpiForMonitor) = *GET_DPI_FOR_MONITOR {
// We are on Windows 8.1 or later.
let monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if monitor.0 == 0 {
if monitor == 0 {
return BASE_DPI;
}

Expand Down
25 changes: 13 additions & 12 deletions src/platform_impl/windows/drop_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{ffi::OsString, os::windows::ffi::OsStringExt, path::PathBuf, ptr};

use windows::{
self as Windows,
runtime::implement,
Win32::{
Foundation::{self as win32f, HWND, POINTL, PWSTR},
System::{
Expand All @@ -17,6 +16,8 @@ use windows::{
},
};

use windows_macros::implement;

use crate::platform_impl::platform::WindowId;

use crate::{event::Event, window::WindowId as SuperWindowId};
Expand Down Expand Up @@ -46,11 +47,11 @@ impl FileDropHandler {
_grfKeyState: u32,
_pt: POINTL,
pdwEffect: *mut u32,
) -> windows::runtime::Result<()> {
) -> windows::core::Result<()> {
use crate::event::WindowEvent::HoveredFile;
let hdrop = Self::iterate_filenames(pDataObj, |filename| {
(self.send_event)(Event::WindowEvent {
window_id: SuperWindowId(WindowId(self.window.0)),
window_id: SuperWindowId(WindowId(self.window)),
event: HoveredFile(filename),
});
});
Expand All @@ -69,16 +70,16 @@ impl FileDropHandler {
_grfKeyState: u32,
_pt: POINTL,
pdwEffect: *mut u32,
) -> windows::runtime::Result<()> {
) -> windows::core::Result<()> {
*pdwEffect = self.cursor_effect;
Ok(())
}

unsafe fn DragLeave(&self) -> windows::runtime::Result<()> {
unsafe fn DragLeave(&self) -> windows::core::Result<()> {
use crate::event::WindowEvent::HoveredFileCancelled;
if self.hovered_is_valid {
(self.send_event)(Event::WindowEvent {
window_id: SuperWindowId(WindowId(self.window.0)),
window_id: SuperWindowId(WindowId(self.window)),
event: HoveredFileCancelled,
});
}
Expand All @@ -91,11 +92,11 @@ impl FileDropHandler {
_grfKeyState: u32,
_pt: POINTL,
_pdwEffect: *mut u32,
) -> windows::runtime::Result<()> {
) -> windows::core::Result<()> {
use crate::event::WindowEvent::DroppedFile;
let hdrop = Self::iterate_filenames(pDataObj, |filename| {
(self.send_event)(Event::WindowEvent {
window_id: SuperWindowId(WindowId(self.window.0)),
window_id: SuperWindowId(WindowId(self.window)),
event: DroppedFile(filename),
});
});
Expand All @@ -110,11 +111,11 @@ impl FileDropHandler {
F: Fn(PathBuf),
{
let drop_format = FORMATETC {
cfFormat: CF_HDROP.0 as u16,
cfFormat: CF_HDROP as u16,
ptd: ptr::null_mut(),
dwAspect: DVASPECT_CONTENT.0 as u32,
dwAspect: DVASPECT_CONTENT as u32,
lindex: -1,
tymed: TYMED_HGLOBAL.0 as u32,
tymed: TYMED_HGLOBAL as u32,
};

match data_obj
Expand All @@ -124,7 +125,7 @@ impl FileDropHandler {
{
Ok(medium) => {
let hglobal = medium.Anonymous.hGlobal;
let hdrop = HDROP(hglobal);
let hdrop = hglobal;

// The second parameter (0xFFFFFFFF) instructs the function to return the item count
let item_count = DragQueryFileW(hdrop, 0xFFFFFFFF, PWSTR::default(), 0);
Expand Down
Loading