Fix touchpads with evdevmouse
evdevmouse only worked properly with real mice, the ABS event handling was somewhat broken, it wasn't possible to properly move a mouse cursor with a touchpad due to unwanted jumps. The button handling is also corrected. Change-Id: Id04ef65d867a75bcfc54240d192a78224a4481d6 Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>bb10
parent
d0b4c7b159
commit
b6535f65e1
|
|
@ -91,7 +91,7 @@ QEvdevMouseHandler *QEvdevMouseHandler::create(const QString &device, const QStr
|
|||
|
||||
QEvdevMouseHandler::QEvdevMouseHandler(const QString &device, int fd, bool compression, int jitterLimit)
|
||||
: m_device(device), m_fd(fd), m_notify(0), m_x(0), m_y(0), m_prevx(0), m_prevy(0),
|
||||
m_compression(compression), m_buttons(0)
|
||||
m_compression(compression), m_buttons(0), m_prevInvalid(true)
|
||||
{
|
||||
setObjectName(QLatin1String("Evdev Mouse Handler"));
|
||||
|
||||
|
|
@ -111,7 +111,14 @@ QEvdevMouseHandler::~QEvdevMouseHandler()
|
|||
|
||||
void QEvdevMouseHandler::sendMouseEvent()
|
||||
{
|
||||
emit handleMouseEvent(m_x - m_prevx, m_y - m_prevy, m_buttons);
|
||||
int x = m_x - m_prevx;
|
||||
int y = m_y - m_prevy;
|
||||
if (m_prevInvalid) {
|
||||
x = y = 0;
|
||||
m_prevInvalid = false;
|
||||
}
|
||||
|
||||
emit handleMouseEvent(x, y, m_buttons);
|
||||
|
||||
m_prevx = m_x;
|
||||
m_prevy = m_y;
|
||||
|
|
@ -148,6 +155,7 @@ void QEvdevMouseHandler::readMouseData()
|
|||
struct ::input_event *data = &buffer[i];
|
||||
//qDebug() << ">>" << hex << data->type << data->code << dec << data->value;
|
||||
if (data->type == EV_ABS) {
|
||||
// Touchpads: store the absolute position for now, will calculate a relative one later.
|
||||
if (data->code == ABS_X && m_x != data->value) {
|
||||
m_x = data->value;
|
||||
posChanged = true;
|
||||
|
|
@ -176,8 +184,9 @@ void QEvdevMouseHandler::readMouseData()
|
|||
delta, Qt::Horizontal);
|
||||
}
|
||||
} else if (data->type == EV_KEY && data->code == BTN_TOUCH) {
|
||||
m_buttons = data->value ? Qt::LeftButton : Qt::NoButton;
|
||||
btnChanged = true;
|
||||
// We care about touchpads only, not touchscreens -> don't map to button press.
|
||||
// Need to invalidate prevx/y however to get proper relative pos.
|
||||
m_prevInvalid = true;
|
||||
} else if (data->type == EV_KEY && data->code >= BTN_LEFT && data->code <= BTN_JOYSTICK) {
|
||||
Qt::MouseButton button = Qt::NoButton;
|
||||
// BTN_LEFT == 0x110 in kernel's input.h
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ private:
|
|||
bool m_compression;
|
||||
Qt::MouseButtons m_buttons;
|
||||
int m_jitterLimitSquared;
|
||||
bool m_prevInvalid;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Generic plug-in for absolute & relative evdev pointer events.
|
||||
Generic plug-in for relative evdev pointer events.
|
||||
|
||||
To use it, launch apps with -plugin EvdevMouse
|
||||
|
||||
|
|
@ -9,3 +9,6 @@ EvdevMouse:/dev/input/eventN to explicitly set the device node.
|
|||
The initial cursor position is assumed to be (0, 0). Relative events
|
||||
will generate Qt mouse events with screen positions relative to this
|
||||
initial position.
|
||||
|
||||
Touchpads reporting absolute events will work too, the positions will
|
||||
be turned into relative. Touchscreens are however not supported.
|
||||
|
|
|
|||
Loading…
Reference in New Issue