[wayland] Get rid of some duplicated code

Summary:
We duplicate ping code in a few places. This change introduces a dedicated
method for sending ping events to an xdg-toplevel. In long term, it can be
used for sending "test" ping messages at random interval.

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D26974
This commit is contained in:
Vlad Zahorodnii 2020-01-29 00:02:05 +02:00
parent ec2204fbe1
commit 2cf832cf29
2 changed files with 13 additions and 5 deletions

View file

@ -652,8 +652,7 @@ void XdgShellClient::closeWindow()
{
if (m_xdgShellSurface && isCloseable()) {
m_xdgShellSurface->close();
const qint32 pingSerial = static_cast<XdgShellInterface *>(m_xdgShellSurface->global())->ping(m_xdgShellSurface);
m_pingSerials.insert(pingSerial, PingReason::CloseWindow);
ping(PingReason::CloseWindow);
}
}
@ -989,8 +988,7 @@ void XdgShellClient::takeFocus()
{
if (rules()->checkAcceptFocus(wantsInput())) {
if (m_xdgShellSurface) {
const qint32 pingSerial = static_cast<XdgShellInterface *>(m_xdgShellSurface->global())->ping(m_xdgShellSurface);
m_pingSerials.insert(pingSerial, PingReason::FocusWindow);
ping(PingReason::FocusWindow);
}
setActive(true);
}
@ -2043,4 +2041,13 @@ QRect XdgShellClient::adjustResizeGeometry(const QRect &rect) const
return geometry;
}
void XdgShellClient::ping(PingReason reason)
{
Q_ASSERT(m_xdgShellSurface);
XdgShellInterface *shell = static_cast<XdgShellInterface *>(m_xdgShellSurface->global());
const quint32 serial = shell->ping(m_xdgShellSurface);
m_pingSerials.insert(serial, reason);
}
}

View file

@ -188,6 +188,7 @@ private:
void unmap();
void markAsMapped();
QRect determineBufferGeometry() const;
void ping(PingReason reason);
static void deleteClient(XdgShellClient *c);
QRect adjustMoveGeometry(const QRect &rect) const;
@ -260,7 +261,7 @@ private:
QRect m_blockedRequestGeometry;
QString m_caption;
QString m_captionSuffix;
QHash<qint32, PingReason> m_pingSerials;
QHash<quint32, PingReason> m_pingSerials;
bool m_isInitialized = false;