gardesk/tarmac / f387dc8

Browse files

Make stack slivers side-aware

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
f387dc807ab1558d63fda69e51f6376235ba3bb6
Parents
dfa2d6d
Tree
da1a022

1 changed file

StatusFile+-
M tarmac/src/core/tree.rs 31 8
tarmac/src/core/tree.rsmodified
@@ -89,6 +89,12 @@ impl Default for Node {
8989
 }
9090
 
9191
 impl Node {
92
+    fn stack_reveal_direction(windows_len: usize, active: usize) -> f64 {
93
+        let left_count = active;
94
+        let right_count = windows_len.saturating_sub(active + 1);
95
+        if left_count > right_count { -1.0 } else { 1.0 }
96
+    }
97
+
9298
     pub fn empty() -> Self {
9399
         Node::Leaf { window: None }
94100
     }
@@ -312,6 +318,7 @@ impl Node {
312318
                 windows, active, ..
313319
             } => {
314320
                 let active_window = windows.get(*active).copied();
321
+                let x_direction = Self::stack_reveal_direction(windows.len(), *active);
315322
                 let mut geoms = Vec::with_capacity(windows.len());
316323
                 let mut depth = 0usize;
317324
                 for (idx, wid) in windows.iter().enumerate() {
@@ -322,7 +329,7 @@ impl Node {
322329
                     geoms.push((
323330
                         *wid,
324331
                         Rect::new(
325
-                            padded.x + STACK_REVEAL_OFFSET_X * depth as f64,
332
+                            padded.x + x_direction * STACK_REVEAL_OFFSET_X * depth as f64,
326333
                             padded.y + STACK_REVEAL_OFFSET_Y * depth as f64,
327334
                             padded.width,
328335
                             padded.height,
@@ -1414,18 +1421,34 @@ mod tests {
14141421
     }
14151422
 
14161423
     #[test]
1417
-    fn stacked_render_geometries_reveal_background_windows() {
1418
-        let mut tree = Node::empty();
1419
-        tree.insert_with_rect(1, None, SCREEN);
1420
-        tree.insert_with_rect(2, Some(1), SCREEN);
1421
-        tree.insert_with_rect(3, Some(2), SCREEN);
1422
-        assert!(tree.make_stack_for_window(3));
1424
+    fn stacked_render_geometries_reveal_background_windows_to_the_right_when_right_biased() {
1425
+        let tree = Node::Stack {
1426
+            windows: vec![1, 2, 3],
1427
+            active: 0,
1428
+            previous: Box::new(Node::Leaf { window: Some(1) }),
1429
+        };
1430
+        let geoms = tree.calculate_geometries(SCREEN);
1431
+        let g1 = geoms.iter().find(|(wid, _)| *wid == 1).unwrap().1;
1432
+        let g2 = geoms.iter().find(|(wid, _)| *wid == 2).unwrap().1;
14231433
 
1434
+        assert!(g2.x > g1.x);
1435
+        assert!(g2.y > g1.y);
1436
+        assert_eq!(g2.width, g1.width);
1437
+        assert_eq!(g2.height, g1.height);
1438
+    }
1439
+
1440
+    #[test]
1441
+    fn stacked_render_geometries_reveal_background_windows_to_the_left_when_left_biased() {
1442
+        let tree = Node::Stack {
1443
+            windows: vec![1, 2, 3],
1444
+            active: 2,
1445
+            previous: Box::new(Node::Leaf { window: Some(3) }),
1446
+        };
14241447
         let geoms = tree.calculate_geometries(SCREEN);
14251448
         let g2 = geoms.iter().find(|(wid, _)| *wid == 2).unwrap().1;
14261449
         let g3 = geoms.iter().find(|(wid, _)| *wid == 3).unwrap().1;
14271450
 
1428
-        assert!(g2.x > g3.x);
1451
+        assert!(g2.x < g3.x);
14291452
         assert!(g2.y > g3.y);
14301453
         assert_eq!(g2.width, g3.width);
14311454
         assert_eq!(g2.height, g3.height);