Warning: That file was not part of the compilation database. It may have many parsing errors.

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 tools applications 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 "qvfbprotocol.h"
43#include "qvfbhdr.h"
44
45#include <QDebug>
46#include <QTimer>
47
48#include <sys/types.h>
49#include <sys/stat.h>
50#include <math.h>
51#include <fcntl.h>
52#include <stdlib.h>
53#include <stdio.h>
54
55#ifdef Q_OS_UNIX
56#include <unistd.h>
57#endif
58
59#include "qvfbshmem.h"
60
61QT_BEGIN_NAMESPACE
62
63QVFbViewProtocol::QVFbViewProtocol(int display_id, QObject *parent) :
64 QObject(parent), mDisplayId(display_id) { }
65
66QVFbViewProtocol::~QVFbViewProtocol() {}
67
68void QVFbViewProtocol::flushChanges() {}
69
70void QVFbViewProtocol::sendKeyboardData(QString unicode, int keycode,
71 int modifiers, bool press, bool repeat)
72{
73 if (keyHandler())
74 keyHandler()->sendKeyboardData(unicode, keycode, modifiers, press, repeat);
75}
76
77void QVFbViewProtocol::sendMouseData(const QPoint &pos, int buttons, int wheel)
78{
79 if (mouseHandler())
80 mouseHandler()->sendMouseData(pos, buttons, wheel);
81}
82
83static int openPipe(const char *fileName)
84{
85 unlink(fileName);
86
87 mkfifo(fileName, 0666);
88 int fd = ::open(fileName, O_RDWR | O_NDELAY);
89 return fd;
90}
91
92QVFbKeyPipeProtocol::QVFbKeyPipeProtocol(int display_id)
93 : QVFbKeyProtocol(display_id)
94{
95 fileName = QT_VFB_KEYBOARD_PIPE(display_id);
96 fd = openPipe(fileName.toLocal8Bit().constData());
97
98 if (fd == -1)
99 qFatal("Cannot open keyboard pipe %s", fileName.toLocal8Bit().data());
100}
101
102QVFbKeyPipeProtocol::~QVFbKeyPipeProtocol()
103{
104 sendKeyboardData(0, 0, 0, true, false); // magic die key
105 ::close(fd);
106 unlink(fileName.toLocal8Bit().constData());
107}
108
109void QVFbKeyPipeProtocol::sendKeyboardData(QString unicode, int keycode,
110 int modifiers, bool press, bool repeat)
111{
112 QVFbKeyData kd;
113 kd.unicode = unicode[0].unicode();
114 kd.keycode = keycode;
115 kd.modifiers = static_cast<Qt::KeyboardModifier>(modifiers);
116 kd.press = press;
117 kd.repeat = repeat;
118 write(fd, &kd, sizeof(QVFbKeyData));
119}
120
121QVFbMousePipe::QVFbMousePipe(int display_id)
122 : QVFbMouseProtocol(display_id)
123{
124 fileName = QT_VFB_MOUSE_PIPE(display_id);
125 fd = openPipe(fileName.toLocal8Bit().constData());
126
127 if (fd == -1)
128 qFatal("Cannot open mouse pipe %s", fileName.toLocal8Bit().data());
129}
130
131QVFbMousePipe::~QVFbMousePipe()
132{
133 ::close(fd);
134 unlink(fileName.toLocal8Bit().constData());
135}
136
137
138void QVFbMousePipe::sendMouseData(const QPoint &pos, int buttons, int wheel)
139{
140 write(fd, &pos, sizeof(QPoint));
141 write(fd, &buttons, sizeof(int));
142 write(fd, &wheel, sizeof(int));
143}
144
145QVFbMouseLinuxTP::QVFbMouseLinuxTP(int display_id)
146 : QObject(), QVFbMousePipe(display_id), lastPos(-1,-1)
147{
148 /* the timer is needed because a real touch screen send data as long as
149 there is pressure. And the linux tp driver will filter, requiring
150 a minimum of 5 samples before it even registers a press.
151 */
152 repeater = new QTimer(this);
153 connect(repeater, SIGNAL(timeout()), this, SLOT(repeatLastPress()));
154}
155
156QVFbMouseLinuxTP::~QVFbMouseLinuxTP()
157{
158}
159
160
161void QVFbMouseLinuxTP::sendMouseData(const QPoint &pos, int buttons, int)
162{
163 if (buttons & Qt::LeftButton) {
164 // press
165 repeater->start(5);
166 writeToPipe(pos, 1);
167 lastPos = pos;
168 } else {
169 // release
170 if (lastPos == QPoint(-1,-1))
171 return; /* only send one release */
172 repeater->stop();
173 writeToPipe(pos, 0);
174 lastPos = QPoint(-1,-1);
175 }
176}
177
178void QVFbMouseLinuxTP::writeToPipe(const QPoint &pos, ushort pressure)
179{
180 ushort v;
181 write(fd, &pressure, sizeof(ushort));
182 v = pos.x();
183 write(fd, &v, sizeof(ushort));
184 v = pos.y();
185 write(fd, &v, sizeof(ushort));
186 v = 1; // pad
187 write(fd, &v, sizeof(ushort));
188}
189
190void QVFbMouseLinuxTP::repeatLastPress()
191{
192 writeToPipe(lastPos, 1);
193}
194
195QT_END_NAMESPACE
196

Warning: That file was not part of the compilation database. It may have many parsing errors.