Commit 5a14b6a6 authored by Алексей Шилин's avatar Алексей Шилин
Browse files

Improve tooltips behavior

Summary:
Window buttons tooltips used to appear on hover immediately. As
the result, they mostly appeared when not needed e.g. when user
was closing a window, or when the mouse pointer slightly touched
a button while being moved elsewhere.

This commit changes the tooltips behavior to WakeUp-FallAsleep
approach used by Widgets.

BUG: 392765
FIXED-IN: 5.13

Reviewers: #kwin, graesslin, broulik, #plasma

Reviewed By: #kwin, graesslin, #plasma

Subscribers: zzag, broulik, kwin, hein

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D12404
parent e737a619
......@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KDecoration2/Decoration>
#include <QDebug>
#include <QStyle>
#include <QToolTip>
namespace KWin
......@@ -114,6 +115,16 @@ DecoratedClientImpl::DecoratedClientImpl(AbstractClient *client, KDecoration2::D
connect(client, &AbstractClient::hasApplicationMenuChanged, decoratedClient, &KDecoration2::DecoratedClient::hasApplicationMenuChanged);
connect(client, &AbstractClient::applicationMenuActiveChanged, decoratedClient, &KDecoration2::DecoratedClient::applicationMenuActiveChanged);
m_toolTipWakeUp.setSingleShot(true);
connect(&m_toolTipWakeUp, &QTimer::timeout, this,
[this]() {
int fallAsleepDelay = QApplication::style()->styleHint(QStyle::SH_ToolTip_FallAsleepDelay);
this->m_toolTipFallAsleep.setRemainingTime(fallAsleepDelay);
QToolTip::showText(Cursor::pos(), this->m_toolTipText);
}
);
}
DecoratedClientImpl::~DecoratedClientImpl() = default;
......@@ -203,12 +214,15 @@ QColor DecoratedClientImpl::color(KDecoration2::ColorGroup group, KDecoration2::
void DecoratedClientImpl::requestShowToolTip(const QString &text)
{
QPoint pos = Cursor::pos();
QToolTip::showText(pos, text);
m_toolTipText = text;
int wakeUpDelay = QApplication::style()->styleHint(QStyle::SH_ToolTip_WakeUpDelay);
m_toolTipWakeUp.start(m_toolTipFallAsleep.hasExpired() ? wakeUpDelay : 20);
}
void DecoratedClientImpl::requestHideToolTip()
{
m_toolTipWakeUp.stop();
QToolTip::hideText();
}
......
......@@ -23,7 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KDecoration2/Private/DecoratedClientPrivate>
#include <QDeadlineTimer>
#include <QObject>
#include <QTimer>
namespace KWin
{
......@@ -109,6 +111,10 @@ private:
QSize m_clientSize;
Renderer *m_renderer;
QMetaObject::Connection m_compositorToggledConnection;
QString m_toolTipText;
QTimer m_toolTipWakeUp;
QDeadlineTimer m_toolTipFallAsleep;
};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment