2009-07-23 19:06:50 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2009 Marco Martin notmart@gmail.com
|
[effects/slidingpopups] Don't crash when sliding virtual desktops
Summary:
If you switch virtual desktops while krunner is sliding in, then
depending on whether your distro strips assert statements away,
KWin can crash.
The reason why it crashes is the sliding popups effect tries to unref
deleted windows that it hasn't referenced before (if there is an active
full screen effect, then popups won't be slided out, which in its turn
means that we won't reference deleted windows). So, in the end, the
refcount of those windows can be -1. That triggers an assert statement
in the destructor of the Deleted class, which checks whether the
refcount is equal to 0.
Popups are not slided while there is an active full screen effect because
we don't know what the full screen effect does.
This patch adjusts the sliding popups effect so it stops all active
animations when user switches virtual desktops or when a full screen
effect kicks in. We need to do that so the effect won't try to
unreference windows in postPaintWindow.
Visually, it doesn't look quite nice, but for now that's good enough.
A proper fix would be more complex: we would need to make sure that
full screen effects ignore sliding popups (and also maybe docks) and
perform some input redirection.
BUG: 400170
FIXED-IN: 5.14.4
Test Plan: I'm not able anymore to reproduce bug 400170.
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: davidedmundson, graesslin, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16731
2018-11-05 12:59:42 +00:00
|
|
|
Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com>
|
2009-07-23 19:06:50 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include "slidingpopups.h"
|
2016-11-16 08:02:44 +00:00
|
|
|
#include "slidingpopupsconfig.h"
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2014-02-10 16:59:16 +00:00
|
|
|
#include <QApplication>
|
2017-11-08 10:23:00 +00:00
|
|
|
#include <QFontMetrics>
|
2019-01-13 16:50:32 +00:00
|
|
|
#include <QWindow>
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2015-09-14 14:39:39 +00:00
|
|
|
#include <KWayland/Server/surface_interface.h>
|
|
|
|
#include <KWayland/Server/slide_interface.h>
|
|
|
|
#include <KWayland/Server/display.h>
|
|
|
|
|
2019-01-13 16:50:32 +00:00
|
|
|
#include <KWindowEffects>
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(KWindowEffects::SlideFromLocation)
|
|
|
|
|
2009-07-23 19:06:50 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
SlidingPopupsEffect::SlidingPopupsEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-12-02 19:27:43 +00:00
|
|
|
initConfig<SlidingPopupsConfig>();
|
2015-09-14 14:39:39 +00:00
|
|
|
KWayland::Server::Display *display = effects->waylandDisplay();
|
|
|
|
if (display) {
|
|
|
|
display->createSlideManager(this)->create();
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:10:04 +00:00
|
|
|
m_slideLength = QFontMetrics(qApp->font()).height() * 8;
|
2014-02-10 16:59:16 +00:00
|
|
|
|
2018-08-14 10:10:04 +00:00
|
|
|
m_atom = effects->announceSupportProperty("_KDE_SLIDE", this);
|
2018-08-14 09:51:56 +00:00
|
|
|
connect(effects, &EffectsHandler::windowAdded, this, &SlidingPopupsEffect::slotWindowAdded);
|
2018-07-13 12:08:31 +00:00
|
|
|
connect(effects, &EffectsHandler::windowClosed, this, &SlidingPopupsEffect::slideOut);
|
2018-08-14 09:51:56 +00:00
|
|
|
connect(effects, &EffectsHandler::windowDeleted, this, &SlidingPopupsEffect::slotWindowDeleted);
|
|
|
|
connect(effects, &EffectsHandler::propertyNotify, this, &SlidingPopupsEffect::slotPropertyNotify);
|
2018-07-13 12:08:31 +00:00
|
|
|
connect(effects, &EffectsHandler::windowShown, this, &SlidingPopupsEffect::slideIn);
|
|
|
|
connect(effects, &EffectsHandler::windowHidden, this, &SlidingPopupsEffect::slideOut);
|
2017-09-10 14:51:18 +00:00
|
|
|
connect(effects, &EffectsHandler::xcbConnectionChanged, this,
|
|
|
|
[this] {
|
2018-08-14 10:10:04 +00:00
|
|
|
m_atom = effects->announceSupportProperty(QByteArrayLiteral("_KDE_SLIDE"), this);
|
2017-09-10 14:51:18 +00:00
|
|
|
}
|
|
|
|
);
|
[effects/slidingpopups] Don't crash when sliding virtual desktops
Summary:
If you switch virtual desktops while krunner is sliding in, then
depending on whether your distro strips assert statements away,
KWin can crash.
The reason why it crashes is the sliding popups effect tries to unref
deleted windows that it hasn't referenced before (if there is an active
full screen effect, then popups won't be slided out, which in its turn
means that we won't reference deleted windows). So, in the end, the
refcount of those windows can be -1. That triggers an assert statement
in the destructor of the Deleted class, which checks whether the
refcount is equal to 0.
Popups are not slided while there is an active full screen effect because
we don't know what the full screen effect does.
This patch adjusts the sliding popups effect so it stops all active
animations when user switches virtual desktops or when a full screen
effect kicks in. We need to do that so the effect won't try to
unreference windows in postPaintWindow.
Visually, it doesn't look quite nice, but for now that's good enough.
A proper fix would be more complex: we would need to make sure that
full screen effects ignore sliding popups (and also maybe docks) and
perform some input redirection.
BUG: 400170
FIXED-IN: 5.14.4
Test Plan: I'm not able anymore to reproduce bug 400170.
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: davidedmundson, graesslin, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16731
2018-11-05 12:59:42 +00:00
|
|
|
connect(effects, qOverload<int, int, EffectWindow *>(&EffectsHandler::desktopChanged),
|
|
|
|
this, &SlidingPopupsEffect::stopAnimations);
|
|
|
|
connect(effects, &EffectsHandler::activeFullScreenEffectChanged,
|
|
|
|
this, &SlidingPopupsEffect::stopAnimations);
|
|
|
|
|
2011-03-19 10:46:34 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
|
|
|
SlidingPopupsEffect::~SlidingPopupsEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2017-11-23 09:34:06 +00:00
|
|
|
bool SlidingPopupsEffect::supported()
|
|
|
|
{
|
|
|
|
return effects->animationsSupported();
|
|
|
|
}
|
|
|
|
|
2011-03-19 10:46:34 +00:00
|
|
|
void SlidingPopupsEffect::reconfigure(ReconfigureFlags flags)
|
|
|
|
{
|
|
|
|
Q_UNUSED(flags)
|
2016-11-16 08:02:44 +00:00
|
|
|
SlidingPopupsConfig::self()->read();
|
2018-07-15 07:57:35 +00:00
|
|
|
m_slideInDuration = std::chrono::milliseconds(
|
2018-06-29 20:26:48 +00:00
|
|
|
static_cast<int>(animationTime(SlidingPopupsConfig::slideInTime() != 0 ? SlidingPopupsConfig::slideInTime() : 150)));
|
2018-07-15 07:57:35 +00:00
|
|
|
m_slideOutDuration = std::chrono::milliseconds(
|
2018-06-29 20:26:48 +00:00
|
|
|
static_cast<int>(animationTime(SlidingPopupsConfig::slideOutTime() != 0 ? SlidingPopupsConfig::slideOutTime() : 250)));
|
2018-07-13 12:08:31 +00:00
|
|
|
|
|
|
|
auto animationIt = m_animations.begin();
|
|
|
|
while (animationIt != m_animations.end()) {
|
|
|
|
const auto duration = ((*animationIt).kind == AnimationKind::In)
|
2018-07-15 07:57:35 +00:00
|
|
|
? m_slideInDuration
|
|
|
|
: m_slideOutDuration;
|
2018-07-13 12:08:31 +00:00
|
|
|
(*animationIt).timeLine.setDuration(duration);
|
|
|
|
++animationIt;
|
2011-03-19 10:46:34 +00:00
|
|
|
}
|
2018-07-13 12:08:31 +00:00
|
|
|
|
2018-07-15 07:57:35 +00:00
|
|
|
auto dataIt = m_animationsData.begin();
|
|
|
|
while (dataIt != m_animationsData.end()) {
|
|
|
|
(*dataIt).slideInDuration = m_slideInDuration;
|
|
|
|
(*dataIt).slideOutDuration = m_slideOutDuration;
|
|
|
|
++dataIt;
|
2011-03-19 10:46:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-14 10:10:04 +00:00
|
|
|
void SlidingPopupsEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-07-13 12:08:31 +00:00
|
|
|
auto animationIt = m_animations.find(w);
|
|
|
|
if (animationIt == m_animations.end()) {
|
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
return;
|
|
|
|
}
|
2009-07-27 13:27:16 +00:00
|
|
|
|
2018-07-13 12:08:31 +00:00
|
|
|
(*animationIt).timeLine.update(std::chrono::milliseconds(time));
|
|
|
|
data.setTransformed();
|
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED | EffectWindow::PAINT_DISABLED_BY_DELETE);
|
2011-12-10 11:31:06 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2018-08-14 10:10:04 +00:00
|
|
|
void SlidingPopupsEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-07-13 12:08:31 +00:00
|
|
|
auto animationIt = m_animations.constFind(w);
|
|
|
|
if (animationIt == m_animations.constEnd()) {
|
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2018-07-15 07:57:35 +00:00
|
|
|
const AnimationData &animData = m_animationsData[w];
|
2018-08-14 10:10:04 +00:00
|
|
|
const int slideLength = (animData.slideLength > 0) ? animData.slideLength : m_slideLength;
|
2014-02-07 14:18:45 +00:00
|
|
|
|
2019-01-03 15:57:32 +00:00
|
|
|
const QRect screenRect = effects->clientArea(FullScreenArea, w->screen(), effects->currentDesktop());
|
2018-07-13 12:08:31 +00:00
|
|
|
int splitPoint = 0;
|
|
|
|
const QRect geo = w->expandedGeometry();
|
|
|
|
const qreal t = (*animationIt).timeLine.value();
|
|
|
|
|
2018-08-14 10:10:04 +00:00
|
|
|
switch (animData.location) {
|
2018-07-15 07:57:35 +00:00
|
|
|
case Location::Left:
|
2018-07-13 12:08:31 +00:00
|
|
|
if (slideLength < geo.width()) {
|
|
|
|
data.multiplyOpacity(t);
|
|
|
|
}
|
|
|
|
data.translate(-interpolate(qMin(geo.width(), slideLength), 0.0, t));
|
2018-07-15 07:57:35 +00:00
|
|
|
splitPoint = geo.width() - (geo.x() + geo.width() - screenRect.x() - animData.offset);
|
2018-07-13 12:08:31 +00:00
|
|
|
region = QRegion(geo.x() + splitPoint, geo.y(), geo.width() - splitPoint, geo.height());
|
|
|
|
break;
|
2018-07-15 07:57:35 +00:00
|
|
|
case Location::Top:
|
2018-07-13 12:08:31 +00:00
|
|
|
if (slideLength < geo.height()) {
|
|
|
|
data.multiplyOpacity(t);
|
|
|
|
}
|
|
|
|
data.translate(0.0, -interpolate(qMin(geo.height(), slideLength), 0.0, t));
|
2018-07-15 07:57:35 +00:00
|
|
|
splitPoint = geo.height() - (geo.y() + geo.height() - screenRect.y() - animData.offset);
|
2018-07-13 12:08:31 +00:00
|
|
|
region = QRegion(geo.x(), geo.y() + splitPoint, geo.width(), geo.height() - splitPoint);
|
|
|
|
break;
|
2018-07-15 07:57:35 +00:00
|
|
|
case Location::Right:
|
2018-07-13 12:08:31 +00:00
|
|
|
if (slideLength < geo.width()) {
|
|
|
|
data.multiplyOpacity(t);
|
2009-07-23 19:06:50 +00:00
|
|
|
}
|
2018-07-13 12:08:31 +00:00
|
|
|
data.translate(interpolate(qMin(geo.width(), slideLength), 0.0, t));
|
2018-07-15 07:57:35 +00:00
|
|
|
splitPoint = screenRect.x() + screenRect.width() - geo.x() - animData.offset;
|
2018-07-13 12:08:31 +00:00
|
|
|
region = QRegion(geo.x(), geo.y(), splitPoint, geo.height());
|
|
|
|
break;
|
2018-07-15 07:57:35 +00:00
|
|
|
case Location::Bottom:
|
2018-07-13 12:08:31 +00:00
|
|
|
default:
|
|
|
|
if (slideLength < geo.height()) {
|
|
|
|
data.multiplyOpacity(t);
|
|
|
|
}
|
|
|
|
data.translate(0.0, interpolate(qMin(geo.height(), slideLength), 0.0, t));
|
2018-07-15 07:57:35 +00:00
|
|
|
splitPoint = screenRect.y() + screenRect.height() - geo.y() - animData.offset;
|
2018-07-13 12:08:31 +00:00
|
|
|
region = QRegion(geo.x(), geo.y(), geo.width(), splitPoint);
|
2009-07-23 19:06:50 +00:00
|
|
|
}
|
|
|
|
|
2011-12-10 11:31:06 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 10:10:04 +00:00
|
|
|
void SlidingPopupsEffect::postPaintWindow(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-07-13 12:08:31 +00:00
|
|
|
auto animationIt = m_animations.find(w);
|
|
|
|
if (animationIt != m_animations.end()) {
|
|
|
|
if ((*animationIt).timeLine.done()) {
|
|
|
|
if (w->isDeleted()) {
|
|
|
|
w->unrefWindow();
|
|
|
|
} else {
|
|
|
|
w->setData(WindowForceBackgroundContrastRole, QVariant());
|
|
|
|
w->setData(WindowForceBlurRole, QVariant());
|
|
|
|
}
|
|
|
|
m_animations.erase(animationIt);
|
|
|
|
}
|
|
|
|
w->addRepaintFull();
|
2011-03-18 17:06:03 +00:00
|
|
|
}
|
2018-07-13 12:08:31 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->postPaintWindow(w);
|
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2011-02-25 21:06:02 +00:00
|
|
|
void SlidingPopupsEffect::slotWindowAdded(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2015-09-14 14:39:39 +00:00
|
|
|
//X11
|
2018-08-14 10:10:04 +00:00
|
|
|
if (m_atom != XCB_ATOM_NONE) {
|
|
|
|
slotPropertyNotify(w, m_atom);
|
2017-09-10 14:51:18 +00:00
|
|
|
}
|
2015-09-14 14:39:39 +00:00
|
|
|
|
|
|
|
//Wayland
|
|
|
|
if (auto surf = w->surface()) {
|
|
|
|
slotWaylandSlideOnShowChanged(w);
|
|
|
|
connect(surf, &KWayland::Server::SurfaceInterface::slideOnShowHideChanged, this, [this, surf] {
|
|
|
|
slotWaylandSlideOnShowChanged(effects->findWindow(surf));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-13 16:50:32 +00:00
|
|
|
if (auto internal = w->internalWindow()) {
|
|
|
|
internal->installEventFilter(this);
|
|
|
|
setupInternalWindowSlide(w);
|
|
|
|
}
|
|
|
|
|
2018-07-13 12:08:31 +00:00
|
|
|
slideIn(w);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2018-08-14 10:10:04 +00:00
|
|
|
void SlidingPopupsEffect::slotWindowDeleted(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-07-13 12:08:31 +00:00
|
|
|
m_animations.remove(w);
|
2018-07-15 07:57:35 +00:00
|
|
|
m_animationsData.remove(w);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2018-08-15 14:30:02 +00:00
|
|
|
void SlidingPopupsEffect::slotPropertyNotify(EffectWindow *w, long atom)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2018-08-15 14:30:02 +00:00
|
|
|
if (!w || atom != m_atom || m_atom == XCB_ATOM_NONE) {
|
2009-07-23 19:06:50 +00:00
|
|
|
return;
|
2018-08-14 10:10:04 +00:00
|
|
|
}
|
2009-07-23 19:06:50 +00:00
|
|
|
|
2018-08-15 14:30:02 +00:00
|
|
|
// _KDE_SLIDE atom format(each field is an uint32_t):
|
|
|
|
// <offset> <location> [<slide in duration>] [<slide out duration>] [<slide length>]
|
|
|
|
//
|
|
|
|
// If offset is equal to -1, this effect will decide what offset to use
|
|
|
|
// given edge of the screen, from which the window has to slide.
|
|
|
|
//
|
|
|
|
// If slide in duration is equal to 0 milliseconds, the default slide in
|
|
|
|
// duration will be used. Same with the slide out duration.
|
|
|
|
//
|
|
|
|
// NOTE: If only slide in duration has been provided, then it will be
|
|
|
|
// also used as slide out duration. I.e. if you provided only slide in
|
|
|
|
// duration, then slide in duration == slide out duration.
|
|
|
|
|
|
|
|
const QByteArray rawAtomData = w->readProperty(m_atom, m_atom, 32);
|
|
|
|
|
|
|
|
if (rawAtomData.isEmpty()) {
|
2010-11-30 20:03:03 +00:00
|
|
|
// Property was removed, thus also remove the effect for window
|
2017-03-28 15:51:00 +00:00
|
|
|
if (w->data(WindowClosedGrabRole).value<void *>() == this) {
|
|
|
|
w->setData(WindowClosedGrabRole, QVariant());
|
|
|
|
}
|
2018-07-13 12:08:31 +00:00
|
|
|
m_animations.remove(w);
|
2018-07-15 07:57:35 +00:00
|
|
|
m_animationsData.remove(w);
|
2009-07-23 19:06:50 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-09-09 10:05:52 +00:00
|
|
|
|
2018-08-15 14:30:02 +00:00
|
|
|
// Offset and location are required.
|
|
|
|
if (static_cast<size_t>(rawAtomData.size()) < sizeof(uint32_t) * 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto *atomData = reinterpret_cast<const uint32_t *>(rawAtomData.data());
|
2018-07-15 07:57:35 +00:00
|
|
|
AnimationData &animData = m_animationsData[w];
|
2018-08-15 14:30:02 +00:00
|
|
|
animData.offset = atomData[0];
|
2018-07-15 07:57:35 +00:00
|
|
|
|
2018-08-15 14:30:02 +00:00
|
|
|
switch (atomData[1]) {
|
2018-07-15 07:57:35 +00:00
|
|
|
case 0: // West
|
|
|
|
animData.location = Location::Left;
|
|
|
|
break;
|
|
|
|
case 1: // North
|
|
|
|
animData.location = Location::Top;
|
|
|
|
break;
|
|
|
|
case 2: // East
|
|
|
|
animData.location = Location::Right;
|
|
|
|
break;
|
|
|
|
case 3: // South
|
|
|
|
default:
|
|
|
|
animData.location = Location::Bottom;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-08-15 14:30:02 +00:00
|
|
|
if (static_cast<size_t>(rawAtomData.size()) >= sizeof(uint32_t) * 3) {
|
|
|
|
animData.slideInDuration = std::chrono::milliseconds(atomData[2]);
|
|
|
|
if (static_cast<size_t>(rawAtomData.size()) >= sizeof(uint32_t) * 4) {
|
|
|
|
animData.slideOutDuration = std::chrono::milliseconds(atomData[3]);
|
2018-08-14 10:10:04 +00:00
|
|
|
} else {
|
2018-08-15 14:30:02 +00:00
|
|
|
animData.slideOutDuration = animData.slideInDuration;
|
2018-08-14 10:10:04 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2018-07-15 07:57:35 +00:00
|
|
|
animData.slideInDuration = m_slideInDuration;
|
|
|
|
animData.slideOutDuration = m_slideOutDuration;
|
2009-07-23 19:06:50 +00:00
|
|
|
}
|
2018-07-15 07:57:35 +00:00
|
|
|
|
2018-08-15 14:30:02 +00:00
|
|
|
if (static_cast<size_t>(rawAtomData.size()) >= sizeof(uint32_t) * 5) {
|
|
|
|
animData.slideLength = atomData[4];
|
|
|
|
} else {
|
|
|
|
animData.slideLength = 0;
|
|
|
|
}
|
|
|
|
|
2015-09-14 14:39:39 +00:00
|
|
|
setupAnimData(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlidingPopupsEffect::setupAnimData(EffectWindow *w)
|
|
|
|
{
|
2011-12-10 11:31:06 +00:00
|
|
|
const QRect screenRect = effects->clientArea(FullScreenArea, w->screen(), effects->currentDesktop());
|
2018-07-13 07:08:29 +00:00
|
|
|
const QRect windowGeo = w->geometry();
|
2018-07-15 07:57:35 +00:00
|
|
|
AnimationData &animData = m_animationsData[w];
|
|
|
|
|
|
|
|
if (animData.offset == -1) {
|
|
|
|
switch (animData.location) {
|
|
|
|
case Location::Left:
|
|
|
|
animData.offset = qMax(windowGeo.left() - screenRect.left(), 0);
|
2011-12-10 11:31:06 +00:00
|
|
|
break;
|
2018-07-15 07:57:35 +00:00
|
|
|
case Location::Top:
|
|
|
|
animData.offset = qMax(windowGeo.top() - screenRect.top(), 0);
|
2011-12-10 11:31:06 +00:00
|
|
|
break;
|
2018-07-15 07:57:35 +00:00
|
|
|
case Location::Right:
|
|
|
|
animData.offset = qMax(screenRect.right() - windowGeo.right(), 0);
|
2011-12-10 11:31:06 +00:00
|
|
|
break;
|
2018-07-15 07:57:35 +00:00
|
|
|
case Location::Bottom:
|
2011-12-10 11:31:06 +00:00
|
|
|
default:
|
2018-07-15 07:57:35 +00:00
|
|
|
animData.offset = qMax(screenRect.bottom() - windowGeo.bottom(), 0);
|
2011-12-10 11:31:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// sanitize
|
2018-07-15 07:57:35 +00:00
|
|
|
switch (animData.location) {
|
|
|
|
case Location::Left:
|
|
|
|
animData.offset = qMax(windowGeo.left() - screenRect.left(), animData.offset);
|
2011-12-10 11:31:06 +00:00
|
|
|
break;
|
2018-07-15 07:57:35 +00:00
|
|
|
case Location::Top:
|
|
|
|
animData.offset = qMax(windowGeo.top() - screenRect.top(), animData.offset);
|
2011-12-10 11:31:06 +00:00
|
|
|
break;
|
2018-07-15 07:57:35 +00:00
|
|
|
case Location::Right:
|
|
|
|
animData.offset = qMax(screenRect.right() - windowGeo.right(), animData.offset);
|
2011-12-10 11:31:06 +00:00
|
|
|
break;
|
2018-07-15 07:57:35 +00:00
|
|
|
case Location::Bottom:
|
2011-12-10 11:31:06 +00:00
|
|
|
default:
|
2018-07-15 07:57:35 +00:00
|
|
|
animData.offset = qMax(screenRect.bottom() - windowGeo.bottom(), animData.offset);
|
2011-12-10 11:31:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-07-13 07:08:29 +00:00
|
|
|
|
2018-08-15 14:30:02 +00:00
|
|
|
animData.slideInDuration = (animData.slideInDuration.count() != 0)
|
|
|
|
? animData.slideInDuration
|
|
|
|
: m_slideInDuration;
|
|
|
|
|
|
|
|
animData.slideOutDuration = (animData.slideOutDuration.count() != 0)
|
|
|
|
? animData.slideOutDuration
|
|
|
|
: m_slideOutDuration;
|
|
|
|
|
slidingpopups claim windowClosedGrabRole earlier
This seems like a more proper fix for the flickering issue in the
sliding popups effect. The problem is that slidingpopups grabs the
window in windowClosed, the fade effect checks it there, which makes
it racy.
In my tests, I've not seen this problem with the WindowAddedGrab, but
as far as I understand, the problem may well be present there as well.
(And my proposed trick doesn't work.) I've not seen this happening in my
debugging, however. The problem there is also less visible since the
transparency curves go into the same direction, and are more "in line
with each other".
So, fix: Move the setData(WindowClosedGrabRole, ...) call from
windowClosed into windowAdded, which makes sure it's set whenever the
window goes away.
REVIEW:115903
BUG:329991
2014-02-20 13:38:36 +00:00
|
|
|
// Grab the window, so other windowClosed effects will ignore it
|
|
|
|
w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-08-27 09:21:31 +00:00
|
|
|
|
2015-09-14 14:39:39 +00:00
|
|
|
void SlidingPopupsEffect::slotWaylandSlideOnShowChanged(EffectWindow* w)
|
|
|
|
{
|
|
|
|
if (!w) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KWayland::Server::SurfaceInterface *surf = w->surface();
|
|
|
|
if (!surf) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surf->slideOnShowHide()) {
|
2018-07-15 07:57:35 +00:00
|
|
|
AnimationData &animData = m_animationsData[w];
|
|
|
|
|
|
|
|
animData.offset = surf->slideOnShowHide()->offset();
|
2015-09-14 14:39:39 +00:00
|
|
|
|
|
|
|
switch (surf->slideOnShowHide()->location()) {
|
|
|
|
case KWayland::Server::SlideInterface::Location::Top:
|
2018-07-15 07:57:35 +00:00
|
|
|
animData.location = Location::Top;
|
2015-09-14 14:39:39 +00:00
|
|
|
break;
|
|
|
|
case KWayland::Server::SlideInterface::Location::Left:
|
2018-07-15 07:57:35 +00:00
|
|
|
animData.location = Location::Left;
|
2015-09-14 14:39:39 +00:00
|
|
|
break;
|
|
|
|
case KWayland::Server::SlideInterface::Location::Right:
|
2018-07-15 07:57:35 +00:00
|
|
|
animData.location = Location::Right;
|
2015-09-14 14:39:39 +00:00
|
|
|
break;
|
|
|
|
case KWayland::Server::SlideInterface::Location::Bottom:
|
|
|
|
default:
|
2018-07-15 07:57:35 +00:00
|
|
|
animData.location = Location::Bottom;
|
2015-09-14 14:39:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
animData.slideLength = 0;
|
2018-07-15 07:57:35 +00:00
|
|
|
animData.slideInDuration = m_slideInDuration;
|
|
|
|
animData.slideOutDuration = m_slideOutDuration;
|
2015-09-14 14:39:39 +00:00
|
|
|
|
|
|
|
setupAnimData(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 16:50:32 +00:00
|
|
|
void SlidingPopupsEffect::setupInternalWindowSlide(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (!w) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto internal = w->internalWindow();
|
|
|
|
if (!internal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QVariant slideProperty = internal->property("kwin_slide");
|
|
|
|
if (!slideProperty.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AnimationData &animData = m_animationsData[w];
|
|
|
|
switch (slideProperty.value<KWindowEffects::SlideFromLocation>()) {
|
|
|
|
case KWindowEffects::BottomEdge:
|
|
|
|
animData.location = Location::Bottom;
|
|
|
|
break;
|
|
|
|
case KWindowEffects::TopEdge:
|
|
|
|
animData.location = Location::Top;
|
|
|
|
break;
|
|
|
|
case KWindowEffects::RightEdge:
|
|
|
|
animData.location = Location::Right;
|
|
|
|
break;
|
|
|
|
case KWindowEffects::LeftEdge:
|
|
|
|
animData.location = Location::Left;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool intOk = false;
|
|
|
|
animData.offset = internal->property("kwin_slide_offset").toInt(&intOk);
|
|
|
|
if (!intOk) {
|
|
|
|
animData.offset = -1;
|
|
|
|
}
|
|
|
|
animData.slideLength = 0;
|
|
|
|
animData.slideInDuration = m_slideInDuration;
|
|
|
|
animData.slideOutDuration = m_slideOutDuration;
|
|
|
|
|
|
|
|
setupAnimData(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SlidingPopupsEffect::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
{
|
|
|
|
auto internal = qobject_cast<QWindow*>(watched);
|
|
|
|
if (internal && event->type() == QEvent::DynamicPropertyChange) {
|
|
|
|
QDynamicPropertyChangeEvent *pe = static_cast<QDynamicPropertyChangeEvent*>(event);
|
|
|
|
if (pe->propertyName() == "kwin_slide" || pe->propertyName() == "kwin_slide_offset") {
|
|
|
|
if (auto w = effects->findWindow(internal)) {
|
|
|
|
setupInternalWindowSlide(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-13 12:08:31 +00:00
|
|
|
void SlidingPopupsEffect::slideIn(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (effects->activeFullScreenEffect()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!w->isVisible()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-15 07:57:35 +00:00
|
|
|
auto dataIt = m_animationsData.constFind(w);
|
|
|
|
if (dataIt == m_animationsData.constEnd()) {
|
2018-07-13 12:08:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Animation &animation = m_animations[w];
|
|
|
|
animation.kind = AnimationKind::In;
|
|
|
|
animation.timeLine.setDirection(TimeLine::Forward);
|
2018-07-15 07:57:35 +00:00
|
|
|
animation.timeLine.setDuration((*dataIt).slideInDuration);
|
2018-07-13 12:08:31 +00:00
|
|
|
animation.timeLine.setEasingCurve(QEasingCurve::InOutSine);
|
|
|
|
|
2018-09-20 17:35:01 +00:00
|
|
|
// If the opposite animation (Out) was active and it had shorter duration,
|
|
|
|
// at this point, the timeline can end up in the "done" state. Thus, we have
|
|
|
|
// to reset it.
|
|
|
|
if (animation.timeLine.done()) {
|
|
|
|
animation.timeLine.reset();
|
|
|
|
}
|
|
|
|
|
2018-07-13 12:08:31 +00:00
|
|
|
w->setData(WindowAddedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
|
|
|
|
w->setData(WindowForceBackgroundContrastRole, QVariant(true));
|
|
|
|
w->setData(WindowForceBlurRole, QVariant(true));
|
|
|
|
|
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SlidingPopupsEffect::slideOut(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (effects->activeFullScreenEffect()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!w->isVisible()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-15 07:57:35 +00:00
|
|
|
auto dataIt = m_animationsData.constFind(w);
|
|
|
|
if (dataIt == m_animationsData.constEnd()) {
|
2018-07-13 12:08:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w->isDeleted()) {
|
|
|
|
w->refWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
Animation &animation = m_animations[w];
|
|
|
|
animation.kind = AnimationKind::Out;
|
|
|
|
animation.timeLine.setDirection(TimeLine::Backward);
|
2018-07-15 07:57:35 +00:00
|
|
|
animation.timeLine.setDuration((*dataIt).slideOutDuration);
|
2018-07-13 12:08:31 +00:00
|
|
|
animation.timeLine.setEasingCurve(QEasingCurve::InOutSine);
|
|
|
|
|
2018-09-20 17:35:01 +00:00
|
|
|
// If the opposite animation (In) was active and it had shorter duration,
|
|
|
|
// at this point, the timeline can end up in the "done" state. Thus, we have
|
|
|
|
// to reset it.
|
|
|
|
if (animation.timeLine.done()) {
|
|
|
|
animation.timeLine.reset();
|
|
|
|
}
|
|
|
|
|
2018-07-13 12:08:31 +00:00
|
|
|
w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this)));
|
|
|
|
w->setData(WindowForceBackgroundContrastRole, QVariant(true));
|
|
|
|
w->setData(WindowForceBlurRole, QVariant(true));
|
|
|
|
|
|
|
|
w->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
[effects/slidingpopups] Don't crash when sliding virtual desktops
Summary:
If you switch virtual desktops while krunner is sliding in, then
depending on whether your distro strips assert statements away,
KWin can crash.
The reason why it crashes is the sliding popups effect tries to unref
deleted windows that it hasn't referenced before (if there is an active
full screen effect, then popups won't be slided out, which in its turn
means that we won't reference deleted windows). So, in the end, the
refcount of those windows can be -1. That triggers an assert statement
in the destructor of the Deleted class, which checks whether the
refcount is equal to 0.
Popups are not slided while there is an active full screen effect because
we don't know what the full screen effect does.
This patch adjusts the sliding popups effect so it stops all active
animations when user switches virtual desktops or when a full screen
effect kicks in. We need to do that so the effect won't try to
unreference windows in postPaintWindow.
Visually, it doesn't look quite nice, but for now that's good enough.
A proper fix would be more complex: we would need to make sure that
full screen effects ignore sliding popups (and also maybe docks) and
perform some input redirection.
BUG: 400170
FIXED-IN: 5.14.4
Test Plan: I'm not able anymore to reproduce bug 400170.
Reviewers: #kwin, graesslin
Reviewed By: #kwin, graesslin
Subscribers: davidedmundson, graesslin, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16731
2018-11-05 12:59:42 +00:00
|
|
|
void SlidingPopupsEffect::stopAnimations()
|
|
|
|
{
|
|
|
|
for (auto it = m_animations.constBegin(); it != m_animations.constEnd(); ++it) {
|
|
|
|
EffectWindow *w = it.key();
|
|
|
|
|
|
|
|
if (w->isDeleted()) {
|
|
|
|
w->unrefWindow();
|
|
|
|
} else {
|
|
|
|
w->setData(WindowForceBackgroundContrastRole, QVariant());
|
|
|
|
w->setData(WindowForceBlurRole, QVariant());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_animations.clear();
|
|
|
|
}
|
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool SlidingPopupsEffect::isActive() const
|
|
|
|
{
|
2018-07-13 12:08:31 +00:00
|
|
|
return !m_animations.isEmpty();
|
2011-08-27 09:21:31 +00:00
|
|
|
}
|
|
|
|
|
2009-07-23 19:06:50 +00:00
|
|
|
} // namespace
|