Skip to content

An open-source, self-hosted system for apps built with web technologies.

System 0.8.3: snaps at the screen's edge itself; the carried Map shows where Windows are

zohayrslileh950425d62a43
diff --git a/package.json b/package.json
index e10084e..0042631 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "phreshos",
- "version": "0.8.2",
+ "version": "0.8.3",
"description": "The PhreshOS server, desktop, and authoritative system runtime.",
"type": "module",
"private": true,
diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsx
index 8508cbf..f3f0581 100644
--- a/source/client/view/structure/desktop/desktop.tsx
+++ b/source/client/view/structure/desktop/desktop.tsx
@@ -574,15 +574,13 @@ export default function Workspace() {
{/* What a press means is composed here because it is a person's
expectation, not a system operation: the front window hides;
pressing another takes you to its view and brings it forward.
- A pinned Program keeps its place: its first Window stands there in
- its icon's stead, and its icon returns once its last is closed; every
- other Window follows, as they opened. */}
- {pinnedPrograms.map(program => {
- const first = slotHolders.get(program.identity)
- return first
- ? windowItem(first)
- : <PinnedTaskbarItem key={`pinned:${program.identity}`} program={program} icon={icon({ program: program.identity })} position={appearance.taskbar.position} />
- })}
+ Pinned Programs with no Window come first, as they were pinned;
+ then those with one, each its first Window, as they were pinned;
+ every other Window follows, as they opened. */}
+ {pinnedPrograms.filter(program => !slotHolders.has(program.identity)).map(program =>
+ <PinnedTaskbarItem key={`pinned:${program.identity}`} program={program} icon={icon({ program: program.identity })} position={appearance.taskbar.position} />)}
+
+ {pinnedPrograms.flatMap(program => slotHolders.get(program.identity) ?? []).map(windowItem)}
{windows.listed.filter(record => slotHolders.get(record.program) !== record).map(windowItem)}
diff --git a/source/client/view/structure/desktop/edge-hold.ts b/source/client/view/structure/desktop/edge-hold.ts
index 360f79f..b5299e4 100644
--- a/source/client/view/structure/desktop/edge-hold.ts
+++ b/source/client/view/structure/desktop/edge-hold.ts
@@ -32,12 +32,18 @@ export function useViewTravel(viewport: Viewport) {
}, [view.x, view.y, moveTo, reducedMotion, tempo, size.width, size.height])
}
-/** Which edges of a box a point is held against, within 16 pixels: -1, 0 or 1 in each direction. */
+/**
+ * How close to an edge, in pixels, a point is held against it. Only the edge itself, or beyond it:
+ * a hand that only carries something near the edge does not hold it there.
+ */
+const reach = 3
+
+/** Which edges of a box a point is held against, within `reach` or beyond: -1, 0 or 1 in each direction. */
export function against(x: number, y: number, width: number, height: number): Direction {
return {
- x: x <= 16 ? -1 : x >= width - 16 ? 1 : 0,
- y: y <= 16 ? -1 : y >= height - 16 ? 1 : 0
+ x: x <= reach ? -1 : x >= width - reach ? 1 : 0,
+ y: y <= reach ? -1 : y >= height - reach ? 1 : 0
}
}
@@ -45,10 +51,6 @@ export function against(x: number, y: number, width: number, height: number): Di
* Something held against an edge of the screen takes the view that way: after 700 milliseconds, one
* whole view; then, once the view has arrived and a half second has passed, another, for as long as
* it stays there. Where the plane goes no further, it says so, so the one holding can show it.
- *
- * A hold that can also settle there, as a Window that snaps to the edge, first waits 300 milliseconds
- * to settle and only then 700 more to travel, so a hand that only carries it near the edge does
- * neither. Once settled, it stays so along the edges until it leaves them.
*/
export class EdgeHold {
@@ -58,16 +60,9 @@ export class EdgeHold {
private blocked = false
- /** The edges it has settled against, or null while it has not. */
- public settled: Direction | null = null
-
public constructor(
private readonly travel: (direction: Direction) => number | null | undefined,
- private readonly events: Readonly<{
- onBlocked?: (blocked: boolean) => void
- /** Given, the hold settles before it travels, and says when it settles or leaves. */
- onSettled?: (settled: Direction | null) => void
- }> = {}
+ private readonly onBlocked?: (blocked: boolean) => void
) {}
/** Where it is held now; a new edge starts the wait again, and no edge stops it. */
@@ -75,66 +70,29 @@ export class EdgeHold {
if (direction.x === this.direction.x && direction.y === this.direction.y) return
- if (!direction.x && !direction.y) return this.stop()
-
- this.pause()
+ this.stop()
this.direction = direction
- if (!this.events.onSettled) this.timer = window.setTimeout(() => this.hold(), 700)
-
- else if (this.settled) {
-
- this.settle()
-
- this.timer = window.setTimeout(() => this.hold(), 700)
- }
-
- else this.timer = window.setTimeout(() => {
-
- this.settle()
-
- this.timer = window.setTimeout(() => this.hold(), 700)
-
- }, 300)
+ if (direction.x || direction.y) this.timer = window.setTimeout(() => this.hold(), 700)
}
public stop() {
- this.pause()
-
- this.direction = { x: 0, y: 0 }
-
- if (this.settled) {
-
- this.settled = null
-
- this.events.onSettled?.(null)
- }
- }
-
- /** Stops waiting and shows the plane's end no more, still settled. */
- private pause() {
-
if (this.timer) clearTimeout(this.timer)
this.timer = 0
+ this.direction = { x: 0, y: 0 }
+
if (this.blocked) {
this.blocked = false
- this.events.onBlocked?.(false)
+ this.onBlocked?.(false)
}
}
- private settle() {
-
- this.settled = this.direction
-
- this.events.onSettled?.(this.settled)
- }
-
private hold() {
const took = this.travel(this.direction)
@@ -145,7 +103,7 @@ export class EdgeHold {
this.blocked = true
- this.events.onBlocked?.(true)
+ this.onBlocked?.(true)
return
}
diff --git a/source/client/view/structure/desktop/layers/shell/taskbar/map/map-control.tsx b/source/client/view/structure/desktop/layers/shell/taskbar/map/map-control.tsx
index 57b8b47..aeddb9e 100644
--- a/source/client/view/structure/desktop/layers/shell/taskbar/map/map-control.tsx
+++ b/source/client/view/structure/desktop/layers/shell/taskbar/map/map-control.tsx
@@ -11,6 +11,7 @@ import { motionTransition } from "@client/view/appearance/motion"
import { EdgeHold, against, useViewTravel, type Direction } from "../../../../edge-hold"
import { createPortal } from "react-dom"
import CrossingSign from "./crossing-sign"
+import WindowBearings from "./window-bearings"
import { desktopMargins } from "../../../desktop-layers"
import { surfacePresenceTransition } from "@client/view/appearance/surface-presence"
import { useShellPopover } from "../../shell-popover"
@@ -143,7 +144,7 @@ export default function MapControl({ viewport, windows, taskbar, spacing, onOpen
const held = event.target as Element
- const edges = new EdgeHold(direction => travelNow.current(direction), { onBlocked: blocked => setEdge(current => ({ ...current, blocked })) })
+ const edges = new EdgeHold(direction => travelNow.current(direction), blocked => setEdge(current => ({ ...current, blocked })))
const windowLayer = document.querySelector<HTMLElement>("[data-desktop-layer=\"window\"]")
@@ -272,6 +273,16 @@ export default function MapControl({ viewport, windows, taskbar, spacing, onOpen
</TaskbarTooltip>
</span>
+ {/* Carried, the Map shows which way each Window outside the view lies. */}
+ {edge.layer && createPortal(<WindowBearings
+ shown={ghost !== null}
+ windows={windows}
+ viewport={viewport}
+ margins={desktopMargins(spacing, taskbar)}
+ reducedMotion={reducedMotion}
+ zIndex={2147483646}
+ />, edge.layer)}
+
{edge.shown && edge.layer && createPortal(<CrossingSign
direction={edge.shown}
place={place}
diff --git a/source/client/view/structure/desktop/layers/shell/taskbar/map/window-bearings.tsx b/source/client/view/structure/desktop/layers/shell/taskbar/map/window-bearings.tsx
new file mode 100644
index 0000000..98e0cd3
--- /dev/null
+++ b/source/client/view/structure/desktop/layers/shell/taskbar/map/window-bearings.tsx
@@ -0,0 +1,136 @@
+import { type CSSProperties } from "react"
+import { AnimatePresence, motion } from "motion/react"
+import { Surface, useAppearance, useColor, useScale, useTiming } from "@phreshos/react-ui"
+import { ChevronRight } from "@phreshos/react-ui/icons"
+import { motionTransition } from "@client/view/appearance/motion"
+import { type PaintMargins } from "@client/view/components/window-manager/window-geometry"
+import { type Viewport } from "../../../../viewport-offset"
+import { type MappedWindow } from "./map-control"
+
+type Edge = "left" | "right" | "top" | "bottom"
+
+/** A Window outside the view, as a mark on the edge of the screen that faces it. */
+type Bearing = { identity: string, icon: string, focused: boolean, x: number, y: number, angle: number, edge: Edge }
+
+/**
+ * While the Map is carried, every Window outside the view shows at the edge of the screen that faces
+ * it: its icon, as the map shows it, with a small arrow toward it, where a line from the middle of the
+ * screen to the Window's middle crosses the room the Taskbar leaves. It glides along the edges as the
+ * view crosses, and leaves once the Window is in view, so the hand knows which way to go to reach it.
+ * Marks that would cover each other stand side by side along their edge. They only show the way;
+ * nothing is pressed there.
+ */
+export default function WindowBearings({ shown, windows, viewport, margins, reducedMotion, zIndex }: WindowBearingsProps) {
+
+ const space = useScale(useAppearance().spacing)
+
+ const fade = motionTransition(useTiming()("change"), reducedMotion)
+
+ const icon = space.medium + space.xsmall, card = icon + space.xsmall * 2, arrow = space.medium, gap = space.xsmall
+
+ const primary = useColor("primary").base
+
+ const bearings = shown ? bearingsOf(windows, viewport, margins, { card, arrow, inset: space.medium, gap }) : []
+
+ // The marks travel with the view: the same motion while it glides, at once otherwise.
+ const glide = viewport.transaction && !reducedMotion ? motionTransition(viewport.transaction) : { duration: 0 }
+
+ return <div aria-hidden="true" className="pointer-events-none absolute inset-0" style={{ zIndex }}>
+
+ <AnimatePresence>
+ {bearings.map(bearing => <motion.div key={bearing.identity} className="absolute left-0 top-0"
+ initial={{ opacity: 0, x: bearing.x - card / 2, y: bearing.y - card / 2 }}
+ animate={{ opacity: 1, x: bearing.x - card / 2, y: bearing.y - card / 2, transition: { x: glide, y: glide, opacity: fade } }}
+ exit={{ opacity: 0, transition: fade }}
+ style={{ width: card, height: card }}>
+
+ <Surface color={bearing.focused ? "primary:soft" : "secondary:subtle"} className="grid place-items-center" style={{ width: card, height: card }}>
+ <img src={bearing.icon} alt="" draggable={false} className="object-contain" style={{ width: icon, height: icon }} />
+ </Surface>
+
+ {/* Turned about the card's middle, the arrow stands a little apart from it on the Window's side. */}
+ <motion.div className="absolute inset-0" initial={false} animate={{ rotate: bearing.angle }} transition={glide}>
+ <ChevronRight strokeWidth={3} style={{ position: "absolute", left: card + gap, top: (card - arrow) / 2, width: arrow, height: arrow, color: primary }} />
+ </motion.div>
+
+ </motion.div>)}
+ </AnimatePresence>
+
+ </div>
+}
+
+/** Where each Window outside the view shows: on the room's edge facing it, spread so none covers another. */
+export function bearingsOf(windows: readonly MappedWindow[], viewport: Viewport, margins: PaintMargins, size: Readonly<{ card: number, arrow: number, inset: number, gap: number }>): Bearing[] {
+
+ const { width, height } = viewport.size
+
+ const { offset } = viewport
+
+ // The room a mark's middle may take: inside the Taskbar's room, far enough in for the card and its arrow.
+ const reach = size.inset + size.card / 2 + size.gap + size.arrow
+
+ const room = { left: margins.left + reach, right: width - margins.right - reach, top: margins.top + reach, bottom: height - margins.bottom - reach }
+
+ if (room.left >= room.right || room.top >= room.bottom) return []
+
+ const middle = { x: width / 2, y: height / 2 }
+
+ const bearings: Bearing[] = []
+
+ for (const window of windows) {
+
+ if (window.minimized) continue
+
+ const { x, y, width: windowWidth, height: windowHeight } = window.region
+
+ // Any part of it in view, and it is reached.
+ const seen = x < offset.x + width / 2 && x + windowWidth > offset.x - width / 2 && y < offset.y + height / 2 && y + windowHeight > offset.y - height / 2
+
+ if (seen) continue
+
+ // From the middle of the screen to the Window's middle, until the room's edge.
+ const dx = x + windowWidth / 2 - offset.x, dy = y + windowHeight / 2 - offset.y
+
+ const across = dx > 0 ? (room.right - middle.x) / dx : dx < 0 ? (room.left - middle.x) / dx : Infinity
+
+ const down = dy > 0 ? (room.bottom - middle.y) / dy : dy < 0 ? (room.top - middle.y) / dy : Infinity
+
+ const reached = Math.min(across, down)
+
+ bearings.push({
+ identity: window.identity, icon: window.icon, focused: window.focused,
+ x: middle.x + dx * reached, y: middle.y + dy * reached,
+ angle: Math.atan2(dy, dx) * 180 / Math.PI,
+ edge: across <= down ? (dx > 0 ? "right" : "left") : (dy > 0 ? "bottom" : "top")
+ })
+ }
+
+ // Along each edge, marks closer than a card apart move apart, kept inside the edge's room.
+ const step = size.card + size.gap
+
+ for (const edge of ["left", "right", "top", "bottom"] as const) {
+
+ const along = edge === "left" || edge === "right" ? "y" : "x"
+
+ const [first, last] = along === "y" ? [room.top, room.bottom] : [room.left, room.right]
+
+ const row = bearings.filter(bearing => bearing.edge === edge).sort((one, other) => one[along] - other[along])
+
+ for (let index = 1; index < row.length; index++) row[index][along] = Math.max(row[index][along], row[index - 1][along] + step)
+
+ for (let index = row.length - 1; index >= 0; index--) row[index][along] = Math.max(first, Math.min(row[index][along], index === row.length - 1 ? last : row[index + 1][along] - step))
+ }
+
+ return bearings
+}
+
+interface WindowBearingsProps {
+ /** Whether the Map is carried now. */
+ shown: boolean
+ windows: readonly MappedWindow[]
+ viewport: Viewport
+ /** The room the Taskbar leaves, which the marks stay inside. */
+ margins: PaintMargins
+ reducedMotion: boolean
+ zIndex: CSSProperties["zIndex"]
+}
diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsx
index cf32786..b55075b 100644
--- a/source/client/view/structure/desktop/windows/window.tsx
+++ b/source/client/view/structure/desktop/windows/window.tsx
@@ -484,28 +484,15 @@ export default function ({ title, header = true, surface, layer, icon, children,
let renderFrame = 0
- // A hand holding a standard Window against an edge of the screen settles there, which offers
- // the half or quarter that edge names, then takes the view that way; see EdgeHold. Where the
- // plane goes no further, the preview of the placement turns to danger.
+ // A hand holding a standard Window against an edge of the screen takes the view that way; see
+ // EdgeHold. Where the plane goes no further, the preview of the placement turns to danger.
let blocked = false
- const edges = new EdgeHold(direction => latest.current.onEdgeHold?.(direction), {
+ const edges = new EdgeHold(direction => latest.current.onEdgeHold?.(direction), held => {
- onBlocked(held) {
+ blocked = held
- blocked = held
-
- renderGesture()
- },
-
- onSettled(settled) {
-
- zone = snapZone(settled)
-
- if (zone) shown = zone
-
- renderGesture()
- }
+ renderGesture()
})
function holdAgainst(motion: DesktopMovePoint) {
@@ -549,11 +536,13 @@ export default function ({ title, header = true, surface, layer, icon, children,
})
}
- // A zone is the edges the hold settled against, and names a half or a quarter of the room the
- // view leaves for Windows, which each Desktop resolves in its own space.
- function snapZone(settled: Readonly<{ x: number, y: number }> | null): Snap | null {
+ // A zone is where the pointer is, at an edge or beyond it (see `against`), and names a half or
+ // a quarter of the room the view leaves for Windows, which each Desktop resolves in its own space.
+ function snapTerm(motion: DesktopMovePoint): Snap | null {
- return settled ? snapPlacement(settled, paintMargins) : null
+ const direction = against(physicalToDesktopPixels(motion.x - bounds!.left, desktopScale), physicalToDesktopPixels(motion.y - bounds!.top, desktopScale), bounds!.width, bounds!.height)
+
+ return direction.x || direction.y ? snapPlacement(direction, paintMargins) : null
}
function move(motion: DesktopMovePoint) {
@@ -619,6 +608,8 @@ export default function ({ title, header = true, surface, layer, icon, children,
current = { ...origin, x: origin.x + dx, y: origin.y + dy }
// Only the Desktop's own Windows snap; a raw drawing goes where it is taken.
+ zone = moved && standard ? snapTerm(motion) : null
+
if (moved && standard) {
held.set(1)
@@ -626,8 +617,6 @@ export default function ({ title, header = true, surface, layer, icon, children,
holdAgainst(motion)
}
- zone = moved && standard ? snapZone(edges.settled) : null
-
if (zone) shown = zone
}
@@ -660,10 +649,7 @@ export default function ({ title, header = true, surface, layer, icon, children,
renderGesture()
}
- function release(committed: boolean) {
-
- // Only a hold that settled snaps; one let go before then leaves the Window where it is.
- const term = moved && edge === null && committed && standard ? zone : null
+ function release(motion: DesktopMovePoint, committed: boolean) {
edges.stop()
@@ -682,6 +668,8 @@ export default function ({ title, header = true, surface, layer, icon, children,
return
}
+ const term = moved && edge === null && committed && standard ? snapTerm(motion) : null
+
// Pointer input has ended, but visible gesture ownership remains
// until every authoritative mutation below has settled.
if (term) {
@@ -734,7 +722,7 @@ export default function ({ title, header = true, surface, layer, icon, children,
handle.removeEventListener("pointermove", movePointer)
handle.removeEventListener("pointerup", releasePointer)
handle.removeEventListener("pointercancel", releasePointer)
- release(motion.type === "pointerup")
+ release({ x: motion.clientX, y: motion.clientY }, motion.type === "pointerup")
}
handle.addEventListener("pointermove", movePointer)
handle.addEventListener("pointerup", releasePointer)
@@ -742,8 +730,8 @@ export default function ({ title, header = true, surface, layer, icon, children,
}
else receive?.({
update: move,
- end() { release(true) },
- cancel() { release(false) }
+ end(point) { release(point, true) },
+ cancel() { release(pointer, false) }
})
setGesture({ origin, current, zone, shown, blocked, insets })
diff --git a/tests/edge-hold.test.ts b/tests/edge-hold.test.ts
index 5649513..89af7bb 100644
--- a/tests/edge-hold.test.ts
+++ b/tests/edge-hold.test.ts
@@ -1,8 +1,7 @@
-import { EdgeHold, type Direction } from "@client/view/structure/desktop/edge-hold"
+import { EdgeHold, against, type Direction } from "@client/view/structure/desktop/edge-hold"
import { afterEach, beforeEach, expect, test, vi } from "vitest"
const right: Direction = { x: 1, y: 0 }
-const corner: Direction = { x: 1, y: 1 }
const away: Direction = { x: 0, y: 0 }
beforeEach(() => {
@@ -15,76 +14,47 @@ afterEach(() => {
vi.unstubAllGlobals()
})
-test("a hold that settles waits 300 milliseconds to settle, then 700 more to take the view", () => {
+test("a point is held against an edge only within 3 pixels of it, or beyond it", () => {
+ expect(against(500, 400, 1000, 800)).toEqual({ x: 0, y: 0 })
+ expect(against(4, 400, 1000, 800)).toEqual({ x: 0, y: 0 })
+ expect(against(3, 400, 1000, 800)).toEqual({ x: -1, y: 0 })
+ expect(against(-20, 400, 1000, 800)).toEqual({ x: -1, y: 0 })
+ expect(against(996, 400, 1000, 800)).toEqual({ x: 0, y: 0 })
+ expect(against(997, 797, 1000, 800)).toEqual({ x: 1, y: 1 })
+ expect(against(500, 900, 1000, 800)).toEqual({ x: 0, y: 1 })
+})
+
+test("held against an edge, it takes the view after 700 milliseconds, then again once the view arrived", () => {
const travels: Direction[] = []
- const settled: (Direction | null)[] = []
- const hold = new EdgeHold(direction => { travels.push(direction); return 300 }, { onSettled: value => settled.push(value) })
+ const hold = new EdgeHold(direction => { travels.push(direction); return 300 })
hold.update(right)
- vi.advanceTimersByTime(299)
- expect(settled).toEqual([])
-
- vi.advanceTimersByTime(1)
- expect(settled).toEqual([right])
- expect(hold.settled).toEqual(right)
-
vi.advanceTimersByTime(699)
expect(travels).toEqual([])
vi.advanceTimersByTime(1)
expect(travels).toEqual([right])
- // Once the view arrived, another after a half second.
+ // The view takes 300 milliseconds, then a half second passes.
vi.advanceTimersByTime(800)
expect(travels).toEqual([right, right])
})
-test("a hand that leaves before 300 milliseconds neither settles nor takes the view", () => {
+test("a hand that leaves the edge before 700 milliseconds does not take the view", () => {
const travel = vi.fn(() => 300)
- const onSettled = vi.fn()
- const hold = new EdgeHold(travel, { onSettled })
+ const hold = new EdgeHold(travel)
hold.update(right)
- vi.advanceTimersByTime(250)
+ vi.advanceTimersByTime(500)
hold.update(away)
vi.advanceTimersByTime(5000)
- expect(onSettled).not.toHaveBeenCalled()
expect(travel).not.toHaveBeenCalled()
- expect(hold.settled).toBeNull()
-})
-
-test("once settled, another edge settles at once and waits 700 milliseconds to take the view", () => {
- const travels: Direction[] = []
- const settled: (Direction | null)[] = []
- const hold = new EdgeHold(direction => { travels.push(direction); return 300 }, { onSettled: value => settled.push(value) })
-
- hold.update(right)
- vi.advanceTimersByTime(300)
- hold.update(corner)
- expect(settled).toEqual([right, corner])
-
- vi.advanceTimersByTime(700)
- expect(travels).toEqual([corner])
-
- hold.update(away)
- expect(settled).toEqual([right, corner, null])
-})
-
-test("a hold that only travels, as the Map's, takes the view after 700 milliseconds", () => {
- const travel = vi.fn(() => 300)
- const hold = new EdgeHold(travel)
-
- hold.update(right)
- vi.advanceTimersByTime(700)
-
- expect(travel).toHaveBeenCalledWith(right)
- expect(hold.settled).toBeNull()
})
test("where the plane goes no further, it says so until the hand leaves", () => {
const blocked: boolean[] = []
- const hold = new EdgeHold(() => null, { onBlocked: value => blocked.push(value) })
+ const hold = new EdgeHold(() => null, value => blocked.push(value))
hold.update(right)
vi.advanceTimersByTime(700)
diff --git a/tests/window-bearings.test.ts b/tests/window-bearings.test.ts
new file mode 100644
index 0000000..6c85e6f
--- /dev/null
+++ b/tests/window-bearings.test.ts
@@ -0,0 +1,40 @@
+import { bearingsOf } from "@client/view/structure/desktop/layers/shell/taskbar/map/window-bearings"
+import type { MappedWindow } from "@client/view/structure/desktop/layers/shell/taskbar/map/map-control"
+import type { Viewport } from "@client/view/structure/desktop/viewport-offset"
+import { expect, test } from "vitest"
+
+// A 1000 by 800 screen showing the middle view; a mark's middle stays 44 pixels inside each edge.
+const viewport = { size: { width: 1000, height: 800 }, offset: { x: 0, y: 0 } } as unknown as Viewport
+const margins = { top: 0, right: 0, bottom: 0, left: 0 }
+const size = { card: 20, arrow: 10, inset: 20, gap: 4 }
+
+function window(identity: string, x: number, y: number, minimized = false) {
+ return { identity, icon: "", focused: false, minimized, region: { x, y, width: 200, height: 100 } } as unknown as MappedWindow
+}
+
+test("a Window in the next view to the right shows on the right edge, level with it, pointing right", () => {
+ const [bearing] = bearingsOf([window("w", 900, -50)], viewport, margins, size)
+ expect(bearing).toMatchObject({ edge: "right", x: 956, y: 400, angle: 0 })
+})
+
+test("a Window up and to the left shows on the edge its direction crosses first", () => {
+ const [bearing] = bearingsOf([window("w", -2100, -1050)], viewport, margins, size)
+ expect(bearing.edge).toBe("left")
+ expect(bearing.x).toBe(44)
+ expect(bearing.y).toBeLessThan(400)
+ expect(bearing.angle).toBeLessThan(-90)
+})
+
+test("a Window with any part in view, or minimized, shows no mark", () => {
+ expect(bearingsOf([window("in", 450, -50), window("hidden", 2000, 0, true)], viewport, margins, size)).toEqual([])
+})
+
+test("marks that would cover each other stand side by side along their edge, inside it", () => {
+ const bearings = bearingsOf([window("one", 1500, -50), window("two", 1600, -50), window("three", 1700, -50)], viewport, margins, size)
+ const ys = bearings.map(bearing => bearing.y).sort((one, other) => one - other)
+ expect(bearings.every(bearing => bearing.edge === "right" && bearing.x === 956)).toBe(true)
+ expect(ys[1] - ys[0]).toBeGreaterThanOrEqual(24)
+ expect(ys[2] - ys[1]).toBeGreaterThanOrEqual(24)
+ expect(ys[0]).toBeGreaterThanOrEqual(44)
+ expect(ys[2]).toBeLessThanOrEqual(756)
+})