client: Make use of floating QWindow::mapToGlobal

Wayland input is always surface-local, which we map to a faux global
position for Qt usages. Precision of non-integer co-ordinates were
either lost or handled in a more complicated way that needed.

Change-Id: Ia8101d4903caec42f1087a7b4adeff3a9a097a12
Reviewed-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>
This commit is contained in:
David Edmundson 2023-12-26 22:43:11 +00:00
parent 62f4289cde
commit d335a332f8
3 changed files with 9 additions and 17 deletions

View File

@ -653,7 +653,7 @@ void QWaylandInputDevice::Pointer::pointer_enter(uint32_t serial, struct wl_surf
connect(mFocus.data(), &QObject::destroyed, this, &Pointer::handleFocusDestroyed);
mSurfacePos = QPointF(wl_fixed_to_double(sx), wl_fixed_to_double(sy));
mGlobalPos = window->mapToGlobal(mSurfacePos.toPoint());
mGlobalPos = window->mapToGlobalF(mSurfacePos);
mParent->mSerial = serial;
mEnterSerial = serial;
@ -718,9 +718,7 @@ void QWaylandInputDevice::Pointer::pointer_motion(uint32_t time, wl_fixed_t surf
}
QPointF pos(wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y));
QPointF delta = pos - pos.toPoint();
QPointF global = window->mapToGlobal(pos.toPoint());
global += delta;
QPointF global = window->mapToGlobalF(pos);
mSurfacePos = pos;
mGlobalPos = global;
@ -731,7 +729,7 @@ void QWaylandInputDevice::Pointer::pointer_motion(uint32_t time, wl_fixed_t surf
// We can't know the true position since we're getting events for another surface,
// so we just set it outside of the window boundaries.
pos = QPointF(-1, -1);
global = grab->mapToGlobal(pos.toPoint());
global = grab->mapToGlobalF(pos);
window = grab;
}
setFrameEvent(new MotionEvent(window, time, pos, global, mButtons, mParent->modifiers()));
@ -813,7 +811,7 @@ void QWaylandInputDevice::Pointer::pointer_button(uint32_t serial, uint32_t time
QPointF global = mGlobalPos;
if (grab && grab != focusWindow()) {
pos = QPointF(-1, -1);
global = grab->mapToGlobal(pos.toPoint());
global = grab->mapToGlobalF(pos);
window = grab;
}
@ -1480,11 +1478,8 @@ void QWaylandInputDevice::handleTouchPoint(int id, QEventPoint::State state, con
return;
tp.area = QRectF(0, 0, 8, 8);
QPointF localPosition = win->mapFromWlSurface(surfacePosition);
// TODO: This doesn't account for high dpi scaling for the delta, but at least it matches
// what we have for mouse input.
QPointF delta = localPosition - localPosition.toPoint();
QPointF globalPosition = win->mapToGlobal(localPosition.toPoint()) + delta;
const QPointF localPosition = win->mapFromWlSurface(surfacePosition);
const QPointF globalPosition = win->mapToGlobalF(localPosition);
tp.area.moveCenter(globalPosition);
}

View File

@ -547,9 +547,7 @@ void QWaylandTabletToolV2::zwp_tablet_tool_v2_frame(uint32_t time)
ulong timestamp = time;
const QPointF localPosition = waylandWindow->mapFromWlSurface(m_pending.surfacePosition);
QPointF delta = localPosition - localPosition.toPoint();
QPointF globalPosition = window->mapToGlobal(localPosition.toPoint());
globalPosition += delta;
const QPointF globalPosition = waylandWindow->mapToGlobalF(localPosition);
Qt::MouseButtons buttons = m_pending.down ? Qt::MouseButton::LeftButton : Qt::MouseButton::NoButton;
buttons |= m_pending.buttons;
@ -564,7 +562,7 @@ void QWaylandTabletToolV2::zwp_tablet_tool_v2_frame(uint32_t time)
// but we need surface coordinates to include the decoration
bool decorationHandledEvent = waylandWindow->handleTabletEventDecoration(
m_tabletSeat->seat(), m_pending.surfacePosition,
window->mapToGlobal(m_pending.surfacePosition) + delta, buttons,
window->mapToGlobal(m_pending.surfacePosition), buttons,
m_tabletSeat->seat()->modifiers());
if (!decorationHandledEvent) {

View File

@ -83,8 +83,7 @@ void QWaylandTouchExtension::touch_extension_touch(uint32_t time,
tp.area = QRectF(0, 0, fromFixed(width), fromFixed(height));
// Got surface-relative coords but need a (virtual) screen position.
QPointF relPos = QPointF(fromFixed(x), fromFixed(y));
QPointF delta = relPos - relPos.toPoint();
tp.area.moveCenter(mTargetWindow->mapToGlobal(relPos.toPoint()) + delta);
tp.area.moveCenter(mTargetWindow->mapToGlobal(relPos));
tp.normalPosition.setX(fromFixed(normalized_x));
tp.normalPosition.setY(fromFixed(normalized_y));