Skip to content

Commit e7ab690

Browse files
committed
PropertyTarget: Don't require a ClutterActor
1 parent 3647da5 commit e7ab690

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lib/Gestures/PropertyTarget.vala

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,33 @@
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) {
20-
Object (action: action, property: property, interval: new Clutter.Interval.with_values (value_type, from_value, to_value));
16+
public PropertyTarget (GestureAction action, Object target, string property, Type value_type, Value from_value, Value to_value) {
17+
Object (action: action, target: target, property: property, interval: new Clutter.Interval.with_values (value_type, from_value, to_value));
18+
19+
target.weak_ref (on_target_disposed);
20+
}
21+
22+
~PropertyTarget () {
23+
if (target != null) {
24+
target.weak_unref (on_target_disposed);
25+
}
26+
}
2127

22-
_actor = actor;
23-
_actor.destroy.connect (() => _actor = null);
28+
private void on_target_disposed () {
29+
target = null;
2430
}
2531

2632
public override void propagate (UpdateType update_type, GestureAction action, double progress) {
27-
if (update_type != UPDATE || action != this.action) {
33+
if (target == null || update_type != UPDATE || action != this.action) {
2834
return;
2935
}
3036

31-
actor.set_property (property, interval.compute (progress));
37+
target.set_property (property, interval.compute (progress));
3238
}
3339
}

0 commit comments

Comments
 (0)