From 9420622ddd9e65d0dc4a22587ebc00500420a053 Mon Sep 17 00:00:00 2001 From: Kyuzan0 Date: Tue, 17 Nov 2026 17:05:42 +0700 Subject: [PATCH] feat(ui): add option to switch between Mac traffic lights and Windows caption buttons - Add setting in Appearance page to toggle window controls style - Render Windows-style Minimize, Maximize, and Close buttons on right - Add tests for window controls selection and persistence - Format with gofmt and document in docs/settings.md --- docs/settings.md | 2 +- ui/appearance.go | 1 + ui/appearance_windowcontrols.go | 46 ++++++++++++++ ui/state.go | 2 + ui/titlebar.go | 10 ++- ui/windowbuttons.go | 109 +++++++++++++++++++++++++++++++- ui/windowbuttons_test.go | 99 ++++++++++++++++++++++++++--- 7 files changed, 257 insertions(+), 12 deletions(-) create mode 100644 ui/appearance_windowcontrols.go diff --git a/docs/settings.md b/docs/settings.md index f090c8cc..470f829f 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -2,7 +2,7 @@ The rail's **Settings** (or the command palette) has these sections, for the connected host where they are a host's. -**Appearance** is a page of its own, not one of these sections, reached from the sidebar's menu or the palette. It keeps the app in Dark mode, Light mode, or System mode, which follows the device as its appearance changes. Existing preferences stay dark until another mode is chosen. Every palette has a light variant; the chosen palette and custom accent survive mode changes. Light accents use a contrast-safe shade of the same color. The app and its floating control update together; terminals keep the palette's dark variant so CLI programs with their own pale input text remain readable. These preferences are local to the device. +**Appearance** is a page of its own, not one of these sections, reached from the sidebar's menu or the palette. It keeps the app in Dark mode, Light mode, or System mode, which follows the device as its appearance changes. Existing preferences stay dark until another mode is chosen. Every palette has a light variant; the chosen palette and custom accent survive mode changes. Light accents use a contrast-safe shade of the same color. The app and its floating control update together; terminals keep the palette's dark variant so CLI programs with their own pale input text remain readable. **Window controls** chooses between macOS traffic lights on the left (the default) and Windows caption buttons on the right. These preferences are local to the device. On the same page, **Style** builds the whole app another way, on this device: Liquid Glass (the default), Ledger (real black, flat panes on one-pixel lines, denser controls), Tonal (flat tones of one hue, no lines or shadows) or Bento (Ledger's look with regions and page sections in fixed tiles). Regions, navigation, labels and shortcuts are the same in each. A palette tints any style: Ledger and Bento keep their black ground, taking the palette's accent and a tint in their surfaces; Tonal takes the palette's ground and accent for its whole field. A background image, its opacity and blur, and Follow background apply to Liquid Glass only: in the others those controls are disabled and say so, and the image is kept for going back. Ledger, Tonal and Bento ask for IBM Plex Sans or Rubik and use the system's font on a device that lacks it. diff --git a/ui/appearance.go b/ui/appearance.go index 2f90521f..80ce23f2 100644 --- a/ui/appearance.go +++ b/ui/appearance.go @@ -51,6 +51,7 @@ func (a *App) appearancePage(c *ui.Context) { widget.Card(c).Children(func() { a.appearanceMode(c) }) widget.Card(c).Children(func() { a.accentPicker(c) }) }) + widget.Card(c).Children(func() { a.windowControlStyleCard(c) }) }) widget.Card(c).Grow(5).Basis(0).Children(func() { a.themePreview(c) }) }) diff --git a/ui/appearance_windowcontrols.go b/ui/appearance_windowcontrols.go new file mode 100644 index 00000000..9b53dcc4 --- /dev/null +++ b/ui/appearance_windowcontrols.go @@ -0,0 +1,46 @@ +package ui + +import ( + "github.com/egoist/mygo/ui" + + "github.com/enowx/enowx/ui/icon" + "github.com/enowx/enowx/ui/theme" + "github.com/enowx/enowx/ui/widget" +) + +func (a *App) windowControlStyleCard(c *ui.Context) { + widget.CardTitle(c, nil, "Window controls", nil) + selected := 0 + if a.isWindowsControlStyle() { + selected = 1 + } + ui.Row(c).FillWidth().Children(func() { + if picked := widget.Segmented(c.Key("window-controls-picker"), []string{"Mac style", "Windows style"}, selected, nil); picked >= 0 { + if picked == 1 { + a.setWindowControlStyle(WindowControlStyleWindows) + } else { + a.setWindowControlStyle(WindowControlStyleMac) + } + } + }) + ui.Text(c, "Choose between macOS traffic lights on the left or Windows caption buttons on the right."). + FontSize(theme.TextLabel).TextColor(theme.TextSoft) + + // Visual preview of selected control style + ui.Row(c).Height(32).AlignItems(ui.Center).Gap(theme.S3).Children(func() { + ui.Text(c, "Preview:").FontSize(theme.TextLabel).TextColor(theme.TextSoft) + if a.isWindowsControlStyle() { + ui.Row(c).Height(24).Radius(theme.RadiusSmall).Background(theme.Panel).BorderColor(theme.Border).BorderWidth(1, 1, 1, 1).Clip().Children(func() { + ui.Row(c).Size(28, 24).Center().Children(func() { ui.Icon(c, icon.Minus).FontSize(9).TextColor(theme.TextSoft) }) + ui.Row(c).Size(28, 24).Center().Children(func() { ui.Icon(c, icon.Square).FontSize(9).TextColor(theme.TextSoft) }) + ui.Row(c).Size(28, 24).Center().Background(ui.Hex("#E81123")).Children(func() { ui.Icon(c, icon.Close).FontSize(9).TextColor(ui.Hex("#FFFFFF")) }) + }) + } else { + ui.Row(c).Height(24).PaddingX(theme.S2).Radius(theme.RadiusSmall).Background(theme.Panel).BorderColor(theme.Border).BorderWidth(1, 1, 1, 1).AlignItems(ui.Center).Gap(theme.S2).Children(func() { + ui.Box(c).Size(10, 10).Radius(theme.RadiusFull).Background(windowDots[0]) + ui.Box(c).Size(10, 10).Radius(theme.RadiusFull).Background(windowDots[1]) + ui.Box(c).Size(10, 10).Radius(theme.RadiusFull).Background(windowDots[2]) + }) + } + }) +} diff --git a/ui/state.go b/ui/state.go index 0ed6a7d9..674c892b 100644 --- a/ui/state.go +++ b/ui/state.go @@ -27,6 +27,8 @@ type appState struct { CloneDirs map[string]string `json:"cloneDirs,omitempty"` // host ID → the folder cloned into last Theme string `json:"theme,omitempty"` // palette ID ThemeMode string `json:"themeMode,omitempty"` // dark (default), light, or system + // WindowControlStyle is "mac" (default) or "windows". + WindowControlStyle string `json:"windowControlStyle,omitempty"` // BackgroundImage is this device's image behind the panels, "" for the // theme's own; BackgroundOpacity how opaque the main surfaces over it are, // nil for the default; BackgroundBlur its blur's sigma, nil for the default. diff --git a/ui/titlebar.go b/ui/titlebar.go index c03e61a9..f32cade3 100644 --- a/ui/titlebar.go +++ b/ui/titlebar.go @@ -33,13 +33,21 @@ func (a *App) titleBarWith(c *ui.Context, actions func()) { row.Background(theme.Panel) gap = 0 } + isWindows := a.isWindowsControlStyle() row.Gap(gap).Children(func() { - ui.Row(c).Height(theme.BarHeight).PaddingX(theme.S3).Shrink(0).Children(func() { a.windowButtons(c) }) + if !isWindows { + ui.Row(c).Height(theme.BarHeight).PaddingX(theme.S3).Shrink(0).Children(func() { a.windowButtons(c) }) + } else { + ui.Box(c).Width(theme.S2) + } a.contextCapsule(c) a.pagesCapsule(c) a.commandButton(c) ui.Spacer(c) capsule(c).Shrink(0).Gap(theme.S1).PaddingX(theme.S1).Children(actions) + if isWindows { + capsule(c).Shrink(0).Gap(0).PaddingX(0).Clip().Children(func() { a.windowsWindowButtons(c) }) + } }) } diff --git a/ui/windowbuttons.go b/ui/windowbuttons.go index 815cd723..7da58587 100644 --- a/ui/windowbuttons.go +++ b/ui/windowbuttons.go @@ -5,8 +5,35 @@ import ( "github.com/enowx/enowx/ui/icon" "github.com/enowx/enowx/ui/theme" + "github.com/enowx/enowx/ui/widget" ) +// Window control style options. +const ( + WindowControlStyleMac = "mac" + WindowControlStyleWindows = "windows" +) + +// isWindowsControlStyle reports whether Windows caption buttons are chosen. +func (a *App) isWindowsControlStyle() bool { + return a.state.WindowControlStyle == WindowControlStyleWindows +} + +// setWindowControlStyle sets the window controls appearance ("mac" or "windows"). +func (a *App) setWindowControlStyle(style string) { + if style != WindowControlStyleWindows { + style = WindowControlStyleMac + } + if a.state.WindowControlStyle == style { + return + } + a.state.WindowControlStyle = style + a.saveState() + if a.win != nil { + a.win.Invalidate() + } +} + // The window's close, minimize and maximize buttons, drawn by the app so // they look the same on macOS, Windows and Linux: three dots on the left, // their signs showing while the pointer is over them, grey while the @@ -25,7 +52,7 @@ type windowControl interface { ToggleFullScreen() } -// windowButtons draws them in the title bar. +// windowButtons draws them in the title bar (Mac style traffic lights). func (a *App) windowButtons(c *ui.Context) { win := a.winCtl if win == nil && a.win != nil { @@ -74,3 +101,83 @@ func (a *App) windowButtons(c *ui.Context) { } }) } + +// windowsWindowButtons draws Windows-style caption buttons (Minimize, Maximize, Close) +// at the right side of the title bar. +func (a *App) windowsWindowButtons(c *ui.Context) { + win := a.winCtl + if win == nil && a.win != nil { + win = a.win + } + if win == nil { + return + } + + group := ui.Row(c.Key("windows-buttons")).Shrink(0).Height(theme.BarHeight) + group.Children(func() { + // 1. Minimize + minBtn := ui.ButtonBase(c.Key("win-minimize")). + Height(theme.BarHeight).Width(44).Shrink(0).Center(). + Label("Minimize").Tooltip("Minimize").Cursor(ui.CursorPointer) + minBg := theme.Fade(theme.Selected, 0) + if minBtn.Hovered() { + minBg = theme.Selected + } + fg := theme.TextSoft + if minBtn.Hovered() { + fg = theme.TextStrong + } else if a.blurred { + fg = theme.Idle + } + minBtn.Background(widget.QuickTint(minBtn, "bg", minBg)).Children(func() { + ui.Icon(c, icon.Minus).FontSize(11).TextColor(fg) + }) + if minBtn.Clicked() { + win.Minimize() + } + + // 2. Maximize / Restore + maxBtn := ui.ButtonBase(c.Key("win-maximize")). + Height(theme.BarHeight).Width(44).Shrink(0).Center(). + Label("Maximize").Tooltip("Maximize").Cursor(ui.CursorPointer) + maxBg := theme.Fade(theme.Selected, 0) + if maxBtn.Hovered() { + maxBg = theme.Selected + } + maxFg := theme.TextSoft + if maxBtn.Hovered() { + maxFg = theme.TextStrong + } else if a.blurred { + maxFg = theme.Idle + } + maxBtn.Background(widget.QuickTint(maxBtn, "bg", maxBg)).Children(func() { + ui.Icon(c, icon.Square).FontSize(10).TextColor(maxFg) + }) + if maxBtn.Clicked() { + if zoomGoesFullScreen && maxBtn.ClickModifiers()&ui.Alt == 0 { + win.ToggleFullScreen() + } else { + win.ToggleMaximize() + } + } + + // 3. Close + closeBtn := ui.ButtonBase(c.Key("win-close")). + Height(theme.BarHeight).Width(46).Shrink(0).Center(). + Label("Close").Tooltip("Close").Cursor(ui.CursorPointer) + closeBg := theme.Fade(theme.Selected, 0) + closeFg := theme.TextSoft + if closeBtn.Hovered() { + closeBg = ui.Hex("#E81123") // Windows close red + closeFg = ui.Hex("#FFFFFF") + } else if a.blurred { + closeFg = theme.Idle + } + closeBtn.Background(widget.QuickTint(closeBtn, "bg", closeBg)).Children(func() { + ui.Icon(c, icon.Close).FontSize(11).TextColor(closeFg) + }) + if closeBtn.Clicked() { + win.Close() + } + }) +} diff --git a/ui/windowbuttons_test.go b/ui/windowbuttons_test.go index 2d37b5c9..58429c09 100644 --- a/ui/windowbuttons_test.go +++ b/ui/windowbuttons_test.go @@ -1,6 +1,7 @@ package ui import ( + "path/filepath" "testing" "github.com/egoist/mygo/ui" @@ -8,30 +9,69 @@ import ( "github.com/enowx/enowx/ui/theme" ) -type fakeWindow struct{ did []string } +type fakeWindow struct { + did []string +} -func (w *fakeWindow) Close() { w.did = append(w.did, "close") } -func (w *fakeWindow) Minimize() { w.did = append(w.did, "minimize") } -func (w *fakeWindow) ToggleMaximize() { w.did = append(w.did, "maximize") } -func (w *fakeWindow) ToggleFullScreen() { w.did = append(w.did, "full screen") } +func (w *fakeWindow) Close() { w.did = append(w.did, "close") } +func (w *fakeWindow) Minimize() { w.did = append(w.did, "minimize") } +func (w *fakeWindow) ToggleMaximize() { w.did = append(w.did, "maximize") } +func (w *fakeWindow) ToggleFullScreen() { w.did = append(w.did, "full screen") } +func (w *fakeWindow) Invalidate() {} +func (w *fakeWindow) Focus() {} +func (w *fakeWindow) IsFocused() bool { return true } +func (w *fakeWindow) IsFullScreen() bool { return false } +func (w *fakeWindow) IsMaximized() bool { return false } +func (w *fakeWindow) Restore() {} +func (w *fakeWindow) SetTitle(string) {} +func (w *fakeWindow) SetSubtitle(string) {} +func (w *fakeWindow) SetRepresentedFilename(string) {} -// The title bar's own buttons close, minimize, and take the window full -// screen (macOS) or maximize it. func TestWindowButtons(t *testing.T) { + w := &fakeWindow{} + a := New(Options{}) + a.winCtl = w + tt := ui.NewTester(func(c *ui.Context) { + ui.Column(c).Width(900).Height(60).Background(theme.Ground).Children(func() { a.titleBar(c) }) + }, 900, 60) + tt.Frame() + for _, b := range []string{"Close", "Minimize", "Zoom"} { + if err := tt.Click(b); err != nil { + t.Fatal(err) + } + tt.Frame() + } + zoom := "maximize" + if zoomGoesFullScreen { + zoom = "full screen" + } + if got := w.did; len(got) != 3 || got[0] != "close" || got[1] != "minimize" || got[2] != zoom { + t.Fatalf("did %q", got) + } +} + +func TestWindowsStyleButtons(t *testing.T) { a := New(Options{}) + a.state.WindowControlStyle = WindowControlStyleWindows w := &fakeWindow{} a.winCtl = w tt := ui.NewTester(func(c *ui.Context) { ui.Column(c).Width(900).Height(60).Background(theme.Ground).Children(func() { a.titleBar(c) }) }, 900, 60) tt.Frame() - for _, b := range []string{"Zoom", "Minimize", "Close"} { + + // Mac dots Zoom should not be present + if _, ok := tt.Find("Zoom"); ok { + t.Fatal("mac style Zoom button should not exist in Windows style") + } + + // Click Windows buttons: Maximize, Minimize, Close + for _, b := range []string{"Maximize", "Minimize", "Close"} { if err := tt.Click(b); err != nil { t.Fatal(err) } tt.Frame() } - shot(t, tt, "title-bar.png") zoom := "maximize" if zoomGoesFullScreen { zoom = "full screen" @@ -40,3 +80,44 @@ func TestWindowButtons(t *testing.T) { t.Fatalf("did %q", got) } } + +func TestWindowControlStyleAppearanceSetting(t *testing.T) { + file := filepath.Join(t.TempDir(), "state.json") + app := New(Options{StateFile: file}) + app.host = LocalHost() + + tt := ui.NewTester(func(c *ui.Context) { + ui.Column(c).Width(1000).Height(800).Background(theme.Ground).Children(func() { app.appearancePage(c) }) + }, 1000, 800) + tt.Frame() + + // Initially mac style + if app.isWindowsControlStyle() { + t.Fatal("expected default to be mac style") + } + + // Click "Windows style" + if err := tt.Click("Windows style"); err != nil { + t.Fatal(err) + } + tt.Frame() + + if !app.isWindowsControlStyle() { + t.Fatal("expected Windows style to be active") + } + + app.saveState() + reopened := New(Options{StateFile: file}) + if reopened.state.WindowControlStyle != WindowControlStyleWindows { + t.Fatalf("expected reopened to have windows control style, got %q", reopened.state.WindowControlStyle) + } + + // Switch back to "Mac style" + if err := tt.Click("Mac style"); err != nil { + t.Fatal(err) + } + tt.Frame() + if app.isWindowsControlStyle() { + t.Fatal("expected Mac style to be active") + } +}