Files
openchamber-android-native/third_party/mygo/internal/platform/clicks.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
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.
2026-11-18 13:22:59 +08:00

42 lines
1.3 KiB
Go

package platform
import (
"math"
"time"
)
// DoubleClick is how far apart in time and on each axis two presses make
// a double click.
type DoubleClick struct {
Time time.Duration
DX, DY float64
}
// DefaultDoubleClick is the double click where the system tells none.
var DefaultDoubleClick = DoubleClick{Time: 500 * time.Millisecond, DX: 5, DY: 5}
// ClickCounter counts quick successive presses for a backend whose system
// reports no count with a press, by the system's double-click time and
// distance where it has them.
type ClickCounter struct {
ms uint32
x, y float64
button int
count int
}
// Press counts a press of button at x, y at ms, the event's time in
// milliseconds, which may wrap around as the system's does: one more than
// the last press's count when that press was of the same button and
// within d of it; else 1. The event's time rather than now's keeps presses
// waiting for a busy main thread as far apart as they were made.
func (c *ClickCounter) Press(button int, x, y float64, ms uint32, d DoubleClick) int {
if c.count > 0 && button == c.button && ms-c.ms <= uint32(d.Time.Milliseconds()) && math.Abs(x-c.x) <= d.DX && math.Abs(y-c.y) <= d.DY {
c.count++
} else {
c.count = 1
}
c.ms, c.x, c.y, c.button = ms, x, y, button
return c.count
}