aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Gräßlin <[email protected]>2017-01-04 18:01:25 +0100
committerMartin Gräßlin <[email protected]>2017-01-04 18:04:15 +0100
commit80adfd0274afd95e1f7589bf2ae444f40e408eea (patch)
tree11d5e95a0a138607f1b1955147c07a74d36af6f4
parent6a78bd45fea399f76c0d45bc3b34c2a29001a85b (diff)
Fade out OnScreenNotification when moving with the mouse over it
Summary: This change triggers a fade out animation when the mouse is moved over the OnScreenNotification, thus revealing the windows underneath. When moving the mouse out of the OnScreenNotification it gets faded in again. This is useful for various cases, e.g. when picking a color and the pixel one wants to pick is underneath the notification, or when trying to kill a window... Test Plan: Manual testing in nested setup Reviewers: #kwin, #plasma_on_wayland Subscribers: plasma-devel, kwin Tags: #plasma_on_wayland, #kwin Differential Revision: https://phabricator.kde.org/D3964
-rw-r--r--autotests/CMakeLists.txt2
-rw-r--r--autotests/onscreennotificationtest.cpp18
-rw-r--r--onscreennotification.cpp69
-rw-r--r--onscreennotification.h11
4 files changed, 100 insertions, 0 deletions
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 5cc6da4..174653d 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -320,11 +320,13 @@ ecm_mark_as_test(testScreenEdges)
set( testOnScreenNotification_SRCS
onscreennotificationtest.cpp
../onscreennotification.cpp
+ ../input_event_spy.cpp
)
add_executable( testOnScreenNotification ${testOnScreenNotification_SRCS})
target_link_libraries(testOnScreenNotification
Qt5::Test
+ Qt5::Widgets # QAction include
Qt5::Quick
KF5::ConfigCore
)
diff --git a/autotests/onscreennotificationtest.cpp b/autotests/onscreennotificationtest.cpp
index a446552..a46e851 100644
--- a/autotests/onscreennotificationtest.cpp
+++ b/autotests/onscreennotificationtest.cpp
@@ -21,6 +21,7 @@
#include "onscreennotificationtest.h"
#include "../onscreennotification.h"
+#include "../input.h"
#include <KSharedConfig>
#include <KConfigGroup>
@@ -31,6 +32,23 @@
QTEST_MAIN(OnScreenNotificationTest);
+namespace KWin
+{
+
+void InputRedirection::installInputEventSpy(InputEventSpy *spy)
+{
+ Q_UNUSED(spy);
+}
+
+void InputRedirection::uninstallInputEventSpy(InputEventSpy *spy)
+{
+ Q_UNUSED(spy);
+}
+
+InputRedirection *InputRedirection::s_self = nullptr;
+
+}
+
using KWin::OnScreenNotification;
void OnScreenNotificationTest::show()
diff --git a/onscreennotification.cpp b/onscreennotification.cpp
index 9bca931..b32349e 100644
--- a/onscreennotification.cpp
+++ b/onscreennotification.cpp
@@ -20,8 +20,12 @@
*/
#include "onscreennotification.h"
+#include "input.h"
+#include "input_event.h"
+#include "input_event_spy.h"
#include <config-kwin.h>
+#include <QPropertyAnimation>
#include <QStandardPaths>
#include <QTimer>
#include <QQmlComponent>
@@ -35,6 +39,31 @@
using namespace KWin;
+class KWin::OnScreenNotificationInputEventSpy : public InputEventSpy
+{
+public:
+ explicit OnScreenNotificationInputEventSpy(OnScreenNotification *parent);
+
+ void pointerEvent(MouseEvent *event) override;
+private:
+ OnScreenNotification *m_parent;
+};
+
+OnScreenNotificationInputEventSpy::OnScreenNotificationInputEventSpy(OnScreenNotification *parent)
+ : m_parent(parent)
+{
+}
+
+void OnScreenNotificationInputEventSpy::pointerEvent(MouseEvent *event)
+{
+ if (event->type() != QEvent::MouseMove) {
+ return;
+ }
+
+ m_parent->setContainsPointer(m_parent->geometry().contains(event->globalPos()));
+}
+
+
OnScreenNotification::OnScreenNotification(QObject *parent)
: QObject(parent)
, m_timer(new QTimer(this))
@@ -47,6 +76,8 @@ OnScreenNotification::OnScreenNotification(QObject *parent)
show();
} else {
m_timer->stop();
+ m_spy.reset();
+ m_containsPointer = false;
}
}
);
@@ -131,6 +162,7 @@ void OnScreenNotification::show()
Q_ASSERT(m_visible);
ensureQmlContext();
ensureQmlComponent();
+ createInputSpy();
if (m_timer->interval() != 0) {
m_timer->start();
}
@@ -167,4 +199,41 @@ void OnScreenNotification::ensureQmlComponent()
}
}
+void OnScreenNotification::createInputSpy()
+{
+ Q_ASSERT(m_spy.isNull());
+ if (auto w = qobject_cast<QQuickWindow*>(m_mainItem.data())) {
+ m_spy.reset(new OnScreenNotificationInputEventSpy(this));
+ input()->installInputEventSpy(m_spy.data());
+ if (!m_animation) {
+ m_animation = new QPropertyAnimation(w, "opacity", this);
+ m_animation->setStartValue(1.0);
+ m_animation->setEndValue(0.0);
+ m_animation->setDuration(250);
+ m_animation->setEasingCurve(QEasingCurve::InOutQuad);
+ }
+ }
+}
+
+QRect OnScreenNotification::geometry() const
+{
+ if (QQuickWindow *w = qobject_cast<QQuickWindow*>(m_mainItem.data())) {
+ return w->geometry();
+ }
+ return QRect();
+}
+
+void OnScreenNotification::setContainsPointer(bool contains)
+{
+ if (m_containsPointer == contains) {
+ return;
+ }
+ m_containsPointer = contains;
+ if (!m_animation) {
+ return;
+ }
+ m_animation->setDirection(m_containsPointer ? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
+ m_animation->start();
+}
+
#include "onscreennotification.moc"
diff --git a/onscreennotification.h b/onscreennotification.h
index 40a67e1..0c91612 100644
--- a/onscreennotification.h
+++ b/onscreennotification.h
@@ -26,6 +26,7 @@
#include <KSharedConfig>
+class QPropertyAnimation;
class QTimer;
class QQmlContext;
class QQmlComponent;
@@ -33,6 +34,8 @@ class QQmlEngine;
namespace KWin {
+class OnScreenNotificationInputEventSpy;
+
class OnScreenNotification : public QObject
{
Q_OBJECT
@@ -49,6 +52,8 @@ public:
QString iconName() const;
int timeout() const;
+ QRect geometry() const;
+
void setVisible(bool m_visible);
void setMessage(const QString &message);
void setIconName(const QString &iconName);
@@ -57,6 +62,8 @@ public:
void setConfig(KSharedConfigPtr config);
void setEngine(QQmlEngine *engine);
+ void setContainsPointer(bool contains);
+
Q_SIGNALS:
void visibleChanged();
void messageChanged();
@@ -67,6 +74,7 @@ private:
void show();
void ensureQmlContext();
void ensureQmlComponent();
+ void createInputSpy();
bool m_visible = false;
QString m_message;
QString m_iconName;
@@ -76,6 +84,9 @@ private:
QScopedPointer<QQmlComponent> m_qmlComponent;
QQmlEngine *m_qmlEngine = nullptr;
QScopedPointer<QObject> m_mainItem;
+ QScopedPointer<OnScreenNotificationInputEventSpy> m_spy;
+ QPropertyAnimation *m_animation = nullptr;
+ bool m_containsPointer = false;
};
}