Skip to content

Commit

Permalink
Send analog button values based on W3C GamePad
Browse files Browse the repository at this point in the history
This PR dependent on libWPE changes for getting Gamepad button values from 0.0 to 1.0.
WebPlatformForEmbedded/libwpe#133

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.

Original Author: [email protected]
See: WebPlatformForEmbedded#1410
  • Loading branch information
Ganesh prasad Sahu authored and Ganesh prasad Sahu committed Dec 12, 2024
1 parent 1667f9e commit 6aa8bee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Source/WebCore/platform/gamepad/wpe/WPEGamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ WPEGamepad::WPEGamepad(struct wpe_gamepad_provider* provider, uintptr_t gamepadI
auto& self = *static_cast<WPEGamepad*>(data);
self.absoluteAxisChanged(static_cast<unsigned>(axis), value);
},
nullptr, nullptr, nullptr,
// analog_button_value
[](void* data, enum wpe_gamepad_button button, double value) {
auto& self = *static_cast<WPEGamepad*>(data);
self.analogButtonChanged(static_cast<unsigned>(button), value);
},
nullptr, nullptr,
};
wpe_gamepad_set_client(m_gamepad.get(), &s_client, this);
}
Expand All @@ -84,6 +89,15 @@ void WPEGamepad::absoluteAxisChanged(unsigned axis, double value)
WPEGamepadProvider::singleton().scheduleInputNotification(*this, WPEGamepadProvider::ShouldMakeGamepadsVisible::Yes);
}

void WPEGamepad::analogButtonChanged(unsigned button, double value)
{
m_lastUpdateTime = MonotonicTime::now();
m_buttonValues[button].setValue(clampTo(value, 0.0, 1.0));

WPEGamepadProvider::singleton().scheduleInputNotification(*this, WPEGamepadProvider::ShouldMakeGamepadsVisible::Yes);

}

} // namespace WebCore

#endif // ENABLE(GAMEPAD)
1 change: 1 addition & 0 deletions Source/WebCore/platform/gamepad/wpe/WPEGamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class WPEGamepad final : public PlatformGamepad {
private:
void buttonPressedOrReleased(unsigned, bool);
void absoluteAxisChanged(unsigned, double);
void analogButtonChanged(unsigned, double);

Vector<SharedGamepadValue> m_buttonValues;
Vector<SharedGamepadValue> m_axisValues;
Expand Down

0 comments on commit 6aa8bee

Please sign in to comment.