workspace

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTerminalToWorkspace

func AddTerminalToWorkspace(desktop int, agentSlot bool) (int, error)

AddTerminalToWorkspace increments terminal count and optionally adds agent slot. Returns the new slot index. If desktop is -1, auto-detect current desktop.

func CheckCanAddTerminal

func CheckCanAddTerminal(wsName string, currentCount int, cfg *config.Config) error

CheckCanAddTerminal verifies limits allow adding a terminal to an existing workspace.

func CheckCanCreateTerminals

func CheckCanCreateTerminals(wsName string, count int, cfg *config.Config) error

CheckCanCreateTerminals verifies bulk terminal creation is allowed.

func CheckCanCreateWorkspace

func CheckCanCreateWorkspace(cfg *config.Config) error

CheckCanCreateWorkspace verifies limits allow creating a new workspace.

func ClearActiveWorkspace

func ClearActiveWorkspace() error

ClearActiveWorkspace removes the workspace on the current desktop. This is a convenience wrapper for ClearWorkspace(-1).

func ClearSlotsByDesktop

func ClearSlotsByDesktop(desktop int) error

ClearSlotsByDesktop removes all slot entries for a specific desktop.

func ClearWorkspace

func ClearWorkspace(desktop int) error

ClearWorkspace removes the workspace on a specific desktop. If desktop is -1, clear workspace on current desktop.

func CloseTerminals

func CloseTerminals(lister TerminalLister) error

CloseTerminals closes all terminal windows by sending SIGKILL to their processes. This ensures a clean close without "are you sure" prompts from terminals. For agent-mode workspaces using tmux, the tmux sessions survive the terminal close.

func ConfigPath

func ConfigPath(name string) string

ConfigPath returns the path to a workspace config file.

func Delete

func Delete(name string) error

func GetAllSlots

func GetAllSlots() (map[uint32]SlotInfo, error)

GetAllSlots returns all tracked slots.

func GetAllWorkspaces

func GetAllWorkspaces() (map[int]WorkspaceInfo, error)

GetAllWorkspaces returns all registered workspaces keyed by desktop number.

func HasSessionInRegistry

func HasSessionInRegistry(sessionName string) bool

HasSessionInRegistry checks if a session name exists in the registry.

func HasUnsavedChanges

func HasUnsavedChanges(workspaceName string) bool

HasUnsavedChanges checks if the current terminal state differs from the saved workspace. This compares the terminal count - if different, there are unsaved changes.

func InsertTerminalAtSlot

func InsertTerminalAtSlot(desktop int, insertSlot int, agentSlot bool) error

InsertTerminalAtSlot inserts a terminal at a specific slot position, shifting existing slots up. If agentSlot is true, the new slot is added to AgentSlots. Returns error if slot is out of range. If desktop is -1, auto-detect current desktop.

func List

func List() ([]string, error)

func Load

func Load(cfg *WorkspaceConfig, spawnTemplates map[string]string, lister TerminalLister, minimizer WindowMinimizer, applier LayoutApplier, opts LoadOptions) error

func MoveTerminalBetweenWorkspaces

func MoveTerminalBetweenWorkspaces(srcDesktop, srcSlot, dstDesktop int) (newSlot int, err error)

MoveTerminalBetweenWorkspaces moves a terminal slot from one workspace to another. It removes the slot from the source workspace, appends it to the destination, and returns the new slot index in the destination workspace.

func ReconcileRegistry

func ReconcileRegistry() error

ReconcileRegistry removes stale workspace entries from the registry. For agent-mode workspaces, it checks if tmux sessions still exist. Workspaces with no live sessions are removed; workspaces with fewer live sessions than recorded get their count updated.

func RemoveSlotByWindowID

func RemoveSlotByWindowID(windowID uint32) error

RemoveSlotByWindowID removes a slot from the registry by its window ID.

func RemoveTerminalFromWorkspace

func RemoveTerminalFromWorkspace(desktop int, slot int) error

RemoveTerminalFromWorkspace removes a slot from the workspace. Returns error if slot doesn't exist. If desktop is -1, auto-detect current desktop.

func SetActiveWorkspace

func SetActiveWorkspace(name string, terminalCount int, agentMode bool, desktop int, agentSlots []int) error

SetActiveWorkspace registers a workspace on a specific desktop. If desktop is -1, auto-detect current desktop. If agentSlots is provided and agentMode is true, the slots are recorded.

func SetSlotInfo

func SetSlotInfo(windowID uint32, slotIndex int, sessionName string, desktop int) error

SetSlotInfo records a terminal slot with its window ID and session name.

func SwapSessionNamesInConfig

func SwapSessionNamesInConfig(workspaceName string, slotA, slotB int) error

SwapSessionNamesInConfig swaps the session_name fields for two slots in the config.

func SwapSlotsInRegistry

func SwapSlotsInRegistry(desktop, slotA, slotB int) error

SwapSlotsInRegistry swaps two slot indices in the workspace's AgentSlots. This is called after a move/swap operation to keep runtime state in sync. If desktop is -1, auto-detect current desktop.

func UpdateSessionNameInConfig

