// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module device.mojom;
import "mojo/public/mojom/base/shared_memory.mojom";
struct GamepadQuaternion {
float x;
float y;
float z;
float w;
};
struct GamepadVector {
float x;
float y;
float z;
};
struct GamepadButton {
bool pressed;
bool touched;
double value;
};
// ButtonChange holds all necessary information for creating the correct
// events when a button state changes on a gamepad.
struct ButtonChange {
// Index of the button in the |buttons| array.
uint32 button_index;
// True when the GamepadButton's |pressed| value just changed to true.
bool button_down;
// True when the GamepadButton's |pressed| value just changed to false.
bool button_up;
// True when the GamepadButton's |value| has changed.
bool value_changed;
// Snapshot of the GamepadButton's state when these events were triggered.
GamepadButton button_snapshot;
};
// AxisChange holds information about an axis value change on a gamepad.
struct AxisChange {
// Index of the axis in the |axes| array.
uint32 axis_index;
// Snapshot of the axis's value when these events were triggered.
double axis_snapshot;
};
// GamepadChanges holds all the simultaneous changes that occurred to a
// gamepad at the same moment.
struct GamepadChanges {
// Index of the Gamepad in the array returned to the user from GetGamepads
uint32 gamepad_index;
// Array of all changes to the buttons.
array<ButtonChange> button_changes;
// Array of all changes to the axes.
array<AxisChange> axis_changes;
// The timestamp when these changes occurred.
int64 timestamp;
};
enum GamepadMapping {
GamepadMappingNone = 0,
GamepadMappingStandard = 1,
GamepadMappingXRStandard = 2
};
struct GamepadTouch {
uint32 touch_id;
uint8 surface_id;
double x;
double y;
uint32 surface_height;
uint32 surface_width;
bool has_surface_dimensions;
};
struct GamepadPose {
GamepadQuaternion? orientation;
GamepadVector? position;
GamepadVector? angular_velocity;
GamepadVector? linear_velocity;
GamepadVector? angular_acceleration;
GamepadVector? linear_acceleration;
};
enum GamepadHand {
GamepadHandNone = 0,
GamepadHandLeft = 1,
GamepadHandRight = 2
};
enum GamepadHapticActuatorType {
GamepadHapticActuatorTypeVibration = 0,
GamepadHapticActuatorTypeDualRumble = 1,
GamepadHapticActuatorTypeTriggerRumble = 2
};
enum GamepadHapticEffectType {
GamepadHapticEffectTypeDualRumble = 0,
GamepadHapticEffectTypeTriggerRumble = 1
};
struct GamepadHapticActuator {
GamepadHapticActuatorType type;
};
struct Gamepad {
bool connected;
array<uint16> id;
int64 timestamp;
array<double> axes;
array<GamepadButton> buttons;
GamepadHapticActuator? vibration_actuator;
GamepadMapping mapping;
GamepadPose? pose;
GamepadHand hand;
array<GamepadTouch> touch_events;
uint32 display_id;
};
interface GamepadObserver {
// Called when a gamepad is connected. |index| is the index of the gamepad in
// the gamepad array, and |gamepad| is a reference to the connected gamepad.
GamepadConnected(uint32 index, Gamepad gamepad);
// Called when a gamepad is disconnected. |index| is the former index of the
// gamepad in the gamepad array, and |gamepad| is a reference to the
// connected gamepad.
GamepadDisconnected(uint32 index, Gamepad gamepad);
// Called when a button or axis is changed on a connected gamepad.
// |changes| contains the necessary info to generate the proper
// events.
GamepadChanged(GamepadChanges changes);
};
// Asks the browser process to start polling, and return a shared memory
// region that will hold the data from the hardware. See
// gamepad_shared_buffer.h for a description of how synchronization is
// handled. The number of Starts should match the number of Stops.
interface GamepadMonitor {
[Sync]
GamepadStartPolling()
=> (mojo_base.mojom.ReadOnlySharedMemoryRegion memory_region);
[Sync]
GamepadStopPolling() => ();
SetObserver(pending_remote<GamepadObserver> gamepad_observer);
};
struct GamepadEffectParameters {
double duration;
double start_delay;
double strong_magnitude;
double weak_magnitude;
double left_trigger;
double right_trigger;
};
enum GamepadHapticsResult {
GamepadHapticsResultError = 0,
GamepadHapticsResultComplete = 1,
GamepadHapticsResultPreempted = 2,
GamepadHapticsResultInvalidParameter = 3,
GamepadHapticsResultNotSupported = 4
};
interface GamepadHapticsManager {
PlayVibrationEffectOnce(uint32 pad_index,
GamepadHapticEffectType type,
GamepadEffectParameters params)
=> (GamepadHapticsResult result);
ResetVibrationActuator(uint32 pad_index) => (GamepadHapticsResult result);
};