Expose a GamepadProvider and use Responder types for messages#41568
Expose a GamepadProvider and use Responder types for messages#41568atbrakhi merged 2 commits intoservo:mainfrom
GamepadProvider and use Responder types for messages#41568Conversation
c05ffe5 to
b421b8c
Compare
mrobinson
left a comment
There was a problem hiding this comment.
Nice start. This needs a bit of a rework to make it match the design of the other parts of the API:
| #[cfg(feature = "gamepad")] | ||
| pub(crate) struct ServoshellGamepadProvider { | ||
| gamepad_support: Rc<RefCell<Option<GamepadSupport>>>, | ||
| } |
There was a problem hiding this comment.
Instead of wrapping a GamepadSupport make GamepadSuport the actual implementation of GamepadProvider and just don't set it if it is None.
There was a problem hiding this comment.
@mrobinson Just to confirm my understanding: GamepadSupport should directly implement GamepadProvider, and ServoBuilder::gamepad_provider() should only be called if GamepadSupport::maybe_new() returns Some. This would require adding RefCell internally to GamepadSupport for the haptic_effects field since the trait method takes &self. Is that correct?
dae3040 to
bbdc172
Compare
|
@mrobinson i have addressed rest of your feedback in bbdc172. Sorry for the delay, i was ooo until recently. |
8531d4f to
4da9dee
Compare
mrobinson
left a comment
There was a problem hiding this comment.
Nice. This is getting closer. Just a few suggestions:
| #[cfg(feature = "gamepad")] | ||
| pub(crate) struct ServoshellGamepadProvider { | ||
| gamepad_support: Rc<RefCell<Option<GamepadSupport>>>, | ||
| } |
There was a problem hiding this comment.
Yes, I think we should do that. There should only be GamepadSupport would be renamed ServoshellGamepadProvider and implement GamepadProvider directly.
There was a problem hiding this comment.
@mrobinson done in 09461e8 , thanks. Also updated some comments!
Signed-off-by: atbrakhi <[email protected]>
7873e31 to
09461e8
Compare
components/servo/gamepad_provider.rs
Outdated
| pub fn effect_type(&self) -> Option<&GamepadHapticEffectType> { | ||
| match &self.request_type { | ||
| GamepadHapticEffectRequestType::Play(effect_type) => Some(effect_type), | ||
| GamepadHapticEffectRequestType::Stop => None, | ||
| } | ||
| } |
There was a problem hiding this comment.
I think you can just remove this as it's in the GamepadHapticEffectRequestType.
ports/servoshell/desktop/app.rs
Outdated
| #[cfg(feature = "gamepad")] | ||
| gamepad_provider, |
There was a problem hiding this comment.
I would just move the above line here, if possible:
| #[cfg(feature = "gamepad")] | |
| gamepad_provider, | |
| #[cfg(feature = "gamepad")] | |
| ServoshellGamepadProvider::maybe_new().map(Rc::new), |
ports/servoshell/desktop/gamepad.rs
Outdated
| GamepadHapticEffectRequestType::Play(_) => { | ||
| self.play_haptic_effect(request); |
There was a problem hiding this comment.
Passing the effect type directly can make play_haptic_effect a little simpler:
| GamepadHapticEffectRequestType::Play(_) => { | |
| self.play_haptic_effect(request); | |
| GamepadHapticEffectRequestType::Play(effect_type) => { | |
| self.play_haptic_effect(request, effect_type); |
ports/servoshell/egl/app.rs
Outdated
| let servo_builder = ServoBuilder::default() | ||
| .opts(init.opts) | ||
| .preferences(init.preferences.clone()) | ||
| .event_loop_waker(init.event_loop_waker.clone()); | ||
|
|
There was a problem hiding this comment.
I think you'll want to revert these lines. This will break if WebXR is enabled, I believe.
| self.gamepad_provider | ||
| .as_ref() | ||
| .map(|p| p.clone() as Rc<dyn GamepadProvider>) |
There was a problem hiding this comment.
I think you should be able to return this directly using clone (or cloned, I can never remember).
| self.gamepad_provider | |
| .as_ref() | |
| .map(|p| p.clone() as Rc<dyn GamepadProvider>) | |
| self.gamepad_provider.clone() |
There was a problem hiding this comment.
@mrobinson We would need to change the type to Option<Rc<ServoshellGamepadProvider>> in that case. .clone() won't compile due to the type mismatch between Rc<ServoshellGamepadProvider> and Rc<dyn GamepadProvider>. I am not sure if we should do that just to make clone work.
There was a problem hiding this comment.
@atbrakhi Well spotted. I think changing the type is appropriate here and simplifies the code. Additionally, other callers might want to do servoshell-specific things with this getter so we stay as specific as possible until inserting it into the WebViewDelegate.
09461e8 to
fd65ca0
Compare
fd65ca0 to
5469db7
Compare
…1568) Expose a `GamepadProvider` and use `Responder` types for messages Testing: Fixes: #41453 --------- Signed-off-by: atbrakhi <[email protected]>
Signed-off-by: atbrakhi <[email protected]>
5469db7 to
6e6798e
Compare
Expose a
GamepadProviderand useRespondertypes for messagesTesting:
Fixes: #41453