diff --git a/desktop/internal/i18n/en.go b/desktop/internal/i18n/en.go index 2fa45b09f4..123843defc 100644 --- a/desktop/internal/i18n/en.go +++ b/desktop/internal/i18n/en.go @@ -6,6 +6,7 @@ var english = Messages{ App: appMessages(English), Welcome: welcomeMessages(English), Title: titleMessages(English), + Window: windowMessages(English), Tools: toolMessages(English), Dock: dockMessages(English), Panel: panelMessages(English), diff --git a/desktop/internal/i18n/messages.go b/desktop/internal/i18n/messages.go index 647d3b1507..5f9245c623 100644 --- a/desktop/internal/i18n/messages.go +++ b/desktop/internal/i18n/messages.go @@ -6,6 +6,7 @@ type Messages struct { App AppMessages Welcome WelcomeMessages Title TitleMessages + Window WindowMessages Tools ToolMessages Dock DockMessages Panel PanelMessages @@ -60,6 +61,15 @@ type WelcomeMessages struct { Missing string } +// WindowMessages names the minimize, maximize, restore and close buttons that Viva draws +// in the title bar on Windows and Linux. Assistive technology reads them. +type WindowMessages struct { + Minimize string + Maximize string + Restore string + Close string +} + // TitleMessages are the workbench title bar's words. type TitleMessages struct { ProjectMenu string diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index 83622512cc..7db6c4c52c 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -574,6 +574,10 @@ var sharedCatalogs = map[string]map[string]string{ "welcome.projects": "Projects", "welcome.searchProjects": "Search projects", "welcome.title": "Welcome to Lithe", + "window.close": "Close", + "window.maximize": "Maximize", + "window.minimize": "Minimize", + "window.restore": "Restore", "workbench.commit": "Commit", "workbench.currentFile": "Current File", "workbench.project": "Project", @@ -1153,6 +1157,10 @@ var sharedCatalogs = map[string]map[string]string{ "welcome.projects": "项目", "welcome.searchProjects": "搜索项目", "welcome.title": "欢迎使用 Lithe", + "window.close": "关闭", + "window.maximize": "最大化", + "window.minimize": "最小化", + "window.restore": "还原", "workbench.commit": "提交", "workbench.currentFile": "当前文件", "workbench.project": "项目", diff --git a/desktop/internal/i18n/window_messages.go b/desktop/internal/i18n/window_messages.go new file mode 100644 index 0000000000..89eb616895 --- /dev/null +++ b/desktop/internal/i18n/window_messages.go @@ -0,0 +1,11 @@ +package i18n + +// windowMessages reads the names of the window buttons from the shared catalog. +func windowMessages(language Language) WindowMessages { + return WindowMessages{ + Minimize: Shared(language, "window.minimize"), + Maximize: Shared(language, "window.maximize"), + Restore: Shared(language, "window.restore"), + Close: Shared(language, "window.close"), + } +} diff --git a/desktop/internal/i18n/zh.go b/desktop/internal/i18n/zh.go index f6f2ef7630..26ffeedb1a 100644 --- a/desktop/internal/i18n/zh.go +++ b/desktop/internal/i18n/zh.go @@ -6,6 +6,7 @@ var chinese = Messages{ App: appMessages(Chinese), Welcome: welcomeMessages(Chinese), Title: titleMessages(Chinese), + Window: windowMessages(Chinese), Tools: toolMessages(Chinese), Dock: dockMessages(Chinese), Panel: panelMessages(Chinese), diff --git a/desktop/internal/logwindow/window.go b/desktop/internal/logwindow/window.go index effea76f5b..eb0290cbc1 100644 --- a/desktop/internal/logwindow/window.go +++ b/desktop/internal/logwindow/window.go @@ -14,6 +14,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/icons" "github.com/1lck/Lithe-IDEA/desktop/internal/sysinfo" + "github.com/1lck/Lithe-IDEA/desktop/internal/windowcontrols" "github.com/vivaui/viva/app" "github.com/vivaui/viva/components" "github.com/vivaui/viva/gfx" @@ -281,6 +282,7 @@ func (w *window) config() app.Config { MinHeight: 500, WindowMode: app.WindowCustomTitlebar, TitlebarHeight: titleHeight, + WindowControls: func() app.WindowControlsStyle { return windowcontrols.Style(w.pal.tx, w.ctrl.text()) }, Tree: &tree, Paint: w.paint, OnKey: w.onKey, diff --git a/desktop/internal/logwindow/window_test.go b/desktop/internal/logwindow/window_test.go index 9182d4b53f..607f13b6ac 100644 --- a/desktop/internal/logwindow/window_test.go +++ b/desktop/internal/logwindow/window_test.go @@ -6,6 +6,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/vivaui/viva/app" + "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" ) @@ -35,3 +36,41 @@ func TestOpenWindowRepaintsWhenLanguageAndAppearanceChange(t *testing.T) { t.Fatal("the open log window did not repaint with the new appearance") } } + +// TestWindowControlsFollowTheTitleBar covers the buttons Viva draws in the custom title bar on +// Windows and Linux: unstyled, they took Viva's ink for its default dark clear color and were +// white on the light title bar. They must take the ink of the title bar and the language of +// the window, and follow both when they change. +func TestWindowControlsFollowTheTitleBar(t *testing.T) { + fixture := newExportFixture(t) + var current atomic.Pointer[i18n.Messages] + var dark atomic.Bool + current.Store(i18n.For(i18n.English)) + controller := NewController(WindowOptions{Text: current.Load, Dark: dark.Load}) + w := &window{ctrl: controller, model: fixture.model, filterRevision: -1, anchors: map[menuKind]ui.Box{}} + controller.current = w + config := w.config() + if config.WindowControls == nil { + t.Fatal("the log window leaves its window buttons to Viva's default ink") + } + driver, err := app.NewDriver(config, nil) + if err != nil { + t.Fatal(err) + } + t.Cleanup(driver.Close) + check := func(look string, ink gfx.Color, minimize string) { + t.Helper() + style := config.WindowControls() + if style.Foreground != ink || style.Minimize != minimize { + t.Fatalf("%s look: glyph color %v and minimize name %q, want %v and %q", look, style.Foreground, style.Minimize, ink, minimize) + } + } + check("light", lightPalette().tx, "Minimize") + current.Store(i18n.For(i18n.Chinese)) + dark.Store(true) + controller.Invalidate() + if err := driver.Pump(); err != nil { + t.Fatal(err) + } + check("dark", darkPalette().tx, "最小化") +} diff --git a/desktop/internal/settingswindow/general_view_test.go b/desktop/internal/settingswindow/general_view_test.go index 6f76d6d4dd..03fb7f258c 100644 --- a/desktop/internal/settingswindow/general_view_test.go +++ b/desktop/internal/settingswindow/general_view_test.go @@ -260,3 +260,35 @@ func TestGeneralNarrowWindowKeepsSystemAppearanceVisible(t *testing.T) { } t.Fatalf("system appearance label %q is missing", want) } + +// TestWindowControlsFollowTheTitleBar covers the buttons Viva draws in the custom title bar on +// Windows and Linux: unstyled, they took Viva's ink for its default dark clear color and were +// white on the light title bar. They must take the ink of the title bar and the language of +// the client, and follow the look when it changes. +func TestWindowControlsFollowTheTitleBar(t *testing.T) { + w := newWindow(NewController(Options{Text: func() *i18n.Messages { return i18n.For(i18n.Chinese) }}), + Values{Language: "zh-Hans", Theme: themeLight}) + config := w.config() + if config.WindowControls == nil { + t.Fatal("the settings window leaves its window buttons to Viva's default ink") + } + driver, err := app.NewDriver(config, nil) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { w.market.close(); driver.Close() }) + check := func(look string, ink gfx.Color) { + t.Helper() + style := config.WindowControls() + if style.Foreground != ink || style.Minimize != "最小化" { + t.Fatalf("%s look: glyph color %v and minimize name %q, want %v and %q", look, style.Foreground, style.Minimize, ink, "最小化") + } + } + check("light", lightPalette().text) + w.sess.values.Theme = themeDark + w.inv.Invalidate() + if err := driver.Pump(); err != nil { + t.Fatal(err) + } + check("dark", darkPalette().text) +} diff --git a/desktop/internal/settingswindow/window.go b/desktop/internal/settingswindow/window.go index adf2ea0b17..b966c8c51c 100644 --- a/desktop/internal/settingswindow/window.go +++ b/desktop/internal/settingswindow/window.go @@ -9,6 +9,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/icons" "github.com/1lck/Lithe-IDEA/desktop/internal/splitpane" + "github.com/1lck/Lithe-IDEA/desktop/internal/windowcontrols" "github.com/vivaui/viva/app" "github.com/vivaui/viva/components" "github.com/vivaui/viva/gfx" @@ -200,6 +201,7 @@ func (w *window) config() app.Config { MinHeight: windowMinHeight, WindowMode: app.WindowCustomTitlebar, TitlebarHeight: titleHeight, + WindowControls: func() app.WindowControlsStyle { return windowcontrols.Style(w.pal.text, w.ctrl.text()) }, Tree: &tree, Paint: w.paint, OnKey: w.onKey, diff --git a/desktop/internal/windowcontrols/style.go b/desktop/internal/windowcontrols/style.go new file mode 100644 index 0000000000..00972e23de --- /dev/null +++ b/desktop/internal/windowcontrols/style.go @@ -0,0 +1,42 @@ +// Package windowcontrols styles the minimize, maximize and close buttons that Viva draws in +// a custom title bar on Windows and Linux (macOS keeps its own traffic lights). +// +// Without a style Viva takes the glyph color from the window's clear color, which is dark +// by default and is not the color of the title bar the buttons stand on: in the light look +// the glyphs were white on a light title bar and could not be seen. Every window of the +// client therefore styles its buttons from the ink of its own title bar. +package windowcontrols + +import ( + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/gfx" +) + +const ( + // hoverAlpha and pressedAlpha are the opacity of the ink behind a button under the + // pointer and while it is held down: the tints Viva itself uses, taken from the + // title bar's ink instead of the clear color. + hoverAlpha = 0.10 + pressedAlpha = 0.18 +) + +// Style is the buttons' style on a title bar whose text is ink: the glyphs in ink, the +// hover and press tints ink at low opacity, and the names in the user's language. The +// close button keeps Viva's red. A zero ink (a window that has not painted yet) leaves +// the colors to Viva. +func Style(ink gfx.Color, text *i18n.Messages) app.WindowControlsStyle { + var style app.WindowControlsStyle + if ink != (gfx.Color{}) { + style.Foreground = ink + style.Hover = ink.WithAlpha(hoverAlpha) + style.Pressed = ink.WithAlpha(pressedAlpha) + } + if text != nil { + style.Minimize = text.Window.Minimize + style.Maximize = text.Window.Maximize + style.Restore = text.Window.Restore + style.CloseName = text.Window.Close + } + return style +} diff --git a/desktop/internal/windowcontrols/style_test.go b/desktop/internal/windowcontrols/style_test.go new file mode 100644 index 0000000000..3756f2d60a --- /dev/null +++ b/desktop/internal/windowcontrols/style_test.go @@ -0,0 +1,51 @@ +package windowcontrols + +import ( + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/gfx" +) + +// TestStyleDrawsTheButtonsInTheTitleBarInk covers the light look: Viva takes the default +// glyph color from the clear color, which is dark, so the glyphs came out white on the +// light title bar. The buttons must take the title bar's ink, and their tints with it. +func TestStyleDrawsTheButtonsInTheTitleBarInk(t *testing.T) { + ink := gfx.RGB24(0x1F2328) + style := Style(ink, i18n.For(i18n.English)) + if style.Foreground != ink { + t.Fatalf("glyph color = %v, want the title bar's ink %v", style.Foreground, ink) + } + if style.Hover != ink.WithAlpha(hoverAlpha) || style.Pressed != ink.WithAlpha(pressedAlpha) { + t.Fatalf("hover and press tints = %v and %v, want the ink at %v and %v", style.Hover, style.Pressed, hoverAlpha, pressedAlpha) + } + if style.Close != (gfx.Color{}) || style.CloseForeground != (gfx.Color{}) { + t.Fatalf("close button colors = %v and %v, want them left to Viva's red", style.Close, style.CloseForeground) + } +} + +func TestStyleNamesTheButtonsInTheUsersLanguage(t *testing.T) { + for _, test := range []struct { + language i18n.Language + want [4]string + }{ + {i18n.English, [4]string{"Minimize", "Maximize", "Restore", "Close"}}, + {i18n.Chinese, [4]string{"最小化", "最大化", "还原", "关闭"}}, + } { + style := Style(gfx.RGB24(0x1F2328), i18n.For(test.language)) + got := [4]string{style.Minimize, style.Maximize, style.Restore, style.CloseName} + if got != test.want { + t.Fatalf("language %s: button names = %q, want %q", test.language.Code(), got, test.want) + } + } +} + +// TestStyleLeavesToVivaWhatItIsNotGiven covers a window asked for its style before its first +// paint, when it has no ink and no catalog yet: Viva's defaults must stand, not black glyphs +// on black tints or nameless buttons. +func TestStyleLeavesToVivaWhatItIsNotGiven(t *testing.T) { + if style := Style(gfx.Color{}, nil); style != (app.WindowControlsStyle{}) { + t.Fatalf("style without ink or catalog = %+v, want the zero style", style) + } +} diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 03fb792fe7..9aaafe3da9 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -36,6 +36,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" "github.com/1lck/Lithe-IDEA/desktop/internal/settingswindow" "github.com/1lck/Lithe-IDEA/desktop/internal/store" + "github.com/1lck/Lithe-IDEA/desktop/internal/windowcontrols" "github.com/vivaui/viva/app" "github.com/vivaui/viva/gfx" "github.com/vivaui/viva/ui" @@ -403,6 +404,7 @@ func (a *App) Config() app.Config { MinHeight: 600, WindowMode: app.WindowCustomTitlebar, TitlebarHeight: titleBarHeight, + WindowControls: func() app.WindowControlsStyle { return windowcontrols.Style(a.colors.Text, a.text) }, Tree: &tree, Paint: a.paint, OnPointer: a.onPointer, diff --git a/desktop/internal/workbench/app_test.go b/desktop/internal/workbench/app_test.go index 5c11dae21d..484fe5e07e 100644 --- a/desktop/internal/workbench/app_test.go +++ b/desktop/internal/workbench/app_test.go @@ -34,8 +34,11 @@ func (k *testKernel) ReduceChromeLayout(ctx context.Context, catalog []core.Chro // harness is a window driven without a screen. type harness struct { - t testing.TB - app *App + t testing.TB + app *App + // config is the configuration the driver runs, so a test reads the callbacks the + // window was opened with instead of building a second configuration. + config app.Config driver *app.Driver store *store.Store } @@ -78,7 +81,8 @@ func newHarnessWithLanguages(t testing.TB, kernel Kernel, languages []string) *h return start.Add(h.driver.Now()) }, }) - driver, err := app.NewDriver(h.app.Config(), nil) + h.config = h.app.Config() + driver, err := app.NewDriver(h.config, nil) if err != nil { t.Fatalf("NewDriver: %v", err) } @@ -802,6 +806,30 @@ func TestMarketplaceWidthPersistsWithOtherSettings(t *testing.T) { } } +// TestWindowControlsFollowTheTitleBar covers the buttons Viva draws in the custom title bar on +// Windows and Linux: unstyled, they took Viva's ink for its default dark clear color and were +// white on the light title bar. They must take the ink of the title bar and the language of +// the window, and follow both when they change. +func TestWindowControlsFollowTheTitleBar(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + if h.config.WindowControls == nil { + t.Fatal("the workbench leaves its window buttons to Viva's default ink") + } + check := func(look string, ink gfx.Color, minimize string) { + t.Helper() + style := h.config.WindowControls() + if style.Foreground != ink || style.Minimize != minimize { + t.Fatalf("%s look: glyph color %v and minimize name %q, want %v and %q", look, style.Foreground, style.Minimize, ink, minimize) + } + } + _, darkColors := darkLook() + check("dark", darkColors.Text, "最小化") + h.app.setLanguage("en") + h.app.setTheme(themeLight) + _, lightColors := lightLook() + check("light", lightColors.Text, "Minimize") +} + func TestSettingsChangesUpdateSharedStateAndPersist(t *testing.T) { h := newHarness(t, &testKernel{Client: core.NewClient()}) h.app.setLanguage("en") diff --git a/shared/i18n/messages.json b/shared/i18n/messages.json index a89db88080..89530be7af 100644 --- a/shared/i18n/messages.json +++ b/shared/i18n/messages.json @@ -98031,14 +98031,16 @@ "id": "window.close", "description": "Windows UI: window.close", "platforms": [ - "windows" + "windows", + "desktop" ] }, { "id": "window.maximize", "description": "Windows UI: window.maximize", "platforms": [ - "windows" + "windows", + "desktop" ] }, { @@ -98052,14 +98054,16 @@ "id": "window.minimize", "description": "Windows UI: window.minimize", "platforms": [ - "windows" + "windows", + "desktop" ] }, { "id": "window.restore", "description": "Windows UI: window.restore", "platforms": [ - "windows" + "windows", + "desktop" ] }, { diff --git a/shared/platform-feature-matrix/features/window-controls.json b/shared/platform-feature-matrix/features/window-controls.json index 3168760a97..a92615d822 100644 --- a/shared/platform-feature-matrix/features/window-controls.json +++ b/shared/platform-feature-matrix/features/window-controls.json @@ -11,10 +11,14 @@ ] }, "windows": { - "implementationStatus": "unassessed", + "implementationStatus": "partial", "verificationStatus": "pending", "evidence": [ - ".agents/notes/implemented/process/2026-09-24-cross-platform-feature-parity-matrix.md" + "desktop/internal/windowcontrols/style.go", + "desktop/internal/windowcontrols/style_test.go", + "desktop/internal/workbench/app.go", + "desktop/internal/settingswindow/window.go", + "desktop/internal/logwindow/window.go" ] }, "owner": "Workbench", @@ -41,5 +45,5 @@ "verificationStatus": "pending" } }, - "notes": "Viva 客户端尚未逐项盘点;legacy 是迁移前基线,不代表当前实现。" + "notes": "Viva 客户端:Windows 与 Linux 的自定义标题栏最小化、最大化/还原、关闭按钮由 Viva 绘制和命中,工作台、设置窗口和日志窗口通过 windowcontrols.Style 按各自标题栏文字色着色并使用共享 i18n 名称(此前沿用 Viva 按默认深色清屏色推出的白色字形,浅色标题栏上看不见);命令面板的窗口操作尚未接入,原生窗口中的按钮行为待在 Windows 与 Linux 验证。macOS 尚未逐项盘点。legacy 是迁移前基线,不代表当前实现。" }