mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Add tests for Gamepad API by utilising virtual SDL3 joysticks
This commit is contained in:
parent
74e0483ea5
commit
9adf27f009
Notes:
github-actions[bot]
2025-09-01 19:11:51 +00:00
Author: https://github.com/Lubrsi
Commit: 9adf27f009
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5902
Reviewed-by: https://github.com/gmta
Reviewed-by: https://github.com/trflynn89
28 changed files with 897 additions and 0 deletions
51
Libraries/LibWeb/Internals/InternalGamepad.h
Normal file
51
Libraries/LibWeb/Internals/InternalGamepad.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <SDL3/SDL_gamepad.h>
|
||||
#include <SDL3/SDL_joystick.h>
|
||||
|
||||
namespace Web::Internals {
|
||||
|
||||
class InternalGamepad : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(InternalGamepad, Bindings::PlatformObject);
|
||||
GC_DECLARE_ALLOCATOR(InternalGamepad);
|
||||
|
||||
public:
|
||||
static GC::Ref<InternalGamepad> create(JS::Realm&);
|
||||
|
||||
virtual ~InternalGamepad() override;
|
||||
|
||||
Array<SDL_GamepadButton, 15> const& buttons();
|
||||
Array<SDL_GamepadAxis, 4> const& axes();
|
||||
Array<SDL_GamepadAxis, 2> const& triggers();
|
||||
|
||||
void set_button(int button, bool down);
|
||||
void set_axis(int axis, short value);
|
||||
|
||||
GC::RootVector<JS::Object*> get_received_rumble_effects() const;
|
||||
GC::RootVector<JS::Object*> get_received_rumble_trigger_effects() const;
|
||||
|
||||
void received_rumble(u16 low_frequency_rumble, u16 high_frequency_rumble);
|
||||
void received_rumble_triggers(u16 left_rumble, u16 right_rumble);
|
||||
|
||||
void disconnect();
|
||||
|
||||
private:
|
||||
InternalGamepad(JS::Realm&);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
virtual void finalize() override;
|
||||
|
||||
SDL_JoystickID m_sdl_joystick_id;
|
||||
SDL_Joystick* m_sdl_joystick;
|
||||
Vector<GC::Ref<JS::Object>> m_received_rumble_effects;
|
||||
Vector<GC::Ref<JS::Object>> m_received_rumble_trigger_effects;
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue