Skip to content

Commit

Permalink
Analog button should have values from 0.0 to 1.0 instead of only digi…
Browse files Browse the repository at this point in the history
…tal value. (#134)

https://www.w3.org/TR/gamepad/#dom-gamepadbutton-value

value attribute
For buttons that have an analog sensor, this property MUST represent the amount which the button has been pressed. All button values MUST be linearly normalized to the range [0.0 .. 1.0]. 0.0 MUST mean fully unpressed, and 1.0 MUST mean fully pressed. For buttons without an analog sensor, only the values 0.0 and 1.0 for fully unpressed and fully pressed respectively, MUST be provided.

Co-authored-by: Ganesh prasad Sahu <[email protected]>
  • Loading branch information
ganeshprasads and Ganesh prasad Sahu authored Jan 13, 2025
1 parent 0a4a335 commit 77fc241
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/wpe/gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct wpe_gamepad_provider_client_interface {
struct wpe_gamepad_client_interface {
void (*button_changed)(void*, enum wpe_gamepad_button, bool);
void (*axis_changed)(void*, enum wpe_gamepad_axis, double);
void (*analog_button_changed)(void*, enum wpe_gamepad_button, double);

/*< private >*/
void (*_wpe_reserved1)(void);
Expand Down Expand Up @@ -358,6 +359,20 @@ void wpe_gamepad_set_client(struct wpe_gamepad*, const struct wpe_gamepad_client
WPE_EXPORT
const char* wpe_gamepad_get_id(struct wpe_gamepad*);

/**
* wpe_gamepad_dispatch_analog_button_changed:
* @gamepad: opaque gamepad object.
* @button: the analog button that changed its value.
* @value: the new analog @button value.
*
* Method called by application (gamepad implementator). It reports to
* WPEWebkit a change in the value of analog @button.
*
* Since: 1.16
*/
WPE_EXPORT
void wpe_gamepad_dispatch_analog_button_changed(struct wpe_gamepad*, enum wpe_gamepad_button, double);

/**
* wpe_gamepad_dispatch_button_changed:
* @gamepad: opaque gamepad object.
Expand Down
7 changes: 7 additions & 0 deletions src/gamepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ wpe_gamepad_get_id(struct wpe_gamepad* gamepad)
return "Unknown device";
}

void
wpe_gamepad_dispatch_analog_button_changed(struct wpe_gamepad* gamepad, enum wpe_gamepad_button button, double value)
{
if (gamepad && gamepad->client_interface && gamepad->client_interface->analog_button_changed)
gamepad->client_interface->analog_button_changed(gamepad->client_data, button, value);
}

void
wpe_gamepad_dispatch_button_changed(struct wpe_gamepad* gamepad, enum wpe_gamepad_button button, bool pressed)
{
Expand Down

0 comments on commit 77fc241

Please sign in to comment.