mirror of
https://github.com/servo/servo.git
synced 2025-06-12 10:24:43 +00:00
Implement non-XR Gamepad discovery and input (#31200)
* Create embedder event to send to constellation * Handle gamepad message in constellation, send to script thread * Handle GamepadEvent in script thread and dispatch event to document * Add missing Clones, fix event * Add gamepad task source * Adjust GamepadIndex type, remove unused imports * Add internal getter for gamepads list * Update gamepad new methods * Handle gamepad connect and disconnect events * Proto will be none, no need for HandleObject * Initialize buttons and axes to standard mapping * Adjust update type index types * Update GamepadButton update function * Adjust Gamepad mapping comments to match spec, add update logic * Amend comment * Update button and axis inputs on Updated event * Add GilRs as gamepad backend in servoshell * Add spec links, queue gamepad updates on task source * ./mach fmt * Fix comment length * Split out button init, update spec comments * Move gamepad event handling from document to global * Map and normalize axes/button values * Use std::time for gamepad timestamp * Adjust gamepad handling in event loop * Move button press/touch check into map+normalize function - Small change but is more in line with spec * ./mach fmt * Update comment spec links and warning messages * Doc comments -> regular comments * Add window event handlers for gamepad connect/disconnect * Adjust gamepad disconnect behavior * Add missing TODO's, adjust gamepad/gamepadbutton list methods and formatting * Update button handling from gilrs, add comments * Enable gamepad pref during WPT tests and update expectations * Update WPT expectations in meta-legacy-layout
This commit is contained in:
parent
1cc546c4fc
commit
c999d4546c
27 changed files with 695 additions and 208 deletions
|
@ -75,8 +75,8 @@ use profile_traits::time::{self as profile_time, profile, ProfilerCategory};
|
|||
use script_layout_interface::message::{self, LayoutThreadInit, Msg, ReflowGoal};
|
||||
use script_traits::webdriver_msg::WebDriverScriptCommand;
|
||||
use script_traits::CompositorEvent::{
|
||||
CompositionEvent, IMEDismissedEvent, KeyboardEvent, MouseButtonEvent, MouseMoveEvent,
|
||||
ResizeEvent, TouchEvent, WheelEvent,
|
||||
CompositionEvent, GamepadEvent, IMEDismissedEvent, KeyboardEvent, MouseButtonEvent,
|
||||
MouseMoveEvent, ResizeEvent, TouchEvent, WheelEvent,
|
||||
};
|
||||
use script_traits::{
|
||||
AnimationTickType, CompositorEvent, ConstellationControlMsg, DiscardBrowsingContext,
|
||||
|
@ -152,6 +152,7 @@ use crate::task_manager::TaskManager;
|
|||
use crate::task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
||||
use crate::task_source::dom_manipulation::DOMManipulationTaskSource;
|
||||
use crate::task_source::file_reading::FileReadingTaskSource;
|
||||
use crate::task_source::gamepad::GamepadTaskSource;
|
||||
use crate::task_source::history_traversal::HistoryTraversalTaskSource;
|
||||
use crate::task_source::media_element::MediaElementTaskSource;
|
||||
use crate::task_source::networking::NetworkingTaskSource;
|
||||
|
@ -568,6 +569,8 @@ pub struct ScriptThread {
|
|||
|
||||
dom_manipulation_task_sender: Box<dyn ScriptChan>,
|
||||
|
||||
gamepad_task_sender: Box<dyn ScriptChan>,
|
||||
|
||||
#[no_trace]
|
||||
media_element_task_sender: Sender<MainThreadScriptMsg>,
|
||||
|
||||
|
@ -1354,6 +1357,7 @@ impl ScriptThread {
|
|||
|
||||
chan: MainThreadScriptChan(chan.clone()),
|
||||
dom_manipulation_task_sender: boxed_script_sender.clone(),
|
||||
gamepad_task_sender: boxed_script_sender.clone(),
|
||||
media_element_task_sender: chan.clone(),
|
||||
user_interaction_task_sender: chan.clone(),
|
||||
networking_task_sender: boxed_script_sender.clone(),
|
||||
|
@ -2858,6 +2862,10 @@ impl ScriptThread {
|
|||
DOMManipulationTaskSource(self.dom_manipulation_task_sender.clone(), pipeline_id)
|
||||
}
|
||||
|
||||
pub fn gamepad_task_source(&self, pipeline_id: PipelineId) -> GamepadTaskSource {
|
||||
GamepadTaskSource(self.gamepad_task_sender.clone(), pipeline_id)
|
||||
}
|
||||
|
||||
pub fn media_element_task_source(&self, pipeline_id: PipelineId) -> MediaElementTaskSource {
|
||||
MediaElementTaskSource(self.media_element_task_sender.clone(), pipeline_id)
|
||||
}
|
||||
|
@ -3283,6 +3291,7 @@ impl ScriptThread {
|
|||
let task_manager = TaskManager::new(
|
||||
self.dom_manipulation_task_source(incomplete.pipeline_id),
|
||||
self.file_reading_task_source(incomplete.pipeline_id),
|
||||
self.gamepad_task_source(incomplete.pipeline_id),
|
||||
self.history_traversal_task_source(incomplete.pipeline_id),
|
||||
self.media_element_task_source(incomplete.pipeline_id),
|
||||
self.networking_task_source(incomplete.pipeline_id),
|
||||
|
@ -3669,6 +3678,15 @@ impl ScriptThread {
|
|||
};
|
||||
document.dispatch_composition_event(composition_event);
|
||||
},
|
||||
|
||||
GamepadEvent(gamepad_event) => {
|
||||
let window = match self.documents.borrow().find_window(pipeline_id) {
|
||||
Some(window) => window,
|
||||
None => return warn!("Message sent to closed pipeline {}.", pipeline_id),
|
||||
};
|
||||
let global = window.upcast::<GlobalScope>();
|
||||
global.handle_gamepad_event(gamepad_event);
|
||||
},
|
||||
}
|
||||
|
||||
ScriptThread::set_user_interacting(false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue