Reload lastScrollPosition on window enter

We need the lastScrollPosition position to calculated scrolling deltas
on scroll events. Since the position is tied to the device and might
have changed while scroll events were send to other applications we need
to reload the value when mouse focus reenters our application.

Task-number: QTBUG-38274
Change-Id: Ic166648f8e7ae486288cbed339a057e3faa1ef2d
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
Allan Sandfeld Jensen 2014-04-11 12:09:59 +02:00 committed by The Qt Project
parent 387f75c39b
commit fb7da5cc8c
3 changed files with 36 additions and 0 deletions

View File

@ -454,6 +454,10 @@ public:
QXcbSystemTrayTracker *systemTrayTracker(); QXcbSystemTrayTracker *systemTrayTracker();
#ifdef XCB_USE_XINPUT2
void handleEnterEvent(const xcb_enter_notify_event_t *);
#endif
private slots: private slots:
void processXcbEvents(); void processXcbEvents();

View File

@ -524,6 +524,35 @@ void QXcbConnection::xi2HandleEvent(xcb_ge_event_t *event)
} }
} }
void QXcbConnection::handleEnterEvent(const xcb_enter_notify_event_t *)
{
#ifdef XCB_USE_XINPUT21
QHash<int, ScrollingDevice>::iterator it = m_scrollingDevices.begin();
const QHash<int, ScrollingDevice>::iterator end = m_scrollingDevices.end();
while (it != end) {
ScrollingDevice& scrollingDevice = it.value();
int nrDevices = 0;
XIDeviceInfo* xiDeviceInfo = XIQueryDevice(static_cast<Display *>(m_xlib_display), scrollingDevice.deviceId, &nrDevices);
if (nrDevices <= 0) {
it = m_scrollingDevices.erase(it);
continue;
}
for (int c = 0; c < xiDeviceInfo->num_classes; ++c) {
if (xiDeviceInfo->classes[c]->type == XIValuatorClass) {
XIValuatorClassInfo *vci = reinterpret_cast<XIValuatorClassInfo *>(xiDeviceInfo->classes[c]);
const int valuatorAtom = qatom(vci->label);
if (valuatorAtom == QXcbAtom::RelHorizScroll || valuatorAtom == QXcbAtom::RelHorizWheel)
scrollingDevice.lastScrollPosition.setX(vci->value);
else if (valuatorAtom == QXcbAtom::RelVertScroll || valuatorAtom == QXcbAtom::RelVertWheel)
scrollingDevice.lastScrollPosition.setY(vci->value);
}
}
XIFreeDeviceInfo(xiDeviceInfo);
++it;
}
#endif
}
void QXcbConnection::xi2HandleScrollEvent(void *event, ScrollingDevice &scrollingDevice) void QXcbConnection::xi2HandleScrollEvent(void *event, ScrollingDevice &scrollingDevice)
{ {
#ifdef XCB_USE_XINPUT21 #ifdef XCB_USE_XINPUT21

View File

@ -1778,6 +1778,9 @@ public:
void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *event) void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *event)
{ {
connection()->setTime(event->time); connection()->setTime(event->time);
#ifdef XCB_USE_XINPUT2
connection()->handleEnterEvent(event);
#endif
if ((event->mode != XCB_NOTIFY_MODE_NORMAL && event->mode != XCB_NOTIFY_MODE_UNGRAB) if ((event->mode != XCB_NOTIFY_MODE_NORMAL && event->mode != XCB_NOTIFY_MODE_UNGRAB)
|| event->detail == XCB_NOTIFY_DETAIL_VIRTUAL || event->detail == XCB_NOTIFY_DETAIL_VIRTUAL