Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
7
8#include <QThread>
9#include <QDebug>
10#include <qpa/qwindowsysteminterface.h>
11#include <QMouseEvent>
12#include <QEvent>
13
14#include <directfb.h>
15
17
18QDirectFbInput::QDirectFbInput(IDirectFB *dfb, IDirectFBDisplayLayer *dfbLayer)
19 : m_dfbInterface(dfb)
20 , m_dfbDisplayLayer(dfbLayer)
21 , m_shouldStop(false)
22{
23 DFBResult ok = m_dfbInterface->CreateEventBuffer(m_dfbInterface, m_eventBuffer.outPtr());
24 if (ok != DFB_OK)
25 DirectFBError("Failed to initialise eventbuffer", ok);
26}
27
29{
30 while (!m_shouldStop) {
31 if (m_eventBuffer->WaitForEvent(m_eventBuffer.data()) == DFB_OK)
32 handleEvents();
33 }
34}
35
37{
38 m_shouldStop = true;
39 m_eventBuffer->WakeUp(m_eventBuffer.data());
40}
41
42void QDirectFbInput::addWindow(IDirectFBWindow *window, QWindow *platformWindow)
43{
44 DFBResult res;
45 DFBWindowID id;
46
47 res = window->GetID(window, &id);
48 if (res != DFB_OK) {
49 DirectFBError("QDirectFbInput::addWindow", res);
50 return;
51 }
52
53 m_tlwMap.insert(id, platformWindow);
54 window->AttachEventBuffer(window, m_eventBuffer.data());
55}
56
57void QDirectFbInput::removeWindow(IDirectFBWindow *window)
58{
59 DFBResult res;
60 DFBWindowID id;
61
62 res = window->GetID(window, &id);
63 if (res != DFB_OK) {
64 DirectFBError("QDirectFbInput::removeWindow", res);
65 return;
66 }
67
68 window->DetachEventBuffer(window, m_eventBuffer.data());
69 m_tlwMap.remove(id);
70}
71
72void QDirectFbInput::handleEvents()
73{
74 DFBResult hasEvent = m_eventBuffer->HasEvent(m_eventBuffer.data());
75 while(hasEvent == DFB_OK){
76 DFBEvent event;
77 DFBResult ok = m_eventBuffer->GetEvent(m_eventBuffer.data(), &event);
78 if (ok != DFB_OK)
79 DirectFBError("Failed to get event",ok);
80 if (event.clazz == DFEC_WINDOW) {
81 switch (event.window.type) {
82 case DWET_BUTTONDOWN:
83 case DWET_BUTTONUP:
84 case DWET_MOTION:
85 handleMouseEvents(event);
86 break;
87 case DWET_WHEEL:
88 handleWheelEvent(event);
89 break;
90 case DWET_KEYDOWN:
91 case DWET_KEYUP:
92 handleKeyEvents(event);
93 break;
94 case DWET_ENTER:
95 case DWET_LEAVE:
96 handleEnterLeaveEvents(event);
97 break;
98 case DWET_GOTFOCUS:
99 handleGotFocusEvent(event);
100 break;
101 case DWET_CLOSE:
102 handleCloseEvent(event);
103 break;
104 case DWET_POSITION_SIZE:
105 handleGeometryEvent(event);
106 break;
107 default:
108 break;
109 }
110
111 }
112
113 hasEvent = m_eventBuffer->HasEvent(m_eventBuffer.data());
114 }
115}
116
117void QDirectFbInput::handleMouseEvents(const DFBEvent &event)
118{
119 QPoint p(event.window.x, event.window.y);
120 QPoint globalPos(event.window.cx, event.window.cy);
121 Qt::MouseButtons buttons = QDirectFbConvenience::mouseButtons(event.window.buttons);
122
123 QDirectFBPointer<IDirectFBDisplayLayer> layer(QDirectFbConvenience::dfbDisplayLayer());
124 QDirectFBPointer<IDirectFBWindow> window;
125 layer->GetWindow(layer.data(), event.window.window_id, window.outPtr());
126
127 long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000);
128
129 QWindow *tlw = m_tlwMap.value(event.window.window_id);
130 QWindowSystemInterface::handleMouseEvent(tlw, timestamp, p, globalPos, buttons, Qt::NoButton, QEvent::None);
131}
132
133void QDirectFbInput::handleWheelEvent(const DFBEvent &event)
134{
135 QPoint p(event.window.x, event.window.y);
136 QPoint globalPos(event.window.cx, event.window.cy);
137 long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000);
138 QWindow *tlw = m_tlwMap.value(event.window.window_id);
139 QWindowSystemInterface::handleWheelEvent(tlw,
140 timestamp,
141 p,
142 globalPos,
143 QPoint(),
144 QPoint(0, event.window.step*120));
145}
146
147void QDirectFbInput::handleKeyEvents(const DFBEvent &event)
148{
149 QEvent::Type type = QDirectFbConvenience::eventType(event.window.type);
150 Qt::Key key = QDirectFbConvenience::keyMap()->value(event.window.key_symbol);
151 Qt::KeyboardModifiers modifiers = QDirectFbConvenience::keyboardModifiers(event.window.modifiers);
152
153 long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000);
154
155 QChar character;
156 if (DFB_KEY_TYPE(event.window.key_symbol) == DIKT_UNICODE)
157 character = QChar(event.window.key_symbol);
158 QWindow *tlw = m_tlwMap.value(event.window.window_id);
159 QWindowSystemInterface::handleKeyEvent(tlw, timestamp, type, key, modifiers, character);
160}
161
162void QDirectFbInput::handleEnterLeaveEvents(const DFBEvent &event)
163{
164 QWindow *tlw = m_tlwMap.value(event.window.window_id);
165 switch (event.window.type) {
166 case DWET_ENTER:
167 QWindowSystemInterface::handleEnterEvent(tlw);
168 break;
169 case DWET_LEAVE:
170 QWindowSystemInterface::handleLeaveEvent(tlw);
171 break;
172 default:
173 break;
174 }
175}
176
177void QDirectFbInput::handleGotFocusEvent(const DFBEvent &event)
178{
179 QWindow *tlw = m_tlwMap.value(event.window.window_id);
180 QWindowSystemInterface::handleFocusWindowChanged(tlw, Qt::ActiveWindowFocusReason);
181}
182
183void QDirectFbInput::handleCloseEvent(const DFBEvent &event)
184{
185 QWindow *tlw = m_tlwMap.value(event.window.window_id);
186 QWindowSystemInterface::handleCloseEvent(tlw);
187}
188
189void QDirectFbInput::handleGeometryEvent(const DFBEvent &event)
190{
191 QWindow *tlw = m_tlwMap.value(event.window.window_id);
192 QRect rect(event.window.x, event.window.y, event.window.w, event.window.h);
193 QWindowSystemInterface::handleGeometryChange(tlw, rect);
194}
195
196QT_END_NAMESPACE
static QDirectFbKeyMap * keyMap()
void removeWindow(IDirectFBWindow *window)
void run() override
void addWindow(IDirectFBWindow *window, QWindow *platformWindow)