Implement the shortcut caption suffix for Wayland windows

Summary:
The generation of the shortcut caption part is moved from Client to
AbstractClient. The ShellClient also has a captionSuffix and implements
the full part in caption.

Overall this needs more refactoring to support more sharing between the
two implementations. But one step at a time.

Reviewers: #kwin, #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D7093
This commit is contained in:
Martin Flöser 2017-08-03 07:11:40 +02:00
parent bbad15f661
commit bbca8c6677
8 changed files with 29 additions and 5 deletions

View file

@ -1750,4 +1750,12 @@ void AbstractClient::setUnresponsive(bool unresponsive)
} }
} }
QString AbstractClient::shortcutCaptionSuffix() const
{
if (shortcut().isEmpty()) {
return QString();
}
return QLatin1String(" {") + shortcut().toString() + QLatin1Char('}');
}
} }

View file

@ -983,6 +983,8 @@ protected:
void setUnresponsive(bool unresponsive); void setUnresponsive(bool unresponsive);
virtual void setShortcutInternal(); virtual void setShortcutInternal();
QString shortcutCaptionSuffix() const;
virtual void updateCaption() = 0;
private: private:
void handlePaletteChange(); void handlePaletteChange();

View file

@ -292,7 +292,6 @@ void GlobalShortcutsTest::testWaylandClientShortcut()
client->setShortcut(seq.toString()); client->setShortcut(seq.toString());
QCOMPARE(client->shortcut(), seq); QCOMPARE(client->shortcut(), seq);
QVERIFY(!workspace()->shortcutAvailable(seq)); QVERIFY(!workspace()->shortcutAvailable(seq));
QEXPECT_FAIL("", "Caption adjustment not yet implemented", Continue);
QCOMPARE(client->caption(), QStringLiteral(" {Meta+Shift+Y}")); QCOMPARE(client->caption(), QStringLiteral(" {Meta+Shift+Y}"));
workspace()->activateClient(nullptr); workspace()->activateClient(nullptr);

View file

@ -1442,7 +1442,7 @@ void Client::setCaption(const QString& _s, bool force)
if (clientMachine()->hostName() != ClientMachine::localhost() && !clientMachine()->isLocal()) if (clientMachine()->hostName() != ClientMachine::localhost() && !clientMachine()->isLocal())
machine_suffix = QLatin1String(" <@") + QString::fromUtf8(clientMachine()->hostName()) + QLatin1Char('>') + LRM; machine_suffix = QLatin1String(" <@") + QString::fromUtf8(clientMachine()->hostName()) + QLatin1Char('>') + LRM;
} }
QString shortcut_suffix = !shortcut().isEmpty() ? (QLatin1String(" {") + shortcut().toString() + QLatin1Char('}')) : QString(); QString shortcut_suffix = shortcutCaptionSuffix();
cap_suffix = machine_suffix + shortcut_suffix; cap_suffix = machine_suffix + shortcut_suffix;
auto fetchNameInternalPredicate = [this](const Client *cl) { auto fetchNameInternalPredicate = [this](const Client *cl) {
return (!cl->isSpecialWindow() || cl->isToolbar()) && return (!cl->isSpecialWindow() || cl->isToolbar()) &&

View file

@ -339,7 +339,7 @@ public:
public Q_SLOTS: public Q_SLOTS:
void closeWindow() override; void closeWindow() override;
void updateCaption(); void updateCaption() override;
void evaluateWindowRules(); void evaluateWindowRules();
private Q_SLOTS: private Q_SLOTS:

View file

@ -556,8 +556,20 @@ void ShellClient::blockActivityUpdates(bool b)
QString ShellClient::caption(bool full) const QString ShellClient::caption(bool full) const
{ {
Q_UNUSED(full) QString caption = m_caption;
return m_caption; if (full) {
caption += m_captionSuffix;
}
return caption;
}
void ShellClient::updateCaption()
{
const QString oldSuffix = m_captionSuffix;
m_captionSuffix = shortcutCaptionSuffix();
if (m_captionSuffix != oldSuffix) {
emit captionChanged();
}
} }
void ShellClient::closeWindow() void ShellClient::closeWindow()

View file

@ -163,6 +163,7 @@ protected:
bool acceptsFocus() const override; bool acceptsFocus() const override;
void doMinimize() override; void doMinimize() override;
void doMove(int x, int y) override; void doMove(int x, int y) override;
void updateCaption() override;
private Q_SLOTS: private Q_SLOTS:
void clientFullScreenChanged(bool fullScreen); void clientFullScreenChanged(bool fullScreen);
@ -236,6 +237,7 @@ private:
int m_requestGeometryBlockCounter = 0; int m_requestGeometryBlockCounter = 0;
QRect m_blockedRequestGeometry; QRect m_blockedRequestGeometry;
QString m_caption; QString m_caption;
QString m_captionSuffix;
bool m_compositingSetup = false; bool m_compositingSetup = false;
}; };

View file

@ -1826,6 +1826,7 @@ void AbstractClient::setShortcut(const QString& _cut)
void AbstractClient::setShortcutInternal() void AbstractClient::setShortcutInternal()
{ {
updateCaption();
workspace()->clientShortcutUpdated(this); workspace()->clientShortcutUpdated(this);
} }