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
- Variables
- type Bounds
- type DragBegin
- type DragBeginEvent
- type DragEndEvent
- type DragLeaveEvent
- type DragPointerEvent
- type DropResult
- type Info
- type Kind
- type OpenRequest
- type Service
- func (s *Service) BeginDrag(b DragBegin) error
- func (s *Service) CancelDrag(sessionID string)
- func (s *Service) Close(name string) error
- func (s *Service) EndDrag(ctx context.Context, sessionID string, clientX, clientY float64) (DropResult, error)
- func (s *Service) Focus(name string) error
- func (s *Service) GetSettingsState() SettingsState
- func (s *Service) GetState(name string) (map[string]string, error)
- func (s *Service) HideSettings() error
- func (s *Service) List() []Info
- func (s *Service) ListStates() map[string]map[string]string
- func (s *Service) MoveDrag(sessionID string, clientX, clientY float64)
- func (s *Service) MoveToPointer(name string, clientX, clientY float64) error
- func (s *Service) Open(req OpenRequest) (string, error)
- func (s *Service) OpenSettings(target string) (string, error)
- func (s *Service) ReportViewport(name string, width, height float64)
- func (s *Service) RespondDrop(sessionID string, accepted bool, targetInstanceID string)
- func (s *Service) SaveState(name, slot, stateJSON string) error
- func (s *Service) ServiceShutdown() error
- func (s *Service) SetSettingsLocation(target string, requestID uint64) error
- type ServiceOptions
- type SettingsState
- type WindowClosedEvent
- type WindowsChangedEvent
Constants ¶
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.
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.
const SessionFileName = "windows.json"
SessionFileName is the session file name inside the state root.
const SettingsWindowName = "settings"
SettingsWindowName identifies the single, non-restorable settings window.
Variables ¶
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
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
CancelDrag ends a session without a drop. Unknown sessions are ignored.
func (*Service) Close ¶ added in v0.10.0
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) 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
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
HideSettings keeps the native window and its frontend drafts alive.
func (*Service) ListStates ¶ added in v0.10.0
ListStates returns every live window's slots (window -> slot -> JSON).
func (*Service) MoveDrag ¶ added in v0.10.0
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
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
OpenSettings shows the single settings window. Empty targets preserve its location.
func (*Service) ReportViewport ¶ added in v0.10.0
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
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
SaveState stores one slot of the named window and schedules persistence.
func (*Service) ServiceShutdown ¶ added in v0.10.0
ServiceShutdown flushes the session. Windows closed by the application teardown afterwards keep their persisted state.
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.