Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ set(WPE_PUBLIC_HEADERS
include/wpe/view-backend.h
include/wpe/wpe-egl.h
include/wpe/wpe.h
include/wpe/gamepad.h
)

add_library(wpe SHARED
Expand All @@ -77,6 +78,7 @@ add_library(wpe SHARED
src/renderer-host.c
src/version.c
src/view-backend.c
src/gamepad.c
)
target_include_directories(wpe PRIVATE
"include"
Expand Down
180 changes: 180 additions & 0 deletions include/wpe/gamepad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
* If not stated otherwise in this file or this component's Licenses.txt file the
* following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#if !defined(__WPE_H_INSIDE__) && !defined(WPE_COMPILATION)
#error "Only <wpe/wpe.h> can be included directly."
#endif

#ifndef wpe_gamepad_h
#define wpe_gamepad_h

#if defined(WPE_COMPILATION)
#include <wpe/export.h>
#endif

#include <stdint.h>

/*
* https://www.w3.org/TR/gamepad/#remapping
*
* buttons[0] Bottom button in right cluster
* buttons[1] Right button in right cluster
* buttons[2] Left button in right cluster
* buttons[3] Top button in right cluster
* buttons[4] Top left front button
* buttons[5] Top right front button
* buttons[6] Bottom left front button
* buttons[7] Bottom right front button
* buttons[8] Left button in center cluster
* buttons[9] Right button in center cluster
* buttons[10] Left stick pressed button
* buttons[11] Right stick pressed button
* buttons[12] Top button in left cluster
* buttons[13] Bottom button in left cluster
* buttons[14] Right button in left cluster
* buttons[15] Left button in left cluster
*
* axes[0] Horizontal axis for left stick (negative left/positive right)
* axes[1] Vertical axis for left stick (negative up/positive down)
* axes[2] Horizontal axis for right stick (negative left/positive right)
* axes[3] Vertical axis for right stick (negative up/positive down)
*/

#ifdef __cplusplus
extern "C" {
#endif

struct wpe_view_backend;

struct wpe_gamepad;
struct wpe_gamepad_client;

struct wpe_gamepad_provider;
struct wpe_gamepad_provider_client;

struct wpe_gamepad_provider_interface {
void* (*create)(struct wpe_gamepad_provider*);
void (*destroy)(void*);
void (*start)(void*);
void (*stop)(void*);
struct wpe_view_backend* (*get_view_for_gamepad_input)(void*, void*);
};

struct wpe_gamepad_interface {
void* (*create)(void*, struct wpe_gamepad*, uint32_t);
void (*destroy)(void*);
uint32_t (*get_id)(void*);
const char* (*get_device_name)(void*);
uint32_t (*get_button_count)(void*);
uint32_t (*copy_button_values)(void*, double*, uint32_t);
uint32_t (*get_axis_count)(void*);
uint32_t (*copy_axis_values)(void*, double*, uint32_t);
};

WPE_EXPORT
struct wpe_gamepad_provider*
wpe_gamepad_provider_create();

WPE_EXPORT
void
wpe_gamepad_provider_destroy(struct wpe_gamepad_provider*);

WPE_EXPORT
void
wpe_gamepad_provider_set_client(struct wpe_gamepad_provider*, struct wpe_gamepad_provider_client*, void*);

WPE_EXPORT
void
wpe_gamepad_provider_start(struct wpe_gamepad_provider*);

WPE_EXPORT
void
wpe_gamepad_provider_stop(struct wpe_gamepad_provider*);

WPE_EXPORT
struct wpe_view_backend*
wpe_gamepad_provider_get_view_for_gamepad_input(struct wpe_gamepad_provider*, struct wpe_gamepad*);

WPE_EXPORT
void
wpe_gamepad_provider_dispatch_gamepad_connected(struct wpe_gamepad_provider*, uint32_t gamepad_id);

WPE_EXPORT
void
wpe_gamepad_provider_dispatch_gamepad_disconnected(struct wpe_gamepad_provider*, uint32_t gamepad_id);

WPE_EXPORT
struct wpe_gamepad*
wpe_gamepad_create(struct wpe_gamepad_provider* provider, uint32_t gamepad_id);

WPE_EXPORT
void
wpe_gamepad_destroy(struct wpe_gamepad*);

WPE_EXPORT
void
wpe_gamepad_set_client(struct wpe_gamepad*, struct wpe_gamepad_client*, void*);

WPE_EXPORT
uint32_t
wpe_gamepad_get_id(struct wpe_gamepad*);

WPE_EXPORT
const char*
wpe_gamepad_get_device_name(struct wpe_gamepad*);

WPE_EXPORT
uint32_t
wpe_gamepad_get_button_count(struct wpe_gamepad*);

WPE_EXPORT
uint32_t
wpe_gamepad_copy_button_values(struct wpe_gamepad*, double*, uint32_t);

WPE_EXPORT
uint32_t
wpe_gamepad_get_axis_count(struct wpe_gamepad*);

WPE_EXPORT
uint32_t
wpe_gamepad_copy_axis_values(struct wpe_gamepad*, double*, uint32_t);

WPE_EXPORT
void
wpe_gamepad_dispatch_button_values_changed(struct wpe_gamepad*);

WPE_EXPORT
void
wpe_gamepad_dispatch_axis_values_changed(struct wpe_gamepad*);

struct wpe_gamepad_provider_client {
void (*gamepad_connected)(void*, uint32_t gamepad_id);
void (*gamepad_disconnected)(void*, uint32_t gamepad_id);
};

struct wpe_gamepad_client {
void (*button_values_changed)(struct wpe_gamepad*, void*);
void (*axis_values_changed)(struct wpe_gamepad*, void*);
};

#ifdef __cplusplus
}
#endif

#endif /* wpe_gamepad_h */
1 change: 1 addition & 0 deletions include/wpe/wpe.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "version.h"
#include "version-deprecated.h"
#include "view-backend.h"
#include "gamepad.h"

#undef __WPE_H_INSIDE__

Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ libwpe = library('wpe-' + api_version,
'src/renderer-host.c',
'src/version.c',
'src/view-backend.c',
'src/gamepad.c',
install: true,
dependencies: dependencies,
version: soversion,
Expand All @@ -95,6 +96,7 @@ api_headers = [
'include/wpe/view-backend.h',
'include/wpe/wpe-egl.h',
'include/wpe/wpe.h',
'include/wpe/gamepad.h',

# Generated API headers.
configure_file(
Expand Down
47 changes: 47 additions & 0 deletions src/gamepad-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* If not stated otherwise in this file or this component's Licenses.txt file the
* following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef wpe_gamepad_private_h
#define wpe_gamepad_private_h

#include <wpe/gamepad.h>

#ifdef __cplusplus
extern "C" {
#endif

struct wpe_gamepad_provider {
struct wpe_gamepad_provider_interface* interface;
void* interface_data;
const struct wpe_gamepad_provider_client* provider_client;
void* provider_client_data;
};

struct wpe_gamepad {
struct wpe_gamepad_interface* interface;
void* interface_data;
const struct wpe_gamepad_client* gamepad_client;
void* gamepad_client_data;
uint32_t gamepad_id;
};

#ifdef __cplusplus
}
#endif

#endif /* wpe_gamepad_private_h */
Loading