Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
445d730
Introduce a PropertyGestureTarget
leolost2605 Sep 26, 2024
725177f
Some fixes and use in workspace clone
leolost2605 Sep 26, 2024
d36034f
Use in WindowClone
leolost2605 Sep 26, 2024
2b7653d
Rename to GesturePropertyTransition, add done signal
leolost2605 Sep 26, 2024
a2ae8a5
Some API improvements
leolost2605 Sep 28, 2024
bb05871
Add documentation and allow intermediate without gesture
leolost2605 Sep 29, 2024
8ff631b
Better value transforms, use in windowmanager
leolost2605 Sep 29, 2024
6b4851d
Rename file, follow animation settings
leolost2605 Sep 29, 2024
0991190
Add missing file
leolost2605 Sep 29, 2024
377c397
Merge branch 'main' into leolost/propertygesturetarget
leolost2605 Sep 29, 2024
4f5db98
Fix initial window position
leolost2605 Sep 30, 2024
f4c9462
Fix window icon position
leolost2605 Sep 30, 2024
ef61a5e
Add done_callback
leolost2605 Oct 10, 2024
2a7c2e0
Merge branch 'main' into leolost/propertygesturetarget
leolost2605 Oct 10, 2024
4af996f
Fix rare crash
leolost2605 Oct 10, 2024
3eb95ef
Merge branch 'leolost/propertygesturetarget' of github.com:elementary…
leolost2605 Oct 10, 2024
f5fb15c
Merge branch 'main' into leolost/propertygesturetarget
leolost2605 Oct 20, 2024
3299054
Merge branch 'main' into leolost/propertygesturetarget
leolost2605 Nov 26, 2024
0935972
Merge branch 'main' into leolost/propertygesturetarget
lenemter Dec 4, 2024
529aa13
Use `AnimationsSettings`
lenemter Dec 4, 2024
2e7af0b
Merge branch 'main' into leolost/propertygesturetarget
leolost2605 Dec 6, 2024
6acf811
Remove done signal
leolost2605 Dec 6, 2024
7c34a54
Add comment
leolost2605 Dec 7, 2024
d423d62
Fix desktop nudge and cancel
leolost2605 Dec 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions src/Gestures/PropertyGestureTransition.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@


public class Gala.GesturePropertyTransition : Object {
public signal void done ();

public Clutter.Actor actor { get; construct; }
public GestureTracker gesture_tracker { get; construct; }
public string property { get; construct; }
public Value? from_value { get; construct; }
public Value to_value { get; construct; }
public bool with_gesture { get; construct; }
public Value? intermediate_value { get; construct; }

public GesturePropertyTransition (
Clutter.Actor actor,
GestureTracker gesture_tracker,
string property,
Value? from_value,
Value to_value,
bool with_gesture,
Value? intermediate_value = null
) {
Object (
actor: actor,
gesture_tracker: gesture_tracker,
property: property,
from_value: from_value,
to_value: to_value,
with_gesture: with_gesture,
intermediate_value: intermediate_value
);
}

construct {
ref ();

if (from_value == null) {
Value current_value;
actor.get_property (property, ref current_value);
from_value = current_value;
}

GestureTracker.OnBegin on_animation_begin = () => {
actor.set_property (property, from_value);
};

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var animation_value = GestureTracker.animation_value (value_to_float (from_value), value_to_float (intermediate_value ?? to_value), percentage);
actor.set_property (property, value_from_float (animation_value));
};

GestureTracker.OnEnd on_animation_end = (percentage, cancel_action, calculated_duration) => {
if (cancel_action) {
return;
}

actor.save_easing_state ();
actor.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
actor.set_easing_duration (calculated_duration);
actor.set_property (property, cancel_action ? from_value : to_value);
actor.restore_easing_state ();

done ();

unref ();
};

if (with_gesture) {
gesture_tracker.connect_handlers (on_animation_begin, on_animation_update, on_animation_end);
} else {
on_animation_begin (0);
on_animation_end (1, false, gesture_tracker.min_animation_duration);
}
}

