Screens answers a list that cannot be empty and has one primary - #114
Merged
Merged
Conversation
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>
This was referenced Sep 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Screensreturned[]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:
liveDisplaysanswered(nil, nil)when the window server counted zero.go-xrkit/desklooks its display up by name, found none, and quit — twice on 2026-09-08, on a headset somebody was wearing: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
primaryFirstwalked 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.newScreenListis the only way a populated one comes into being, and it is where both rules live.ErrNoScreensis deliberately notErrScreensUnsupported: 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.ByNameis 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'slen(screens) == 0on both Linux and Windows, and itsscreens[0], which isPrimary()said properly. The platform messages that name a reason are kept and wrapped aroundErrNoScreens, 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 acrossgo-xrkit/deskandgo-xrkit/player, updated in follow-ups.Proved by sabotage: with the empty check disabled, the new test names both cases.
🤖 Generated with Claude Code