2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2008-01-24 10:36:32 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2008, 2009 Martin Gräßlin <mgraesslin@kde.org>
|
2008-01-24 10:36:32 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2008-01-24 10:36:32 +00:00
|
|
|
#include "flipswitch.h"
|
2012-09-14 12:35:18 +00:00
|
|
|
// KConfigSkeleton
|
|
|
|
#include "flipswitchconfig.h"
|
2008-01-24 10:36:32 +00:00
|
|
|
|
2013-08-14 19:13:12 +00:00
|
|
|
#include <QAction>
|
2008-01-24 10:36:32 +00:00
|
|
|
#include <kwinconfig.h>
|
2011-03-13 15:56:25 +00:00
|
|
|
#include <QKeyEvent>
|
2008-01-24 10:36:32 +00:00
|
|
|
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KGlobalAccel>
|
|
|
|
#include <KLocalizedString>
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2008-01-24 10:36:32 +00:00
|
|
|
#include <kwinglutils.h>
|
|
|
|
|
2015-03-06 03:41:04 +00:00
|
|
|
#include <cmath>
|
2008-01-24 10:36:32 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
FlipSwitchEffect::FlipSwitchEffect()
|
2017-03-17 15:17:36 +00:00
|
|
|
: m_selectedWindow(nullptr)
|
2020-09-09 13:03:02 +00:00
|
|
|
, m_currentAnimationEasingCurve(QEasingCurve::InOutSine)
|
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_active(false)
|
|
|
|
, m_start(false)
|
|
|
|
, m_stop(false)
|
|
|
|
, m_animation(false)
|
|
|
|
, m_hasKeyboardGrab(false)
|
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
|
|
|
, m_captionFrame(nullptr)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-12-02 19:27:43 +00:00
|
|
|
initConfig<FlipSwitchConfig>();
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
// Caption frame
|
2011-01-30 14:34:42 +00:00
|
|
|
m_captionFont.setBold(true);
|
|
|
|
m_captionFont.setPointSize(m_captionFont.pointSize() * 2);
|
|
|
|
|
2013-12-10 10:45:33 +00:00
|
|
|
QAction* flipSwitchCurrentAction = new QAction(this);
|
|
|
|
flipSwitchCurrentAction->setObjectName(QStringLiteral("FlipSwitchCurrent"));
|
2013-08-14 19:13:12 +00:00
|
|
|
flipSwitchCurrentAction->setText(i18n("Toggle Flip Switch (Current desktop)"));
|
|
|
|
KGlobalAccel::self()->setShortcut(flipSwitchCurrentAction, QList<QKeySequence>());
|
|
|
|
m_shortcutCurrent = KGlobalAccel::self()->shortcut(flipSwitchCurrentAction);
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(QKeySequence(), flipSwitchCurrentAction);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(flipSwitchCurrentAction, &QAction::triggered, this, &FlipSwitchEffect::toggleActiveCurrent);
|
2013-12-10 10:45:33 +00:00
|
|
|
QAction* flipSwitchAllAction = new QAction(this);
|
|
|
|
flipSwitchAllAction->setObjectName(QStringLiteral("FlipSwitchAll"));
|
2013-08-14 19:13:12 +00:00
|
|
|
flipSwitchAllAction->setText(i18n("Toggle Flip Switch (All desktops)"));
|
|
|
|
KGlobalAccel::self()->setShortcut(flipSwitchAllAction, QList<QKeySequence>());
|
2013-07-10 10:26:50 +00:00
|
|
|
effects->registerGlobalShortcut(QKeySequence(), flipSwitchAllAction);
|
2013-08-14 19:13:12 +00:00
|
|
|
m_shortcutAll = KGlobalAccel::self()->shortcut(flipSwitchAllAction);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(flipSwitchAllAction, &QAction::triggered, this, &FlipSwitchEffect::toggleActiveAllDesktops);
|
2013-08-14 19:13:12 +00:00
|
|
|
connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutChanged, this, &FlipSwitchEffect::globalShortcutChanged);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(effects, &EffectsHandler::windowAdded, this, &FlipSwitchEffect::slotWindowAdded);
|
|
|
|
connect(effects, &EffectsHandler::windowClosed, this, &FlipSwitchEffect::slotWindowClosed);
|
|
|
|
connect(effects, &EffectsHandler::tabBoxAdded, this, &FlipSwitchEffect::slotTabBoxAdded);
|
|
|
|
connect(effects, &EffectsHandler::tabBoxClosed, this, &FlipSwitchEffect::slotTabBoxClosed);
|
|
|
|
connect(effects, &EffectsHandler::tabBoxUpdated, this, &FlipSwitchEffect::slotTabBoxUpdated);
|
|
|
|
connect(effects, &EffectsHandler::tabBoxKeyEvent, this, &FlipSwitchEffect::slotTabBoxKeyEvent);
|
2019-06-23 15:59:44 +00:00
|
|
|
connect(effects, &EffectsHandler::screenAboutToLock, this, [this]() {
|
|
|
|
setActive(false, AllDesktopsMode);
|
|
|
|
setActive(false, CurrentDesktopMode);
|
|
|
|
});
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-10-02 09:27:32 +00:00
|
|
|
|
|
|
|
FlipSwitchEffect::~FlipSwitchEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
delete m_captionFrame;
|
|
|
|
}
|
2008-10-02 09:27:32 +00:00
|
|
|
|
2008-12-04 08:47:07 +00:00
|
|
|
bool FlipSwitchEffect::supported()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-08-10 07:24:53 +00:00
|
|
|
return effects->isOpenGLCompositing() && effects->animationsSupported();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-12-04 08:47:07 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FlipSwitchEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2014-03-25 15:29:03 +00:00
|
|
|
FlipSwitchConfig::self()->read();
|
2012-09-14 12:35:18 +00:00
|
|
|
m_tabbox = FlipSwitchConfig::tabBox();
|
|
|
|
m_tabboxAlternative = FlipSwitchConfig::tabBoxAlternative();
|
2012-11-25 17:46:13 +00:00
|
|
|
const int duration = animationTime<FlipSwitchConfig>(200);
|
2011-01-30 14:34:42 +00:00
|
|
|
m_timeLine.setDuration(duration);
|
|
|
|
m_startStopTimeLine.setDuration(duration);
|
|
|
|
|
2012-09-14 12:35:18 +00:00
|
|
|
m_angle = FlipSwitchConfig::angle();
|
|
|
|
m_xPosition = FlipSwitchConfig::xPosition() / 100.0f;
|
|
|
|
m_yPosition = FlipSwitchConfig::yPosition() / 100.0f;
|
|
|
|
m_windowTitle = FlipSwitchConfig::windowTitle();
|
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
|
|
|
void FlipSwitchEffect::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) {
|
2009-07-21 10:18:48 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_start)
|
2011-03-14 21:50:05 +00:00
|
|
|
m_startStopTimeLine.setCurrentTime(m_startStopTimeLine.currentTime() + time);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_stop && m_scheduledDirections.isEmpty())
|
2011-03-14 21:50:05 +00:00
|
|
|
m_startStopTimeLine.setCurrentTime(m_startStopTimeLine.currentTime() - time);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_animation)
|
2011-03-14 21:50:05 +00:00
|
|
|
m_timeLine.setCurrentTime(m_timeLine.currentTime() + time);
|
2008-01-24 10:36:32 +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
|
|
|
effects->prePaintScreen(data, presentTime);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-24 10:36:32 +00:00
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
void FlipSwitchEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData& data)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
effects->paintScreen(mask, region, data);
|
|
|
|
if (m_active) {
|
2009-07-21 10:18:48 +00:00
|
|
|
EffectWindowList tempList;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_mode == TabboxMode)
|
2009-07-21 10:18:48 +00:00
|
|
|
tempList = effects->currentTabBoxWindowList();
|
2011-01-30 14:34:42 +00:00
|
|
|
else {
|
2009-07-21 10:18:48 +00:00
|
|
|
// we have to setup the list
|
|
|
|
// using stacking order directly is not possible
|
|
|
|
// as not each window in stacking order is shown
|
|
|
|
// TODO: store list instead of calculating in each frame?
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (EffectWindow * w, effects->stackingOrder()) {
|
|
|
|
if (m_windows.contains(w))
|
|
|
|
tempList.append(w);
|
2008-04-28 17:51:52 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
m_flipOrderedWindows.clear();
|
2011-01-30 14:34:42 +00:00
|
|
|
int index = tempList.indexOf(m_selectedWindow);
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
int tabIndex = index;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_mode == TabboxMode) {
|
|
|
|
foreach (SwitchingDirection direction, m_scheduledDirections) { // krazy:exclude=foreach
|
|
|
|
if (direction == DirectionBackward)
|
2009-07-21 10:18:48 +00:00
|
|
|
index++;
|
|
|
|
else
|
|
|
|
index--;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (index < 0)
|
2009-07-21 10:18:48 +00:00
|
|
|
index = tempList.count() + index;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (index >= tempList.count())
|
2009-07-21 10:18:48 +00:00
|
|
|
index = index % tempList.count();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
tabIndex = index;
|
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
|
|
|
EffectWindow* w = nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!m_scheduledDirections.isEmpty() && m_scheduledDirections.head() == DirectionBackward) {
|
2009-07-21 10:18:48 +00:00
|
|
|
index--;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (index < 0)
|
2009-07-21 10:18:48 +00:00
|
|
|
index = tempList.count() + index;
|
2011-01-30 14:34:42 +00:00
|
|
|
w = tempList.at(index);
|
|
|
|
}
|
|
|
|
for (int i = index - 1; i >= 0; i--)
|
|
|
|
m_flipOrderedWindows.append(tempList.at(i));
|
|
|
|
for (int i = effects->currentTabBoxWindowList().count() - 1; i >= index; i--)
|
|
|
|
m_flipOrderedWindows.append(tempList.at(i));
|
|
|
|
if (w) {
|
|
|
|
m_flipOrderedWindows.removeAll(w);
|
|
|
|
m_flipOrderedWindows.append(w);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foreach (SwitchingDirection direction, m_scheduledDirections) { // krazy:exclude=foreach
|
|
|
|
if (direction == DirectionForward)
|
2009-07-21 10:18:48 +00:00
|
|
|
index++;
|
|
|
|
else
|
|
|
|
index--;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (index < 0)
|
|
|
|
index = tempList.count() - 1;
|
|
|
|
if (index >= tempList.count())
|
2009-07-21 10:18:48 +00:00
|
|
|
index = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
tabIndex = index;
|
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
|
|
|
EffectWindow* w = nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!m_scheduledDirections.isEmpty() && m_scheduledDirections.head() == DirectionBackward) {
|
2009-07-21 10:18:48 +00:00
|
|
|
index++;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (index >= tempList.count())
|
2009-07-21 10:18:48 +00:00
|
|
|
index = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
// sort from stacking order
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = index + 1; i < tempList.count(); i++)
|
|
|
|
m_flipOrderedWindows.append(tempList.at(i));
|
|
|
|
for (int i = 0; i <= index; i++)
|
|
|
|
m_flipOrderedWindows.append(tempList.at(i));
|
|
|
|
if (w) {
|
|
|
|
m_flipOrderedWindows.removeAll(w);
|
|
|
|
m_flipOrderedWindows.append(w);
|
2008-04-28 17:51:52 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-24 10:36:32 +00:00
|
|
|
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
int winMask = PAINT_WINDOW_TRANSFORMED | PAINT_WINDOW_TRANSLUCENT;
|
|
|
|
// fade in/out one window at the end of the stack during animation
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_animation && !m_scheduledDirections.isEmpty()) {
|
2009-07-21 10:18:48 +00:00
|
|
|
EffectWindow* w = m_flipOrderedWindows.last();
|
2011-05-09 23:46:02 +00:00
|
|
|
if (ItemInfo *info = m_windows.value(w,0)) {
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowPaintData data(w);
|
2015-02-01 03:29:50 +00:00
|
|
|
if (effects->numScreens() > 1) {
|
|
|
|
data.setProjectionMatrix(m_projectionMatrix);
|
|
|
|
data.setModelViewMatrix(m_modelviewMatrix);
|
|
|
|
}
|
2012-06-02 19:54:18 +00:00
|
|
|
data.setRotationAxis(Qt::YAxis);
|
|
|
|
data.setRotationAngle(m_angle * m_startStopTimeLine.currentValue());
|
2012-07-12 15:20:17 +00:00
|
|
|
data.setOpacity(info->opacity);
|
|
|
|
data.setBrightness(info->brightness);
|
|
|
|
data.setSaturation(info->saturation);
|
2009-07-21 10:18:48 +00:00
|
|
|
int distance = tempList.count() - 1;
|
|
|
|
float zDistance = 500.0f;
|
2012-05-28 12:45:46 +00:00
|
|
|
data.translate(- (w->x() - m_screenArea.x() + data.xTranslation()) * m_startStopTimeLine.currentValue());
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2012-05-28 12:45:46 +00:00
|
|
|
data.translate(m_screenArea.width() * m_xPosition * m_startStopTimeLine.currentValue(),
|
|
|
|
(m_screenArea.y() + m_screenArea.height() * m_yPosition - (w->y() + w->height() + data.yTranslation())) * m_startStopTimeLine.currentValue());
|
|
|
|
data.translate(- (m_screenArea.width() * 0.25f) * distance * m_startStopTimeLine.currentValue(),
|
|
|
|
- (m_screenArea.height() * 0.10f) * distance * m_startStopTimeLine.currentValue(),
|
|
|
|
- (zDistance * distance) * m_startStopTimeLine.currentValue());
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_scheduledDirections.head() == DirectionForward)
|
2012-07-12 15:20:17 +00:00
|
|
|
data.multiplyOpacity(0.8 * m_timeLine.currentValue());
|
2009-07-21 10:18:48 +00:00
|
|
|
else
|
2012-07-12 15:20:17 +00:00
|
|
|
data.multiplyOpacity(0.8 * (1.0 - m_timeLine.currentValue()));
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->numScreens() > 1) {
|
|
|
|
adjustWindowMultiScreen(w, data);
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->drawWindow(w, winMask, infiniteRegion(), data);
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2011-05-09 23:46:02 +00:00
|
|
|
foreach (EffectWindow *w, m_flipOrderedWindows) {
|
|
|
|
ItemInfo *info = m_windows.value(w,0);
|
|
|
|
if (!info)
|
2009-07-21 10:18:48 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowPaintData data(w);
|
2015-02-01 03:29:50 +00:00
|
|
|
if (effects->numScreens() > 1) {
|
|
|
|
data.setProjectionMatrix(m_projectionMatrix);
|
|
|
|
data.setModelViewMatrix(m_modelviewMatrix);
|
|
|
|
}
|
2012-06-02 19:54:18 +00:00
|
|
|
data.setRotationAxis(Qt::YAxis);
|
|
|
|
data.setRotationAngle(m_angle * m_startStopTimeLine.currentValue());
|
2012-07-12 15:20:17 +00:00
|
|
|
data.setOpacity(info->opacity);
|
|
|
|
data.setBrightness(info->brightness);
|
|
|
|
data.setSaturation(info->saturation);
|
2011-01-30 14:34:42 +00:00
|
|
|
int windowIndex = tempList.indexOf(w);
|
2009-07-21 10:18:48 +00:00
|
|
|
int distance;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_mode == TabboxMode) {
|
|
|
|
if (windowIndex < tabIndex)
|
2009-07-21 10:18:48 +00:00
|
|
|
distance = tempList.count() - (tabIndex - windowIndex);
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (windowIndex > tabIndex)
|
2009-07-21 10:18:48 +00:00
|
|
|
distance = windowIndex - tabIndex;
|
|
|
|
else
|
|
|
|
distance = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
distance = m_flipOrderedWindows.count() - m_flipOrderedWindows.indexOf(w) - 1;
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!m_scheduledDirections.isEmpty() && m_scheduledDirections.head() == DirectionBackward) {
|
2009-07-21 10:18:48 +00:00
|
|
|
distance--;
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (!m_scheduledDirections.isEmpty() && m_scheduledDirections.head() == DirectionBackward) {
|
|
|
|
if (w == m_flipOrderedWindows.last()) {
|
2009-07-21 10:18:48 +00:00
|
|
|
distance = -1;
|
2012-07-12 15:20:17 +00:00
|
|
|
data.multiplyOpacity(m_timeLine.currentValue());
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
float zDistance = 500.0f;
|
2012-05-28 12:45:46 +00:00
|
|
|
data.translate(- (w->x() - m_screenArea.x() + data.xTranslation()) * m_startStopTimeLine.currentValue());
|
|
|
|
data.translate(m_screenArea.width() * m_xPosition * m_startStopTimeLine.currentValue(),
|
|
|
|
(m_screenArea.y() + m_screenArea.height() * m_yPosition - (w->y() + w->height() + data.yTranslation())) * m_startStopTimeLine.currentValue());
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2012-05-28 12:45:46 +00:00
|
|
|
data.translate(-(m_screenArea.width() * 0.25f) * distance * m_startStopTimeLine.currentValue(),
|
|
|
|
-(m_screenArea.height() * 0.10f) * distance * m_startStopTimeLine.currentValue(),
|
|
|
|
-(zDistance * distance) * m_startStopTimeLine.currentValue());
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_animation && !m_scheduledDirections.isEmpty()) {
|
|
|
|
if (m_scheduledDirections.head() == DirectionForward) {
|
2012-05-28 12:45:46 +00:00
|
|
|
data.translate((m_screenArea.width() * 0.25f) * m_timeLine.currentValue(),
|
|
|
|
(m_screenArea.height() * 0.10f) * m_timeLine.currentValue(),
|
|
|
|
zDistance * m_timeLine.currentValue());
|
2011-01-30 14:34:42 +00:00
|
|
|
if (distance == 0)
|
2012-07-12 15:20:17 +00:00
|
|
|
data.multiplyOpacity((1.0 - m_timeLine.currentValue()));
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2012-05-28 12:45:46 +00:00
|
|
|
data.translate(- (m_screenArea.width() * 0.25f) * m_timeLine.currentValue(),
|
|
|
|
- (m_screenArea.height() * 0.10f) * m_timeLine.currentValue(),
|
|
|
|
- zDistance * m_timeLine.currentValue());
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2012-07-12 15:20:17 +00:00
|
|
|
data.multiplyOpacity((0.8 + 0.2 * (1.0 - m_startStopTimeLine.currentValue())));
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->numScreens() > 1) {
|
|
|
|
adjustWindowMultiScreen(w, data);
|
|
|
|
}
|
2008-01-24 10:36:32 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->drawWindow(w, winMask, infiniteRegion(), data);
|
|
|
|
}
|
2008-01-24 10:36:32 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_windowTitle) {
|
2009-07-21 10:18:48 +00:00
|
|
|
// Render the caption frame
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_animation) {
|
2011-03-14 21:50:05 +00:00
|
|
|
m_captionFrame->setCrossFadeProgress(m_timeLine.currentValue());
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-03-14 21:50:05 +00:00
|
|
|
m_captionFrame->render(region, m_startStopTimeLine.currentValue());
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
void FlipSwitchEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_active) {
|
2011-03-14 21:50:05 +00:00
|
|
|
if (m_start && m_startStopTimeLine.currentValue() == 1.0f) {
|
2009-07-21 10:18:48 +00:00
|
|
|
m_start = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!m_scheduledDirections.isEmpty()) {
|
2009-07-21 10:18:48 +00:00
|
|
|
m_animation = true;
|
2011-03-14 21:50:05 +00:00
|
|
|
m_timeLine.setCurrentTime(0);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_scheduledDirections.count() == 1) {
|
2020-09-09 13:03:02 +00:00
|
|
|
m_currentAnimationEasingCurve = QEasingCurve::OutSine;
|
|
|
|
m_timeLine.setEasingCurve(m_currentAnimationEasingCurve);
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2020-09-09 13:03:02 +00:00
|
|
|
m_currentAnimationEasingCurve = QEasingCurve::Linear;
|
|
|
|
m_timeLine.setEasingCurve(m_currentAnimationEasingCurve);
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2011-03-14 21:50:05 +00:00
|
|
|
if (m_stop && m_startStopTimeLine.currentValue() == 0.0f) {
|
2009-07-21 10:18:48 +00:00
|
|
|
m_stop = false;
|
|
|
|
m_active = false;
|
2010-07-18 16:32:37 +00:00
|
|
|
m_captionFrame->free();
|
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();
|
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
|
|
|
effects->setActiveFullScreenEffect(nullptr);
|
2009-07-21 10:18:48 +00:00
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
qDeleteAll(m_windows);
|
2009-07-21 10:18:48 +00:00
|
|
|
m_windows.clear();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-03-14 21:50:05 +00:00
|
|
|
if (m_animation && m_timeLine.currentValue() == 1.0f) {
|
|
|
|
m_timeLine.setCurrentTime(0);
|
2009-07-21 10:18:48 +00:00
|
|
|
m_scheduledDirections.dequeue();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_scheduledDirections.isEmpty()) {
|
2009-07-21 10:18:48 +00:00
|
|
|
m_animation = false;
|
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
if (m_scheduledDirections.count() == 1) {
|
|
|
|
if (m_stop)
|
2020-09-09 13:03:02 +00:00
|
|
|
m_currentAnimationEasingCurve = QEasingCurve::Linear;
|
2008-01-24 10:36:32 +00:00
|
|
|
else
|
2020-09-09 13:03:02 +00:00
|
|
|
m_currentAnimationEasingCurve = QEasingCurve::OutSine;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2020-09-09 13:03:02 +00:00
|
|
|
m_currentAnimationEasingCurve = QEasingCurve::Linear;
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2020-09-09 13:03:02 +00:00
|
|
|
m_timeLine.setEasingCurve(m_currentAnimationEasingCurve);
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_start || m_stop || m_animation)
|
|
|
|
effects->addRepaintFull();
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
2009-07-21 10:18:48 +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 FlipSwitchEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, std::chrono::milliseconds presentTime)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_active) {
|
|
|
|
if (m_windows.contains(w)) {
|
2009-07-21 10:18:48 +00:00
|
|
|
data.setTransformed();
|
|
|
|
data.setTranslucent();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!w->isOnCurrentDesktop())
|
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DESKTOP);
|
|
|
|
if (w->isMinimized())
|
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_MINIMIZE);
|
|
|
|
} else {
|
|
|
|
if ((m_start || m_stop) && !w->isDesktop() && w->isOnCurrentDesktop())
|
2009-07-21 10:18:48 +00:00
|
|
|
data.setTranslucent();
|
2011-01-30 14:34:42 +00:00
|
|
|
else if (!w->isDesktop())
|
|
|
|
w->disablePainting(EffectWindow::PAINT_DISABLED_BY_DESKTOP);
|
2009-07-21 10:18:48 +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
|
|
|
effects->prePaintWindow(w, data, presentTime);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FlipSwitchEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
if (m_active) {
|
2011-05-09 23:46:02 +00:00
|
|
|
ItemInfo *info = m_windows.value(w,0);
|
|
|
|
if (info) {
|
2012-07-12 15:20:17 +00:00
|
|
|
info->opacity = data.opacity();
|
|
|
|
info->brightness = data.brightness();
|
|
|
|
info->saturation = data.saturation();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-05-09 23:46:02 +00:00
|
|
|
|
|
|
|
// fade out all windows not in window list except the desktops
|
|
|
|
const bool isFader = (m_start || m_stop) && !info && !w->isDesktop();
|
|
|
|
if (isFader)
|
2012-07-12 15:20:17 +00:00
|
|
|
data.multiplyOpacity((1.0 - m_startStopTimeLine.currentValue()));
|
2011-05-09 23:46:02 +00:00
|
|
|
|
|
|
|
// if not a fader or the desktop, skip painting here to prevent flicker
|
|
|
|
if (!(isFader || w->isDesktop()))
|
2009-07-21 10:18:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-05-09 23:46:02 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
//*************************************************************
|
|
|
|
// Tabbox handling
|
|
|
|
//*************************************************************
|
2011-03-06 11:15:16 +00:00
|
|
|
void FlipSwitchEffect::slotTabBoxAdded(int mode)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this)
|
2009-07-21 10:18:48 +00:00
|
|
|
return;
|
|
|
|
// only for windows mode
|
2015-04-30 19:15:58 +00:00
|
|
|
effects->setShowingDesktop(false);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (((mode == TabBoxWindowsMode && m_tabbox) ||
|
2012-04-25 20:57:48 +00:00
|
|
|
(mode == TabBoxWindowsAlternativeMode && m_tabboxAlternative) ||
|
|
|
|
(mode == TabBoxCurrentAppWindowsMode && m_tabbox) ||
|
|
|
|
(mode == TabBoxCurrentAppWindowsAlternativeMode && m_tabboxAlternative))
|
2011-01-30 14:34:42 +00:00
|
|
|
&& (!m_active || (m_active && m_stop))
|
|
|
|
&& !effects->currentTabBoxWindowList().isEmpty()) {
|
|
|
|
setActive(true, TabboxMode);
|
|
|
|
if (m_active)
|
2009-07-21 10:18:48 +00:00
|
|
|
effects->refTabBox();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2011-03-06 11:15:16 +00:00
|
|
|
void FlipSwitchEffect::slotTabBoxClosed()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_active) {
|
|
|
|
setActive(false, TabboxMode);
|
2009-07-21 10:18:48 +00:00
|
|
|
effects->unrefTabBox();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2011-03-06 11:15:16 +00:00
|
|
|
void FlipSwitchEffect::slotTabBoxUpdated()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_active && !m_stop) {
|
|
|
|
if (!effects->currentTabBoxWindowList().isEmpty()) {
|
2009-07-21 10:18:48 +00:00
|
|
|
// determine the switch direction
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_selectedWindow != effects->currentTabBoxWindow()) {
|
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
|
|
|
if (m_selectedWindow != nullptr) {
|
2011-01-30 14:34:42 +00:00
|
|
|
int old_index = effects->currentTabBoxWindowList().indexOf(m_selectedWindow);
|
|
|
|
int new_index = effects->currentTabBoxWindowList().indexOf(effects->currentTabBoxWindow());
|
2009-07-21 10:18:48 +00:00
|
|
|
SwitchingDirection new_direction;
|
|
|
|
int distance = new_index - old_index;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (distance > 0)
|
2009-07-21 10:18:48 +00:00
|
|
|
new_direction = DirectionForward;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (distance < 0)
|
2009-07-21 10:18:48 +00:00
|
|
|
new_direction = DirectionBackward;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->currentTabBoxWindowList().count() == 2) {
|
2009-07-21 10:18:48 +00:00
|
|
|
new_direction = DirectionForward;
|
|
|
|
distance = 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (distance != 0) {
|
|
|
|
distance = abs(distance);
|
2009-07-21 10:18:48 +00:00
|
|
|
int tempDistance = effects->currentTabBoxWindowList().count() - distance;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (tempDistance < abs(distance)) {
|
2009-07-21 10:18:48 +00:00
|
|
|
distance = tempDistance;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (new_direction == DirectionForward)
|
2009-07-21 10:18:48 +00:00
|
|
|
new_direction = DirectionBackward;
|
|
|
|
else
|
|
|
|
new_direction = DirectionForward;
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
scheduleAnimation(new_direction, distance);
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
m_selectedWindow = effects->currentTabBoxWindow();
|
2012-03-29 08:34:33 +00:00
|
|
|
updateCaption();
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaintFull();
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
//*************************************************************
|
|
|
|
// Window adding/removing handling
|
|
|
|
//*************************************************************
|
|
|
|
|
2011-02-25 21:06:02 +00:00
|
|
|
void FlipSwitchEffect::slotWindowAdded(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_active && isSelectableWindow(w)) {
|
2011-05-09 23:46:02 +00:00
|
|
|
m_windows[ w ] = new ItemInfo;
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2011-02-27 08:25:45 +00:00
|
|
|
void FlipSwitchEffect::slotWindowClosed(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-04-03 22:04:23 +00:00
|
|
|
if (m_selectedWindow == w)
|
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
|
|
|
m_selectedWindow = nullptr;
|
2011-05-11 19:07:34 +00:00
|
|
|
if (m_active) {
|
|
|
|
QHash< const EffectWindow*, ItemInfo* >::iterator it = m_windows.find(w);
|
|
|
|
if (it != m_windows.end()) {
|
|
|
|
delete *it;
|
|
|
|
m_windows.erase(it);
|
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
//*************************************************************
|
|
|
|
// Activation
|
|
|
|
//*************************************************************
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FlipSwitchEffect::setActive(bool activate, FlipSwitchMode mode)
|
|
|
|
{
|
|
|
|
if (activate) {
|
2009-07-21 10:18:48 +00:00
|
|
|
// effect already active, do some sanity checks
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_active) {
|
|
|
|
if (m_stop) {
|
|
|
|
if (mode != m_mode) {
|
2009-07-21 10:18:48 +00:00
|
|
|
// only the same mode may reactivate the effect
|
|
|
|
return;
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2009-07-21 10:18:48 +00:00
|
|
|
// active, but not scheduled for closing -> abort
|
|
|
|
return;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
m_mode = mode;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (EffectWindow * w, effects->stackingOrder()) {
|
|
|
|
if (isSelectableWindow(w) && !m_windows.contains(w))
|
2011-05-09 23:46:02 +00:00
|
|
|
m_windows[ w ] = new ItemInfo;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (m_windows.isEmpty())
|
2009-07-21 10:18:48 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->setActiveFullScreenEffect(this);
|
2009-07-21 10:18:48 +00:00
|
|
|
m_active = true;
|
|
|
|
m_start = true;
|
2020-09-09 13:03:02 +00:00
|
|
|
m_startStopTimeLine.setEasingCurve(QEasingCurve::InOutSine);
|
2009-07-21 10:18:48 +00:00
|
|
|
m_activeScreen = effects->activeScreen();
|
2011-01-30 14:34:42 +00:00
|
|
|
m_screenArea = effects->clientArea(ScreenArea, m_activeScreen, effects->currentDesktop());
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2015-02-01 03:29:50 +00:00
|
|
|
if (effects->numScreens() > 1) {
|
|
|
|
// unfortunatelly we have to change the projection matrix in dual screen mode
|
|
|
|
// code is copied from Coverswitch
|
|
|
|
QRect fullRect = effects->clientArea(FullArea, m_activeScreen, effects->currentDesktop());
|
|
|
|
float fovy = 60.0f;
|
|
|
|
float aspect = 1.0f;
|
|
|
|
float zNear = 0.1f;
|
|
|
|
float zFar = 100.0f;
|
|
|
|
|
|
|
|
float ymax = zNear * std::tan(fovy * M_PI / 360.0f);
|
|
|
|
float ymin = -ymax;
|
|
|
|
float xmin = ymin * aspect;
|
|
|
|
float xmax = ymax * aspect;
|
|
|
|
|
|
|
|
if (m_screenArea.width() != fullRect.width()) {
|
|
|
|
if (m_screenArea.x() == 0) {
|
|
|
|
// horizontal layout: left screen
|
|
|
|
xmin *= (float)m_screenArea.width() / (float)fullRect.width();
|
|
|
|
xmax *= (fullRect.width() - 0.5f * m_screenArea.width()) / (0.5f * fullRect.width());
|
|
|
|
} else {
|
|
|
|
// horizontal layout: right screen
|
|
|
|
xmin *= (fullRect.width() - 0.5f * m_screenArea.width()) / (0.5f * fullRect.width());
|
|
|
|
xmax *= (float)m_screenArea.width() / (float)fullRect.width();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_screenArea.height() != fullRect.height()) {
|
|
|
|
if (m_screenArea.y() == 0) {
|
|
|
|
// vertical layout: top screen
|
|
|
|
ymin *= (fullRect.height() - 0.5f * m_screenArea.height()) / (0.5f * fullRect.height());
|
|
|
|
ymax *= (float)m_screenArea.height() / (float)fullRect.height();
|
|
|
|
} else {
|
|
|
|
// vertical layout: bottom screen
|
|
|
|
ymin *= (float)m_screenArea.height() / (float)fullRect.height();
|
|
|
|
ymax *= (fullRect.height() - 0.5f * m_screenArea.height()) / (0.5f * fullRect.height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_projectionMatrix = QMatrix4x4();
|
|
|
|
m_projectionMatrix.frustum(xmin, xmax, ymin, ymax, zNear, zFar);
|
|
|
|
|
|
|
|
const float scaleFactor = 1.1f / zNear;
|
|
|
|
|
|
|
|
// Create a second matrix that transforms screen coordinates
|
|
|
|
// to world coordinates.
|
|
|
|
QMatrix4x4 matrix;
|
|
|
|
matrix.translate(xmin * scaleFactor, ymax * scaleFactor, -1.1);
|
|
|
|
matrix.scale( (xmax - xmin) * scaleFactor / fullRect.width(),
|
|
|
|
-(ymax - ymin) * scaleFactor / fullRect.height(),
|
|
|
|
0.001);
|
|
|
|
// Combine the matrices
|
|
|
|
m_projectionMatrix *= matrix;
|
|
|
|
|
|
|
|
m_modelviewMatrix = QMatrix4x4();
|
|
|
|
m_modelviewMatrix.translate(m_screenArea.x(), m_screenArea.y(), 0.0);
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_stop) {
|
2009-07-21 10:18:48 +00:00
|
|
|
// effect is still closing from last usage
|
|
|
|
m_stop = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2009-07-21 10:18:48 +00:00
|
|
|
// things to do only when there is no closing animation
|
|
|
|
m_scheduledDirections.clear();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(m_mode) {
|
|
|
|
case TabboxMode:
|
|
|
|
m_selectedWindow = effects->currentTabBoxWindow();
|
2013-04-24 14:51:04 +00:00
|
|
|
effects->startMouseInterception(this, Qt::ArrowCursor);
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
|
|
|
case CurrentDesktopMode:
|
|
|
|
m_selectedWindow = effects->activeWindow();
|
2013-04-24 14:51:04 +00:00
|
|
|
effects->startMouseInterception(this, Qt::BlankCursor);
|
2011-01-30 14:34:42 +00:00
|
|
|
m_hasKeyboardGrab = effects->grabKeyboard(this);
|
|
|
|
break;
|
|
|
|
case AllDesktopsMode:
|
|
|
|
m_selectedWindow = effects->activeWindow();
|
2013-04-24 14:51:04 +00:00
|
|
|
effects->startMouseInterception(this, Qt::BlankCursor);
|
2011-01-30 14:34:42 +00:00
|
|
|
m_hasKeyboardGrab = effects->grabKeyboard(this);
|
|
|
|
break;
|
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
// Setup caption frame geometry
|
2011-01-30 14:34:42 +00:00
|
|
|
QRect frameRect = QRect(m_screenArea.width() * 0.25f + m_screenArea.x(),
|
|
|
|
m_screenArea.height() * 0.1f + m_screenArea.y() - QFontMetrics(m_captionFont).height(),
|
|
|
|
m_screenArea.width() * 0.5f,
|
|
|
|
QFontMetrics(m_captionFont).height());
|
2012-05-01 17:50:22 +00:00
|
|
|
if (!m_captionFrame) {
|
|
|
|
m_captionFrame = effects->effectFrame(EffectFrameStyled);
|
|
|
|
m_captionFrame->setFont(m_captionFont);
|
|
|
|
m_captionFrame->enableCrossFade(true);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
m_captionFrame->setGeometry(frameRect);
|
|
|
|
m_captionFrame->setIconSize(QSize(frameRect.height(), frameRect.height()));
|
2012-03-29 08:34:33 +00:00
|
|
|
updateCaption();
|
2009-07-21 10:18:48 +00:00
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2009-07-21 10:18:48 +00:00
|
|
|
// only deactivate if mode is current mode
|
2011-01-30 14:34:42 +00:00
|
|
|
if (mode != m_mode)
|
2009-07-21 10:18:48 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_start && m_scheduledDirections.isEmpty()) {
|
2009-07-21 10:18:48 +00:00
|
|
|
m_start = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
m_stop = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_animation) {
|
2020-09-09 13:03:02 +00:00
|
|
|
m_startStopTimeLine.setEasingCurve(QEasingCurve::OutSine);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_scheduledDirections.count() == 1) {
|
2020-09-09 13:03:02 +00:00
|
|
|
if (m_currentAnimationEasingCurve == QEasingCurve::InOutSine)
|
|
|
|
m_currentAnimationEasingCurve = QEasingCurve::InSine;
|
|
|
|
else if (m_currentAnimationEasingCurve == QEasingCurve::OutSine)
|
|
|
|
m_currentAnimationEasingCurve = QEasingCurve::Linear;
|
|
|
|
m_timeLine.setEasingCurve(m_currentAnimationEasingCurve);
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
2020-09-09 13:03:02 +00:00
|
|
|
m_startStopTimeLine.setEasingCurve(QEasingCurve::InOutSine);
|
2013-04-24 14:51:04 +00:00
|
|
|
effects->stopMouseInterception(this);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_hasKeyboardGrab) {
|
2009-07-21 10:18:48 +00:00
|
|
|
effects->ungrabKeyboard();
|
|
|
|
m_hasKeyboardGrab = false;
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaintFull();
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-24 10:36:32 +00:00
|
|
|
|
2009-07-21 10:18:48 +00:00
|
|
|
void FlipSwitchEffect::toggleActiveAllDesktops()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_active) {
|
|
|
|
if (m_stop) {
|
2009-07-21 10:18:48 +00:00
|
|
|
// reactivate if stopping
|
2011-01-30 14:34:42 +00:00
|
|
|
setActive(true, AllDesktopsMode);
|
|
|
|
} else {
|
2009-07-21 10:18:48 +00:00
|
|
|
// deactivate if not stopping
|
2011-01-30 14:34:42 +00:00
|
|
|
setActive(false, AllDesktopsMode);
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
setActive(true, AllDesktopsMode);
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
void FlipSwitchEffect::toggleActiveCurrent()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_active) {
|
|
|
|
if (m_stop) {
|
2009-07-21 10:18:48 +00:00
|
|
|
// reactivate if stopping
|
2011-01-30 14:34:42 +00:00
|
|
|
setActive(true, CurrentDesktopMode);
|
|
|
|
} else {
|
2009-07-21 10:18:48 +00:00
|
|
|
// deactivate if not stopping
|
2011-01-30 14:34:42 +00:00
|
|
|
setActive(false, CurrentDesktopMode);
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
setActive(true, CurrentDesktopMode);
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
//*************************************************************
|
|
|
|
// Helper function
|
|
|
|
//*************************************************************
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool FlipSwitchEffect::isSelectableWindow(EffectWindow* w) const
|
|
|
|
{
|
2010-12-16 18:51:19 +00:00
|
|
|
// desktop windows might be included
|
2011-01-30 14:34:42 +00:00
|
|
|
if ((w->isSpecialWindow() && !w->isDesktop()) || w->isUtility())
|
2009-07-21 10:18:48 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isDesktop())
|
|
|
|
return (m_mode == TabboxMode && effects->currentTabBoxWindowList().contains(w));
|
|
|
|
if (w->isDeleted())
|
2009-07-21 10:18:48 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!w->acceptsFocus())
|
2009-07-21 10:18:48 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(m_mode) {
|
|
|
|
case TabboxMode:
|
|
|
|
return effects->currentTabBoxWindowList().contains(w);
|
|
|
|
case CurrentDesktopMode:
|
|
|
|
return w->isOnCurrentDesktop();
|
|
|
|
case AllDesktopsMode:
|
|
|
|
//nothing special
|
|
|
|
break;
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FlipSwitchEffect::scheduleAnimation(const SwitchingDirection& direction, int distance)
|
|
|
|
{
|
|
|
|
if (m_start) {
|
2009-07-21 10:18:48 +00:00
|
|
|
// start is still active so change the shape to have a nice transition
|
2020-09-09 13:03:02 +00:00
|
|
|
m_startStopTimeLine.setEasingCurve(QEasingCurve::InSine);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (!m_animation && !m_start) {
|
2009-07-21 10:18:48 +00:00
|
|
|
m_animation = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
m_scheduledDirections.enqueue(direction);
|
2009-07-21 10:18:48 +00:00
|
|
|
distance--;
|
|
|
|
// reset shape just to make sure
|
2020-09-09 13:03:02 +00:00
|
|
|
m_currentAnimationEasingCurve = QEasingCurve::InOutSine;
|
|
|
|
m_timeLine.setEasingCurve(m_currentAnimationEasingCurve);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < distance; i++) {
|
|
|
|
if (m_scheduledDirections.count() > 1 && m_scheduledDirections.last() != direction)
|
2009-07-21 10:18:48 +00:00
|
|
|
m_scheduledDirections.pop_back();
|
|
|
|
else
|
2011-01-30 14:34:42 +00:00
|
|
|
m_scheduledDirections.enqueue(direction);
|
|
|
|
if (m_scheduledDirections.count() == m_windows.count() + 1) {
|
2009-07-21 10:18:48 +00:00
|
|
|
SwitchingDirection temp = m_scheduledDirections.dequeue();
|
|
|
|
m_scheduledDirections.clear();
|
2011-01-30 14:34:42 +00:00
|
|
|
m_scheduledDirections.enqueue(temp);
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (m_scheduledDirections.count() > 1) {
|
2020-09-09 13:03:02 +00:00
|
|
|
QEasingCurve curve;
|
|
|
|
switch (m_currentAnimationEasingCurve.type()) {
|
|
|
|
case QEasingCurve::InOutSine:
|
|
|
|
curve = QEasingCurve::InSine;
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
2020-09-09 13:03:02 +00:00
|
|
|
case QEasingCurve::OutSine:
|
|
|
|
curve = QEasingCurve::Linear;
|
2011-01-30 14:34:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
2020-09-09 13:03:02 +00:00
|
|
|
curve = m_currentAnimationEasingCurve;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2020-09-09 13:03:02 +00:00
|
|
|
if (m_currentAnimationEasingCurve != curve) {
|
|
|
|
m_currentAnimationEasingCurve = curve;
|
|
|
|
m_timeLine.setEasingCurve(curve);
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FlipSwitchEffect::adjustWindowMultiScreen(const KWin::EffectWindow* w, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
if (effects->numScreens() <= 1)
|
2009-07-21 10:18:48 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
QRect clientRect = effects->clientArea(FullScreenArea, w->screen(), effects->currentDesktop());
|
|
|
|
QRect rect = effects->clientArea(ScreenArea, m_activeScreen, effects->currentDesktop());
|
|
|
|
QRect fullRect = effects->clientArea(FullArea, m_activeScreen, effects->currentDesktop());
|
|
|
|
if (w->screen() == m_activeScreen) {
|
|
|
|
if (clientRect.width() != fullRect.width() && clientRect.x() != fullRect.x()) {
|
2012-05-28 12:45:46 +00:00
|
|
|
data.translate(- clientRect.x());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (clientRect.height() != fullRect.height() && clientRect.y() != fullRect.y()) {
|
2012-05-28 12:45:46 +00:00
|
|
|
data.translate(0.0, - clientRect.y());
|
2009-07-21 10:18:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
if (clientRect.width() != fullRect.width() && clientRect.x() < rect.x()) {
|
2012-08-10 15:02:19 +00:00
|
|
|
data.translate(- (m_screenArea.x() - clientRect.x()));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (clientRect.height() != fullRect.height() && clientRect.y() < m_screenArea.y()) {
|
2012-08-10 15:02:19 +00:00
|
|
|
data.translate(0.0, - (m_screenArea.y() - clientRect.y()));
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-24 10:36:32 +00:00
|
|
|
|
2012-05-25 07:04:58 +00:00
|
|
|
void FlipSwitchEffect::selectNextOrPreviousWindow(bool forward)
|
|
|
|
{
|
|
|
|
if (!m_active || !m_selectedWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const int index = effects->currentTabBoxWindowList().indexOf(m_selectedWindow);
|
|
|
|
int newIndex = index;
|
|
|
|
if (forward) {
|
|
|
|
++newIndex;
|
|
|
|
} else {
|
|
|
|
--newIndex;
|
|
|
|
}
|
|
|
|
if (newIndex == effects->currentTabBoxWindowList().size()) {
|
|
|
|
newIndex = 0;
|
|
|
|
} else if (newIndex < 0) {
|
|
|
|
newIndex = effects->currentTabBoxWindowList().size() -1;
|
|
|
|
}
|
|
|
|
if (index == newIndex) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
effects->setTabBoxWindow(effects->currentTabBoxWindowList().at(newIndex));
|
|
|
|
}
|
|
|
|
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
//*************************************************************
|
|
|
|
// Keyboard handling
|
|
|
|
//*************************************************************
|
2020-01-14 16:42:24 +00:00
|
|
|
void FlipSwitchEffect::globalShortcutChanged(QAction *action, const QKeySequence &shortcut)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-08-14 19:13:12 +00:00
|
|
|
if (action->objectName() == QStringLiteral("FlipSwitchAll")) {
|
|
|
|
m_shortcutAll.clear();
|
|
|
|
m_shortcutAll.append(shortcut);
|
|
|
|
} else if (action->objectName() == QStringLiteral("FlipSwitchCurrent")) {
|
|
|
|
m_shortcutCurrent.clear();
|
|
|
|
m_shortcutCurrent.append(shortcut);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
void FlipSwitchEffect::grabbedKeyboardEvent(QKeyEvent* e)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (e->type() == QEvent::KeyPress) {
|
2009-07-21 10:18:48 +00:00
|
|
|
// check for global shortcuts
|
|
|
|
// HACK: keyboard grab disables the global shortcuts so we have to check for global shortcut (bug 156155)
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_mode == CurrentDesktopMode && m_shortcutCurrent.contains(e->key() + e->modifiers())) {
|
2009-07-21 10:18:48 +00:00
|
|
|
toggleActiveCurrent();
|
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (m_mode == AllDesktopsMode && m_shortcutAll.contains(e->key() + e->modifiers())) {
|
2009-07-21 10:18:48 +00:00
|
|
|
toggleActiveAllDesktops();
|
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
switch(e->key()) {
|
|
|
|
case Qt::Key_Escape:
|
|
|
|
setActive(false, m_mode);
|
|
|
|
return;
|
|
|
|
case Qt::Key_Tab: {
|
|
|
|
// find next window
|
|
|
|
if (m_windows.isEmpty())
|
|
|
|
return; // sanity check
|
|
|
|
bool found = false;
|
|
|
|
for (int i = effects->stackingOrder().indexOf(m_selectedWindow) - 1; i >= 0; i--) {
|
|
|
|
if (isSelectableWindow(effects->stackingOrder().at(i))) {
|
|
|
|
m_selectedWindow = effects->stackingOrder().at(i);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
for (int i = effects->stackingOrder().count() - 1; i > effects->stackingOrder().indexOf(m_selectedWindow); i--) {
|
|
|
|
if (isSelectableWindow(effects->stackingOrder().at(i))) {
|
|
|
|
m_selectedWindow = effects->stackingOrder().at(i);
|
2009-07-21 10:18:48 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (found) {
|
2012-03-29 08:34:33 +00:00
|
|
|
updateCaption();
|
2011-01-30 14:34:42 +00:00
|
|
|
scheduleAnimation(DirectionForward);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Qt::Key_Backtab: {
|
|
|
|
// find previous window
|
|
|
|
if (m_windows.isEmpty())
|
|
|
|
return; // sanity check
|
|
|
|
bool found = false;
|
|
|
|
for (int i = effects->stackingOrder().indexOf(m_selectedWindow) + 1; i < effects->stackingOrder().count(); i++) {
|
|
|
|
if (isSelectableWindow(effects->stackingOrder().at(i))) {
|
|
|
|
m_selectedWindow = effects->stackingOrder().at(i);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
for (int i = 0; i < effects->stackingOrder().indexOf(m_selectedWindow); i++) {
|
|
|
|
if (isSelectableWindow(effects->stackingOrder().at(i))) {
|
|
|
|
m_selectedWindow = effects->stackingOrder().at(i);
|
2009-07-21 10:18:48 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (found) {
|
2012-03-29 08:34:33 +00:00
|
|
|
updateCaption();
|
2011-01-30 14:34:42 +00:00
|
|
|
scheduleAnimation(DirectionBackward);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Qt::Key_Return:
|
|
|
|
case Qt::Key_Enter:
|
|
|
|
case Qt::Key_Space:
|
|
|
|
if (m_selectedWindow)
|
|
|
|
effects->activateWindow(m_selectedWindow);
|
|
|
|
setActive(false, m_mode);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->addRepaintFull();
|
2008-01-24 10:36:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-24 10:36:32 +00:00
|
|
|
|
2012-03-29 09:11:10 +00:00
|
|
|
void FlipSwitchEffect::slotTabBoxKeyEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::KeyPress) {
|
|
|
|
switch (event->key()) {
|
|
|
|
case Qt::Key_Up:
|
|
|
|
case Qt::Key_Left:
|
2012-05-25 07:04:58 +00:00
|
|
|
selectPreviousWindow();
|
2012-03-29 09:11:10 +00:00
|
|
|
break;
|
|
|
|
case Qt::Key_Down:
|
|
|
|
case Qt::Key_Right:
|
2012-05-25 07:04:58 +00:00
|
|
|
selectNextWindow();
|
2012-03-29 09:11:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool FlipSwitchEffect::isActive() const
|
|
|
|
{
|
2015-11-20 10:17:16 +00:00
|
|
|
return m_active && !effects->isScreenLocked();
|
2011-08-27 09:21:31 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 08:34:33 +00:00
|
|
|
void FlipSwitchEffect::updateCaption()
|
|
|
|
{
|
|
|
|
if (!m_selectedWindow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_selectedWindow->isDesktop()) {
|
|
|
|
m_captionFrame->setText(i18nc("Special entry in alt+tab list for minimizing all windows",
|
|
|
|
"Show Desktop"));
|
2013-09-05 08:29:33 +00:00
|
|
|
static QPixmap pix = QIcon::fromTheme(QStringLiteral("user-desktop")).pixmap(m_captionFrame->iconSize());
|
2012-03-30 06:12:23 +00:00
|
|
|
m_captionFrame->setIcon(pix);
|
2012-03-29 08:34:33 +00:00
|
|
|
} else {
|
|
|
|
m_captionFrame->setText(m_selectedWindow->caption());
|
2012-03-30 06:12:23 +00:00
|
|
|
m_captionFrame->setIcon(m_selectedWindow->icon());
|
2012-03-29 08:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-25 07:04:58 +00:00
|
|
|
//*************************************************************
|
|
|
|
// Mouse handling
|
|
|
|
//*************************************************************
|
|
|
|
|
2013-04-24 14:51:04 +00:00
|
|
|
void FlipSwitchEffect::windowInputMouseEvent(QEvent* e)
|
2012-05-25 07:04:58 +00:00
|
|
|
{
|
|
|
|
if (e->type() != QEvent::MouseButtonPress)
|
|
|
|
return;
|
|
|
|
// we don't want click events during animations
|
|
|
|
if (m_animation)
|
|
|
|
return;
|
|
|
|
QMouseEvent* event = static_cast< QMouseEvent* >(e);
|
|
|
|
|
|
|
|
switch (event->button()) {
|
|
|
|
case Qt::XButton1: // wheel up
|
|
|
|
selectPreviousWindow();
|
|
|
|
break;
|
|
|
|
case Qt::XButton2: // wheel down
|
|
|
|
selectNextWindow();
|
|
|
|
break;
|
|
|
|
case Qt::LeftButton:
|
|
|
|
case Qt::RightButton:
|
2020-09-01 05:14:58 +00:00
|
|
|
case Qt::MiddleButton:
|
2012-05-25 07:04:58 +00:00
|
|
|
default:
|
|
|
|
// TODO: Change window on mouse button click
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-21 10:18:48 +00:00
|
|
|
//*************************************************************
|
|
|
|
// Item Info
|
|
|
|
//*************************************************************
|
|
|
|
FlipSwitchEffect::ItemInfo::ItemInfo()
|
|
|
|
: deleted(false)
|
2011-01-30 14:34:42 +00:00
|
|
|
, opacity(0.0)
|
|
|
|
, brightness(0.0)
|
|
|
|
, saturation(0.0)
|
|
|
|
{
|
|
|
|
}
|
2009-07-21 10:18:48 +00:00
|
|
|
|
|
|
|
FlipSwitchEffect::ItemInfo::~ItemInfo()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2008-01-24 10:36:32 +00:00
|
|
|
|
|
|
|
} // namespace
|
2009-07-21 10:18:48 +00:00
|
|
|
|