MultitaskingView: cleanup and bugfixes (#1787)

Co-authored-by: Danielle Foré <danielle@elementary.io>
This commit is contained in:
Leo 2023-11-08 04:55:26 +09:00 committed by GitHub
parent ad90feec44
commit 27cc39c9e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 32 deletions

View File

@ -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>

View File

@ -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);
}
@ -294,16 +301,23 @@ namespace Gala {
}
private void switch_workspace_with_gesture (Meta.MotionDirection direction) {
if (switching_workspace_in_progress) {
return;
}
unowned var manager = display.get_workspace_manager ();
var num_workspaces = manager.get_n_workspaces ();
var relative_dir = (direction == Meta.MotionDirection.LEFT) ? -1 : 1;
unowned Meta.WorkspaceManager 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;
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);
@ -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;
}
}
@ -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);
@ -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) :
@ -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 ());
}
};
@ -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 {