Skip to content

[WPE] Add ManetteGamepadProvider with libmanette 1.0 support and haptic feedback - #1709

Open
petartijanic01 wants to merge 3 commits into
WebPlatformForEmbedded:wpe-2.46from
petartijanic01:feature/manette-gamepad-provider-toggle
Open

petartijanic01 wants to merge 3 commits into
WebPlatformForEmbedded:wpe-2.46from
petartijanic01:feature/manette-gamepad-provider-toggle

Conversation

@petartijanic01

@petartijanic01 petartijanic01 commented Aug 6, 2026

Copy link
Copy Markdown

This PR adds USE_MANETTE_GAMEPAD_PROVIDER (default OFF) to allow the WPE port
to use ManetteGamepadProvider directly, matching the GTK port's approach.

Motivation

The existing ManetteGamepadProvider (used by the GTK port) lacks:

  • Analog trigger support — with libmanette 0.2, triggers are reported as
    digital button events (0/1). libmanette 1.0 exposes triggers as axis events
    (MANETTE_AXIS_LEFT_TRIGGER / MANETTE_AXIS_RIGHT_TRIGGER) with continuous
    0.0–1.0 values, enabling proper analog input per the W3C Gamepad spec.
  • Haptic feedback — playEffect (dual-rumble) was not implemented for the
    ManetteGamepadProvider on WPE. This PR ports the GTK implementation using
    manette_device_rumble().
  • libmanette 1.0 support — the existing code only supports libmanette 0.2
    API (ManetteEvent-based signals, BTN_* constants, ManetteMonitorIter).

Changes

Commit 1: Build toggle
USE_MANETTE_GAMEPAD_PROVIDER cmake option (default OFF). FindManette.cmake
tries manette-1 first, falls back to manette-0.2. When enabled, builds
ManetteGamepadProvider instead of GamepadLibWPE.

Commit 2: playEffect (haptic feedback)
Rumble support via manette_device_rumble(), ported from the GTK implementation
(upstream commit 2e1369350dab). Uses MANETTE_CHECK_VERSION(0, 2, 13) for API
selection between double and guint16 magnitudes.

Commit 3: libmanette 1.0 API with 0.2 fallback
Version-guarded signal names, button/axis enums, device iteration, and
analogButtonChanged() for analog triggers. Includes #ifndef MANETTE_CHECK_VERSION
fallback for libmanette < 0.2.10.

Tested with both libmanette 0.2.6 and 1.0.
f212889

Build-Tests Layout-Tests
✅ 🛠 wpe-246-amd64-build ✅ 🧪 wpe-246-amd64-layout
✅ 🛠 wpe-246-arm32-build ❌ 🧪 wpe-246-arm32-layout

Add USE_MANETTE_GAMEPAD_PROVIDER cmake option (default OFF) that allows
WPE to use ManetteGamepadProvider (direct libmanette) instead of the
existing GamepadLibWPE (libwpe gamepad) backend.

When enabled (-DUSE_MANETTE_GAMEPAD_PROVIDER=ON):
- FindManette.cmake searches for manette-1 first, falls back to manette-0.2
- WebCore builds ManetteGamepad.cpp/ManetteGamepadProvider.cpp
- WebKit builds UIGamepadProviderManette.cpp

When disabled (default):
- WebCore builds GamepadLibWPE.cpp/GamepadProviderLibWPE.cpp
- WebKit builds UIGamepadProviderLibWPE.cpp
- Original libwpe-based gamepad input routing is preserved

This brings the WPE port in line with how the GTK port uses libmanette
directly, while keeping GamepadLibWPE as the default.

* Source/cmake/FindManette.cmake:
* Source/cmake/OptionsWPE.cmake:
* Source/WebCore/PlatformWPE.cmake:
* Source/WebCore/SourcesWPE.txt:
* Source/WebKit/PlatformWPE.cmake:
* Source/WebKit/SourcesWPE.txt:
* Source/WebKit/UIProcess/API/wpe/WPEWebViewLegacy.cpp:
* Source/WebKit/UIProcess/Gamepad/manette/UIGamepadProviderManette.cpp:
Port gamepad haptic feedback (dual-rumble) support to the WPE
ManetteGamepadProvider, matching the GTK port implementation.

