screen

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT, MIT Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package screen is the login screen: one screen the greeter shows before login and the lock screen shows over a locked session, built by the same code (Build) and styled by the same lock.css rules, so the two look and behave alike. A Mode adds only what genuinely differs: the greeter's user list, username entry, session picker and power buttons.

The layout is the macOS lock screen's: the date over a large clock at the top, and at the bottom the account being asked for, the password pill under it, the caps lock warning and the error line, and under all of it the greeter's power buttons. A chip in the top right corner shows the keyboard layout when there are several.

Index

Constants

View Source
const AvatarPx = 80

AvatarPx is the side of an account's round picture.

Variables

This section is empty.

Functions

func AvatarPicture

func AvatarPicture(load func(path string) (image.Image, error), path string, scale int) image.Image

AvatarPicture is the image at path decoded by load and cut to what a tile shows on an output of the given buffer scale, nil when there is none or it does not read: a photo would keep megabytes for a small circle otherwise.

func Background

func Background(bg *Backdrop, color render.Color) widget.Widget

Background builds the surface background (build_background): the backdrop scaled to cover under the .lock-bg-scrim legibility layer, or the configured color painted by a .lock-bg area when there is no backdrop.

func Cover

func Cover(s Spec) widget.Widget

func HexFill

func HexFill(c config.HexColor) render.Color

HexFill converts a config color to a premultiplied fill.

func Icons

func Icons() []string

Icons are the theme icons the prompt draws.

func MaxScale

func MaxScale(outputs []*app.Output) int

MaxScale is the largest buffer scale of outputs, 1 without any.

func RefusalText

func RefusalText(r auth.Refusal) string

RefusalText words a refused login for the person logging in.

func Scrim

func Scrim() *widget.Box

Scrim is the blank-screen blackout (.lock-scrim), hidden until the blank timer shows it.

func SquareThumbnail

func SquareThumbnail(src image.Image, px int) image.Image

SquareThumbnail is src's middle square area-resampled to px on a side, for a picture only ever drawn that small and cropped to cover: the source's pixels are not kept. A source no larger on either side comes back as it is.

func Window

func Window(sheet *widget.Stylesheet, layers ...widget.Widget) widget.Widget

Window is a lock or greeter surface's root (the node the .lock-window rules select), styled by sheet, holding the layers bottom to top.

Types

type AccountTile

type AccountTile struct {
	Root *widget.Box
	// contains filtered or unexported fields
}

AccountTile is one account as the login screen shows it: the round picture above the name, the picture the initials until one is set.

func NewAccountTile

func NewAccountTile(font render.Font, displayName string) *AccountTile

NewAccountTile is the tile of the account called displayName.

func (*AccountTile) Initials

func (a *AccountTile) Initials() string

Initials are what the picture shows without an image.

func (*AccountTile) SetPicture

func (a *AccountTile) SetPicture(img image.Image)

SetPicture shows img as the account's picture.

type Backdrop

type Backdrop struct {
	Image render.StillImage
	// contains filtered or unexported fields
}

Backdrop is a background image at the size it is shown at, blurred, with its pixels off the Go heap. Image keeps its identity for as long as the pixels live, so a GPU renderer's texture of it can be dropped by ID before the pixels are freed.

func LoadBackdrop

func LoadBackdrop(mem *memory.Shared, decode func(mem *memory.Shared, path string) (imagedecode.Decoded, error), path string, sigma float64, outputs []image.Point) (*Backdrop, error)

LoadBackdrop decodes the background at path into mem and makes it a backdrop for outputs, as NewBackdrop does; the decoded image is freed before it returns.

func NewBackdrop

func NewBackdrop(mem *memory.Shared, src image.Image, sigma float64, outputs []image.Point) (Backdrop, error)

NewBackdrop resamples src to the smallest size that still covers every one of outputs (device pixel sizes) and blurs it with a gaussian of standard deviation sigma in src's pixels, scaled with the image so the result looks as blurring src itself would. A src already no larger than that keeps its size: it is blurred as it is and scaled up where it is drawn. The pixels and the blur's scratch raster live in mem; the scratch is freed before it returns.

func (Backdrop) Free

func (b Backdrop) Free() error

Free frees the backdrop's pixels; nothing may draw them any more.

func (Backdrop) Retire

func (b Backdrop) Retire(forget func(render.ImageID), who string)

Retire lets go of the backdrop once no surface draws it: forget drops the renderer's texture now, and the pixels are freed once every List recorded until now has ended, so no frame still being played reads freed memory. A failed free is logged under who.

