Implement consume/expel animations
Browse files at this commitb28810286649cadeb5178d958a91d45f1ea462c0Parent: ff42f9b1 changed file +93 -13
- src/layout/workspace.rs +93 -13
src/layout/workspace.rsmodified+93 -13
| @@ -670,6 +670,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 670 | self.options.clone(), | 670 | self.options.clone(), |
| 671 | width, | 671 | width, |
| 672 | is_full_width, | 672 | is_full_width, |
| 673 | + true, | ||
| 673 | ); | 674 | ); |
| 674 | let width = column.width(); | 675 | let width = column.width(); |
| 675 | self.columns.insert(col_idx, column); | 676 | self.columns.insert(col_idx, column); |
| @@ -747,6 +748,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 747 | self.options.clone(), | 748 | self.options.clone(), |
| 748 | width, | 749 | width, |
| 749 | is_full_width, | 750 | is_full_width, |
| 751 | + true, | ||
| 750 | ); | 752 | ); |
| 751 | self.columns.insert(idx, column); | 753 | self.columns.insert(idx, column); |
| 752 | 754 | ||
| @@ -1313,31 +1315,57 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1313 | return; | 1315 | return; |
| 1314 | } | 1316 | } |
| 1315 | 1317 | ||
| 1316 | - let source_column = &self.columns[self.active_column_idx]; | 1318 | + let source_col_idx = self.active_column_idx; |
| 1319 | + let source_column = &self.columns[source_col_idx]; | ||
| 1320 | + let prev_y = source_column.tile_y(source_column.active_tile_idx); | ||
| 1321 | + | ||
| 1317 | if source_column.tiles.len() == 1 { | 1322 | if source_column.tiles.len() == 1 { |
| 1318 | if self.active_column_idx == 0 { | 1323 | if self.active_column_idx == 0 { |
| 1319 | return; | 1324 | return; |
| 1320 | } | 1325 | } |
| 1321 | 1326 | ||
| 1327 | + let offset_x = self.column_x(source_col_idx) - self.column_x(source_col_idx - 1); | ||
| 1328 | + | ||
| 1322 | // Move into adjacent column. | 1329 | // Move into adjacent column. |
| 1323 | - let target_column_idx = self.active_column_idx - 1; | 1330 | + let target_column_idx = source_col_idx - 1; |
| 1324 | - let window = self.remove_window_by_idx(self.active_column_idx, 0); | 1331 | + |
| 1332 | + // Make sure the previous (target) column is activated so the animation looks right. | ||
| 1333 | + self.activate_prev_column_on_removal = Some(self.static_view_offset()); | ||
| 1334 | + let window = self.remove_window_by_idx(source_col_idx, 0); | ||
| 1325 | self.enter_output_for_window(&window); | 1335 | self.enter_output_for_window(&window); |
| 1326 | 1336 | ||
| 1337 | + let next_col_idx = source_col_idx; | ||
| 1338 | + let prev_next_x = self.column_x(next_col_idx); | ||
| 1339 | + | ||
| 1327 | let target_column = &mut self.columns[target_column_idx]; | 1340 | let target_column = &mut self.columns[target_column_idx]; |
| 1341 | + let offset_y = prev_y - target_column.tile_y(target_column.tiles.len()); | ||
| 1342 | + | ||
| 1328 | target_column.add_window(window, true); | 1343 | target_column.add_window(window, true); |
| 1329 | target_column.focus_last(); | 1344 | target_column.focus_last(); |
| 1330 | - self.activate_column(target_column_idx); | 1345 | + |
| 1346 | + let new_tile = target_column.tiles.last_mut().unwrap(); | ||
| 1347 | + new_tile.animate_move_from(Point::from((offset_x, offset_y))); | ||
| 1348 | + | ||
| 1349 | + // Consuming a window into a column could've increased its width if the new window had a | ||
| 1350 | + // larger min width. Move the next columns to account for this. | ||
| 1351 | + let offset_next = prev_next_x - self.column_x(next_col_idx); | ||
| 1352 | + for col in &mut self.columns[next_col_idx..] { | ||
| 1353 | + col.animate_move_from(offset_next); | ||
| 1354 | + } | ||
| 1331 | } else { | 1355 | } else { |
| 1332 | // Move out of column. | 1356 | // Move out of column. |
| 1333 | let width = source_column.width; | 1357 | let width = source_column.width; |
| 1334 | let is_full_width = source_column.is_full_width; | 1358 | let is_full_width = source_column.is_full_width; |
| 1335 | - let window = | 1359 | + |
| 1336 | - self.remove_window_by_idx(self.active_column_idx, source_column.active_tile_idx); | 1360 | + let window = self.remove_window_by_idx(source_col_idx, source_column.active_tile_idx); |
| 1337 | 1361 | ||
| 1338 | self.add_window_at(self.active_column_idx, window, true, width, is_full_width); | 1362 | self.add_window_at(self.active_column_idx, window, true, width, is_full_width); |
| 1339 | // We added to the left, don't activate even further left on removal. | 1363 | // We added to the left, don't activate even further left on removal. |
| 1340 | self.activate_prev_column_on_removal = None; | 1364 | self.activate_prev_column_on_removal = None; |
| 1365 | + | ||
| 1366 | + let new_col = &mut self.columns[self.active_column_idx]; | ||
| 1367 | + let offset_y = prev_y - new_col.tile_y(0); | ||
| 1368 | + new_col.tiles[0].animate_move_from(Point::from((0, offset_y))); | ||
| 1341 | } | 1369 | } |
| 1342 | } | 1370 | } |
| 1343 | 1371 | ||
| @@ -1346,29 +1374,53 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1346 | return; | 1374 | return; |
| 1347 | } | 1375 | } |
| 1348 | 1376 | ||
| 1349 | - let source_column = &self.columns[self.active_column_idx]; | 1377 | + let source_col_idx = self.active_column_idx; |
| 1378 | + let offset_x = self.column_x(source_col_idx) - self.column_x(source_col_idx + 1); | ||
| 1379 | + | ||
| 1380 | + let source_column = &self.columns[source_col_idx]; | ||
| 1381 | + let prev_y = source_column.tile_y(source_column.active_tile_idx); | ||
| 1382 | + | ||
| 1350 | if source_column.tiles.len() == 1 { | 1383 | if source_column.tiles.len() == 1 { |
| 1351 | if self.active_column_idx + 1 == self.columns.len() { | 1384 | if self.active_column_idx + 1 == self.columns.len() { |
| 1352 | return; | 1385 | return; |
| 1353 | } | 1386 | } |
| 1354 | 1387 | ||
| 1355 | // Move into adjacent column. | 1388 | // Move into adjacent column. |
| 1356 | - let target_column_idx = self.active_column_idx; | 1389 | + let target_column_idx = source_col_idx; |
| 1357 | - let window = self.remove_window_by_idx(self.active_column_idx, 0); | 1390 | + |
| 1391 | + // Make sure the target column gets activated. | ||
| 1392 | + self.activate_prev_column_on_removal = None; | ||
| 1393 | + let window = self.remove_window_by_idx(source_col_idx, 0); | ||
| 1358 | self.enter_output_for_window(&window); | 1394 | self.enter_output_for_window(&window); |
| 1359 | 1395 | ||
| 1396 | + let prev_next_x = self.column_x(target_column_idx + 1); | ||
| 1397 | + | ||
| 1360 | let target_column = &mut self.columns[target_column_idx]; | 1398 | let target_column = &mut self.columns[target_column_idx]; |
| 1399 | + let offset_y = prev_y - target_column.tile_y(target_column.tiles.len()); | ||
| 1400 | + | ||
| 1361 | target_column.add_window(window, true); | 1401 | target_column.add_window(window, true); |
| 1362 | target_column.focus_last(); | 1402 | target_column.focus_last(); |
| 1363 | - self.activate_column(target_column_idx); | 1403 | + |
| 1404 | + let new_tile = target_column.tiles.last_mut().unwrap(); | ||
| 1405 | + new_tile.animate_move_from(Point::from((offset_x, offset_y))); | ||
| 1406 | + | ||
| 1407 | + // Consuming a window into a column could've increased its width if the new window had a | ||
| 1408 | + // larger min width. Move the next columns to account for this. | ||
| 1409 | + let offset_next = prev_next_x - self.column_x(target_column_idx + 1); | ||
| 1410 | + for col in &mut self.columns[target_column_idx + 1..] { | ||
| 1411 | + col.animate_move_from(offset_next); | ||
| 1412 | + } | ||
| 1364 | } else { | 1413 | } else { |
| 1365 | // Move out of column. | 1414 | // Move out of column. |
| 1366 | let width = source_column.width; | 1415 | let width = source_column.width; |
| 1367 | let is_full_width = source_column.is_full_width; | 1416 | let is_full_width = source_column.is_full_width; |
| 1368 | - let window = | 1417 | + let window = self.remove_window_by_idx(source_col_idx, source_column.active_tile_idx); |
| 1369 | - self.remove_window_by_idx(self.active_column_idx, source_column.active_tile_idx); | ||
| 1370 | 1418 | ||
| 1371 | self.add_window(window, true, width, is_full_width); | 1419 | self.add_window(window, true, width, is_full_width); |
| 1420 | + | ||
| 1421 | + let new_col = &mut self.columns[self.active_column_idx]; | ||
| 1422 | + let offset_y = prev_y - new_col.tile_y(0); | ||
| 1423 | + new_col.tiles[0].animate_move_from(Point::from((offset_x, offset_y))); | ||
| 1372 | } | 1424 | } |
| 1373 | } | 1425 | } |
| 1374 | 1426 | ||
| @@ -1382,17 +1434,34 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1382 | } | 1434 | } |
| 1383 | 1435 | ||
| 1384 | let source_column_idx = self.active_column_idx + 1; | 1436 | let source_column_idx = self.active_column_idx + 1; |
| 1437 | + | ||
| 1438 | + let offset_x = self.column_x(source_column_idx) - self.column_x(self.active_column_idx); | ||
| 1439 | + let prev_y = self.columns[source_column_idx].tile_y(0); | ||
| 1440 | + | ||
| 1385 | let window = self.remove_window_by_idx(source_column_idx, 0); | 1441 | let window = self.remove_window_by_idx(source_column_idx, 0); |
| 1386 | self.enter_output_for_window(&window); | 1442 | self.enter_output_for_window(&window); |
| 1387 | 1443 | ||
| 1444 | + let prev_next_x = self.column_x(self.active_column_idx + 1); | ||
| 1445 | + | ||
| 1388 | let target_column = &mut self.columns[self.active_column_idx]; | 1446 | let target_column = &mut self.columns[self.active_column_idx]; |
| 1389 | let was_fullscreen = target_column.tiles[target_column.active_tile_idx].is_fullscreen(); | 1447 | let was_fullscreen = target_column.tiles[target_column.active_tile_idx].is_fullscreen(); |
| 1448 | + let offset_y = prev_y - target_column.tile_y(target_column.tiles.len()); | ||
| 1390 | 1449 | ||
| 1391 | target_column.add_window(window, true); | 1450 | target_column.add_window(window, true); |
| 1392 | 1451 | ||
| 1393 | if !was_fullscreen { | 1452 | if !was_fullscreen { |
| 1394 | self.view_offset_before_fullscreen = None; | 1453 | self.view_offset_before_fullscreen = None; |
| 1395 | } | 1454 | } |
| 1455 | + | ||
| 1456 | + let new_tile = target_column.tiles.last_mut().unwrap(); | ||
| 1457 | + new_tile.animate_move_from(Point::from((offset_x, offset_y))); | ||
| 1458 | + | ||
| 1459 | + // Consuming a window into a column could've increased its width if the new window had a | ||
| 1460 | + // larger min width. Move the next columns to account for this. | ||
| 1461 | + let offset_next = prev_next_x - self.column_x(self.active_column_idx + 1); | ||
| 1462 | + for col in &mut self.columns[self.active_column_idx + 1..] { | ||
| 1463 | + col.animate_move_from(offset_next); | ||
| 1464 | + } | ||
| 1396 | } | 1465 | } |
| 1397 | 1466 | ||
| 1398 | pub fn expel_from_column(&mut self) { | 1467 | pub fn expel_from_column(&mut self) { |
| @@ -1400,17 +1469,26 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1400 | return; | 1469 | return; |
| 1401 | } | 1470 | } |
| 1402 | 1471 | ||
| 1472 | + let offset_x = | ||
| 1473 | + self.column_x(self.active_column_idx) - self.column_x(self.active_column_idx + 1); | ||
| 1474 | + | ||
| 1403 | let source_column = &self.columns[self.active_column_idx]; | 1475 | let source_column = &self.columns[self.active_column_idx]; |
| 1404 | if source_column.tiles.len() == 1 { | 1476 | if source_column.tiles.len() == 1 { |
| 1405 | return; | 1477 | return; |
| 1406 | } | 1478 | } |
| 1407 | 1479 | ||
| 1480 | + let prev_y = source_column.tile_y(source_column.active_tile_idx); | ||
| 1481 | + | ||
| 1408 | let width = source_column.width; | 1482 | let width = source_column.width; |
| 1409 | let is_full_width = source_column.is_full_width; | 1483 | let is_full_width = source_column.is_full_width; |
| 1410 | let window = | 1484 | let window = |
| 1411 | self.remove_window_by_idx(self.active_column_idx, source_column.active_tile_idx); | 1485 | self.remove_window_by_idx(self.active_column_idx, source_column.active_tile_idx); |
| 1412 | 1486 | ||
| 1413 | self.add_window(window, true, width, is_full_width); | 1487 | self.add_window(window, true, width, is_full_width); |
| 1488 | + | ||
| 1489 | + let new_col = &mut self.columns[self.active_column_idx]; | ||
| 1490 | + let offset_y = prev_y - new_col.tile_y(0); | ||
| 1491 | + new_col.tiles[0].animate_move_from(Point::from((offset_x, offset_y))); | ||
| 1414 | } | 1492 | } |
| 1415 | 1493 | ||
| 1416 | pub fn center_column(&mut self) { | 1494 | pub fn center_column(&mut self) { |
| @@ -1608,6 +1686,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1608 | self.options.clone(), | 1686 | self.options.clone(), |
| 1609 | width, | 1687 | width, |
| 1610 | is_full_width, | 1688 | is_full_width, |
| 1689 | + false, | ||
| 1611 | ), | 1690 | ), |
| 1612 | ); | 1691 | ); |
| 1613 | 1692 | ||
| @@ -1942,6 +2021,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 1942 | options: Rc<Options>, | 2021 | options: Rc<Options>, |
| 1943 | width: ColumnWidth, | 2022 | width: ColumnWidth, |
| 1944 | is_full_width: bool, | 2023 | is_full_width: bool, |
| 2024 | + animate_resize: bool, | ||
| 1945 | ) -> Self { | 2025 | ) -> Self { |
| 1946 | let mut rv = Self { | 2026 | let mut rv = Self { |
| 1947 | tiles: vec![], | 2027 | tiles: vec![], |
| @@ -1959,7 +2039,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 1959 | 2039 | ||
| 1960 | let is_pending_fullscreen = window.is_pending_fullscreen(); | 2040 | let is_pending_fullscreen = window.is_pending_fullscreen(); |
| 1961 | 2041 | ||
| 1962 | - rv.add_window(window, false); | 2042 | + rv.add_window(window, animate_resize); |
| 1963 | 2043 | ||
| 1964 | if is_pending_fullscreen { | 2044 | if is_pending_fullscreen { |
| 1965 | rv.set_fullscreen(true); | 2045 | rv.set_fullscreen(true); |