Touch support in libinput

master
Martin Gräßlin 10 years ago
parent 36f987198d
commit 60783b8228

@ -232,6 +232,11 @@ void InputRedirection::setupLibInput()
processPointerMotion(screen, time);
}
);
connect(conn, &LibInput::Connection::touchDown, this, &InputRedirection::processTouchDown);
connect(conn, &LibInput::Connection::touchUp, this, &InputRedirection::processTouchUp);
connect(conn, &LibInput::Connection::touchMotion, this, &InputRedirection::processTouchMotion);
connect(conn, &LibInput::Connection::touchCanceled, this, &InputRedirection::cancelTouch);
connect(conn, &LibInput::Connection::touchFrame, this, &InputRedirection::touchFrame);
connect(screens(), &Screens::changed, this, &InputRedirection::updatePointerAfterScreenChange);
// set pos to center of all screens
if (screens()) {

@ -136,6 +136,29 @@ void Connection::handleEvent()
emit pointerMotionAbsolute(pe->absolutePos(), pe->absolutePos(m_size), pe->time());
break;
}
case LIBINPUT_EVENT_TOUCH_DOWN: {
TouchEvent *te = static_cast<TouchEvent*>(event.data());
emit touchDown(te->id(), te->absolutePos(m_size), te->time());
break;
}
case LIBINPUT_EVENT_TOUCH_UP: {
TouchEvent *te = static_cast<TouchEvent*>(event.data());
emit touchUp(te->id(), te->time());
break;
}
case LIBINPUT_EVENT_TOUCH_MOTION: {
TouchEvent *te = static_cast<TouchEvent*>(event.data());
emit touchMotion(te->id(), te->absolutePos(m_size), te->time());
break;
}
case LIBINPUT_EVENT_TOUCH_CANCEL: {
emit touchCanceled();
break;
}
case LIBINPUT_EVENT_TOUCH_FRAME: {
emit touchFrame();
break;
}
default:
// nothing
break;

@ -54,6 +54,11 @@ Q_SIGNALS:
void pointerMotionAbsolute(QPointF orig, QPointF screen, uint32_t time);
void pointerMotion(QPointF delta, uint32_t time);
void pointerAxisChanged(InputRedirection::PointerAxis axis, qreal delta, uint32_t time);
void touchFrame();
void touchCanceled();
void touchDown(qint32 id, const QPointF &absolutePos, quint32 time);
void touchUp(qint32 id, quint32 time);
void touchMotion(qint32 id, const QPointF &absolutePos, quint32 time);
private:
Connection(Context *input, QObject *parent = nullptr);

@ -42,6 +42,12 @@ Event *Event::create(libinput_event *event)
case LIBINPUT_EVENT_POINTER_MOTION:
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
return new PointerEvent(event, t);
case LIBINPUT_EVENT_TOUCH_DOWN:
case LIBINPUT_EVENT_TOUCH_UP:
case LIBINPUT_EVENT_TOUCH_MOTION:
case LIBINPUT_EVENT_TOUCH_CANCEL:
case LIBINPUT_EVENT_TOUCH_FRAME:
return new TouchEvent(event, t);
default:
return new Event(event, t);
}
@ -165,5 +171,38 @@ qreal PointerEvent::axisValue(InputRedirection::PointerAxis axis) const
return libinput_event_pointer_get_axis_value(m_pointerEvent, a);
}
TouchEvent::TouchEvent(libinput_event *event, libinput_event_type type)
: Event(event, type)
, m_touchEvent(libinput_event_get_touch_event(event))
{
}
TouchEvent::~TouchEvent() = default;
quint32 TouchEvent::time() const
{
return libinput_event_touch_get_time(m_touchEvent);
}
QPointF TouchEvent::absolutePos() const
{
Q_ASSERT(type() == LIBINPUT_EVENT_TOUCH_DOWN || type() == LIBINPUT_EVENT_TOUCH_MOTION);
return QPointF(libinput_event_touch_get_x(m_touchEvent),
libinput_event_touch_get_y(m_touchEvent));
}
QPointF TouchEvent::absolutePos(const QSize &size) const
{
Q_ASSERT(type() == LIBINPUT_EVENT_TOUCH_DOWN || type() == LIBINPUT_EVENT_TOUCH_MOTION);
return QPointF(libinput_event_touch_get_x_transformed(m_touchEvent, size.width()),
libinput_event_touch_get_y_transformed(m_touchEvent, size.height()));
}
qint32 TouchEvent::id() const
{
Q_ASSERT(type() != LIBINPUT_EVENT_TOUCH_CANCEL && type() != LIBINPUT_EVENT_TOUCH_FRAME);
return libinput_event_touch_get_slot(m_touchEvent);
}
}
}

@ -101,6 +101,28 @@ private:
libinput_event_pointer *m_pointerEvent;
};
class TouchEvent : public Event
{
public:
TouchEvent(libinput_event *event, libinput_event_type type);
virtual ~TouchEvent();
quint32 time() const;
QPointF absolutePos() const;
QPointF absolutePos(const QSize &size) const;
qint32 id() const;
operator libinput_event_touch*() {
return m_touchEvent;
}
operator libinput_event_touch*() const {
return m_touchEvent;
}
private:
libinput_event_touch *m_touchEvent;
};
inline
libinput_event_type Event::type() const
{

@ -83,6 +83,31 @@ int main(int argc, char **argv)
std::cout << "Axis: " << axis << " with delta" << delta << std::endl;
}
);
QObject::connect(conn, &Connection::touchDown,
[](qint32 id, const QPointF &position, quint32 time) {
std::cout << "Touch down at: " << position.x() << "/" << position.y() << " id " << id << " timestamp: " << time << std::endl;
}
);
QObject::connect(conn, &Connection::touchMotion,
[](qint32 id, const QPointF &position, quint32 time) {
std::cout << "Touch motion at: " << position.x() << "/" << position.y() << " id " << id << " timestamp: " << time << std::endl;
}
);
QObject::connect(conn, &Connection::touchUp,
[](qint32 id, quint32 time) {
std::cout << "Touch up for id " << id << " timestamp: " << time << std::endl;
}
);
QObject::connect(conn, &Connection::touchCanceled,
[]() {
std::cout << "Touch canceled" << std::endl;
}
);
QObject::connect(conn, &Connection::touchFrame,
[]() {
std::cout << "Touch frame " << std::endl;
}
);
QObject::connect(&app, &QCoreApplication::aboutToQuit, [conn] { delete conn; });
}
);

Loading…
Cancel
Save