Skip to content

Commit

Permalink
fws: Support relative ordering for window stacking
Browse files Browse the repository at this point in the history
Add support for relative window ordering based on existing order
when saved as templates when launching on top of current
windows.

BUG=b:296619806
TEST=FloatingWorkspaceTest, manually verified.

Change-Id: I3141ac6447a98db75b052f84d14aad65b6038895
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4793782
Reviewed-by: Daniel Andersson <dandersson@chromium.org>
Reviewed-by: Yanzhu Du <yzd@google.com>
Commit-Queue: Matthew Zhu <zhumatthew@google.com>
Cr-Commit-Position: refs/heads/main@{#1185447}
  • Loading branch information
zhumatthew authored and Chromium LUCI CQ committed Aug 18, 2023
1 parent aa13997 commit 3946245
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
21 changes: 21 additions & 0 deletions ash/wm/desks/templates/saved_desk_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,26 @@ void UpdateTemplateActivationIndices(DeskTemplate& saved_desk) {
}
}

void UpdateTemplateActivationIndicesRelativeOrder(DeskTemplate& saved_desk) {
auto& app_id_to_launch_list =
saved_desk.mutable_desk_restore_data()->mutable_app_id_to_launch_list();
std::vector<app_restore::AppRestoreData*> relative_window_stack_order;
for (auto& [app_id, launch_list] : app_id_to_launch_list) {
for (auto& [window_id, app_restore_data] : launch_list) {
relative_window_stack_order.push_back(app_restore_data.get());
}
}
// Sort in descending order so that we maintain the relative window
// stacking order.
base::ranges::sort(relative_window_stack_order,
[](auto* window1, auto* window2) {
return window1->activation_index.value_or(0) >
window2->activation_index.value_or(0);
});
for (auto* app_restore_data : relative_window_stack_order) {
app_restore_data->activation_index = g_template_next_activation_index--;
}
}

} // namespace saved_desk_util
} // namespace ash
7 changes: 7 additions & 0 deletions ash/wm/desks/templates/saved_desk_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ bool IsWindowOnTopForTemplate(aura::Window* window);
// defined, while also stacking on top of any existing windows.
ASH_EXPORT void UpdateTemplateActivationIndices(DeskTemplate& saved_desk);

// This function updates the activation indices of all the windows in a
// template so that windows launched from it will stack in the order that they
// were stacked upon saving as a template, while also stacking on top of any
// existing windows.
ASH_EXPORT void UpdateTemplateActivationIndicesRelativeOrder(
DeskTemplate& saved_desk);

} // namespace saved_desk_util
} // namespace ash

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ void FloatingWorkspaceService::LaunchFloatingWorkspaceTemplate(
VLOG(1) << "Combining Floating Workspace apps to current desk.";
std::unique_ptr<DeskTemplate> template_copy = desk_template->Clone();
// Open the apps from the floating workspace on top of existing windows.
saved_desk_util::UpdateTemplateActivationIndices(*template_copy);
saved_desk_util::UpdateTemplateActivationIndicesRelativeOrder(*template_copy);
GetDesksClient()->LaunchAppsFromTemplate(std::move(template_copy));
RecordLaunchSavedDeskHistogram(DeskTemplateType::kFloatingWorkspace);
}
Expand Down

0 comments on commit 3946245

Please sign in to comment.