func UpdateSessionNameInConfig(workspaceName string, slot int, newSessionName string) error

UpdateSessionNameInConfig updates the session_name field for a specific slot in the saved workspace config file. This is called after renaming tmux sessions.

func UpdateSlotIndex

func UpdateSlotIndex(windowID uint32, newIndex int, newSessionName string) error

UpdateSlotIndex updates the slot index and session name for a window.

func ValidateWorkspaceName

func ValidateWorkspaceName(name string) error

ValidateWorkspaceName validates a workspace name (exported version).

func Write

func Write(cfg *WorkspaceConfig) error

Types

type ActiveState

type ActiveState struct {
	Name          string    `json:"name"`
	TerminalCount int       `json:"terminal_count"`
	LoadedAt      time.Time `json:"loaded_at"`
}

ActiveState is kept for backwards compatibility during migration. Deprecated: Use WorkspaceInfo instead.

func GetActiveState

func GetActiveState() (*ActiveState, error)

GetActiveState returns the full active workspace state for backwards compatibility. Deprecated: Use GetActiveWorkspace() instead.

type CrossDesktopLister

type CrossDesktopLister interface {
	ListTerminalsAllDesktops() ([]TerminalWindow, error)
}

CrossDesktopLister is an optional interface that TerminalLister implementations can support to list terminals across all virtual desktops (not just the current one). Used by workspace new to detect newly spawned windows that may appear on any desktop.

type LayoutApplier

type LayoutApplier interface {
	ApplyLayout(layoutName string, tileNow bool) error
	ApplyLayoutWithOrder(layoutName string, windowOrder []uint32) error
}

type LoadOptions

type LoadOptions struct {
	Timeout              time.Duration
	RerunCommand         bool
	NoReplace            bool
	AutoSaveLayout       string
	AutoSaveTerminalSort string
	AppConfig            *config.Config // Application config for agent mode multiplexer settings
}

type SlotInfo

type SlotInfo struct {
	WindowID    uint32 `json:"window_id"`
	SessionName string `json:"session_name,omitempty"`
	SlotIndex   int    `json:"slot_index"`
	Desktop     int    `json:"desktop"`
}

SlotInfo tracks a single terminal slot with its X11 window ID and tmux session.

func GetSlotByWindowID

func GetSlotByWindowID(windowID uint32) (SlotInfo, bool)

GetSlotByWindowID returns slot info for a given window ID. Returns the slot and true if found, empty SlotInfo and false otherwise.

func GetSlotsByDesktop

func GetSlotsByDesktop(desktop int) ([]SlotInfo, error)

GetSlotsByDesktop returns all slots for a specific desktop, sorted by slot index.

type TerminalConfig

type TerminalConfig struct {
	WMClass     string   `json:"wm_class"`
	Cwd         string   `json:"cwd,omitempty"`
	Cmd         []string `json:"cmd,omitempty"`
	SlotIndex   int      `json:"slot_index"`
	SessionName string   `json:"session_name,omitempty"`
}

type TerminalLister

type TerminalLister interface {
	ListTerminals() ([]TerminalWindow, error)
	ActiveWindowID() (uint32, error)
}

type TerminalWindow

type TerminalWindow struct {
	WindowID uint32
	WMClass  string
	X        int
	Y        int
	PID      int
}

TerminalWindow is a lightweight snapshot of a currently-open terminal window.

type WindowMinimizer

type WindowMinimizer interface {
	MinimizeWindow(windowID uint32) error
}

type WorkspaceConfig

type WorkspaceConfig struct {
	Name      string           `json:"name"`
	Layout    string           `json:"layout"`
	AgentMode bool             `json:"agent_mode,omitempty"`
	Terminals []TerminalConfig `json:"terminals"`
}

WorkspaceConfig is a persisted snapshot of a set of terminal sessions.

func Read

func Read(name string) (*WorkspaceConfig, error)

func Save

func Save(name, layout, terminalSort string, includeCmd bool, lister TerminalLister) (*WorkspaceConfig, error)

type WorkspaceInfo

type WorkspaceInfo struct {
	Name          string    `json:"name"`
	Desktop       int       `json:"desktop"`
	TerminalCount int       `json:"terminal_count"`
	AgentMode     bool      `json:"agent_mode"`
	AgentSlots    []int     `json:"agent_slots,omitempty"`
	OpenedAt      time.Time `json:"opened_at"`
}

WorkspaceInfo holds information about an active workspace on a specific desktop.

func GetActiveWorkspace

func GetActiveWorkspace() (WorkspaceInfo, error)

GetActiveWorkspace returns the workspace on the current desktop (auto-detected). Returns empty WorkspaceInfo if no workspace on current desktop.

func GetWorkspaceByDesktop

func GetWorkspaceByDesktop(desktop int) (WorkspaceInfo, bool)

GetWorkspaceByDesktop returns workspace on a specific desktop. Returns empty WorkspaceInfo and false if no workspace on that desktop.

func GetWorkspaceByName

func GetWorkspaceByName(name string) (WorkspaceInfo, error)

GetWorkspaceByName finds a workspace by name across all desktops. Returns error if workspace not found.

Jump to

Keyboard shortcuts

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