diff --git a/abstract_client.cpp b/abstract_client.cpp index e3c488127d..17e88ccdd9 100644 --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -1750,4 +1750,12 @@ void AbstractClient::setUnresponsive(bool unresponsive) } } +QString AbstractClient::shortcutCaptionSuffix() const +{ + if (shortcut().isEmpty()) { + return QString(); + } + return QLatin1String(" {") + shortcut().toString() + QLatin1Char('}'); +} + } diff --git a/abstract_client.h b/abstract_client.h index 10e359b50c..a2fc9ad0d9 100644 --- a/abstract_client.h +++ b/abstract_client.h @@ -983,6 +983,8 @@ protected: void setUnresponsive(bool unresponsive); virtual void setShortcutInternal(); + QString shortcutCaptionSuffix() const; + virtual void updateCaption() = 0; private: void handlePaletteChange(); diff --git a/autotests/integration/globalshortcuts_test.cpp b/autotests/integration/globalshortcuts_test.cpp index 0c1893bc1e..14a924a852 100644 --- a/autotests/integration/globalshortcuts_test.cpp +++ b/autotests/integration/globalshortcuts_test.cpp @@ -292,7 +292,6 @@ void GlobalShortcutsTest::testWaylandClientShortcut() client->setShortcut(seq.toString()); QCOMPARE(client->shortcut(), seq); QVERIFY(!workspace()->shortcutAvailable(seq)); - QEXPECT_FAIL("", "Caption adjustment not yet implemented", Continue); QCOMPARE(client->caption(), QStringLiteral(" {Meta+Shift+Y}")); workspace()->activateClient(nullptr); diff --git a/client.cpp b/client.cpp index 19ddb96795..1187b8bb83 100644 --- a/client.cpp +++ b/client.cpp @@ -1442,7 +1442,7 @@ void Client::setCaption(const QString& _s, bool force) if (clientMachine()->hostName() != ClientMachine::localhost() && !clientMachine()->isLocal()) 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; auto fetchNameInternalPredicate = [this](const Client *cl) { return (!cl->isSpecialWindow() || cl->isToolbar()) && diff --git a/client.h b/client.h index 076b3c0c7c..b77c8cdf86 100644 --- a/client.h +++ b/client.h @@ -339,7 +339,7 @@ public: public Q_SLOTS: void closeWindow() override; - void updateCaption(); + void updateCaption() override; void evaluateWindowRules(); private Q_SLOTS: diff --git a/shell_client.cpp b/shell_client.cpp index 58ba2165fb..82e6bb8753 100644 --- a/shell_client.cpp +++ b/shell_client.cpp @@ -556,8 +556,20 @@ void ShellClient::blockActivityUpdates(bool b) QString ShellClient::caption(bool full) const { - Q_UNUSED(full) - return m_caption; + QString caption = 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() diff --git a/shell_client.h b/shell_client.h index f4fc852319..1328ad747f 100644 --- a/shell_client.h +++ b/shell_client.h @@ -163,6 +163,7 @@ protected: bool acceptsFocus() const override; void doMinimize() override; void doMove(int x, int y) override; + void updateCaption() override; private Q_SLOTS: void clientFullScreenChanged(bool fullScreen); @@ -236,6 +237,7 @@ private: int m_requestGeometryBlockCounter = 0; QRect m_blockedRequestGeometry; QString m_caption; + QString m_captionSuffix; bool m_compositingSetup = false; }; diff --git a/useractions.cpp b/useractions.cpp index 62052baa39..91bb925cb6 100644 --- a/useractions.cpp +++ b/useractions.cpp @@ -1826,6 +1826,7 @@ void AbstractClient::setShortcut(const QString& _cut) void AbstractClient::setShortcutInternal() { + updateCaption(); workspace()->clientShortcutUpdated(this); }