Skip to content

Commit

Permalink
[WPE] Touch event support
Browse files Browse the repository at this point in the history
  • Loading branch information
abihf committed Dec 12, 2015
1 parent f3ad245 commit 49fb5bd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
50 changes: 50 additions & 0 deletions Source/WPE/Source/Input/LibinputServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ void LibinputServer::setHandlePointerEvents(bool handle)
fprintf(stderr, "[LibinputServer] %s pointer events.\n", handle ? "Enabling" : "Disabling");
}

void LibinputServer::setHandleTouchEvents(bool handle)
{
m_handleTouchEvents = handle;
fprintf(stderr, "[LibinputServer] %s handle events.\n", handle ? "Enabling" : "Disabling");
}

void LibinputServer::setPointerBounds(uint32_t width, uint32_t height)
{
m_pointerBounds = { width, height };
Expand All @@ -114,6 +120,19 @@ void LibinputServer::processEvents()

while (auto* event = libinput_get_event(m_libinput)) {
switch (libinput_event_get_type(event)) {
case LIBINPUT_EVENT_TOUCH_DOWN:
if (m_handleTouchEvents)
handleTouchEvent(event, Input::TouchEvent::Type::Down);
printf("touch down\n");
break;
case LIBINPUT_EVENT_TOUCH_UP:
if (m_handleTouchEvents)
handleTouchEvent(event, Input::TouchEvent::Type::Up);
break;
case LIBINPUT_EVENT_TOUCH_MOTION:
if (m_handleTouchEvents)
handleTouchEvent(event, Input::TouchEvent::Type::Motion);
break;
case LIBINPUT_EVENT_KEYBOARD_KEY:
{
auto* keyEvent = libinput_event_get_keyboard_event(event);
Expand Down Expand Up @@ -204,6 +223,37 @@ void LibinputServer::dispatchKeyboardEvent(const Input::KeyboardEvent::Raw& even
m_client->handleKeyboardEvent({ event.time, std::get<0>(result), std::get<1>(result), !!event.state, std::get<2>(result) });
}

void LibinputServer::handleTouchEvent(struct libinput_event *event, Input::TouchEvent::Type type)
{
auto* touchEvent = libinput_event_get_touch_event(event);
uint32_t time = libinput_event_touch_get_time(touchEvent);
int id = libinput_event_touch_get_slot(touchEvent);
auto& targetPoint = m_touchEvents[id];
int32_t x, y;

if (type != Input::TouchEvent::Up) {
x = libinput_event_touch_get_x_transformed(touchEvent, m_pointerBounds.first);
y = libinput_event_touch_get_y_transformed(touchEvent, m_pointerBounds.second);
} else {
// libinput can't return pointer position on touch-up
x = targetPoint.x;
y = targetPoint.y;
}
targetPoint = Input::TouchEvent::Raw{ type, time, id, x, y };

m_client->handleTouchEvent({
m_touchEvents,
type,
id,
time
});

if (type == Input::TouchEvent::Up) {
targetPoint = Input::TouchEvent::Raw{ Input::TouchEvent::Null, 0, -1, -1, -1 };
}
}


GSourceFuncs LibinputServer::EventSource::s_sourceFuncs = {
nullptr, // prepare
// check
Expand Down
5 changes: 5 additions & 0 deletions Source/WPE/Source/Input/LibinputServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class LibinputServer : public Input::KeyboardEventRepeating::Client {

void setClient(Input::Client* client);
void setHandlePointerEvents(bool handle);
void setHandleTouchEvents(bool handle);
void setPointerBounds(uint32_t, uint32_t);

private:
Expand All @@ -68,6 +69,10 @@ class LibinputServer : public Input::KeyboardEventRepeating::Client {
std::pair<int32_t, int32_t> m_pointerCoords;
std::pair<uint32_t, uint32_t> m_pointerBounds;

bool m_handleTouchEvents { false };
std::array<Input::TouchEvent::Raw, 10> m_touchEvents;
void handleTouchEvent(struct libinput_event *event, Input::TouchEvent::Type type)

class EventSource {
public:
static GSourceFuncs s_sourceFuncs;
Expand Down
8 changes: 6 additions & 2 deletions Source/WPE/Source/ViewBackend/BCMRPi/ViewBackendBCMRPi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,15 @@ void ViewBackendBCMRPi::destroyBuffer(uint32_t)

void ViewBackendBCMRPi::setInputClient(Input::Client* client)
{
if (std::getenv("WPE_BCMRPI_TOUCH")) {
LibinputServer::singleton().setHandleTouchEvents(true);
}
if (std::getenv("WPE_BCMRPI_CURSOR")) {
m_cursor.reset(new Cursor(client, m_displayHandle, m_width, m_height));
client = m_cursor.get();
LibinputServer::singleton().setHandlePointerEvents(true);
LibinputServer::singleton().setPointerBounds(m_width, m_height);
}
LibinputServer::singleton().setPointerBounds(m_width, m_height);

LibinputServer::singleton().setClient(client);
}
Expand Down Expand Up @@ -197,8 +200,9 @@ void ViewBackendBCMRPi::Cursor::handleAxisEvent(Input::AxisEvent&& event)
m_targetClient->handleAxisEvent(std::move(event));
}

void ViewBackendBCMRPi::Cursor::handleTouchEvent(Input::TouchEvent&&)
void ViewBackendBCMRPi::Cursor::handleTouchEvent(Input::TouchEvent&& event)
{
m_targetClient->handleTouchEvent(std::move(event));
}

// The cursor pointer data uses the modified left_ptr cursor from the
Expand Down

0 comments on commit 49fb5bd

Please sign in to comment.