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

Attempt to implement AccessKit inside the window crate #5995

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
93 changes: 93 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ gl_generator = "0.14"
wayland = ["wayland-client", "smithay-client-toolkit", "wayland-egl", "wayland-protocols"]

[dependencies]
accesskit = "0.16"
async-channel = "2.3"
async-io = "2.3"
async-task = "4.7"
Expand Down Expand Up @@ -48,6 +49,7 @@ wezterm-font = { path = "../wezterm-font" }
wezterm-input-types = { path = "../wezterm-input-types" }

[target."cfg(windows)".dependencies]
accesskit_windows = "0.22"
clipboard-win = "2.2"
shared_library = "0.1"
winapi = { version = "0.3", features = [
Expand Down
31 changes: 26 additions & 5 deletions window/examples/async.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use ::window::*;
use accesskit::{NodeBuilder, NodeId, Role, Tree, TreeUpdate};
use config::Dimension;
use promise::spawn::spawn;
use std::cell::RefCell;
use std::rc::Rc;
use wezterm_font::FontConfiguration;

const WINDOW_TITLE: &str = "the title";
const WINDOW_ID: NodeId = NodeId(0);

struct MyWindow {
allow_close: bool,
cursor_pos: Point,
Expand Down Expand Up @@ -77,6 +81,10 @@ impl MyWindow {
frame.clear_color_srgb(0.25, 0.125, 0.375, 1.0);
win.finish_frame(frame).unwrap();
}
win.update_accesskit_if_active(accesskit_tree);
}
WindowEvent::InitialAccessKitTreeRequested => {
win.update_accesskit_if_active(accesskit_tree);
}
WindowEvent::AppearanceChanged(_)
| WindowEvent::AdviseDeadKeyStatus(_)
Expand All @@ -89,11 +97,24 @@ impl MyWindow {
| WindowEvent::DroppedString(_)
| WindowEvent::PerformKeyAssignment(_)
| WindowEvent::MouseLeave
| WindowEvent::SetInnerSizeCompleted => {}
| WindowEvent::SetInnerSizeCompleted
| WindowEvent::AccessKitActionRequested(_)
| WindowEvent::AccessibilityDeactivated => {}
}
}
}

fn accesskit_tree() -> TreeUpdate {
let mut root = NodeBuilder::new(Role::Window);
root.set_name(WINDOW_TITLE);
let tree = Tree::new(WINDOW_ID);
TreeUpdate {
nodes: vec![(WINDOW_ID, root.build())],
tree: Some(tree),
focus: WINDOW_ID,
}
}

async fn spawn_window() -> Result<(), Box<dyn std::error::Error>> {
let fontconfig = Rc::new(FontConfiguration::new(
None,
Expand All @@ -114,7 +135,7 @@ async fn spawn_window() -> Result<(), Box<dyn std::error::Error>> {
let cb_state = Rc::clone(&state);
let win = Window::new_window(
"myclass",
"the title",
WINDOW_TITLE,
RequestedWindowGeometry {
width: Dimension::Pixels(800.),
height: Dimension::Pixels(600.),
Expand All @@ -129,11 +150,11 @@ async fn spawn_window() -> Result<(), Box<dyn std::error::Error>> {
)
.await?;

eprintln!("before show");
win.show();
let gl = win.enable_opengl().await?;

state.borrow_mut().gl.replace(gl);

eprintln!("before show");
win.show();
win.invalidate();
Ok(())
}
Expand Down
11 changes: 11 additions & 0 deletions window/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use accesskit::{ActionRequest, TreeUpdate};
use async_trait::async_trait;
use bitflags::bitflags;
use config::window::WindowLevel;
Expand Down Expand Up @@ -216,6 +217,10 @@ pub enum WindowEvent {
PerformKeyAssignment(config::keyassignment::KeyAssignment),

AdviseModifiersLedStatus(Modifiers, KeyboardLedStatus),

InitialAccessKitTreeRequested,
AccessKitActionRequested(ActionRequest),
AccessibilityDeactivated,
}

pub struct WindowEventSender {
Expand Down Expand Up @@ -349,6 +354,12 @@ pub trait WindowOps {
) -> anyhow::Result<Option<os::parameters::Parameters>> {
Ok(None)
}

fn update_accesskit_if_active(
&self,
_update_factory: impl FnOnce() -> TreeUpdate + Send + 'static,
) {
}
}

#[derive(Debug, Clone, Default)]
Expand Down
Loading