Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdirectfbinput.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qdirectfbinput.h"
6
7#include <QThread>
8#include <QDebug>
9#include <qpa/qwindowsysteminterface.h>
10#include <QMouseEvent>
11#include <QEvent>
12
13#include <directfb.h>
14
16
17QDirectFbInput::QDirectFbInput(IDirectFB *dfb, IDirectFBDisplayLayer *dfbLayer)
18 : m_dfbInterface(dfb)
19 , m_dfbDisplayLayer(dfbLayer)
20 , m_shouldStop(false)
21{
22 DFBResult ok = m_dfbInterface->CreateEventBuffer(m_dfbInterface, m_eventBuffer.outPtr());
23 if (ok != DFB_OK)
24 DirectFBError("Failed to initialise eventbuffer", ok);
25}
26
28{
29 while (!m_shouldStop) {
30 if (m_eventBuffer->WaitForEvent(m_eventBuffer.data()) == DFB_OK)
31 handleEvents();
32 }
33}
34
36{
37 m_shouldStop = true;
38 m_eventBuffer->WakeUp(m_eventBuffer.data());
39}
40
41void QDirectFbInput::addWindow(IDirectFBWindow *window, QWindow *platformWindow)
42{
43 DFBResult res;
44 DFBWindowID id;
45
46 res = window->GetID(window, &id);
47 if (res != DFB_OK) {
48 DirectFBError("QDirectFbInput::addWindow", res);
49 return;
50 }
51
52 m_tlwMap.insert(id, platformWindow);
53 window->AttachEventBuffer(window, m_eventBuffer.data());
54}
55
57{
58 DFBResult res;
59 DFBWindowID id;
60
61 res = window->GetID(window, &id);
62 if (res != DFB_OK) {
63 DirectFBError("QDirectFbInput::removeWindow", res);
64 return;
65 }
66
67 window->DetachEventBuffer(window, m_eventBuffer.data());
68 m_tlwMap.remove(id);
69}
70
71void QDirectFbInput::handleEvents()
72{
73 DFBResult hasEvent = m_eventBuffer->HasEvent(m_eventBuffer.data());
74 while(hasEvent == DFB_OK){
75 DFBEvent event;
76 DFBResult ok = m_eventBuffer->GetEvent(m_eventBuffer.data(), &event);
77 if (ok != DFB_OK)
78 DirectFBError("Failed to get event",ok);
79 if (event.clazz == DFEC_WINDOW) {
80 switch (event.window.type) {
81 case DWET_BUTTONDOWN:
82 case DWET_BUTTONUP:
83 case DWET_MOTION:
84 handleMouseEvents(event);
85 break;
86 case DWET_WHEEL:
87 handleWheelEvent(event);
88 break;
89 case DWET_KEYDOWN:
90 case DWET_KEYUP:
91 handleKeyEvents(event);
92 break;
93 case DWET_ENTER:
94 case DWET_LEAVE:
95 handleEnterLeaveEvents(event);
96 break;
97 case DWET_GOTFOCUS:
98 handleGotFocusEvent(event);
99 break;
100 case DWET_CLOSE:
101 handleCloseEvent(event);
102 break;
103 case DWET_POSITION_SIZE:
104 handleGeometryEvent(event);
105 break;
106 default:
107 break;
108 }
109
110 }
111
112 hasEvent = m_eventBuffer->HasEvent(m_eventBuffer.data());
113 }
114}
115
116void QDirectFbInput::handleMouseEvents(const DFBEvent &event)
117{
118 QPoint p(event.window.x, event.window.y);
119 QPoint globalPos(event.window.cx, event.window.cy);
120 Qt::MouseButtons buttons = QDirectFbConvenience::mouseButtons(event.window.buttons);
121
122 QDirectFBPointer<IDirectFBDisplayLayer> layer(QDirectFbConvenience::dfbDisplayLayer());
123 QDirectFBPointer<IDirectFBWindow> window;
124 layer->GetWindow(layer.data(), event.window.window_id, window.outPtr());
125
126 long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000);
127
128 QWindow *tlw = m_tlwMap.value(event.window.window_id);
129 QWindowSystemInterface::handleMouseEvent(tlw, timestamp, p, globalPos, buttons, Qt::NoButton, QEvent::None);
130}
131
132void QDirectFbInput::handleWheelEvent(const DFBEvent &event)
133{
134 QPoint p(event.window.x, event.window.y);
135 QPoint globalPos(event.window.cx, event.window.cy);
136 long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000);
137 QWindow *tlw = m_tlwMap.value(event.window.window_id);
139 timestamp,
140 p,
141 globalPos,
142 QPoint(),
143 QPoint(0, event.window.step*120));
144}
145
146void QDirectFbInput::handleKeyEvents(const DFBEvent &event)
147{
149 Qt::Key key = QDirectFbConvenience::keyMap()->value(event.window.key_symbol);
150 Qt::KeyboardModifiers modifiers = QDirectFbConvenience::keyboardModifiers(event.window.modifiers);
151
152 long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000);
153
154 QChar character;
155 if (DFB_KEY_TYPE(event.window.key_symbol) == DIKT_UNICODE)
156 character = QChar(event.window.key_symbol);
157 QWindow *tlw = m_tlwMap.value(event.window.window_id);
158 QWindowSystemInterface::handleKeyEvent(tlw, timestamp, type, key, modifiers, character);
159}
160
161void QDirectFbInput::handleEnterLeaveEvents(const DFBEvent &event)
162{
163 QWindow *tlw = m_tlwMap.value(event.window.window_id);
164 switch (event.window.type) {
165 case DWET_ENTER:
167 break;
168 case DWET_LEAVE:
170 break;
171 default:
172 break;
173 }
174}
175
176void QDirectFbInput::handleGotFocusEvent(const DFBEvent &event)
177{
178 QWindow *tlw = m_tlwMap.value(event.window.window_id);
180}
181
182void QDirectFbInput::handleCloseEvent(const DFBEvent &event)
183{
184 QWindow *tlw = m_tlwMap.value(event.window.window_id);
186}
187
188void QDirectFbInput::handleGeometryEvent(const DFBEvent &event)
189{
190 QWindow *tlw = m_tlwMap.value(event.window.window_id);
191 QRect rect(event.window.x, event.window.y, event.window.w, event.window.h);
193}
194
\inmodule QtCore
static QEvent::Type eventType(DFBWindowEventType type)
static Qt::MouseButtons mouseButtons(DFBInputDeviceButtonMask mask)
static Qt::KeyboardModifiers keyboardModifiers(DFBInputDeviceModifierMask mask)
static QDirectFbKeyMap * keyMap()
static IDirectFBDisplayLayer * dfbDisplayLayer(int display=DLID_PRIMARY)
QDirectFbInput(IDirectFB *dfb, IDirectFBDisplayLayer *dfbLayer)
void removeWindow(IDirectFBWindow *window)
void run() override
void addWindow(IDirectFBWindow *window, QWindow *platformWindow)
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
bool remove(const Key &key)
Removes the item that has the key from the hash.
Definition qhash.h:958
T value(const Key &key) const noexcept
Definition qhash.h:1054
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1303
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
T * data() const noexcept
Returns the value of the pointer referenced by this object.
static void handleLeaveEvent(QWindow *window)
static void handleFocusWindowChanged(QWindow *window, Qt::FocusReason r=Qt::OtherFocusReason)
static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
static bool handleCloseEvent(QWindow *window)
static void handleGeometryChange(QWindow *window, const QRect &newRect)
static bool handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
static void handleEnterEvent(QWindow *window, const QPointF &local=QPointF(), const QPointF &global=QPointF())
static bool handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::ScrollPhase phase=Qt::NoScrollPhase, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
\inmodule QtGui
Definition qwindow.h:63
EGLImageKHR int int EGLuint64KHR * modifiers
rect
[4]
Combined button and popup list for selecting options.
@ NoButton
Definition qnamespace.h:57
@ ActiveWindowFocusReason
EGLOutputLayerEXT layer
GLuint64 key
GLenum GLuint id
[7]
GLenum type
struct _cl_event * event
GLuint res
GLfloat GLfloat p
[1]
aWidget window() -> setWindowTitle("New Window Title")
[2]