Skip to content

Commit 8ff631b

Browse files
committed
Better value transforms, use in windowmanager
1 parent bb05871 commit 8ff631b

File tree

4 files changed

+38
-94
lines changed

4 files changed

+38
-94
lines changed

src/Gestures/PropertyGestureTransition.vala

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,19 @@ public class Gala.GesturePropertyTransition : Object {
5757
);
5858
}
5959

60+
construct {
61+
done.connect (unref);
62+
}
63+
6064
/**
6165
* Starts animating the property from {@link from_value} to {@link to_value}. If with_gesture is true
6266
* it will connect to the gesture trackers signals and animate according to the input finishing with an easing
6367
* to the final position. If with_gesture is false it will just ease to the {@link to_value}.
68+
* #this will keep itself alive until the animation finishes so it is safe to immediatly unref it after creation and calling start.
6469
*/
6570
public void start (bool with_gesture) {
71+
ref ();
72+
6673
Value current_value = {};
6774
actor.get_property (property, ref current_value);
6875

@@ -76,16 +83,17 @@ public class Gala.GesturePropertyTransition : Object {
7683
});
7784
} else if (from_value.type () != current_value.type ()) {
7885
warning ("from_value of type %s is not of the same type as the property %s which is %s. Can't animate.", from_value.type_name (), property, current_value.type_name ());
86+
done ();
7987
return;
8088
}
8189

8290
if (current_value.type () != to_value.type ()) {
8391
warning ("to_value of type %s is not of the same type as the property %s which is %s. Can't animate.", to_value.type_name (), property, current_value.type_name ());
92+
done ();
8493
return;
8594
}
8695

8796
GestureTracker.OnBegin on_animation_begin = () => {
88-
ref ();
8997
actor.set_property (property, from_value);
9098
};
9199

@@ -108,12 +116,8 @@ public class Gala.GesturePropertyTransition : Object {
108116
unowned var transition = actor.get_transition (property);
109117
if (transition == null) {
110118
done ();
111-
unref ();
112119
} else {
113-
transition.stopped.connect (() => {
114-
done ();
115-
unref ();
116-
});
120+
transition.stopped.connect (() => done ());
117121
}
118122
};
119123

