window

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 19 Imported by: 1 module, 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 window owns the application's OS windows: the window registry, per-window frontend state slots, cross-window tab drag coordination and session persistence. The frontend reaches it through the bound Service.

Index

Constants

View Source
const (
	EventWindowsChanged = "windows/changed"
	EventSettingsState  = "settings/state"
	EventWindowClosed   = "windows/closed"
	EventDragBegin      = "windows/drag/begin"
	EventDragHover      = "windows/drag/hover"
	EventDragLeave      = "windows/drag/leave"
	EventDragDrop       = "windows/drag/drop"
	EventDragEnd        = "windows/drag/end"
)

Event names emitted by the service. Every payload either carries a target window name or is meant for all windows.

View Source
const MainWindowName = "main"

MainWindowName is the name of the first application window. It always exists, hides instead of closing, and is never torn down by the service.

View Source
const SessionFileName = "windows.json"

SessionFileName is the session file name inside the state root.

View Source
const SettingsWindowName = "settings"

SettingsWindowName identifies the single, non-restorable settings window.

Variables

View Source
var (
	ErrUnknownWindow      = errors.New("unknown window")
	ErrInvalidKind        = errors.New("invalid window kind")
	ErrMainWindowClose    = errors.New("the main window cannot be closed")
	ErrInvalidState       = errors.New("invalid window state")
	ErrInvalidDrag        = errors.New("invalid drag session")
	ErrUnknownDragSession = errors.New("unknown drag session")
	// ErrUnknownGeometry means a window has no native bounds or reported
	// viewport yet, so client coordinates cannot be mapped to the screen.
	ErrUnknownGeometry = errors.New("window geometry unknown")
)

Errors returned by the service.

Functions

This section is empty.

Types

type Bounds added in v0.10.0

type Bounds struct {
	X      int `json:"x"`
	Y      int `json:"y"`
	Width  int `json:"width"`
	Height int `json:"height"`
}

Bounds is a window's OS frame in screen DIP.

type DragBegin added in v0.10.0

type DragBegin struct {
	SessionID    string `json:"sessionId"`
	SourceWindow string `json:"sourceWindow"`
	DragType     string `json:"dragType"`
	// Payload is the JSON of the base-ui TabDragPayload; it is forwarded to
	// target windows verbatim.
	Payload string `json:"payload"`
}

DragBegin starts a cross-window tab drag session.

type DragBeginEvent added in v0.10.0

type DragBeginEvent struct {
	SessionID    string `json:"sessionId"`
	SourceWindow string `json:"sourceWindow"`
	DragType     string `json:"dragType"`
}

DragBeginEvent is the payload of EventDragBegin; every window reports a fresh viewport in response.

type DragEndEvent added in v0.10.0

type DragEndEvent struct {
	SessionID string `json:"sessionId"`
}

DragEndEvent is the payload of EventDragEnd; all windows clear remote drag state for the session.

type DragLeaveEvent added in v0.10.0

type DragLeaveEvent struct {
	SessionID    string `json:"sessionId"`
	TargetWindow string `json:"targetWindow"`
}

DragLeaveEvent is the payload of EventDragLeave.

type DragPointerEvent added in v0.10.0

type DragPointerEvent struct {
	SessionID    string `json:"sessionId"`
	TargetWindow string `json:"targetWindow"`
	// Payload is DragBegin.Payload verbatim (JSON of TabDragPayload).
	Payload string  `json:"payload"`
	ClientX float64 `json:"clientX"`
	ClientY float64 `json:"clientY"`
}

DragPointerEvent is the payload of EventDragHover and EventDragDrop. The pointer is in the target window's client space.

type DropResult added in v0.10.0

type DropResult struct {
	Accepted         bool   `json:"accepted"`
	TargetWindow     string `json:"targetWindow"`
	TargetInstanceID string `json:"targetInstanceId"`
}

DropResult is the outcome of EndDrag.

type Info added in v0.10.0

type Info struct {
	Name string `json:"name"`
	Kind Kind   `json:"kind"`
	// Focused is true for the most recently focused window.
	Focused bool `json:"focused"`
}

Info describes one live window.

type Kind added in v0.10.0

type Kind string

Kind selects which shell a window renders.

const (
	// KindWorkspace renders the full shell (header, rail, page tabs, panes,
	// bottom drawer, footer).
	KindWorkspace Kind = "workspace"
	// KindPanel renders only a drawer tab strip and the drawer tab content.
	KindPanel Kind = "panel"
	// KindSettings renders the compact settings shell.
	KindSettings Kind = "settings"
)

type OpenRequest added in v0.10.0

type OpenRequest struct {
	Kind Kind `json:"kind"`
	// InitialState is the opaque per-slot state handed to the new window
	// before it loads (same format as SaveState slots).
	InitialState map[string]string `json:"initialState"`
	// When HasPosition is set the new window's top-left is placed near the
	// pointer at (ClientX, ClientY) in AnchorWindow's client space.
	AnchorWindow string  `json:"anchorWindow"`
	ClientX      float64 `json:"clientX"`
	ClientY      float64 `json:"clientY"`
	HasPosition  bool    `json:"hasPosition"`
	// Width and Height of the new window; 0 selects the kind's default.
	Width  int `json:"width"`
	Height int `json:"height"`
}

OpenRequest describes a window to open.

type Service added in v0.10.0

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

Service is the bound window service: registry, per-window state slots, cross-window drag coordination and session persistence.

func NewService added in v0.10.0

