bool LipstickCompositorWindow::eventFilter(QObject *obj, QEvent *event)
{
#if QT_VERSION >= 0x050202
    if (obj == window() && m_interceptingTouch) {
        switch (event->type()) {
        case QEvent::TouchUpdate: {
            QTouchEvent *te = static_cast<QTouchEvent *>(event);
            // If we get press/release, don't intercept the event, but send it through QQuickWindow.
            // These are sent through to QQuickWindow so that the integrity of the touch
            // handling is maintained.
            if (te->touchPointStates() & (Qt::TouchPointPressed | Qt::TouchPointReleased))
                return false;
            handleTouchEvent(static_cast<QTouchEvent *>(event));
            return true;
        }
        case QEvent::TouchEnd: // Intentional fall through...
        case QEvent::TouchCancel:
            obj->removeEventFilter(this);
            m_interceptingTouch = false;
        default:
            break;
        }
        return false;
    }
#else
    Q_UNUSED(obj);
#endif
    if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
        QKeyEvent *ke = static_cast<QKeyEvent *>(event);
        QWaylandSurface *m_surface = surface();
        if (m_surface && (m_grabbedKeys.contains(ke->key()) || m_pressedGrabbedKeys.keys.contains(ke->key())) && !ke->isAutoRepeat()) {
            QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice();
            if (event->type() == QEvent::KeyPress) {
                if (m_pressedGrabbedKeys.keys.isEmpty()) {
                    QWaylandSurface *old = inputDevice->keyboardFocus();
                    m_pressedGrabbedKeys.oldFocus = old;
                    inputDevice->setKeyboardFocus(m_surface);
                }
                m_pressedGrabbedKeys.keys << ke->key();
            }
            inputDevice->sendFullKeyEvent(ke);
            if (event->type() == QEvent::KeyRelease) {
                m_pressedGrabbedKeys.keys.removeOne(ke->key());
                if (m_pressedGrabbedKeys.keys.isEmpty()) {
                    inputDevice->setKeyboardFocus(m_pressedGrabbedKeys.oldFocus);
                    if (m_grabbedKeys.isEmpty())
                        qApp->removeEventFilter(this);
                }
            }
            return true;
        }
    }
    return false;
}
bool LipstickCompositorWindow::eventFilter(QObject *, QEvent *event)
{
    if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
        QKeyEvent *ke = static_cast<QKeyEvent *>(event);
        QWaylandSurface *m_surface = surface();
        if (m_surface && m_grabbedKeys.contains(ke->key())) {
            QWaylandInputDevice *inputDevice = m_surface->compositor()->defaultInputDevice();
            inputDevice->sendFullKeyEvent(m_surface, ke);

            return true;
        }
    }
    return false;
}