2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of the KDE project.
|
[effects] Re-implement the Minimize Animation effect in JavaScript
Summary:
There were several reasons to rewrite the Minimize Animation effect in
JavaScript: to simplify code and to get rid of full repaints. One could
say that nothing prevents us from calculating the dirty region in
postPaintScreen or postPaintWindow and it is correct, but with the
scripting effects API the dirty region will be calculated for us, so we
can focus more on "what we want" instead of "how".
Visually, the "old" effect and the rewritten one look quite the same.
Except one tiny bit: if a window doesn't have an icon in the task manager,
it won't be animated. The reason for that is the purpose of this effect is
to show where the window will be after it's minimized, if the window
doesn't have icon in the task manager, one can't click at the center of
the screen to unminimize the window.
There is one significant change, the name of the effect was changed to
"Squash". If we put this effect and the Magic lamp effect under "Window
Minimize Animation" category (or if we add some "heading" label), then
the old name and the name of the category would "conflict". The new name
was suggested by Nate Graham and it very closely describes what the
effect does. "Scale" doesn't fit this effect because while a window is
being animated, its aspect ratio is not preserved.
Reviewers: #kwin, #plasma, davidedmundson
Reviewed By: #kwin, #plasma, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16372
2018-09-23 17:07:48 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
[effects] Re-implement the Minimize Animation effect in JavaScript
Summary:
There were several reasons to rewrite the Minimize Animation effect in
JavaScript: to simplify code and to get rid of full repaints. One could
say that nothing prevents us from calculating the dirty region in
postPaintScreen or postPaintWindow and it is correct, but with the
scripting effects API the dirty region will be calculated for us, so we
can focus more on "what we want" instead of "how".
Visually, the "old" effect and the rewritten one look quite the same.
Except one tiny bit: if a window doesn't have an icon in the task manager,
it won't be animated. The reason for that is the purpose of this effect is
to show where the window will be after it's minimized, if the window
doesn't have icon in the task manager, one can't click at the center of
the screen to unminimize the window.
There is one significant change, the name of the effect was changed to
"Squash". If we put this effect and the Magic lamp effect under "Window
Minimize Animation" category (or if we add some "heading" label), then
the old name and the name of the category would "conflict". The new name
was suggested by Nate Graham and it very closely describes what the
effect does. "Scale" doesn't fit this effect because while a window is
being animated, its aspect ratio is not preserved.
Reviewers: #kwin, #plasma, davidedmundson
Reviewed By: #kwin, #plasma, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16372
2018-09-23 17:07:48 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
[effects] Re-implement the Minimize Animation effect in JavaScript
Summary:
There were several reasons to rewrite the Minimize Animation effect in
JavaScript: to simplify code and to get rid of full repaints. One could
say that nothing prevents us from calculating the dirty region in
postPaintScreen or postPaintWindow and it is correct, but with the
scripting effects API the dirty region will be calculated for us, so we
can focus more on "what we want" instead of "how".
Visually, the "old" effect and the rewritten one look quite the same.
Except one tiny bit: if a window doesn't have an icon in the task manager,
it won't be animated. The reason for that is the purpose of this effect is
to show where the window will be after it's minimized, if the window
doesn't have icon in the task manager, one can't click at the center of
the screen to unminimize the window.
There is one significant change, the name of the effect was changed to
"Squash". If we put this effect and the Magic lamp effect under "Window
Minimize Animation" category (or if we add some "heading" label), then
the old name and the name of the category would "conflict". The new name
was suggested by Nate Graham and it very closely describes what the
effect does. "Scale" doesn't fit this effect because while a window is
being animated, its aspect ratio is not preserved.
Reviewers: #kwin, #plasma, davidedmundson
Reviewed By: #kwin, #plasma, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16372
2018-09-23 17:07:48 +00:00
|
|
|
|
2018-11-05 09:50:53 +00:00
|
|
|
"use strict";
|
|
|
|
|
[effects] Re-implement the Minimize Animation effect in JavaScript
Summary:
There were several reasons to rewrite the Minimize Animation effect in
JavaScript: to simplify code and to get rid of full repaints. One could
say that nothing prevents us from calculating the dirty region in
postPaintScreen or postPaintWindow and it is correct, but with the
scripting effects API the dirty region will be calculated for us, so we
can focus more on "what we want" instead of "how".
Visually, the "old" effect and the rewritten one look quite the same.
Except one tiny bit: if a window doesn't have an icon in the task manager,
it won't be animated. The reason for that is the purpose of this effect is
to show where the window will be after it's minimized, if the window
doesn't have icon in the task manager, one can't click at the center of
the screen to unminimize the window.
There is one significant change, the name of the effect was changed to
"Squash". If we put this effect and the Magic lamp effect under "Window
Minimize Animation" category (or if we add some "heading" label), then
the old name and the name of the category would "conflict". The new name
was suggested by Nate Graham and it very closely describes what the
effect does. "Scale" doesn't fit this effect because while a window is
being animated, its aspect ratio is not preserved.
Reviewers: #kwin, #plasma, davidedmundson
Reviewed By: #kwin, #plasma, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16372
2018-09-23 17:07:48 +00:00
|
|
|
var squashEffect = {
|
|
|
|
duration: animationTime(250),
|
|
|
|
loadConfig: function () {
|
|
|
|
squashEffect.duration = animationTime(250);
|
|
|
|
},
|
|
|
|
slotWindowMinimized: function (window) {
|
|
|
|
if (effects.hasActiveFullScreenEffect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the window doesn't have an icon in the task manager,
|
|
|
|
// don't animate it.
|
|
|
|
var iconRect = window.iconGeometry;
|
|
|
|
if (iconRect.width == 0 || iconRect.height == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window.unminimizeAnimation) {
|
2018-10-24 20:25:00 +00:00
|
|
|
if (redirect(window.unminimizeAnimation, Effect.Backward)) {
|
|
|
|
return;
|
|
|
|
}
|
[effects] Re-implement the Minimize Animation effect in JavaScript
Summary:
There were several reasons to rewrite the Minimize Animation effect in
JavaScript: to simplify code and to get rid of full repaints. One could
say that nothing prevents us from calculating the dirty region in
postPaintScreen or postPaintWindow and it is correct, but with the
scripting effects API the dirty region will be calculated for us, so we
can focus more on "what we want" instead of "how".
Visually, the "old" effect and the rewritten one look quite the same.
Except one tiny bit: if a window doesn't have an icon in the task manager,
it won't be animated. The reason for that is the purpose of this effect is
to show where the window will be after it's minimized, if the window
doesn't have icon in the task manager, one can't click at the center of
the screen to unminimize the window.
There is one significant change, the name of the effect was changed to
"Squash". If we put this effect and the Magic lamp effect under "Window
Minimize Animation" category (or if we add some "heading" label), then
the old name and the name of the category would "conflict". The new name
was suggested by Nate Graham and it very closely describes what the
effect does. "Scale" doesn't fit this effect because while a window is
being animated, its aspect ratio is not preserved.
Reviewers: #kwin, #plasma, davidedmundson
Reviewed By: #kwin, #plasma, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16372
2018-09-23 17:07:48 +00:00
|
|
|
cancel(window.unminimizeAnimation);
|
|
|
|
delete window.unminimizeAnimation;
|
|
|
|
}
|
|
|
|
|
2018-10-24 20:25:00 +00:00
|
|
|
if (window.minimizeAnimation) {
|
|
|
|
if (redirect(window.minimizeAnimation, Effect.Forward)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cancel(window.minimizeAnimation);
|
|
|
|
}
|
|
|
|
|
[effects] Re-implement the Minimize Animation effect in JavaScript
Summary:
There were several reasons to rewrite the Minimize Animation effect in
JavaScript: to simplify code and to get rid of full repaints. One could
say that nothing prevents us from calculating the dirty region in
postPaintScreen or postPaintWindow and it is correct, but with the
scripting effects API the dirty region will be calculated for us, so we
can focus more on "what we want" instead of "how".
Visually, the "old" effect and the rewritten one look quite the same.
Except one tiny bit: if a window doesn't have an icon in the task manager,
it won't be animated. The reason for that is the purpose of this effect is
to show where the window will be after it's minimized, if the window
doesn't have icon in the task manager, one can't click at the center of
the screen to unminimize the window.
There is one significant change, the name of the effect was changed to
"Squash". If we put this effect and the Magic lamp effect under "Window
Minimize Animation" category (or if we add some "heading" label), then
the old name and the name of the category would "conflict". The new name
was suggested by Nate Graham and it very closely describes what the
effect does. "Scale" doesn't fit this effect because while a window is
being animated, its aspect ratio is not preserved.
Reviewers: #kwin, #plasma, davidedmundson
Reviewed By: #kwin, #plasma, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16372
2018-09-23 17:07:48 +00:00
|
|
|
var windowRect = window.geometry;
|
|
|
|
|
|
|
|
window.minimizeAnimation = animate({
|
|
|
|
window: window,
|
|
|
|
curve: QEasingCurve.InOutSine,
|
|
|
|
duration: squashEffect.duration,
|
|
|
|
animations: [
|
|
|
|
{
|
|
|
|
type: Effect.Size,
|
|
|
|
from: {
|
|
|
|
value1: windowRect.width,
|
|
|
|
value2: windowRect.height
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
value1: iconRect.width,
|
|
|
|
value2: iconRect.height
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: Effect.Translation,
|
|
|
|
from: {
|
|
|
|
value1: 0.0,
|
|
|
|
value2: 0.0
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
value1: iconRect.x - windowRect.x -
|
|
|
|
(windowRect.width - iconRect.width) / 2,
|
|
|
|
value2: iconRect.y - windowRect.y -
|
|
|
|
(windowRect.height - iconRect.height) / 2,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: Effect.Opacity,
|
|
|
|
from: 1.0,
|
|
|
|
to: 0.0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
},
|
|
|
|
slotWindowUnminimized: function (window) {
|
|
|
|
if (effects.hasActiveFullScreenEffect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the window doesn't have an icon in the task manager,
|
|
|
|
// don't animate it.
|
|
|
|
var iconRect = window.iconGeometry;
|
|
|
|
if (iconRect.width == 0 || iconRect.height == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window.minimizeAnimation) {
|
2018-10-24 20:25:00 +00:00
|
|
|
if (redirect(window.minimizeAnimation, Effect.Backward)) {
|
|
|
|
return;
|
|
|
|
}
|
[effects] Re-implement the Minimize Animation effect in JavaScript
Summary:
There were several reasons to rewrite the Minimize Animation effect in
JavaScript: to simplify code and to get rid of full repaints. One could
say that nothing prevents us from calculating the dirty region in
postPaintScreen or postPaintWindow and it is correct, but with the
scripting effects API the dirty region will be calculated for us, so we
can focus more on "what we want" instead of "how".
Visually, the "old" effect and the rewritten one look quite the same.
Except one tiny bit: if a window doesn't have an icon in the task manager,
it won't be animated. The reason for that is the purpose of this effect is
to show where the window will be after it's minimized, if the window
doesn't have icon in the task manager, one can't click at the center of
the screen to unminimize the window.
There is one significant change, the name of the effect was changed to
"Squash". If we put this effect and the Magic lamp effect under "Window
Minimize Animation" category (or if we add some "heading" label), then
the old name and the name of the category would "conflict". The new name
was suggested by Nate Graham and it very closely describes what the
effect does. "Scale" doesn't fit this effect because while a window is
being animated, its aspect ratio is not preserved.
Reviewers: #kwin, #plasma, davidedmundson
Reviewed By: #kwin, #plasma, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16372
2018-09-23 17:07:48 +00:00
|
|
|
cancel(window.minimizeAnimation);
|
|
|
|
delete window.minimizeAnimation;
|
|
|
|
}
|
|
|
|
|
2018-10-24 20:25:00 +00:00
|
|
|
if (window.unminimizeAnimation) {
|
|
|
|
if (redirect(window.unminimizeAnimation, Effect.Forward)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cancel(window.unminimizeAnimation);
|
|
|
|
}
|
|
|
|
|
[effects] Re-implement the Minimize Animation effect in JavaScript
Summary:
There were several reasons to rewrite the Minimize Animation effect in
JavaScript: to simplify code and to get rid of full repaints. One could
say that nothing prevents us from calculating the dirty region in
postPaintScreen or postPaintWindow and it is correct, but with the
scripting effects API the dirty region will be calculated for us, so we
can focus more on "what we want" instead of "how".
Visually, the "old" effect and the rewritten one look quite the same.
Except one tiny bit: if a window doesn't have an icon in the task manager,
it won't be animated. The reason for that is the purpose of this effect is
to show where the window will be after it's minimized, if the window
doesn't have icon in the task manager, one can't click at the center of
the screen to unminimize the window.
There is one significant change, the name of the effect was changed to
"Squash". If we put this effect and the Magic lamp effect under "Window
Minimize Animation" category (or if we add some "heading" label), then
the old name and the name of the category would "conflict". The new name
was suggested by Nate Graham and it very closely describes what the
effect does. "Scale" doesn't fit this effect because while a window is
being animated, its aspect ratio is not preserved.
Reviewers: #kwin, #plasma, davidedmundson
Reviewed By: #kwin, #plasma, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D16372
2018-09-23 17:07:48 +00:00
|
|
|
var windowRect = window.geometry;
|
|
|
|
|
|
|
|
window.unminimizeAnimation = animate({
|
|
|
|
window: window,
|
|
|
|
curve: QEasingCurve.InOutSine,
|
|
|
|
duration: squashEffect.duration,
|
|
|
|
animations: [
|
|
|
|
{
|
|
|
|
type: Effect.Size,
|
|
|
|
from: {
|
|
|
|
value1: iconRect.width,
|
|
|
|
value2: iconRect.height
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
value1: windowRect.width,
|
|
|
|
value2: windowRect.height
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: Effect.Translation,
|
|
|
|
from: {
|
|
|
|
value1: iconRect.x - windowRect.x -
|
|
|
|
(windowRect.width - iconRect.width) / 2,
|
|
|
|
value2: iconRect.y - windowRect.y -
|
|
|
|
(windowRect.height - iconRect.height) / 2,
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
value1: 0.0,
|
|
|
|
value2: 0.0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: Effect.Opacity,
|
|
|
|
from: 0.0,
|
|
|
|
to: 1.0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
},
|
|
|
|
init: function () {
|
|
|
|
effect.configChanged.connect(squashEffect.loadConfig);
|
|
|
|
effects.windowMinimized.connect(squashEffect.slotWindowMinimized);
|
|
|
|
effects.windowUnminimized.connect(squashEffect.slotWindowUnminimized);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
squashEffect.init();
|