Skip to content

Commit 6aa8bee

Browse files
committed
Send analog button values based on W3C GamePad
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: manoj_bhatta@comcast.com See: #1410
1 parent 1667f9e commit 6aa8bee

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Source/WebCore/platform/gamepad/wpe/WPEGamepad.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ WPEGamepad::WPEGamepad(struct wpe_gamepad_provider* provider, uintptr_t gamepadI
5858
auto& self = *static_cast<WPEGamepad*>(data);
5959
self.absoluteAxisChanged(static_cast<unsigned>(axis), value);
6060
},
61-
nullptr, nullptr, nullptr,
61+
// analog_button_value
62+
[](void* data, enum wpe_gamepad_button button, double value) {
63+
auto& self = *static_cast<WPEGamepad*>(data);
64+
self.analogButtonChanged(static_cast<unsigned>(button), value);
65+
},
66+
nullptr, nullptr,
6267
};
6368
wpe_gamepad_set_client(m_gamepad.get(), &s_client, this);
6469
}
@@ -84,6 +89,15 @@ void WPEGamepad::absoluteAxisChanged(unsigned axis, double value)
8489
WPEGamepadProvider::singleton().scheduleInputNotification(*this, WPEGamepadProvider::ShouldMakeGamepadsVisible::Yes);
8590
}
8691

92+
void WPEGamepad::analogButtonChanged(unsigned button, double value)
93+
{
94+
m_lastUpdateTime = MonotonicTime::now();
95+
m_buttonValues[button].setValue(clampTo(value, 0.0, 1.0));
96+
97+
WPEGamepadProvider::singleton().scheduleInputNotification(*this, WPEGamepadProvider::ShouldMakeGamepadsVisible::Yes);
98+
99+
}
100+
87101
} // namespace WebCore
88102

89103
#endif // ENABLE(GAMEPAD)

Source/WebCore/platform/gamepad/wpe/WPEGamepad.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class WPEGamepad final : public PlatformGamepad {
4848
private:
4949
void buttonPressedOrReleased(unsigned, bool);
5050
void absoluteAxisChanged(unsigned, double);
51+
void analogButtonChanged(unsigned, double);
5152

5253
Vector<SharedGamepadValue> m_buttonValues;
5354
Vector<SharedGamepadValue> m_axisValues;

0 commit comments

Comments
 (0)