gui: the main window opens where it was left (jorbenzhu)
jorbenzhu on Discord: after every update and restart the panel is back in the middle of the screen. It is the main window: after an update magpie starts again with `magpie gui <tab>`, and Wails opens a window centred unless told otherwise. Its size and maximised state were kept; its place never was (gui-shell.md said "The window's position is not kept"), so nothing was lost on upgrade, there was nothing to restore. The tray's panel opens under the tray icon on the Mac and Windows, and where the click was on Linux, so it is not what moved. Now settings.WindowAt keeps the window's top left corner (system coordinates across every screen), per machine like Window (KeepOwn, and the Settings page's save carries it over). keepAt saves it once a move or resize has rested 500ms, unless the window is maximised, full screen, minimised or hidden; settings.Save writes through temp and rename, and an unreadable settings file is left alone. On the first show placeMain puts it back (putBack): openAt picks the screen holding most of the window and moves it fully onto that screen's work area; when no screen holds any of it (a monitor gone) or the screens or the file can't be read, it stays centred. Under Wayland a window can't place itself, so nothing is kept or restored there unless GDK_BACKEND is x11 (keepsPlace). Run: - mote, at 3f8f1d88b (ond99e213f5): go test -timeout 45m -count=1 ./... 80 packages ok; internal/gui red only in its 10 real-window AppKit tests (TestDockJoinLeadsCommandTab, TestPanelCloseHidesIt, TestPanelJoinsFullScreenSpaces, TestPluginPageLoadsItsFilesInTheWindow, TestDockReopenKeepsTheWindowsSpace, TestMainWindowCorners, TestMainWindowRightToLeft, TestHandoverLeavesTheMenuBarIconForTheNextMagpie, TestTrayCellClickReleasedPanel, TestCoveredWindowStaysUp), each killed at its deadline. The same 10 fail the same way on origin/mainfa427216a: mote has no console session (#4125). - mote, after rebasing onto024393fbb(two gateway commits, none of these files): internal/gui (less the 10 above), internal/settings and internal/gateway: ok. - mote: gofmt -l; go vet ./internal/gui ./internal/settings; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...; go build, and GOOS=windows / GOOS=linux -tags nogui builds: clean. - Windows (win-run) and Linux (wsl-run, -tags gtk3): TestOpenAt, TestSettleAt, TestKeepsPlace, TestOpenSize, TestSettle*, TestSettingsSaveKeeps*, TestWindowMaximisedKeptAndOwn: ok. Broken by hand (each red, then restored): - api.go not carrying WindowAt over a Settings save: TestSettingsSaveKeepsWhatItDoesNotSend red ("WindowAt: [] after a save of the Settings page, was [-1440 120]"). - KeepOwn not keeping WindowAt: TestWindowMaximisedKeptAndOwn red. - openAt without the clamp and the gone-screen check: TestOpenAt red in 7 of 12 cases. Real app, Linux X11 (magpie-desktop, Xvfb 1920x1080 + xfwm4, sandbox HOME/XDG dirs, MAGPIE_ADDR 127.0.0.1:3447, gtk3 build of this tree): first start centred (630,240 in X terms); xdotool moved it to 200,150 and settings.json got windowAt; restarted, it opened at 200,150; windowAt [5000,4000] (a gone monitor) opened centred; [1700,900] opened at [1260,480], flush with the bottom right (660x600 + GTK's 26px shadow). Not tried: the real app on macOS (mote has no console session, #4125) and on Windows (a sandbox magpie.exe rewrites HKCU\Software\Classes\magpie, which points at another session's build there). Wayland is not restored by design. Multi-monitor setups with mixed scaling were not tried on real hardware; openAt's cases cover a second screen left of and right of the main one.
This commit is contained in:
@@ -30,7 +30,7 @@ three.
|
||||
3. The panel and the window load `index.html` from `Handler`. `boot.js` passes the saved language, theme, colorblind mode, text size and desktop font choices before the first paint.
|
||||
4. The page reads `GET /api/state` and writes through `POST` routes. Each write answers with the new state, built under `held`.
|
||||
5. Closing the window hides it. On the Mac a full-screen window first leaves full screen (`closeStep`). The system's close on the panel (a title bar's X, Alt+F4, a window manager's close key) hides it as Escape does, so the tray icon opens it again; a panel lightweight mode let go, no longer `h.panel`, closes (`makePanel`, `TestPanelCloseHidesIt`). Lightweight mode lets go only of a window closed this way: one covered by another app's window, minimised, or open as magpie was hidden is still open (`windowUp`, not Wails' `IsVisible`, which is the occlusion state), and so is it for the Dock while the window is open and for a restart (#1381, `TestCoveredWindowStaysUp`). On the Mac the tray icon and a usage cell close an open panel by the same test (`windowOpen` in `togglePanelNow` and `trayCellClick`, not Wails' `ToggleWindow`), so under a window over the whole screen, such as a remote-desktop server's privacy curtain, the icon still closes the panel instead of showing it again (#1661, `TestTrayCellClickReleasedPanel`).
|
||||
6. The window opens as it was last left. Its settled size and whether it was maximised are kept in `settings.Window` and `settings.WindowMaximised` (`settle`; per machine, see `KeepOwn`). A maximised window keeps the size it restores to. `makeMain` opens it at that size (`openSize`). On its first show, `placeMain` maximises it again on the Mac and Windows (on Windows once the page has come). On Linux, `makeMain` makes it maximised with `StartState`. On Windows a size larger than the screen's work area is fitted and centred (`fitRoom`), and the larger size stays kept. The window's position is not kept.
|
||||
6. The window opens as it was last left. Its settled size and whether it was maximised are kept in `settings.Window` and `settings.WindowMaximised` (`settle`; per machine, see `KeepOwn`). A maximised window keeps the size it restores to. `makeMain` opens it at that size (`openSize`). On its first show, `placeMain` maximises it again on the Mac and Windows (on Windows once the page has come). On Linux, `makeMain` makes it maximised with `StartState`. On Windows a size larger than the screen's work area is fitted and centred (`fitRoom`), and the larger size stays kept. Where it was left is kept too, in `settings.WindowAt` (its top left corner across every screen, in the system's coordinates), so after a restart or an update it opens there rather than in the middle (jorbenzhu on Discord). `keepAt` saves it once a move or resize has rested for half a second, unless the window is maximised, full screen, minimised or hidden; `settings.Save` writes through temp and rename, and a settings file that can't be read is left alone. On its first show `placeMain` puts it back (`putBack`): `openAt` takes the screen holding most of the window, moves the window fully onto that screen's work area, and leaves it centred when no screen holds any of it, such as a monitor that is gone, or when the screens or the file can't be read (`TestOpenAt`). Under Wayland a window can't place itself, so nothing is kept or put back there unless GDK_BACKEND is x11 (`keepsPlace`, `TestKeepsPlace`). The tray's panel isn't kept: on the Mac and Windows it opens under the tray icon, and on Linux where the click was.
|
||||
7. The page's header is the window's title bar. `plainTitlebar` sets it up once the app has started, and again on a window lightweight mode made again (`madeAgain`). On Linux it hides GTK's title bar and keeps the shadow and the resize edges; GTK 3 leaves the corners square. On the Mac the traffic lights are inset into the header (`MacTitleBarHiddenInset`). In the design of macOS 26 a window with a toolbar has larger corners than one with a plain title bar, so `insetLights` ([`titlebar_darwin.go`](../../internal/gui/titlebar_darwin.go)) takes the toolbar off, and `MagpieLights` keeps the lights and the title bar's height where the toolbar had them: after a resize, a new title, light or dark, more contrast or less transparency, and leaving full screen. A sheet, such as the folder chooser, still begins below the title bar. A first press while another app is in front still moves the window from anywhere in that title bar (`firstPress`), as AppKit moved it with the toolbar; AppKit itself now does so only in a plain title bar's top 32pt. AppKit gives a program that design from macOS 26 when the program is linked against the macOS 26 SDK or a later one and its Info.plist doesn't ask for the earlier design (`UIDesignRequiresCompatibility`); `designOf26` reads each at run time, as the SDK depends on the toolchain that built magpie. The toolbar stays in the earlier design, where it doesn't change the corners, with the lights on the right (a right-to-left language), or when the title bar isn't laid out as expected; this is decided once, when the window is set up. In full screen the title bar is AppKit's own. Windows keeps its own title bar.
|
||||
8. On the Mac, Settings › Show in Dock puts magpie in the Dock never (`DockNever`), while the window is open (the default; `DockWindow` records it chosen, for an older magpie that took none for never) or always (`Dock`, which wins). The default was never until ShouguangCao on X found the open window out of Command-Tab, so going back to it to paste a key copied elsewhere took the menu bar; a new install (no settings.json) reads With window, and Hide is a choice of its own (`inDock`, `dockChoice` in app.js, `TestDockFollowsWindowByDefault`, `dock-choice.test.cjs`). A file written before that has no `dockSettled`, and stored Hide as nothing, so a user who chose Hide can't be told from one who never chose: such a file with no Dock choice reads as Hide, and the first save writes it so with `dockSettled` (`settleDock`, `TestOlderSettingsKeepHide`, `TestNewInstallFollowsWindow`). A file nobody can read reads the same way. The page never sends `dockSettled`; the save keeps the file's (`TestSettingsSaveKeepsDockReading`). It is this computer's own, as the Dock choice is (`KeepOwn`). A full-screen window joins it whatever the setting (`inDock`, `dockOnFullscreen`). `openMain` joins before it shows the window (`setDock` runs on the main thread at once). An app activated out of the Dock (the quick panel's focus) that then joins it stays last in Command-Tab's order though it is in front, so joining to the front activates magpie by way of the Dock (`dockStep`, `activateAgain`; #1381, `TestDockStep`, `TestDockJoinLeadsCommandTab`). It does so without asking NSApp whether magpie is active: the Mac makes it the front app at once, and NSApp says so only once the main thread has taken that in, after the join on a busy Mac (#1651).
|
||||
9. Settings › General › Quick panel shortcut binds a key combination that opens the tray's panel from any app (ben hanks on Discord); none is set by default. The page records the keys and posts them to `POST /api/settings/panel-shortcut`, which checks them (`panelShortcut`: a letter, digit, Space or F1–F20 with Ctrl, Alt/Option or Cmd/Super, or an F key alone, written as Wails' accelerator), has the running app bind them (`onPanelShortcut`, `bindPanelKey` through Wails' `GlobalShortcut`: Carbon's hot keys on the Mac, `RegisterHotKey` on Windows, `XGrabKey` on X11) and saves them only once bound. One the system refuses (on Windows and X11, another app holding it) is not saved and the old one stays bound; one saved but refused as magpie starts is retried after a handed-over magpie exits and else said in the row (`panelKeysJSON.Taken`). A pressed shortcut toggles the panel as a tray click does (`togglePanel`). The Mac's Carbon hot keys don't refuse a combination another app registered too, so there both are taken and magpie can't tell the user. The shortcut is per computer (`KeepOwn`), and the Mac's old process lets go of it as it hands over (`leaveMenuBar`). On Wayland no app may grab keys itself, so the field is off and the row says the command to bind in the desktop's own keyboard settings (`magpie panel`); Wails' GlobalShortcuts portal is not used, since the compositor decides its keys and Hyprland binds none unless configured. From there a not-connected Claude Code's or Codex's opened row switches its account (shuizhuyu on X, [Switch accounts only](providers-accounts.md)).
|
||||
|
||||
+1
-1
@@ -1355,7 +1355,7 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
|
||||
in.MaskAlert = cur.MaskAlert
|
||||
}
|
||||
in.AgentOrder, in.AgentsHidden, in.AgentsShown = cur.AgentOrder, cur.AgentsHidden, cur.AgentsShown
|
||||
in.Window, in.WindowMaximised = cur.Window, cur.WindowMaximised // the window's own, as it was last resized
|
||||
in.Window, in.WindowMaximised, in.WindowAt = cur.Window, cur.WindowMaximised, cur.WindowAt // the window's own, as it was last resized and moved
|
||||
// and what other pages keep here: which models an agent is shown, and
|
||||
// everything the user said of a model anywhere else in the app, set on
|
||||
// its own. The per-model maps are carried whole rather than named one
|
||||
|
||||
@@ -83,8 +83,18 @@ func (h *host) makeMain(url string) *application.WebviewWindow {
|
||||
if s := settings.Load(); settle(&s, wd, ht, sw, sh, w.IsMaximised()) {
|
||||
settings.Save(s)
|
||||
}
|
||||
h.keepAt(w) // a resize by the top or left edge moves it too
|
||||
})
|
||||
})
|
||||
// A move is kept once it settles too (keepAt), so the window opens
|
||||
// where it was left after a restart, an update's included.
|
||||
var moved *time.Timer
|
||||
w.OnWindowEvent(events.Common.WindowDidMove, func(*application.WindowEvent) {
|
||||
if moved != nil {
|
||||
moved.Stop()
|
||||
}
|
||||
moved = time.AfterFunc(500*time.Millisecond, func() { h.keepAt(w) })
|
||||
})
|
||||
// Closing the window keeps the tray alive; quitting is a menu action.
|
||||
// One lightweight mode lets go is closed for good.
|
||||
w.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
|
||||
@@ -324,7 +334,8 @@ func showHere(w *application.WebviewWindow) {
|
||||
}
|
||||
|
||||
// placeMain puts the main window, made and not shown yet, as it was last
|
||||
// left; on the main thread, before its first Show. On Windows, a size kept
|
||||
// left; on the main thread, before its first Show. It goes back where it
|
||||
// was put (putBack). On Windows, a size kept
|
||||
// on a larger screen is fitted to this one's work area and centred: Windows
|
||||
// doesn't, and the title bar would be out of reach. Then, if it was
|
||||
// maximised, it is maximised again; on Linux it was made so (StartState),
|
||||
@@ -345,10 +356,12 @@ func showHere(w *application.WebviewWindow) {
|
||||
// to its own size, which the Mac fits to the screen again, so it couldn't
|
||||
// be restored at all.
|
||||
func (h *host) placeMain(w *application.WebviewWindow) {
|
||||
if h.placed.Swap(w) == w || runtime.GOOS == "linux" {
|
||||
if h.placed.Swap(w) == w {
|
||||
return
|
||||
}
|
||||
if w.IsMaximised() {
|
||||
// where it was left, on a screen there now (putBack)
|
||||
put := h.putBack(w)
|
||||
if runtime.GOOS == "linux" || w.IsMaximised() {
|
||||
return
|
||||
}
|
||||
wd, ht := w.Size()
|
||||
@@ -356,7 +369,9 @@ func (h *host) placeMain(w *application.WebviewWindow) {
|
||||
fw, fh, fitted := fitRoom(wd, ht, sw, sh)
|
||||
if fitted && runtime.GOOS == "windows" {
|
||||
w.SetSize(fw, fh)
|
||||
w.Center()
|
||||
if !put || !h.putBack(w) {
|
||||
w.Center()
|
||||
}
|
||||
fitted = false
|
||||
}
|
||||
if settings.Load().WindowMaximised && !fitted {
|
||||
@@ -366,6 +381,57 @@ func (h *host) placeMain(w *application.WebviewWindow) {
|
||||
}
|
||||
}
|
||||
|
||||
// putBack moves the main window, not shown yet, to where it was last left
|
||||
// (settings.WindowAt), whole on a screen there now (openAt), and says
|
||||
// whether it did; on the main thread. Nothing kept, or no screen there now
|
||||
// holding any of it, leaves it where the system put it, centred.
|
||||
func (h *host) putBack(w *application.WebviewWindow) bool {
|
||||
s, err := settings.LoadChecked()
|
||||
if err != nil || len(s.WindowAt) != 2 || !keepsPlace(runtime.GOOS, os.Getenv) {
|
||||
return false // an unreadable file is no place known
|
||||
}
|
||||
wd, ht := w.Size()
|
||||
x, y, ok := openAt(s.WindowAt, wd, ht, workAreas(h.app.Screen.GetAll()))
|
||||
if ok {
|
||||
w.SetPosition(x, y)
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
// keepAt keeps where the main window has been moved to (settleAt): only a
|
||||
// window placed and shown (placeMain), up, and not maximised, full screen
|
||||
// or minimised, which are the screen's place and not one the user gave it
|
||||
// (Windows puts a minimised window at -32000, -32000).
|
||||
func (h *host) keepAt(w *application.WebviewWindow) {
|
||||
if h.placed.Load() != w || !keepsPlace(runtime.GOOS, os.Getenv) || w.IsFullscreen() || w.IsMinimised() || w.IsMaximised() || !w.IsVisible() {
|
||||
return
|
||||
}
|
||||
if wd, _ := w.Size(); wd == 0 {
|
||||
return // let go by lightweight mode
|
||||
}
|
||||
x, y := w.Position()
|
||||
s, err := settings.LoadChecked()
|
||||
if err != nil {
|
||||
return // unreadable: left as it is, not written over
|
||||
}
|
||||
if settleAt(&s, x, y) {
|
||||
if err := settings.Save(s); err != nil {
|
||||
log.Println("window: keeping its place:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// workAreas is the screens' work areas as openAt takes them.
|
||||
func workAreas(screens []*application.Screen) []area {
|
||||
var out []area
|
||||
for _, sc := range screens {
|
||||
if sc != nil && sc.WorkArea.Width > 0 && sc.WorkArea.Height > 0 {
|
||||
out = append(out, area{sc.WorkArea.X, sc.WorkArea.Y, sc.WorkArea.Width, sc.WorkArea.Height})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// mainRoom is the work area of the screen the main window is on, in the
|
||||
// units of its Size, 0s when unknown: DIPs on Windows, points on the Mac,
|
||||
// where GetScreen gives it in pixels (Wails' cScreenToScreen; the Screen
|
||||
|
||||
@@ -176,6 +176,7 @@ func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) {
|
||||
UpdateMirror: "https://mirror.example/",
|
||||
Window: []int{900, 700},
|
||||
WindowMaximised: true,
|
||||
WindowAt: []int{-1440, 120},
|
||||
FullContext: true,
|
||||
DesktopLongest: true,
|
||||
GuideHidden: true,
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package gui
|
||||
|
||||
import "github.com/yetone/magpie/internal/settings"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// The main window opens as it was last left: at the size it was last given
|
||||
// (settings.Window) and maximised again if it was (settings.WindowMaximised).
|
||||
// (settings.Window), where it was last put (settings.WindowAt) and maximised
|
||||
// again if it was (settings.WindowMaximised).
|
||||
|
||||
// windowW, windowH is the main window's size, in points, before it is first
|
||||
// given one.
|
||||
@@ -75,3 +80,61 @@ func abs(n int) int {
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// area is a screen's work area, in the units and coordinates of the main
|
||||
// window's Position: x, y of its top left corner, width and height.
|
||||
type area struct{ x, y, w, h int }
|
||||
|
||||
// openAt is where the main window, w×h, opens: at the place it was last
|
||||
// left (saved: x, y), moved as little as it takes to lie whole on the work
|
||||
// area of the screen holding most of it now (areas). Not ok — left where the
|
||||
// system puts it, the middle of the screen — when no place was kept, or
|
||||
// no screen there now holds any of it: the screen it was on is gone, the
|
||||
// screens were laid out again, or none is known. A window larger than the
|
||||
// area keeps its top left corner in it, title bar in reach.
|
||||
func openAt(saved []int, w, h int, areas []area) (x, y int, ok bool) {
|
||||
if len(saved) != 2 || w <= 0 || h <= 0 {
|
||||
return 0, 0, false
|
||||
}
|
||||
x, y = saved[0], saved[1]
|
||||
best, most := area{}, 0
|
||||
for _, a := range areas {
|
||||
if n := overlap(x, w, a.x, a.w) * overlap(y, h, a.y, a.h); n > most {
|
||||
best, most = a, n
|
||||
}
|
||||
}
|
||||
if most == 0 {
|
||||
return 0, 0, false
|
||||
}
|
||||
return within(x, w, best.x, best.w), within(y, h, best.y, best.h), true
|
||||
}
|
||||
|
||||
// overlap is how much of the span from p, n long, lies in the one from
|
||||
// ap, an long.
|
||||
func overlap(p, n, ap, an int) int {
|
||||
return max(0, min(p+n, ap+an)-max(p, ap))
|
||||
}
|
||||
|
||||
// within is p moved as little as it takes for the span from it, n long, to
|
||||
// lie in the one from ap, an long; ap when it is the longer.
|
||||
func within(p, n, ap, an int) int {
|
||||
return max(ap, min(p, ap+an-n))
|
||||
}
|
||||
|
||||
// settleAt keeps in s the place the main window was left at, x, y, and
|
||||
// says whether s changed.
|
||||
func settleAt(s *settings.Settings, x, y int) bool {
|
||||
if len(s.WindowAt) == 2 && s.WindowAt[0] == x && s.WindowAt[1] == y {
|
||||
return false
|
||||
}
|
||||
s.WindowAt = []int{x, y}
|
||||
return true
|
||||
}
|
||||
|
||||
// keepsPlace says whether the main window's place can be read and set on
|
||||
// goos: not in a Wayland session (unless GTK is made to speak X11 there,
|
||||
// GDK_BACKEND=x11), where a window has no place it can know and the
|
||||
// compositor puts it where it likes; Wails reads 0, 0 there.
|
||||
func keepsPlace(goos string, getenv func(string) string) bool {
|
||||
return !waylandSession(goos, getenv) || strings.HasPrefix(getenv("GDK_BACKEND"), "x11")
|
||||
}
|
||||
|
||||
@@ -108,3 +108,85 @@ func TestSettle(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The window opens where it was left (jorbenzhu on Discord: back in the
|
||||
// middle after every update), moved whole onto a screen there now; with
|
||||
// no place kept, or its screen gone, it is left to the system's centre.
|
||||
func TestOpenAt(t *testing.T) {
|
||||
laptop := area{0, 25, 1512, 919} // a Mac's work area under the menu bar
|
||||
left := area{-1920, -200, 1920, 1040} // a monitor to its left, higher
|
||||
right := area{1512, 0, 2560, 1400} // one to its right
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
saved []int
|
||||
w, h int
|
||||
areas []area
|
||||
x, y int
|
||||
ok bool
|
||||
}{
|
||||
{"nothing kept", nil, 800, 600, []area{laptop}, 0, 0, false},
|
||||
{"malformed", []int{40}, 800, 600, []area{laptop}, 0, 0, false},
|
||||
{"no screen known", []int{100, 100}, 800, 600, nil, 0, 0, false},
|
||||
{"where it was", []int{300, 140}, 800, 600, []area{laptop}, 300, 140, true},
|
||||
{"on the left monitor", []int{-1500, -100}, 800, 600, []area{laptop, left}, -1500, -100, true},
|
||||
{"its monitor gone", []int{-1500, -100}, 800, 600, []area{laptop}, 0, 0, false},
|
||||
{"its right monitor gone", []int{2400, 300}, 800, 600, []area{laptop}, 0, 0, false},
|
||||
{"over the edge, onto the screen with most of it", []int{1300, 200}, 800, 600, []area{laptop, right}, 1512, 200, true},
|
||||
{"hanging off the bottom", []int{900, 700}, 800, 600, []area{laptop}, 712, 344, true},
|
||||
{"under the menu bar", []int{100, 0}, 800, 600, []area{laptop}, 100, 25, true},
|
||||
{"larger than the screen", []int{-50, 10}, 1600, 1000, []area{laptop}, 0, 25, true},
|
||||
{"no size", []int{100, 100}, 0, 0, []area{laptop}, 0, 0, false},
|
||||
} {
|
||||
x, y, ok := openAt(c.saved, c.w, c.h, c.areas)
|
||||
if x != c.x || y != c.y || ok != c.ok {
|
||||
t.Errorf("%s: openAt = %d, %d, %v; want %d, %d, %v", c.name, x, y, ok, c.x, c.y, c.ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Where the window was moved to is kept, and a move to the same place
|
||||
// writes nothing.
|
||||
func TestSettleAt(t *testing.T) {
|
||||
var s settings.Settings
|
||||
if !settleAt(&s, -1500, -100) || !slices.Equal(s.WindowAt, []int{-1500, -100}) {
|
||||
t.Fatalf("not kept: %v", s.WindowAt)
|
||||
}
|
||||
if settleAt(&s, -1500, -100) {
|
||||
t.Fatal("the same place counted as a change")
|
||||
}
|
||||
if !settleAt(&s, 0, 25) || !slices.Equal(s.WindowAt, []int{0, 25}) {
|
||||
t.Fatalf("a new place not kept: %v", s.WindowAt)
|
||||
}
|
||||
}
|
||||
|
||||
// A Wayland session can't place a window, so no place is kept or put
|
||||
// back there; X11, XWayland by GDK_BACKEND, the Mac and Windows can.
|
||||
func TestKeepsPlace(t *testing.T) {
|
||||
env := func(kv ...string) func(string) string {
|
||||
return func(k string) string {
|
||||
for i := 0; i+1 < len(kv); i += 2 {
|
||||
if kv[i] == k {
|
||||
return kv[i+1]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
goos string
|
||||
env func(string) string
|
||||
want bool
|
||||
}{
|
||||
{"mac", "darwin", env("WAYLAND_DISPLAY", "wayland-0"), true},
|
||||
{"windows", "windows", env(), true},
|
||||
{"x11", "linux", env("XDG_SESSION_TYPE", "x11", "DISPLAY", ":0"), true},
|
||||
{"wayland", "linux", env("XDG_SESSION_TYPE", "wayland", "WAYLAND_DISPLAY", "wayland-0"), false},
|
||||
{"wayland by its display alone", "linux", env("WAYLAND_DISPLAY", "wayland-0"), false},
|
||||
{"xwayland by GDK_BACKEND", "linux", env("XDG_SESSION_TYPE", "wayland", "GDK_BACKEND", "x11"), true},
|
||||
} {
|
||||
if got := keepsPlace(c.goos, c.env); got != c.want {
|
||||
t.Errorf("%s: keepsPlace = %v, want %v", c.name, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,14 +77,14 @@ func TestKeepAwakeKeptAndOwn(t *testing.T) {
|
||||
// a synced or restored bundle doesn't bring another's.
|
||||
func TestWindowMaximisedKeptAndOwn(t *testing.T) {
|
||||
from := Settings{}
|
||||
from.KeepOwn(Settings{Window: []int{900, 700}, WindowMaximised: true})
|
||||
if !from.WindowMaximised || len(from.Window) != 2 {
|
||||
t.Fatalf("KeepOwn dropped it: %v %v", from.Window, from.WindowMaximised)
|
||||
from.KeepOwn(Settings{Window: []int{900, 700}, WindowMaximised: true, WindowAt: []int{40, 60}})
|
||||
if !from.WindowMaximised || len(from.Window) != 2 || len(from.WindowAt) != 2 {
|
||||
t.Fatalf("KeepOwn dropped it: %v %v %v", from.Window, from.WindowMaximised, from.WindowAt)
|
||||
}
|
||||
from = Settings{Window: []int{1200, 800}, WindowMaximised: true}
|
||||
from = Settings{Window: []int{1200, 800}, WindowMaximised: true, WindowAt: []int{2560, 0}}
|
||||
from.KeepOwn(Settings{})
|
||||
if from.WindowMaximised || from.Window != nil {
|
||||
t.Fatalf("another computer's window here: %v %v", from.Window, from.WindowMaximised)
|
||||
if from.WindowMaximised || from.Window != nil || from.WindowAt != nil {
|
||||
t.Fatalf("another computer's window here: %v %v %v", from.Window, from.WindowMaximised, from.WindowAt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -848,6 +848,14 @@ type Settings struct {
|
||||
// when it last settled, so it opens maximised again; Window is still the
|
||||
// size it is restored to.
|
||||
WindowMaximised bool `json:"windowMaximised,omitempty"`
|
||||
// WindowAt is where the main window was last left, its top left corner
|
||||
// x and y in the system's coordinates across every screen (points on
|
||||
// the Mac, DIPs on Windows, X11's pixels on Linux), so it opens there
|
||||
// again after a restart rather than in the middle (jorbenzhu on
|
||||
// Discord). Kept only while it isn't maximised, full screen or
|
||||
// minimised; not at all under Wayland, where a window can't place
|
||||
// itself. gui's openAt moves it onto a screen there now.
|
||||
WindowAt []int `json:"windowAt,omitempty"`
|
||||
}
|
||||
|
||||
// ModelPrice is the price of one model as the user states it. Each part is a
|
||||
@@ -1172,8 +1180,8 @@ func (s Settings) Compact() int {
|
||||
}
|
||||
|
||||
// KeepOwn puts back cur's settings that are this computer's own, which a
|
||||
// sync or a restored backup never brings from another: the window's size
|
||||
// and whether it was maximised, the proxy, the gateway's port, whether it
|
||||
// sync or a restored backup never brings from another: the window's size,
|
||||
// place and whether it was maximised, the proxy, the gateway's port, whether it
|
||||
// is shared on the local network and the addresses let in to it, the
|
||||
// Dock, gateway mode, whether WSL is looked in, whether agents' sign-ins
|
||||
// are read, when allowances are read, the terminal app a session resumes
|
||||
@@ -1190,6 +1198,7 @@ func (s *Settings) KeepOwn(cur Settings) {
|
||||
s.DockNever, s.DockSettled = cur.DockNever, cur.DockSettled
|
||||
s.ProxyCustom = cur.ProxyCustom
|
||||
s.WindowMaximised, s.KeepAwake, s.KeepAwakeDisplay = cur.WindowMaximised, cur.KeepAwake, cur.KeepAwakeDisplay
|
||||
s.WindowAt = cur.WindowAt
|
||||
s.TrayUsages, s.TrayUsage, s.TrayUsageEvery, s.TrayNoLogos, s.TrayNoBird, s.TrayPace, s.TrayNoCost = cur.TrayUsages, cur.TrayUsage, cur.TrayUsageEvery, cur.TrayNoLogos, cur.TrayNoBird, cur.TrayPace, cur.TrayNoCost
|
||||
s.GatewayMode = cur.GatewayMode
|
||||
s.NoWSLAgents = cur.NoWSLAgents
|
||||
|
||||
Reference in New Issue
Block a user