type ClockTicker

type ClockTicker struct {
	// contains filtered or unexported fields
}

ClockTicker shows a clock when what its formats show changes, and not in between: a clock of hours and minutes wakes the loop once a minute. Its timer runs on the wall clock, so what it shows is right the moment the machine resumes, the clock is set or the zone changes.

func NewClockTicker

func NewClockTicker(wall WallClock, show func(), formats ...func(time.Time) string) *ClockTicker

NewClockTicker makes a stopped ticker that calls show on the loop whenever one of formats would give something new. With no formats nothing shows a clock, so it never arms.

func (*ClockTicker) Arm

func (c *ClockTicker) Arm()

Arm keeps a clock shown just now right until Stop.

func (*ClockTicker) Start

func (c *ClockTicker) Start()

Start shows the clock and keeps it right until Stop.

func (*ClockTicker) Stop

func (c *ClockTicker) Stop()

Stop lets the clock go stale until the next Start.

type Fingerprint

type Fingerprint struct {
	Text       string
	OnPassword func()
}

Fingerprint is the lock screen's fingerprint prompt, shown in place of the password entry while the reader listens: Text beside the glyph, and OnPassword, run when the person clicks it or types, before the typed character reaches the password entry.

type FingerprintPrompt

type FingerprintPrompt struct {
	*widget.Button
	// contains filtered or unexported fields
}

FingerprintPrompt is the built fingerprint prompt. It takes keyboard focus while shown, so the first character typed switches to the password entry and lands in it.

func (*FingerprintPrompt) InsertRune

func (f *FingerprintPrompt) InsertRune(r rune)

InsertRune hands r to the password entry once OnPassword has run.

type GreeterRows

type GreeterRows struct {
	Session, Power widget.Widget
}

GreeterRows are the rows only the greeter shows: the session picker under the entries and the power buttons at the bottom of the screen. Either may be nil.

type KeyboardLayouts

type KeyboardLayouts struct {
	// contains filtered or unexported fields
}

func NewKeyboardLayouts

func NewKeyboardLayouts(d LayoutDeps) *KeyboardLayouts

func (*KeyboardLayouts) Active

func (k *KeyboardLayouts) Active() string

func (*KeyboardLayouts) CanSwitch

func (k *KeyboardLayouts) CanSwitch() bool

func (*KeyboardLayouts) Cycle

func (k *KeyboardLayouts) Cycle()

func (*KeyboardLayouts) Set

func (*KeyboardLayouts) ShowOn

func (k *KeyboardLayouts) ShowOn(p *Prompt)

func (*KeyboardLayouts) Want

func (k *KeyboardLayouts) Want(name string)

type LayoutDeps

type LayoutDeps struct {
	Invoke func(func())
	Label  func(names []string) ([]layouts.Layout, error)
	Next   func(steps int)
	Show   func(labeled []layouts.Layout, active uint32)
	Mode   string
}

type LockRows

type LockRows struct {
	Status, Corner, Footer widget.Widget
	Fingerprint            *Fingerprint
}

type Mode

type Mode int

Mode is the situation the login screen is shown in.

const (
	Greeter Mode = iota
	Lock
)

The modes: the greeter before login, and the lock over a session.

type Options

type Options struct {
	// Font is the face the labels and entries shape with; the
	// stylesheet sets their sizes and weights.
	Font render.Font
	// ShowClock shows the clock and date.
	ShowClock bool
	// WithUsername adds a visible username entry above the secret one
	// (the greeter; the lock screen authenticates the session user).
	WithUsername bool
	// Identity goes above the entries: the lock screen's account, the
	// greeter's user list. Extra goes between the caps lock warning and
	// the error line (the greeter's session picker), Footer at the
	// bottom of the screen under all of it (the greeter's power
	// buttons). Any may be nil.
	Identity, Extra, Footer widget.Widget
	Status, Corner          widget.Widget
	// Password is the secret entry's placeholder, CapsLock the caps
	// lock warning's text.
	Password, CapsLock string
	// Focus moves keyboard focus; the username entry's Enter uses it
	// to move on to the secret entry.
	Focus      func(widget.Widget)
	NextLayout func()
	// Fingerprint adds the fingerprint prompt; nil leaves it out.
	Fingerprint *Fingerprint
}

Options configure one prompt.

type Prompt