func NewService(
	app *application.App,
	mainWindow *application.WebviewWindow,
	options ServiceOptions,
) *Service

NewService creates the window service around the existing main window: main hides instead of closing, the persisted session is loaded and its non-main windows are recreated. Register the result with app.RegisterService so it is bound and flushed on shutdown.

func (*Service) BeginDrag added in v0.10.0

func (s *Service) BeginDrag(b DragBegin) error

BeginDrag starts a cross-window drag owned by the source window, refreshes every window's native bounds and asks every window to report a fresh viewport.

func (*Service) CancelDrag added in v0.10.0

func (s *Service) CancelDrag(sessionID string)

CancelDrag ends a session without a drop. Unknown sessions are ignored.

func (*Service) Close added in v0.10.0

func (s *Service) Close(name string) error

Close closes a non-main window. Its state is removed and windows/closed is emitted once the OS window has closed.

func (*Service) EndDrag added in v0.10.0

func (s *Service) EndDrag(ctx context.Context, sessionID string, clientX, clientY float64) (DropResult, error)

EndDrag drops the tab on the window under the pointer (given in the source window's client space) and waits for that window's RespondDrop. It returns a not-accepted result when no other window is under the pointer, the target declines, closes, or does not answer in time. The session always ends with windows/drag/end.

func (*Service) Focus added in v0.10.0

func (s *Service) Focus(name string) error

Focus shows, restores and focuses the named window.

func (*Service) GetSettingsState added in v0.16.0

func (s *Service) GetSettingsState() SettingsState

GetSettingsState returns the current routing request and native visibility.

func (*Service) GetState added in v0.10.0

func (s *Service) GetState(name string) (map[string]string, error)

GetState returns the named window's slots (slot -> JSON). A window calls it once its frontend has loaded, which also releases the next queued restore.

func (*Service) HideSettings added in v0.16.0

func (s *Service) HideSettings() error

HideSettings keeps the native window and its frontend drafts alive.

func (*Service) List added in v0.10.0

func (s *Service) List() []Info

List returns the live windows in creation order.

func (*Service) ListStates added in v0.10.0

func (s *Service) ListStates() map[string]map[string]string

ListStates returns every live window's slots (window -> slot -> JSON).

func (*Service) MoveDrag added in v0.10.0

func (s *Service) MoveDrag(sessionID string, clientX, clientY float64)

MoveDrag routes the pointer, given in the source window's client space, to the window under it: the previous target gets a leave event, the current target a hover event. Moves for unknown or ending sessions are ignored; they race with EndDrag/CancelDrag by design.

func (*Service) MoveToPointer added in v0.10.0

func (s *Service) MoveToPointer(name string, clientX, clientY float64) error

MoveToPointer places the named window like a torn-off tab: its top-left goes up/left of the pointer, which is given in the window's own client space.

func (*Service) Open added in v0.10.0

func (s *Service) Open(req OpenRequest) (string, error)

Open creates a window of the requested kind and returns its name. The InitialState slots are served by GetState before the window loads.

func (*Service) OpenSettings added in v0.16.0

func (s *Service) OpenSettings(target string) (string, error)

OpenSettings shows the single settings window. Empty targets preserve its location.

func (*Service) ReportViewport added in v0.10.0

func (s *Service) ReportViewport(name string, width, height float64)

ReportViewport records the named window's webview viewport size in CSS px. Together with the native bounds it locates the window's content on screen for drag hit-testing. Reports from unknown windows (for example a window that just closed) are ignored.

func (*Service) RespondDrop added in v0.10.0

func (s *Service) RespondDrop(sessionID string, accepted bool, targetInstanceID string)

RespondDrop delivers the drop target's answer to the waiting EndDrag. Answers for unknown sessions, sessions not waiting on a drop, and duplicate answers are ignored.

func (*Service) SaveState added in v0.10.0

func (s *Service) SaveState(name, slot, stateJSON string) error

SaveState stores one slot of the named window and schedules persistence.

func (*Service) ServiceShutdown added in v0.10.0

func (s *Service) ServiceShutdown() error

ServiceShutdown flushes the session. Windows closed by the application teardown afterwards keep their persisted state.

func (*Service) SetSettingsLocation added in v0.16.0

func (s *Service) SetSettingsLocation(target string, requestID uint64) error

SetSettingsLocation records only navigation accepted for the current request.

type ServiceOptions added in v0.10.0

type ServiceOptions struct {
	// WindowTemplate carries the options every window shares with the main
	// window (title, background colour, platform options). Name, URL, size,
	// minimum size and initial position are set per window.
	WindowTemplate application.WebviewWindowOptions
	// SessionPath is the session file, normally <stateRoot>/windows.json.
	SessionPath string
	Log         logging.Logger
}

ServiceOptions configures NewService.

type SettingsState added in v0.16.0

type SettingsState struct {
	RequestID uint64 `json:"requestId"`
	Target    string `json:"target"`
	Visible   bool   `json:"visible"`
}

SettingsState is the backend-owned location and visibility of settings.

type WindowClosedEvent added in v0.10.0

type WindowClosedEvent struct {
	Name   string            `json:"name"`
	Kind   Kind              `json:"kind"`
	States map[string]string `json:"states"`
}

WindowClosedEvent is the payload of EventWindowClosed. States holds the closed window's last saved slots (slot -> JSON).

type WindowsChangedEvent added in v0.10.0

type WindowsChangedEvent struct {
	Windows []Info `json:"windows"`
}

WindowsChangedEvent is the payload of EventWindowsChanged.

Jump to

Keyboard shortcuts

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