refactor!: Simplify over-complicated platform adapter APIs #294
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I remembered a wart in the API of the core (non-subclassing) Windows adapter, which I mentioned in this comment on a winit issue. Basically,
handle_wm_getobject
doesn't really need to return an intermediate struct that is then converted into anLRESULT
in a second step. Any window implementations that need to acquire a mutex, mutable borrow, or the like in order to handle theWM_GETOBJECT
message can work around the reentrancy issue by storing the adapter in anRc
, obtaining a reference to the adapter, then callinghandle_wm_getobject
while the mutex/borrow/whatever isn't held. I decided that this workaround is better than complicating the API for everyone.Then I realized that, by the same logic, we really don't need to have the update methods return a
QueuedEvents
struct that the caller then has to callraise
on. On Windows, that separation could theoretically have allowed the updating and the raising of events to happen on different threads. But then I ended up making it all single-threaded anyway on macOS. So I decided to require that the top-levelAdapter
struct on Windows be bound to the thread that owns the window, while keeping the ability for UIA to run most of the provider methods on another thread. In any case, I eliminatedQueuedEvents
, so the API is simpler.