Introduce geometry conversion helpers

The new helpers are designed for the purpose of mapping points from the
global screen coordinates to the frame-local and the surface-local coords
This commit is contained in:
Vlad Zahorodnii 2020-10-17 15:40:51 +03:00
parent 7eccfdc528
commit ba4f6b35ae
3 changed files with 29 additions and 2 deletions

View file

@ -1714,7 +1714,7 @@ public:
switch (event->type()) {
case QEvent::TabletMove: {
const auto pos = event->globalPosF() - toplevel->bufferGeometry().topLeft();
const auto pos = toplevel->mapToLocal(event->globalPosF());
tool->sendMotion(pos);
m_cursorByTool[tool]->setPos(event->globalPos());
break;
@ -1725,7 +1725,7 @@ public:
tool->sendProximityOut();
break;
case QEvent::TabletPress: {
const auto pos = event->globalPosF() - toplevel->bufferGeometry().topLeft();
const auto pos = toplevel->mapToLocal(event->globalPosF());
tool->sendMotion(pos);
m_cursorByTool[tool]->setPos(event->globalPos());
tool->sendDown();

View file

@ -789,6 +789,21 @@ QMatrix4x4 Toplevel::inputTransformation() const
return m;
}
QPoint Toplevel::mapToFrame(const QPoint &point) const
{
return point - frameGeometry().topLeft();
}
QPoint Toplevel::mapToLocal(const QPoint &point) const
{
return point - bufferGeometry().topLeft();
}
QPointF Toplevel::mapToLocal(const QPointF &point) const
{
return point - bufferGeometry().topLeft();
}
quint32 Toplevel::windowId() const
{
return window();

View file

@ -381,6 +381,18 @@ public:
virtual bool isClient() const;
virtual bool isDeleted() const;
/**
* Maps the specified @a point from the global screen coordinates to the frame coordinates.
*/
QPoint mapToFrame(const QPoint &point) const;
/**
* Maps the specified @a point from the global screen coordinates to the surface-local
* coordinates of the main surface. For X11 clients, this function maps the specified point
* from the global screen coordinates to the buffer-local coordinates.
*/
QPoint mapToLocal(const QPoint &point) const;
QPointF mapToLocal(const QPointF &point) const;
// prefer isXXX() instead
// 0 for supported types means default for managed/unmanaged types
virtual NET::WindowType windowType(bool direct = false, int supported_types = 0) const = 0;