1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the tools applications of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
36 ** If you have questions regarding the use of this file, please contact
37 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "qvfbprotocol.h"
48 #include <sys/types.h>
61 QVFbViewProtocol::QVFbViewProtocol(int display_id
, QObject
*parent
) :
62 QObject(parent
), mDisplayId(display_id
) { }
64 QVFbViewProtocol::~QVFbViewProtocol() {}
66 void QVFbViewProtocol::flushChanges() {}
68 void QVFbViewProtocol::sendKeyboardData(QString unicode
, int keycode
,
69 int modifiers
, bool press
, bool repeat
)
72 keyHandler()->sendKeyboardData(unicode
, keycode
, modifiers
, press
, repeat
);
75 void QVFbViewProtocol::sendMouseData(const QPoint
&pos
, int buttons
, int wheel
)
78 mouseHandler()->sendMouseData(pos
, buttons
, wheel
);
81 static int openPipe(const char *fileName
)
85 mkfifo(fileName
, 0666);
86 int fd
= ::open(fileName
, O_RDWR
| O_NDELAY
);
90 QVFbKeyPipeProtocol::QVFbKeyPipeProtocol(int display_id
)
91 : QVFbKeyProtocol(display_id
)
93 fileName
= QString(QT_VFB_KEYBOARD_PIPE
).arg(display_id
);
94 fd
= openPipe(fileName
.toLocal8Bit().constData());
97 qFatal("Cannot open keyboard pipe %s", fileName
.toLocal8Bit().data());
100 QVFbKeyPipeProtocol::~QVFbKeyPipeProtocol()
102 sendKeyboardData(0, 0, 0, true, false); // magic die key
104 unlink(fileName
.toLocal8Bit().constData());
107 void QVFbKeyPipeProtocol::sendKeyboardData(QString unicode
, int keycode
,
108 int modifiers
, bool press
, bool repeat
)
111 kd
.unicode
= unicode
[0].unicode();
112 kd
.keycode
= keycode
;
113 kd
.modifiers
= static_cast<Qt::KeyboardModifier
>(modifiers
);
116 write(fd
, &kd
, sizeof(QVFbKeyData
));
119 QVFbMousePipe::QVFbMousePipe(int display_id
)
120 : QVFbMouseProtocol(display_id
)
122 fileName
= QString(QT_VFB_MOUSE_PIPE
).arg(display_id
);
123 fd
= openPipe(fileName
.toLocal8Bit().constData());
126 qFatal("Cannot open mouse pipe %s", fileName
.toLocal8Bit().data());
129 QVFbMousePipe::~QVFbMousePipe()
132 unlink(fileName
.toLocal8Bit().constData());
136 void QVFbMousePipe::sendMouseData(const QPoint
&pos
, int buttons
, int wheel
)
138 write(fd
, &pos
, sizeof(QPoint
));
139 write(fd
, &buttons
, sizeof(int));
140 write(fd
, &wheel
, sizeof(int));
143 QVFbMouseLinuxTP::QVFbMouseLinuxTP(int display_id
)
144 : QObject(), QVFbMousePipe(display_id
), lastPos(-1,-1)
146 /* the timer is needed because a real touch screen send data as long as
147 there is pressure. And the linux tp driver will filter, requiring
148 a minimum of 5 samples before it even registers a press.
150 repeater
= new QTimer(this);
151 connect(repeater
, SIGNAL(timeout()), this, SLOT(repeatLastPress()));
154 QVFbMouseLinuxTP::~QVFbMouseLinuxTP()
159 void QVFbMouseLinuxTP::sendMouseData(const QPoint
&pos
, int buttons
, int)
161 if (buttons
& Qt::LeftButton
) {
168 if (lastPos
== QPoint(-1,-1))
169 return; /* only send one release */
172 lastPos
= QPoint(-1,-1);
176 void QVFbMouseLinuxTP::writeToPipe(const QPoint
&pos
, ushort pressure
)
179 write(fd
, &pressure
, sizeof(ushort
));
181 write(fd
, &v
, sizeof(ushort
));
183 write(fd
, &v
, sizeof(ushort
));
185 write(fd
, &v
, sizeof(ushort
));
188 void QVFbMouseLinuxTP::repeatLastPress()
190 writeToPipe(lastPos
, 1);