Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultitaskingView: cleanup and bugfixes #1787

Merged
merged 9 commits into from
Nov 7, 2023
1 change: 1 addition & 0 deletions data/gala.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ul>
<li>Changing the wallpaper or going to sleep respects the "Reduce Motion" option</li>
<li>Use appropriate drag-and-drop pointers when moving windows</li>
<li>Fix the issue when gestures in the multitasking view might stop working</li>
<li>Improve dynamic workspaces behaviour with multiple monitors</li>
<li>Updated translations</li>
</ul>
Expand Down
71 changes: 39 additions & 32 deletions src/Widgets/MultitaskingView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ namespace Gala {

private GLib.Settings gala_behavior_settings;

private bool switching_workspace_with_gesture = false;
private bool switching_workspace_in_progress {
get {
return switching_workspace_with_gesture || workspaces.get_transition ("x") != null;
}
}

public MultitaskingView (WindowManager wm) {
Object (wm: wm);
}
Expand Down Expand Up @@ -294,16 +301,23 @@ namespace Gala {
}

private void switch_workspace_with_gesture (Meta.MotionDirection direction) {
var relative_dir = (direction == Meta.MotionDirection.LEFT) ? -1 : 1;
if (switching_workspace_in_progress) {
return;
}

unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();
unowned var manager = display.get_workspace_manager ();
var num_workspaces = manager.get_n_workspaces ();
var active_workspace_index = manager.get_active_workspace ().index ();
var target_workspace_index = active_workspace_index + relative_dir;
var relative_dir = (direction == Meta.MotionDirection.LEFT) ? -1 : 1;

unowned var active_workspace = manager.get_active_workspace ();

var target_workspace_index = active_workspace.index () + relative_dir;
var target_workspace_exists = target_workspace_index >= 0 && target_workspace_index < num_workspaces;
unowned var target_workspace = manager.get_workspace_by_index (target_workspace_index);

float initial_x = workspaces.x;
float target_x = 0;
bool is_nudge_animation = (target_workspace_index < 0 || target_workspace_index >= num_workspaces);
bool is_nudge_animation = !target_workspace_exists;
var scale = display.get_monitor_scale (display.get_primary_monitor ());
var nudge_gap = InternalUtils.scale_to_int (WindowManagerGala.NUDGE_GAP, scale);

Expand All @@ -316,12 +330,12 @@ namespace Gala {
} else {
foreach (unowned var child in workspaces.get_children ()) {
unowned var workspace_clone = (WorkspaceClone) child;
var index = workspace_clone.workspace.index ();
var workspace = workspace_clone.workspace;

if (index == target_workspace_index) {
if (workspace == target_workspace) {
target_icon_group = workspace_clone.icon_group;
target_x = -workspace_clone.multitasking_view_x ();
} else if (index == active_workspace_index) {
} else if (workspace == active_workspace) {
active_icon_group = workspace_clone.icon_group;
}
}
Expand All @@ -335,13 +349,18 @@ namespace Gala {
}

debug ("Starting MultitaskingView switch workspace animation:");
debug ("Active workspace index: %d", active_workspace_index);
debug ("Active workspace index: %d", active_workspace.index ());
debug ("Target workspace index: %d", target_workspace_index);
debug ("Total number of workspaces: %d", num_workspaces);
debug ("Is nudge animation: %s", is_nudge_animation ? "Yes" : "No");
debug ("Initial X: %f", initial_x);
debug ("Target X: %f", target_x);

switching_workspace_with_gesture = true;
if (target_workspace != null) {
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);
Expand All @@ -359,7 +378,7 @@ namespace Gala {
};

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

var duration = is_nudge_animation ?
(uint) (AnimationDuration.NUDGE / 2) :
Expand Down Expand Up @@ -394,24 +413,8 @@ namespace Gala {
}
}


var transition = workspaces.get_transition ("x");
if (transition != null) {
transition.completed.connect (() => {
workspace_gesture_tracker.enabled = true;

if (!is_nudge_animation && !cancel_action) {
manager.get_workspace_by_index (target_workspace_index).activate (display.get_current_time ());
update_positions (false);
}
});
} else {
workspace_gesture_tracker.enabled = true;

if (!is_nudge_animation && !cancel_action) {
manager.get_workspace_by_index (target_workspace_index).activate (display.get_current_time ());
update_positions (false);
}
if (is_nudge_animation || cancel_action) {
active_workspace.activate (display.get_current_time ());
}
};

Expand All @@ -430,16 +433,20 @@ namespace Gala {
* positions immediately.
*/
private void update_positions (bool animate) {
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();
var active_index = manager.get_active_workspace ().index ();
if (switching_workspace_with_gesture) {
return;
}

unowned var manager = display.get_workspace_manager ();
var active_workspace = manager.get_active_workspace ();
var active_x = 0.0f;

foreach (unowned var child in workspaces.get_children ()) {
unowned var workspace_clone = (WorkspaceClone) child;
var index = workspace_clone.workspace.index ();
var workspace = workspace_clone.workspace;
var dest_x = workspace_clone.multitasking_view_x ();

if (index == active_index) {
if (workspace == active_workspace) {
active_x = dest_x;
workspace_clone.icon_group.backdrop_opacity = 1.0f;
} else {
Expand Down