Skip to content

Screens answers a list that cannot be empty and has one primary - #114

Merged
tannevaled merged 1 commit into
mainfrom
a-display-list-that-cannot-be-empty
Sep 8, 2026
Merged

tannevaled merged 1 commit into
mainfrom
a-display-list-that-cannot-be-empty

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Screens returned []Screen, so two rules lived as conventions rather than as the type — and one of them cost somebody their desk.

Never empty

Nothing stopped an empty slice arriving, and the darwin back-end sent one: liveDisplays answered (nil, nil) when the window server counted zero. go-xrkit/desk looks its display up by name, found none, and quit — twice on 2026-09-08, on a headset somebody was wearing:

desk: "VITURE Beast" is not attached any more; there is  -- stopping

Nothing after there is: the message names every attached display, and it named none. Three of the four back-ends already refused to say it; the fourth was the one that shipped.

Exactly one primary, first

primaryFirst walked the slice unsetting duplicate flags — "only one may claim it" — and every caller that wanted the main display then scanned for the flag again. It is a property of the list, not something to go looking for.

type ScreenList struct{ all []Screen }

func (l ScreenList) Primary() Screen
func (l ScreenList) All() []Screen
func (l ScreenList) Len() int
func (l ScreenList) ByName(string) (Screen, bool)

newScreenList is the only way a populated one comes into being, and it is where both rules live.

ErrNoScreens is deliberately not ErrScreensUnsupported: that one means this build cannot enumerate at all, which no retry will change; this one means the enumeration ran and came back empty, which a second later may not.

ByName is here because every caller wrote it — looking a display up by name is what survives the desktop being rearranged, and three separate loops were doing it.

What goes away

Two hand-written guards: VisibleScreenSize's len(screens) == 0 on both Linux and Windows, and its screens[0], which is Primary() said properly. The platform messages that name a reason are kept and wrapped around ErrNoScreens, so a caller can test one sentinel without losing "the Wayland compositor advertises no output".

Callers

The back-end tests are about the geometry a protocol reports rather than about the list, so they take a one-word adapter (allOf) and are otherwise unchanged. Downstream: 9 non-test call sites across go-xrkit/desk and go-xrkit/player, updated in follow-ups.

Proved by sabotage: with the empty check disabled, the new test names both cases.

🤖 Generated with Claude Code

Screens returned []Screen, so two rules lived as conventions rather than as
the type, and one of them cost somebody their desk.

NEVER EMPTY. Nothing stopped an empty slice arriving, and the darwin
back-end sent one: liveDisplays answered (nil, nil) when the window server
counted zero, which is a failed read wearing the clothes of a fact.
go-xrkit/desk looks its display up by name, found none, and quit -- twice on
2026-09-08, on a headset somebody was wearing:

  desk: "VITURE Beast" is not attached any more; there is  -- stopping

Nothing after "there is": the message names every attached display, and it
named NONE. Three of the four back-ends already refused to say it; the
fourth was the one that shipped.

EXACTLY ONE PRIMARY, FIRST. primaryFirst walked the slice unsetting
duplicate flags -- "only one may claim it" -- and every caller that wanted
the main display then scanned for the flag again. It is a property of the
list, not something to go looking for.

    type ScreenList struct{ all []Screen }
    func (l ScreenList) Primary() Screen
    func (l ScreenList) All() []Screen
    func (l ScreenList) Len() int
    func (l ScreenList) ByName(string) (Screen, bool)

newScreenList is the only way a populated one comes into being, and it is
where both rules live. ErrNoScreens is deliberately NOT
ErrScreensUnsupported: that one means this build cannot enumerate at all,
which no retry will change; this one means the enumeration ran and came back
empty, which a second later may not.

ByName is here because every caller wrote it: looking a display up by name
is what survives the desktop being rearranged, and three separate loops were
doing it.

Two hand-written guards go away with it -- VisibleScreenSize's
"len(screens) == 0" on both Linux and Windows, and its screens[0], which is
Primary() said properly. The platform messages that name a REASON are kept
and wrapped around ErrNoScreens, so a caller can test one sentinel without
losing "the Wayland compositor advertises no output".

The back-end tests are about the geometry a protocol reports rather than
about the list, so they take a one-word adapter (allOf) and are otherwise
unchanged.

Proved by sabotage: with the empty check disabled the new test names both
cases.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit fe9b259 into main Sep 8, 2026
28 checks passed
@tannevaled
tannevaled deleted the a-display-list-that-cannot-be-empty branch September 8, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant