windows: Bump windows-rs version (#14719)

Release Notes:

- N/A
This commit is contained in:
张小白
2024-07-25 10:41:59 -07:00
committed by GitHub
parent 82d6ad4616
commit d2501e8886
13 changed files with 164 additions and 90 deletions
+1 -1
View File
@@ -150,7 +150,7 @@ x11-clipboard = "0.9.2"
[target.'cfg(windows)'.dependencies]
windows.workspace = true
windows-core = "0.57"
windows-core = "0.58"
[[example]]
name = "hello_world"
+2
View File
@@ -6,6 +6,7 @@ mod platform;
mod system_settings;
mod util;
mod window;
mod wrapper;
pub(crate) use direct_write::*;
pub(crate) use dispatcher::*;
@@ -15,5 +16,6 @@ pub(crate) use platform::*;
pub(crate) use system_settings::*;
pub(crate) use util::*;
pub(crate) use window::*;
pub(crate) use wrapper::*;
pub(crate) use windows::Win32::Foundation::HWND;
@@ -924,7 +924,7 @@ struct RendererContext<'t, 'a, 'b> {
}
#[allow(non_snake_case)]
impl IDWritePixelSnapping_Impl for TextRenderer {
impl IDWritePixelSnapping_Impl for TextRenderer_Impl {
fn IsPixelSnappingDisabled(
&self,
_clientdrawingcontext: *const ::core::ffi::c_void,
@@ -959,7 +959,7 @@ impl IDWritePixelSnapping_Impl for TextRenderer {
}
#[allow(non_snake_case)]
impl IDWriteTextRenderer_Impl for TextRenderer {
impl IDWriteTextRenderer_Impl for TextRenderer_Impl {
fn DrawGlyphRun(
&self,
clientdrawingcontext: *const ::core::ffi::c_void,
@@ -27,6 +27,10 @@ pub(crate) struct WindowsDisplay {
uuid: Uuid,
}
// The `HMONITOR` is thread-safe.
unsafe impl Send for WindowsDisplay {}
unsafe impl Sync for WindowsDisplay {}
impl WindowsDisplay {
pub(crate) fn new(display_id: DisplayId) -> Option<Self> {
let screen = available_monitors().into_iter().nth(display_id.0 as _)?;
+2 -2
View File
@@ -217,7 +217,7 @@ fn handle_destroy_msg(handle: HWND, state_ptr: Rc<WindowsWindowStatePtr>) -> Opt
callback();
}
unsafe {
PostMessageW(None, CLOSE_ONE_WINDOW, None, LPARAM(handle.0)).log_err();
PostMessageW(None, CLOSE_ONE_WINDOW, None, LPARAM(handle.0 as isize)).log_err();
}
Some(0)
}
@@ -1040,7 +1040,7 @@ fn handle_nc_mouse_up_msg(
}
fn handle_cursor_changed(lparam: LPARAM, state_ptr: Rc<WindowsWindowStatePtr>) -> Option<isize> {
state_ptr.state.borrow_mut().current_cursor = HCURSOR(lparam.0);
state_ptr.state.borrow_mut().current_cursor = HCURSOR(lparam.0 as _);
Some(0)
}
+8 -7
View File
@@ -191,7 +191,7 @@ impl Platform for WindowsPlatform {
match msg.message {
WM_QUIT => break 'a,
CLOSE_ONE_WINDOW => {
if self.close_one_window(HWND(msg.lParam.0)) {
if self.close_one_window(HWND(msg.lParam.0 as _)) {
break 'a;
}
}
@@ -484,7 +484,7 @@ impl Platform for WindowsPlatform {
let hcursor = load_cursor(style);
let mut lock = self.state.borrow_mut();
if lock.current_cursor.0 != hcursor.0 {
self.post_message(CURSOR_STYLE_CHANGED, WPARAM(0), LPARAM(hcursor.0));
self.post_message(CURSOR_STYLE_CHANGED, WPARAM(0), LPARAM(hcursor.0 as isize));
lock.current_cursor = hcursor;
}
}
@@ -595,7 +595,7 @@ fn open_target(target: &str) {
None,
SW_SHOWDEFAULT,
);
if ret.0 <= 32 {
if ret.0 as isize <= 32 {
log::error!("Unable to open target: {}", std::io::Error::last_os_error());
}
}
@@ -611,7 +611,7 @@ fn open_target_in_explorer(target: &str) {
None,
SW_SHOWDEFAULT,
);
if ret.0 <= 32 {
if ret.0 as isize <= 32 {
log::error!(
"Unable to open target in explorer: {}",
std::io::Error::last_os_error()
@@ -643,11 +643,12 @@ unsafe fn show_savefile_dialog(directory: PathBuf) -> Result<IFileSaveDialog> {
Ok(dialog)
}
fn begin_vsync(vsync_evnet: HANDLE) {
fn begin_vsync(vsync_event: HANDLE) {
let event: SafeHandle = vsync_event.into();
std::thread::spawn(move || unsafe {
loop {
windows::Win32::Graphics::Dwm::DwmFlush().log_err();
SetEvent(vsync_evnet).log_err();
SetEvent(*event).log_err();
}
});
}
@@ -723,7 +724,7 @@ fn set_data_to_clipboard(data: &[u16], format: u32) -> Result<()> {
let handle = GlobalLock(global);
u_memcpy(handle as _, data.as_ptr(), data.len() as _);
let _ = GlobalUnlock(global);
SetClipboardData(format, HANDLE(global.0 as isize))?;
SetClipboardData(format, HANDLE(global.0))?;
}
Ok(())
}
+10 -9
View File
@@ -85,13 +85,13 @@ pub(crate) fn windows_credentials_target_name(url: &str) -> String {
}
pub(crate) fn load_cursor(style: CursorStyle) -> HCURSOR {
static ARROW: OnceLock<HCURSOR> = OnceLock::new();
static IBEAM: OnceLock<HCURSOR> = OnceLock::new();
static CROSS: OnceLock<HCURSOR> = OnceLock::new();
static HAND: OnceLock<HCURSOR> = OnceLock::new();
static SIZEWE: OnceLock<HCURSOR> = OnceLock::new();
static SIZENS: OnceLock<HCURSOR> = OnceLock::new();
static NO: OnceLock<HCURSOR> = OnceLock::new();
static ARROW: OnceLock<SafeCursor> = OnceLock::new();
static IBEAM: OnceLock<SafeCursor> = OnceLock::new();
static CROSS: OnceLock<SafeCursor> = OnceLock::new();
static HAND: OnceLock<SafeCursor> = OnceLock::new();
static SIZEWE: OnceLock<SafeCursor> = OnceLock::new();
static SIZENS: OnceLock<SafeCursor> = OnceLock::new();
static NO: OnceLock<SafeCursor> = OnceLock::new();
let (lock, name) = match style {
CursorStyle::IBeam | CursorStyle::IBeamCursorForVerticalLayout => (&IBEAM, IDC_IBEAM),
CursorStyle::Crosshair => (&CROSS, IDC_CROSS),
@@ -107,14 +107,15 @@ pub(crate) fn load_cursor(style: CursorStyle) -> HCURSOR {
CursorStyle::OperationNotAllowed => (&NO, IDC_NO),
_ => (&ARROW, IDC_ARROW),
};
*lock.get_or_init(|| {
*(*lock.get_or_init(|| {
HCURSOR(
unsafe { LoadImageW(None, name, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED) }
.log_err()
.unwrap_or_default()
.0,
)
})
.into()
}))
}
#[inline]
+16 -12
View File
@@ -297,7 +297,7 @@ impl WindowsWindow {
current_cursor,
};
let lpparam = Some(&context as *const _ as *const _);
let raw_hwnd = unsafe {
let creation_result = unsafe {
CreateWindowExW(
dwexstyle,
classname,
@@ -313,7 +313,10 @@ impl WindowsWindow {
lpparam,
)
};
// We should call `?` on state_ptr first, then call `?` on raw_hwnd.
// Or, we will lose the error info reported by `WindowsWindowState::new`
let state_ptr = context.inner.take().unwrap()?;
let raw_hwnd = creation_result?;
register_drag_drop(state_ptr.clone())?;
unsafe {
@@ -343,9 +346,10 @@ impl WindowsWindow {
impl rwh::HasWindowHandle for WindowsWindow {
fn window_handle(&self) -> std::result::Result<rwh::WindowHandle<'_>, rwh::HandleError> {
let raw =
rwh::Win32WindowHandle::new(unsafe { NonZeroIsize::new_unchecked(self.0.hwnd.0) })
.into();
let raw = rwh::Win32WindowHandle::new(unsafe {
NonZeroIsize::new_unchecked(self.0.hwnd.0 as isize)
})
.into();
Ok(unsafe { rwh::WindowHandle::borrow_raw(raw) })
}
}
@@ -509,8 +513,8 @@ impl PlatformWindow for WindowsWindow {
fn activate(&self) {
let hwnd = self.0.hwnd;
unsafe { SetActiveWindow(hwnd) };
unsafe { SetFocus(hwnd) };
unsafe { SetActiveWindow(hwnd).log_err() };
unsafe { SetFocus(hwnd).log_err() };
// todo(windows)
// crate `windows 0.56` reports true as Err
unsafe { SetForegroundWindow(hwnd).as_bool() };
@@ -678,7 +682,7 @@ impl WindowsDragDropHandler {
}
#[allow(non_snake_case)]
impl IDropTarget_Impl for WindowsDragDropHandler {
impl IDropTarget_Impl for WindowsDragDropHandler_Impl {
fn DragEnter(
&self,
pdataobj: Option<&IDataObject>,
@@ -956,7 +960,7 @@ unsafe extern "system" fn wnd_proc(
}
pub(crate) fn try_get_window_inner(hwnd: HWND) -> Option<Rc<WindowsWindowStatePtr>> {
if hwnd == HWND(0) {
if hwnd.is_invalid() {
return None;
}
@@ -1058,7 +1062,7 @@ mod windows_renderer {
};
pub(super) fn windows_renderer(hwnd: HWND, transparent: bool) -> anyhow::Result<BladeRenderer> {
let raw = RawWindow { hwnd: hwnd.0 };
let raw = RawWindow { hwnd };
let gpu: Arc<gpu::Context> = Arc::new(
unsafe {
gpu::Context::init_windowed(
@@ -1081,15 +1085,15 @@ mod windows_renderer {
}
struct RawWindow {
hwnd: isize,
hwnd: HWND,
}
impl rwh::HasWindowHandle for RawWindow {
fn window_handle(&self) -> Result<rwh::WindowHandle<'_>, rwh::HandleError> {
Ok(unsafe {
let hwnd = NonZeroIsize::new_unchecked(self.hwnd);
let hwnd = NonZeroIsize::new_unchecked(self.hwnd.0 as isize);
let mut handle = rwh::Win32WindowHandle::new(hwnd);
let hinstance = get_window_long(HWND(self.hwnd), GWLP_HINSTANCE);
let hinstance = get_window_long(self.hwnd, GWLP_HINSTANCE);
handle.hinstance = NonZeroIsize::new(hinstance);
rwh::WindowHandle::borrow_raw(handle.into())
})
@@ -0,0 +1,47 @@
use std::ops::Deref;
use windows::Win32::{Foundation::HANDLE, UI::WindowsAndMessaging::HCURSOR};
#[derive(Debug, Clone, Copy)]
pub(crate) struct SafeHandle {
raw: HANDLE,
}
unsafe impl Send for SafeHandle {}
unsafe impl Sync for SafeHandle {}
impl From<HANDLE> for SafeHandle {
fn from(value: HANDLE) -> Self {
SafeHandle { raw: value }
}
}
impl Deref for SafeHandle {
type Target = HANDLE;
fn deref(&self) -> &Self::Target {
&self.raw
}
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct SafeCursor {
raw: HCURSOR,
}
unsafe impl Send for SafeCursor {}
unsafe impl Sync for SafeCursor {}
impl From<HCURSOR> for SafeCursor {
fn from(value: HCURSOR) -> Self {
SafeCursor { raw: value }
}
}
impl Deref for SafeCursor {
type Target = HCURSOR;
fn deref(&self) -> &Self::Target {
&self.raw
}
}
+3 -3
View File
@@ -38,9 +38,9 @@ impl ProcessIdGetter {
fn new(pty: &Pty) -> ProcessIdGetter {
let child = pty.child_watcher();
let handle = child.raw_handle();
let fallback_pid = child
.pid()
.unwrap_or_else(|| unsafe { NonZeroU32::new_unchecked(GetProcessId(HANDLE(handle))) });
let fallback_pid = child.pid().unwrap_or_else(|| unsafe {
NonZeroU32::new_unchecked(GetProcessId(HANDLE(handle as _)))
});
ProcessIdGetter {
handle: handle as i32,