Skip to content

Commit

Permalink
Use new objc2 crates
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Apr 23, 2024
1 parent f808c53 commit 50ac029
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 73 deletions.
71 changes: 47 additions & 24 deletions Cargo.lock

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

31 changes: 16 additions & 15 deletions platforms/macos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ default-target = "x86_64-apple-darwin"
[dependencies]
accesskit = { version = "0.13.0", path = "../../common" }
accesskit_consumer = { version = "0.18.0", path = "../../consumer" }
objc2 = "0.5.0"
once_cell = "1.13.0"

[dependencies.icrate]
version = "0.1.0"
features = [
"AppKit",
"AppKit_NSAccessibilityElement",
"AppKit_NSView",
"AppKit_NSWindow",
"Foundation",
"Foundation_NSArray",
"Foundation_NSMutableDictionary",
"Foundation_NSNumber",
"Foundation_NSThread",
]
objc2 = "0.5.1"
objc2-foundation = { version = "0.2.0", features = [
"NSArray",
"NSDictionary",
"NSValue",
"NSThread",
] }
objc2-app-kit = { version = "0.2.0", features = [
"NSAccessibility",
"NSAccessibilityConstants",
"NSAccessibilityElement",
"NSAccessibilityProtocols",
"NSResponder",
"NSView",
"NSWindow",
] }
6 changes: 2 additions & 4 deletions platforms/macos/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ use accesskit::{
TreeUpdate,
};
use accesskit_consumer::{FilterResult, Tree};
use icrate::{
AppKit::NSView,
Foundation::{MainThreadMarker, NSArray, NSObject, NSPoint},
};
use objc2::rc::{Id, WeakId};
use objc2_app_kit::NSView;
use objc2_foundation::{MainThreadMarker, NSArray, NSObject, NSPoint};
use std::{ffi::c_void, ptr::null_mut, rc::Rc};

