Strange behavior for mousePressEvent
-
Hello,
I'm developing custom serial touchscreen-like driver around Linux evdev events. We have QT5 application on ARM mobile platform and I'm stuck with strange behavior inside QT events. The driver itself simulates an absolute mouse and, I'm confident, works fine on kernel level.
QT environment is configured like this :export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2
export QT_QPA_GENERIC_PLUGINS evdevmouse:abs:/dev/input/event2The driver sends (X Y) coordinates, button and button state in following format:
(X,Y, btn_number, btn_state).
So I'm sending (100,100, 1, 1) expecting mouse left button press in 100,100 location. And eventually (100,100, 1, 0) to release button. What I'm calling strange, inside the QT mousePressEvent() the first click is always shown as (0,0,1,1) when in reality I'm sending (100,100, 1, 1) . Then all following clicks will have an offset of (100,100). It looks like the first coordinates are setting up some kind of relative offset. So following this logic, I need to send (200,200,1,1) to have a click in (100,100, 1, 1). To make it work properly I have to always send the first click to (0,0, 1, 1) then magically everything works until the system reboot. There is no accumulation so it's not like QT is not set to ABS. It will be always the exact same offset using the first click coordinates as value.
So this is not on kernel driver level, I see the data on evtest /dev/input/event2 and the data is valid. It's just QT taking the first click coordinates as reference point!
Any advise where I should look to fix this?Thanks all!
-
Hello,
I'm developing custom serial touchscreen-like driver around Linux evdev events. We have QT5 application on ARM mobile platform and I'm stuck with strange behavior inside QT events. The driver itself simulates an absolute mouse and, I'm confident, works fine on kernel level.
QT environment is configured like this :export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2
export QT_QPA_GENERIC_PLUGINS evdevmouse:abs:/dev/input/event2The driver sends (X Y) coordinates, button and button state in following format:
(X,Y, btn_number, btn_state).
So I'm sending (100,100, 1, 1) expecting mouse left button press in 100,100 location. And eventually (100,100, 1, 0) to release button. What I'm calling strange, inside the QT mousePressEvent() the first click is always shown as (0,0,1,1) when in reality I'm sending (100,100, 1, 1) . Then all following clicks will have an offset of (100,100). It looks like the first coordinates are setting up some kind of relative offset. So following this logic, I need to send (200,200,1,1) to have a click in (100,100, 1, 1). To make it work properly I have to always send the first click to (0,0, 1, 1) then magically everything works until the system reboot. There is no accumulation so it's not like QT is not set to ABS. It will be always the exact same offset using the first click coordinates as value.
So this is not on kernel driver level, I see the data on evtest /dev/input/event2 and the data is valid. It's just QT taking the first click coordinates as reference point!
Any advise where I should look to fix this?Thanks all!
@lateDev said in Strange behavior for mousePressEvent:
What I'm calling strange, inside the QT mousePressEvent() the first click is always shown as (0,0,1,1)
Where are you calling what code for this
mousePressEvent()? For example,QWidget::mousePressEvent(QMouseEvent *event)hasevent->position()(as opposed toglobalPosition()) as relative to the widget. But maybe you know you have a situation/problem outside of this. -
@lateDev said in Strange behavior for mousePressEvent:
What I'm calling strange, inside the QT mousePressEvent() the first click is always shown as (0,0,1,1)
Where are you calling what code for this
mousePressEvent()? For example,QWidget::mousePressEvent(QMouseEvent *event)hasevent->position()(as opposed toglobalPosition()) as relative to the widget. But maybe you know you have a situation/problem outside of this.@JonB
There are different widgets but they all look like this:
void GridWidget::mousePressEvent(QMouseEvent *event)
{
lastPos = mapToGlobal(event->pos());
pressPos = mapToGlobal(event->pos());
printf("[GridWidget] mousePressEvent pos: %d, globalPos: %d, X: %d, Y: %d, globalX: %d, globalY: %d, button:%d\n",
event->pos(), event->globalPos(), event->x(), event->y(), event->globalX(), event->globalY(), event->button());
}
This printf always returns 0 for coordinates during the first press. Then starts returning (data - offset from the first press) for consecutive presses.By chance, do you know where data goes between:
input_report_abs(input_v_mouse, ABS_X, pos->xPos);
input_report_abs(input_v_mouse, ABS_Y, pos->yPos);
input_report_key(input_v_mouse, BTN_LEFT, button->status);
input_sync(input_v_mouse);in driver and
mousePressEvent() callback in QT?
Perhaps something happens is in this middle layer but I don't know where to look.
Thank you!
-
Hello,
I'm developing custom serial touchscreen-like driver around Linux evdev events. We have QT5 application on ARM mobile platform and I'm stuck with strange behavior inside QT events. The driver itself simulates an absolute mouse and, I'm confident, works fine on kernel level.
QT environment is configured like this :export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2
export QT_QPA_GENERIC_PLUGINS evdevmouse:abs:/dev/input/event2The driver sends (X Y) coordinates, button and button state in following format:
(X,Y, btn_number, btn_state).
So I'm sending (100,100, 1, 1) expecting mouse left button press in 100,100 location. And eventually (100,100, 1, 0) to release button. What I'm calling strange, inside the QT mousePressEvent() the first click is always shown as (0,0,1,1) when in reality I'm sending (100,100, 1, 1) . Then all following clicks will have an offset of (100,100). It looks like the first coordinates are setting up some kind of relative offset. So following this logic, I need to send (200,200,1,1) to have a click in (100,100, 1, 1). To make it work properly I have to always send the first click to (0,0, 1, 1) then magically everything works until the system reboot. There is no accumulation so it's not like QT is not set to ABS. It will be always the exact same offset using the first click coordinates as value.
So this is not on kernel driver level, I see the data on evtest /dev/input/event2 and the data is valid. It's just QT taking the first click coordinates as reference point!
Any advise where I should look to fix this?Thanks all!
My first step is usually to turn on all debugging output.
export QT_LOGGING_RULES=".=true"QT_DEBUG_PLUGINS=1 might help as well.
@lateDev said in Strange behavior for mousePressEvent:
export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2
export QT_QPA_GENERIC_PLUGINS evdevmouse:abs:/dev/input/event2If QT_QPA_EVDEV_MOUSE_PARAMETERS is not empty, the specification portion of the plugin passed via QT_QPA_GENERIC_PLUGINS is discarded. Either don't use QT_QPA_EVDEV_MOUSE_PARAMETERS, or use that to pass the full configuration, including
abs.QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent) : QObject(parent), m_x(0), m_y(0), m_xoffset(0), m_yoffset(0) { Q_UNUSED(key); QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_MOUSE_PARAMETERS")); if (spec.isEmpty()) spec = specification; auto parsed = QEvdevUtil::parseSpecification(spec); -
My first step is usually to turn on all debugging output.
export QT_LOGGING_RULES=".=true"QT_DEBUG_PLUGINS=1 might help as well.
@lateDev said in Strange behavior for mousePressEvent:
export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2
export QT_QPA_GENERIC_PLUGINS evdevmouse:abs:/dev/input/event2If QT_QPA_EVDEV_MOUSE_PARAMETERS is not empty, the specification portion of the plugin passed via QT_QPA_GENERIC_PLUGINS is discarded. Either don't use QT_QPA_EVDEV_MOUSE_PARAMETERS, or use that to pass the full configuration, including
abs.QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent) : QObject(parent), m_x(0), m_y(0), m_xoffset(0), m_yoffset(0) { Q_UNUSED(key); QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_MOUSE_PARAMETERS")); if (spec.isEmpty()) spec = specification; auto parsed = QEvdevUtil::parseSpecification(spec);@jeremy_k
Thank you for suggestions!
Putting all config in QT_QPA_EVDEV_MOUSE_PARAMETERS doesn't work, if I remove
QT_QPA_GENERIC_PLUGINS evdevmouse
QT stops receiving events.
So I'm stuck with :
export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2:abs
export QT_QPA_GENERIC_PLUGINS evdevmouse
which seems to translate driver events to QT.
I don't have qevdevmousemanager sources, only .h in my environment.
And my .h is quite different from the one in your link.
Yours is:class QEvdevMouseManager : public QObject { public: QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent = nullptr); ~QEvdevMouseManager(); void handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons, Qt::MouseButton button, QEvent::Type type); void handleWheelEvent(QPoint delta); void addMouse(const QString &deviceNode = QString()); void removeMouse(const QString &deviceNode); private: void clampPosition(); void updateDeviceCount(); QString m_spec; QtInputSupport::DeviceHandlerList<QEvdevMouseHandler> m_mice; int m_x; int m_y; int m_xoffset; int m_yoffset; };And this is mine:
class QEvdevMouseManager : public QObject { Q_OBJECT public: QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent = 0); ~QEvdevMouseManager(); QDeviceDiscovery *deviceDiscovery() { return m_deviceDiscovery; } public slots: void handleMouseEvent(int x, int y, Qt::MouseButtons buttons); void handleWheelEvent(int delta, Qt::Orientation orientation); private slots: void addMouse(const QString &deviceNode = QString()); void removeMouse(const QString &deviceNode); private: QString m_spec; QHash<QString,QEvdevMouseHandler*> m_mice; QDeviceDiscovery *m_deviceDiscovery; int m_x; int m_y; int m_xoffset; int m_yoffset; };My handleMouseEvent() doesn't have bool abs parameter which brings me to think that perhaps it's not made to work with absolute mouses. Is there any possibility to add this function to my environment? What would be the library to recompile?
I don't have sources but these are all QT libraries I have in my environment:
libfunnyutil.so
libfunnyutil.so.1
libfunnyutil.so.1.0
libfunnyutil.so.1.0.0
libQt5Concurrent.so
libQt5Concurrent.so.5
libQt5Concurrent.so.5.3
libQt5Concurrent.so.5.3.2
libQt5Core.so
libQt5Core.so.5
libQt5Core.so.5.3
libQt5Core.so.5.3.2
libQt5DBus.so
libQt5DBus.so.5
libQt5DBus.so.5.3
libQt5DBus.so.5.3.2
libQt5Gui.so
libQt5Gui.so.5
libQt5Gui.so.5.3
libQt5Gui.so.5.3.2
libQt5Multimedia.so
libQt5Multimedia.so.5
libQt5Multimedia.so.5.3
libQt5Multimedia.so.5.3.2
libQt5MultimediaWidgets.so
libQt5MultimediaWidgets.so.5
libQt5MultimediaWidgets.so.5.3
libQt5MultimediaWidgets.so.5.3.2
libQt5Network.so
libQt5Network.so.5
libQt5Network.so.5.3
libQt5Network.so.5.3.2
libQt5PrintSupport.so
libQt5PrintSupport.so.5
libQt5PrintSupport.so.5.3
libQt5PrintSupport.so.5.3.2
libQt5Sql.so
libQt5Sql.so.5
libQt5Sql.so.5.3
libQt5Sql.so.5.3.2
libQt5Widgets.so
libQt5Widgets.so.5
libQt5Widgets.so.5.3
libQt5Widgets.so.5.3.2
libQt5Xml.so
libQt5Xml.so.5
libQt5Xml.so.5.3
libQt5Xml.so.5.3.2 -
@jeremy_k
Thank you for suggestions!
Putting all config in QT_QPA_EVDEV_MOUSE_PARAMETERS doesn't work, if I remove
QT_QPA_GENERIC_PLUGINS evdevmouse
QT stops receiving events.
So I'm stuck with :
export QT_QPA_EVDEV_MOUSE_PARAMETERS /dev/input/event2:abs
export QT_QPA_GENERIC_PLUGINS evdevmouse
which seems to translate driver events to QT.
I don't have qevdevmousemanager sources, only .h in my environment.
And my .h is quite different from the one in your link.
Yours is:class QEvdevMouseManager : public QObject { public: QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent = nullptr); ~QEvdevMouseManager(); void handleMouseEvent(int x, int y, bool abs, Qt::MouseButtons buttons, Qt::MouseButton button, QEvent::Type type); void handleWheelEvent(QPoint delta); void addMouse(const QString &deviceNode = QString()); void removeMouse(const QString &deviceNode); private: void clampPosition(); void updateDeviceCount(); QString m_spec; QtInputSupport::DeviceHandlerList<QEvdevMouseHandler> m_mice; int m_x; int m_y; int m_xoffset; int m_yoffset; };And this is mine:
class QEvdevMouseManager : public QObject { Q_OBJECT public: QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent = 0); ~QEvdevMouseManager(); QDeviceDiscovery *deviceDiscovery() { return m_deviceDiscovery; } public slots: void handleMouseEvent(int x, int y, Qt::MouseButtons buttons); void handleWheelEvent(int delta, Qt::Orientation orientation); private slots: void addMouse(const QString &deviceNode = QString()); void removeMouse(const QString &deviceNode); private: QString m_spec; QHash<QString,QEvdevMouseHandler*> m_mice; QDeviceDiscovery *m_deviceDiscovery; int m_x; int m_y; int m_xoffset; int m_yoffset; };My handleMouseEvent() doesn't have bool abs parameter which brings me to think that perhaps it's not made to work with absolute mouses. Is there any possibility to add this function to my environment? What would be the library to recompile?
I don't have sources but these are all QT libraries I have in my environment:
libfunnyutil.so
libfunnyutil.so.1
libfunnyutil.so.1.0
libfunnyutil.so.1.0.0
libQt5Concurrent.so
libQt5Concurrent.so.5
libQt5Concurrent.so.5.3
libQt5Concurrent.so.5.3.2
libQt5Core.so
libQt5Core.so.5
libQt5Core.so.5.3
libQt5Core.so.5.3.2
libQt5DBus.so
libQt5DBus.so.5
libQt5DBus.so.5.3
libQt5DBus.so.5.3.2
libQt5Gui.so
libQt5Gui.so.5
libQt5Gui.so.5.3
libQt5Gui.so.5.3.2
libQt5Multimedia.so
libQt5Multimedia.so.5
libQt5Multimedia.so.5.3
libQt5Multimedia.so.5.3.2
libQt5MultimediaWidgets.so
libQt5MultimediaWidgets.so.5
libQt5MultimediaWidgets.so.5.3
libQt5MultimediaWidgets.so.5.3.2
libQt5Network.so
libQt5Network.so.5
libQt5Network.so.5.3
libQt5Network.so.5.3.2
libQt5PrintSupport.so
libQt5PrintSupport.so.5
libQt5PrintSupport.so.5.3
libQt5PrintSupport.so.5.3.2
libQt5Sql.so
libQt5Sql.so.5
libQt5Sql.so.5.3
libQt5Sql.so.5.3.2
libQt5Widgets.so
libQt5Widgets.so.5
libQt5Widgets.so.5.3
libQt5Widgets.so.5.3.2
libQt5Xml.so
libQt5Xml.so.5
libQt5Xml.so.5.3
libQt5Xml.so.5.3.2@lateDev said in Strange behavior for mousePressEvent:
I don't have qevdevmousemanager sources, only .h in my environment.
And my .h is quite different from the one in your link.The platform interface has a history of being more volatile. If the vendor is reasonably responsive, asking for a full copy might might save a lot of time.
My handleMouseEvent() doesn't have bool abs parameter which brings me to think that perhaps it's not made to work with absolute mouses. Is there any possibility to add this function to my environment? What would be the library to recompile?
I don't have sources but these are all QT libraries I have in my environment:The absolute coordinate change originates with commit 1d4a1be - https://codereview.qt-project.org/c/qt/qtbase/+/81593
That was merged in March of 2014. It looks like the change made it into Qt 5.4.0.libQt5Core.so.5.3.2
That concurs with my investigation. If you have any reasonable route to upgrade, it will save a lot of headaches.