fix(wm): promoting a container shouldn't change resize dimensions

- When promoting a container it is using the
  `remove_focused_container()` and `insert_container_at_idx` functions
  which will remove the focused container size from `resize_dimensions`
  and then add the new container with size `None`. Then it was adding
  the previously stored size of the main container back to the first
  one. However this would result in at least 3 issues:

    1. We were removing the size from index 0, however when inserting it
       back on the primary_idx we might not add it to index 0, specially
       now that there could be locked containers so if container 0 is
       locked we would be adding it to the next container, which would
       result in the main container having no size information which
       would result in a recalculation on the next update and it would
       revert back to default, so if a user had resized their containers
       that information would be lost.

    2. We were removing the size from index 0. Then on
       `remove_focused_container` it would remove the size from the
       focused container index, but since we had already removed one
       size from the `resize_dimensions` that index would no longer
       match the actual focused container, so once again we would be
       losing information.

    3. Since we were removing the size of the focused container idx from
       `resize_dimensions` (albeit the wrong one as stated above), this
       would mean that the container that moved to that position would
       have no resize information so it would show up as if the main
       container was taking up half width of the area, ignoring any user
       resize, until the next workspace update was triggered.

- This commit completely ignores the `resize_dimensions` since promoting
  a container simply means moving one container from one position to the
  main one (usually index 0) and then shift all the rest to the "right".
  The existing `resize_dimensions` should be kept untouched. To do this
  we use the functions `remove_respecting_locks` and
  `insert_respecting_locks` on the containers themselves, which simply
  move the container and shifts the others which is precisely what we
  want.
This commit is contained in:
alex-ds13
2025-11-20 15:12:32 +00:00
committed by LGUG2Z
parent df2adde13d
commit 31c969fc55

View File

@@ -825,9 +825,10 @@ impl Workspace {
}
pub fn promote_container(&mut self) -> eyre::Result<()> {
let resize = self.resize_dimensions.remove(0);
let focused_idx = self.focused_container_idx();
let container = self
.remove_focused_container()
.containers_mut()
.remove_respecting_locks(focused_idx)
.ok_or_eyre("there is no container")?;
let primary_idx = match &self.layout {
@@ -839,9 +840,10 @@ impl Workspace {
),
};
let insertion_idx = self.insert_container_at_idx(primary_idx, container);
self.resize_dimensions[insertion_idx] = resize;
self.focus_container(primary_idx);
let insertion_idx = self
.containers_mut()
.insert_respecting_locks(primary_idx, container);
self.focus_container(insertion_idx);
Ok(())
}