workmap 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
workmap/layout.py ADDED
@@ -0,0 +1,64 @@
1
+ """Screen geometry for `organize`: how to divide the desktop into regions.
2
+
3
+ Pure arithmetic plus one call into the terminal driver to place windows."""
4
+ from __future__ import annotations
5
+
6
+ from . import terminal
7
+
8
+
9
+ def _usable_desktop() -> tuple[int, int, int, int]:
10
+ """left, top, right, bottom, leaves room for menu bar + dock."""
11
+ x1, y1, x2, y2 = terminal.desktop_bounds()
12
+ return x1 + 6, y1 + 28, x2 - 6, y2 - 56
13
+
14
+
15
+ def _grid_shape(n: int) -> tuple[int, int]:
16
+ if n <= 1:
17
+ return 1, 1
18
+ if n == 2:
19
+ return 1, 2
20
+ if n <= 4:
21
+ return 2, 2
22
+ if n <= 6:
23
+ return 2, 3
24
+ cols = 3 if n <= 9 else 4
25
+ rows = (n + cols - 1) // cols
26
+ return rows, cols
27
+
28
+
29
+ def tile_windows_in_rect(
30
+ window_ids: list[int],
31
+ rect: tuple[int, int, int, int],
32
+ *,
33
+ front: bool = True,
34
+ ) -> int:
35
+ """Tile windows inside (left, top, right, bottom).
36
+
37
+ Returns how many windows actually moved, which is not always how many were
38
+ asked to: see `place_windows`.
39
+ """
40
+ if not window_ids:
41
+ return 0
42
+ left, top, right, bottom = rect
43
+ width = max(320, right - left)
44
+ height = max(240, bottom - top)
45
+ rows, cols = _grid_shape(len(window_ids))
46
+ cell_w, cell_h = width // cols, height // rows
47
+ gap = 4
48
+ placements = []
49
+ for i, wid in enumerate(window_ids):
50
+ row, col = i // cols, i % cols
51
+ placements.append((wid, (
52
+ left + col * cell_w + gap,
53
+ top + row * cell_h + gap,
54
+ left + (col + 1) * cell_w - gap,
55
+ top + (row + 1) * cell_h - gap,
56
+ )))
57
+ return terminal.place_windows(placements, front_first=front)
58
+
59
+
60
+ def gather_windows(window_ids: list[int]) -> int:
61
+ """Legacy helper: tile across the full usable desktop."""
62
+ left, top, right, bottom = _usable_desktop()
63
+ return tile_windows_in_rect(window_ids, (left, top, right, bottom),
64
+ front=True)