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

[Suggestion] Add missing ApplicationServices bindings #7536

Open
Semptra opened this issue Dec 3, 2019 · 5 comments
Open

[Suggestion] Add missing ApplicationServices bindings #7536

Semptra opened this issue Dec 3, 2019 · 5 comments
Labels
enhancement The issue or pull request is an enhancement help wanted This is an issue or pull request where we request help from the community to fix or complete macOS Issues affecting macOS missing-api-bindings
Milestone

Comments

@Semptra
Copy link

Semptra commented Dec 3, 2019

There is a lot of accessibility-related APIs existing in Application Services framework that does not have bindings to them in Xamarin.Mac. For example, I cannot find any binding for AXUIElement which can be used to directly access accessibility features for other applications.
It there any plans for adding those bindings?

@spouliot spouliot added enhancement The issue or pull request is an enhancement macOS Issues affecting macOS labels Dec 3, 2019
@spouliot spouliot added this to the Future milestone Dec 3, 2019
@spouliot spouliot added the help wanted This is an issue or pull request where we request help from the community to fix or complete label Dec 3, 2019
@spouliot
Copy link
Contributor

spouliot commented Dec 3, 2019

There's no concrete plans (as someone currently working on them) to add those API.

IIRC (I'm no expert on the subject) those are API to create applications that use/control accessibility than providing accessibility itself, right ?

Feel free to contribute bindings/samples for them, your contributions would be welcome :)

@lars-berger
Copy link

Are there resources on how to contribute bindings? I'd very much like this as well.

@rolfbjarne
Copy link
Member

It looks like this is C-based API (and not Objective-C), in which case the binding workflow would go something like this:

  • Figure out how you want the C# API to look like. My guess (which may be wrong, I haven't looked much at the documentation) is that you'd want two classes (AXUIElement and AXObserver), with properties/methods based on the various AXUIElement* and AXObserver* C methods (from here: https://developer.apple.com/documentation/applicationservices/axuielement_h?language=objc)

  • It looks like memory management is done using CFRetain/CFRelease, in which case base class for the managed types should be CoreFoundation.NativeObject, which handles some of the related boiler plate code:

https://github.com/xamarin/xamarin-macios/blob/b2ae8507e062093daf8502efb9988a1d23d12e19/src/CoreFoundation/NativeObject.cs#L24-L42

  • Bind the C methods using P/Invokes. You can look at some of the CoreFoundation types to see how we've done it elsewhere: https://github.com/xamarin/xamarin-macios/tree/main/src/CoreFoundation

  • Write tests! This is very important, not only to make sure you're binding the API correctly, but you'll often come up with a better C# API when you try to actually use the API in C#.

  • I would suggest creating a draft PR early in the process (maybe when you have a single method/property bound) with your current work and ask for feedback, because we have a lot of patterns/requirements which would be too much to list here.

@Irasil
Copy link

Irasil commented Dec 11, 2023

Is there any news about this or has anyone already managed to use AXUIElement in .Net?

@snechaev
Copy link
Contributor

If anyone is still interested, I have implemented bindings for the very limited set of APIs from the AXUIElement.h, including AXUIElement and some APIs for traversing the elements tree and working with the attributes and actions. See here: https://github.com/snechaev/xamarin-mac-accessibility-bindings/

All constructive feedback and contributions are welcome.

I hope that the code will eventually be mature enough to be integrated into the standard library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue or pull request is an enhancement help wanted This is an issue or pull request where we request help from the community to fix or complete macOS Issues affecting macOS missing-api-bindings
Projects
None yet
Development

No branches or pull requests

6 participants