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$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
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 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "qvfbprotocol.h"
48 #include <sys/types.h>
59 #include "qvfbshmem.h"
63 QVFbViewProtocol::QVFbViewProtocol(int display_id
, QObject
*parent
) :
64 QObject(parent
), mDisplayId(display_id
) { }
66 QVFbViewProtocol::~QVFbViewProtocol() {}
68 void QVFbViewProtocol::flushChanges() {}
70 void QVFbViewProtocol::sendKeyboardData(QString unicode
, int keycode
,
71 int modifiers
, bool press
, bool repeat
)
74 keyHandler()->sendKeyboardData(unicode
, keycode
, modifiers
, press
, repeat
);
77 void QVFbViewProtocol::sendMouseData(const QPoint
&pos
, int buttons
, int wheel
)
80 mouseHandler()->sendMouseData(pos
, buttons
, wheel
);
83 static int openPipe(const char *fileName
)
87 mkfifo(fileName
, 0666);
88 int fd
= ::open(fileName
, O_RDWR
| O_NDELAY
);
92 QVFbKeyPipeProtocol::QVFbKeyPipeProtocol(int display_id
)
93 : QVFbKeyProtocol(display_id
)
95 fileName
= QT_VFB_KEYBOARD_PIPE(display_id
);
96 fd
= openPipe(fileName
.toLocal8Bit().constData());
99 qFatal("Cannot open keyboard pipe %s", fileName
.toLocal8Bit().data());
102 QVFbKeyPipeProtocol::~QVFbKeyPipeProtocol()
104 sendKeyboardData(0, 0, 0, true, false); // magic die key
106 unlink(fileName
.toLocal8Bit().constData());
109 void QVFbKeyPipeProtocol::sendKeyboardData(QString unicode
, int keycode
,
110 int modifiers
, bool press
, bool repeat
)
113 kd
.unicode
= unicode
[0].unicode();
114 kd
.keycode
= keycode
;
115 kd
.modifiers
= static_cast<Qt::KeyboardModifier
>(modifiers
);
118 write(fd
, &kd
, sizeof(QVFbKeyData
));
121 QVFbMousePipe::QVFbMousePipe(int display_id
)
122 : QVFbMouseProtocol(display_id
)
124 fileName
= QT_VFB_MOUSE_PIPE(display_id
);
125 fd
= openPipe(fileName
.toLocal8Bit().constData());
128 qFatal("Cannot open mouse pipe %s", fileName
.toLocal8Bit().data());
131 QVFbMousePipe::~QVFbMousePipe()
134 unlink(fileName
.toLocal8Bit().constData());
138 void QVFbMousePipe::sendMouseData(const QPoint
&pos
, int buttons
, int wheel
)
140 write(fd
, &pos
, sizeof(QPoint
));
141 write(fd
, &buttons
, sizeof(int));
142 write(fd
, &wheel
, sizeof(int));
145 QVFbMouseLinuxTP::QVFbMouseLinuxTP(int display_id
)
146 : QObject(), QVFbMousePipe(display_id
), lastPos(-1,-1)
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.
152 repeater
= new QTimer(this);
153 connect(repeater
, SIGNAL(timeout()), this, SLOT(repeatLastPress()));
156 QVFbMouseLinuxTP::~QVFbMouseLinuxTP()
161 void QVFbMouseLinuxTP::sendMouseData(const QPoint
&pos
, int buttons
, int)
163 if (buttons
& Qt::LeftButton
) {
170 if (lastPos
== QPoint(-1,-1))
171 return; /* only send one release */
174 lastPos
= QPoint(-1,-1);
178 void QVFbMouseLinuxTP::writeToPipe(const QPoint
&pos
, ushort pressure
)
181 write(fd
, &pressure
, sizeof(ushort
));
183 write(fd
, &v
, sizeof(ushort
));
185 write(fd
, &v
, sizeof(ushort
));
187 write(fd
, &v
, sizeof(ushort
));
190 void QVFbMouseLinuxTP::repeatLastPress()
192 writeToPipe(lastPos
, 1);