diff options
Diffstat (limited to 'src/plugins/graphicssystems/minimaldfb/qdirectfbinput.cpp')
-rw-r--r-- | src/plugins/graphicssystems/minimaldfb/qdirectfbinput.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/plugins/graphicssystems/minimaldfb/qdirectfbinput.cpp b/src/plugins/graphicssystems/minimaldfb/qdirectfbinput.cpp new file mode 100644 index 0000000..4ba4ff8 --- /dev/null +++ b/src/plugins/graphicssystems/minimaldfb/qdirectfbinput.cpp @@ -0,0 +1,104 @@ +#include "qdirectfbinput.h" +#include "qdirectfbconvenience.h" + +#include <QThread> +#include <QDebug> +#include <private/qapplication_p.h> +#include <QMouseEvent> +#include <QEvent> + +#include <directfb/directfb.h> + +InputSocketWaiter::InputSocketWaiter(IDirectFBEventBuffer *eventBuffer, QObject *parent) + : QThread(parent), eventBuffer(eventBuffer) + { + this->start(); + } + +void InputSocketWaiter::run() +{ + while (1) { + eventBuffer->WaitForEvent(eventBuffer); + emit newEvent(); + } +} + +QDirectFbInput::QDirectFbInput(QObject *parent) + : QObject(parent) +{ + DFBResult ok = DirectFBCreate(&dfbInterface); + if (ok != DFB_OK) + DirectFBError("Failed to initialise QDirectFBInput", ok); + + ok = dfbInterface->CreateEventBuffer(dfbInterface,&eventBuffer); + if (ok != DFB_OK) + DirectFBError("Failed to initialise eventbuffer", ok); + + dfbInterface->GetDisplayLayer(dfbInterface,DLID_PRIMARY, &dfbDisplayLayer); + + InputSocketWaiter *inputHandler = new InputSocketWaiter(eventBuffer,this); + connect(inputHandler,SIGNAL(newEvent()),this,SLOT(handleEvents())); +} + +void QDirectFbInput::addWindow(DFBWindowID id, QWidget *tlw) +{ + tlwMap.insert(id,tlw); + IDirectFBWindow *window; + dfbDisplayLayer->GetWindow(dfbDisplayLayer,id,&window); + +// window->DisableEvents(window,DWET_ALL); + window->EnableEvents(window,DFBWindowEventType(DWET_ALL)); + window->SetKeySelection(window,DWKS_ALL,NULL,0); + window->AttachEventBuffer(window,eventBuffer); +} + +void QDirectFbInput::handleEvents() +{ + DFBResult hasEvent = eventBuffer->HasEvent(eventBuffer); + while(hasEvent == DFB_OK){ + DFBEvent event; + DFBResult ok = eventBuffer->GetEvent(eventBuffer,&event); + if (ok != DFB_OK) + DirectFBError("Failed to get event",ok); + if (event.clazz == DFEC_WINDOW) { + switch (event.window.type) { + case DWET_BUTTONDOWN: + case DWET_BUTTONUP: +// case DWET_MOTION: + case DWET_WHEEL: + handleMouseEvents(event); + break; + case DWET_KEYDOWN: + qDebug() << "FOOOOBAR!"; + } + + } else + qDebug() << "WHAT!"; + + hasEvent = eventBuffer->HasEvent(eventBuffer); + } +} + +void QDirectFbInput::handleMouseEvents(const DFBEvent &event) +{ + QEvent::Type type = QDirectFbConvenience::eventType(event.window.type); + QPoint p(event.window.cx, event.window.cy); + QPoint globalPos = globalPoint(event); + Qt::MouseButton button = QDirectFbConvenience::mouseButton(event.window.button); + Qt::MouseButtons buttons = QDirectFbConvenience::mouseButtons(event.window.buttons); + + qDebug() << QDirectFbConvenience::keyMap()->value(event.window.key_symbol); + QMouseEvent mouseEvent(type,p,globalPos,button, buttons,(Qt::KeyboardModifiers)0); + QWidget *tlw = tlwMap.value(event.window.window_id); + QApplicationPrivate::handleMouseEvent(tlw,mouseEvent); +} + +inline QPoint QDirectFbInput::globalPoint(const DFBEvent &event) const +{ + IDirectFBWindow *window; + dfbDisplayLayer->GetWindow(dfbDisplayLayer,event.window.window_id,&window); + int x,y; + window->GetPosition(window,&x,&y); + return QPoint(event.window.cx +x, event.window.cy + y); +} + |