mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add GetGamepadsForDisplay message for initializing inputs
This commit is contained in:
parent
0f952c7ff8
commit
f98143d60b
2 changed files with 33 additions and 0 deletions
|
@ -128,6 +128,9 @@ impl WebVRThread {
|
|||
WebVRMsg::GetGamepads(synced_ids, sender) => {
|
||||
self.handle_get_gamepads(synced_ids, sender);
|
||||
},
|
||||
WebVRMsg::GetGamepadsForDisplay(display_id, sender) => {
|
||||
self.handle_get_gamepads_for_display(display_id, sender);
|
||||
},
|
||||
WebVRMsg::Exit => break,
|
||||
}
|
||||
}
|
||||
|
@ -251,6 +254,32 @@ impl WebVRThread {
|
|||
self.vr_compositor_chan.send(compositor).unwrap();
|
||||
}
|
||||
|
||||
fn handle_get_gamepads_for_display(
|
||||
&mut self,
|
||||
display_id: u32,
|
||||
sender: IpcSender<WebVRResult<Vec<(VRGamepadData, VRGamepadState)>>>,
|
||||
) {
|
||||
match self.service.get_display(display_id) {
|
||||
Some(display) => {
|
||||
let gamepads = display.borrow_mut().fetch_gamepads();
|
||||
match gamepads {
|
||||
Ok(gamepads) => {
|
||||
let data = gamepads
|
||||
.iter()
|
||||
.map(|g| {
|
||||
let g = g.borrow();
|
||||
(g.data(), g.state())
|
||||
})
|
||||
.collect();
|
||||
sender.send(Ok(data)).unwrap();
|
||||
},
|
||||
Err(e) => sender.send(Err(e)).unwrap(),
|
||||
}
|
||||
},
|
||||
None => sender.send(Err("Device not found".into())).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_get_gamepads(
|
||||
&mut self,
|
||||
synced_ids: Vec<u32>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue