summaryrefslogtreecommitdiffstats
path: root/src/plugins/generic
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2012-04-16 17:36:03 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-16 17:49:55 +0200
commit1afff0e5fae90eaa6d7d95055d56969a29f068af (patch)
treec8d7493cb36854c50efb8dc3660944b034a611d7 /src/plugins/generic
parent44be58226e2fae82c9e8b9b21ccbd53e396c333e (diff)
Made the evdev mouse plugin clamp coordinates to screen.
Useful when we get relative events, as otherwise the mouse might end up far outside the screen boundaries. Change-Id: I8e3884ab2acb03eaa6afce8926f503dbd03b0c5d Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
Diffstat (limited to 'src/plugins/generic')
-rw-r--r--src/plugins/generic/evdevmouse/qevdevmousehandler.cpp24
-rw-r--r--src/plugins/generic/evdevmouse/qevdevmousehandler.h3
2 files changed, 23 insertions, 4 deletions
diff --git a/src/plugins/generic/evdevmouse/qevdevmousehandler.cpp b/src/plugins/generic/evdevmouse/qevdevmousehandler.cpp
index 5e2911a806..6edd470874 100644
--- a/src/plugins/generic/evdevmouse/qevdevmousehandler.cpp
+++ b/src/plugins/generic/evdevmouse/qevdevmousehandler.cpp
@@ -44,6 +44,8 @@
#include <QSocketNotifier>
#include <QStringList>
#include <QPoint>
+#include <QGuiApplication>
+#include <QScreen>
#include <QWindowSystemInterface>
#include <qplatformdefs.h>
@@ -70,6 +72,7 @@ QEvdevMouseHandler *QEvdevMouseHandler::createLinuxInputMouseHandler(const QStri
QString device = "/dev/input/event0";
bool compression = true;
+ bool clamp = true;
bool smooth = false;
int jitterLimit = 0;
int xoffset = 0;
@@ -79,6 +82,8 @@ QEvdevMouseHandler *QEvdevMouseHandler::createLinuxInputMouseHandler(const QStri
foreach (const QString &arg, args) {
if (arg == "nocompress")
compression = false;
+ else if (arg == "noclamp")
+ clamp = false;
else if (arg.startsWith("dejitter="))
jitterLimit = arg.mid(9).toInt();
else if (arg.startsWith("xoffset="))
@@ -96,16 +101,16 @@ QEvdevMouseHandler *QEvdevMouseHandler::createLinuxInputMouseHandler(const QStri
int fd;
fd = qt_safe_open(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0);
if (fd >= 0) {
- return new QEvdevMouseHandler(fd, compression, smooth, jitterLimit, xoffset, yoffset);
+ return new QEvdevMouseHandler(fd, compression, clamp, smooth, jitterLimit, xoffset, yoffset);
} else {
qWarning("Cannot open mouse input device '%s': %s", qPrintable(device), strerror(errno));
return 0;
}
}
-QEvdevMouseHandler::QEvdevMouseHandler(int deviceDescriptor, bool compression, bool smooth, int jitterLimit, int xoffset, int yoffset)
+QEvdevMouseHandler::QEvdevMouseHandler(int deviceDescriptor, bool compression, bool clamp, bool smooth, int jitterLimit, int xoffset, int yoffset)
: m_notify(0), m_x(0), m_y(0), m_prevx(0), m_prevy(0),
- m_fd(deviceDescriptor), m_compression(compression), m_smooth(smooth),
+ m_fd(deviceDescriptor), m_compression(compression), m_clamp(clamp), m_smooth(smooth),
m_xoffset(xoffset), m_yoffset(yoffset), m_buttons(0)
{
setObjectName(QLatin1String("Evdev Mouse Handler"));
@@ -126,6 +131,19 @@ QEvdevMouseHandler::~QEvdevMouseHandler()
void QEvdevMouseHandler::sendMouseEvent()
{
+ if (m_clamp) {
+ QRect g = QGuiApplication::primaryScreen()->virtualGeometry();
+ if (m_x + m_xoffset < g.left())
+ m_x = g.left() - m_xoffset;
+ else if (m_x + m_xoffset > g.right())
+ m_x = g.right() - m_xoffset;
+
+ if (m_y + m_yoffset < g.top())
+ m_y = g.top() - m_yoffset;
+ else if (m_y + m_yoffset > g.bottom())
+ m_y = g.bottom() - m_yoffset;
+ }
+
QPoint pos(m_x + m_xoffset, m_y + m_yoffset);
#ifdef QT_QPA_MOUSE_HANDLER_DEBUG
diff --git a/src/plugins/generic/evdevmouse/qevdevmousehandler.h b/src/plugins/generic/evdevmouse/qevdevmousehandler.h
index 7a74eaa701..fc65c6a414 100644
--- a/src/plugins/generic/evdevmouse/qevdevmousehandler.h
+++ b/src/plugins/generic/evdevmouse/qevdevmousehandler.h
@@ -62,7 +62,7 @@ private slots:
void readMouseData();
private:
- QEvdevMouseHandler(int deviceDescriptor, bool compression, bool smooth, int jitterLimit, int xoffset, int yoffset);
+ QEvdevMouseHandler(int deviceDescriptor, bool compression, bool clamp, bool smooth, int jitterLimit, int xoffset, int yoffset);
void sendMouseEvent();
@@ -71,6 +71,7 @@ private:
int m_prevx, m_prevy;
int m_fd;
bool m_compression;
+ bool m_clamp;
bool m_smooth;
int m_xoffset, m_yoffset;
Qt::MouseButtons m_buttons;