js: Use GObject properties for animated properties

Clutter animations work on GObject properties on animatables. The
last commit took care of the latter by turning all animated objects
into actor subclasses, now it's time to make all properties used
in Tweens into GObject properties.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/666
This commit is contained in:
Florian Müllner 2019-07-25 22:13:19 +00:00
parent 3d3dca4aa2
commit dfa41f6926
4 changed files with 133 additions and 42 deletions

View File

@ -571,6 +571,12 @@ var FocusTracker = class {
Signals.addSignalMethods(FocusTracker.prototype); Signals.addSignalMethods(FocusTracker.prototype);
var EmojiPager = GObject.registerClass({ var EmojiPager = GObject.registerClass({
Properties: {
'delta': GObject.ParamSpec.int(
'delta', 'delta', 'delta',
GObject.ParamFlags.READWRITE,
0, GLib.MAXINT32, 0)
},
Signals: { Signals: {
'emoji': { param_types: [GObject.TYPE_STRING] }, 'emoji': { param_types: [GObject.TYPE_STRING] },
'page-changed': { 'page-changed': {
@ -619,7 +625,11 @@ var EmojiPager = GObject.registerClass({
else if (value < -this._width) else if (value < -this._width)
value = -this._width; value = -this._width;
if (this._delta == value)
return;
this._delta = value; this._delta = value;
this.notify('delta');
if (value == 0) if (value == 0)
return; return;

View File

@ -24,16 +24,31 @@ t = clamp(t, 0.0, 1.0);\n\
float pixel_brightness = mix(1.0, 1.0 - vignette_sharpness, t);\n\ float pixel_brightness = mix(1.0, 1.0 - vignette_sharpness, t);\n\
cogl_color_out.a = cogl_color_out.a * (1 - pixel_brightness * brightness);'; cogl_color_out.a = cogl_color_out.a * (1 - pixel_brightness * brightness);';
var RadialShaderEffect = GObject.registerClass( var RadialShaderEffect = GObject.registerClass({
class RadialShaderEffect extends Shell.GLSLEffect { Properties: {
'brightness': GObject.ParamSpec.float(
'brightness', 'brightness', 'brightness',
GObject.ParamFlags.READWRITE,
0, 1, 1
),
'sharpness': GObject.ParamSpec.float(
'sharpness', 'sharpness', 'sharpness',
GObject.ParamFlags.READWRITE,
0, 1, 0
)
}
}, class RadialShaderEffect extends Shell.GLSLEffect {
_init(params) { _init(params) {
this._brightness = undefined;
this._sharpness = undefined;
super._init(params); super._init(params);
this._brightnessLocation = this.get_uniform_location('brightness'); this._brightnessLocation = this.get_uniform_location('brightness');
this._sharpnessLocation = this.get_uniform_location('vignette_sharpness'); this._sharpnessLocation = this.get_uniform_location('vignette_sharpness');
this.brightness = 1.0; this.brightness = 1.0;
this.vignetteSharpness = 0.0; this.sharpness = 0.0;
} }
vfunc_build_pipeline() { vfunc_build_pipeline() {
@ -46,19 +61,25 @@ class RadialShaderEffect extends Shell.GLSLEffect {
} }
set brightness(v) { set brightness(v) {
if (this._brightness == v)
return;
this._brightness = v; this._brightness = v;
this.set_uniform_float(this._brightnessLocation, this.set_uniform_float(this._brightnessLocation,
1, [this._brightness]); 1, [this._brightness]);
this.notify('brightness');
} }
get vignetteSharpness() { get sharpness() {
return this._sharpness; return this._sharpness;
} }
set vignetteSharpness(v) { set sharpness(v) {
if (this._sharpness == v)
return;
this._sharpness = v; this._sharpness = v;
this.set_uniform_float(this._sharpnessLocation, this.set_uniform_float(this._sharpnessLocation,
1, [this._sharpness]); 1, [this._sharpness]);
this.notify('sharpness');
} }
}); });
@ -159,7 +180,7 @@ var Lightbox = class Lightbox {
Tweener.removeTweens(effect); Tweener.removeTweens(effect);
Tweener.addTween(effect, Tweener.addTween(effect,
{ brightness: VIGNETTE_BRIGHTNESS, { brightness: VIGNETTE_BRIGHTNESS,
vignetteSharpness: VIGNETTE_SHARPNESS, sharpness: VIGNETTE_SHARPNESS,
time: fadeInTime / 1000, time: fadeInTime / 1000,
transition: 'easeOutQuad', transition: 'easeOutQuad',
onComplete: () => { onComplete: () => {
@ -193,7 +214,7 @@ var Lightbox = class Lightbox {
Tweener.removeTweens(effect); Tweener.removeTweens(effect);
Tweener.addTween(effect, Tweener.addTween(effect,
{ brightness: 1.0, { brightness: 1.0,
vignetteSharpness: 0.0, sharpness: 0.0,
opacity: 0, opacity: 0,
time: fadeOutTime / 1000, time: fadeOutTime / 1000,
transition: 'easeOutQuad', transition: 'easeOutQuad',

View File

@ -26,11 +26,21 @@ var SlideDirection = {
RIGHT: 1 RIGHT: 1
}; };
var SlideLayout = GObject.registerClass( var SlideLayout = GObject.registerClass({
class SlideLayout extends Clutter.FixedLayout { Properties: {
'slide-x': GObject.ParamSpec.double(
'slide-x', 'slide-x', 'slide-x',
GObject.ParamFlags.READWRITE,
0, 1, 1),
'translation-x': GObject.ParamSpec.double(
'translation-x', 'translation-x', 'translation-x',
GObject.ParamFlags.READWRITE,
-Infinity, Infinity, 0)
}
}, class SlideLayout extends Clutter.FixedLayout {
_init(params) { _init(params) {
this._slideX = 1; this._slideX = 1;
this._translationX = undefined; this._translationX = 0;
this._direction = SlideDirection.LEFT; this._direction = SlideDirection.LEFT;
super._init(params); super._init(params);
@ -70,12 +80,17 @@ class SlideLayout extends Clutter.FixedLayout {
child.allocate(actorBox, flags); child.allocate(actorBox, flags);
} }
set slideX(value) { // eslint-disable-next-line camelcase
set slide_x(value) {
if (this._slideX == value)
return;
this._slideX = value; this._slideX = value;
this.notify('slide-x');
this.layout_changed(); this.layout_changed();
} }
get slideX() { // eslint-disable-next-line camelcase
get slide_x() {
return this._slideX; return this._slideX;
} }
@ -88,12 +103,17 @@ class SlideLayout extends Clutter.FixedLayout {
return this._direction; return this._direction;
} }
set translationX(value) { // eslint-disable-next-line camelcase
set translation_x(value) {
if (this._translationX == value)
return;
this._translationX = value; this._translationX = value;
this.notify('translation-x');
this.layout_changed(); this.layout_changed();
} }
get translationX() { // eslint-disable-next-line camelcase
get translation_x() {
return this._translationX; return this._translationX;
} }
}); });
@ -127,7 +147,7 @@ var SlidingControl = class {
} }
_updateSlide() { _updateSlide() {
Tweener.addTween(this.layout, { slideX: this._getSlide(), Tweener.addTween(this.layout, { slide_x: this._getSlide(),
time: SIDE_CONTROLS_ANIMATION_TIME / 1000, time: SIDE_CONTROLS_ANIMATION_TIME / 1000,
transition: 'easeOutQuad' }); transition: 'easeOutQuad' });
} }
@ -161,11 +181,11 @@ var SlidingControl = class {
translationEnd = translation; translationEnd = translation;
} }
if (this.layout.translationX == translationEnd) if (this.layout.translation_x == translationEnd)
return; return;
this.layout.translationX = translationStart; this.layout.translation_x = translationStart;
Tweener.addTween(this.layout, { translationX: translationEnd, Tweener.addTween(this.layout, { translation_x: translationEnd,
time: SIDE_CONTROLS_ANIMATION_TIME / 1000, time: SIDE_CONTROLS_ANIMATION_TIME / 1000,
transition: 'easeOutQuad' }); transition: 'easeOutQuad' });
} }
@ -213,13 +233,13 @@ var SlidingControl = class {
slideIn() { slideIn() {
this._visible = true; this._visible = true;
// we will update slideX and the translation from pageEmpty // we will update slide_x and the translation from pageEmpty
} }
slideOut() { slideOut() {
this._visible = false; this._visible = false;
this._updateTranslation(); this._updateTranslation();
// we will update slideX from pageEmpty // we will update slide_x from pageEmpty
} }
pageEmpty() { pageEmpty() {
@ -227,7 +247,7 @@ var SlidingControl = class {
// selector; this means we can now safely set the full slide for // selector; this means we can now safely set the full slide for
// the next page, since slideIn or slideOut might have been called, // the next page, since slideIn or slideOut might have been called,
// changing the visiblity // changing the visiblity
this.layout.slideX = this._getSlide(); this.layout.slide_x = this._getSlide();
this._updateTranslation(); this._updateTranslation();
} }
}; };

View File

@ -244,8 +244,18 @@ var ThumbnailState = {
/** /**
* @metaWorkspace: a #Meta.Workspace * @metaWorkspace: a #Meta.Workspace
*/ */
var WorkspaceThumbnail = GObject.registerClass( var WorkspaceThumbnail = GObject.registerClass({
class WorkspaceThumbnail extends St.Widget { Properties: {
'collapse-fraction': GObject.ParamSpec.double(
'collapse-fraction', 'collapse-fraction', 'collapse-fraction',
GObject.ParamFlags.READWRITE,
0, 1, 0),
'slide-position': GObject.ParamSpec.double(
'slide-position', 'slide-position', 'slide-position',
GObject.ParamFlags.READWRITE,
0, 1, 0),
}
}, class WorkspaceThumbnail extends St.Widget {
_init(metaWorkspace) { _init(metaWorkspace) {
super._init({ super._init({
clip_to_allocation: true, clip_to_allocation: true,
@ -337,21 +347,31 @@ class WorkspaceThumbnail extends St.Widget {
} }
} }
set slidePosition(slidePosition) { // eslint-disable-next-line camelcase
set slide_position(slidePosition) {
if (this._slidePosition == slidePosition)
return;
this._slidePosition = slidePosition; this._slidePosition = slidePosition;
this.notify('slide-position');
this.queue_relayout(); this.queue_relayout();
} }
get slidePosition() { // eslint-disable-next-line camelcase
get slide_position() {
return this._slidePosition; return this._slidePosition;
} }
set collapseFraction(collapseFraction) { // eslint-disable-next-line camelcase
set collapse_fraction(collapseFraction) {
if (this._collapseFraction == collapseFraction)
return;
this._collapseFraction = collapseFraction; this._collapseFraction = collapseFraction;
this.notify('collapse-fraction');
this.queue_relayout(); this.queue_relayout();
} }
get collapseFraction() { // eslint-disable-next-line camelcase
get collapse_fraction() {
return this._collapseFraction; return this._collapseFraction;
} }
@ -590,8 +610,18 @@ class WorkspaceThumbnail extends St.Widget {
}); });
var ThumbnailsBox = GObject.registerClass( var ThumbnailsBox = GObject.registerClass({
class ThumbnailsBox extends St.Widget { Properties: {
'indicator-y': GObject.ParamSpec.double(
'indicator-y', 'indicator-y', 'indicator-y',
GObject.ParamFlags.READWRITE,
0, Infinity, 0),
'scale': GObject.ParamSpec.double(
'scale', 'scale', 'scale',
GObject.ParamFlags.READWRITE,
0, Infinity, 0)
}
}, class ThumbnailsBox extends St.Widget {
_init() { _init() {
super._init({ reactive: true, super._init({ reactive: true,
style_class: 'workspace-thumbnails', style_class: 'workspace-thumbnails',
@ -843,7 +873,7 @@ class ThumbnailsBox extends St.Widget {
// an old one which just became empty) // an old one which just became empty)
let thumbnail = this._thumbnails[newWorkspaceIndex]; let thumbnail = this._thumbnails[newWorkspaceIndex];
this._setThumbnailState(thumbnail, ThumbnailState.NEW); this._setThumbnailState(thumbnail, ThumbnailState.NEW);
thumbnail.slidePosition = 1; thumbnail.slide_position = 1;
this._queueUpdateStates(); this._queueUpdateStates();
@ -956,7 +986,7 @@ class ThumbnailsBox extends St.Widget {
if (start > 0 && this._spliceIndex == -1) { if (start > 0 && this._spliceIndex == -1) {
// not the initial fill, and not splicing via DND // not the initial fill, and not splicing via DND
thumbnail.state = ThumbnailState.NEW; thumbnail.state = ThumbnailState.NEW;
thumbnail.slidePosition = 1; // start slid out thumbnail.slide_position = 1; // start slid out
this._haveNewThumbnails = true; this._haveNewThumbnails = true;
} else { } else {
thumbnail.state = ThumbnailState.NORMAL; thumbnail.state = ThumbnailState.NORMAL;
@ -999,7 +1029,11 @@ class ThumbnailsBox extends St.Widget {
} }
set scale(scale) { set scale(scale) {
if (this._scale == scale)
return;
this._scale = scale; this._scale = scale;
this.notify('scale');
this.queue_relayout(); this.queue_relayout();
} }
@ -1007,12 +1041,18 @@ class ThumbnailsBox extends St.Widget {
return this._scale; return this._scale;
} }
set indicatorY(indicatorY) { // eslint-disable-next-line camelcase
set indicator_y(indicatorY) {
if (this._indicatorY == indicatorY)
return;
this._indicatorY = indicatorY; this._indicatorY = indicatorY;
this.notify('indicator-y');
this.queue_relayout(); this.queue_relayout();
} }
get indicatorY() { // eslint-disable-next-line camelcase
get indicator_y() {
return this._indicatorY; return this._indicatorY;
} }
@ -1053,7 +1093,7 @@ class ThumbnailsBox extends St.Widget {
this._setThumbnailState(thumbnail, ThumbnailState.ANIMATING_OUT); this._setThumbnailState(thumbnail, ThumbnailState.ANIMATING_OUT);
Tweener.addTween(thumbnail, Tweener.addTween(thumbnail,
{ slidePosition: 1, { slide_position: 1,
time: SLIDE_ANIMATION_TIME / 1000, time: SLIDE_ANIMATION_TIME / 1000,
transition: 'linear', transition: 'linear',
onComplete: () => { onComplete: () => {
@ -1071,7 +1111,7 @@ class ThumbnailsBox extends St.Widget {
this._iterateStateThumbnails(ThumbnailState.ANIMATED_OUT, thumbnail => { this._iterateStateThumbnails(ThumbnailState.ANIMATED_OUT, thumbnail => {
this._setThumbnailState(thumbnail, ThumbnailState.COLLAPSING); this._setThumbnailState(thumbnail, ThumbnailState.COLLAPSING);
Tweener.addTween(thumbnail, Tweener.addTween(thumbnail,
{ collapseFraction: 1, { collapse_fraction: 1,
time: RESCALE_ANIMATION_TIME / 1000, time: RESCALE_ANIMATION_TIME / 1000,
transition: 'easeOutQuad', transition: 'easeOutQuad',
onComplete: () => { onComplete: () => {
@ -1100,7 +1140,7 @@ class ThumbnailsBox extends St.Widget {
this._iterateStateThumbnails(ThumbnailState.NEW, thumbnail => { this._iterateStateThumbnails(ThumbnailState.NEW, thumbnail => {
this._setThumbnailState(thumbnail, ThumbnailState.ANIMATING_IN); this._setThumbnailState(thumbnail, ThumbnailState.ANIMATING_IN);
Tweener.addTween(thumbnail, Tweener.addTween(thumbnail,
{ slidePosition: 0, { slide_position: 0,
time: SLIDE_ANIMATION_TIME / 1000, time: SLIDE_ANIMATION_TIME / 1000,
transition: 'easeOutQuad', transition: 'easeOutQuad',
onComplete: () => { onComplete: () => {
@ -1241,14 +1281,14 @@ class ThumbnailsBox extends St.Widget {
let thumbnail = this._thumbnails[i]; let thumbnail = this._thumbnails[i];
if (i > 0) if (i > 0)
y += spacing - Math.round(thumbnail.collapseFraction * spacing); y += spacing - Math.round(thumbnail.collapse_fraction * spacing);
let x1, x2; let x1, x2;
if (rtl) { if (rtl) {
x1 = box.x1 + slideOffset * thumbnail.slidePosition; x1 = box.x1 + slideOffset * thumbnail.slide_position;
x2 = x1 + thumbnailWidth; x2 = x1 + thumbnailWidth;
} else { } else {
x1 = box.x2 - thumbnailWidth + slideOffset * thumbnail.slidePosition; x1 = box.x2 - thumbnailWidth + slideOffset * thumbnail.slide_position;
x2 = x1 + thumbnailWidth; x2 = x1 + thumbnailWidth;
} }
@ -1291,7 +1331,7 @@ class ThumbnailsBox extends St.Widget {
// We round the collapsing portion so that we don't get thumbnails resizing // We round the collapsing portion so that we don't get thumbnails resizing
// during an animation due to differences in rounded, but leave the uncollapsed // during an animation due to differences in rounded, but leave the uncollapsed
// portion unrounded so that non-animating we end up with the right total // portion unrounded so that non-animating we end up with the right total
y += thumbnailHeight - Math.round(thumbnailHeight * thumbnail.collapseFraction); y += thumbnailHeight - Math.round(thumbnailHeight * thumbnail.collapse_fraction);
} }
if (rtl) { if (rtl) {
@ -1322,9 +1362,9 @@ class ThumbnailsBox extends St.Widget {
this._animatingIndicator = true; this._animatingIndicator = true;
let indicatorThemeNode = this._indicator.get_theme_node(); let indicatorThemeNode = this._indicator.get_theme_node();
let indicatorTopFullBorder = indicatorThemeNode.get_padding(St.Side.TOP) + indicatorThemeNode.get_border_width(St.Side.TOP); let indicatorTopFullBorder = indicatorThemeNode.get_padding(St.Side.TOP) + indicatorThemeNode.get_border_width(St.Side.TOP);
this.indicatorY = this._indicator.allocation.y1 + indicatorTopFullBorder; this.indicator_y = this._indicator.allocation.y1 + indicatorTopFullBorder;
Tweener.addTween(this, Tweener.addTween(this,
{ indicatorY: thumbnail.allocation.y1, { indicator_y: thumbnail.allocation.y1,
time: WorkspacesView.WORKSPACE_SWITCH_TIME / 1000, time: WorkspacesView.WORKSPACE_SWITCH_TIME / 1000,
transition: 'easeOutQuad', transition: 'easeOutQuad',
onComplete: () => { onComplete: () => {