diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2019-04-29 18:16:18 -0700 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2019-05-03 14:37:41 -0700 |
commit | f98143d60bf7065ca8c59bf610d60c2a6dee55e7 (patch) | |
tree | f3fbb7f71bcfb8ddb49e31ea7ccd8275d9a4c51f /components/webvr | |
parent | 0f952c7ff8d4132c2a6eca9acf599788c1ec9c8c (diff) | |
download | servo-f98143d60bf7065ca8c59bf610d60c2a6dee55e7.tar.gz servo-f98143d60bf7065ca8c59bf610d60c2a6dee55e7.zip |
Add GetGamepadsForDisplay message for initializing inputs
Diffstat (limited to 'components/webvr')
-rw-r--r-- | components/webvr/webvr_thread.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/components/webvr/webvr_thread.rs b/components/webvr/webvr_thread.rs index 1077581f10c..e90ddbf7df5 100644 --- a/components/webvr/webvr_thread.rs +++ b/components/webvr/webvr_thread.rs @@ -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>, |