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 to 0.58 #453

Merged
merged 2 commits into from
Sep 24, 2024
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
107 changes: 63 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions platforms/windows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ accesskit = { version = "0.16.0", path = "../../common" }
accesskit_consumer = { version = "0.24.0", path = "../../consumer" }
paste = "1.0"
static_assertions = "1.1.0"
windows-core = "0.58.0"

[dependencies.windows]
version = "0.54"
version = "0.58.0"
features = [
"implement",
"Win32_Foundation",
Expand All @@ -36,4 +37,3 @@ features = [
once_cell = "1.13.0"
scopeguard = "1.1.0"
winit = "0.30"

13 changes: 8 additions & 5 deletions platforms/windows/examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ struct SimpleActionHandler {
window: HWND,
}

unsafe impl Send for SimpleActionHandler {}
unsafe impl Sync for SimpleActionHandler {}

impl ActionHandler for SimpleActionHandler {
fn do_action(&mut self, request: ActionRequest) {
match request.action {
Expand Down Expand Up @@ -334,9 +337,9 @@ fn create_window(title: &str, initial_focus: NodeId) -> Result<HWND> {
None,
GetModuleHandleW(None).unwrap(),
Some(Box::into_raw(create_params) as _),
)
)?
};
if window.0 == 0 {
if window.is_invalid() {
return Err(Error::from_win32());
}

Expand All @@ -350,11 +353,11 @@ fn main() -> Result<()> {
println!("Enable Narrator with [Win]+[Ctrl]+[Enter] (or [Win]+[Enter] on older versions of Windows).");

let window = create_window(WINDOW_TITLE, INITIAL_FOCUS)?;
unsafe { ShowWindow(window, SW_SHOW) };
let _ = unsafe { ShowWindow(window, SW_SHOW) };

let mut message = MSG::default();
while unsafe { GetMessageW(&mut message, HWND(0), 0, 0) }.into() {
unsafe { TranslateMessage(&message) };
while unsafe { GetMessageW(&mut message, HWND::default(), 0, 0) }.into() {
let _ = unsafe { TranslateMessage(&message) };
unsafe { DispatchMessageW(&message) };
}

Expand Down
9 changes: 5 additions & 4 deletions platforms/windows/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{
filters::filter,
node::{NodeWrapper, PlatformNode},
util::QueuedEvent,
window_handle::WindowHandle,
};

fn focus_event(context: &Arc<Context>, node_id: NodeId) -> QueuedEvent {
Expand Down Expand Up @@ -140,7 +141,7 @@ const PLACEHOLDER_ROOT_ID: NodeId = NodeId(0);

enum State {
Inactive {
hwnd: HWND,
hwnd: WindowHandle,
is_window_focused: bool,
action_handler: Arc<dyn ActionHandlerNoMut + Send + Sync>,
},
Expand Down Expand Up @@ -186,7 +187,7 @@ impl Adapter {
init_uia();

let state = State::Inactive {
hwnd,
hwnd: hwnd.into(),
is_window_focused,
action_handler,
};
Expand Down Expand Up @@ -356,15 +357,15 @@ fn normalize_objid(lparam: LPARAM) -> i32 {
}

struct WmGetObjectResult {
hwnd: HWND,
hwnd: WindowHandle,
wparam: WPARAM,
lparam: LPARAM,
el: IRawElementProviderSimple,
}

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

Expand Down
7 changes: 3 additions & 4 deletions platforms/windows/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
use accesskit::{ActionHandler, ActionRequest, Point};
use accesskit_consumer::Tree;
use std::sync::{atomic::AtomicBool, Arc, Mutex, RwLock, RwLockReadGuard};
use windows::Win32::Foundation::*;

use crate::util::*;
use crate::{util::*, window_handle::WindowHandle};

pub(crate) trait ActionHandlerNoMut {
fn do_action(&self, request: ActionRequest);
Expand All @@ -29,15 +28,15 @@ impl<H: ActionHandler + Send> ActionHandlerNoMut for ActionHandlerWrapper<H> {
}

pub(crate) struct Context {
pub(crate) hwnd: HWND,
pub(crate) hwnd: WindowHandle,
pub(crate) tree: RwLock<Tree>,
pub(crate) action_handler: Arc<dyn ActionHandlerNoMut + Send + Sync>,
pub(crate) is_placeholder: AtomicBool,
}

impl Context {
pub(crate) fn new(
hwnd: HWND,
hwnd: WindowHandle,
tree: Tree,
action_handler: Arc<dyn ActionHandlerNoMut + Send + Sync>,
is_placeholder: bool,
Expand Down
1 change: 1 addition & 0 deletions platforms/windows/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod filters;
mod node;
mod text;
mod util;
mod window_handle;

mod adapter;
pub use adapter::{Adapter, QueuedEvents};
Expand Down
Loading