Skip to content

Commit

Permalink
chore(platforms/windows)!: Bump windows-rs dependency (#126)
Browse files Browse the repository at this point in the history
chore(platforms/winit): Bump windows-rs dependency (#126)
  • Loading branch information
DataTriny authored Sep 22, 2022
1 parent 6026c1b commit 472a75e
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 269 deletions.
278 changes: 67 additions & 211 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions platforms/windows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ accesskit = { version = "0.4.0", path = "../../common" }
accesskit_consumer = { version = "0.4.0", path = "../../consumer" }
arrayvec = "0.7.1"
lazy-init = "0.5.0"
libc = "0.2.112"
paste = "1.0"

[dependencies.windows]
version = "0.37.0"
version = "0.40.0"
features = [
"alloc",
"implement",
"Win32_Foundation",
"Win32_Graphics_Gdi",
Expand All @@ -39,4 +37,4 @@ crossbeam-utils = "0.8.5"
lazy_static = "1.4.0"
parking_lot = "0.11.2"
scopeguard = "1.1.0"
winit = "0.26.1"
winit = "0.27.3"
15 changes: 4 additions & 11 deletions platforms/windows/examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,17 @@ lazy_static! {
let instance = unsafe { GetModuleHandleW(None) };
instance.unwrap()
};

static ref DEFAULT_CURSOR: HCURSOR = {
let cursor = unsafe { LoadCursorW(None, IDC_ARROW) };
cursor.unwrap()
};

static ref WINDOW_CLASS_ATOM: u16 = {
// The following is a combination of the implementation of
// IntoParam<PWSTR> and the class registration function from winit.
let class_name_wsz: Vec<_> = "AccessKitTest"
.encode_utf16()
.chain(std::iter::once(0))
.collect();
let class_name = w!("AccessKitTest");

let wc = WNDCLASSW {
hCursor: *DEFAULT_CURSOR,
hInstance: *WIN32_INSTANCE,
lpszClassName: PCWSTR(class_name_wsz.as_ptr() as _),
lpszClassName: class_name.into(),
style: CS_HREDRAW | CS_VREDRAW,
lpfnWndProc: Some(wndproc),
..Default::default()
Expand Down Expand Up @@ -233,7 +226,7 @@ extern "system" fn wndproc(window: HWND, message: u32, wparam: WPARAM, lparam: L
unsafe { DefWindowProcW(window, message, wparam, lparam) }
}
WM_PAINT => {
unsafe { ValidateRect(window, std::ptr::null()) }.unwrap();
unsafe { ValidateRect(window, None) }.unwrap();
LRESULT(0)
}
WM_DESTROY => {
Expand Down Expand Up @@ -323,7 +316,7 @@ fn create_window(title: &str, initial_state: TreeUpdate, initial_focus: NodeId)
CreateWindowExW(
Default::default(),
PCWSTR(*WINDOW_CLASS_ATOM as usize as _),
title,
&HSTRING::from(title),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
Expand Down
12 changes: 6 additions & 6 deletions platforms/windows/src/adapter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The AccessKit Authors. All rights reserved.
// Copyright 2022 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.
Expand Down Expand Up @@ -177,7 +177,7 @@ struct WmGetObjectResult {

impl From<WmGetObjectResult> for LRESULT {
fn from(this: WmGetObjectResult) -> Self {
unsafe { UiaReturnRawElementProvider(this.hwnd, this.wparam, this.lparam, this.el) }
unsafe { UiaReturnRawElementProvider(this.hwnd, this.wparam, this.lparam, &this.el) }
}
}

Expand Down Expand Up @@ -210,7 +210,7 @@ impl QueuedEvents {
for event in self.0 {
match event {
QueuedEvent::Simple { element, event_id } => {
unsafe { UiaRaiseAutomationEvent(element, event_id) }.unwrap();
unsafe { UiaRaiseAutomationEvent(&element, event_id) }.unwrap();
}
QueuedEvent::PropertyChanged {
element,
Expand All @@ -220,10 +220,10 @@ impl QueuedEvents {
} => {
unsafe {
UiaRaiseAutomationPropertyChangedEvent(
element,
&element,
property_id,
old_value,
new_value,
&old_value,
&new_value,
)
}
.unwrap();
Expand Down
11 changes: 2 additions & 9 deletions platforms/windows/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The AccessKit Authors. All rights reserved.
// Copyright 2022 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.
Expand Down Expand Up @@ -783,14 +783,7 @@ patterns! {
), (
fn SetValue(&self, value: &PCWSTR) -> Result<()> {
self.0.resolve(|resolved| {
// Based on BSTR::as_wide in windows-rs
let value_as_wide = if value.0.is_null() {
&[]
} else {
let len = unsafe { libc::wcslen(value.0) };
unsafe { std::slice::from_raw_parts(value.0 as *const _, len) }
};
let value = String::from_utf16(value_as_wide).unwrap();
let value = unsafe { value.to_string() }.unwrap();
resolved.set_value(value);
Ok(())
})
Expand Down
2 changes: 1 addition & 1 deletion platforms/windows/src/subclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use windows::{

use crate::Adapter;

const PROP_NAME: &str = "AccessKitAdapter";
const PROP_NAME: &HSTRING = w!("AccessKitAdapter");

struct SubclassImpl {
adapter: Adapter,
Expand Down
17 changes: 5 additions & 12 deletions platforms/windows/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The AccessKit Authors. All rights reserved.
// Copyright 2022 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.
Expand Down Expand Up @@ -27,24 +27,17 @@ lazy_static! {
let instance = unsafe { GetModuleHandleW(None) };
instance.unwrap()
};

static ref DEFAULT_CURSOR: HCURSOR = {
let cursor = unsafe { LoadCursorW(None, IDC_ARROW) };
cursor.unwrap()
};

static ref WINDOW_CLASS_ATOM: u16 = {
// The following is a combination of the implementation of
// IntoParam<PWSTR> and the class registration function from winit.
let class_name_wsz: Vec<_> = "AccessKitTest"
.encode_utf16()
.chain(std::iter::once(0))
.collect();
let class_name = w!("AccessKitTest");

let wc = WNDCLASSW {
hCursor: *DEFAULT_CURSOR,
hInstance: *WIN32_INSTANCE,
lpszClassName: PCWSTR(class_name_wsz.as_ptr() as _),
lpszClassName: class_name.into(),
style: CS_HREDRAW | CS_VREDRAW,
lpfnWndProc: Some(wndproc),
..Default::default()
Expand Down Expand Up @@ -118,7 +111,7 @@ extern "system" fn wndproc(window: HWND, message: u32, wparam: WPARAM, lparam: L
unsafe { DefWindowProcW(window, message, wparam, lparam) }
}
WM_PAINT => {
unsafe { ValidateRect(window, std::ptr::null()) }.unwrap();
unsafe { ValidateRect(window, None) }.unwrap();
LRESULT(0)
}
WM_DESTROY => {
Expand Down Expand Up @@ -172,7 +165,7 @@ fn create_window(
CreateWindowExW(
Default::default(),
PCWSTR(*WINDOW_CLASS_ATOM as usize as _),
title,
&HSTRING::from(title),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
Expand Down
7 changes: 5 additions & 2 deletions platforms/windows/src/tests/simple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The AccessKit Authors. All rights reserved.
// Copyright 2022 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.
Expand Down Expand Up @@ -167,7 +167,10 @@ fn navigation() -> Result<()> {
fn focus() -> Result<()> {
scope(|s| {
let (focus_event_handler, received_focus_event) = FocusEventHandler::new();
unsafe { s.uia.AddFocusChangedEventHandler(None, focus_event_handler) }?;
unsafe {
s.uia
.AddFocusChangedEventHandler(None, &focus_event_handler)
}?;

s.show_and_focus_window();
let focus_from_event = received_focus_event.wait(is_button_1);
Expand Down
8 changes: 4 additions & 4 deletions platforms/windows/src/tests/subclassed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::num::NonZeroU128;
use accesskit::{ActionHandler, ActionRequest, Node, NodeId, Role, Tree, TreeUpdate};
use windows::Win32::{Foundation::*, UI::Accessibility::*};
use winit::{
event_loop::EventLoop,
platform::windows::{EventLoopExtWindows, WindowExtWindows},
event_loop::EventLoopBuilder,
platform::windows::{EventLoopBuilderExtWindows, WindowExtWindows},
window::WindowBuilder,
};

Expand Down Expand Up @@ -57,12 +57,12 @@ impl ActionHandler for NullActionHandler {
fn has_native_uia() {
// This test is simple enough that we know it's fine to run entirely
// on one thread, so we don't need a full multithreaded test harness.
let event_loop = EventLoop::<()>::new_any_thread();
let event_loop = EventLoopBuilder::<()>::new().with_any_thread(true).build();
let window = WindowBuilder::new()
.with_title(WINDOW_TITLE)
.build(&event_loop)
.unwrap();
let hwnd = HWND(window.hwnd() as _);
let hwnd = HWND(window.hwnd());
assert!(!unsafe { UiaHasServerSideProvider(hwnd) }.as_bool());
let adapter = Adapter::new(
hwnd,
Expand Down
19 changes: 11 additions & 8 deletions platforms/windows/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Copyright 2021 The AccessKit Authors. All rights reserved.
// Copyright 2022 The AccessKit Authors. All rights reserved.
// Licensed under the Apache License, Version 2.0 (found in
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

use std::{convert::TryInto, mem::ManuallyDrop};
use windows::Win32::{
Foundation::*,
System::{Com::*, Ole::*},
UI::Accessibility::*,
use windows::{
core::*,
Win32::{
System::{Com::*, Ole::*},
UI::Accessibility::*,
},
};

pub(crate) struct VariantFactory(VARENUM, VARIANT_0_0_0);
Expand All @@ -18,7 +20,7 @@ impl From<VariantFactory> for VARIANT {
Self {
Anonymous: VARIANT_0 {
Anonymous: ManuallyDrop::new(VARIANT_0_0 {
vt: vt.0 as u16,
vt: VARENUM(vt.0 as u16),
wReserved1: 0,
wReserved2: 0,
wReserved3: 0,
Expand Down Expand Up @@ -101,13 +103,14 @@ impl<T: Into<VariantFactory>> From<Option<T>> for VariantFactory {
}

fn safe_array_from_slice<T>(vt: VARENUM, slice: &[T]) -> *mut SAFEARRAY {
let sa = unsafe { SafeArrayCreateVector(vt.0 as u16, 0, slice.len().try_into().unwrap()) };
let sa =
unsafe { SafeArrayCreateVector(VARENUM(vt.0 as u16), 0, slice.len().try_into().unwrap()) };
if sa.is_null() {
panic!("SAFEARRAY allocation failed");
}
for (i, item) in slice.iter().enumerate() {
let i: i32 = i.try_into().unwrap();
unsafe { SafeArrayPutElement(sa, &i, (item as *const T) as *const _) }.unwrap();
unsafe { SafeArrayPutElement(&*sa, &i, (item as *const T) as *const _) }.unwrap();
}
sa
}
Expand Down
2 changes: 1 addition & 1 deletion platforms/winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ winit = "0.27.3"
accesskit_windows = { version = "0.4.0", path = "../windows" }

[target.'cfg(target_os = "windows")'.dependencies.windows]
version = "0.37.0"
version = "0.40.0"
features = [
"Win32_Foundation",
]

0 comments on commit 472a75e

Please sign in to comment.