Uses MANETTE_CHECK_VERSION(0, 2, 13) to select the correct rumble API:
- >= 0.2.13 (and all of 1.0): magnitudes passed as double directly
- < 0.2.13: magnitudes scaled by G_MAXUINT16

Includes a fallback #define for MANETTE_CHECK_VERSION for libmanette
versions < 0.2.10 that lack the macro.

Also enables defaultGamepadVibrationActuatorEnabled when USE(MANETTE).

* Source/WebCore/platform/gamepad/manette/ManetteGamepad.cpp:
(WebCore::ManetteGamepad::ManetteGamepad):
(WebCore::ManetteGamepad::playEffect):
(WebCore::ManetteGamepad::stopEffects):
(WebCore::ManetteGamepad::effectDelayTimerFired):
(WebCore::ManetteGamepad::startRumble):
(WebCore::ManetteGamepad::effectDurationTimerFired):
* Source/WebCore/platform/gamepad/manette/ManetteGamepad.h:
* Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:
(WebCore::ManetteGamepadProvider::playEffect):
(WebCore::ManetteGamepadProvider::stopEffects):
* Source/WebKit/Shared/WebPreferencesDefaultValues.cpp:
(WebKit::defaultGamepadVibrationActuatorEnabled):
Add MANETTE_CHECK_VERSION(1, 0, 0) guards to support libmanette 1.0
while retaining compilation with 0.2:

- Signal callbacks: 1.0 uses direct parameter signals (button-pressed,
  button-released, absolute-axis-changed with ManetteButton/ManetteAxis),
  0.2 uses ManetteEvent-based signals (button-press-event, etc.)
- Button mapping: 1.0 uses ManetteButton enum (MANETTE_BUTTON_SOUTH, etc.),
  0.2 uses linux input-event-codes (BTN_A, etc.)
- Axis mapping: 1.0 uses ManetteAxis enum with trigger axes,
  0.2 uses ABS_* constants
- Device iteration: 1.0 uses manette_monitor_list_devices(),
  0.2 uses ManetteMonitorIter
- Analog trigger support in 1.0 via analogButtonChanged() for
  MANETTE_AXIS_LEFT_TRIGGER / MANETTE_AXIS_RIGHT_TRIGGER
- GUniquePtrManette.h include guarded (ManetteMonitorIter absent in 1.0)

* Source/WebCore/platform/gamepad/manette/ManetteGamepad.cpp:
* Source/WebCore/platform/gamepad/manette/ManetteGamepad.h:
* Source/WebCore/platform/gamepad/manette/ManetteGamepadProvider.cpp:
@pgorszkowski-igalia

Copy link
Copy Markdown

@petartijanic01 : how did you test this PR? with WPEFramework? To test it on my side with WPEFramework I had to do some libmanette modification which I am trying to upstream: https://gitlab.gnome.org/GNOME/libmanette/-/merge_requests/160.

Comment on lines +329 to +333
#if MANETTE_CHECK_VERSION(0, 2, 13)
manette_device_rumble(m_device.get(), parameters.strongMagnitude, parameters.weakMagnitude, static_cast<guint>(parameters.duration));
#else
manette_device_rumble(m_device.get(), parameters.strongMagnitude * G_MAXUINT16, parameters.weakMagnitude * G_MAXUINT16, static_cast<guint>(parameters.duration));
#endif

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In libmanette < 1.0 manette_device_rumble uses guint16 in case of magnitudes:
https://github.com/GNOME/libmanette/blob/0.2.13/src/manette-device.h#L48

even in case of development 0.2 branch, they are still guint16:
https://github.com/GNOME/libmanette/blob/libmanette-0-2/src/manette-device.h#L48

only in development main branch they changed that to double:
https://github.com/GNOME/libmanette/blob/main/src/manette-device.h#L84
GNOME/libmanette@4a3ee6c

I know that this is because you backport this change from upstream and in upstream there is the same bug. I am going to fix that in upstream: https://bugs.webkit.org/show_bug.cgi?id=323663

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and one more thing, MANETTE_CHECK_VERSION was introduced in 0.2.10, before that version this macro does not exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants