Skip to content

Commit

Permalink
Gestures: Replace passing with_gesture with GestureTracker.recognizing
Browse files Browse the repository at this point in the history
  • Loading branch information
leolost2605 committed Jan 15, 2025
1 parent d084eb3 commit b0cb89e
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 68 deletions.
8 changes: 4 additions & 4 deletions src/Gestures/GesturePropertyTransition.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ public class Gala.GesturePropertyTransition : Object {
}

/**
* Starts animating the property from {@link from_value} to {@link to_value}. If with_gesture is true
* Starts animating the property from {@link from_value} to {@link to_value}. If the GestureTracker is recognizing
* it will connect to the gesture trackers signals and animate according to the input finishing with an easing
* to the final position. If with_gesture is false it will just ease to the {@link to_value}.
* to the final position. If it's not it will just ease to the {@link to_value}.
* #this will keep itself alive until the animation finishes so it is safe to immediatly unref it after creation and calling start.
*
* @param done_callback a callback for when the transition finishes. This shouldn't be used for setting state, instead state should
* be set immediately on {@link GestureTracker.OnEnd} not only once the animation ends to allow for interrupting the animation by starting a new gesture.
* done_callback will only be called if the animation finishes, not if it is interrupted e.g. by starting a new animation for the same property,
* destroying the actor or removing the transition.
*/
public void start (bool with_gesture, owned DoneCallback? done_callback = null) {
public void start (owned DoneCallback? done_callback = null) {
ref ();

this.done_callback = (owned) done_callback;
Expand Down Expand Up @@ -159,7 +159,7 @@ public class Gala.GesturePropertyTransition : Object {
}
};

if (with_gesture && AnimationsSettings.get_enable_animations ()) {
if (gesture_tracker.recognizing && AnimationsSettings.get_enable_animations ()) {
gesture_tracker.connect_handlers (on_animation_begin, on_animation_update, on_animation_end);
} else {
on_animation_begin (0);
Expand Down
11 changes: 6 additions & 5 deletions src/Gestures/GestureTracker.vala
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ public class Gala.GestureTracker : Object {

/**
* Connects a callback that will only be called if != 0 completions were made.
* If with_gesture is false it will be called immediately, otherwise once {@link on_end} is emitted.
* If #this is not recognizing it will be called immediately, otherwise once {@link on_end} is emitted.
*/
public void add_success_callback (bool with_gesture, owned OnEnd callback) {
if (!with_gesture) {
public void add_success_callback (owned OnEnd callback) {
if (!recognizing || !AnimationsSettings.get_enable_animations ()) {
callback (1, 1, min_animation_duration);
} else {
ulong handler_id = on_end.connect ((percentage, completions, duration) => {
Expand Down Expand Up @@ -249,6 +249,7 @@ public class Gala.GestureTracker : Object {
private bool gesture_detected (GestureBackend backend, Gesture gesture, uint32 timestamp) {
if (enabled && on_gesture_detected (gesture)) {
backend.prepare_gesture_handling ();
recognizing = true;
on_gesture_handled (gesture, timestamp);
return true;
}
Expand All @@ -261,7 +262,6 @@ public class Gala.GestureTracker : Object {
on_begin (percentage);
}

recognizing = true;
previous_percentage = percentage;
previous_time = elapsed_time;
}
Expand Down Expand Up @@ -298,12 +298,13 @@ public class Gala.GestureTracker : Object {
completions += end_percentage < 0 ? -1 : 1;
}

recognizing = false;

if (enabled) {
on_end (end_percentage, completions, calculated_duration);
}

disconnect_all_handlers ();
recognizing = false;
previous_percentage = 0;
previous_time = 0;
percentage_delta = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/ShellClients/PanelClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public class Gala.PanelClone : Object {
return;
}

new GesturePropertyTransition (actor, default_gesture_tracker, "translation-y", null, calculate_translation_y (true)).start (false);
new GesturePropertyTransition (actor, default_gesture_tracker, "translation-y", null, calculate_translation_y (true)).start ();

default_gesture_tracker.add_success_callback (false, () => panel_hidden = true);
default_gesture_tracker.add_success_callback (() => panel_hidden = true);
}

private void show () {
Expand All @@ -103,8 +103,8 @@ public class Gala.PanelClone : Object {
Utils.x11_unset_window_pass_through (panel.window);
}

new GesturePropertyTransition (actor, default_gesture_tracker, "translation-y", null, calculate_translation_y (false)).start (false);
new GesturePropertyTransition (actor, default_gesture_tracker, "translation-y", null, calculate_translation_y (false)).start ();

default_gesture_tracker.add_success_callback (false, () => panel_hidden = false);
default_gesture_tracker.add_success_callback (() => panel_hidden = false);
}
}
8 changes: 4 additions & 4 deletions src/Widgets/MonitorClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ namespace Gala {
/**
* Animate the windows from their old location to a tiled layout
*/
public void open (bool with_gesture = false, bool is_cancel_animation = false) {
public void open (bool is_cancel_animation = false) {
window_container.restack_windows ();
window_container.open (null, with_gesture, is_cancel_animation);
window_container.open (null, is_cancel_animation);
}

/**
* Animate the windows back to their old location
*/
public void close (bool with_gesture = false, bool is_cancel_animation = false) {
public void close (bool is_cancel_animation = false) {
window_container.restack_windows ();
window_container.close (with_gesture);
window_container.close ();
}

private void window_left (int window_monitor, Meta.Window window) {
Expand Down
30 changes: 15 additions & 15 deletions src/Widgets/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Gala {
multitasking_gesture_tracker = new GestureTracker (ANIMATION_DURATION, ANIMATION_DURATION);
multitasking_gesture_tracker.enable_touchpad ();
multitasking_gesture_tracker.on_gesture_detected.connect (on_multitasking_gesture_detected);
multitasking_gesture_tracker.on_gesture_handled.connect (() => toggle (true, false));
multitasking_gesture_tracker.on_gesture_handled.connect (() => toggle (false));

workspace_gesture_tracker = new GestureTracker (AnimationDuration.WORKSPACE_SWITCH_MIN, AnimationDuration.WORKSPACE_SWITCH);
workspace_gesture_tracker.enable_touchpad ();
Expand Down Expand Up @@ -367,7 +367,7 @@ namespace Gala {
new GesturePropertyTransition (workspaces, workspace_gesture_tracker, "x", null, target_x) {
overshoot_lower_clamp = lower_clamp,
overshoot_upper_clamp = upper_clamp
}.start (true);
}.start ();

GestureTracker.OnEnd on_animation_end = (percentage, completions, calculated_duration) => {
switching_workspace_with_gesture = false;
Expand Down Expand Up @@ -595,7 +595,7 @@ namespace Gala {
* starting the modal mode and hiding the WindowGroup. Finally tells all components
* to animate to their positions.
*/
private void toggle (bool with_gesture = false, bool is_cancel_animation = false) {
private void toggle (bool is_cancel_animation = false) {
if (animating) {
return;
}
Expand All @@ -618,9 +618,9 @@ namespace Gala {
foreach (var container in window_containers_monitors) {
if (opening) {
container.visible = true;
container.open (with_gesture, is_cancel_animation);
container.open (is_cancel_animation);
} else {
container.close (with_gesture, is_cancel_animation);
container.close (is_cancel_animation);
}
}

Expand Down Expand Up @@ -668,16 +668,16 @@ namespace Gala {
foreach (unowned var child in workspaces.get_children ()) {
unowned WorkspaceClone workspace = (WorkspaceClone) child;
if (opening) {
workspace.open (with_gesture, is_cancel_animation);
workspace.open (is_cancel_animation);
} else {
workspace.close (with_gesture, is_cancel_animation);
workspace.close (is_cancel_animation);
}
}

if (opening) {
show_docks (with_gesture, is_cancel_animation);
show_docks (is_cancel_animation);
} else {
hide_docks (with_gesture, is_cancel_animation);
hide_docks (is_cancel_animation);
}

GestureTracker.OnEnd on_animation_end = (percentage, completions) => {
Expand All @@ -702,21 +702,21 @@ namespace Gala {
animating = false;

if (completions == 0) {
toggle (false, true);
toggle (true);
}

return Source.REMOVE;
});
};

if (!with_gesture) {
if (!multitasking_gesture_tracker.recognizing) {
on_animation_end (1, 1, 0);
} else {
multitasking_gesture_tracker.connect_handlers (null, null, (owned) on_animation_end);
}
}

private void show_docks (bool with_gesture, bool is_cancel_animation) {
private void show_docks (bool is_cancel_animation) {
unowned GLib.List<Meta.WindowActor> window_actors = display.get_window_actors ();
foreach (unowned Meta.WindowActor actor in window_actors) {
const int MAX_OFFSET = 200;
Expand Down Expand Up @@ -778,15 +778,15 @@ namespace Gala {
clone.restore_easing_state ();
};

if (!with_gesture || !AnimationsSettings.get_enable_animations ()) {
if (!multitasking_gesture_tracker.recognizing || !AnimationsSettings.get_enable_animations ()) {
on_animation_end (1, 1, 0);
} else {
multitasking_gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
}
}
}

private void hide_docks (bool with_gesture, bool is_cancel_animation) {
private void hide_docks (bool is_cancel_animation) {
foreach (unowned var child in dock_clones.get_children ()) {
var dock = (Clutter.Clone) child;
var initial_y = dock.y;
Expand All @@ -809,7 +809,7 @@ namespace Gala {
dock.restore_easing_state ();
};

if (!with_gesture || !AnimationsSettings.get_enable_animations ()) {
if (!multitasking_gesture_tracker.recognizing || !AnimationsSettings.get_enable_animations ()) {
on_animation_end (1, 1, 0);
} else {
multitasking_gesture_tracker.connect_handlers (null, (owned) on_animation_update, (owned) on_animation_end);
Expand Down
34 changes: 17 additions & 17 deletions src/Widgets/WindowClone.vala
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public class Gala.WindowClone : Clutter.Actor {
*
* @param animate Animate the transformation of the placement
*/
public void transition_to_original_state (bool with_gesture = false) {
public void transition_to_original_state () {
var outer_rect = window.get_frame_rect ();

unowned var display = window.get_display ();
Expand All @@ -257,28 +257,28 @@ public class Gala.WindowClone : Clutter.Actor {
active = false;
update_hover_widgets (true);

new GesturePropertyTransition (this, gesture_tracker, "x", null, (float) target_x).start (with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "y", null, (float) target_y).start (with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "width", null, (float) outer_rect.width).start (with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "height", null, (float) outer_rect.height).start (with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", (uint8) 255, (uint8) 0).start (with_gesture);
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 255u, 0u).start (with_gesture, () => {
new GesturePropertyTransition (this, gesture_tracker, "x", null, (float) target_x).start ();
new GesturePropertyTransition (this, gesture_tracker, "y", null, (float) target_y).start ();
new GesturePropertyTransition (this, gesture_tracker, "width", null, (float) outer_rect.width).start ();
new GesturePropertyTransition (this, gesture_tracker, "height", null, (float) outer_rect.height).start ();
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", (uint8) 255, (uint8) 0).start ();
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 255u, 0u).start (() => {
update_hover_widgets (false);
toggle_shadow (false);
});

if (should_fade ()) {
new GesturePropertyTransition (this, gesture_tracker, "opacity", null, 0u).start (with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "opacity", null, 0u).start ();
}
}

/**
* Animate the window to the given slot
*/
#if HAS_MUTTER45
public void take_slot (Mtk.Rectangle rect, bool from_window_position, bool with_gesture = false) {
public void take_slot (Mtk.Rectangle rect, bool from_window_position) {
#else
public void take_slot (Meta.Rectangle rect, bool from_window_position, bool with_gesture = false) {
public void take_slot (Meta.Rectangle rect, bool from_window_position) {
#endif
slot = rect;
active = false;
Expand All @@ -294,13 +294,13 @@ public class Gala.WindowClone : Clutter.Actor {

update_hover_widgets (true);

new GesturePropertyTransition (this, gesture_tracker, "x", intial_x, (float) rect.x).start (with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "y", intial_y, (float) rect.y).start (with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "width", (float) initial_width, (float) rect.width).start (with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "height", (float) initial_height, (float) rect.height).start (with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "opacity", null, 255u).start (with_gesture);
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", (uint8) 0, (uint8) 255).start (with_gesture);
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 0u, 255u).start (with_gesture, () => {
new GesturePropertyTransition (this, gesture_tracker, "x", intial_x, (float) rect.x).start ();
new GesturePropertyTransition (this, gesture_tracker, "y", intial_y, (float) rect.y).start ();
new GesturePropertyTransition (this, gesture_tracker, "width", (float) initial_width, (float) rect.width).start ();
new GesturePropertyTransition (this, gesture_tracker, "height", (float) initial_height, (float) rect.height).start ();
new GesturePropertyTransition (this, gesture_tracker, "opacity", null, 255u).start ();
new GesturePropertyTransition (this, gesture_tracker, "shadow-opacity", (uint8) 0, (uint8) 255).start ();
new GesturePropertyTransition (window_icon, gesture_tracker, "opacity", 0u, 255u).start (() => {
update_hover_widgets (false);
toggle_shadow (true);
});
Expand Down
12 changes: 6 additions & 6 deletions src/Widgets/WindowCloneContainer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace Gala {
* Recalculate the tiling positions of the windows and animate them to
* the resulting spots.
*/
public void reflow (bool with_gesture = false, bool is_cancel_animation = false, bool opening = false) {
private void reflow (bool is_cancel_animation = false, bool opening = false) {
if (!opened) {
return;
}
Expand Down Expand Up @@ -206,7 +206,7 @@ namespace Gala {

foreach (var tilable in window_positions) {
unowned var clone = (WindowClone) tilable.id;
clone.take_slot (tilable.rect, opening && !is_cancel_animation, with_gesture);
clone.take_slot (tilable.rect, opening && !is_cancel_animation);
}
}

Expand Down Expand Up @@ -369,7 +369,7 @@ namespace Gala {
/**
* When opened the WindowClones are animated to a tiled layout
*/
public void open (Meta.Window? selected_window, bool with_gesture, bool is_cancel_animation) {
public void open (Meta.Window? selected_window, bool is_cancel_animation) {
if (opened) {
return;
}
Expand All @@ -393,22 +393,22 @@ namespace Gala {
current_window = null;
}

reflow (with_gesture, is_cancel_animation, true);
reflow (is_cancel_animation, true);
}

/**
* Calls the transition_to_original_state() function on each child
* to make them take their original locations again.
*/
public void close (bool with_gesture = false) {
public void close () {
if (!opened) {
return;
}

opened = false;

foreach (var window in get_children ()) {
((WindowClone) window).transition_to_original_state (with_gesture);
((WindowClone) window).transition_to_original_state ();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/WindowOverview.vala
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public class Gala.WindowOverview : Clutter.Actor, ActivatableComponent {
}

container.add_window (window);
container.open (display.get_focus_window (), false, false);
container.open (display.get_focus_window (), false);
}
}

Expand Down
Loading

0 comments on commit b0cb89e

Please sign in to comment.