Skip to content

Expose a GamepadProvider and use Responder types for messages#41568

Merged
atbrakhi merged 2 commits intoservo:mainfrom
atbrakhi:gamepadprovider
Feb 1, 2026
Merged

Expose a GamepadProvider and use Responder types for messages#41568
atbrakhi merged 2 commits intoservo:mainfrom
atbrakhi:gamepadprovider

Conversation

@atbrakhi
Copy link
Copy Markdown
Member

Expose a GamepadProvider and use Responder types for messages

Testing:
Fixes: #41453

@atbrakhi
Copy link
Copy Markdown
Member Author

Copy link
Copy Markdown
Member

@mrobinson mrobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice start. This needs a bit of a rework to make it match the design of the other parts of the API:

Comment on lines +150 to +153
#[cfg(feature = "gamepad")]
pub(crate) struct ServoshellGamepadProvider {
gamepad_support: Rc<RefCell<Option<GamepadSupport>>>,
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of wrapping a GamepadSupport make GamepadSuport the actual implementation of GamepadProvider and just don't set it if it is None.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

@atbrakhi atbrakhi force-pushed the gamepadprovider branch 2 times, most recently from dae3040 to bbdc172 Compare January 18, 2026 12:35
@atbrakhi
Copy link
Copy Markdown
Member Author

@mrobinson i have addressed rest of your feedback in bbdc172. Sorry for the delay, i was ooo until recently.

@atbrakhi atbrakhi force-pushed the gamepadprovider branch 2 times, most recently from 8531d4f to 4da9dee Compare January 18, 2026 12:57
Copy link
Copy Markdown
Member

@mrobinson mrobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. This is getting closer. Just a few suggestions:

#[cfg(feature = "gamepad")]
pub(crate) struct ServoshellGamepadProvider {
gamepad_support: Rc<RefCell<Option<GamepadSupport>>>,
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we should do that. There should only be GamepadSupport would be renamed ServoshellGamepadProvider and implement GamepadProvider directly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrobinson done in 09461e8 , thanks. Also updated some comments!

@atbrakhi atbrakhi marked this pull request as ready for review January 27, 2026 14:31
@atbrakhi atbrakhi requested a review from jschwe as a code owner January 27, 2026 14:31
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jan 27, 2026
@atbrakhi atbrakhi requested a review from mrobinson January 27, 2026 14:31
Copy link
Copy Markdown
Member

@mrobinson mrobinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work @atbrakhi. A few comments before landing:

Comment on lines +39 to +44
pub fn effect_type(&self) -> Option<&GamepadHapticEffectType> {
match &self.request_type {
GamepadHapticEffectRequestType::Play(effect_type) => Some(effect_type),
GamepadHapticEffectRequestType::Stop => None,
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just remove this as it's in the GamepadHapticEffectRequestType.

Comment on lines +131 to +132
#[cfg(feature = "gamepad")]
gamepad_provider,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just move the above line here, if possible:

Suggested change
#[cfg(feature = "gamepad")]
gamepad_provider,
#[cfg(feature = "gamepad")]
ServoshellGamepadProvider::maybe_new().map(Rc::new),

Comment on lines +248 to +249
GamepadHapticEffectRequestType::Play(_) => {
self.play_haptic_effect(request);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the effect type directly can make play_haptic_effect a little simpler:

Suggested change
GamepadHapticEffectRequestType::Play(_) => {
self.play_haptic_effect(request);
GamepadHapticEffectRequestType::Play(effect_type) => {
self.play_haptic_effect(request, effect_type);

Comment on lines +272 to +276
let servo_builder = ServoBuilder::default()
.opts(init.opts)
.preferences(init.preferences.clone())
.event_loop_waker(init.event_loop_waker.clone());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll want to revert these lines. This will break if WebXR is enabled, I believe.

Comment on lines +300 to +302
self.gamepad_provider
.as_ref()
.map(|p| p.clone() as Rc<dyn GamepadProvider>)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be able to return this directly using clone (or cloned, I can never remember).

Suggested change
self.gamepad_provider
.as_ref()
.map(|p| p.clone() as Rc<dyn GamepadProvider>)
self.gamepad_provider.clone()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Jan 28, 2026
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jan 29, 2026
@atbrakhi atbrakhi added this pull request to the merge queue Jan 29, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jan 29, 2026
github-merge-queue bot pushed a commit that referenced this pull request Jan 29, 2026
…1568)

Expose a `GamepadProvider` and use `Responder` types for messages

Testing: 
Fixes: #41453

---------

Signed-off-by: atbrakhi <[email protected]>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 29, 2026
@servo-highfive servo-highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jan 29, 2026
Signed-off-by: atbrakhi <[email protected]>
@servo-highfive servo-highfive removed the S-tests-failed The changes caused existing tests to fail. label Feb 1, 2026
@atbrakhi atbrakhi added this pull request to the merge queue Feb 1, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Feb 1, 2026
Merged via the queue into servo:main with commit b6a1761 Feb 1, 2026
29 checks passed
@atbrakhi atbrakhi deleted the gamepadprovider branch February 1, 2026 13:58
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose a GamepadProvider and use Responder types for messages

3 participants