Client decorations: Show menu on right click

[ChangeLog][QPA plugin] A window menu is now shown when the window decorations
are right-clicked (if supported by the compositor).

Change-Id: I13bf0c8cd91a6e5a3b44e47114dfdc2ff0e97f3a
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@liri.io>
This commit is contained in:
Johan Klokkhammer Helsing 2019-01-11 11:22:23 +01:00 committed by Johan Helsing
parent 0552060620
commit 516c75d5d0
12 changed files with 57 additions and 6 deletions

View File

@ -333,6 +333,8 @@ void QWaylandBradientDecoration::processMouseTop(QWaylandInputDevice *inputDevic
processMouseLeft(inputDevice, local, b, mods);
} else if (local.x() > window()->width() + margins().left()) {
processMouseRight(inputDevice, local, b, mods);
} else if (isRightClicked(b)) {
showWindowMenu(inputDevice);
} else if (closeButtonRect().contains(local)) {
if (clickButton(b, Close))
QWindowSystemInterface::handleCloseEvent(window());

View File

@ -95,6 +95,13 @@ bool QWaylandXdgSurfaceV5::move(QWaylandInputDevice *inputDevice)
return true;
}
bool QWaylandXdgSurfaceV5::showWindowMenu(QWaylandInputDevice *seat)
{
QPoint position = seat->pointerSurfacePosition().toPoint();
show_window_menu(seat->wl_seat(), seat->serial(), position.x(), position.y());
return true;
}
void QWaylandXdgSurfaceV5::updateTransientParent(QWaylandWindow *parent)
{
if (!parent)

View File

@ -84,6 +84,7 @@ public:
using QtWayland::xdg_surface_v5::move;
bool move(QWaylandInputDevice *inputDevice) override;
bool showWindowMenu(QWaylandInputDevice *seat) override;
void setTitle(const QString &title) override;
void setAppId(const QString &appId) override;

View File

@ -251,6 +251,16 @@ bool QWaylandXdgSurfaceV6::move(QWaylandInputDevice *inputDevice)
return false;
}
bool QWaylandXdgSurfaceV6::showWindowMenu(QWaylandInputDevice *seat)
{
if (m_toplevel && m_toplevel->isInitialized()) {
QPoint position = seat->pointerSurfacePosition().toPoint();
m_toplevel->show_window_menu(seat->wl_seat(), seat->serial(), position.x(), position.y());
return true;
}
return false;
}
void QWaylandXdgSurfaceV6::setTitle(const QString &title)
{
if (m_toplevel)

View File

@ -79,6 +79,7 @@ public:
void resize(QWaylandInputDevice *inputDevice, Qt::Edges edges) override;
bool move(QWaylandInputDevice *inputDevice) override;
bool showWindowMenu(QWaylandInputDevice *seat) override;
void setTitle(const QString &title) override;
void setAppId(const QString &appId) override;

View File

@ -279,6 +279,16 @@ bool QWaylandXdgSurface::move(QWaylandInputDevice *inputDevice)
return false;
}
bool QWaylandXdgSurface::showWindowMenu(QWaylandInputDevice *seat)
{
if (m_toplevel && m_toplevel->isInitialized()) {
QPoint position = seat->pointerSurfacePosition().toPoint();
m_toplevel->show_window_menu(seat->wl_seat(), seat->serial(), position.x(), position.y());
return true;
}
return false;
}
void QWaylandXdgSurface::setTitle(const QString &title)
{
if (m_toplevel)

View File

@ -82,6 +82,7 @@ public:
void resize(QWaylandInputDevice *inputDevice, Qt::Edges edges) override;
bool move(QWaylandInputDevice *inputDevice) override;
bool showWindowMenu(QWaylandInputDevice *seat) override;
void setTitle(const QString &title) override;
void setAppId(const QString &appId) override;
void setWindowFlags(Qt::WindowFlags flags) override;

View File

@ -164,20 +164,29 @@ void QWaylandAbstractDecoration::startMove(QWaylandInputDevice *inputDevice, Qt:
}
}
void QWaylandAbstractDecoration::showWindowMenu(QWaylandInputDevice *inputDevice)
{
Q_D(QWaylandAbstractDecoration);
if (auto *s = d->m_wayland_window->shellSurface())
s->showWindowMenu(inputDevice);
}
bool QWaylandAbstractDecoration::isLeftClicked(Qt::MouseButtons newMouseButtonState)
{
Q_D(QWaylandAbstractDecoration);
if (!(d->m_mouseButtons & Qt::LeftButton) && (newMouseButtonState & Qt::LeftButton))
return true;
return false;
return !(d->m_mouseButtons & Qt::LeftButton) && (newMouseButtonState & Qt::LeftButton);
}
bool QWaylandAbstractDecoration::isRightClicked(Qt::MouseButtons newMouseButtonState)
{
Q_D(QWaylandAbstractDecoration);
return !(d->m_mouseButtons & Qt::RightButton) && (newMouseButtonState & Qt::RightButton);
}
bool QWaylandAbstractDecoration::isLeftReleased(Qt::MouseButtons newMouseButtonState)
{
Q_D(QWaylandAbstractDecoration);
if ((d->m_mouseButtons & Qt::LeftButton) && !(newMouseButtonState & Qt::LeftButton))
return true;
return false;
return (d->m_mouseButtons & Qt::LeftButton) && !(newMouseButtonState & Qt::LeftButton);
}
bool QWaylandAbstractDecoration::isDirty() const

View File

@ -105,8 +105,10 @@ protected:
void startResize(QWaylandInputDevice *inputDevice, Qt::Edges edges, Qt::MouseButtons buttons);
void startMove(QWaylandInputDevice *inputDevice, Qt::MouseButtons buttons);
void showWindowMenu(QWaylandInputDevice *inputDevice);
bool isLeftClicked(Qt::MouseButtons newMouseButtonState);
bool isRightClicked(Qt::MouseButtons newMouseButtonState);
bool isLeftReleased(Qt::MouseButtons newMouseButtonState);
};

View File

@ -331,6 +331,11 @@ QWaylandWindow *QWaylandInputDevice::touchFocus() const
return mTouch ? mTouch->mFocus : nullptr;
}
QPointF QWaylandInputDevice::pointerSurfacePosition() const
{
return mPointer ? mPointer->mSurfacePos : QPointF();
}
Qt::KeyboardModifiers QWaylandInputDevice::modifiers() const
{
if (!mKeyboard)

View File

@ -129,6 +129,8 @@ public:
QWaylandWindow *keyboardFocus() const;
QWaylandWindow *touchFocus() const;
QPointF pointerSurfacePosition() const;
Qt::KeyboardModifiers modifiers() const;
uint32_t serial() const;

View File

@ -76,6 +76,7 @@ public:
virtual void resize(QWaylandInputDevice * /*inputDevice*/, Qt::Edges /*edges*/) {}
virtual bool move(QWaylandInputDevice *) { return false; }
virtual bool showWindowMenu(QWaylandInputDevice *seat) { Q_UNUSED(seat); return false; }
virtual void setTitle(const QString & /*title*/) {}
virtual void setAppId(const QString & /*appId*/) {}