@@ -130,9 +134,9 @@ public class Gala.GesturePropertyTransition : Object {
130134

131135
unowned var transition = actor.get_transition (property);
132136
if (transition == null) {
133-
on_animation_end (1, false, gesture_tracker.min_animation_duration / 2);
137+
on_animation_end (1, false, gesture_tracker.min_animation_duration);
134138
} else {
135-
transition.stopped.connect (() => on_animation_end (1, false, gesture_tracker.min_animation_duration / 2));
139+
transition.stopped.connect (() => on_animation_end (1, false, gesture_tracker.min_animation_duration));
136140
}
137141
} else {
138142
on_animation_end (1, false, gesture_tracker.min_animation_duration);
@@ -141,29 +145,25 @@ public class Gala.GesturePropertyTransition : Object {
141145
}
142146

143147
private float value_to_float (Value val) {
144-
if (val.holds (typeof (float))) {
145-
return val.get_float ();
146-
}
147-
148-
if (val.holds (typeof (double))) {
149-
return (float) val.get_double ();
150-
}
151-
152-
if (val.holds (typeof (uint))) {
153-
return (float) val.get_uint ();
154-
}
155-
156-
if (val.holds (typeof (int))) {
157-
return (float) val.get_int ();
148+
Value float_val = Value (typeof (float));
149+
if (val.transform (ref float_val)) {
150+
return float_val.get_float ();
158151
}
159152

160153
critical ("Non numeric property specified");
161154
return 0;
162155
}
163156

164157
private Value value_from_float (float f) {
158+
var float_val = Value (typeof (float));
159+
float_val.set_float (f);
160+
165161
var val = Value (from_value.type ());
166-
val.set_float (f);
162+
163+
if (!float_val.transform (ref val)) {
164+
warning ("Failed to transform float to give type");
165+
}
166+
167167
return val;
168168
}
169169
}

src/Widgets/WindowClone.vala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ public class Gala.WindowClone : Clutter.Actor {
292292
new GesturePropertyTransition (this, gesture_tracker, "y", null, (float) target_y).start (with_gesture);
293293
new GesturePropertyTransition (this, gesture_tracker, "width", null, (float) outer_rect.width).start (with_gesture);
294294
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);
295+
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", (uint8) 255, (uint8) 0).start (with_gesture);
296+
var opacity_transition = new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 255u, 0u);
297297
opacity_transition.start (with_gesture);
298298
opacity_transition.done.connect (() => {
299299
in_slot_animation = false;
@@ -357,8 +357,8 @@ public class Gala.WindowClone : Clutter.Actor {
357357
new GesturePropertyTransition (this, gesture_tracker, "y", null, (float) rect.y).start (with_gesture);
358358
new GesturePropertyTransition (this, gesture_tracker, "width", null, (float) rect.width).start (with_gesture);
359359
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);
360+
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", (uint8) 0, (uint8) 255).start (with_gesture);
361+
var opacity_transition = new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 0u, 255u);
362362
opacity_transition.start (with_gesture);
363363
opacity_transition.done.connect (() => {
364364
in_slot_animation = false;

src/Widgets/WorkspaceClone.vala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ namespace Gala {
370370
update_size (monitor);
371371

372372
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);
373+
new GesturePropertyTransition (background, gesture_tracker, "scale-x", 1.0d, (double) scale).start (with_gesture);
374+
new GesturePropertyTransition (background, gesture_tracker, "scale-y", 1.0d, (double) scale).start (with_gesture);
375375

376376
#if HAS_MUTTER45
377377
Mtk.Rectangle area = {
@@ -413,8 +413,8 @@ namespace Gala {
413413
var target_x = multitasking_view_x () + current_x_overlap ();
414414

415415
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);
416+
new GesturePropertyTransition (background, gesture_tracker, "scale-x", null, 1.0d).start (with_gesture);
417+
new GesturePropertyTransition (background, gesture_tracker, "scale-y", null, 1.0d).start (with_gesture);
418418

419419
window_container.close (with_gesture, is_cancel_animation);
420420
}

src/WindowManager.vala

Lines changed: 7 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -643,69 +643,13 @@ namespace Gala {
643643
dest *= -1;
644644
}
645645

646-
var animation_mode = Clutter.AnimationMode.EASE_OUT_CUBIC;
647-
648-
GestureTracker.OnUpdate on_animation_update = (percentage) => {
649-
var x_out = GestureTracker.animation_value (0.0f, dest, percentage, true).clamp (-nudge_gap, nudge_gap);
650-
out_group.x = x_out;
651-
wallpaper.x = x_out;
652-
};
653-
654-
GestureTracker.OnEnd on_animation_end = (percentage, cancel_action, duration) => {
655-
out_group.save_easing_state ();
656-
out_group.set_easing_mode (animation_mode);
657-
out_group.set_easing_duration (AnimationDuration.NUDGE / 2);
658-
659-
wallpaper.save_easing_state ();
660-
wallpaper.set_easing_mode (animation_mode);
661-
wallpaper.set_easing_duration (AnimationDuration.NUDGE / 2);
662-
663-
out_group.x = 0.0f;
664-
out_group.restore_easing_state ();
665-
666-
wallpaper.x = 0.0f;
667-
wallpaper.restore_easing_state ();
668-
669-
unowned var transition = out_group.get_transition ("x");
670-
transition.completed.connect (() => {
671-
switch_workspace_animation_finished (direction, false, true);
672-
animating_switch_workspace = false;
673-
});
674-
};
675-
676-
if (!switch_workspace_with_gesture) {
677-
double[] keyframes = { 0.5 };
678-
GLib.Value[] x = { dest };
679-
680-
var out_group_nudge = new Clutter.KeyframeTransition ("translation-x") {
681-
duration = AnimationDuration.NUDGE,
682-
remove_on_complete = true,
683-
progress_mode = Clutter.AnimationMode.EASE_IN_QUAD
684-
};
685-
out_group_nudge.set_from_value (0.0f);
686-
out_group_nudge.set_to_value (0.0f);
687-
out_group_nudge.set_key_frames (keyframes);
688-
out_group_nudge.set_values (x);
689-
out_group.add_transition ("nudge", out_group_nudge);
690-
691-
var wallpaper_nudge = new Clutter.KeyframeTransition ("translation-x") {
692-
duration = AnimationDuration.NUDGE,
693-
remove_on_complete = true,
694-
progress_mode = Clutter.AnimationMode.EASE_IN_QUAD
695-
};
696-
wallpaper_nudge.set_from_value (0.0f);
697-
wallpaper_nudge.set_to_value (0.0f);
698-
wallpaper_nudge.set_key_frames (keyframes);
699-
wallpaper_nudge.set_values (x);
700-
wallpaper.add_transition ("nudge", wallpaper_nudge);
701-
702-
wallpaper_nudge.completed.connect (() => {
703-
switch_workspace_animation_finished (direction, false, true);
704-
animating_switch_workspace = false;
705-
});
706-
} else {
707-
gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
708-
}
646+
new GesturePropertyTransition (out_group, gesture_tracker, "x", 0f, 0f, dest).start (switch_workspace_with_gesture);
647+
var transition = new GesturePropertyTransition (wallpaper, gesture_tracker, "x", 0f, 0f, dest);
648+
transition.done.connect (() => {
649+
switch_workspace_animation_finished (direction, false, true);
650+
animating_switch_workspace = false;
651+
});
652+
transition.start (switch_workspace_with_gesture);
709653
}
710654

711655
private void update_input_area () {

0 commit comments

Comments
 (0)