use crate::{
Expand Down
3 changes: 2 additions & 1 deletion platforms/macos/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

use accesskit::{ActionHandler, ActionRequest, NodeId};
use accesskit_consumer::Tree;
use icrate::{AppKit::*, Foundation::MainThreadMarker};
use objc2::rc::{Id, WeakId};
use objc2_app_kit::*;
use objc2_foundation::MainThreadMarker;
use std::{cell::RefCell, collections::HashMap, rc::Rc};

use crate::node::PlatformNode;
Expand Down
12 changes: 5 additions & 7 deletions platforms/macos/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

use accesskit::{Live, NodeId, Role};
use accesskit_consumer::{DetachedNode, FilterResult, Node, TreeChangeHandler, TreeState};
use icrate::{
AppKit::*,
Foundation::{NSMutableDictionary, NSNumber, NSString},
};
use objc2::runtime::{AnyObject, ProtocolObject};
use objc2_app_kit::*;
use objc2_foundation::{NSMutableDictionary, NSNumber, NSString};
use std::{collections::HashSet, rc::Rc};

use crate::{
Expand Down Expand Up @@ -37,9 +35,9 @@ impl QueuedEvent {
Self::Announcement {
text: node.name().unwrap(),
priority: if node.live() == Live::Assertive {
NSAccessibilityPriorityHigh
NSAccessibilityPriorityLevel::NSAccessibilityPriorityHigh
} else {
NSAccessibilityPriorityMedium
NSAccessibilityPriorityLevel::NSAccessibilityPriorityMedium
},
}
}
Expand Down Expand Up @@ -86,7 +84,7 @@ impl QueuedEvent {
ProtocolObject::from_ref(NSAccessibilityAnnouncementKey),
)
};
let priority = NSNumber::new_isize(priority);
let priority = NSNumber::new_isize(priority.0);
unsafe {
user_info.setObject_forKey(
&*priority,
Expand Down
2 changes: 1 addition & 1 deletion platforms/macos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ pub use patch::add_focus_forwarder_to_window_class;
mod subclass;
pub use subclass::SubclassingAdapter;

pub use icrate::Foundation::{NSArray, NSObject, NSPoint};
pub use objc2_foundation::{NSArray, NSObject, NSPoint};
12 changes: 5 additions & 7 deletions platforms/macos/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@

use accesskit::{Action, ActionData, ActionRequest, Checked, NodeId, Role, TextSelection};
use accesskit_consumer::{DetachedNode, FilterResult, Node, NodeState};
use icrate::{
AppKit::*,
Foundation::{
ns_string, NSArray, NSCopying, NSInteger, NSNumber, NSObject, NSPoint, NSRange, NSRect,
NSString,
},
};
use objc2::{
declare_class, msg_send_id,
mutability::InteriorMutable,
rc::Id,
runtime::{AnyObject, Sel},
sel, ClassType, DeclaredClass,
};
use objc2_app_kit::*;
use objc2_foundation::{
ns_string, NSArray, NSCopying, NSInteger, NSNumber, NSObject, NSPoint, NSRange, NSRect,
NSString,
};
use std::rc::{Rc, Weak};

use crate::{context::Context, filters::filter, util::*};
Expand Down
2 changes: 1 addition & 1 deletion platforms/macos/src/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
// the LICENSE-APACHE file) or the MIT license (found in
// the LICENSE-MIT file), at your option.

use icrate::AppKit::NSWindow;
use objc2::{
encode::{Encode, EncodeArguments, EncodeReturn, Encoding},
ffi::class_addMethod,
msg_send,
runtime::{AnyClass, AnyObject, Bool, MethodImplementation, Sel},
sel, Message,
};
use objc2_app_kit::NSWindow;
use std::{ffi::CString, ptr::null_mut};

extern "C" fn focus_forwarder(this: &NSWindow, _cmd: Sel) -> *mut AnyObject {
Expand Down
6 changes: 2 additions & 4 deletions platforms/macos/src/subclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
// the LICENSE-MIT file), at your option.

use accesskit::{ActionHandler, ActivationHandler, TreeUpdate};
use icrate::{
AppKit::{NSView, NSWindow},
Foundation::{NSArray, NSObject, NSPoint},
};
use objc2::{
declare::ClassBuilder,
declare_class,
Expand All @@ -21,6 +17,8 @@ use objc2::{
runtime::{AnyClass, Sel},
sel, ClassType, DeclaredClass,
};
use objc2_app_kit::{NSView, NSWindow};
use objc2_foundation::{NSArray, NSObject, NSPoint};
use once_cell::sync::Lazy;
use std::{cell::RefCell, collections::HashMap, ffi::c_void, sync::Mutex};

Expand Down
16 changes: 7 additions & 9 deletions platforms/macos/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

use accesskit::{Point, Rect};
use accesskit_consumer::{Node, TextPosition, TextRange};
use icrate::{
AppKit::*,
Foundation::{NSPoint, NSRange, NSRect, NSSize},
};
use objc2_app_kit::*;
use objc2_foundation::{NSPoint, NSRange, NSRect, NSSize};

pub(crate) fn from_ns_range<'a>(node: &'a Node<'a>, ns_range: NSRange) -> Option<TextRange<'a>> {
let pos = node.text_position_from_global_utf16_index(ns_range.location)?;
Expand Down Expand Up @@ -37,14 +35,14 @@ pub(crate) fn to_ns_range_for_character(pos: &TextPosition) -> NSRange {

pub(crate) fn from_ns_point(view: &NSView, node: &Node, point: NSPoint) -> Point {
let window = view.window().unwrap();
let point = unsafe { window.convertPointFromScreen(point) };
let point = window.convertPointFromScreen(point);
let point = view.convertPoint_fromView(point, None);
// AccessKit coordinates are in physical (DPI-dependent) pixels, but
// macOS provides logical (DPI-independent) coordinates here.
let factor = window.backingScaleFactor();
let point = Point::new(
point.x * factor,
if unsafe { view.isFlipped() } {
if view.isFlipped() {
point.y * factor
} else {
let view_bounds = view.bounds();
Expand All @@ -63,7 +61,7 @@ pub(crate) fn to_ns_rect(view: &NSView, rect: Rect) -> NSRect {
let rect = NSRect {
origin: NSPoint {
x: rect.x0 / factor,
y: if unsafe { view.isFlipped() } {
y: if view.isFlipped() {
rect.y0 / factor
} else {
let view_bounds = view.bounds();
Expand All @@ -75,7 +73,7 @@ pub(crate) fn to_ns_rect(view: &NSView, rect: Rect) -> NSRect {
height: rect.height() / factor,
},
};
let rect = unsafe { view.convertRect_toView(rect, None) };
let rect = view.convertRect_toView(rect, None);
let window = view.window().unwrap();
unsafe { window.convertRectToScreen(rect) }
window.convertRectToScreen(rect)
}

0 comments on commit 50ac029

Please sign in to comment.