[libinput] Pass device capabilities to Wayland::Server::SeatInterface

We handle device added/remove to monitor whether we have keyboard,
pointer and touch devices and emit signals. Those are used to update
the SeatInferface from InputRedirection.
icc-effect-5.14.5
Martin Gräßlin 2015-03-26 16:19:26 +01:00
parent 93b3626a37
commit f7bed6a003
3 changed files with 78 additions and 12 deletions

View File

@ -203,6 +203,17 @@ InputRedirection::~InputRedirection()
s_self = NULL;
}
#if HAVE_WAYLAND
static KWayland::Server::SeatInterface *findSeat()
{
auto server = waylandServer();
if (!server) {
return nullptr;
}
return server->seat();
}
#endif
void InputRedirection::setupLibInput()
{
#if HAVE_INPUT
@ -245,20 +256,19 @@ void InputRedirection::setupLibInput()
// sanitize
updatePointerAfterScreenChange();
}
}
#endif
}
#if HAVE_WAYLAND
static KWayland::Server::SeatInterface *findSeat()
{
auto server = waylandServer();
if (!server) {
return nullptr;
}
return server->seat();
}
if (auto s = findSeat()) {
s->setHasKeyboard(conn->hasKeyboard());
s->setHasPointer(conn->hasPointer());
s->setHasTouch(conn->hasTouch());
connect(conn, &LibInput::Connection::hasKeyboardChanged, s, &KWayland::Server::SeatInterface::setHasKeyboard);
connect(conn, &LibInput::Connection::hasPointerChanged, s, &KWayland::Server::SeatInterface::setHasPointer);
connect(conn, &LibInput::Connection::hasTouchChanged, s, &KWayland::Server::SeatInterface::setHasTouch);
}
#endif
}
#endif
}
void InputRedirection::updatePointerWindow()
{

View File

@ -109,6 +109,46 @@ void Connection::handleEvent()
break;
}
switch (event->type()) {
case LIBINPUT_EVENT_DEVICE_ADDED:
if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_KEYBOARD)) {
m_keyboard++;
if (m_keyboard == 1) {
emit hasKeyboardChanged(true);
}
}
if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_POINTER)) {
m_pointer++;
if (m_pointer == 1) {
emit hasPointerChanged(true);
}
}
if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_TOUCH)) {
m_touch++;
if (m_touch == 1) {
emit hasTouchChanged(true);
}
}
break;
case LIBINPUT_EVENT_DEVICE_REMOVED:
if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_KEYBOARD)) {
m_keyboard--;
if (m_keyboard == 0) {
emit hasKeyboardChanged(false);
}
}
if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_POINTER)) {
m_pointer--;
if (m_pointer == 0) {
emit hasPointerChanged(false);
}
}
if (libinput_device_has_capability(event->device(), LIBINPUT_DEVICE_CAP_TOUCH)) {
m_touch--;
if (m_touch == 0) {
emit hasTouchChanged(false);
}
}
break;
case LIBINPUT_EVENT_KEYBOARD_KEY: {
KeyEvent *ke = static_cast<KeyEvent*>(event.data());
emit keyChanged(ke->key(), ke->state(), ke->time());

View File

@ -48,6 +48,16 @@ public:
**/
void setScreenSize(const QSize &size);
bool hasKeyboard() const {
return m_keyboard > 0;
}
bool hasTouch() const {
return m_touch > 0;
}
bool hasPointer() const {
return m_pointer > 0;
}
Q_SIGNALS:
void keyChanged(uint32_t key, InputRedirection::KeyboardKeyState, uint32_t time);
void pointerButtonChanged(uint32_t button, InputRedirection::PointerButtonState state, uint32_t time);
@ -59,6 +69,9 @@ Q_SIGNALS:
void touchDown(qint32 id, const QPointF &absolutePos, quint32 time);
void touchUp(qint32 id, quint32 time);
void touchMotion(qint32 id, const QPointF &absolutePos, quint32 time);
void hasKeyboardChanged(bool);
void hasPointerChanged(bool);
void hasTouchChanged(bool);
private:
Connection(Context *input, QObject *parent = nullptr);
@ -66,6 +79,9 @@ private:
Context *m_input;
QSocketNotifier *m_notifier;
QSize m_size;
int m_keyboard = 0;
int m_pointer = 0;
int m_touch = 0;
KWIN_SINGLETON(Connection)
};