Skip to content

Commit a2ae8a5

Browse files
committed
Some API improvements
1 parent 2b7653d commit a2ae8a5

File tree

4 files changed

+56
-60
lines changed

4 files changed

+56
-60
lines changed

src/Gestures/PropertyGestureTransition.vala

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11

22

3+
34
public class Gala.GesturePropertyTransition : Object {
5+
46
public signal void done ();
57

68
public Clutter.Actor actor { get; construct; }
79
public GestureTracker gesture_tracker { get; construct; }
810
public string property { get; construct; }
9-
public Value? from_value { get; construct; }
10-
public Value to_value { get; construct; }
11-
public bool with_gesture { get; construct; }
11+
public Value? from_value { get; construct set; }
12+
public Value to_value { get; construct set; }
1213
public Value? intermediate_value { get; construct; }
14+
public bool reversed { get; construct set; default = false; }
1315

1416
public GesturePropertyTransition (
1517
Clutter.Actor actor,
1618
GestureTracker gesture_tracker,
1719
string property,
1820
Value? from_value,
1921
Value to_value,
20-
bool with_gesture,
2122
Value? intermediate_value = null
2223
) {
2324
Object (
@@ -26,21 +27,25 @@ public class Gala.GesturePropertyTransition : Object {
2627
property: property,
2728
from_value: from_value,
2829
to_value: to_value,
29-
with_gesture: with_gesture,
3030
intermediate_value: intermediate_value
3131
);
3232
}
3333

34-
construct {
35-
ref ();
36-
34+
public void start (bool with_gesture) {
3735
if (from_value == null) {
38-
Value current_value;
36+
Value current_value = {};
3937
actor.get_property (property, ref current_value);
4038
from_value = current_value;
39+
40+
ulong done_handler = 0;
41+
done_handler = done.connect (() => {
42+
from_value = null;
43+
disconnect (done_handler);
44+
});
4145
}
4246

4347
GestureTracker.OnBegin on_animation_begin = () => {
48+
ref ();
4449
actor.set_property (property, from_value);
4550
};
4651

@@ -60,9 +65,16 @@ public class Gala.GesturePropertyTransition : Object {
6065
actor.set_property (property, cancel_action ? from_value : to_value);
6166
actor.restore_easing_state ();
6267

63-
done ();
64-
65-
unref ();
68+
unowned var transition = actor.get_transition (property);
69+
if (transition == null) {
70+
done ();
71+
unref ();
72+
} else {
73+
transition.stopped.connect (() => {
74+
done ();
75+
unref ();
76+
});
77+
}
6678
};
6779

6880
if (with_gesture) {

src/Widgets/MultitaskingView.vala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ namespace Gala {
384384
}
385385

386386
if (is_nudge_animation) {
387-
new GesturePropertyTransition (workspaces, workspace_gesture_tracker, "x", null, initial_x, true, initial_x + nudge_gap * -relative_dir);
387+
new GesturePropertyTransition (workspaces, workspace_gesture_tracker, "x", null, initial_x, initial_x + nudge_gap * -relative_dir).start (true);
388388
} else {
389-
new GesturePropertyTransition (workspaces, workspace_gesture_tracker, "x", null, target_x, true);
390-
new GesturePropertyTransition (active_icon_group, workspace_gesture_tracker, "backdrop-opacity", 1f, 0f, true);
391-
new GesturePropertyTransition (target_icon_group, workspace_gesture_tracker, "backdrop-opacity", 0f, 1f, true);
389+
new GesturePropertyTransition (workspaces, workspace_gesture_tracker, "x", null, target_x).start (true);
390+
new GesturePropertyTransition (active_icon_group, workspace_gesture_tracker, "backdrop-opacity", 1f, 0f).start (true);
391+
new GesturePropertyTransition (target_icon_group, workspace_gesture_tracker, "backdrop-opacity", 0f, 1f).start (true);
392392
}
393393

394394
GestureTracker.OnEnd on_animation_end = (percentage, cancel_action, calculated_duration) => {

src/Widgets/WindowClone.vala

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,17 @@ public class Gala.WindowClone : Clutter.Actor {
288288
in_slot_animation = true;
289289
place_widgets (outer_rect.width, outer_rect.height, initial_scale);
290290

291-
new GesturePropertyTransition (this, gesture_tracker, "x", null, (float) target_x, with_gesture);
292-
new GesturePropertyTransition (this, gesture_tracker, "y", null, (float) target_y, with_gesture);
293-
new GesturePropertyTransition (this, gesture_tracker, "width", null, (float) outer_rect.width, with_gesture);
294-
new GesturePropertyTransition (this, gesture_tracker, "height", null, (float) outer_rect.height, with_gesture);
295-
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", 255f, 0f, with_gesture);
296-
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 255f, 0f, with_gesture);
291+
new GesturePropertyTransition (this, gesture_tracker, "x", null, (float) target_x).start (with_gesture);
292+
new GesturePropertyTransition (this, gesture_tracker, "y", null, (float) target_y).start (with_gesture);
293+
new GesturePropertyTransition (this, gesture_tracker, "width", null, (float) outer_rect.width).start (with_gesture);
294+
new GesturePropertyTransition (this, gesture_tracker, "height", null, (float) outer_rect.height).start (with_gesture);
295+
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", 255f, 0f).start (with_gesture);
296+
var opacity_transition = new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 255f, 0f);
297+
opacity_transition.start (with_gesture);
298+
opacity_transition.done.connect (() => {
299+
in_slot_animation = false;
300+
place_widgets (outer_rect.width, outer_rect.height, target_scale);
301+
});
297302

298303
GestureTracker.OnUpdate on_animation_update = (percentage) => {
299304
var width = GestureTracker.animation_value (initial_width, outer_rect.width, percentage);
@@ -320,17 +325,6 @@ public class Gala.WindowClone : Clutter.Actor {
320325
window_icon.set_easing_duration (duration);
321326
set_window_icon_position (outer_rect.width, outer_rect.height, target_scale);
322327
window_icon.restore_easing_state ();
323-
324-
var transition = window_icon.get_transition ("opacity");
325-
if (transition != null) {
326-
transition.completed.connect (() => {
327-
in_slot_animation = false;
328-
place_widgets (outer_rect.width, outer_rect.height, target_scale);
329-
});
330-
} else {
331-
in_slot_animation = false;
332-
place_widgets (outer_rect.width, outer_rect.height, target_scale);
333-
}
334328
};
335329

336330
if (!animate || gesture_tracker == null || !with_gesture || !wm.enable_animations) {
@@ -359,12 +353,17 @@ public class Gala.WindowClone : Clutter.Actor {
359353
in_slot_animation = true;
360354
place_widgets (rect.width, rect.height, scale);
361355

362-
new GesturePropertyTransition (this, gesture_tracker, "x", null, (float) rect.x, with_gesture);
363-
new GesturePropertyTransition (this, gesture_tracker, "y", null, (float) rect.y, with_gesture);
364-
new GesturePropertyTransition (this, gesture_tracker, "width", null, (float) rect.width, with_gesture);
365-
new GesturePropertyTransition (this, gesture_tracker, "height", null, (float) rect.height, with_gesture);
366-
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", 0f, 255f, with_gesture);
367-
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 0f, 255f, with_gesture);
356+
new GesturePropertyTransition (this, gesture_tracker, "x", null, (float) rect.x).start (with_gesture);
357+
new GesturePropertyTransition (this, gesture_tracker, "y", null, (float) rect.y).start (with_gesture);
358+
new GesturePropertyTransition (this, gesture_tracker, "width", null, (float) rect.width).start (with_gesture);
359+
new GesturePropertyTransition (this, gesture_tracker, "height", null, (float) rect.height).start (with_gesture);
360+
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", 0f, 255f).start (with_gesture);
361+
var opacity_transition = new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 0f, 255f);
362+
opacity_transition.start (with_gesture);
363+
opacity_transition.done.connect (() => {
364+
in_slot_animation = false;
365+
place_widgets (rect.width, rect.height, scale);
366+
});
368367

369368
GestureTracker.OnUpdate on_animation_update = (percentage) => {
370369
var width = GestureTracker.animation_value (initial_width, rect.width, percentage);
@@ -380,25 +379,13 @@ public class Gala.WindowClone : Clutter.Actor {
380379

381380
var duration = wm.enable_animations ? MultitaskingView.ANIMATION_DURATION : 0;
382381

383-
384382
window_icon.save_easing_state ();
385383
window_icon.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
386384
window_icon.set_easing_duration (duration);
387385
set_window_icon_position (rect.width, rect.height, scale);
388386
window_icon.restore_easing_state ();
389387

390388
toggle_shadow (true);
391-
392-
var transition = window_icon.get_transition ("opacity");
393-
if (transition != null) {
394-
transition.completed.connect (() => {
395-
in_slot_animation = false;
396-
place_widgets (rect.width, rect.height, scale);
397-
});
398-
} else {
399-
in_slot_animation = false;
400-
place_widgets (rect.width, rect.height, scale);
401-
}
402389
};
403390

404391
if (gesture_tracker == null || !with_gesture || !wm.enable_animations) {

src/Widgets/WorkspaceClone.vala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ namespace Gala {
369369

370370
update_size (monitor);
371371

372-
new GesturePropertyTransition (this, gesture_tracker, "x", initial_x, target_x, with_gesture);
373-
new GesturePropertyTransition (background, gesture_tracker, "scale-x", 1.0f, (float) scale, with_gesture);
374-
new GesturePropertyTransition (background, gesture_tracker, "scale-y", 1.0f, (float) scale, with_gesture);
372+
new GesturePropertyTransition (this, gesture_tracker, "x", initial_x, target_x).start (with_gesture);
373+
new GesturePropertyTransition (background, gesture_tracker, "scale-x", 1.0f, (float) scale).start (with_gesture);
374+
new GesturePropertyTransition (background, gesture_tracker, "scale-y", 1.0f, (float) scale).start (with_gesture);
375375

376376
#if HAS_MUTTER45
377377
Mtk.Rectangle area = {
@@ -412,12 +412,9 @@ namespace Gala {
412412
var initial_x = is_cancel_animation ? x : multitasking_view_x ();
413413
var target_x = multitasking_view_x () + current_x_overlap ();
414414

415-
double initial_scale_x, initial_scale_y;
416-
background.get_scale (out initial_scale_x, out initial_scale_y);
417-
418-
new GesturePropertyTransition (this, gesture_tracker, "x", initial_x, target_x, with_gesture);
419-
new GesturePropertyTransition (background, gesture_tracker, "scale-x", initial_scale_x, 1.0f, with_gesture);
420-
new GesturePropertyTransition (background, gesture_tracker, "scale-y", initial_scale_y, 1.0f, with_gesture);
415+
new GesturePropertyTransition (this, gesture_tracker, "x", initial_x, target_x).start (with_gesture);
416+
new GesturePropertyTransition (background, gesture_tracker, "scale-x", null, 1.0f).start (with_gesture);
417+
new GesturePropertyTransition (background, gesture_tracker, "scale-y", null, 1.0f).start (with_gesture);
421418

422419
window_container.close (with_gesture, is_cancel_animation);
423420
}

0 commit comments

Comments
 (0)