Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
68 lines
2.3 KiB
Go
68 lines
2.3 KiB
Go
//go:build windows && (amd64 || arm64)
|
|
|
|
package windows
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"github.com/egoist/mygo/internal/platform"
|
|
)
|
|
|
|
// WindowStateBounds is the window's rectangle in the screen's pixels,
|
|
// which Bounds rounds through the scale of the window's display.
|
|
func (w *window) WindowStateBounds() platform.Rect {
|
|
var r rect
|
|
procGetWindowRect.Call(w.hwnd, uintptr(unsafe.Pointer(&r)))
|
|
return pixelRect(r)
|
|
}
|
|
|
|
// RestoreWindowState finds the display of a state's pixels, which its
|
|
// DIPs cannot tell when displays have different scales, and the window's
|
|
// size in that display's scale.
|
|
func (b *Backend) RestoreWindowState(o *platform.WindowOptions, pixels platform.Rect) bool {
|
|
r, ok := restoreStateBounds(pixels, platform.Size{Width: o.Width, Height: o.Height}, screenDisplays())
|
|
if !ok {
|
|
return false
|
|
}
|
|
o.StateBounds, o.Center = &r, false
|
|
return true
|
|
}
|
|
|
|
func pixelRect(r rect) platform.Rect {
|
|
return platform.Rect{X: int(r.Left), Y: int(r.Top), Width: int(r.Right - r.Left), Height: int(r.Bottom - r.Top)}
|
|
}
|
|
|
|
// restoreStateBounds places a window of size, in DIPs, at saved, in
|
|
// pixels, if enough of it shows on a display to reach it, as onDisplay
|
|
// decides in the core. Its size is in the scale of the display with the
|
|
// most of saved, whose scale Windows gives a window across displays.
|
|
func restoreStateBounds(saved platform.Rect, size platform.Size, displays []screenDisplay) (platform.Rect, bool) {
|
|
if saved.Width <= 0 || saved.Height <= 0 || size.Width <= 0 || size.Height <= 0 {
|
|
return platform.Rect{}, false
|
|
}
|
|
target, largest := -1, int64(0)
|
|
for i, d := range displays {
|
|
w, h := stateOverlap(saved, d.bounds)
|
|
if area := int64(w) * int64(h); area > largest {
|
|
target, largest = i, area
|
|
}
|
|
}
|
|
if target < 0 {
|
|
return platform.Rect{}, false
|
|
}
|
|
dpi := displays[target].dpi
|
|
r := platform.Rect{X: saved.X, Y: saved.Y, Width: int(toPx(size.Width, dpi)), Height: int(toPx(size.Height, dpi))}
|
|
for _, d := range displays {
|
|
w, h := stateOverlap(r, d.work)
|
|
if w >= int(toPx(min(100, size.Width), d.dpi)) && h >= int(toPx(min(50, size.Height), d.dpi)) {
|
|
return r, true
|
|
}
|
|
}
|
|
return platform.Rect{}, false
|
|
}
|
|
|
|
func stateOverlap(a, b platform.Rect) (int, int) {
|
|
return max(0, min(a.X+a.Width, b.X+b.Width)-max(a.X, b.X)),
|
|
max(0, min(a.Y+a.Height, b.Y+b.Height)-max(a.Y, b.Y))
|
|
}
|