windowstate

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 8 Imported by: ? 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 windowstate remembers where a window was: its position, size and whether it was maximized, saved as it changes and restored the next time the app starts.

s, _ := app.NewSurface(tango.SurfaceOptions{Hidden: true, Resizable: true})
windowstate.Track(s, "main", nil) // nil: <UserConfigDir>/<App.ID>/windows.json
s.Show()

Track before showing the window so it does not jump. A saved position that is no longer on any display (a monitor was unplugged) is not restored; the window keeps its size and is centered instead.

Index

Constants

This section is empty.

Variables

View Source
var SaveDelay = 400 * time.Millisecond

SaveDelay is how long Track waits after the last change before saving.

Functions

func DefaultPath

func DefaultPath(appID string) (string, error)

DefaultPath returns <os.UserConfigDir>/<appID>/windows.json. An empty appID uses the executable's name.

func Track

func Track(s *tango.Surface, key string, store Store) error

Track restores s from store under key, then saves its state whenever it is moved, resized, maximized or restored, and when it closes or the app terminates. A nil store is the shared file at DefaultPath(app ID). It returns tango.ErrUnsupported when the platform cannot place windows.

Types

type FileStore

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

FileStore is a Store backed by one JSON file holding every key.

func NewFileStore

func NewFileStore(path string) *FileStore

NewFileStore returns the store for the JSON file at path. Stores for the same path are shared, so windows tracked separately do not overwrite each other's entries.

func (*FileStore) Load

func (fs *FileStore) Load(key string) (State, bool)

func (*FileStore) Path

func (fs *FileStore) Path() string

Path returns the file's path.

func (*FileStore) Save

func (fs *FileStore) Save(key string, st State) error

Save records st under key and rewrites the file atomically.

type State

type State struct {
	X         int  `json:"x"`
	Y         int  `json:"y"`
	Width     int  `json:"width"`
	Height    int  `json:"height"`
	Maximized bool `json:"maximized,omitempty"`
}

State is what is remembered of one window. X, Y, Width, Height are the normal (not maximized) bounds, as tango.Surface.Bounds returns them.

type Store

type Store interface {
	Load(key string) (State, bool)
	Save(key string, st State) error
}

Store keeps states by key. Implementations must be safe for concurrent use.

Jump to

Keyboard shortcuts

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