private float value_to_float (Value val) {
if (val.holds (typeof (float))) {
return val.get_float ();
}

if (val.holds (typeof (double))) {
return (float) val.get_double ();
}

if (val.holds (typeof (uint))) {
return (float) val.get_uint ();
}

critical ("Non numeric property specified");
return 0;
}

private Value value_from_float (float f) {
var val = Value (from_value.type ());
val.set_float (f);
return val;
}
}
57 changes: 8 additions & 49 deletions src/Widgets/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -383,58 +383,17 @@ namespace Gala {
target_workspace.activate (display.get_current_time ());
}

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (initial_x, target_x, percentage, true);
var icon_group_opacity = GestureTracker.animation_value (0.0f, 1.0f, percentage, false);

if (is_nudge_animation) {
x = x.clamp (initial_x - nudge_gap, initial_x + nudge_gap);
}

workspaces.x = x;

if (!is_nudge_animation) {
active_icon_group.backdrop_opacity = 1.0f - icon_group_opacity;
target_icon_group.backdrop_opacity = icon_group_opacity;
}
};
if (is_nudge_animation) {
new GesturePropertyTransition (workspaces, workspace_gesture_tracker, "x", null, initial_x, true, initial_x + nudge_gap * -relative_dir);
} else {
new GesturePropertyTransition (workspaces, workspace_gesture_tracker, "x", null, target_x, true);
new GesturePropertyTransition (active_icon_group, workspace_gesture_tracker, "backdrop-opacity", 1f, 0f, true);
new GesturePropertyTransition (target_icon_group, workspace_gesture_tracker, "backdrop-opacity", 0f, 1f, true);
}