type Prompt struct {
	// Reveal is the root: everything over the background, hidden until
	// the screen shows it (CredentialBox::reveal).
	Reveal *widget.Revealer
	// Username is the visible username entry; nil without
	// WithUsername.
	Username *widget.Entry
	// Entry is the secret entry; Enter submits it.
	Entry *widget.Entry
	// Fingerprint stands in for Entry while SetFingerprint shows it; nil
	// without Options.Fingerprint.
	Fingerprint *FingerprintPrompt
	// Clock and Date are hidden without ShowClock.
	Clock, Date *widget.Label
	// Caps is the caps lock warning, hidden until SetCapsLock shows it.
	Caps *widget.Label
	// Error is the error and info line, hidden until it has text.
	Error  *widget.Label
	Layout *widget.Button
	// contains filtered or unexported fields
}

Prompt is a built credential prompt and the handles its screen drives.

func (*Prompt) FocusTarget

func (p *Prompt) FocusTarget() widget.Widget

FocusTarget is what keyboard focus belongs on: the fingerprint prompt while it shows, else the password entry.

func (*Prompt) PreloadIcons

func (p *Prompt) PreloadIcons(num, denom int) error

func (*Prompt) SetCapsLock

func (p *Prompt) SetCapsLock(on bool)

SetCapsLock shows or hides the caps lock warning.

func (*Prompt) SetFingerprint

func (p *Prompt) SetFingerprint(on bool)

SetFingerprint shows the fingerprint prompt in place of the password entry, or the entry again; a prompt without one keeps its entry.

func (*Prompt) SetLayouts

func (p *Prompt) SetLayouts(all []layouts.Layout, active uint32)

func (*Prompt) SetMessage

func (p *Prompt) SetMessage(text string)

SetMessage shows text on the error line, or hides it when empty.

type Spec

type Spec struct {
	Mode   Mode
	Config config.LoginConfig
	Font   render.Font
	Sheet  *widget.Stylesheet
	// Backdrop is the background image, nil for the color fill.
	Backdrop *Backdrop
	// Identity is who the screen asks for, above the entries: the lock
	// screen's account, the greeter's user list. nil for none.
	Identity widget.Widget
	// Greeter holds the greeter's own rows; Build reads it in greeter
	// mode only.
	Greeter GreeterRows
	Lock    LockRows
	// Password is the password entry's placeholder and CapsLock the caps
	// lock warning's text, in the mode's locale.
	Password, CapsLock string
	// Focus moves keyboard focus.
	Focus func(widget.Widget)
	// OnSubmit receives the secret entry's text on Enter.
	OnSubmit   func(string)
	NextLayout func()
}

Spec is one login screen surface.

type Surface

type Surface struct {
	Root   widget.Widget
	Prompt *Prompt
	// Scrim is the blank-screen blackout over everything.
	Scrim *widget.Box
}

Surface is a built login screen and the handles its mode drives.

func Build

func Build(s Spec) *Surface

Build assembles a login screen: the background, the clock, the account asked for and the credential prompt with the caps lock warning, and the blank scrim, the same in every mode; the greeter adds its username entry and its rows.

type SystemClock

type SystemClock struct {
	// contains filtered or unexported fields
}

SystemClock is the WallClock of this machine. An absolute timer on CLOCK_REALTIME fires on the wall clock's time however long the machine slept, and TFD_TIMER_CANCEL_ON_SET fails its read the moment the clock is set; a watch on /etc/localtime reloads the zone, which the runtime only reads once.

func NewSystemClock

func NewSystemClock(invoke func(func())) (*SystemClock, error)

NewSystemClock starts a clock that runs what is armed through invoke, on the loop.

func (*SystemClock) Arm

func (c *SystemClock) Arm(at time.Time, fn func())

Arm runs fn on the loop at at, or when the clock or the zone jumps.

func (*SystemClock) Close

func (c *SystemClock) Close() error

Close stops the clock; nothing armed runs after it.

func (*SystemClock) Disarm

func (c *SystemClock) Disarm()

Disarm forgets what was armed.

func (*SystemClock) Now

func (c *SystemClock) Now() time.Time

Now is the time in the current zone.

type WallClock

type WallClock interface {
	// Now is the time in the current zone.
	Now() time.Time
	// Arm runs fn on the loop when the wall clock reaches at, or at once when it
	// or the zone jumps, replacing what was armed.
	Arm(at time.Time, fn func())
	// Disarm forgets what was armed; a firing on its way finds nothing.
	Disarm()
}

WallClock is the time a clock on screen shows, which unlike the timers of the runtime is what the user reads off their wall: it moves on through a suspend, and jumps when NTP or an administrator sets it or the time zone changes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL