diff --git a/applications/launcher/controller.h b/applications/launcher/controller.h index 1f946872f..ba4ef43d8 100644 --- a/applications/launcher/controller.h +++ b/applications/launcher/controller.h @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "appitem.h" @@ -19,7 +18,6 @@ using namespace codes::eeems::oxide1; using codes::eeems::oxide1::Power; using Oxide::SysObject; -using Oxide::EventFilter; using namespace Oxide::Sentry; enum State { Normal, PowerSaving }; @@ -61,7 +59,6 @@ class Controller : public QObject Q_PROPERTY(int maxTouchHeight READ maxTouchHeight) public: static std::string exec(const char* cmd); - EventFilter* filter; QObject* stateController; QObject* root = nullptr; explicit Controller(QObject* parent = 0) diff --git a/applications/launcher/main.cpp b/applications/launcher/main.cpp index 3010c4748..65e3072d8 100644 --- a/applications/launcher/main.cpp +++ b/applications/launcher/main.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "controller.h" @@ -30,16 +31,13 @@ int main(int argc, char* argv[]){ deviceSettings.setupQtEnvironment(); QGuiApplication app(argc, argv); sentry_init("oxide", argv); - auto filter = new EventFilter(&app); app.setOrganizationName("Eeems"); app.setOrganizationDomain(OXIDE_SERVICE); app.setApplicationName("oxide"); app.setApplicationDisplayName("Launcher"); - app.installEventFilter(filter); QQmlApplicationEngine engine; QQmlContext* context = engine.rootContext(); Controller* controller = new Controller(); - controller->filter = filter; qmlRegisterAnonymousType("codes.eeems.oxide", 2); qmlRegisterAnonymousType("codes.eeems.oxide", 2); context->setContextProperty("screenGeometry", app.primaryScreen()->geometry()); @@ -52,7 +50,7 @@ int main(int argc, char* argv[]){ } QObject* root = engine.rootObjects().first(); controller->root = root; - filter->root = (QQuickItem*)root; + root->installEventFilter(new EventFilter(&app)); QObject* stateController = root->findChild("stateController"); if(!stateController){ qDebug() << "Can't find stateController"; diff --git a/applications/lockscreen/main.cpp b/applications/lockscreen/main.cpp index d187c2aad..aeaae8663 100644 --- a/applications/lockscreen/main.cpp +++ b/applications/lockscreen/main.cpp @@ -17,8 +17,6 @@ int main(int argc, char *argv[]){ deviceSettings.setupQtEnvironment(); QGuiApplication app(argc, argv); sentry_init("decay", argv); - auto filter = new EventFilter(&app); - app.installEventFilter(filter); app.setOrganizationName("Eeems"); app.setOrganizationDomain(OXIDE_SERVICE); app.setApplicationName("decay"); @@ -34,7 +32,8 @@ int main(int argc, char *argv[]){ return -1; } auto root = engine.rootObjects().first(); - filter->root = (QQuickItem*)root; + root->installEventFilter(new EventFilter(&app)); controller.setRoot(root); + qDebug() << root; return app.exec(); } diff --git a/applications/process-manager/main.cpp b/applications/process-manager/main.cpp index 57286d8d9..af506fd5b 100755 --- a/applications/process-manager/main.cpp +++ b/applications/process-manager/main.cpp @@ -25,8 +25,6 @@ int main(int argc, char *argv[]){ app.setApplicationName("tarnish"); app.setApplicationDisplayName("Process Monitor"); app.setApplicationVersion(APP_VERSION); - EventFilter filter; - app.installEventFilter(&filter); QQmlApplicationEngine engine; QQmlContext* context = engine.rootContext(); Controller controller(&engine); @@ -38,7 +36,7 @@ int main(int argc, char *argv[]){ return -1; } QObject* root = engine.rootObjects().first(); - filter.root = (QQuickItem*)root; + root->installEventFilter(new EventFilter(&app)); QQuickItem* tasksView = root->findChild("tasksView"); if(!tasksView){ qDebug() << "Can't find tasksView"; diff --git a/applications/screenshot-viewer/main.cpp b/applications/screenshot-viewer/main.cpp index e2ce0ab6f..a41248e98 100644 --- a/applications/screenshot-viewer/main.cpp +++ b/applications/screenshot-viewer/main.cpp @@ -22,8 +22,6 @@ int main(int argc, char *argv[]){ deviceSettings.setupQtEnvironment(); QGuiApplication app(argc, argv); sentry_init("anxiety", argv); - auto filter = new EventFilter(&app); - app.installEventFilter(filter); app.setOrganizationName("Eeems"); app.setOrganizationDomain(OXIDE_SERVICE); app.setApplicationName("anxiety"); @@ -40,7 +38,7 @@ int main(int argc, char *argv[]){ return -1; } auto root = engine.rootObjects().first(); - filter->root = (QQuickItem*)root; + root->installEventFilter(new EventFilter(&app)); controller.setRoot(root); signal(SIGINT, sigHandler); diff --git a/applications/task-switcher/main.cpp b/applications/task-switcher/main.cpp index a975a2e48..2180c6c2c 100644 --- a/applications/task-switcher/main.cpp +++ b/applications/task-switcher/main.cpp @@ -25,8 +25,6 @@ int main(int argc, char *argv[]){ deviceSettings.setupQtEnvironment(); QGuiApplication app(argc, argv); sentry_init("corrupt", argv); - auto filter = new EventFilter(&app); - app.installEventFilter(filter); app.setOrganizationName("Eeems"); app.setOrganizationDomain(OXIDE_SERVICE); app.setApplicationName("corrupt"); @@ -46,7 +44,7 @@ int main(int argc, char *argv[]){ return -1; } auto root = engine.rootObjects().first(); - filter->root = (QQuickItem*)root; + root->installEventFilter(new EventFilter(&app)); controller.setRoot(root); signal(SIGINT, sigHandler); diff --git a/shared/liboxide/eventfilter.cpp b/shared/liboxide/eventfilter.cpp index c207f825d..1ccc2f87c 100644 --- a/shared/liboxide/eventfilter.cpp +++ b/shared/liboxide/eventfilter.cpp @@ -7,11 +7,13 @@ #include #include +#include +#include + #define DISPLAYWIDTH 1404 #define DISPLAYHEIGHT 1872.0 #define WACOM_X_SCALAR (float(DISPLAYWIDTH) / float(DISPLAYHEIGHT)) #define WACOM_Y_SCALAR (float(DISPLAYHEIGHT) / float(DISPLAYWIDTH)) -//#define DEBUG_EVENTS #ifdef DEBUG_EVENTS #define O_DEBUG_EVENT(msg) O_DEBUG(msg) #else @@ -19,7 +21,7 @@ #endif namespace Oxide{ - EventFilter::EventFilter(QObject *parent) : QObject(parent), root(nullptr){} + EventFilter::EventFilter(QObject *parent) : QObject(parent) {} QPointF swap(QPointF pointF){ return QPointF(pointF.y(), pointF.x()); @@ -32,124 +34,65 @@ namespace Oxide{ pointF.setY((DISPLAYWIDTH - pointF.y()) * WACOM_Y_SCALAR); return pointF; } - QPointF globalPos(QQuickItem* obj){ - qreal x = obj->x(); - qreal y = obj->y(); - while(obj->parentItem() != nullptr){ - obj = obj->parentItem(); - x += obj->x(); - y += obj->y(); + + bool EventFilter::eventFilter(QObject* obj, QEvent* ev){ + auto type = ev->type(); + if(QObject::eventFilter(obj, ev)){ + return true; } - return QPointF(x, y); - } - QMouseEvent* toMouseEvent(QEvent::Type type, QEvent* ev){ - auto tabletEvent = (QTabletEvent*)ev; - auto button = tabletEvent->pressure() > 0 || type == QMouseEvent::MouseButtonRelease ? Qt::LeftButton : Qt::NoButton; - return new QMouseEvent( - type, - transpose(tabletEvent->posF()), - transpose(tabletEvent->globalPosF()), - transpose(tabletEvent->globalPosF()), - button, - button, - tabletEvent->modifiers() - ); - } - bool isAt(QQuickItem* item, QPointF pos){ - auto itemPos = globalPos(item); - auto otherItemPos = QPointF(itemPos.x() + item->width(), itemPos.y() + item->height()); - return pos.x() >= itemPos.x() && pos.x() <= otherItemPos.x() && pos.y() >= itemPos.y() && pos.y() <= otherItemPos.y(); - } - QList widgetsAt(QQuickItem* root, QPointF pos){ - QList result; - auto children = root->findChildren(); - for(auto child : children){ - if(result.contains(child)){ - continue; - } - if(!child->isVisible() || !child->isEnabled()){ - continue; - } - if(child->acceptedMouseButtons() & Qt::LeftButton && isAt(child, pos)){ - result.append((QObject*)child); - for(auto item : widgetsAt(child, pos)){ - if(!result.contains(item)){ - result.append(item); - } - } - continue; - } - if(!child->clip()){ - for(auto item : widgetsAt(child, pos)){ - if(!result.contains(item)){ - result.append(item); - } - } - } + if(type == QEvent::TabletPress){ + O_DEBUG_EVENT(ev); + auto tabletEvent = (QTabletEvent*)ev; + QWindowSystemInterface::handleMouseEvent( + nullptr, + transpose(tabletEvent->posF()), + transpose(tabletEvent->globalPosF()), + tabletEvent->buttons(), + tabletEvent->button(), + QEvent::MouseButtonPress + ); + tabletEvent->accept(); + return true; } - return result; - } - int parentCount(QQuickItem* obj){ - int count = 0; - while(obj->parentItem()){ - count++; - obj = obj->parentItem(); + if(type == QEvent::TabletRelease){ + O_DEBUG_EVENT(ev); + auto tabletEvent = (QTabletEvent*)ev; + QWindowSystemInterface::handleMouseEvent( + nullptr, + transpose(tabletEvent->posF()), + transpose(tabletEvent->globalPosF()), + tabletEvent->buttons(), + tabletEvent->button(), + QEvent::MouseButtonRelease + ); + tabletEvent->accept(); + return true; } - return count; - } - void postEvent(QEvent::Type type, QEvent* ev, QQuickItem* root){ - auto mouseEvent = toMouseEvent(type, ev); - auto pos = mouseEvent->globalPos(); - for(auto postWidget : widgetsAt(root, pos)){ - if(parentCount((QQuickItem*)postWidget)){ - O_DEBUG_EVENT("postWidget: " << postWidget); - auto event = new QMouseEvent( - mouseEvent->type(), mouseEvent->localPos(), mouseEvent->windowPos(), - mouseEvent->screenPos(), mouseEvent->button(), mouseEvent->buttons(), - mouseEvent->modifiers() - ); - auto widgetPos = globalPos((QQuickItem*)postWidget); - auto localPos = event->localPos(); - localPos.setX(pos.x() - widgetPos.x()); - localPos.setY((pos.y()) - widgetPos.y()); - event->setLocalPos(localPos); - QGuiApplication::postEvent(postWidget, event); - } + if(type == QEvent::TabletMove){ + O_DEBUG_EVENT(ev); + auto tabletEvent = (QTabletEvent*)ev; + QWindowSystemInterface::handleMouseEvent( + nullptr, + transpose(tabletEvent->posF()), + transpose(tabletEvent->globalPosF()), + tabletEvent->buttons(), + tabletEvent->button(), + QEvent::MouseMove + ); + tabletEvent->accept(); + return true; } - delete mouseEvent; - } - - bool EventFilter::eventFilter(QObject* obj, QEvent* ev){ - auto type = ev->type(); - bool filtered = QObject::eventFilter(obj, ev); - if(!filtered){ - if(type == QEvent::TabletPress){ - O_DEBUG_EVENT(ev); - postEvent(QMouseEvent::MouseButtonPress, ev, root); - }else if(type == QEvent::TabletRelease){ - O_DEBUG_EVENT(ev); - postEvent(QMouseEvent::MouseButtonRelease, ev, root); - }else if(type == QEvent::TabletMove){ - O_DEBUG_EVENT(ev); - postEvent(QMouseEvent::MouseMove, ev, root); - } #ifdef DEBUG_EVENTS - else if( - type == QEvent::MouseMove - || type == QEvent::MouseButtonPress - || type == QEvent::MouseButtonRelease - ){ - for(auto widget : widgetsAt(root, ((QMouseEvent*)ev)->globalPos())){ - if(parentCount((QQuickItem*)widget)){ - O_DEBUG("postWidget: " << widget); - } - } - O_DEBUG(obj); - O_DEBUG(ev); - } -#endif + if( + type == QEvent::MouseMove + || type == QEvent::MouseButtonPress + || type == QEvent::MouseButtonRelease + ){ + O_DEBUG(obj); + O_DEBUG(ev); } - return filtered; +#endif + return false; } } diff --git a/shared/liboxide/eventfilter.h b/shared/liboxide/eventfilter.h index ede694155..17260a799 100644 --- a/shared/liboxide/eventfilter.h +++ b/shared/liboxide/eventfilter.h @@ -25,12 +25,6 @@ namespace Oxide{ { Q_OBJECT public: - /*! - * \brief The root element in the Qt application - * - * This is needed to find wigets to send mouse events when a pen touch is detected - */ - QQuickItem* root; /*! * \brief Create a new EventFilter instance * \param parent The parent object. Usually should be qApp diff --git a/shared/liboxide/examples/oxide.cpp b/shared/liboxide/examples/oxide.cpp index 874caa102..b4b154838 100644 --- a/shared/liboxide/examples/oxide.cpp +++ b/shared/liboxide/examples/oxide.cpp @@ -41,6 +41,7 @@ try{ #include #import +#include #ifdef __arm__ Q_IMPORT_PLUGIN(QsgEpaperPlugin) @@ -49,10 +50,6 @@ Q_IMPORT_PLUGIN(QsgEpaperPlugin) using namespace Oxide; int main(int argc, char *argv[]){ QGuiApplication app(argc, argv); - - auto filter = new EventFilter(&app); - app.installEventFilter(filter); - QQmlApplicationEngine engine; QQmlContext* context = engine.rootContext(); context->setContextProperty("screenGeometry", app.primaryScreen()->geometry()); @@ -63,7 +60,7 @@ int main(int argc, char *argv[]){ } auto root = engine.rootObjects().first(); - filter->root = (QQuickItem*)root; + root->installEventFilter(new EventFilter(&app)); return app.exec(); } //! [EventFilter] diff --git a/shared/liboxide/liboxide.pro b/shared/liboxide/liboxide.pro index b3eb5a6d9..262fdbb8a 100644 --- a/shared/liboxide/liboxide.pro +++ b/shared/liboxide/liboxide.pro @@ -1,6 +1,7 @@ QT -= gui QT += quick QT += dbus +QT += gui-private TEMPLATE = lib DEFINES += LIBOXIDE_LIBRARY