Skip to content

Commit

Permalink
floating: Transition via maximized state
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Nov 15, 2023
1 parent 6d3c429 commit 7f62de0
Showing 1 changed file with 57 additions and 37 deletions.
94 changes: 57 additions & 37 deletions src/shell/layout/floating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,43 @@ impl FloatingLayout {
}
StackMoveResult::Default => {
let mut tiled_state = focused.floating_tiled.lock().unwrap();

let output = self.space.outputs().next().unwrap().clone();
let layers = layer_map_for_output(&output);
let output_geometry = layers.non_exclusive_zone();
std::mem::drop(layers);

let start_rectangle = if let Some((previous_start, previous_rect)) =
self.tiling_animations.remove(focused)
{
if let Some(target_rect) = tiled_state
.as_ref()
.map(|state| state.relative_geometry(output_geometry))
{
ease(
EaseInOutCubic,
EaseRectangle(previous_rect),
EaseRectangle(target_rect),
Instant::now()
.duration_since(previous_start)
.max(ANIMATION_DURATION)
.as_secs_f64()
/ ANIMATION_DURATION.as_secs_f64(),
)
.unwrap()
} else {
self.space
.element_geometry(focused)
.map(RectExt::as_local)
.unwrap()
}
} else {
self.space
.element_geometry(focused)
.map(RectExt::as_local)
.unwrap()
};

let new_state = match (direction, &*tiled_state) {
// figure out if we are moving between workspaces/outputs
(
Expand Down Expand Up @@ -726,6 +763,20 @@ impl FloatingLayout {
));
}

// to we go maximized?
(Direction::Up, Some(TiledCorners::Bottom))
| (Direction::Down, Some(TiledCorners::Top))
| (Direction::Left, Some(TiledCorners::Right))
| (Direction::Right, Some(TiledCorners::Left)) => {
self.tiling_animations
.insert(focused.clone(), (Instant::now(), start_rectangle));
*tiled_state = None;
std::mem::drop(tiled_state);

self.map_maximized(focused.clone());
return MoveResult::Done;
}

// figure out if we need to quater tile
(Direction::Up, Some(TiledCorners::Left))
| (Direction::Left, Some(TiledCorners::Top)) => TiledCorners::TopLeft,
Expand All @@ -751,47 +802,12 @@ impl FloatingLayout {
(Direction::Left, _) => TiledCorners::Left,
};

let output = self.space.outputs().next().unwrap().clone();
let layers = layer_map_for_output(&output);
let output_geometry = layers.non_exclusive_zone();
std::mem::drop(layers);

let new_geo = new_state.relative_geometry(output_geometry);
let (new_pos, new_size) = (new_geo.loc, new_geo.size);
focused.set_tiled(true); // TODO: More fine grained?
focused.set_maximized(false);

let start_rectangle = if let Some((previous_start, previous_rect)) =
self.tiling_animations.remove(focused)
{
if let Some(target_rect) = tiled_state
.as_ref()
.map(|state| state.relative_geometry(output_geometry))
{
ease(
EaseInOutCubic,
EaseRectangle(previous_rect),
EaseRectangle(target_rect),
Instant::now()
.duration_since(previous_start)
.max(ANIMATION_DURATION)
.as_secs_f64()
/ ANIMATION_DURATION.as_secs_f64(),
)
.unwrap()
} else {
self.space
.element_geometry(focused)
.map(RectExt::as_local)
.unwrap()
}
} else {
self.space
.element_geometry(focused)
.map(RectExt::as_local)
.unwrap()
};

if tiled_state.is_none() {
if tiled_state.is_none() && focused.is_maximized(false) {
*focused.last_geometry.lock().unwrap() =
self.space.element_geometry(focused).map(RectExt::as_local);
}
Expand Down Expand Up @@ -923,6 +939,10 @@ impl FloatingLayout {
.unwrap()
.as_ref()
.map(|state| state.relative_geometry(output_geometry))
.or_else(|| {
elem.is_maximized(true)
.then_some(output_geometry.as_local())
})
{
geometry = ease(
EaseInOutCubic,
Expand Down

0 comments on commit 7f62de0

Please sign in to comment.