Skip to content

Commit 11ec157

Browse files
committed
dnd.js: Convert GenericDragPlaceHolderItem to a real class, get rid
of last use of addTween. - Keep .child and .actor compatibility (point to self) - keep Tweener.getTweenCount check, since many spices still use Tweener, and check for existing transitions also.
1 parent 5e4efae commit 11ec157

6 files changed

Lines changed: 76 additions & 189 deletions

File tree

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -835,14 +835,14 @@ class GroupedWindowListApplet extends Applet.Applet {
835835

836836
if(this.state.dragging.isForeign) {
837837
if (this.state.dragging.dragPlaceholder)
838-
currentWorkspace.actor.set_child_at_index(this.state.dragging.dragPlaceholder.actor, pos);
838+
currentWorkspace.actor.set_child_at_index(this.state.dragging.dragPlaceholder, pos);
839839
else {
840840
const iconSize = this.getPanelIconSize() * global.ui_scale;
841841
this.state.dragging.dragPlaceholder = new DND.GenericDragPlaceholderItem();
842-
this.state.dragging.dragPlaceholder.child.width = iconSize;
843-
this.state.dragging.dragPlaceholder.child.height = iconSize;
842+
this.state.dragging.dragPlaceholder.width = iconSize;
843+
this.state.dragging.dragPlaceholder.height = iconSize;
844844
currentWorkspace.actor.insert_child_at_index(
845-
this.state.dragging.dragPlaceholder.actor,
845+
this.state.dragging.dragPlaceholder,
846846
this.state.dragging.pos
847847
);
848848
this.state.dragging.dragPlaceholder.animateIn();
@@ -893,7 +893,7 @@ class GroupedWindowListApplet extends Applet.Applet {
893893
if(animate)
894894
this.state.dragging.dragPlaceholder.animateOutAndDestroy();
895895
else
896-
this.state.dragging.dragPlaceholder.actor.destroy();
896+
this.state.dragging.dragPlaceholder.destroy();
897897
this.state.dragging.dragPlaceholder = null;
898898
}
899899
}

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ class FavoriteAppsBox {
11231123
// the remove target has the same size as "normal" items, we don't
11241124
// need to do the same adjustment there.
11251125
if (this._dragPlaceholder) {
1126-
boxHeight -= this._dragPlaceholder.actor.height;
1126+
boxHeight -= this._dragPlaceholder.height;
11271127
numChildren--;
11281128
}
11291129

@@ -1144,7 +1144,7 @@ class FavoriteAppsBox {
11441144
if (this._dragPlaceholder) {
11451145
this._dragPlaceholder.animateOutAndDestroy();
11461146
this._animatingPlaceholdersCount++;
1147-
this._dragPlaceholder.actor.connect('destroy', () => {
1147+
this._dragPlaceholder.connect('destroy', () => {
11481148
this._animatingPlaceholdersCount--;
11491149
});
11501150
}
@@ -1158,16 +1158,16 @@ class FavoriteAppsBox {
11581158
// an animation
11591159
let fadeIn;
11601160
if (this._dragPlaceholder) {
1161-
this._dragPlaceholder.actor.destroy();
1161+
this._dragPlaceholder.destroy();
11621162
fadeIn = false;
11631163
} else {
11641164
fadeIn = true;
11651165
}
11661166

11671167
this._dragPlaceholder = new DND.GenericDragPlaceholderItem();
1168-
this._dragPlaceholder.child.set_width (source.actor.height);
1169-
this._dragPlaceholder.child.set_height (source.actor.height);
1170-
this.actor.insert_child_at_index(this._dragPlaceholder.actor,
1168+
this._dragPlaceholder.set_width (source.actor.height);
1169+
this._dragPlaceholder.set_height (source.actor.height);
1170+
this.actor.insert_child_at_index(this._dragPlaceholder,
11711171
this._dragPlaceholderPos);
11721172
if (fadeIn)
11731173
this._dragPlaceholder.animateIn();
@@ -1197,7 +1197,7 @@ class FavoriteAppsBox {
11971197
let children = this.actor.get_children();
11981198
for (let i = 0; i < this._dragPlaceholderPos; i++) {
11991199
if (this._dragPlaceholder &&
1200-
children[i] == this._dragPlaceholder.actor)
1200+
children[i] == this._dragPlaceholder)
12011201
continue;
12021202

12031203
if (!(children[i]._delegate instanceof FavoritesButton)) continue;

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ class LaunchersBox {
364364
let vertical = this.applet.orientation == St.Side.LEFT || this.applet.orientation == St.Side.RIGHT;
365365
this._dragPlaceholder = new DND.GenericDragPlaceholderItem();
366366
let placeholderSize = vertical ? [1, this.applet.icon_size * global.ui_scale] : [this.applet.icon_size * global.ui_scale, 1];
367-
this._dragPlaceholder.child.set_size(...placeholderSize);
368-
this.actor.insert_child_at_index(this._dragPlaceholder.actor, index);
367+
this._dragPlaceholder.set_size(...placeholderSize);
368+
this.actor.insert_child_at_index(this._dragPlaceholder, index);
369369

370370
if (!skipAnimation) {
371371
this._dragAnimating = true;
@@ -381,7 +381,7 @@ class LaunchersBox {
381381

382382
if (this._dragPlaceholder) {
383383
if (skipAnimation) {
384-
this._dragPlaceholder.actor.destroy();
384+
this._dragPlaceholder.destroy();
385385
} else {
386386
this._dragAnimating = true;
387387
this._dragPlaceholder.animateOutAndDestroy(() => this._dragAnimating = false);
@@ -434,7 +434,7 @@ class LaunchersBox {
434434
// animates in a new placeholder
435435
this._createDragPlaceholder(dropIndex);
436436
} else {
437-
this.actor.set_child_at_index(this._dragPlaceholder.actor, dropIndex);
437+
this.actor.set_child_at_index(this._dragPlaceholder, dropIndex);
438438
}
439439
this._dragTargetIndex = dropIndex;
440440
}

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,13 +1532,13 @@ class CinnamonWindowListApplet extends Applet.Applet {
15321532
source.actor.hide();
15331533
if (this._dragPlaceholder == undefined) {
15341534
this._dragPlaceholder = new DND.GenericDragPlaceholderItem();
1535-
this._dragPlaceholder.child.set_width (source.actor.width);
1536-
this._dragPlaceholder.child.set_height (source.actor.height);
1535+
this._dragPlaceholder.set_width (source.actor.width);
1536+
this._dragPlaceholder.set_height (source.actor.height);
15371537

1538-
this.manager_container.insert_child_at_index(this._dragPlaceholder.actor,
1538+
this.manager_container.insert_child_at_index(this._dragPlaceholder,
15391539
this._dragPlaceholderPos);
15401540
} else {
1541-
this.manager_container.set_child_at_index(this._dragPlaceholder.actor,
1541+
this.manager_container.set_child_at_index(this._dragPlaceholder,
15421542
this._dragPlaceholderPos);
15431543
}
15441544

@@ -1559,7 +1559,7 @@ class CinnamonWindowListApplet extends Applet.Applet {
15591559

15601560
clearDragPlaceholder() {
15611561
if (this._dragPlaceholder) {
1562-
this._dragPlaceholder.actor.destroy();
1562+
this._dragPlaceholder.destroy();
15631563
this._dragPlaceholder = undefined;
15641564
this._dragPlaceholderPos = undefined;
15651565
}

js/ui/dnd.js

Lines changed: 48 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const Clutter = imports.gi.Clutter;
44
const GLib = imports.gi.GLib;
5+
const GObject = imports.gi.GObject;
56
const Gtk = imports.gi.Gtk;
67
const St = imports.gi.St;
78
const Lang = imports.lang;
@@ -12,7 +13,7 @@ const Main = imports.ui.main;
1213

1314
const Params = imports.misc.params;
1415

15-
var DND_ANIMATION_TIME = 0.2;
16+
var DND_ANIMATION_TIME = 200;
1617
// Time to scale down to maxDragActorSize
1718
var SCALE_ANIMATION_TIME = 250;
1819
// Time to animate to original position on cancel
@@ -139,6 +140,9 @@ var _Draggable = new Lang.Class({
139140
if (Tweener.getTweenCount(actor))
140141
return false;
141142

143+
if (['opacity', 'scale-x', 'scale-y', 'x', 'y', 'width', 'height'].some(p => actor.get_transition(p)))
144+
return false;
145+
142146
// Clean up any existing grab before starting a new one (fixes #13462)
143147
// This prevents pointer grabs from accumulating during rapid clicks
144148
if (this._onEventId) {
@@ -706,172 +710,55 @@ function makeDraggable(actor, params, target) {
706710
return new _Draggable(actor, params, target);
707711
}
708712

709-
function GenericDragItemContainer() {
710-
this._init();
711-
}
712-
713-
GenericDragItemContainer.prototype = {
714-
_init: function() {
715-
this.actor = new Cinnamon.GenericContainer({ style_class: 'drag-item-container' });
716-
this.actor.connect('get-preferred-width',
717-
Lang.bind(this, this._getPreferredWidth));
718-
this.actor.connect('get-preferred-height',
719-
Lang.bind(this, this._getPreferredHeight));
720-
this.actor.connect('allocate',
721-
Lang.bind(this, this._allocate));
722-
this.actor._delegate = this;
723-
724-
this.child = null;
725-
this._childScale = 1;
726-
this._childOpacity = 255;
727-
this.animatingOut = false;
728-
},
729-
730-
_allocate: function(actor, box, flags) {
731-
if (this.child == null)
732-
return;
733-
734-
let availWidth = box.x2 - box.x1;
735-
let availHeight = box.y2 - box.y1;
736-
let [minChildWidth, minChildHeight, natChildWidth, natChildHeight] =
737-
this.child.get_preferred_size();
738-
let [childScaleX, childScaleY] = this.child.get_scale();
739-
740-
let childWidth = Math.min(natChildWidth * childScaleX, availWidth);
741-
let childHeight = Math.min(natChildHeight * childScaleY, availHeight);
742-
743-
let childBox = new Clutter.ActorBox();
744-
childBox.x1 = (availWidth - childWidth) / 2;
745-
childBox.y1 = (availHeight - childHeight) / 2;
746-
childBox.x2 = childBox.x1 + childWidth;
747-
childBox.y2 = childBox.y1 + childHeight;
748-
749-
this.child.allocate(childBox, flags);
750-
},
751-
752-
_getPreferredHeight: function(actor, forWidth, alloc) {
753-
alloc.min_size = 0;
754-
alloc.natural_size = 0;
755-
756-
if (this.child == null)
757-
return;
758-
759-
let [minHeight, natHeight] = this.child.get_preferred_height(forWidth);
760-
alloc.min_size += minHeight * this.child.scale_y;
761-
alloc.natural_size += natHeight * this.child.scale_y;
762-
},
763-
764-
_getPreferredWidth: function(actor, forHeight, alloc) {
765-
alloc.min_size = 0;
766-
alloc.natural_size = 0;
767-
768-
if (this.child == null)
769-
return;
770-
771-
let [minWidth, natWidth] = this.child.get_preferred_width(forHeight);
772-
alloc.min_size = minWidth * this.child.scale_y;
773-
alloc.natural_size = natWidth * this.child.scale_y;
774-
},
775-
776-
setChild: function(actor) {
777-
if (this.child == actor)
778-
return;
779-
780-
this.actor.destroy_all_children();
781-
782-
this.child = actor;
783-
this.actor.add_actor(this.child);
784-
},
785-
786-
animateIn: function(onCompleteFunc) {
787-
if (!this.child) {
788-
if (typeof(onCompleteFunc) === 'function')
789-
onCompleteFunc();
790-
return;
791-
}
792-
793-
this.childScale = 0;
794-
this.childOpacity = 0;
795-
796-
let params = { childScale: 1.0,
797-
childOpacity: 255,
798-
time: DND_ANIMATION_TIME,
799-
transition: 'easeOutQuad' };
800-
801-
if (typeof(onCompleteFunc) === 'function')
802-
params.onComplete = onCompleteFunc;
803-
804-
Tweener.addTween(this, params);
805-
},
806-
807-
animateOutAndDestroy: function(onCompleteFunc) {
808-
let _onComplete = () => {
809-
if (typeof(onCompleteFunc) === 'function')
810-
onCompleteFunc();
811-
this.actor.destroy();
812-
};
813-
814-
if (!this.child) {
815-
_onComplete();
816-
return;
817-
}
818-
819-
this.animatingOut = true;
820-
this.childScale = 1.0;
821-
Tweener.addTween(this,
822-
{ childScale: 0.0,
823-
childOpacity: 0,
824-
time: DND_ANIMATION_TIME,
825-
transition: 'easeOutQuad',
826-
onComplete: _onComplete });
827-
},
828-
829-
set childScale(scale) {
830-
if (this.child.is_finalized()) return;
831-
this._childScale = scale;
832-
833-
if (this.child == null)
834-
return;
835-
836-
this.child.pivot_point.x = 0.5;
837-
this.child.pivot_point.y = 0.5;
838-
this.child.scale_x = scale;
839-
this.child.scale_y = scale;
840-
this.actor.queue_relayout();
841-
},
842-
843-
get childScale() {
844-
return this._childScale;
845-
},
846-
847-
set childOpacity(opacity) {
848-
if (this.child.is_finalized()) return;
849-
this._childOpacity = opacity;
850-
851-
if (this.child == null)
852-
return;
853-
854-
this.child.set_opacity(opacity);
855-
this.actor.queue_redraw();
856-
},
713+
var GenericDragPlaceholderItem = GObject.registerClass(
714+
class GenericDragPlaceholderItem extends St.Bin {
715+
_init() {
716+
super._init({ style_class: 'drag-placeholder' });
717+
this._delegate = this;
718+
}
857719

858-
get childOpacity() {
859-
return this._childOpacity;
720+
get actor() {
721+
return this;
860722
}
861-
};
862723

863-
function GenericDragPlaceholderItem() {
864-
this._init();
865-
}
724+
get child() {
725+
return this;
726+
}
866727

867-
GenericDragPlaceholderItem.prototype = {
868-
__proto__: GenericDragItemContainer.prototype,
728+
animateIn(onCompleteFunc) {
729+
let targetWidth = this.width;
730+
let targetHeight = this.height;
731+
732+
this.set_size(0, 0);
733+
this.set_opacity(0);
734+
this.ease({
735+
width: targetWidth,
736+
height: targetHeight,
737+
opacity: 255,
738+
duration: DND_ANIMATION_TIME,
739+
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
740+
onComplete: () => {
741+
if (typeof onCompleteFunc === 'function')
742+
onCompleteFunc();
743+
}
744+
});
745+
}
869746

870-
_init: function() {
871-
GenericDragItemContainer.prototype._init.call(this);
872-
this.setChild(new St.Bin({ style_class: 'drag-placeholder' }));
747+
animateOutAndDestroy(onCompleteFunc) {
748+
this.ease({
749+
width: 0,
750+
height: 0,
751+
opacity: 0,
752+
duration: DND_ANIMATION_TIME,
753+
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
754+
onComplete: () => {
755+
if (typeof onCompleteFunc === 'function')
756+
onCompleteFunc();
757+
this.destroy();
758+
}
759+
});
873760
}
874-
};
761+
});
875762

876763
var LauncherDraggable = class {
877764
constructor(launchersBox) {

0 commit comments

Comments
 (0)