2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2010 Martin Gräßlin <mgraesslin@kde.org>
|
2020-11-03 10:56:57 +00:00
|
|
|
SPDX-FileCopyrightText: 2020 David Redondo <kde@david-redondo.de>
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2010-10-16 08:50:38 +00:00
|
|
|
#include "startupfeedback.h"
|
|
|
|
// Qt
|
2014-03-16 09:16:52 +00:00
|
|
|
#include <QApplication>
|
2020-11-03 10:56:57 +00:00
|
|
|
#include <QDBusConnectionInterface>
|
|
|
|
#include <QDBusServiceWatcher>
|
2015-11-30 09:51:27 +00:00
|
|
|
#include <QFile>
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QSize>
|
2014-03-16 09:16:52 +00:00
|
|
|
#include <QStyle>
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QPainter>
|
2010-10-16 08:50:38 +00:00
|
|
|
// KDE
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KConfigGroup>
|
2014-03-29 08:05:08 +00:00
|
|
|
#include <KSharedConfig>
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KSelectionOwner>
|
2016-10-20 08:57:25 +00:00
|
|
|
#include <KWindowSystem>
|
2010-10-16 08:50:38 +00:00
|
|
|
// KWin
|
|
|
|
#include <kwinglutils.h>
|
|
|
|
|
|
|
|
// based on StartupId in KRunner by Lubos Lunak
|
2020-08-02 22:10:35 +00:00
|
|
|
// SPDX-FileCopyrightText: 2001 Lubos Lunak <l.lunak@kde.org>
|
2010-10-16 08:50:38 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
// number of key frames for bouncing animation
|
|
|
|
static const int BOUNCE_FRAMES = 20;
|
|
|
|
// duration between two key frames in msec
|
|
|
|
static const int BOUNCE_FRAME_DURATION = 30;
|
|
|
|
// duration of one bounce animation
|
|
|
|
static const int BOUNCE_DURATION = BOUNCE_FRAME_DURATION * BOUNCE_FRAMES;
|
|
|
|
// number of key frames for blinking animation
|
|
|
|
static const int BLINKING_FRAMES = 5;
|
|
|
|
// duration between two key frames in msec
|
|
|
|
static const int BLINKING_FRAME_DURATION = 100;
|
|
|
|
// duration of one blinking animation
|
|
|
|
static const int BLINKING_DURATION = BLINKING_FRAME_DURATION * BLINKING_FRAMES;
|
|
|
|
//const int color_to_pixmap[] = { 0, 1, 2, 3, 2, 1 };
|
2011-01-30 14:34:42 +00:00
|
|
|
static const int FRAME_TO_BOUNCE_YOFFSET[] = {
|
2010-10-16 08:50:38 +00:00
|
|
|
-5, -1, 2, 5, 8, 10, 12, 13, 15, 15, 15, 15, 14, 12, 10, 8, 5, 2, -1, -5
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
|
|
|
static const QSize BOUNCE_SIZES[] = {
|
2010-10-16 08:50:38 +00:00
|
|
|
QSize(16, 16), QSize(14, 18), QSize(12, 20), QSize(18, 14), QSize(20, 12)
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
|
|
|
static const int FRAME_TO_BOUNCE_TEXTURE[] = {
|
2010-10-16 08:50:38 +00:00
|
|
|
0, 0, 0, 1, 2, 2, 1, 0, 3, 4, 4, 3, 0, 1, 2, 2, 1, 0, 0, 0
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
|
|
|
static const int FRAME_TO_BLINKING_COLOR[] = {
|
2010-10-16 08:50:38 +00:00
|
|
|
0, 1, 2, 3, 2, 1
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
|
|
|
static const QColor BLINKING_COLORS[] = {
|
2010-10-16 08:50:38 +00:00
|
|
|
Qt::black, Qt::darkGray, Qt::lightGray, Qt::white, Qt::white
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2014-01-16 12:02:13 +00:00
|
|
|
static const int s_startupDefaultTimeout = 5;
|
2010-10-16 08:50:38 +00:00
|
|
|
|
|
|
|
StartupFeedbackEffect::StartupFeedbackEffect()
|
2012-08-27 09:14:03 +00:00
|
|
|
: m_bounceSizesRatio(1.0)
|
|
|
|
, m_startupInfo(new KStartupInfo(KStartupInfo::CleanOnCantDetect, this))
|
2016-10-20 08:57:25 +00:00
|
|
|
, m_selection(nullptr)
|
2011-01-30 14:34:42 +00:00
|
|
|
, m_active(false)
|
|
|
|
, m_frame(0)
|
|
|
|
, m_progress(0)
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
, m_lastPresentTime(std::chrono::milliseconds::zero())
|
2011-01-30 14:34:42 +00:00
|
|
|
, m_type(BouncingFeedback)
|
2020-04-07 13:32:22 +00:00
|
|
|
, m_cursorSize(24)
|
2019-12-10 11:21:23 +00:00
|
|
|
, m_configWatcher(KConfigWatcher::create(KSharedConfig::openConfig("klaunchrc", KConfig::NoGlobals)))
|
2020-11-03 10:56:57 +00:00
|
|
|
, m_splashVisible(false)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-10-20 08:57:25 +00:00
|
|
|
if (KWindowSystem::isPlatformX11()) {
|
|
|
|
m_selection = new KSelectionOwner("_KDE_STARTUP_FEEDBACK", xcbConnection(), x11RootWindow(), this);
|
|
|
|
m_selection->claim(true);
|
|
|
|
}
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(m_startupInfo, &KStartupInfo::gotNewStartup, this, &StartupFeedbackEffect::gotNewStartup);
|
|
|
|
connect(m_startupInfo, &KStartupInfo::gotRemoveStartup, this, &StartupFeedbackEffect::gotRemoveStartup);
|
|
|
|
connect(m_startupInfo, &KStartupInfo::gotStartupChange, this, &StartupFeedbackEffect::gotStartupChange);
|
|
|
|
connect(effects, &EffectsHandler::mouseChanged, this, &StartupFeedbackEffect::slotMouseChanged);
|
2019-12-10 11:21:23 +00:00
|
|
|
connect(m_configWatcher.data(), &KConfigWatcher::configChanged, this, [this]() {
|
|
|
|
reconfigure(ReconfigureAll);
|
|
|
|
});
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
2019-12-10 11:21:23 +00:00
|
|
|
|
2020-11-03 10:56:57 +00:00
|
|
|
m_splashVisible = QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.KSplash"));
|
|
|
|
auto serviceWatcher = new QDBusServiceWatcher(QStringLiteral("org.kde.KSplash"), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this);
|
|
|
|
connect(serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this] {
|
|
|
|
m_splashVisible = true;
|
|
|
|
stop();
|
|
|
|
});
|
|
|
|
connect(serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, [this] {
|
|
|
|
m_splashVisible = false;
|
|
|
|
gotRemoveStartup(KStartupInfoId(), KStartupInfoData()); // Start the next feedback
|
|
|
|
});
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
|
|
|
StartupFeedbackEffect::~StartupFeedbackEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_active) {
|
2010-10-16 08:50:38 +00:00
|
|
|
effects->stopMousePolling();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
|
|
|
bool StartupFeedbackEffect::supported()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-09-20 09:33:32 +00:00
|
|
|
return effects->isOpenGLCompositing();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void StartupFeedbackEffect::reconfigure(Effect::ReconfigureFlags flags)
|
|
|
|
{
|
|
|
|
Q_UNUSED(flags)
|
2019-12-10 11:21:23 +00:00
|
|
|
KConfigGroup c = m_configWatcher->config()->group("FeedbackStyle");
|
2011-01-30 14:34:42 +00:00
|
|
|
const bool busyCursor = c.readEntry("BusyCursor", true);
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2019-12-10 11:21:23 +00:00
|
|
|
c = m_configWatcher->config()->group("BusyCursorSettings");
|
2014-01-16 12:02:13 +00:00
|
|
|
m_startupInfo->setTimeout(c.readEntry("Timeout", s_startupDefaultTimeout));
|
2011-01-30 14:34:42 +00:00
|
|
|
const bool busyBlinking = c.readEntry("Blinking", false);
|
|
|
|
const bool busyBouncing = c.readEntry("Bouncing", true);
|
|
|
|
if (!busyCursor)
|
2010-10-16 08:50:38 +00:00
|
|
|
m_type = NoFeedback;
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (busyBouncing)
|
2010-10-16 08:50:38 +00:00
|
|
|
m_type = BouncingFeedback;
|
2011-01-06 12:47:42 +00:00
|
|
|
else if (busyBlinking) {
|
2010-10-16 08:50:38 +00:00
|
|
|
m_type = BlinkingFeedback;
|
2012-09-21 07:09:52 +00:00
|
|
|
if (effects->compositingType() == OpenGL2Compositing) {
|
2020-11-09 17:26:57 +00:00
|
|
|
m_blinkingShader.reset(ShaderManager::instance()->generateShaderFromResources(ShaderTrait::MapTexture, QString(), QStringLiteral("blinking-startup-fragment.glsl")));
|
2016-01-26 14:38:42 +00:00
|
|
|
if (m_blinkingShader->isValid()) {
|
|
|
|
qCDebug(KWINEFFECTS) << "Blinking Shader is valid";
|
2011-01-06 12:47:42 +00:00
|
|
|
} else {
|
2016-01-26 14:38:42 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "Blinking Shader is not valid";
|
2011-01-06 12:47:42 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
2010-10-16 08:50:38 +00:00
|
|
|
m_type = PassiveFeedback;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_active) {
|
2010-10-16 08:50:38 +00:00
|
|
|
stop();
|
2011-01-30 14:34:42 +00:00
|
|
|
start(m_startups[ m_currentStartup ]);
|
2010-10-16 08:50:38 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
void StartupFeedbackEffect::prePaintScreen(ScreenPrePaintData& data, std::chrono::milliseconds presentTime)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
int time = 0;
|
|
|
|
if (m_lastPresentTime.count()) {
|
|
|
|
time = (presentTime - m_lastPresentTime).count();
|
|
|
|
}
|
|
|
|
m_lastPresentTime = presentTime;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_active) {
|
2010-10-16 08:50:38 +00:00
|
|
|
// need the unclipped version
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(m_type) {
|
2010-10-16 08:50:38 +00:00
|
|
|
case BouncingFeedback:
|
|
|
|
m_progress = (m_progress + time) % BOUNCE_DURATION;
|
2013-07-26 12:09:06 +00:00
|
|
|
m_frame = qRound((qreal)m_progress / (qreal)BOUNCE_FRAME_DURATION) % BOUNCE_FRAMES;
|
|
|
|
m_currentGeometry = feedbackRect(); // bounce alters geometry with m_frame
|
2015-05-03 21:03:13 +00:00
|
|
|
data.paint = data.paint.united(m_currentGeometry);
|
2010-10-16 08:50:38 +00:00
|
|
|
break;
|
|
|
|
case BlinkingFeedback:
|
|
|
|
m_progress = (m_progress + time) % BLINKING_DURATION;
|
2011-02-06 18:47:30 +00:00
|
|
|
m_frame = qRound((qreal)m_progress / (qreal)BLINKING_FRAME_DURATION) % BLINKING_FRAMES;
|
2010-10-16 08:50:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break; // nothing
|
|
|
|
}
|
|
|
|
}
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
effects->prePaintScreen(data, presentTime);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
void StartupFeedbackEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData& data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
effects->paintScreen(mask, region, data);
|
|
|
|
if (m_active) {
|
2010-10-16 08:50:38 +00:00
|
|
|
GLTexture* texture;
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(m_type) {
|
2010-10-16 08:50:38 +00:00
|
|
|
case BouncingFeedback:
|
2020-11-09 17:26:57 +00:00
|
|
|
texture = m_bouncingTextures[ FRAME_TO_BOUNCE_TEXTURE[ m_frame ]].get();
|
2010-10-16 08:50:38 +00:00
|
|
|
break;
|
|
|
|
case BlinkingFeedback: // fall through
|
|
|
|
case PassiveFeedback:
|
2020-11-09 17:26:57 +00:00
|
|
|
texture = m_texture.get();
|
2010-10-16 08:50:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return; // safety
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2010-10-16 08:50:38 +00:00
|
|
|
texture->bind();
|
2015-11-30 09:51:27 +00:00
|
|
|
if (m_type == BlinkingFeedback && m_blinkingShader && m_blinkingShader->isValid()) {
|
2010-10-16 08:50:38 +00:00
|
|
|
const QColor& blinkingColor = BLINKING_COLORS[ FRAME_TO_BLINKING_COLOR[ m_frame ]];
|
2020-11-09 17:26:57 +00:00
|
|
|
ShaderManager::instance()->pushShader(m_blinkingShader.get());
|
2015-11-30 09:51:27 +00:00
|
|
|
m_blinkingShader->setUniform(GLShader::Color, blinkingColor);
|
2014-02-25 10:02:32 +00:00
|
|
|
} else {
|
2015-11-30 09:51:27 +00:00
|
|
|
ShaderManager::instance()->pushShader(ShaderTrait::MapTexture);
|
2011-01-06 12:47:42 +00:00
|
|
|
}
|
2015-11-30 09:51:27 +00:00
|
|
|
QMatrix4x4 mvp = data.projectionMatrix();
|
|
|
|
mvp.translate(m_currentGeometry.x(), m_currentGeometry.y());
|
|
|
|
ShaderManager::instance()->getBoundShader()->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
2011-01-30 14:34:42 +00:00
|
|
|
texture->render(m_currentGeometry, m_currentGeometry);
|
2015-11-30 09:51:27 +00:00
|
|
|
ShaderManager::instance()->popShader();
|
2010-10-16 08:50:38 +00:00
|
|
|
texture->unbind();
|
2011-01-30 14:34:42 +00:00
|
|
|
glDisable(GL_BLEND);
|
2010-10-16 08:50:38 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
|
|
|
void StartupFeedbackEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_active) {
|
2013-07-23 20:35:35 +00:00
|
|
|
m_dirtyRect = m_currentGeometry; // ensure the now dirty region is cleaned on the next pass
|
|
|
|
if (m_type == BlinkingFeedback || m_type == BouncingFeedback)
|
|
|
|
effects->addRepaint(m_dirtyRect); // we also have to trigger a repaint
|
2010-10-16 08:50:38 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2011-03-12 13:37:30 +00:00
|
|
|
void StartupFeedbackEffect::slotMouseChanged(const QPoint& pos, const QPoint& oldpos, Qt::MouseButtons buttons,
|
2011-01-30 14:34:42 +00:00
|
|
|
Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers)
|
|
|
|
{
|
|
|
|
Q_UNUSED(pos)
|
|
|
|
Q_UNUSED(oldpos)
|
|
|
|
Q_UNUSED(buttons)
|
|
|
|
Q_UNUSED(oldbuttons)
|
|
|
|
Q_UNUSED(modifiers)
|
|
|
|
Q_UNUSED(oldmodifiers)
|
|
|
|
if (m_active) {
|
2012-06-28 16:12:13 +00:00
|
|
|
m_dirtyRect |= m_currentGeometry;
|
|
|
|
m_currentGeometry = feedbackRect();
|
|
|
|
m_dirtyRect |= m_currentGeometry;
|
|
|
|
effects->addRepaint(m_dirtyRect);
|
2010-10-16 08:50:38 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void StartupFeedbackEffect::gotNewStartup(const KStartupInfoId& id, const KStartupInfoData& data)
|
|
|
|
{
|
2010-10-16 08:50:38 +00:00
|
|
|
const QString& icon = data.findIcon();
|
|
|
|
m_currentStartup = id;
|
|
|
|
m_startups[ id ] = icon;
|
2011-01-30 14:34:42 +00:00
|
|
|
start(icon);
|
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void StartupFeedbackEffect::gotRemoveStartup(const KStartupInfoId& id, const KStartupInfoData& data)
|
|
|
|
{
|
2011-04-30 11:17:26 +00:00
|
|
|
Q_UNUSED( data )
|
2011-01-30 14:34:42 +00:00
|
|
|
m_startups.remove(id);
|
2020-11-09 17:24:08 +00:00
|
|
|
if (m_startups.isEmpty()) {
|
2010-10-16 08:50:38 +00:00
|
|
|
m_currentStartup = KStartupInfoId(); // null
|
|
|
|
stop();
|
|
|
|
return;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
m_currentStartup = m_startups.begin().key();
|
|
|
|
start(m_startups[ m_currentStartup ]);
|
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void StartupFeedbackEffect::gotStartupChange(const KStartupInfoId& id, const KStartupInfoData& data)
|
|
|
|
{
|
|
|
|
if (m_currentStartup == id) {
|
2010-10-16 08:50:38 +00:00
|
|
|
const QString& icon = data.findIcon();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!icon.isEmpty() && icon != m_startups[ m_currentStartup ]) {
|
2010-10-16 08:50:38 +00:00
|
|
|
m_startups[ id ] = icon;
|
2011-01-30 14:34:42 +00:00
|
|
|
start(icon);
|
2010-10-16 08:50:38 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void StartupFeedbackEffect::start(const QString& icon)
|
|
|
|
{
|
2020-11-03 10:56:57 +00:00
|
|
|
if (m_type == NoFeedback || m_splashVisible)
|
2010-10-16 08:50:38 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!m_active)
|
2010-12-04 12:04:05 +00:00
|
|
|
effects->startMousePolling();
|
2010-10-16 08:50:38 +00:00
|
|
|
m_active = true;
|
2020-11-09 17:24:46 +00:00
|
|
|
|
|
|
|
// read details about the mouse-cursor theme define per default
|
|
|
|
KConfigGroup mousecfg(effects->inputConfig(), "Mouse");
|
|
|
|
m_cursorSize = mousecfg.readEntry("cursorSize", 24);
|
|
|
|
|
2019-11-01 21:40:35 +00:00
|
|
|
int iconSize = m_cursorSize / 1.5;
|
|
|
|
if (!iconSize) {
|
2020-02-28 19:09:26 +00:00
|
|
|
iconSize = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize);
|
2019-11-01 21:40:35 +00:00
|
|
|
}
|
2019-10-17 17:04:14 +00:00
|
|
|
// get ratio for bouncing cursor so we don't need to manually calculate the sizes for each icon size
|
|
|
|
if (m_type == BouncingFeedback)
|
|
|
|
m_bounceSizesRatio = iconSize / 16.0;
|
|
|
|
const QPixmap iconPixmap = QIcon::fromTheme(icon, QIcon::fromTheme(QStringLiteral("system-run"))).pixmap(iconSize);
|
|
|
|
prepareTextures(iconPixmap);
|
2012-08-08 17:51:00 +00:00
|
|
|
m_dirtyRect = m_currentGeometry = feedbackRect();
|
2013-07-23 20:35:35 +00:00
|
|
|
effects->addRepaint(m_dirtyRect);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
|
|
|
void StartupFeedbackEffect::stop()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_active)
|
2010-12-04 12:04:05 +00:00
|
|
|
effects->stopMousePolling();
|
2010-10-16 08:50:38 +00:00
|
|
|
m_active = false;
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
m_lastPresentTime = std::chrono::milliseconds::zero();
|
Better handling for making the compositing OpenGL context current
With QtQuick2 it's possible that the scene graph rendering context either
lives in an own thread or uses the main GUI thread. In the latter case
it's the same thread as our compositing OpenGL context lives in. This
means our basic assumption that between two rendering passes the context
stays current does not hold.
The code already ensured that before we start a rendering pass the
context is made current, but there are many more possible cases. If we
use OpenGL in areas not triggered by the rendering loop but in response
to other events the context needs to be made current. This includes the
loading and unloading of effects (some effects use OpenGL in the static
effect check, in the ctor and dtor), background loading of texture data,
lazy loading after first usage invoked by shortcut, etc. etc.
To properly handle these cases new methods are added to EffectsHandler
to make the compositing OpenGL context current. These calls delegate down
into the scene. On non-OpenGL scenes they are noop, but on OpenGL they go
into the backend and make the context current. In addition they ensure
that Qt doesn't think that it's QOpenGLContext is current by calling
doneCurrent() on the QOpenGLContext::currentContext(). This unfortunately
causes an additional call to makeCurrent with a null context, but there
is no other way to tell Qt - it doesn't notice when a different context
is made current with low level API calls. In the multi-threaded
architecture this doesn't matter as ::currentContext() returns null.
A short evaluation showed that a transition to QOpenGLContext doesn't
seem feasible. Qt only supports either GLX or EGL while KWin supports
both and when entering the transition phase for Wayland, it would become
extremely tricky if our native platform is X11, but we want a Wayland
EGL context. A future solution might be to have a "KWin-QPA plugin" which
uses either xcb or Wayland and hides everything from Qt.
The API documentation is extended to describe when the effects-framework
ensures that an OpenGL context is current. The effects are changed to
make the context current in cases where it's not guaranteed. This has
been done by looking for creation or deletion of GLTextures and Shaders.
If there are other OpenGL usages outside the rendering loop, ctor/dtor
this needs to be changed, too.
2013-11-22 14:05:36 +00:00
|
|
|
effects->makeOpenGLContextCurrent();
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(m_type) {
|
2010-10-16 08:50:38 +00:00
|
|
|
case BouncingFeedback:
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < 5; ++i) {
|
2020-11-09 17:26:57 +00:00
|
|
|
m_bouncingTextures[i].reset();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
break;
|
|
|
|
case BlinkingFeedback:
|
|
|
|
case PassiveFeedback:
|
2020-11-09 17:26:57 +00:00
|
|
|
m_texture.reset();
|
2010-10-16 08:50:38 +00:00
|
|
|
break;
|
|
|
|
case NoFeedback:
|
|
|
|
return; // don't want the full repaint
|
|
|
|
default:
|
|
|
|
break; // impossible
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void StartupFeedbackEffect::prepareTextures(const QPixmap& pix)
|
|
|
|
{
|
Better handling for making the compositing OpenGL context current
With QtQuick2 it's possible that the scene graph rendering context either
lives in an own thread or uses the main GUI thread. In the latter case
it's the same thread as our compositing OpenGL context lives in. This
means our basic assumption that between two rendering passes the context
stays current does not hold.
The code already ensured that before we start a rendering pass the
context is made current, but there are many more possible cases. If we
use OpenGL in areas not triggered by the rendering loop but in response
to other events the context needs to be made current. This includes the
loading and unloading of effects (some effects use OpenGL in the static
effect check, in the ctor and dtor), background loading of texture data,
lazy loading after first usage invoked by shortcut, etc. etc.
To properly handle these cases new methods are added to EffectsHandler
to make the compositing OpenGL context current. These calls delegate down
into the scene. On non-OpenGL scenes they are noop, but on OpenGL they go
into the backend and make the context current. In addition they ensure
that Qt doesn't think that it's QOpenGLContext is current by calling
doneCurrent() on the QOpenGLContext::currentContext(). This unfortunately
causes an additional call to makeCurrent with a null context, but there
is no other way to tell Qt - it doesn't notice when a different context
is made current with low level API calls. In the multi-threaded
architecture this doesn't matter as ::currentContext() returns null.
A short evaluation showed that a transition to QOpenGLContext doesn't
seem feasible. Qt only supports either GLX or EGL while KWin supports
both and when entering the transition phase for Wayland, it would become
extremely tricky if our native platform is X11, but we want a Wayland
EGL context. A future solution might be to have a "KWin-QPA plugin" which
uses either xcb or Wayland and hides everything from Qt.
The API documentation is extended to describe when the effects-framework
ensures that an OpenGL context is current. The effects are changed to
make the context current in cases where it's not guaranteed. This has
been done by looking for creation or deletion of GLTextures and Shaders.
If there are other OpenGL usages outside the rendering loop, ctor/dtor
this needs to be changed, too.
2013-11-22 14:05:36 +00:00
|
|
|
effects->makeOpenGLContextCurrent();
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(m_type) {
|
2010-10-16 08:50:38 +00:00
|
|
|
case BouncingFeedback:
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < 5; ++i) {
|
2020-11-09 17:26:57 +00:00
|
|
|
m_bouncingTextures[i].reset(new GLTexture(scalePixmap(pix, BOUNCE_SIZES[i])));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
break;
|
|
|
|
case BlinkingFeedback:
|
|
|
|
case PassiveFeedback:
|
2020-11-09 17:26:57 +00:00
|
|
|
m_texture.reset(new GLTexture(pix));
|
2010-10-16 08:50:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// for safety
|
|
|
|
m_active = false;
|
Provide expected presentation time to effects
Effects are given the interval between two consecutive frames. The main
flaw of this approach is that if the Compositor transitions from the idle
state to "active" state, i.e. when there is something to repaint,
effects may see a very large interval between the last painted frame and
the current. In order to address this issue, the Scene invalidates the
timer that is used to measure time between consecutive frames before the
Compositor is about to become idle.
While this works perfectly fine with Xinerama-style rendering, with per
screen rendering, determining whether the compositor is about to idle is
rather a tedious task mostly because a single output can't be used for
the test.
Furthermore, since the Compositor schedules pointless repaints just to
ensure that it's idle, it might take several attempts to figure out
whether the scene timer must be invalidated if you use (true) per screen
rendering.
Ideally, all effects should use a timeline helper that is aware of the
underlying render loop and its timings. However, this option is off the
table because it will involve a lot of work to implement it.
Alternative and much simpler option is to pass the expected presentation
time to effects rather than time between consecutive frames. This means
that effects are responsible for determining how much animation timelines
have to be advanced. Typically, an effect would have to store the
presentation timestamp provided in either prePaint{Screen,Window} and
use it in the subsequent prePaint{Screen,Window} call to estimate the
amount of time passed between the next and the last frames.
Unfortunately, this is an API incompatible change. However, it shouldn't
take a lot of work to port third-party binary effects, which don't use the
AnimationEffect class, to the new API. On the bright side, we no longer
need to be concerned about the Compositor getting idle.
We do still try to determine whether the Compositor is about to idle,
primarily, because the OpenGL render backend swaps buffers on present,
but that will change with the ongoing compositing timing rework.
2020-11-20 15:44:04 +00:00
|
|
|
m_lastPresentTime = std::chrono::milliseconds::zero();
|
2010-10-16 08:50:38 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QImage StartupFeedbackEffect::scalePixmap(const QPixmap& pm, const QSize& size) const
|
|
|
|
{
|
2012-08-27 09:14:03 +00:00
|
|
|
const QSize& adjustedSize = size * m_bounceSizesRatio;
|
|
|
|
QImage scaled = pm.toImage().scaled(adjustedSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (scaled.format() != QImage::Format_ARGB32_Premultiplied && scaled.format() != QImage::Format_ARGB32)
|
|
|
|
scaled = scaled.convertToFormat(QImage::Format_ARGB32);
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2012-08-27 09:14:03 +00:00
|
|
|
QImage result(20 * m_bounceSizesRatio, 20 * m_bounceSizesRatio, QImage::Format_ARGB32);
|
2011-01-30 14:34:42 +00:00
|
|
|
QPainter p(&result);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.fillRect(result.rect(), Qt::transparent);
|
2012-08-27 09:14:03 +00:00
|
|
|
p.drawImage((20 * m_bounceSizesRatio - adjustedSize.width()) / 2, (20*m_bounceSizesRatio - adjustedSize.height()) / 2, scaled, 0, 0, adjustedSize.width(), adjustedSize.height() * m_bounceSizesRatio);
|
2010-10-16 08:50:38 +00:00
|
|
|
return result;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
|
|
|
QRect StartupFeedbackEffect::feedbackRect() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-10-16 08:50:38 +00:00
|
|
|
int xDiff;
|
2014-03-16 09:16:52 +00:00
|
|
|
if (m_cursorSize <= 16)
|
2010-10-16 08:50:38 +00:00
|
|
|
xDiff = 8 + 7;
|
2014-03-16 09:16:52 +00:00
|
|
|
else if (m_cursorSize <= 32)
|
2010-10-16 08:50:38 +00:00
|
|
|
xDiff = 16 + 7;
|
2014-03-16 09:16:52 +00:00
|
|
|
else if (m_cursorSize <= 48)
|
2010-10-16 08:50:38 +00:00
|
|
|
xDiff = 24 + 7;
|
|
|
|
else
|
|
|
|
xDiff = 32 + 7;
|
|
|
|
int yDiff = xDiff;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
GLTexture* texture = nullptr;
|
2010-10-16 08:50:38 +00:00
|
|
|
int yOffset = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(m_type) {
|
|
|
|
case BouncingFeedback:
|
2020-11-09 17:26:57 +00:00
|
|
|
texture = m_bouncingTextures[ FRAME_TO_BOUNCE_TEXTURE[ m_frame ]].get();
|
2012-08-27 09:14:03 +00:00
|
|
|
yOffset = FRAME_TO_BOUNCE_YOFFSET[ m_frame ] * m_bounceSizesRatio;
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
|
|
|
case BlinkingFeedback: // fall through
|
|
|
|
case PassiveFeedback:
|
2020-11-09 17:26:57 +00:00
|
|
|
texture = m_texture.get();
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// nothing
|
|
|
|
break;
|
2010-10-16 08:50:38 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
const QPoint cursorPos = effects->cursorPos() + QPoint(xDiff, yDiff + yOffset);
|
2011-04-30 11:17:26 +00:00
|
|
|
QRect rect;
|
|
|
|
if( texture )
|
|
|
|
rect = QRect(cursorPos, texture->size());
|
2011-01-30 14:34:42 +00:00
|
|
|
return rect;
|
|
|
|
}
|
2010-10-16 08:50:38 +00:00
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool StartupFeedbackEffect::isActive() const
|
|
|
|
{
|
|
|
|
return m_active;
|
|
|
|
}
|
|
|
|
|
2010-10-16 08:50:38 +00:00
|
|
|
} // namespace
|