Add GetGamepadsForDisplay message for initializing inputs

This commit is contained in:
Manish Goregaokar 2019-04-29 18:16:18 -07:00
parent 0f952c7ff8
commit f98143d60b
2 changed files with 33 additions and 0 deletions

View file

@ -128,6 +128,9 @@ impl WebVRThread {
WebVRMsg::GetGamepads(synced_ids, sender) => { WebVRMsg::GetGamepads(synced_ids, sender) => {
self.handle_get_gamepads(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, WebVRMsg::Exit => break,
} }
} }
@ -251,6 +254,32 @@ impl WebVRThread {
self.vr_compositor_chan.send(compositor).unwrap(); 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( fn handle_get_gamepads(
&mut self, &mut self,
synced_ids: Vec<u32>, synced_ids: Vec<u32>,

View file

@ -30,5 +30,9 @@ pub enum WebVRMsg {
Vec<u32>, Vec<u32>,
IpcSender<WebVRResult<Vec<(Option<VRGamepadData>, VRGamepadState)>>>, IpcSender<WebVRResult<Vec<(Option<VRGamepadData>, VRGamepadState)>>>,
), ),
GetGamepadsForDisplay(
u32,
IpcSender<WebVRResult<Vec<(VRGamepadData, VRGamepadState)>>>,
),
Exit, Exit,
} }