|
7 | 7 |
|
8 | 8 | public class Gala.PropertyTarget : Object, GestureTarget { |
9 | 9 | 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; } |
15 | 12 | public string property { get; construct; } |
16 | 13 |
|
17 | 14 | public Clutter.Interval interval { get; construct; } |
18 | 15 |
|
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 | + } |
21 | 27 |
|
22 | | - _actor = actor; |
23 | | - _actor.destroy.connect (() => _actor = null); |
| 28 | + private void on_target_disposed () { |
| 29 | + target = null; |
24 | 30 | } |
25 | 31 |
|
26 | 32 | 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) { |
28 | 34 | return; |
29 | 35 | } |
30 | 36 |
|
31 | | - actor.set_property (property, interval.compute (progress)); |
| 37 | + target.set_property (property, interval.compute (progress)); |
32 | 38 | } |
33 | 39 | } |
0 commit comments