Files
coucou/tests/IslandDisplayChoiceTests.swift
Steeven 4c4831d732 Choose which screen Mochi lives on
Settings → General → Display: the screen with the notch (default, unchanged
behaviour), the main screen with the menu bar, a specific screen by name, or
Follow the mouse.

- IslandDisplayChoice.swift (new): pure choice + resolver, tested by
  scripts/test-display-choice.sh. A chosen screen is stored by its display
  UUID and falls back to the notch screen while it is disconnected.
- IslandWindowController: relocate(to:) recomputes the resting geometry
  (notch or bar) and moves the panel. Follow the mouse runs in the existing
  60 Hz loop and only moves a hidden or compact island, never an open one.
  The island now follows screen changes (plug, unplug, lid, resolution).
- Settings window and desktop Mochi flights target the island's screen.
- BotCanvasView: eye tracking used the global midX of NSScreen.main against
  a screen-local mouse position, so Mochi looked off on an external screen.
- docs/SPEC.md, README.md, CONTRIBUTING.md updated.
2026-10-05 14:07:28 +02:00

43 lines
2.2 KiB
Swift

import Foundation
@main
enum IslandDisplayChoiceTests {
static func main() {
// Storage round-trip, unknown values fall back to the notch default.
for choice: IslandDisplayChoice in [.notch, .menuBar, .followMouse, .display(uuid: "ABC-123")] {
precondition(IslandDisplayChoice(storageValue: choice.storageValue) == choice)
}
precondition(IslandDisplayChoice(storageValue: "") == .notch)
precondition(IslandDisplayChoice(storageValue: "garbage") == .notch)
precondition(IslandDisplayChoice(storageValue: "display:") == .notch)
// External screen holds the menu bar, MacBook (with notch) is second, mouse on the third.
let screens = [
IslandDisplayCandidate(uuid: "EXT-1", hasNotch: false, containsMouse: false),
IslandDisplayCandidate(uuid: "MBP", hasNotch: true, containsMouse: false),
IslandDisplayCandidate(uuid: "EXT-2", hasNotch: false, containsMouse: true),
]
precondition(IslandDisplayResolver.index(for: .notch, in: screens) == 1)
precondition(IslandDisplayResolver.index(for: .menuBar, in: screens) == 0)
precondition(IslandDisplayResolver.index(for: .followMouse, in: screens) == 2)
precondition(IslandDisplayResolver.index(for: .display(uuid: "EXT-2"), in: screens) == 2)
// A disconnected chosen screen falls back to the notch screen.
precondition(IslandDisplayResolver.index(for: .display(uuid: "GONE"), in: screens) == 1)
// No notch anywhere (lid closed): nil means "use the main screen".
let desk = [
IslandDisplayCandidate(uuid: "EXT-1", hasNotch: false, containsMouse: false),
IslandDisplayCandidate(uuid: "EXT-2", hasNotch: false, containsMouse: false),
]
precondition(IslandDisplayResolver.index(for: .notch, in: desk) == nil)
precondition(IslandDisplayResolver.index(for: .display(uuid: "GONE"), in: desk) == nil)
// Mouse between screens (rounding at an edge): keep the default.
precondition(IslandDisplayResolver.index(for: .followMouse, in: desk) == nil)
precondition(IslandDisplayResolver.index(for: .menuBar, in: []) == nil)
print("IslandDisplayChoice tests passed")
}
}