chore(deps): update windows-rs to 0.51 (#817)

* chore(deps): update windows-rs to 0.51.1

* Update Cargo.toml

* Update Cargo.toml

* Update .changes/windows-0.51.md

* Update .changes/windows-0.51.md
This commit is contained in:
Amr Bashir
2023-10-17 20:19:35 +03:00
committed by GitHub
parent f569bbabda
commit 7e854cb1f5
16 changed files with 143 additions and 143 deletions

View File

@@ -0,0 +1,5 @@
---
"tao": "patch"
---
On Windows, fix incorrect delta reported for `DeviceEvent::MouseWheel` event.

View File

@@ -0,0 +1,5 @@
---
"tao": "patch"
---
On Windows, fix `Window::set_progress_bar` incorrect states.

5
.changes/windows-0.51.md Normal file
View File

@@ -0,0 +1,5 @@
---
"tao": "minor"
---
Update `windows` and `windows-implement` crate to `0.51`

View File

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

View File

@@ -2,7 +2,7 @@
// Copyright 2021-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
#![cfg(any(target_os = "android"))]
#![cfg(target_os = "android")]
#[doc(hidden)]
pub use crate::platform_impl::ndk_glue;

View File

@@ -7,8 +7,7 @@ use once_cell::sync::Lazy;
/// This is a simple implementation of support for Windows Dark Mode,
/// which is inspired by the solution in https://github.com/ysc3839/win32-darkmode
use windows::{
core::{s, PCSTR, PSTR},
w,
core::{s, w, PCSTR, PSTR},
Win32::{
Foundation::{BOOL, HANDLE, HMODULE, HWND},
System::{LibraryLoader::*, SystemInformation::OSVERSIONINFOW},
@@ -242,12 +241,12 @@ fn refresh_titlebar_theme_color(hwnd: HWND) {
if let Some(ver) = *WIN10_BUILD_VERSION {
if ver < 18362 {
unsafe {
SetPropW(
let _ = SetPropW(
hwnd,
w!("UseImmersiveDarkModeColors"),
HANDLE(&mut is_dark_mode_bigbool as *mut _ as _),
)
};
);
}
} else if let Some(set_window_composition_attribute) = *SET_WINDOW_COMPOSITION_ATTRIBUTE {
let mut data = WINDOWCOMPOSITIONATTRIBDATA {
Attrib: WCA_USEDARKMODECOLORS,
@@ -301,5 +300,5 @@ fn is_high_contrast() -> bool {
)
};
ok.as_bool() && (HCF_HIGHCONTRASTON & hc.dwFlags.0) != 0
ok.is_ok() && (HCF_HIGHCONTRASTON & hc.dwFlags.0) != 0
}

View File

@@ -56,8 +56,8 @@ impl FileDropHandler {
.GetData(&drop_format)
{
Ok(medium) => {
let hglobal = medium.Anonymous.hGlobal;
let hdrop = HDROP(hglobal.0);
let hglobal = medium.u.hGlobal;
let hdrop = HDROP(hglobal.0 as _);
// The second parameter (0xFFFFFFFF) instructs the function to return the item count
let mut lpsz_file = [];

View File

@@ -24,7 +24,9 @@ use windows::{
core::{s, PCWSTR},
Win32::{
Devices::HumanInterfaceDevice::*,
Foundation::{BOOL, HANDLE, HMODULE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_TIMEOUT, WPARAM},
Foundation::{
BOOL, HANDLE, HINSTANCE, HMODULE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_TIMEOUT, WPARAM,
},
Graphics::Gdi::*,
System::{
LibraryLoader::GetModuleHandleW,
@@ -319,7 +321,7 @@ impl<T> EventLoopWindowTarget<T> {
#[inline]
pub fn cursor_position(&self) -> Result<PhysicalPosition<f64>, ExternalError> {
util::cursor_position()
util::cursor_position().map_err(Into::into)
}
}
@@ -361,7 +363,7 @@ fn wait_thread(parent_thread_id: u32, msg_window_id: HWND) {
let mut msg: MSG;
let cur_thread_id = GetCurrentThreadId();
PostThreadMessageW(
let _ = PostThreadMessageW(
parent_thread_id,
*SEND_WAIT_THREAD_ID_MSG_ID,
WPARAM(0),
@@ -405,8 +407,8 @@ fn wait_thread(parent_thread_id: u32, msg_window_id: HWND) {
QS_ALLEVENTS,
MWMO_INPUTAVAILABLE,
);
if resume_reason == WAIT_TIMEOUT.0 {
PostMessageW(
if resume_reason == WAIT_TIMEOUT {
let _ = PostMessageW(
msg_window_id,
*PROCESS_NEW_EVENTS_MSG_ID,
WPARAM(0),
@@ -415,7 +417,7 @@ fn wait_thread(parent_thread_id: u32, msg_window_id: HWND) {
wait_until_opt = None;
}
} else {
PostMessageW(
let _ = PostMessageW(
msg_window_id,
*PROCESS_NEW_EVENTS_MSG_ID,
WPARAM(0),
@@ -461,7 +463,7 @@ fn dur2timeout(dur: Duration) -> u32 {
impl<T> Drop for EventLoop<T> {
fn drop(&mut self) {
unsafe {
DestroyWindow(self.window_target.p.thread_msg_target);
let _ = DestroyWindow(self.window_target.p.thread_msg_target);
}
}
}
@@ -515,7 +517,7 @@ impl EventLoopThreadExecutor {
LPARAM(0),
);
assert!(
res.as_bool(),
res.is_ok(),
"PostMessage failed ; is the messages queue full?"
);
}
@@ -544,7 +546,7 @@ impl<T: 'static> Clone for EventLoopProxy<T> {
impl<T: 'static> EventLoopProxy<T> {
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
unsafe {
if PostMessageW(self.target_window, *USER_EVENT_MSG_ID, WPARAM(0), LPARAM(0)).as_bool() {
if PostMessageW(self.target_window, *USER_EVENT_MSG_ID, WPARAM(0), LPARAM(0)).is_ok() {
self.event_send.send(event).ok();
Ok(())
} else {
@@ -621,7 +623,7 @@ lazy_static! {
lpfnWndProc: Some(util::call_default_window_proc),
cbClsExtra: 0,
cbWndExtra: 0,
hInstance: GetModuleHandleW(PCWSTR::null()).unwrap_or_default(),
hInstance:HINSTANCE(GetModuleHandleW(PCWSTR::null()).unwrap_or_default().0),
hIcon: HICON::default(),
hCursor: HCURSOR::default(), // must be null in order for cursor state to work properly
hbrBackground: HBRUSH::default(),
@@ -721,7 +723,7 @@ unsafe fn release_mouse(mut window_state: parking_lot::MutexGuard<'_, WindowStat
if window_state.mouse.capture_count == 0 {
// ReleaseCapture() causes a WM_CAPTURECHANGED where we lock the window_state.
drop(window_state);
ReleaseCapture();
let _ = ReleaseCapture();
}
}
@@ -808,7 +810,7 @@ unsafe fn flush_paint_messages<T: 'static>(
unsafe fn process_control_flow<T: 'static>(runner: &EventLoopRunner<T>) {
match runner.control_flow() {
ControlFlow::Poll => {
PostMessageW(
let _ = PostMessageW(
runner.thread_msg_target(),
*PROCESS_NEW_EVENTS_MSG_ID,
WPARAM(0),
@@ -817,7 +819,7 @@ unsafe fn process_control_flow<T: 'static>(runner: &EventLoopRunner<T>) {
}
ControlFlow::Wait => (),
ControlFlow::WaitUntil(until) => {
PostThreadMessageW(
let _ = PostThreadMessageW(
runner.wait_thread_id(),
*WAIT_UNTIL_MSG_ID,
WPARAM(0),
@@ -1030,7 +1032,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
}
win32wm::WM_NCLBUTTONDOWN => {
if wparam.0 == HTCAPTION as _ {
PostMessageW(window, WM_MOUSEMOVE, WPARAM(0), lparam);
let _ = PostMessageW(window, WM_MOUSEMOVE, WPARAM(0), lparam);
}
use crate::event::WindowEvent::DecorationsClick;
@@ -1256,7 +1258,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
});
// Calling TrackMouseEvent in order to receive mouse leave events.
TrackMouseEvent(&mut TRACKMOUSEEVENT {
let _ = TrackMouseEvent(&mut TRACKMOUSEEVENT {
cbSize: mem::size_of::<TRACKMOUSEEVENT>() as u32,
dwFlags: TME_LEAVE,
hwndTrack: window,
@@ -1361,7 +1363,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
win32wm::WM_LBUTTONDOWN => {
use crate::event::{ElementState::Pressed, MouseButton::Left, WindowEvent::MouseInput};
capture_mouse(window, &mut *subclass_input.window_state.lock());
capture_mouse(window, &mut subclass_input.window_state.lock());
let modifiers = update_modifiers(window, subclass_input);
@@ -1437,7 +1439,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
win32wm::WM_MBUTTONDOWN => {
use crate::event::{ElementState::Pressed, MouseButton::Middle, WindowEvent::MouseInput};
capture_mouse(window, &mut *subclass_input.window_state.lock());
capture_mouse(window, &mut subclass_input.window_state.lock());
let modifiers = update_modifiers(window, subclass_input);
@@ -1476,7 +1478,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
use crate::event::{ElementState::Pressed, MouseButton::Other, WindowEvent::MouseInput};
let xbutton = util::GET_XBUTTON_WPARAM(wparam);
capture_mouse(window, &mut *subclass_input.window_state.lock());
capture_mouse(window, &mut subclass_input.window_state.lock());
let modifiers = update_modifiers(window, subclass_input);
@@ -1533,7 +1535,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
mem::transmute(uninit_inputs),
mem::size_of::<TOUCHINPUT>() as i32,
)
.as_bool()
.is_ok()
{
inputs.set_len(pcount);
for input in &inputs {
@@ -1569,7 +1571,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
});
}
}
CloseTouchInputHandle(htouch);
let _ = CloseTouchInputHandle(htouch);
result = ProcResult::Value(LRESULT(0));
}
@@ -1880,7 +1882,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
let old_physical_inner_rect = {
let mut old_physical_inner_rect = RECT::default();
GetClientRect(window, &mut old_physical_inner_rect);
let _ = GetClientRect(window, &mut old_physical_inner_rect);
let mut origin = POINT::default();
ClientToScreen(window, &mut origin);
@@ -1954,7 +1956,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
let bias = {
let cursor_pos = {
let mut pos = POINT::default();
GetCursorPos(&mut pos);
let _ = GetCursorPos(&mut pos);
pos
};
let suggested_cursor_horizontal_ratio = (cursor_pos.x - suggested_rect.left) as f64
@@ -2026,7 +2028,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
};
}
SetWindowPos(
let _ = SetWindowPos(
window,
HWND::default(),
new_outer_rect.left,
@@ -2066,7 +2068,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
result = ProcResult::DefSubclassProc;
} else {
// adjust the maximized borderless window so it doesn't cover the taskbar
if util::is_maximized(window) {
if util::is_maximized(window).unwrap_or(false) {
let params = &mut *(lparam.0 as *mut NCCALCSIZE_PARAMS);
if let Ok(monitor_info) =
monitor::get_monitor_info(MonitorFromRect(&params.rgrc[0], MONITOR_DEFAULTTONULL))
@@ -2112,7 +2114,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
win32wm::WM_NCHITTEST => {
// Allow resizing unmaximized borderless window
if !util::is_maximized(window)
if !util::is_maximized(window).unwrap_or(false)
&& !subclass_input
.window_state
.lock()
@@ -2138,7 +2140,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
_ => {
if msg == *DESTROY_MSG_ID {
DestroyWindow(window);
let _ = DestroyWindow(window);
result = ProcResult::Value(LRESULT(0));
} else if msg == *SET_RETAIN_STATE_ON_SIZE_MSG_ID {
let mut window_state = subclass_input.window_state.lock();
@@ -2254,7 +2256,7 @@ unsafe extern "system" fn thread_event_target_callback<T: 'static>(
LRESULT(0)
}
_ if msg == *PROCESS_NEW_EVENTS_MSG_ID => {
PostThreadMessageW(
let _ = PostThreadMessageW(
subclass_input.event_loop_runner.wait_thread_id(),
*CANCEL_WAIT_UNTIL_MSG_ID,
WPARAM(0),
@@ -2349,7 +2351,7 @@ unsafe fn handle_raw_input<T: 'static>(
RI_MOUSE_WHEEL as u16,
) {
// We must cast to SHORT first, becaues `usButtonData` must be interpreted as signed.
let delta = mouse.Anonymous.Anonymous.usButtonData as f32 / WHEEL_DELTA as f32;
let delta = mouse.Anonymous.Anonymous.usButtonData as i16 as f32 / WHEEL_DELTA as f32;
subclass_input.send_event(Event::DeviceEvent {
device_id,
event: MouseWheel {

View File

@@ -40,8 +40,8 @@ impl RgbaIcon {
self.height as i32,
1,
(PIXEL_SIZE * 8) as u8,
and_mask.as_ptr() as *const u8,
rgba.as_ptr() as *const u8,
and_mask.as_ptr(),
rgba.as_ptr(),
)
};
Ok(WinIcon::from_handle(
@@ -148,7 +148,7 @@ impl WinIcon {
impl Drop for RaiiIcon {
fn drop(&mut self) {
unsafe { DestroyIcon(self.handle) };
let _ = unsafe { DestroyIcon(self.handle) };
}
}

View File

@@ -198,11 +198,7 @@ impl KeyEventBuilder {
more_char_coming = false;
} else {
let next_msg = next_msg.assume_init().message;
if next_msg == WM_CHAR || next_msg == WM_SYSCHAR {
more_char_coming = true;
} else {
more_char_coming = false;
}
more_char_coming = next_msg == WM_CHAR || next_msg == WM_SYSCHAR;
}
}
@@ -708,7 +704,7 @@ fn ex_scancode_from_lparam(lparam: LPARAM) -> ExScancode {
fn get_kbd_state() -> [u8; 256] {
unsafe {
let mut kbd_state: MaybeUninit<[u8; 256]> = MaybeUninit::uninit();
GetKeyboardState(&mut *kbd_state.as_mut_ptr());
let _ = GetKeyboardState(&mut *kbd_state.as_mut_ptr());
kbd_state.assume_init()
}
}

View File

@@ -67,11 +67,7 @@ impl MinimalIme {
more_char_coming = false;
} else {
let next_msg = next_msg.assume_init().message;
if next_msg == WM_CHAR || next_msg == WM_SYSCHAR {
more_char_coming = true;
} else {
more_char_coming = false;
}
more_char_coming = next_msg == WM_CHAR || next_msg == WM_SYSCHAR;
}
}
if !more_char_coming {

View File

@@ -111,6 +111,24 @@ impl std::fmt::Display for OsError {
}
}
impl From<windows::core::Error> for OsError {
fn from(value: windows::core::Error) -> Self {
OsError::IoError(value.into())
}
}
impl From<windows::core::Error> for crate::error::OsError {
fn from(value: windows::core::Error) -> Self {
os_error!(OsError::IoError(value.into()))
}
}
impl From<windows::core::Error> for crate::error::ExternalError {
fn from(value: windows::core::Error) -> Self {
crate::error::ExternalError::Os(os_error!(OsError::IoError(value.into())))
}
}
// Constant device ID, to be removed when this backend is updated to report real device IDs.
const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId(0));

View File

@@ -121,10 +121,7 @@ pub fn get_raw_input_device_name(handle: HANDLE) -> Option<String> {
pub fn register_raw_input_devices(devices: &[RAWINPUTDEVICE]) -> bool {
let device_size = size_of::<RAWINPUTDEVICE>() as u32;
let success = unsafe { RegisterRawInputDevices(devices, device_size) };
success.as_bool()
unsafe { RegisterRawInputDevices(devices, device_size) }.is_ok()
}
pub fn register_all_mice_and_keyboards_for_raw_input(

View File

@@ -14,7 +14,6 @@ use std::{
use crate::{
dpi::{PhysicalPosition, PhysicalSize},
error::ExternalError,
window::CursorIcon,
};
@@ -34,8 +33,6 @@ use windows::{
},
};
use super::OsError;
pub fn has_flag<T>(bitset: T, flag: T) -> bool
where
T: Copy + PartialEq + BitAnd<T, Output = T>,
@@ -57,15 +54,6 @@ pub fn encode_wide(string: impl AsRef<std::ffi::OsStr>) -> Vec<u16> {
string.as_ref().encode_wide().chain(once(0)).collect()
}
pub unsafe fn status_map<T, F: FnMut(&mut T) -> BOOL>(mut fun: F) -> Option<T> {
let mut data: T = mem::zeroed();
if fun(&mut data).as_bool() {
Some(data)
} else {
None
}
}
fn win_to_err<F: FnOnce() -> BOOL>(f: F) -> Result<(), io::Error> {
if f().as_bool() {
Ok(())
@@ -74,8 +62,9 @@ fn win_to_err<F: FnOnce() -> BOOL>(f: F) -> Result<(), io::Error> {
}
}
pub fn get_window_rect(hwnd: HWND) -> Option<RECT> {
unsafe { status_map(|rect| GetWindowRect(hwnd, rect)) }
pub unsafe fn get_window_rect(hwnd: HWND) -> Option<RECT> {
let mut rect = std::mem::zeroed();
GetWindowRect(hwnd, &mut rect).ok().map(|_| rect)
}
pub fn get_client_rect(hwnd: HWND) -> Result<RECT, io::Error> {
@@ -84,7 +73,7 @@ pub fn get_client_rect(hwnd: HWND) -> Result<RECT, io::Error> {
unsafe {
win_to_err(|| ClientToScreen(hwnd, &mut top_left))?;
win_to_err(|| GetClientRect(hwnd, &mut rect))?;
GetClientRect(hwnd, &mut rect)?;
}
rect.left += top_left.x;
@@ -123,7 +112,7 @@ pub(crate) fn set_inner_size_physical(window: HWND, x: u32, y: u32, is_decorated
let outer_x = (rect.right - rect.left).abs();
let outer_y = (rect.top - rect.bottom).abs();
SetWindowPos(
let _ = SetWindowPos(
window,
HWND::default(),
0,
@@ -155,23 +144,23 @@ pub fn adjust_window_rect_with_styles(
hwnd: HWND,
style: WINDOW_STYLE,
style_ex: WINDOW_EX_STYLE,
rect: RECT,
mut rect: RECT,
) -> Option<RECT> {
unsafe {
status_map(|r| {
*r = rect;
let b_menu: BOOL = (!unsafe { GetMenu(hwnd) }.is_invalid()).into();
let b_menu: BOOL = (!GetMenu(hwnd).is_invalid()).into();
if let (Some(get_dpi_for_window), Some(adjust_window_rect_ex_for_dpi)) =
(*GET_DPI_FOR_WINDOW, *ADJUST_WINDOW_RECT_EX_FOR_DPI)
{
let dpi = get_dpi_for_window(hwnd);
adjust_window_rect_ex_for_dpi(r, style, b_menu, style_ex, dpi)
} else {
AdjustWindowRectEx(r, style, b_menu, style_ex)
}
})
if let (Some(get_dpi_for_window), Some(adjust_window_rect_ex_for_dpi)) =
(*GET_DPI_FOR_WINDOW, *ADJUST_WINDOW_RECT_EX_FOR_DPI)
{
let dpi = unsafe { get_dpi_for_window(hwnd) };
if unsafe { adjust_window_rect_ex_for_dpi(&mut rect, style, b_menu, style_ex, dpi) }.as_bool() {
Some(rect)
} else {
None
}
} else {
unsafe { AdjustWindowRectEx(&mut rect, style, b_menu, style_ex) }
.ok()
.map(|_| rect)
}
}
@@ -183,20 +172,20 @@ pub fn set_cursor_hidden(hidden: bool) {
}
}
pub fn get_cursor_clip() -> Result<RECT, io::Error> {
pub fn get_cursor_clip() -> windows::core::Result<RECT> {
unsafe {
let mut rect = RECT::default();
win_to_err(|| GetClipCursor(&mut rect)).map(|_| rect)
GetClipCursor(&mut rect).map(|_| rect)
}
}
/// Sets the cursor's clip rect.
///
/// Note that calling this will automatically dispatch a `WM_MOUSEMOVE` event.
pub fn set_cursor_clip(rect: Option<RECT>) -> Result<(), io::Error> {
pub fn set_cursor_clip(rect: Option<RECT>) -> windows::core::Result<()> {
unsafe {
let rect_ptr = rect.as_ref().map(|r| r as *const RECT);
win_to_err(|| ClipCursor(rect_ptr))
ClipCursor(rect_ptr)
}
}
@@ -221,25 +210,18 @@ pub fn is_visible(window: HWND) -> bool {
unsafe { IsWindowVisible(window).as_bool() }
}
pub fn is_maximized(window: HWND) -> bool {
pub fn is_maximized(window: HWND) -> windows::core::Result<bool> {
let mut placement = WINDOWPLACEMENT {
length: mem::size_of::<WINDOWPLACEMENT>() as u32,
..WINDOWPLACEMENT::default()
};
unsafe {
GetWindowPlacement(window, &mut placement);
}
placement.showCmd == SW_MAXIMIZE
unsafe { GetWindowPlacement(window, &mut placement)? };
Ok(placement.showCmd == SW_MAXIMIZE.0 as u32)
}
pub fn cursor_position() -> Result<PhysicalPosition<f64>, ExternalError> {
pub fn cursor_position() -> windows::core::Result<PhysicalPosition<f64>> {
let mut pt = POINT { x: 0, y: 0 };
if !unsafe { GetCursorPos(&mut pt) }.as_bool() {
return Err(ExternalError::Os(os_error!(OsError::IoError(
io::Error::last_os_error()
))));
}
unsafe { GetCursorPos(&mut pt)? };
Ok((pt.x, pt.y).into())
}

View File

@@ -14,7 +14,6 @@ use std::{
ffi::OsStr,
io, mem,
os::windows::ffi::OsStrExt,
ptr,
sync::Arc,
};
@@ -22,7 +21,7 @@ use crossbeam_channel as channel;
use windows::{
core::PCWSTR,
Win32::{
Foundation::{self as win32f, HMODULE, HWND, LPARAM, LRESULT, POINT, RECT, WPARAM},
Foundation::{self as win32f, HINSTANCE, HMODULE, HWND, LPARAM, LRESULT, POINT, RECT, WPARAM},
Graphics::{
Dwm::{DwmEnableBlurBehindWindow, DWM_BB_BLURREGION, DWM_BB_ENABLE, DWM_BLURBEHIND},
Gdi::*,
@@ -30,7 +29,7 @@ use windows::{
System::{Com::*, LibraryLoader::*, Ole::*},
UI::{
Input::{Ime::*, KeyboardAndMouse::*, Touch::*},
Shell::{ITaskbarList4 as ITaskbarList, TaskbarList, TBPFLAG, *},
Shell::{ITaskbarList4 as ITaskbarList, TaskbarList, *},
WindowsAndMessaging::{self as win32wm, *},
},
},
@@ -87,7 +86,7 @@ impl Window {
let file_drop_handler = if drag_and_drop {
// It is ok if the initialize result is `S_FALSE` because it might happen that
// multiple windows are created on the same thread.
if let Err(error) = OleInitialize(ptr::null_mut()) {
if let Err(error) = OleInitialize(None) {
match error.code() {
win32f::OLE_E_WRONGCOMPOBJ => {
panic!("OleInitialize failed! Result was: `OLE_E_WRONGCOMPOBJ`")
@@ -135,7 +134,7 @@ impl Window {
pub fn set_title(&self, text: &str) {
let text = util::encode_wide(text);
unsafe {
SetWindowTextW(self.window.0, PCWSTR::from_raw(text.as_ptr()));
let _ = SetWindowTextW(self.window.0, PCWSTR::from_raw(text.as_ptr()));
}
}
@@ -185,7 +184,7 @@ impl Window {
#[inline]
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
util::get_window_rect(self.window.0)
unsafe { util::get_window_rect(self.window.0) }
.map(|rect| Ok(PhysicalPosition::new(rect.left as i32, rect.top as i32)))
.expect("Unexpected GetWindowRect failure")
}
@@ -212,7 +211,7 @@ impl Window {
});
unsafe {
SetWindowPos(
let _ = SetWindowPos(
self.window.0,
HWND::default(),
x as i32,
@@ -228,7 +227,7 @@ impl Window {
#[inline]
pub fn inner_size(&self) -> PhysicalSize<u32> {
let mut rect = RECT::default();
if !unsafe { GetClientRect(self.window.0, &mut rect) }.as_bool() {
if unsafe { GetClientRect(self.window.0, &mut rect) }.is_err() {
panic!("Unexpected GetClientRect failure")
}
PhysicalSize::new(
@@ -239,7 +238,7 @@ impl Window {
#[inline]
pub fn outer_size(&self) -> PhysicalSize<u32> {
util::get_window_rect(self.window.0)
unsafe { util::get_window_rect(self.window.0) }
.map(|rect| {
PhysicalSize::new(
(rect.right - rect.left) as u32,
@@ -419,7 +418,7 @@ impl Window {
#[inline]
pub fn cursor_position(&self) -> Result<PhysicalPosition<f64>, ExternalError> {
util::cursor_position()
util::cursor_position().map_err(Into::into)
}
#[inline]
@@ -439,27 +438,23 @@ impl Window {
io::Error::last_os_error()
))));
}
if !SetCursorPos(point.x, point.y).as_bool() {
return Err(ExternalError::Os(os_error!(OsError::IoError(
io::Error::last_os_error()
))));
}
SetCursorPos(point.x, point.y)
.map_err(|e| ExternalError::Os(os_error!(OsError::IoError(e.into()))))
}
Ok(())
}
#[inline]
pub fn drag_window(&self) -> Result<(), ExternalError> {
let mut pos = POINT::default();
unsafe {
GetCursorPos(&mut pos);
ReleaseCapture();
GetCursorPos(&mut pos)?;
ReleaseCapture()?;
PostMessageW(
self.window.0,
WM_NCLBUTTONDOWN,
WPARAM(HTCAPTION as _),
util::MAKELPARAM(pos.x as i16, pos.y as i16),
);
)?;
}
Ok(())
@@ -660,7 +655,7 @@ impl Window {
// Save window bounds before entering fullscreen
let placement = unsafe {
let mut placement = WINDOWPLACEMENT::default();
GetWindowPlacement(window.0, &mut placement);
let _ = GetWindowPlacement(window.0, &mut placement);
placement
};
@@ -678,7 +673,7 @@ impl Window {
let size: (u32, u32) = monitor.size().into();
unsafe {
SetWindowPos(
let _ = SetWindowPos(
window.0,
HWND::default(),
position.0,
@@ -695,7 +690,7 @@ impl Window {
if let Some(SavedWindow { placement }) = window_state_lock.saved_window.take() {
drop(window_state_lock);
unsafe {
SetWindowPlacement(window.0, &placement);
let _ = SetWindowPlacement(window.0, &placement);
InvalidateRgn(window.0, HRGN::default(), false);
}
}
@@ -864,8 +859,8 @@ impl Window {
let w_param = WPARAM(edge as _);
let l_param = util::MAKELPARAM(x as i16, y as i16);
ReleaseCapture();
PostMessageW(self.hwnd(), button, w_param, l_param);
let _ = ReleaseCapture();
let _ = PostMessageW(self.hwnd(), button, w_param, l_param);
}
}
@@ -884,16 +879,16 @@ impl Window {
if let Some(state) = progress.state {
let taskbar_state = {
match state {
ProgressState::None => 0,
ProgressState::Indeterminate => 1,
ProgressState::Normal => 2,
ProgressState::Error => 3,
ProgressState::Paused => 4,
ProgressState::None => TBPF_NOPROGRESS,
ProgressState::Indeterminate => TBPF_INDETERMINATE,
ProgressState::Normal => TBPF_NORMAL,
ProgressState::Error => TBPF_ERROR,
ProgressState::Paused => TBPF_PAUSED,
}
};
taskbar_list
.SetProgressState(handle, TBPFLAG(taskbar_state))
.SetProgressState(handle, taskbar_state)
.unwrap_or(());
}
if let Some(value) = progress.progress {
@@ -921,7 +916,7 @@ impl Window {
pub fn set_content_protection(&self, enabled: bool) {
unsafe {
SetWindowDisplayAffinity(
let _ = SetWindowDisplayAffinity(
self.hwnd(),
if enabled {
WDA_EXCLUDEFROMCAPTURE
@@ -940,7 +935,7 @@ impl Drop for Window {
unsafe {
// The window must be destroyed from the same thread that created it, so we send a
// custom message to be handled by our callback to do the actual work.
PostMessageW(self.window.0, *DESTROY_MSG_ID, WPARAM(0), LPARAM(0));
let _ = PostMessageW(self.window.0, *DESTROY_MSG_ID, WPARAM(0), LPARAM(0));
}
}
}
@@ -1038,7 +1033,7 @@ unsafe fn init<T: 'static>(
{
let digitizer = GetSystemMetrics(SM_DIGITIZER) as u32;
if digitizer & NID_READY != 0 {
RegisterTouchWindow(real_window.0, TWF_WANTPALM);
RegisterTouchWindow(real_window.0, TWF_WANTPALM)?;
}
}
@@ -1138,7 +1133,7 @@ unsafe fn register_window_class(window_classname: &str) -> Vec<u16> {
lpfnWndProc: Some(window_proc),
cbClsExtra: 0,
cbWndExtra: 0,
hInstance: GetModuleHandleW(PCWSTR::null()).unwrap_or_default(),
hInstance: HINSTANCE(GetModuleHandleW(PCWSTR::null()).unwrap_or_default().0),
hIcon: HICON::default(),
hCursor: HCURSOR::default(), // must be null in order for cursor state to work properly
hbrBackground: HBRUSH::default(),
@@ -1176,7 +1171,7 @@ unsafe extern "system" fn window_proc(
}
// adjust the maximized borderless window so it doesn't cover the taskbar
if util::is_maximized(window) {
if util::is_maximized(window).unwrap_or(false) {
let params = &mut *(lparam.0 as *mut NCCALCSIZE_PARAMS);
if let Ok(monitor_info) =
monitor::get_monitor_info(MonitorFromRect(&params.rgrc[0], MONITOR_DEFAULTTONULL))
@@ -1313,7 +1308,7 @@ pub fn hit_test(hwnd: isize, cx: i32, cy: i32) -> LRESULT {
let hwnd = HWND(hwnd);
let mut window_rect = RECT::default();
unsafe {
if GetWindowRect(hwnd, <*mut _>::cast(&mut window_rect)).as_bool() {
if GetWindowRect(hwnd, &mut window_rect).is_ok() {
const CLIENT: isize = 0b0000;
const LEFT: isize = 0b0001;
const RIGHT: isize = 0b0010;

View File

@@ -305,7 +305,7 @@ impl WindowFlags {
if diff.contains(WindowFlags::ALWAYS_ON_TOP) {
unsafe {
SetWindowPos(
let _ = SetWindowPos(
window,
match new.contains(WindowFlags::ALWAYS_ON_TOP) {
true => HWND_TOPMOST,
@@ -323,7 +323,7 @@ impl WindowFlags {
if diff.contains(WindowFlags::ALWAYS_ON_BOTTOM) {
unsafe {
SetWindowPos(
let _ = SetWindowPos(
window,
match new.contains(WindowFlags::ALWAYS_ON_BOTTOM) {
true => HWND_BOTTOM,
@@ -417,7 +417,7 @@ impl WindowFlags {
}
// Refresh the window frame
SetWindowPos(window, HWND::default(), 0, 0, 0, 0, flags);
let _ = SetWindowPos(window, HWND::default(), 0, 0, 0, 0, flags);
SendMessageW(
window,
*event_loop::SET_RETAIN_STATE_ON_SIZE_MSG_ID,