GestureTracker.OnEnd on_animation_end = (percentage, cancel_action, calculated_duration) => {
switching_workspace_with_gesture = false;

var duration = is_nudge_animation ?
(uint) (AnimationDuration.NUDGE / 2) :
(uint) calculated_duration;

workspaces.save_easing_state ();
workspaces.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
workspaces.set_easing_duration (duration);
workspaces.x = (is_nudge_animation || cancel_action) ? initial_x : target_x;
workspaces.restore_easing_state ();

if (!is_nudge_animation) {
if (wm.enable_animations) {
var active_transition = new Clutter.PropertyTransition ("backdrop-opacity") {
duration = duration,
remove_on_complete = true
};
active_transition.set_from_value (active_icon_group.backdrop_opacity);
active_transition.set_to_value (cancel_action ? 1.0f : 0.0f);
active_icon_group.add_transition ("backdrop-opacity", active_transition);

var target_transition = new Clutter.PropertyTransition ("backdrop-opacity") {
duration = duration,
remove_on_complete = true
};
target_transition.set_from_value (target_icon_group.backdrop_opacity);
target_transition.set_to_value (cancel_action ? 0.0f : 1.0f);
target_icon_group.add_transition ("backdrop-opacity", target_transition);
} else {
active_icon_group.backdrop_opacity = cancel_action ? 1.0f : 0.0f;
target_icon_group.backdrop_opacity = cancel_action ? 0.0f : 1.0f;
}
}

if (is_nudge_animation || cancel_action) {
active_workspace.activate (display.get_current_time ());
}
Expand All @@ -443,7 +402,7 @@ namespace Gala {
if (!wm.enable_animations) {
on_animation_end (1, false, 0);
} else {
workspace_gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
workspace_gesture_tracker.connect_handlers (null, null, (owned) on_animation_end);
}
}

Expand Down
59 changes: 14 additions & 45 deletions src/Widgets/WindowClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ public class Gala.WindowClone : Clutter.Actor {
var offset_x = monitor_geom.x;
var offset_y = monitor_geom.y;

var initial_x = x;
var initial_y = y;
var initial_width = width;
var initial_height = height;

Expand All @@ -290,22 +288,20 @@ public class Gala.WindowClone : Clutter.Actor {
in_slot_animation = true;
place_widgets (outer_rect.width, outer_rect.height, initial_scale);

new GesturePropertyTransition (this, gesture_tracker, "x", null, (float) target_x, with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "y", null, (float) target_y, with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "width", null, (float) outer_rect.width, with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "height", null, (float) outer_rect.height, with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", 255f, 0f, with_gesture);
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 255f, 0f, with_gesture);

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (initial_x, target_x, percentage);
var y = GestureTracker.animation_value (initial_y, target_y, percentage);
var width = GestureTracker.animation_value (initial_width, outer_rect.width, percentage);
var height = GestureTracker.animation_value (initial_height, outer_rect.height, percentage);
var scale = GestureTracker.animation_value (initial_scale, target_scale, percentage);
var opacity = GestureTracker.animation_value (255f, 0f, percentage);

set_size (width, height);
set_position (x, y);

window_icon.opacity = (uint) opacity;
set_window_icon_position (width, height, scale, false);
place_widgets ((int)width, (int)height, scale);

shadow_opacity = (uint8) opacity;
};

GestureTracker.OnEnd on_animation_end = (percentage, cancel_action) => {
Expand All @@ -315,27 +311,13 @@ public class Gala.WindowClone : Clutter.Actor {

var duration = (animate && wm.enable_animations) ? MultitaskingView.ANIMATION_DURATION : 0;

save_easing_state ();
set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
set_easing_duration (duration);

set_position (target_x, target_y);
set_size (outer_rect.width, outer_rect.height);

if (should_fade ()) {
opacity = 0;
}

restore_easing_state ();

if (animate) {
toggle_shadow (false);
}

window_icon.save_easing_state ();
window_icon.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
window_icon.set_easing_duration (duration);
window_icon.opacity = 0;
set_window_icon_position (outer_rect.width, outer_rect.height, target_scale);
window_icon.restore_easing_state ();

Expand Down Expand Up @@ -367,8 +349,6 @@ public class Gala.WindowClone : Clutter.Actor {
public void take_slot (Meta.Rectangle rect, bool with_gesture = false, bool is_cancel_animation = false) {
#endif
slot = rect;
var initial_x = x;
var initial_y = y;
var initial_width = width;
var initial_height = height;

Expand All @@ -379,20 +359,18 @@ public class Gala.WindowClone : Clutter.Actor {
in_slot_animation = true;
place_widgets (rect.width, rect.height, scale);

new GesturePropertyTransition (this, gesture_tracker, "x", null, (float) rect.x, with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "y", null, (float) rect.y, with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "width", null, (float) rect.width, with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "height", null, (float) rect.height, with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", 0f, 255f, with_gesture);
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 0f, 255f, with_gesture);

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (initial_x, rect.x, percentage);
var y = GestureTracker.animation_value (initial_y, rect.y, percentage);
var width = GestureTracker.animation_value (initial_width, rect.width, percentage);
var height = GestureTracker.animation_value (initial_height, rect.height, percentage);
var opacity = GestureTracker.animation_value (0f, 255f, percentage);

set_size (width, height);
set_position (x, y);

window_icon.opacity = (uint) opacity;
set_window_icon_position (width, height, scale, false);

shadow_opacity = (uint8) opacity;
};

GestureTracker.OnEnd on_animation_end = (percentage, cancel_action) => {
Expand All @@ -402,19 +380,10 @@ public class Gala.WindowClone : Clutter.Actor {

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

save_easing_state ();
set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
set_easing_duration (duration);

set_size (rect.width, rect.height);
set_position (rect.x, rect.y);
opacity = 255;
restore_easing_state ();

window_icon.save_easing_state ();
window_icon.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
window_icon.set_easing_duration (duration);
window_icon.opacity = 255;
set_window_icon_position (rect.width, rect.height, scale);
window_icon.restore_easing_state ();

Expand Down
76 changes: 7 additions & 69 deletions src/Widgets/WorkspaceClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -365,46 +365,13 @@ namespace Gala {

var scale = (float)(monitor.height - InternalUtils.scale_to_int (TOP_OFFSET + BOTTOM_OFFSET, scale_factor)) / monitor.height;
var pivot_y = InternalUtils.scale_to_int (TOP_OFFSET, scale_factor) / (monitor.height - monitor.height * scale);
background.set_pivot_point (0.5f, pivot_y);

update_size (monitor);

GestureTracker.OnBegin on_animation_begin = () => {
x = initial_x;
background.set_pivot_point (0.5f, pivot_y);
};

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (initial_x, target_x, percentage);
set_x (x);

var update_scale = (double) GestureTracker.animation_value (1.0f, (float)scale, percentage);
background.set_scale (update_scale, update_scale);
};

GestureTracker.OnEnd on_animation_end = (percentage, cancel_action) => {
if (cancel_action) {
return;
}

save_easing_state ();
set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
set_easing_duration (wm.enable_animations ? MultitaskingView.ANIMATION_DURATION : 0);
set_x (target_x);
restore_easing_state ();

background.save_easing_state ();
background.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
background.set_easing_duration (wm.enable_animations ? MultitaskingView.ANIMATION_DURATION : 0);
background.set_scale (scale, scale);
background.restore_easing_state ();
};

if (!with_gesture || !wm.enable_animations) {
on_animation_begin (0);
on_animation_end (1, false, 0);
} else {
gesture_tracker.connect_handlers ((owned) on_animation_begin, (owned) on_animation_update, (owned)on_animation_end);
}
new GesturePropertyTransition (this, gesture_tracker, "x", initial_x, target_x, with_gesture);
new GesturePropertyTransition (background, gesture_tracker, "scale-x", 1.0f, (float) scale, with_gesture);
new GesturePropertyTransition (background, gesture_tracker, "scale-y", 1.0f, (float) scale, with_gesture);

#if HAS_MUTTER45
Mtk.Rectangle area = {
Expand Down Expand Up @@ -448,38 +415,9 @@ namespace Gala {
double initial_scale_x, initial_scale_y;
background.get_scale (out initial_scale_x, out initial_scale_y);

GestureTracker.OnUpdate on_animation_update = (percentage) => {
var x = GestureTracker.animation_value (initial_x, target_x, percentage);
set_x (x);

double scale_x = (double) GestureTracker.animation_value ((float) initial_scale_x, 1.0f, percentage);
double scale_y = (double) GestureTracker.animation_value ((float) initial_scale_y, 1.0f, percentage);
background.set_scale (scale_x, scale_y);
};

GestureTracker.OnEnd on_animation_end = (percentage, cancel_action) => {
if (cancel_action) {
return;
}

save_easing_state ();
set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
set_easing_duration (wm.enable_animations ? MultitaskingView.ANIMATION_DURATION : 0);
set_x (target_x);
restore_easing_state ();

background.save_easing_state ();
background.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
background.set_easing_duration (wm.enable_animations ? MultitaskingView.ANIMATION_DURATION : 0);
background.set_scale (1, 1);
background.restore_easing_state ();
};

if (!with_gesture || !wm.enable_animations) {
on_animation_end (1, false, 0);
} else {
gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
}
new GesturePropertyTransition (this, gesture_tracker, "x", initial_x, target_x, with_gesture);
new GesturePropertyTransition (background, gesture_tracker, "scale-x", initial_scale_x, 1.0f, with_gesture);
new GesturePropertyTransition (background, gesture_tracker, "scale-y", initial_scale_y, 1.0f, with_gesture);

window_container.close (with_gesture, is_cancel_animation);
}
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ gala_bin_sources = files(
'Gestures/Gesture.vala',
'Gestures/GestureSettings.vala',
'Gestures/GestureTracker.vala',
'Gestures/PropertyGestureTransition.vala',
'Gestures/ScrollBackend.vala',
'Gestures/ToucheggBackend.vala',
'HotCorners/Barrier.vala',
Expand Down