window

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: AGPL-3.0 Imports: 43 Imported by: 0

README

ui/window

窗口:打开、关闭、置前、窗口快捷键、事件循环、离屏截图。

文件 内容
window.go Open、Main、Options(含 Overlay)、Window
shortcut.go 快捷键解析与分发
root.go 窗口根视图:背景、滚动、24dp 边距
position_* 首次显示居中;macOS 按屏幕可用区域计算,其他平台使用 Gio 动作
screenshot.go Screenshot 离屏渲染成 PNG
automation.go 自动化模式:内存窗口、语义快照、模拟点击输入滚动
automation_server.go 自动化协议:KEEL_AUTOMATION socket 上的 JSON 请求
testdata/raise 真实窗口死锁回归测试
  • 依赖:core、theme。不依赖 el、kit:窗口只认 core.Widget 接口。
  • 被谁依赖:应用代码。cmd/keel-mcp 通过 socket 协议驱动它,不引用它的代码。

设置环境变量 KEEL_AUTOMATION=1(或 socket 路径)启动应用时,每个窗口会多一个影子窗口,供 Agent 操作;真实窗口照常显示,Agent 的操作会实时反映在屏幕上。再加 KEEL_HEADLESS=1 则不显示窗口,见 Agent 端到端测试。

window.Open(window.Options{Title: "Hello", Content: page})
window.Main() // 最后一个窗口关闭后退出进程

改这里的代码前先读 架构 · 不能在锁内等待主线程。详见 窗口与应用。

macOS 的 Main 会订阅 NSWorkspace 的辅助功能显示偏好,启动时读取“减少动态效果”,变化时更新 theme.ReducedMotion。AppKit 回调通过有界队列交给后台消费者,再在 core.Update 中更新主题,避免主线程等待帧锁。无窗口测试不安装原生观察者;其他平台目前使用应用设置。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main()

Main runs the platform event loop. The process exits after the last window closes. With KEEL_AUTOMATION set it also serves automation requests, or only those with KEEL_HEADLESS=1; see automation.go.

func Screenshot

func Screenshot(content core.Widget, width, height int, path string) error

Screenshot renders content as a window would, off-screen at 2× scale, and writes a PNG. Width and height are in dp.

func ScreenshotAtScale

func ScreenshotAtScale(content core.Widget, width, height int, scale float32, path string) error

ScreenshotAtScale renders the first frame at an explicit pixel density. Dimensions are in dp; scale must be finite and positive.

func SocketDir

func SocketDir() string

SocketDir is where apps started with KEEL_AUTOMATION=1 listen. keel-mcp computes the same path; keep the two in sync.

Types

type Element

type Element struct {
	Ref      string `json:"ref"`
	Role     string `json:"role"` // see roleOf
	Name     string `json:"name,omitempty"`
	Value    string `json:"value,omitempty"`    // textbox content, select choice, progress
	Checked  *bool  `json:"checked,omitempty"`  // checkbox, radio, switch
	Selected *bool  `json:"selected,omitempty"` // tab, row, option; a button only when selected
	Disabled bool   `json:"disabled,omitempty"`
	X        int    `json:"x"`
	Y        int    `json:"y"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
}

Element is one node of a window's semantic tree, as reported to agents.

type Options

type Options struct {
	Title         string
	Width, Height int
	Content       core.Widget
	// Overlay is drawn over the whole window, above Content, for hand-written
	// Gio content; el views declare overlays with cx.Overlay instead. It should
	// take no space while it has nothing to show.
	Overlay core.Widget
	// Shortcuts maps accelerators to callbacks while the window has focus, e.g.
	// "mod+," (Cmd on macOS, Ctrl elsewhere), "ctrl+shift+s", "esc".
	Shortcuts map[string]func()
	OnClose   func()
	// Frameless hides the system title bar so the content can draw its own,
	// e.g. a kit.TitleBar; the content then starts at the window's top edge.
	Frameless bool
}

Options configures a window. Width and Height are in dp; zero uses 640×480.

type Snapshot

type Snapshot struct {
	Window   WindowInfo `json:"window"`
	Elements []Element  `json:"elements"`
}

Snapshot is a window and its elements.

type Window

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

func Open

func Open(o Options) *Window

Open creates and shows a centered window where the platform supports it. Call it before Main or from any callback. It panics on an invalid shortcut, which is a programming error.

func (*Window) Activate added in v0.0.4

func (w *Window) Activate(token string)

Activate brings the window to the front with an activation token that another program granted, such as notification.Activation.Token after a system notification was clicked. Window managers let a token through their focus-stealing prevention, where a plain Raise may only flash the taskbar. On Wayland the token goes to xdg-activation; on X11 it is a startup ID. Elsewhere, with an empty token, or if the platform refuses, Activate is Raise.

func (*Window) Close

func (w *Window) Close()

Close closes the window as if the user clicked its close button.

func (*Window) Closed

func (w *Window) Closed() bool

Closed reports whether the window has been destroyed. Call it from UI code.

func (*Window) Focused

func (w *Window) Focused() bool

func (*Window) Frameless

func (w *Window) Frameless() bool

Frameless reports whether the window draws its own title bar.

func (*Window) Maximized

func (w *Window) Maximized() bool

Maximized reports whether the window is maximized. Call it from UI code.

func (*Window) Minimize

func (w *Window) Minimize()

Minimize hides the window in the Dock or taskbar.

func (*Window) Raise

func (w *Window) Raise()

Raise brings the window to the front.

func (*Window) TitleBarArea

func (w *Window) TitleBarArea(x, y, width, height float32)

func (*Window) ToggleMaximize

func (w *Window) ToggleMaximize()

ToggleMaximize maximizes the window (zooms it on macOS), or restores it when it is maximized.

func (*Window) WaylandDisplay added in v0.0.4

func (w *Window) WaylandDisplay() unsafe.Pointer

WaylandDisplay is this window's wl_display on Linux Wayland, nil elsewhere or before the window is shown. Pass it to native/clipboard's UseWaylandDisplay to read the clipboard while this window has focus.

type WindowInfo

type WindowInfo struct {
	ID     string `json:"id"`
	Title  string `json:"title"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
	Active bool   `json:"active"`
}

WindowInfo describes an open window.

Jump to

Keyboard shortcuts

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