NovaStudiosss wanted to watch Usage and Routing while working in other apps. The main window's toolbar now has a pin between Refresh and Settings. A click keeps the window above other apps' windows (Wails SetAlwaysOnTop through POST /api/window/ontop?on=1|0) and saves it as settings.json's onTop, which this computer keeps for itself (KeepOwn, not synced). makeMain opens the window pinned on the next start, and boot.js shows the pin pressed before the first paint. There is no pin in the panel, in a browser's page (magpie web) or under Wayland, where always-on-top is ignored (GDK_BACKEND=x11 keeps it). A refused pin goes back up. Tooltips "Keep on top" and "Stop keeping on top" are in every language. A Settings save keeps onTop (settingsapi.Merge), which a test showed was lost before. Run (rebased ona80a920f5): - go test -tags nogui ./internal/gui ./internal/settings ./internal/settingsapi on mica: ok. TestPinKeepsWindowOnTop, TestPinRefusedWithoutAWindowToPin, TestSetOnTop*, TestOnTopOwn and the settings-save keep test. - At the rebased head, TestPinRefused had served webHost through Handler and left webPage set, which turned TestSessionTitlesName- OtherAgents and TestCursorEditorChatsAreNotCalledCursorCLI red in a full package run. It now goes through webPageHandler, and the package is ok. TestWebPageHandlerEveryWhere misses a webHost passed in a variable. - window-pin.test.cjs (chromium + webkit, en zh zh-TW ja de) and i18n-keys: 36 pass. - Full GUI suite on mote (pre-rebase tree, still running at push): about 380 reds so far, none in window-pin. Seven of the red files (account-arrange, agent-details-ready, api-key-theme, bark, agent-switch-accounts, allow-ips, agent-bulk-visibility) were run on origin/main30de93e9e: 77 of the same reds, and none red only here. - go vet for darwin, windows, linux nogui and linux gtk3. Windows go test ./internal/gui ./internal/settings: ok. gofmt clean. - Broken by hand: without the route, or without renderOnTop, the Go and GUI tests go red. Without the Merge line the settings-save test goes red. - Real app on mote: with onTop saved, the main window opens at the floating level (CGWindowList layer 3, 0 unpinned). Not tried: clicking the pin in the real app (no Accessibility over ssh), a real Windows or Linux window, Wayland (hidden by design). At the default 660px window, the English tabs now scroll about 15px, as Japanese and German already did on main.
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
package gui
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"runtime"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// The main window's pin keeps it above other apps' windows, for Usage or
|
|
// Routing watched while working elsewhere (NovaStudiosss on X). The title
|
|
// bar's pin (app.js renderOnTop, shown where boot.js says pin) asks POST
|
|
// /api/window/ontop; the choice is this computer's own setting
|
|
// (settings.OnTop), put on the window as it is made (makeMain) and at once
|
|
// on the one showing.
|
|
|
|
// onTopper is a host whose main window can stay on top; a browser's page
|
|
// (magpie web) has no window of its own to pin.
|
|
type onTopper interface {
|
|
// SetOnTop puts the main window above other windows, or back among
|
|
// them.
|
|
SetOnTop(on bool)
|
|
}
|
|
|
|
// canOnTop says whether a window can keep itself above others on goos: not
|
|
// in a Wayland session, which has no way for an app to ask it (Wails sets
|
|
// _NET_WM_STATE_ABOVE, an X11 hint), unless GTK speaks X11 there
|
|
// (GDK_BACKEND=x11), as with the window's place (keepsPlace).
|
|
func canOnTop(goos string, getenv func(string) string) bool {
|
|
return keepsPlace(goos, getenv)
|
|
}
|
|
|
|
var errNoOnTop = errors.New("this window can't stay on top here")
|
|
|
|
// pinnable says whether w's main window can be pinned: the app's host
|
|
// (not a browser's page, magpie web's or the app's served to a browser) on
|
|
// a desktop that can keep a window on top.
|
|
func pinnable(w Windows) bool {
|
|
_, ok := w.(onTopper)
|
|
return ok && !isWeb(w) && canOnTop(runtime.GOOS, os.Getenv)
|
|
}
|
|
|
|
// pinMain saves the pin and puts it on the window; where the window can't
|
|
// be pinned (pinnable) nothing is saved.
|
|
func pinMain(w Windows, on bool) error {
|
|
if !pinnable(w) {
|
|
return errNoOnTop
|
|
}
|
|
p := w.(onTopper)
|
|
if err := settings.SetOnTop(on); err != nil {
|
|
return err
|
|
}
|
|
p.SetOnTop(on)
|
|
return nil
|
|
}
|