Qt 4.8
qdirectfbinput.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qdirectfbinput.h"
43 #include "qdirectfbconvenience.h"
44 
45 #include <QThread>
46 #include <QDebug>
47 #include <QWindowSystemInterface>
48 #include <QMouseEvent>
49 #include <QEvent>
50 
51 #include <directfb.h>
52 
54 
55 QDirectFbInput::QDirectFbInput(IDirectFB *dfb, IDirectFBDisplayLayer *dfbLayer)
56  : m_dfbInterface(dfb)
57  , m_dfbDisplayLayer(dfbLayer)
58  , m_shouldStop(false)
59 {
60  DFBResult ok = m_dfbInterface->CreateEventBuffer(m_dfbInterface, m_eventBuffer.outPtr());
61  if (ok != DFB_OK)
62  DirectFBError("Failed to initialise eventbuffer", ok);
63 }
64 
66 {
67  while (!m_shouldStop) {
68  if (m_eventBuffer->WaitForEvent(m_eventBuffer.data()) == DFB_OK)
69  handleEvents();
70  }
71 }
72 
74 {
75  m_shouldStop = true;
76  m_eventBuffer->WakeUp(m_eventBuffer.data());
77 }
78 
79 void QDirectFbInput::addWindow(IDirectFBWindow *window, QWidget *platformWindow)
80 {
81  DFBResult res;
82  DFBWindowID id;
83 
84  res = window->GetID(window, &id);
85  if (res != DFB_OK) {
86  DirectFBError("QDirectFbInput::addWindow", res);
87  return;
88  }
89 
90  m_tlwMap.insert(id, platformWindow);
91  window->AttachEventBuffer(window, m_eventBuffer.data());
92 }
93 
94 void QDirectFbInput::removeWindow(IDirectFBWindow *window)
95 {
96  DFBResult res;
97  DFBWindowID id;
98 
99  res = window->GetID(window, &id);
100  if (res != DFB_OK) {
101  DirectFBError("QDirectFbInput::removeWindow", res);
102  return;
103  }
104 
105  window->DetachEventBuffer(window, m_eventBuffer.data());
106  m_tlwMap.remove(id);
107 }
108 
110 {
111  DFBResult hasEvent = m_eventBuffer->HasEvent(m_eventBuffer.data());
112  while(hasEvent == DFB_OK){
113  DFBEvent event;
114  DFBResult ok = m_eventBuffer->GetEvent(m_eventBuffer.data(), &event);
115  if (ok != DFB_OK)
116  DirectFBError("Failed to get event",ok);
117  if (event.clazz == DFEC_WINDOW) {
118  switch (event.window.type) {
119  case DWET_BUTTONDOWN:
120  case DWET_BUTTONUP:
121  case DWET_MOTION:
122  handleMouseEvents(event);
123  break;
124  case DWET_WHEEL:
125  handleWheelEvent(event);
126  break;
127  case DWET_KEYDOWN:
128  case DWET_KEYUP:
129  handleKeyEvents(event);
130  break;
131  case DWET_ENTER:
132  case DWET_LEAVE:
133  handleEnterLeaveEvents(event);
134  default:
135  break;
136  }
137 
138  }
139 
140  hasEvent = m_eventBuffer->HasEvent(m_eventBuffer.data());
141  }
142 }
143 
145 {
146  QPoint p(event.window.x, event.window.y);
147  QPoint globalPos = globalPoint(event);
148  Qt::MouseButtons buttons = QDirectFbConvenience::mouseButtons(event.window.buttons);
149 
152  layer->GetWindow(layer.data(), event.window.window_id, window.outPtr());
153 
154  long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000);
155 
156  QWidget *tlw = m_tlwMap.value(event.window.window_id);
157  QWindowSystemInterface::handleMouseEvent(tlw, timestamp, p, globalPos, buttons);
158 }
159 
161 {
162  QPoint p(event.window.cx, event.window.cy);
163  QPoint globalPos = globalPoint(event);
164  long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000);
165  QWidget *tlw = m_tlwMap.value(event.window.window_id);
166  QWindowSystemInterface::handleWheelEvent(tlw, timestamp, p, globalPos,
167  event.window.step*120,
168  Qt::Vertical);
169 }
170 
172 {
174  Qt::Key key = QDirectFbConvenience::keyMap()->value(event.window.key_symbol);
175  Qt::KeyboardModifiers modifiers = QDirectFbConvenience::keyboardModifiers(event.window.modifiers);
176 
177  long timestamp = (event.window.timestamp.tv_sec*1000) + (event.window.timestamp.tv_usec/1000);
178 
179  QChar character;
180  if (DFB_KEY_TYPE(event.window.key_symbol) == DIKT_UNICODE)
181  character = QChar(event.window.key_symbol);
182  QWidget *tlw = m_tlwMap.value(event.window.window_id);
183  QWindowSystemInterface::handleKeyEvent(tlw, timestamp, type, key, modifiers, character);
184 }
185 
187 {
188  QWidget *tlw = m_tlwMap.value(event.window.window_id);
189  switch (event.window.type) {
190  case DWET_ENTER:
192  break;
193  case DWET_LEAVE:
195  break;
196  default:
197  break;
198  }
199 }
200 
201 inline QPoint QDirectFbInput::globalPoint(const DFBEvent &event) const
202 {
204  m_dfbDisplayLayer->GetWindow(m_dfbDisplayLayer, event.window.window_id, window.outPtr());
205  int x,y;
206  window->GetPosition(window.data(), &x, &y);
207  return QPoint(event.window.cx +x, event.window.cy + y);
208 }
209 
QDirectFbInput(IDirectFB *dfb, IDirectFBDisplayLayer *dfbLayer)
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static IDirectFBDisplayLayer * dfbDisplayLayer(int display=DLID_PRIMARY)
QPoint globalPoint(const DFBEvent &event) const
void handleEnterLeaveEvents(const DFBEvent &event)
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
QDirectFBPointer< IDirectFBEventBuffer > m_eventBuffer
T * data() const
Returns the value of the pointer referenced by this object.
static void handleWheelEvent(QWidget *w, const QPoint &local, const QPoint &global, int d, Qt::Orientation o)
static QDirectFbKeyMap * keyMap()
static Qt::MouseButtons buttons
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static void handleKeyEvent(QWidget *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
void handleKeyEvents(const DFBEvent &event)
static QEvent::Type eventType(DFBWindowEventType type)
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void stopInputEventLoop()
static Qt::KeyboardModifiers keyboardModifiers(DFBInputDeviceModifierMask mask)
NSWindow * window
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
IDirectFB * m_dfbInterface
static void handleMouseEvent(QWidget *w, const QPoint &local, const QPoint &global, Qt::MouseButtons b)
tlw == 0 means that ev is in global coords only
void addWindow(IDirectFBWindow *window, QWidget *platformWindow)
void run()
The starting point for the thread.
void handleWheelEvent(const DFBEvent &event)
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
int key
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void handleMouseEvents(const DFBEvent &event)
IDirectFBDisplayLayer * m_dfbDisplayLayer
QHash< DFBWindowID, QWidget * > m_tlwMap
static void handleEnterEvent(QWidget *w)
static Qt::MouseButtons mouseButtons(DFBInputDeviceButtonMask mask)
static void handleLeaveEvent(QWidget *w)
void removeWindow(IDirectFBWindow *window)