Skip to content

Commit e180169

Browse files
committed
PropertyTarget: Don't require a ClutterActor
1 parent 03b5222 commit e180169

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lib/Gestures/PropertyTarget.vala

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,34 @@
77

88
public class Gala.PropertyTarget : Object, GestureTarget {
99
public GestureAction action { get; construct; }
10-
11-
//we don't want to hold a strong reference to the actor because we might've been added to it which would form a reference cycle
12-
private weak Clutter.Actor? _actor;
13-
public Clutter.Actor? actor { get { return _actor; } }
14-
10+
// Don't take a reference since we are most of the time owned by the target
11+
public weak Object? target { get; private set; }
1512
public string property { get; construct; }
1613

1714
public Clutter.Interval interval { get; construct; }
1815

19-
public PropertyTarget (GestureAction action, Clutter.Actor actor, string property, Type value_type, Value from_value, Value to_value) {
16+
public PropertyTarget (GestureAction action, Object target, string property, Type value_type, Value from_value, Value to_value) {
2017
Object (action: action, property: property, interval: new Clutter.Interval.with_values (value_type, from_value, to_value));
2118

22-
_actor = actor;
23-
_actor.destroy.connect (() => _actor = null);
19+
this.target = target;
20+
this.target.weak_ref (on_target_disposed);
21+
}
22+
23+
~PropertyTarget () {
24+
if (target != null) {
25+
target.weak_unref (on_target_disposed);
26+
}
27+
}
28+
29+
private void on_target_disposed () {
30+
target = null;
2431
}
2532

2633
public override void propagate (UpdateType update_type, GestureAction action, double progress) {
27-
if (update_type != UPDATE || action != this.action) {
34+
if (target == null || update_type != UPDATE || action != this.action) {
2835
return;
2936
}
3037

31-
actor.set_property (property, interval.compute (progress));
38+
target.set_property (property, interval.compute (progress));
3239
}
3340
}

0 commit comments

Comments
 (0)