Skip to content

Commit

Permalink
[maliit] Don't block touch events outside the visible part of the key…
Browse files Browse the repository at this point in the history
…board. Contributes to JB#42563

A window surface may be created and destroyed many times over the
lifetime of a window so we need to react to the creation to set
window properties rather than forcing creation as a one off. And
wayland needs to be informed of the input region so it can direct
touchs appropriately.
  • Loading branch information
adenexter committed Aug 1, 2018
1 parent cd3f65f commit 84e2073
Showing 1 changed file with 52 additions and 6 deletions.
58 changes: 52 additions & 6 deletions maliit-framework/src/lipstickplatform.cpp
Expand Up @@ -14,23 +14,69 @@
#include "lipstickplatform.h"

#include <QGuiApplication>
#include <QPlatformSurfaceEvent>
#include <qpa/qplatformnativeinterface.h>

namespace Maliit
{

class LipstickWindowPropertyBroadcaster : public QObject
{
public:
LipstickWindowPropertyBroadcaster(QWindow *window)
: QObject(window)
, m_window(window)
{
m_window->installEventFilter(this);
}

bool eventFilter(QObject *object, QEvent *event)
{
if (object != m_window) {
return false;
} else switch (event->type()) {
case QEvent::PlatformSurface: {
QPlatformSurfaceEvent *platformEvent = static_cast<QPlatformSurfaceEvent *>(event);

if (QPlatformWindow *handle = platformEvent->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated
? m_window->handle()
: nullptr) {
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();

native->setWindowProperty(handle, QStringLiteral("CATEGORY"), QStringLiteral("overlay"));
native->setWindowProperty(handle, QStringLiteral("MOUSE_REGION"), m_window->property("MOUSE_REGION"));
}
return false;
}
case QEvent::DynamicPropertyChange: {
QDynamicPropertyChangeEvent *propertyEvent = static_cast<QDynamicPropertyChangeEvent *>(event);
if (QPlatformWindow *handle = propertyEvent->propertyName() == "MOUSE_REGION"
? m_window->handle()
: nullptr) {
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();

native->setWindowProperty(handle, QStringLiteral("MOUSE_REGION"), m_window->property("MOUSE_REGION"));
}
return false;
}
default:
return false;
}
}

private:
QWindow * const m_window;
};

void LipstickPlatform::setupInputPanel(QWindow* window, Maliit::Position)
{
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
window->create();
native->setWindowProperty(window->handle(), QLatin1String("CATEGORY"), QString("overlay"));
new LipstickWindowPropertyBroadcaster(window);
}

void LipstickPlatform::setInputRegion(QWindow* window, const QRegion& region)
{
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
window->create();
native->setWindowProperty(window->handle(), QLatin1String("MOUSE_REGION"), QVariant(region));
window->setProperty("MOUSE_REGION", region);
window->setMask(region);
}

} // namespace Maliit

0 comments on commit 84e2073

Please sign in to comment.