forked from Blendman974/faceclaw
Merge remote-tracking branch 'upstream/main' into pr36-revive
This commit is contained in:
58 files changed
+2405
-952
No files matched your search
@@ -0,0 +1,22 @@
|
|||||||
|
name: Secret scan
|
||||||
|
|
||||||
|
# Scans for committed secrets on pushes to main and on pull requests.
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
gitleaks:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- uses: gitleaks/gitleaks-action@v2
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -17,3 +17,12 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm test
|
- run: npm test
|
||||||
|
|
||||||
|
# The shared Kotlin tests (tests/kotlin, on the JVM host). The runner image
|
||||||
|
# already carries the JDK 17 and Android SDK the build needs.
|
||||||
|
test-kotlin:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- run: npm ci
|
||||||
|
- run: npm run test:kotlin
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Secret-scanning config for the workflow in .github/workflows/secret-scan.yml.
|
||||||
|
[extend]
|
||||||
|
useDefault = true
|
||||||
|
|
||||||
|
[[rules]]
|
||||||
|
id = "generic-api-key"
|
||||||
|
[rules.allowlist]
|
||||||
|
description = "SIGN_KEY in even-api.ts is a client-side constant the app needs to sign EvenHub requests, not a credential."
|
||||||
|
paths = ['''app/apps/evenhub/even-api\.ts''']
|
||||||
@@ -10,6 +10,9 @@ import org.json.JSONArray
|
|||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
import java.util.Calendar
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads upcoming events from the Android Calendar provider for the Calendar
|
* Reads upcoming events from the Android Calendar provider for the Calendar
|
||||||
* app. Queries the Instances table (rather than Events) so that recurring
|
* app. Queries the Instances table (rather than Events) so that recurring
|
||||||
@@ -20,6 +23,7 @@ import org.json.JSONObject
|
|||||||
class FaceclawCalendarProvider private constructor() {
|
class FaceclawCalendarProvider private constructor() {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "FaceclawCalendar"
|
private const val TAG = "FaceclawCalendar"
|
||||||
|
private const val DAY_MS = 24L * 60 * 60 * 1000
|
||||||
|
|
||||||
private val PROJECTION = arrayOf(
|
private val PROJECTION = arrayOf(
|
||||||
CalendarContract.Instances.EVENT_ID,
|
CalendarContract.Instances.EVENT_ID,
|
||||||
@@ -31,10 +35,23 @@ class FaceclawCalendarProvider private constructor() {
|
|||||||
CalendarContract.Instances.CALENDAR_DISPLAY_NAME,
|
CalendarContract.Instances.CALENDAR_DISPLAY_NAME,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private class Event(
|
||||||
|
val id: Long,
|
||||||
|
val title: String,
|
||||||
|
val startMs: Long,
|
||||||
|
val endMs: Long,
|
||||||
|
val allDay: Boolean,
|
||||||
|
val location: String,
|
||||||
|
val calendarName: String,
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON array of upcoming events starting from now through now+windowMs,
|
* JSON array of events that haven't ended yet and start before
|
||||||
* ordered by start time, capped at maxEvents. Each element carries id,
|
* now+windowMs, ordered by start time, capped at maxEvents. Each
|
||||||
* title, startMs, endMs, allDay, location, and calendarName.
|
* element carries id, title, startMs, endMs, allDay, location, and
|
||||||
|
* calendarName. All-day events are reported as local-midnight
|
||||||
|
* boundaries (matching EventKit on iOS), not the UTC-midnight
|
||||||
|
* boundaries the provider stores them as.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getUpcomingEventsJson(context: Context?, maxEvents: Int, windowMs: Long): String {
|
fun getUpcomingEventsJson(context: Context?, maxEvents: Int, windowMs: Long): String {
|
||||||
@@ -45,12 +62,15 @@ class FaceclawCalendarProvider private constructor() {
|
|||||||
val end = now + Math.max(0L, windowMs)
|
val end = now + Math.max(0L, windowMs)
|
||||||
val limit = Math.min(200, maxEvents)
|
val limit = Math.min(200, maxEvents)
|
||||||
|
|
||||||
|
// The provider matches all-day instances by their UTC-midnight
|
||||||
|
// bounds, which can be up to a day away from the local day they
|
||||||
|
// represent; widen the query and filter after converting.
|
||||||
val builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
|
val builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
|
||||||
ContentUris.appendId(builder, now)
|
ContentUris.appendId(builder, now - DAY_MS)
|
||||||
ContentUris.appendId(builder, end)
|
ContentUris.appendId(builder, end + DAY_MS)
|
||||||
val uri = builder.build()
|
val uri = builder.build()
|
||||||
|
|
||||||
val out = JSONArray()
|
val events = ArrayList<Event>()
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = context.contentResolver.query(
|
cursor = context.contentResolver.query(
|
||||||
@@ -60,12 +80,20 @@ class FaceclawCalendarProvider private constructor() {
|
|||||||
null,
|
null,
|
||||||
CalendarContract.Instances.BEGIN + " ASC")
|
CalendarContract.Instances.BEGIN + " ASC")
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
while (cursor.moveToNext() && out.length() < limit) {
|
val utc = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
|
||||||
try {
|
val local = Calendar.getInstance()
|
||||||
out.put(buildEventJson(cursor))
|
// Rows arrive in raw-BEGIN order, but converting all-day
|
||||||
} catch (e: JSONException) {
|
// events moves them by less than a day. Once `limit`
|
||||||
Log.w(TAG, "failed to serialize calendar event", e)
|
// events are kept, nothing starting after the latest of
|
||||||
}
|
// them can make the cut, and no row whose raw BEGIN is a
|
||||||
|
// day past that can start before it.
|
||||||
|
var cutoff = Long.MAX_VALUE
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
if (cutoff != Long.MAX_VALUE && cursor.getLong(2) - DAY_MS > cutoff) break
|
||||||
|
val event = readEvent(cursor, utc, local)
|
||||||
|
if (event.endMs <= now || event.startMs > end || event.startMs > cutoff) continue
|
||||||
|
events.add(event)
|
||||||
|
if (events.size == limit) cutoff = events.maxOf { it.startMs }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: SecurityException) {
|
} catch (e: SecurityException) {
|
||||||
@@ -77,20 +105,62 @@ class FaceclawCalendarProvider private constructor() {
|
|||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
events.sortBy { it.startMs }
|
||||||
|
val out = JSONArray()
|
||||||
|
for (event in events.take(limit)) {
|
||||||
|
try {
|
||||||
|
out.put(buildEventJson(event))
|
||||||
|
} catch (e: JSONException) {
|
||||||
|
Log.w(TAG, "failed to serialize calendar event", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
return out.toString()
|
return out.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun readEvent(cursor: Cursor, utc: Calendar, local: Calendar): Event {
|
||||||
|
val allDay = cursor.getInt(4) != 0
|
||||||
|
var startMs = cursor.getLong(2)
|
||||||
|
var endMs = cursor.getLong(3)
|
||||||
|
if (allDay) {
|
||||||
|
startMs = utcMidnightToLocal(startMs, utc, local)
|
||||||
|
endMs = utcMidnightToLocal(endMs, utc, local)
|
||||||
|
}
|
||||||
|
return Event(
|
||||||
|
id = cursor.getLong(0),
|
||||||
|
title = if (cursor.isNull(1)) "" else cursor.getString(1),
|
||||||
|
startMs = startMs,
|
||||||
|
endMs = endMs,
|
||||||
|
allDay = allDay,
|
||||||
|
location = if (cursor.isNull(5)) "" else cursor.getString(5),
|
||||||
|
calendarName = if (cursor.isNull(6)) "" else cursor.getString(6),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All-day events are stored as UTC midnights (CalendarContract
|
||||||
|
* requires EVENT_TIMEZONE=UTC for them); re-anchor that calendar
|
||||||
|
* date to midnight in the device's timezone.
|
||||||
|
*/
|
||||||
|
private fun utcMidnightToLocal(utcMs: Long, utc: Calendar, local: Calendar): Long {
|
||||||
|
utc.timeInMillis = utcMs
|
||||||
|
local.timeZone = TimeZone.getDefault()
|
||||||
|
local.clear()
|
||||||
|
local.set(utc.get(Calendar.YEAR), utc.get(Calendar.MONTH), utc.get(Calendar.DAY_OF_MONTH))
|
||||||
|
return local.timeInMillis
|
||||||
|
}
|
||||||
|
|
||||||
@Throws(JSONException::class)
|
@Throws(JSONException::class)
|
||||||
private fun buildEventJson(cursor: Cursor): JSONObject {
|
private fun buildEventJson(event: Event): JSONObject {
|
||||||
val event = JSONObject()
|
val json = JSONObject()
|
||||||
event.put("id", cursor.getLong(0))
|
json.put("id", event.id)
|
||||||
event.put("title", if (cursor.isNull(1)) "" else cursor.getString(1))
|
json.put("title", event.title)
|
||||||
event.put("startMs", cursor.getLong(2))
|
json.put("startMs", event.startMs)
|
||||||
event.put("endMs", cursor.getLong(3))
|
json.put("endMs", event.endMs)
|
||||||
event.put("allDay", cursor.getInt(4) != 0)
|
json.put("allDay", event.allDay)
|
||||||
event.put("location", if (cursor.isNull(5)) "" else cursor.getString(5))
|
json.put("location", event.location)
|
||||||
event.put("calendarName", if (cursor.isNull(6)) "" else cursor.getString(6))
|
json.put("calendarName", event.calendarName)
|
||||||
return event
|
return json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 0.7.3 - Future
|
## 0.8.0 - 2026-09-26
|
||||||
|
|
||||||
### Depth and Animation
|
### Depth and Animation
|
||||||
|
|
||||||
* A new display-list system for glasses-side drawing, unlocking z-effects and animation
|
* A new display-list system for glasses-side drawing, unlocking z-effects and animation
|
||||||
* Menus animate when changing selection and scrolling
|
* Menus animate when changing selection and scrolling
|
||||||
* Menus bounce at the ends, and show part of the next row when there is more below
|
* Menus bounce at the ends, and show part of the next row when there is more below
|
||||||
|
* The launcher and Files app icon grids animate sliding, scrolling and bouncing
|
||||||
* Fade-in/out effects when turning the screen on/off
|
* Fade-in/out effects when turning the screen on/off
|
||||||
* Custom auto-brightness control algorithm, with configurable min, max and curve
|
* Custom auto-brightness control algorithm, with configurable min, max and curve
|
||||||
* Depth effects for the window switcher, top bar, and modals
|
* Depth effects for the window switcher, top bar, and modals
|
||||||
* Glanceboard has configurable distance
|
* Glanceboard has configurable distance
|
||||||
|
* Dimmed background behind the system context menu dithers rather than hiding minimum-brightness underlays
|
||||||
|
|
||||||
### Other Features and Bugfixes
|
### Other Features and Bugfixes
|
||||||
|
|
||||||
@@ -18,12 +20,28 @@
|
|||||||
* Navigate app: Add map-without-destination mode
|
* Navigate app: Add map-without-destination mode
|
||||||
* Nightscout app: Glanceboard widget still shows out-of-bounds values when out of space
|
* Nightscout app: Glanceboard widget still shows out-of-bounds values when out of space
|
||||||
* EvenHub: Fix login form being stuck open without a cancel button
|
* EvenHub: Fix login form being stuck open without a cancel button
|
||||||
|
* Calendar: Fix a timezone issue that could cause all-day events to appear on the preceding day
|
||||||
|
* Compass: Make the calibration readiness visible by default
|
||||||
|
* Terminal app: Tap a host heading to launch a shell there (alternative to the app context menu)
|
||||||
|
* Nightscout: Move the "Always show in top bar" setting earlier in the form so it's harder to miss
|
||||||
|
* EvenHub: Fix the sign-in form reopening on every launch after an unfinished sign-in
|
||||||
|
* EvenHub: Fix the installer not rerendering when an app finishes downloading
|
||||||
|
* Fix a frozen menu in the notification modal
|
||||||
|
* Fix a race when restoring open apps at startup, which could leave the previously-foreground window covering the new one
|
||||||
|
* Reduce phone CPU usage
|
||||||
|
* Fix a memory leak
|
||||||
|
* Better handling of silent mode
|
||||||
|
* Tweak the layout of the voice input dialog
|
||||||
|
* Add GitHub workflows for automated tests
|
||||||
|
|
||||||
### iOS port:
|
### iOS port:
|
||||||
|
|
||||||
* Add iOS calendar integration
|
* Add iOS calendar integration
|
||||||
* iOS main screen matches the Android version's styling
|
* iOS main screen matches the Android version's styling
|
||||||
* Hub apps on iOS no longer have their timers stopped while the phone app is in the background
|
* Hub apps on iOS no longer have their timers stopped while the phone app is in the background
|
||||||
|
* Some settings that were Android-only are now available on iOS
|
||||||
|
* Move a lot more of the iOS implementation onto shared Kotlin code
|
||||||
|
* Converted most Android-specific duplicative code to shared code
|
||||||
|
|
||||||
## 0.7.2 - 2026-09-19
|
## 0.7.2 - 2026-09-19
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import { cardinalDirection, createCompassBackground, drawCompassRose, layoutComp
|
|||||||
import { CompassCalibrationLayer } from "./calibration-layer";
|
import { CompassCalibrationLayer } from "./calibration-layer";
|
||||||
import { getDeclinationAvailability, onDeclinationChanged, refreshDeclination } from "./declination";
|
import { getDeclinationAvailability, onDeclinationChanged, refreshDeclination } from "./declination";
|
||||||
import { getNorthReference, resolveHeading, setNorthReference, type NorthReference } from "./heading";
|
import { getNorthReference, resolveHeading, setNorthReference, type NorthReference } from "./heading";
|
||||||
import { compassDebugLines, isCompassDebugEnabled, setCompassDebugEnabled } from "./debug";
|
|
||||||
|
|
||||||
export const COMPASS_WINDOW_ID = "compass";
|
export const COMPASS_WINDOW_ID = "compass";
|
||||||
export const COMPASS_SURFACE_ID = "window:compass";
|
export const COMPASS_SURFACE_ID = "window:compass";
|
||||||
@@ -92,11 +91,6 @@ class CompassLayer implements Layer {
|
|||||||
this.requestRender();
|
this.requestRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleDebugInfo(): void {
|
|
||||||
setCompassDebugEnabled(!isCompassDebugEnabled());
|
|
||||||
this.requestRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
stop(): void {
|
stop(): void {
|
||||||
if (this.removed) return;
|
if (this.removed) return;
|
||||||
this.removed = true;
|
this.removed = true;
|
||||||
@@ -162,17 +156,9 @@ class CompassLayer implements Layer {
|
|||||||
const headingText = heading === null ? "--°" : `${Math.round(heading)}° ${cardinalDirection(heading)}`;
|
const headingText = heading === null ? "--°" : `${Math.round(heading)}° ${cardinalDirection(heading)}`;
|
||||||
const statusLines = wrapText(small, this.statusText(), width - STACK_GAP * 2);
|
const statusLines = wrapText(small, this.statusText(), width - STACK_GAP * 2);
|
||||||
const smallStep = lineStep(small);
|
const smallStep = lineStep(small);
|
||||||
const debugLines = isCompassDebugEnabled() ? compassDebugLines(this.diagnostics) : [];
|
const headingFont = large.measureText(headingText) <= width - EDGE_PAD * 2 ? large : small;
|
||||||
const debugWidth = Math.max(0, ...debugLines.map((line) => small.measureText(line)));
|
const readoutWidth = headingFont.measureText(headingText);
|
||||||
const debugGap = debugLines.length ? 12 : 0;
|
const readoutHeight = headingFont.lineHeight;
|
||||||
// Keep diagnostics beside the heading even in narrow windows. The rose
|
|
||||||
// stays centred on the optical axis; the combined readout fits the viewport.
|
|
||||||
const headingFont = large.measureText(headingText) + debugGap + debugWidth <= width - EDGE_PAD * 2
|
|
||||||
? large : small;
|
|
||||||
const headingWidth = headingFont.measureText(headingText);
|
|
||||||
const readoutWidth = headingWidth + debugGap + debugWidth;
|
|
||||||
const debugHeight = debugLines.length ? (debugLines.length - 1) * smallStep + small.lineHeight : 0;
|
|
||||||
const readoutHeight = Math.max(headingFont.lineHeight, debugHeight);
|
|
||||||
|
|
||||||
// One column centred on the display's true centre, so the rose sits where
|
// One column centred on the display's true centre, so the rose sits where
|
||||||
// the wearer is looking rather than 32px right of it.
|
// the wearer is looking rather than 32px right of it.
|
||||||
@@ -204,17 +190,14 @@ class CompassLayer implements Layer {
|
|||||||
const image = this.background.image.clone();
|
const image = this.background.image.clone();
|
||||||
drawCompassRose(image, cx, cy, radius, heading);
|
drawCompassRose(image, cx, cy, radius, heading);
|
||||||
const readoutX = Math.round(Math.max(EDGE_PAD, Math.min(width - EDGE_PAD - readoutWidth, cx - readoutWidth / 2)));
|
const readoutX = Math.round(Math.max(EDGE_PAD, Math.min(width - EDGE_PAD - readoutWidth, cx - readoutWidth / 2)));
|
||||||
image.drawText(headingFont, readoutX, y + Math.floor((readoutHeight - headingFont.lineHeight) / 2),
|
image.drawText(headingFont, readoutX, y, headingText, heading === null ? 150 : 255);
|
||||||
headingText, heading === null ? 150 : 255);
|
|
||||||
for (let i = 0; i < debugLines.length; i++) {
|
|
||||||
image.drawText(small, readoutX + headingWidth + debugGap,
|
|
||||||
y + Math.floor((readoutHeight - debugHeight) / 2) + i * smallStep, debugLines[i]!, 175);
|
|
||||||
}
|
|
||||||
y += readoutHeight + 4;
|
y += readoutHeight + 4;
|
||||||
for (const line of statusLines) {
|
for (const line of statusLines) {
|
||||||
image.drawText(small, Math.round(cx - small.measureText(line) / 2), y, line, 125);
|
image.drawText(small, Math.round(cx - small.measureText(line) / 2), y, line, 125);
|
||||||
y += smallStep;
|
y += smallStep;
|
||||||
}
|
}
|
||||||
|
const accuracyText = magneticAccuracyText(this.diagnostics);
|
||||||
|
image.drawText(small, width - EDGE_PAD - small.measureText(accuracyText), TOP_PAD, accuracyText, 175);
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@@ -255,14 +238,6 @@ export function createCompassAppWindow(options: InProcessAppOptions): InProcessW
|
|||||||
layer.toggleNorthReference();
|
layer.toggleNorthReference();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: `Debug information: ${isCompassDebugEnabled() ? "On" : "Off"}`,
|
|
||||||
description: "Show magnetic accuracy (0–3), anomaly flags (0–2), and orientation source beside the heading.",
|
|
||||||
onSelect: (ctx) => {
|
|
||||||
ctx.stack.pop();
|
|
||||||
layer.toggleDebugInfo();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
baseLayer: new YieldAtRootLayer(layer),
|
baseLayer: new YieldAtRootLayer(layer),
|
||||||
submitFrame: options.submitFrame,
|
submitFrame: options.submitFrame,
|
||||||
@@ -299,3 +274,15 @@ function frameStatusText(): string {
|
|||||||
return "Magnetic heading - waiting for location";
|
return "Magnetic heading - waiting for location";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The firmware's magnetometer calibration readiness (0-3) as filled/empty
|
||||||
|
* dots, e.g. "Calibration: ●●○" for 2/3. This is the glasses' own sensor
|
||||||
|
* calibration, not the wearer-fit offset set on the calibration screen.
|
||||||
|
*/
|
||||||
|
function magneticAccuracyText(diagnostics: CompassDiagnostics | null): string {
|
||||||
|
const accuracy = diagnostics && (diagnostics.flags & 0x80) ? diagnostics.magneticAccuracy : -1;
|
||||||
|
if (accuracy < 0) return "Calibration: --";
|
||||||
|
const filled = Math.min(3, accuracy);
|
||||||
|
return `Calibration: ${"●".repeat(filled)}${"○".repeat(3 - filled)}`;
|
||||||
|
}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import type { CompassDiagnostics } from "../../native/compass";
|
|
||||||
import { getBooleanSetting, setBooleanSetting } from "../../native/settings-store";
|
|
||||||
|
|
||||||
const DEBUG_KEY = "compass.debugInfo";
|
|
||||||
|
|
||||||
export function isCompassDebugEnabled(): boolean {
|
|
||||||
return getBooleanSetting(DEBUG_KEY, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setCompassDebugEnabled(enabled: boolean): void {
|
|
||||||
setBooleanSetting(DEBUG_KEY, enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function compassDebugLines(diagnostics: CompassDiagnostics | null): string[] {
|
|
||||||
if (!diagnostics) return ["Diagnostics", "unavailable"];
|
|
||||||
if (!(diagnostics.flags & 0x80)) return ["Sample data", "unavailable"];
|
|
||||||
const accuracy = diagnostics.magneticAccuracy < 0 ? "--" : `${diagnostics.magneticAccuracy}/3`;
|
|
||||||
const anomalies = diagnostics.magneticAnomalies < 0 ? "--" : String(diagnostics.magneticAnomalies);
|
|
||||||
const source = ["--", "GRV", "GMRV", "RV"][diagnostics.orientationSource] ?? "--";
|
|
||||||
return [`Mag: ${accuracy}`, `Anom: ${anomalies}`, `Src: ${source}`];
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Application } from "@nativescript/core";
|
import { Application } from "@nativescript/core";
|
||||||
import { fetchWithUserAgent } from "../../util/http";
|
import { fetchWithUserAgent } from "../../util/http";
|
||||||
|
import { copyToJavaByteBuffer } from "../../native/java-direct-buffer";
|
||||||
|
|
||||||
declare const android: any;
|
declare const android: any;
|
||||||
declare const androidx: any;
|
declare const androidx: any;
|
||||||
@@ -93,8 +94,7 @@ async function downloadAndOpenPdf(url: string, appName: string, activity: any):
|
|||||||
const file = new java.io.File(directory, `policy-${hash.toString(16)}.pdf`);
|
const file = new java.io.File(directory, `policy-${hash.toString(16)}.pdf`);
|
||||||
const stream = new java.io.FileOutputStream(file);
|
const stream = new java.io.FileOutputStream(file);
|
||||||
try {
|
try {
|
||||||
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
stream.getChannel().write(copyToJavaByteBuffer(bytes));
|
||||||
stream.getChannel().write(buffer);
|
|
||||||
} finally {
|
} finally {
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
|
|||||||
+54
-316
@@ -2,10 +2,10 @@ import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
|||||||
import { truncateText, truncateLeft } from "../../graphics/textwrap";
|
import { truncateText, truncateLeft } from "../../graphics/textwrap";
|
||||||
import { GrayImage, type UiFont } from "../../graphics/image";
|
import { GrayImage, type UiFont } from "../../graphics/image";
|
||||||
import { renderIcon, type IconName } from "../../graphics/icons";
|
import { renderIcon, type IconName } from "../../graphics/icons";
|
||||||
import { clamp } from "../../util/numeric-util";
|
import { type MenuItem } from "../../ui/menu";
|
||||||
import { drawListScrollbar, drawSelectionHighlight, scrollToKeepSelectionVisible, type MenuItem } from "../../ui/menu";
|
|
||||||
import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
|
import { Menu, type MenuDrawArgs } from "../../ui/menu-core";
|
||||||
import { centeredTextY, iconGridMinRowHeight, tightRowHeight } from "../../ui/metrics";
|
import { IconGrid, ICON_GRID_ICON_SIZE } from "../../ui/icon-grid";
|
||||||
|
import { centeredTextY, tightRowHeight } from "../../ui/metrics";
|
||||||
import { ConfigSettingEnum } from "../../ui/dashboard-settings";
|
import { ConfigSettingEnum } from "../../ui/dashboard-settings";
|
||||||
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
import { getStringSetting, setStringSetting } from "../../native/settings-store";
|
||||||
import {
|
import {
|
||||||
@@ -16,9 +16,8 @@ import {
|
|||||||
statPath,
|
statPath,
|
||||||
type DirectoryEntry,
|
type DirectoryEntry,
|
||||||
} from "../../native/file-access";
|
} from "../../native/file-access";
|
||||||
import { directionalFallback, isWatchInput, type InputEvent } from "../../ui/gestures";
|
import { directionalFallback, type InputEvent } from "../../ui/gestures";
|
||||||
import { Layer, type LayerContext } from "../../ui/layers";
|
import { Layer, type LayerContext } from "../../ui/layers";
|
||||||
import { shell } from "../../ui/shell/shell";
|
|
||||||
|
|
||||||
const LIST_X = 20;
|
const LIST_X = 20;
|
||||||
/** List view: the selection box extends this far left and right of the row text. */
|
/** List view: the selection box extends this far left and right of the row text. */
|
||||||
@@ -29,10 +28,6 @@ function headerHeight(font: UiFont): number {
|
|||||||
return 10 + font.lineHeight;
|
return 10 + font.lineHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
const GRID_COLS = 5;
|
|
||||||
const ICON_SIZE = 44;
|
|
||||||
const LABEL_GAP = 2;
|
|
||||||
|
|
||||||
export type FilesViewMode = "icons" | "list";
|
export type FilesViewMode = "icons" | "list";
|
||||||
|
|
||||||
export const filesViewModeSetting = new ConfigSettingEnum<FilesViewMode>({
|
export const filesViewModeSetting = new ConfigSettingEnum<FilesViewMode>({
|
||||||
@@ -105,23 +100,14 @@ type EntryItem = {
|
|||||||
|
|
||||||
type BrowserItem = { kind: "grant"; label: string } | { kind: "info"; label: string } | EntryItem;
|
type BrowserItem = { kind: "grant"; label: string } | { kind: "info"; label: string } | EntryItem;
|
||||||
|
|
||||||
type IconRow =
|
|
||||||
| { kind: "special"; item: BrowserItem; flatIndex: number }
|
|
||||||
| { kind: "grid"; items: EntryItem[]; firstIndex: number };
|
|
||||||
|
|
||||||
type IconMode = "row" | "item";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filesystem browser with two views. The top "Places" level lists bookmarks
|
* Filesystem browser with two views. The top "Places" level lists bookmarks
|
||||||
* and the storage roots; descending browses real directories. Icons view is a
|
* and the storage roots; descending browses real directories. Icons view is
|
||||||
* 5-column grid with launcher-style two-level selection (scroll picks a row,
|
* the launcher's IconGrid (two-level ring selection, four-way watch
|
||||||
* click drops into the row, scroll picks the item); list view is a flat list.
|
* selection; notice rows span the full width); list view is a flat list.
|
||||||
* Click descends into a directory or picks a supported file; double-click
|
* Click descends into a directory or picks a supported file; double-click
|
||||||
* backs out one level (item selection, then parent directory, then Places,
|
* backs out one level (item selection, then parent directory, then Places,
|
||||||
* then leaving the browser). That is the ring's scheme; in icons view the
|
* then leaving the browser). Sized to its hosting stack.
|
||||||
* watch (see handleIconsWatchInput) skips row mode and moves one cell at a
|
|
||||||
* time in four directions, exactly as in the launcher. Sized to its hosting
|
|
||||||
* stack.
|
|
||||||
*/
|
*/
|
||||||
export class FileBrowserLayer implements Layer {
|
export class FileBrowserLayer implements Layer {
|
||||||
// Watch swipes are spatial in icons view: up/down move between rows,
|
// Watch swipes are spatial in icons view: up/down move between rows,
|
||||||
@@ -136,7 +122,7 @@ export class FileBrowserLayer implements Layer {
|
|||||||
private entries: DirectoryEntry[] | null = null;
|
private entries: DirectoryEntry[] | null = null;
|
||||||
private listingFailed = false;
|
private listingFailed = false;
|
||||||
|
|
||||||
/** List view. Its selected index is the flat-row index both views translate through (setViewMode). */
|
/** List view. Both views index the same flatRows(), which is how setViewMode carries the selection across. */
|
||||||
private readonly listMenu = new Menu<BrowserItem>({
|
private readonly listMenu = new Menu<BrowserItem>({
|
||||||
wrap: false,
|
wrap: false,
|
||||||
rowGap: 1,
|
rowGap: 1,
|
||||||
@@ -144,10 +130,18 @@ export class FileBrowserLayer implements Layer {
|
|||||||
getHeight: () => tightRowHeight(getDefaultSmallFont()),
|
getHeight: () => tightRowHeight(getDefaultSmallFont()),
|
||||||
draw: (args) => this.drawListRow(args),
|
draw: (args) => this.drawListRow(args),
|
||||||
});
|
});
|
||||||
private selectedRow = 0;
|
/** Icons view. */
|
||||||
private selectedCol = 0;
|
private readonly grid = new IconGrid<BrowserItem>({
|
||||||
private iconMode: IconMode = "row";
|
items: () => this.flatRows(),
|
||||||
private scrollRow = 0;
|
isWide: (item) => item.kind !== "entry",
|
||||||
|
describe: (item, selected) =>
|
||||||
|
item.kind === "entry"
|
||||||
|
? { label: item.label, icon: gridIcon(item), labelValue: item.supported ? 210 : 100 }
|
||||||
|
: { label: item.label, labelValue: itemValue(item, selected) },
|
||||||
|
onActivate: (item, _index, ctx) => this.activateItem(item, ctx),
|
||||||
|
onBack: () => this.navigateUp(),
|
||||||
|
scrollbar: true,
|
||||||
|
});
|
||||||
|
|
||||||
constructor(private readonly options: FileBrowserOptions) {}
|
constructor(private readonly options: FileBrowserOptions) {}
|
||||||
|
|
||||||
@@ -155,7 +149,6 @@ export class FileBrowserLayer implements Layer {
|
|||||||
const font = getDefaultSmallFont();
|
const font = getDefaultSmallFont();
|
||||||
const { width, height } = ctx.stack.getBaseSize();
|
const { width, height } = ctx.stack.getBaseSize();
|
||||||
const image = new GrayImage(width, height, 0);
|
const image = new GrayImage(width, height, 0);
|
||||||
const rows = this.flatRows();
|
|
||||||
|
|
||||||
image.drawText(font, 20, 8, "Files", 220);
|
image.drawText(font, 20, 8, "Files", 220);
|
||||||
const pathLabel = this.location === null ? "Places" : this.location;
|
const pathLabel = this.location === null ? "Places" : this.location;
|
||||||
@@ -163,17 +156,18 @@ export class FileBrowserLayer implements Layer {
|
|||||||
image.drawText(font, pathX, 8, truncateLeft(font, pathLabel, width - pathX - 20), 130);
|
image.drawText(font, pathX, 8, truncateLeft(font, pathLabel, width - pathX - 20), 130);
|
||||||
|
|
||||||
if (filesViewModeSetting.get() === "list") {
|
if (filesViewModeSetting.get() === "list") {
|
||||||
this.paintList(image, font, rows, ctx);
|
this.paintList(image, font, ctx);
|
||||||
} else {
|
} else {
|
||||||
this.paintIcons(image, font, rows, ctx);
|
const headerH = headerHeight(font);
|
||||||
|
this.grid.paint(image, { x: 0, y: headerH, width, height: height - headerH - 6 }, ctx.stack.isFocused());
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
private paintList(image: GrayImage, font: UiFont, rows: BrowserItem[], ctx: LayerContext): void {
|
private paintList(image: GrayImage, font: UiFont, ctx: LayerContext): void {
|
||||||
const { width, height } = ctx.stack.getBaseSize();
|
const { width, height } = ctx.stack.getBaseSize();
|
||||||
const headerH = headerHeight(font);
|
const headerH = headerHeight(font);
|
||||||
this.listMenu.setItems(rows);
|
this.listMenu.setItems(this.flatRows());
|
||||||
// Row boxes start one pixel above the header's bottom edge.
|
// Row boxes start one pixel above the header's bottom edge.
|
||||||
this.listMenu.paint(
|
this.listMenu.paint(
|
||||||
image,
|
image,
|
||||||
@@ -188,96 +182,19 @@ export class FileBrowserLayer implements Layer {
|
|||||||
image.drawText(font, x + LIST_HIGHLIGHT_PAD, centeredTextY(font, y, height), label, itemValue(item, selected));
|
image.drawText(font, x + LIST_HIGHLIGHT_PAD, centeredTextY(font, y, height), label, itemValue(item, selected));
|
||||||
}
|
}
|
||||||
|
|
||||||
private paintIcons(image: GrayImage, font: UiFont, rows: BrowserItem[], ctx: LayerContext): void {
|
|
||||||
const { width, height } = ctx.stack.getBaseSize();
|
|
||||||
const focused = ctx.stack.isFocused();
|
|
||||||
const iconRows = buildIconRows(rows);
|
|
||||||
this.selectedRow = clamp(this.selectedRow, 0, Math.max(0, iconRows.length - 1));
|
|
||||||
|
|
||||||
const gridTop = headerHeight(font);
|
|
||||||
const gridBottom = height - 6;
|
|
||||||
const visibleRows = Math.max(1, Math.floor((gridBottom - gridTop) / iconGridMinRowHeight(font, ICON_SIZE, LABEL_GAP)));
|
|
||||||
const rowH = Math.floor((gridBottom - gridTop) / visibleRows);
|
|
||||||
const colW = width / GRID_COLS;
|
|
||||||
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedRow, visibleRows, iconRows.length);
|
|
||||||
|
|
||||||
const lastVisible = Math.min(iconRows.length, this.scrollRow + visibleRows);
|
|
||||||
for (let rowIndex = this.scrollRow; rowIndex < lastVisible; rowIndex++) {
|
|
||||||
const row = iconRows[rowIndex]!;
|
|
||||||
const y = gridTop + (rowIndex - this.scrollRow) * rowH;
|
|
||||||
const selected = rowIndex === this.selectedRow;
|
|
||||||
|
|
||||||
if (row.kind === "special") {
|
|
||||||
const textY = y + (((rowH - font.lineHeight) / 2) | 0);
|
|
||||||
if (selected) {
|
|
||||||
drawSelectionHighlight(image, LIST_X - 6, textY - 2, width - 2 * LIST_X + 12, font.lineHeight + 4, focused, 4);
|
|
||||||
}
|
|
||||||
image.drawText(font, LIST_X, textY, truncateText(font, row.item.label, width - 2 * LIST_X), itemValue(row.item, selected));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selected) {
|
|
||||||
// Same preview rule as the launcher: while defocused with the watch
|
|
||||||
// as the last-used source, show the cell a click would land on (watch
|
|
||||||
// focus enters item mode directly; see onFocus) instead of a row band
|
|
||||||
// the watch scheme never shows.
|
|
||||||
const cellHighlight = this.iconMode === "item" || (!focused && shell.lastInputWasWatch());
|
|
||||||
if (cellHighlight) {
|
|
||||||
this.selectedCol = clamp(this.selectedCol, 0, row.items.length - 1);
|
|
||||||
drawSelectionHighlight(image, this.selectedCol * colW + 4, y + 1, colW - 8, rowH - 2, focused, 6);
|
|
||||||
} else {
|
|
||||||
drawSelectionHighlight(image, 4, y + 1, width - 8, rowH - 2, focused, 6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let col = 0; col < row.items.length; col++) {
|
|
||||||
const item = row.items[col]!;
|
|
||||||
const centerX = col * colW + colW / 2;
|
|
||||||
const blockTop = y + Math.max(2, (rowH - ICON_SIZE - font.lineHeight - LABEL_GAP) / 2);
|
|
||||||
const icon = renderIcon(item.icon, ICON_SIZE);
|
|
||||||
if (icon) {
|
|
||||||
image.bitBlt(item.supported ? icon : dimmedIcon(item.icon, icon), Math.round(centerX - icon.width / 2), Math.round(blockTop), {
|
|
||||||
transparentZero: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const label = truncateText(font, item.label, colW - 8);
|
|
||||||
const labelY = Math.round(blockTop + ICON_SIZE + LABEL_GAP);
|
|
||||||
image.drawText(font, Math.round(centerX - font.measureText(label) / 2), labelY, label, item.supported ? 210 : 100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iconRows.length > visibleRows) {
|
|
||||||
drawListScrollbar(image, width - 5, gridTop, visibleRows * rowH - 4, this.scrollRow, visibleRows, iconRows.length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||||
if (filesViewModeSetting.get() === "list") {
|
if (filesViewModeSetting.get() === "list") {
|
||||||
// The flat list has no spatial meaning for swipes; give them the
|
// The flat list has no spatial meaning for swipes; give them the
|
||||||
// standard scroll / select / back meanings (the layer opted into
|
// standard scroll / select / back meanings (the layer opted into
|
||||||
// directional delivery for the icons view, so the stack won't).
|
// directional delivery for the icons view, so the stack won't).
|
||||||
await this.handleListInput(directionalFallback(event), ctx);
|
await this.handleListInput(directionalFallback(event), ctx);
|
||||||
} else if (isWatchInput(event)) {
|
|
||||||
await this.handleIconsWatchInput(event, ctx);
|
|
||||||
} else {
|
} else {
|
||||||
await this.handleIconsInput(event, ctx);
|
await this.grid.handleInput(event, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Focus arriving from the watch goes straight to item selection, as in the
|
|
||||||
* launcher: the watch has left/right swipes, so it never needs row mode.
|
|
||||||
* Any other source keeps the two-level scheme and enters in row mode.
|
|
||||||
*/
|
|
||||||
onFocus(lastInput: InputEvent | null): void {
|
onFocus(lastInput: InputEvent | null): void {
|
||||||
if (filesViewModeSetting.get() !== "icons") return;
|
if (filesViewModeSetting.get() === "icons") this.grid.onFocus(lastInput);
|
||||||
if (lastInput && isWatchInput(lastInput)) {
|
|
||||||
this.iconMode = "item";
|
|
||||||
const iconRows = buildIconRows(this.flatRows());
|
|
||||||
this.clampColToRow(iconRows[clamp(this.selectedRow, 0, Math.max(0, iconRows.length - 1))]);
|
|
||||||
} else {
|
|
||||||
this.iconMode = "row";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleListInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
private async handleListInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||||
@@ -300,147 +217,6 @@ export class FileBrowserLayer implements Layer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async handleIconsInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
|
||||||
const rows = this.flatRows();
|
|
||||||
const iconRows = buildIconRows(rows);
|
|
||||||
this.selectedRow = clamp(this.selectedRow, 0, Math.max(0, iconRows.length - 1));
|
|
||||||
const row = iconRows[this.selectedRow];
|
|
||||||
switch (event.type) {
|
|
||||||
case "scroll-up":
|
|
||||||
case "scroll-down": {
|
|
||||||
const delta = event.type === "scroll-down" ? 1 : -1;
|
|
||||||
if (this.iconMode === "item") {
|
|
||||||
// Item selection traverses linearly: past a row's edge it continues
|
|
||||||
// onto the adjacent row (a special row counts as a single item).
|
|
||||||
if (row?.kind === "grid") {
|
|
||||||
const next = clamp(this.selectedCol, 0, row.items.length - 1) + delta;
|
|
||||||
if (next >= 0 && next < row.items.length) {
|
|
||||||
this.selectedCol = next;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const adjacentIndex = this.selectedRow + delta;
|
|
||||||
if (adjacentIndex < 0 || adjacentIndex >= iconRows.length) return;
|
|
||||||
this.selectedRow = adjacentIndex;
|
|
||||||
const adjacent = iconRows[adjacentIndex]!;
|
|
||||||
if (adjacent.kind === "grid") {
|
|
||||||
this.selectedCol = delta > 0 ? 0 : adjacent.items.length - 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.selectedRow = clamp(this.selectedRow + delta, 0, Math.max(0, iconRows.length - 1));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "click": {
|
|
||||||
if (!row) return;
|
|
||||||
if (row.kind === "special") {
|
|
||||||
await this.activateItem(row.item, ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.iconMode === "row") {
|
|
||||||
this.iconMode = "item";
|
|
||||||
// Default to the middle column (clamped to the row's item count).
|
|
||||||
this.selectedCol = Math.min(Math.floor(GRID_COLS / 2), row.items.length - 1);
|
|
||||||
} else {
|
|
||||||
const item = row.items[clamp(this.selectedCol, 0, row.items.length - 1)];
|
|
||||||
if (item) await this.activateItem(item, ctx);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "double-click":
|
|
||||||
if (this.iconMode === "item") {
|
|
||||||
this.iconMode = "row";
|
|
||||||
} else {
|
|
||||||
this.navigateUp();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The watch's scheme for the icons view — the launcher's: there is no row
|
|
||||||
* mode, the selection is always one cell (a special row counts as its
|
|
||||||
* single full-width item). Up/down (and the crown) move between rows
|
|
||||||
* keeping the column, right/left move within the row, and left from the
|
|
||||||
* leftmost column keeps going out — parent directory, Places, then the
|
|
||||||
* sidebar. Row mode is restored on the way out so a ring user finds the
|
|
||||||
* grid as they left it.
|
|
||||||
*/
|
|
||||||
private async handleIconsWatchInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
|
||||||
const iconRows = buildIconRows(this.flatRows());
|
|
||||||
this.selectedRow = clamp(this.selectedRow, 0, Math.max(0, iconRows.length - 1));
|
|
||||||
const row = iconRows[this.selectedRow];
|
|
||||||
if (this.iconMode === "row") {
|
|
||||||
this.iconMode = "item";
|
|
||||||
this.clampColToRow(row);
|
|
||||||
}
|
|
||||||
switch (event.type) {
|
|
||||||
case "swipe-up":
|
|
||||||
case "swipe-down":
|
|
||||||
case "scroll-up":
|
|
||||||
case "scroll-down": {
|
|
||||||
const delta = event.type === "swipe-down" || event.type === "scroll-down" ? 1 : -1;
|
|
||||||
this.selectedRow = clamp(this.selectedRow + delta, 0, Math.max(0, iconRows.length - 1));
|
|
||||||
// Keep the column; a shorter row (or a special one) clamps it.
|
|
||||||
this.clampColToRow(iconRows[this.selectedRow]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "swipe-right":
|
|
||||||
if (row?.kind === "grid") {
|
|
||||||
this.selectedCol = clamp(this.selectedCol + 1, 0, row.items.length - 1);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
case "swipe-left":
|
|
||||||
if (row?.kind === "grid" && this.selectedCol > 0) {
|
|
||||||
this.selectedCol--;
|
|
||||||
} else {
|
|
||||||
this.watchNavigateUp();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
case "click": {
|
|
||||||
if (!row) return;
|
|
||||||
if (row.kind === "special") {
|
|
||||||
await this.activateItem(row.item, ctx);
|
|
||||||
} else {
|
|
||||||
const item = row.items[clamp(this.selectedCol, 0, row.items.length - 1)];
|
|
||||||
if (item) await this.activateItem(item, ctx);
|
|
||||||
}
|
|
||||||
// Descending into a directory resets the selection for the ring (row
|
|
||||||
// mode at the top); the watch scheme stays in single-item selection.
|
|
||||||
this.iconMode = "item";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "double-click":
|
|
||||||
this.watchNavigateUp();
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private clampColToRow(row: IconRow | undefined): void {
|
|
||||||
if (row?.kind === "grid") {
|
|
||||||
this.selectedCol = clamp(this.selectedCol, 0, row.items.length - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* navigateUp for the watch scheme: inside the browser the selection stays
|
|
||||||
* in item mode (resetSelection/selectPath put it back in row mode for the
|
|
||||||
* ring); leaving from Places restores row mode on the way out.
|
|
||||||
*/
|
|
||||||
private watchNavigateUp(): void {
|
|
||||||
if (this.location === null) {
|
|
||||||
this.iconMode = "row";
|
|
||||||
this.options.onLeave();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.navigateUp();
|
|
||||||
this.iconMode = "item";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* App-specific entries for the window long-press menu: the view switch,
|
* App-specific entries for the window long-press menu: the view switch,
|
||||||
* plus bookmark/unbookmark for the selected entry (in icons view only once
|
* plus bookmark/unbookmark for the selected entry (in icons view only once
|
||||||
@@ -480,34 +256,23 @@ export class FileBrowserLayer implements Layer {
|
|||||||
this.listMenu.setItems(rows);
|
this.listMenu.setItems(rows);
|
||||||
return this.listMenu.selectedItem;
|
return this.listMenu.selectedItem;
|
||||||
}
|
}
|
||||||
const iconRows = buildIconRows(rows);
|
return this.grid.selectedItem;
|
||||||
const row = iconRows[clamp(this.selectedRow, 0, iconRows.length - 1)];
|
|
||||||
if (!row) return null;
|
|
||||||
if (row.kind === "special") return row.item;
|
|
||||||
if (this.iconMode !== "item") return null;
|
|
||||||
return row.items[clamp(this.selectedCol, 0, row.items.length - 1)] ?? null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private setViewMode(mode: FilesViewMode): void {
|
private setViewMode(mode: FilesViewMode): void {
|
||||||
if (filesViewModeSetting.get() === mode) return;
|
if (filesViewModeSetting.get() === mode) return;
|
||||||
const rows = this.flatRows();
|
this.listMenu.setItems(this.flatRows());
|
||||||
const iconRows = buildIconRows(rows);
|
|
||||||
this.listMenu.setItems(rows);
|
|
||||||
if (mode === "list") {
|
if (mode === "list") {
|
||||||
// Carry the icon-grid selection into the flat list (clamped column when
|
// Carry the icon-grid selection into the flat list (the remembered
|
||||||
// only a row was selected).
|
// column when only a row was selected).
|
||||||
const row = iconRows[clamp(this.selectedRow, 0, Math.max(0, iconRows.length - 1))];
|
const index = this.grid.cursorIndex;
|
||||||
if (row) {
|
if (index !== null) this.listMenu.select(index);
|
||||||
this.listMenu.select(
|
|
||||||
row.kind === "special" ? row.flatIndex : row.firstIndex + clamp(this.selectedCol, 0, row.items.length - 1),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.setGridSelectionFromFlatIndex(rows, this.listMenu.selectedIndex ?? 0);
|
const index = this.listMenu.selectedIndex ?? 0;
|
||||||
this.iconMode = "row";
|
this.grid.resetSelection();
|
||||||
|
this.grid.selectIndex(index);
|
||||||
}
|
}
|
||||||
filesViewModeSetting.set(mode);
|
filesViewModeSetting.set(mode);
|
||||||
this.scrollRow = 0;
|
|
||||||
this.listMenu.scrollTop = 0;
|
this.listMenu.scrollTop = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,11 +299,12 @@ export class FileBrowserLayer implements Layer {
|
|||||||
this.resetSelection();
|
this.resetSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private navigateUp(): void {
|
/** Back out one level; true when that left the browser (from Places). */
|
||||||
|
private navigateUp(): boolean {
|
||||||
const from = this.location;
|
const from = this.location;
|
||||||
if (from === null) {
|
if (from === null) {
|
||||||
this.options.onLeave();
|
this.options.onLeave();
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
if (from === this.navRoot || from === "/") {
|
if (from === this.navRoot || from === "/") {
|
||||||
this.location = null;
|
this.location = null;
|
||||||
@@ -546,20 +312,18 @@ export class FileBrowserLayer implements Layer {
|
|||||||
this.resetSelection();
|
this.resetSelection();
|
||||||
this.selectPath(this.navRoot ?? from);
|
this.selectPath(this.navRoot ?? from);
|
||||||
this.navRoot = null;
|
this.navRoot = null;
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
const parentRaw = from.slice(0, from.lastIndexOf("/"));
|
const parentRaw = from.slice(0, from.lastIndexOf("/"));
|
||||||
this.navigateTo(parentRaw.length ? parentRaw : "/");
|
this.navigateTo(parentRaw.length ? parentRaw : "/");
|
||||||
this.selectPath(from);
|
this.selectPath(from);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private resetSelection(): void {
|
private resetSelection(): void {
|
||||||
this.listMenu.select(0);
|
this.listMenu.select(0);
|
||||||
this.listMenu.scrollTop = 0;
|
this.listMenu.scrollTop = 0;
|
||||||
this.selectedRow = 0;
|
this.grid.resetSelection();
|
||||||
this.selectedCol = 0;
|
|
||||||
this.iconMode = "row";
|
|
||||||
this.scrollRow = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Select the item with the given path (e.g. the directory just left). */
|
/** Select the item with the given path (e.g. the directory just left). */
|
||||||
@@ -570,27 +334,17 @@ export class FileBrowserLayer implements Layer {
|
|||||||
// Items first, then the selection, so the viewport scrolls minimally from the top.
|
// Items first, then the selection, so the viewport scrolls minimally from the top.
|
||||||
this.listMenu.setItems(rows);
|
this.listMenu.setItems(rows);
|
||||||
this.listMenu.select(index);
|
this.listMenu.select(index);
|
||||||
this.setGridSelectionFromFlatIndex(rows, index);
|
this.grid.selectIndex(index);
|
||||||
}
|
|
||||||
|
|
||||||
private setGridSelectionFromFlatIndex(rows: BrowserItem[], index: number): void {
|
|
||||||
const specials = leadingSpecialCount(rows);
|
|
||||||
if (index < specials) {
|
|
||||||
this.selectedRow = index;
|
|
||||||
this.selectedCol = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const ordinal = index - specials;
|
|
||||||
this.selectedRow = specials + Math.floor(ordinal / GRID_COLS);
|
|
||||||
this.selectedCol = ordinal % GRID_COLS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private flatRows(): BrowserItem[] {
|
private flatRows(): BrowserItem[] {
|
||||||
const rows: BrowserItem[] = [];
|
const rows: BrowserItem[] = [];
|
||||||
if (!hasAllFilesAccess()) {
|
|
||||||
rows.push({ kind: "grant", label: "Grant file access (opens phone Settings)" });
|
|
||||||
}
|
|
||||||
if (this.location === null) {
|
if (this.location === null) {
|
||||||
|
// Only on Places: without All Files access some folders (e.g. Download)
|
||||||
|
// may still be readable, and the prompt shouldn't crowd their listings.
|
||||||
|
if (!hasAllFilesAccess()) {
|
||||||
|
rows.push({ kind: "grant", label: "Grant file access (opens phone Settings)" });
|
||||||
|
}
|
||||||
for (const path of getBookmarkedPaths()) {
|
for (const path of getBookmarkedPaths()) {
|
||||||
rows.push(this.bookmarkItem(path));
|
rows.push(this.bookmarkItem(path));
|
||||||
}
|
}
|
||||||
@@ -663,27 +417,6 @@ export class FileBrowserLayer implements Layer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildIconRows(flat: BrowserItem[]): IconRow[] {
|
|
||||||
const rows: IconRow[] = [];
|
|
||||||
let index = 0;
|
|
||||||
// Special rows (grant prompt, empty/unreadable info) lead the list; each
|
|
||||||
// gets a full-width row of its own. Entries follow, chunked into grid rows.
|
|
||||||
while (index < flat.length && flat[index]!.kind !== "entry") {
|
|
||||||
rows.push({ kind: "special", item: flat[index]!, flatIndex: index });
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
for (; index < flat.length; index += GRID_COLS) {
|
|
||||||
rows.push({ kind: "grid", items: flat.slice(index, index + GRID_COLS) as EntryItem[], firstIndex: index });
|
|
||||||
}
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
function leadingSpecialCount(rows: BrowserItem[]): number {
|
|
||||||
let count = 0;
|
|
||||||
while (count < rows.length && rows[count]!.kind !== "entry") count++;
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
function itemValue(item: BrowserItem, selected: boolean): number {
|
function itemValue(item: BrowserItem, selected: boolean): number {
|
||||||
if (item.kind === "info") return 120;
|
if (item.kind === "info") return 120;
|
||||||
if (item.kind === "grant") return selected ? 255 : 210;
|
if (item.kind === "grant") return selected ? 255 : 210;
|
||||||
@@ -691,6 +424,11 @@ function itemValue(item: BrowserItem, selected: boolean): number {
|
|||||||
return selected ? 255 : 200;
|
return selected ? 255 : 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function gridIcon(item: EntryItem): GrayImage | null {
|
||||||
|
const icon = renderIcon(item.icon, ICON_GRID_ICON_SIZE);
|
||||||
|
return icon && !item.supported ? dimmedIcon(item.icon, icon) : icon;
|
||||||
|
}
|
||||||
|
|
||||||
// Unsupported files draw their grid icon at half brightness; rendered once
|
// Unsupported files draw their grid icon at half brightness; rendered once
|
||||||
// per icon name and cached (all grid icons share one size).
|
// per icon name and cached (all grid icons share one size).
|
||||||
const dimmedIconCache = new Map<IconName, GrayImage>();
|
const dimmedIconCache = new Map<IconName, GrayImage>();
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import { truncateText } from "../../graphics/textwrap";
|
|||||||
import { GrayImage } from "../../graphics/image";
|
import { GrayImage } from "../../graphics/image";
|
||||||
import { type Plane } from "../../graphics/plane";
|
import { type Plane } from "../../graphics/plane";
|
||||||
import { renderIcon, type IconName } from "../../graphics/icons";
|
import { renderIcon, type IconName } from "../../graphics/icons";
|
||||||
import { clamp } from "../../util/numeric-util";
|
import { InputEvent } from "../../ui/gestures";
|
||||||
import { InputEvent, isWatchInput } from "../../ui/gestures";
|
import { IconGrid, ICON_GRID_ICON_SIZE } from "../../ui/icon-grid";
|
||||||
import { Layer, LayerActions, LayerContext } from "../../ui/layers";
|
import { Layer, LayerActions, LayerContext } from "../../ui/layers";
|
||||||
import { drawSelectionHighlight, MenuLayer, scrollToKeepSelectionVisible, type MenuItem } from "../../ui/menu";
|
import { MenuLayer, type MenuItem } from "../../ui/menu";
|
||||||
import { iconGridMinRowHeight } from "../../ui/metrics";
|
|
||||||
import { WINDOW_MENU_LAYOUT } from "../../ui/window-menu";
|
import { WINDOW_MENU_LAYOUT } from "../../ui/window-menu";
|
||||||
import { onAnySettingChanged } from "../../ui/dashboard-settings";
|
import { onAnySettingChanged } from "../../ui/dashboard-settings";
|
||||||
import { createInProcessWindow } from "../../ui/shell/in-process-window";
|
import { createInProcessWindow } from "../../ui/shell/in-process-window";
|
||||||
@@ -45,12 +44,7 @@ export type LauncherOptions = {
|
|||||||
export const LAUNCHER_WINDOW_ID = "launcher";
|
export const LAUNCHER_WINDOW_ID = "launcher";
|
||||||
export const LAUNCHER_SURFACE_ID = "window:launcher";
|
export const LAUNCHER_SURFACE_ID = "window:launcher";
|
||||||
|
|
||||||
const COLS = 5;
|
|
||||||
const GRID_TOP = 6;
|
const GRID_TOP = 6;
|
||||||
const ICON_SIZE = 44;
|
|
||||||
const LABEL_GAP = 2;
|
|
||||||
|
|
||||||
type LauncherMode = "row" | "item";
|
|
||||||
|
|
||||||
/** One cell of the grid: an app, or a folder holding some of the apps. */
|
/** One cell of the grid: an app, or a folder holding some of the apps. */
|
||||||
type LauncherGridEntry =
|
type LauncherGridEntry =
|
||||||
@@ -58,15 +52,11 @@ type LauncherGridEntry =
|
|||||||
| { kind: "folder"; label: string; name: string };
|
| { kind: "folder"; label: string; name: string };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The launcher grid: app and folder icons with labels, arranged in a grid.
|
* The launcher grid: app and folder icons with labels, in an IconGrid (which
|
||||||
* Navigation has two levels so the max number of swipes to any app is halved:
|
* owns layout, selection and the ring/watch navigation schemes). Opening a
|
||||||
* entering from the sidebar starts in "row" mode (scroll picks a row); a tap
|
* folder shows the same grid restricted to that folder's apps; backing out
|
||||||
* drops into "item" mode on that row, defaulting to the middle column (scroll
|
* of a folder returns to the top grid, and from the top grid yields to the
|
||||||
* picks the item); a tap launches an app or opens a folder (the same grid,
|
* sidebar.
|
||||||
* restricted to that folder's apps). Double-click backs out one level (item →
|
|
||||||
* row, folder → top grid), and from the top level yields to the sidebar.
|
|
||||||
* That is the ring's scheme; the watch (see handleWatchInput) skips row mode
|
|
||||||
* and moves one cell at a time in four directions.
|
|
||||||
*
|
*
|
||||||
* The folder grouping lives in the settings store (see launcher-folders.ts)
|
* The folder grouping lives in the settings store (see launcher-folders.ts)
|
||||||
* and is re-read every paint, so assistant folder tools take effect without
|
* and is re-read every paint, so assistant folder tools take effect without
|
||||||
@@ -78,28 +68,24 @@ class LauncherGridLayer implements Layer {
|
|||||||
// open folder if there is one, else yields to the sidebar — "left" points
|
// open folder if there is one, else yields to the sidebar — "left" points
|
||||||
// toward the sidebar all the way out.
|
// toward the sidebar all the way out.
|
||||||
readonly acceptsDirectional = true;
|
readonly acceptsDirectional = true;
|
||||||
private mode: LauncherMode = "row";
|
|
||||||
private selectedRow = 0;
|
|
||||||
private selectedCol = 1;
|
|
||||||
private scrollRow = 0;
|
|
||||||
/** Folder whose contents the grid is showing, or null for the top grid. */
|
/** Folder whose contents the grid is showing, or null for the top grid. */
|
||||||
private currentFolder: string | null = null;
|
private currentFolder: string | null = null;
|
||||||
|
private readonly grid = new IconGrid<LauncherGridEntry>({
|
||||||
|
items: () => this.entries(),
|
||||||
|
describe: (entry) => ({
|
||||||
|
label: entry.label,
|
||||||
|
icon: entry.kind === "app"
|
||||||
|
? entry.renderIcon?.(ICON_GRID_ICON_SIZE) ?? renderIcon(entry.icon, ICON_GRID_ICON_SIZE)
|
||||||
|
: renderIcon("folder-filled", ICON_GRID_ICON_SIZE),
|
||||||
|
}),
|
||||||
|
onActivate: (entry) => this.openEntry(entry),
|
||||||
|
onBack: () => this.back(),
|
||||||
|
});
|
||||||
|
|
||||||
constructor(private readonly options: LauncherOptions) {}
|
constructor(private readonly options: LauncherOptions) {}
|
||||||
|
|
||||||
/**
|
|
||||||
* Focus arriving from the watch goes straight to item selection: the watch
|
|
||||||
* has left/right swipes, so it never needs row mode (see handleWatchInput),
|
|
||||||
* and starting there would paint a row band its scheme can't produce. Any
|
|
||||||
* other source keeps the two-level scheme and enters in row mode.
|
|
||||||
*/
|
|
||||||
onFocus(lastInput: InputEvent | null): void {
|
onFocus(lastInput: InputEvent | null): void {
|
||||||
if (lastInput && isWatchInput(lastInput)) {
|
this.grid.onFocus(lastInput);
|
||||||
this.mode = "item";
|
|
||||||
this.selectedCol = clamp(this.selectedCol, 0, this.itemsInRow(this.entries().length, this.selectedRow) - 1);
|
|
||||||
} else {
|
|
||||||
this.mode = "row";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,22 +136,38 @@ class LauncherGridLayer implements Layer {
|
|||||||
return entries.sort((a, b) => a.label.localeCompare(b.label));
|
return entries.sort((a, b) => a.label.localeCompare(b.label));
|
||||||
}
|
}
|
||||||
|
|
||||||
private rowCount(entryCount: number): number {
|
|
||||||
return Math.max(1, Math.ceil(entryCount / COLS));
|
|
||||||
}
|
|
||||||
|
|
||||||
private itemsInRow(entryCount: number, row: number): number {
|
|
||||||
return Math.max(0, Math.min(COLS, entryCount - row * COLS));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Leave the current folder, putting the selection back on its cell. */
|
/** Leave the current folder, putting the selection back on its cell. */
|
||||||
private exitFolder(): void {
|
private exitFolder(): void {
|
||||||
const folder = this.currentFolder;
|
const folder = this.currentFolder;
|
||||||
this.currentFolder = null;
|
this.currentFolder = null;
|
||||||
this.mode = "row";
|
this.grid.resetSelection();
|
||||||
const index = this.entries().findIndex((entry) => entry.kind === "folder" && entry.name === folder);
|
const index = this.entries().findIndex((entry) => entry.kind === "folder" && entry.name === folder);
|
||||||
this.selectedRow = index >= 0 ? Math.floor(index / COLS) : 0;
|
if (index >= 0) this.grid.selectIndex(index);
|
||||||
this.selectedCol = index >= 0 ? index % COLS : 0;
|
}
|
||||||
|
|
||||||
|
/** Enter a folder or launch an app; true when that left the grid (a launch). */
|
||||||
|
private async openEntry(entry: LauncherGridEntry): Promise<boolean> {
|
||||||
|
if (entry.kind === "folder") {
|
||||||
|
this.currentFolder = entry.name;
|
||||||
|
this.grid.resetSelection();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Return to the top grid before launching, so the launcher never
|
||||||
|
// shows (even briefly) stale folder contents when re-entered.
|
||||||
|
if (this.currentFolder !== null) this.exitFolder();
|
||||||
|
this.grid.enterRowMode();
|
||||||
|
await this.options.launchApp(entry.appId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Leave the open folder, else yield to the sidebar; true when that left the grid. */
|
||||||
|
private back(): boolean {
|
||||||
|
if (this.currentFolder !== null) {
|
||||||
|
this.exitFolder();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
shell.yieldFocusToSidebar();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -174,8 +176,7 @@ class LauncherGridLayer implements Layer {
|
|||||||
* so anywhere else the menu falls back to just the defaults.
|
* so anywhere else the menu falls back to just the defaults.
|
||||||
*/
|
*/
|
||||||
menuItems(): MenuItem[] {
|
menuItems(): MenuItem[] {
|
||||||
if (this.mode !== "item") return [];
|
const entry = this.grid.selectedItem;
|
||||||
const entry = this.entries()[this.selectedRow * COLS + this.selectedCol];
|
|
||||||
if (!entry || entry.kind !== "app") return [];
|
if (!entry || entry.kind !== "app") return [];
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -202,7 +203,7 @@ class LauncherGridLayer implements Layer {
|
|||||||
confirmCtx.stack.pop();
|
confirmCtx.stack.pop();
|
||||||
setAppFolder(entry.appId, null);
|
setAppFolder(entry.appId, null);
|
||||||
await this.options.uninstallApp(entry.appId);
|
await this.options.uninstallApp(entry.appId);
|
||||||
this.mode = "row";
|
this.grid.enterRowMode();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ label: "Cancel", onSelect: (confirmCtx) => confirmCtx.stack.pop() },
|
{ label: "Cancel", onSelect: (confirmCtx) => confirmCtx.stack.pop() },
|
||||||
@@ -257,246 +258,23 @@ class LauncherGridLayer implements Layer {
|
|||||||
const font = getDefaultSmallFont();
|
const font = getDefaultSmallFont();
|
||||||
const { width, height } = ctx.stack.getBaseSize();
|
const { width, height } = ctx.stack.getBaseSize();
|
||||||
const image = new GrayImage(width, height, 0);
|
const image = new GrayImage(width, height, 0);
|
||||||
const focused = ctx.stack.isFocused();
|
|
||||||
const entries = this.entries();
|
|
||||||
const rows = this.rowCount(entries.length);
|
|
||||||
this.selectedRow = clamp(this.selectedRow, 0, rows - 1);
|
|
||||||
this.selectedCol = clamp(
|
|
||||||
this.selectedCol,
|
|
||||||
0,
|
|
||||||
Math.max(0, this.itemsInRow(entries.length, this.selectedRow) - 1),
|
|
||||||
);
|
|
||||||
|
|
||||||
// The folder-name header band scales with the font.
|
// The folder-name header band scales with the font.
|
||||||
const gridTop = this.currentFolder !== null ? GRID_TOP + font.lineHeight + 4 : GRID_TOP;
|
const gridTop = this.currentFolder !== null ? GRID_TOP + font.lineHeight + 4 : GRID_TOP;
|
||||||
if (this.currentFolder !== null) {
|
if (this.currentFolder !== null) {
|
||||||
image.drawText(font, 8, GRID_TOP - 2, truncateText(font, this.currentFolder, width - 16), 160);
|
image.drawText(font, 8, GRID_TOP - 2, truncateText(font, this.currentFolder, width - 16), 160);
|
||||||
}
|
}
|
||||||
const gridBottom = height - 4;
|
const gridBottom = height - 4;
|
||||||
// Rows are exactly as tall as their content (icon + label + breathing
|
this.grid.paint(image, { x: 0, y: gridTop, width, height: gridBottom - gridTop }, ctx.stack.isFocused());
|
||||||
// room), so row height tracks the font instead of stretching to fill the
|
|
||||||
// viewport. Leftover space below the last full row shows the top of the
|
|
||||||
// next row when there are more apps to scroll to.
|
|
||||||
const rowH = iconGridMinRowHeight(font, ICON_SIZE, LABEL_GAP);
|
|
||||||
const fullRows = Math.max(1, Math.floor((gridBottom - gridTop) / rowH));
|
|
||||||
const colW = width / COLS;
|
|
||||||
|
|
||||||
// Scroll to keep the selected row among the fully-visible rows.
|
|
||||||
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedRow, fullRows, rows);
|
|
||||||
|
|
||||||
const rowY = (row: number) => gridTop + (row - this.scrollRow) * rowH;
|
|
||||||
|
|
||||||
// Selection highlight: a row band, or a single cell in item mode. While
|
|
||||||
// defocused with the watch as the last-used source, the cell outline is
|
|
||||||
// shown even in row mode: watch focus enters item mode directly (see
|
|
||||||
// onFocus), so the outline previews the cell a click would land on
|
|
||||||
// rather than a row band the watch scheme never shows.
|
|
||||||
const cellHighlight = this.mode === "item" || (!focused && shell.lastInputWasWatch());
|
|
||||||
const selY = rowY(this.selectedRow);
|
|
||||||
if (cellHighlight) {
|
|
||||||
drawSelectionHighlight(image, this.selectedCol * colW + 6, selY + 2, colW - 12, rowH - 4, focused, 6);
|
|
||||||
} else {
|
|
||||||
drawSelectionHighlight(image, 4, selY + 2, width - 8, rowH - 4, focused, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let index = 0; index < entries.length; index++) {
|
|
||||||
const entry = entries[index]!;
|
|
||||||
const row = Math.floor(index / COLS);
|
|
||||||
if (row < this.scrollRow) continue;
|
|
||||||
const blockTop = rowY(row) + Math.max(2, (rowH - ICON_SIZE - font.lineHeight - LABEL_GAP) / 2);
|
|
||||||
if (blockTop >= gridBottom) break; // fully below the grid
|
|
||||||
const centerX = (index % COLS) * colW + colW / 2;
|
|
||||||
const icon = entry.kind === "app"
|
|
||||||
? entry.renderIcon?.(ICON_SIZE) ?? renderIcon(entry.icon, ICON_SIZE)
|
|
||||||
: renderIcon("folder-filled", ICON_SIZE);
|
|
||||||
if (icon) {
|
|
||||||
// Clip the icon at the grid bottom so a peeking row shows only its top.
|
|
||||||
// A fully visible icon goes through the deferred-image path (texture
|
|
||||||
// cacheable); the clipped peeking row falls back to a raster blit,
|
|
||||||
// since cached draws are whole-image only.
|
|
||||||
// Icons narrower/shorter than ICON_SIZE (a non-square logo scaled to
|
|
||||||
// fit) are centered in the square the row reserves for them.
|
|
||||||
const iconX = Math.round(centerX - icon.width / 2);
|
|
||||||
const iconY = Math.round(blockTop + Math.max(0, (ICON_SIZE - icon.height) / 2));
|
|
||||||
const clipHeight = Math.min(icon.height, Math.floor(gridBottom - iconY));
|
|
||||||
if (clipHeight >= icon.height) {
|
|
||||||
image.drawImage(icon, iconX, iconY);
|
|
||||||
} else if (clipHeight > 0) {
|
|
||||||
image.bitBlt(icon, iconX, iconY, { height: clipHeight, transparentZero: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const labelY = Math.round(blockTop + ICON_SIZE + LABEL_GAP);
|
|
||||||
if (labelY + font.lineHeight <= gridBottom) {
|
|
||||||
const label = truncateText(font, entry.label, colW - 8);
|
|
||||||
image.drawText(font, Math.round(centerX - font.measureText(label) / 2), labelY, label, 210);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||||
if (isWatchInput(event)) {
|
await this.grid.handleInput(event, ctx);
|
||||||
await this.handleWatchInput(event, ctx);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const entries = this.entries();
|
|
||||||
const rows = this.rowCount(entries.length);
|
|
||||||
switch (event.type) {
|
|
||||||
case "scroll-up":
|
|
||||||
case "scroll-down": {
|
|
||||||
const delta = event.type === "scroll-down" ? 1 : -1;
|
|
||||||
if (this.mode === "row") {
|
|
||||||
this.selectedRow = clamp(this.selectedRow + delta, 0, rows - 1);
|
|
||||||
} else {
|
|
||||||
// Item selection traverses the grid linearly: past a row's edge it
|
|
||||||
// continues onto the adjacent row (stopping at the grid's ends).
|
|
||||||
const itemCount = this.itemsInRow(entries.length, this.selectedRow);
|
|
||||||
const next = clamp(this.selectedCol, 0, itemCount - 1) + delta;
|
|
||||||
if (next >= 0 && next < itemCount) {
|
|
||||||
this.selectedCol = next;
|
|
||||||
} else if (next < 0 && this.selectedRow > 0) {
|
|
||||||
this.selectedRow--;
|
|
||||||
this.selectedCol = this.itemsInRow(entries.length, this.selectedRow) - 1;
|
|
||||||
} else if (next >= itemCount && this.selectedRow < rows - 1) {
|
|
||||||
this.selectedRow++;
|
|
||||||
this.selectedCol = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "click": {
|
|
||||||
if (this.mode === "row") {
|
|
||||||
this.mode = "item";
|
|
||||||
// Default to the middle column (clamped to the row's item count).
|
|
||||||
this.selectedCol = Math.min(
|
|
||||||
Math.floor(COLS / 2),
|
|
||||||
this.itemsInRow(entries.length, this.selectedRow) - 1,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
await this.openSelected(entries);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "double-click":
|
|
||||||
if (this.mode === "item") {
|
|
||||||
this.mode = "row";
|
|
||||||
} else if (this.currentFolder !== null) {
|
|
||||||
this.exitFolder();
|
|
||||||
} else {
|
|
||||||
shell.yieldFocusToSidebar();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** A touch on the phone's mirror opens the cell under it. */
|
||||||
* The watch's scheme: there is no row mode to enter first. The selection is
|
|
||||||
* always one cell; up/down/left/right (and the crown) move it spatially,
|
|
||||||
* select opens it, back leaves the folder or the grid, and stepping left
|
|
||||||
* past the first column leaves for the sidebar, which is where "left" goes.
|
|
||||||
* Row mode is restored on the way out so a ring user finds the grid as
|
|
||||||
* they left it.
|
|
||||||
*/
|
|
||||||
private async handleWatchInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
|
||||||
const entries = this.entries();
|
|
||||||
const rows = this.rowCount(entries.length);
|
|
||||||
if (this.mode === "row") {
|
|
||||||
this.mode = "item";
|
|
||||||
this.selectedCol = clamp(this.selectedCol, 0, this.itemsInRow(entries.length, this.selectedRow) - 1);
|
|
||||||
}
|
|
||||||
const leave = () => {
|
|
||||||
this.mode = "row";
|
|
||||||
shell.yieldFocusToSidebar();
|
|
||||||
};
|
|
||||||
switch (event.type) {
|
|
||||||
case "swipe-up":
|
|
||||||
case "swipe-down":
|
|
||||||
case "scroll-up":
|
|
||||||
case "scroll-down": {
|
|
||||||
const delta = event.type === "swipe-down" || event.type === "scroll-down" ? 1 : -1;
|
|
||||||
this.selectedRow = clamp(this.selectedRow + delta, 0, rows - 1);
|
|
||||||
// Keep the column; a shorter last row clamps it.
|
|
||||||
this.selectedCol = clamp(this.selectedCol, 0, this.itemsInRow(entries.length, this.selectedRow) - 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case "swipe-right":
|
|
||||||
this.selectedCol = clamp(this.selectedCol + 1, 0, this.itemsInRow(entries.length, this.selectedRow) - 1);
|
|
||||||
return;
|
|
||||||
case "swipe-left":
|
|
||||||
if (this.selectedCol > 0) {
|
|
||||||
this.selectedCol--;
|
|
||||||
} else if (this.currentFolder !== null) {
|
|
||||||
this.exitFolder();
|
|
||||||
this.mode = "item";
|
|
||||||
} else {
|
|
||||||
leave();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
case "click":
|
|
||||||
await this.openSelected(entries, true);
|
|
||||||
return;
|
|
||||||
case "double-click":
|
|
||||||
if (this.currentFolder !== null) {
|
|
||||||
this.exitFolder();
|
|
||||||
this.mode = "item";
|
|
||||||
} else {
|
|
||||||
leave();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A touch on the phone's mirror: the cell under it becomes the selection
|
|
||||||
* and opens (the same as a watch select on it). Uses the geometry paint
|
|
||||||
* lays the grid out with, so it lands on what the mirror showed.
|
|
||||||
*/
|
|
||||||
async hitTest(x: number, y: number, ctx: LayerContext): Promise<boolean> {
|
async hitTest(x: number, y: number, ctx: LayerContext): Promise<boolean> {
|
||||||
const font = getDefaultSmallFont();
|
return await this.grid.hitTest(x, y, ctx);
|
||||||
const { width, height } = ctx.stack.getBaseSize();
|
|
||||||
const entries = this.entries();
|
|
||||||
const gridTop = this.currentFolder !== null ? GRID_TOP + font.lineHeight + 4 : GRID_TOP;
|
|
||||||
const gridBottom = height - 4;
|
|
||||||
if (y < gridTop || y >= gridBottom || x < 0 || x >= width) return false;
|
|
||||||
const rowH = iconGridMinRowHeight(font, ICON_SIZE, LABEL_GAP);
|
|
||||||
const colW = width / COLS;
|
|
||||||
const row = this.scrollRow + Math.floor((y - gridTop) / rowH);
|
|
||||||
const col = Math.floor(x / colW);
|
|
||||||
if (row < 0 || row >= this.rowCount(entries.length)) return false;
|
|
||||||
if (col < 0 || col >= this.itemsInRow(entries.length, row)) return false;
|
|
||||||
this.mode = "item";
|
|
||||||
this.selectedRow = row;
|
|
||||||
this.selectedCol = col;
|
|
||||||
await this.openSelected(entries);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open the selected cell: enter a folder, or launch the app. A folder
|
|
||||||
* entered by watch input stays in single-item selection (the watch scheme
|
|
||||||
* has no row mode), starting at the folder's first cell.
|
|
||||||
*/
|
|
||||||
private async openSelected(entries: readonly LauncherGridEntry[], watch = false): Promise<void> {
|
|
||||||
const entry = entries[this.selectedRow * COLS + this.selectedCol];
|
|
||||||
if (!entry) return;
|
|
||||||
if (entry.kind === "folder") {
|
|
||||||
this.currentFolder = entry.name;
|
|
||||||
this.mode = watch ? "item" : "row";
|
|
||||||
this.selectedRow = 0;
|
|
||||||
this.selectedCol = watch ? 0 : this.selectedCol;
|
|
||||||
this.scrollRow = 0;
|
|
||||||
} else {
|
|
||||||
// Return to the top grid before launching, so the launcher never
|
|
||||||
// shows (even briefly) stale folder contents when re-entered.
|
|
||||||
if (this.currentFolder !== null) this.exitFolder();
|
|
||||||
this.mode = "row";
|
|
||||||
await this.options.launchApp(entry.appId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
* Terminal app, hosted in its own worker thread. Window model:
|
* Terminal app, hosted in its own worker thread. Window model:
|
||||||
* - "terminal:hub": the window opened from the launcher; shows the list of
|
* - "terminal:hub": the window opened from the launcher; shows the list of
|
||||||
* live g2mirror sessions across every connected host (grouped by host when
|
* live g2mirror sessions across every connected host (grouped by host when
|
||||||
* more than one is connected), and hosts the Manage Connections section
|
* more than one is connected; selecting a host's heading launches a shell
|
||||||
|
* there), and hosts the Manage Connections section
|
||||||
* where g2mirror:// connections are added, removed, and toggled.
|
* where g2mirror:// connections are added, removed, and toggled.
|
||||||
* - "terminal:view:N": opened by selecting a session in the hub; each has
|
* - "terminal:view:N": opened by selecting a session in the hub; each has
|
||||||
* its own websocket connection (the protocol allows one attached session
|
* its own websocket connection (the protocol allows one attached session
|
||||||
@@ -1047,10 +1048,7 @@ function windowMenuItems(window: TerminalWindow): MenuItem[] {
|
|||||||
label,
|
label,
|
||||||
onSelect: (ctx) => {
|
onSelect: (ctx) => {
|
||||||
ctx.stack.pop();
|
ctx.stack.pop();
|
||||||
launchAndOpenView(control, preset).catch((error) => {
|
launchFromUi(control, preset);
|
||||||
// The hub status line also shows the server's error message.
|
|
||||||
console.warn(`terminal launch ${preset} failed: ${error}`);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1180,7 +1178,10 @@ function applyHistoryReply(window: ViewWindow, reply: { start: number; oldest: n
|
|||||||
|
|
||||||
type HubItem = {
|
type HubItem = {
|
||||||
label: string;
|
label: string;
|
||||||
/** Group heading (host name): drawn differently and skipped by selection. */
|
/**
|
||||||
|
* Group heading (host name): drawn unindented and dimmer. Selectable only
|
||||||
|
* when it has an onSelect (launch a shell on that host).
|
||||||
|
*/
|
||||||
heading?: boolean;
|
heading?: boolean;
|
||||||
/** Session with recent output: an animated indicator marks the row. */
|
/** Session with recent output: an animated indicator marks the row. */
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
@@ -1210,7 +1211,7 @@ function hubMenu(window: HubWindow): Menu<HubItem> {
|
|||||||
function drawHubRow({ image, item, x, y, width, selected }: MenuDrawArgs<HubItem>): void {
|
function drawHubRow({ image, item, x, y, width, selected }: MenuDrawArgs<HubItem>): void {
|
||||||
const font = chromeFont();
|
const font = chromeFont();
|
||||||
if (item.heading) {
|
if (item.heading) {
|
||||||
image.drawText(font, x, y + HUB_ROW_TEXT_INSET, item.label, 140);
|
image.drawText(font, x, y + HUB_ROW_TEXT_INSET, item.label, selected ? 255 : 140);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Activity gutter, open-window number column, then the label, truncated
|
// Activity gutter, open-window number column, then the label, truncated
|
||||||
@@ -1282,9 +1283,14 @@ function hubSessionItems(window: HubWindow): HubItem[] {
|
|||||||
];
|
];
|
||||||
const connected = connectedControls();
|
const connected = connectedControls();
|
||||||
const multiHost = connected.length > 1;
|
const multiHost = connected.length > 1;
|
||||||
|
const canLaunch = launchPresetNames().length > 0;
|
||||||
for (const control of connected) {
|
for (const control of connected) {
|
||||||
if (multiHost) {
|
if (multiHost) {
|
||||||
items.push({ label: connectionDisplayName(control.config), heading: true });
|
items.push({
|
||||||
|
label: connectionDisplayName(control.config),
|
||||||
|
heading: true,
|
||||||
|
onSelect: canLaunch ? () => launchOnHost(window, control) : undefined,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const sessions = orderedSessions(window, control);
|
const sessions = orderedSessions(window, control);
|
||||||
for (const session of sessions) {
|
for (const session of sessions) {
|
||||||
@@ -1568,6 +1574,37 @@ function launchPresetNames(): string[] {
|
|||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A host heading in the hub was selected: launch a shell there. With a single
|
||||||
|
* launch preset it starts right away; with several, a submenu titled with the
|
||||||
|
* host's name picks which.
|
||||||
|
*/
|
||||||
|
function launchOnHost(window: HubWindow, control: ControlConnection): void {
|
||||||
|
const presets = launchPresetNames();
|
||||||
|
if (presets.length === 1) {
|
||||||
|
launchFromUi(control, presets[0]!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
windowMenu(window).open(
|
||||||
|
presets.map((preset) => ({
|
||||||
|
label: `Launch ${preset}`,
|
||||||
|
onSelect: (ctx) => {
|
||||||
|
ctx.stack.pop();
|
||||||
|
launchFromUi(control, preset);
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
connectionDisplayName(control.config),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Launch started from a menu or list row; failures only get logged. */
|
||||||
|
function launchFromUi(control: ControlConnection, preset: string): void {
|
||||||
|
launchAndOpenView(control, preset).catch((error) => {
|
||||||
|
// The hub status line also shows the server's error message.
|
||||||
|
console.warn(`terminal launch ${preset} failed: ${error}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** Launch a preset on a host and open a view window on the new session. */
|
/** Launch a preset on a host and open a view window on the new session. */
|
||||||
async function launchAndOpenView(control: ControlConnection, preset: string): Promise<string> {
|
async function launchAndOpenView(control: ControlConnection, preset: string): Promise<string> {
|
||||||
if (!control.client) throw new Error("Not connected to the g2mirror server.");
|
if (!control.client) throw new Error("Not connected to the g2mirror server.");
|
||||||
|
|||||||
@@ -510,7 +510,7 @@ class DashboardController {
|
|||||||
window.relayout();
|
window.relayout();
|
||||||
await this.configureWindowSurface(
|
await this.configureWindowSurface(
|
||||||
window.surfaceId,
|
window.surfaceId,
|
||||||
window.windowId === foregroundWindowId,
|
this.isForegroundWindow(window.windowId),
|
||||||
window.heightMode,
|
window.heightMode,
|
||||||
);
|
);
|
||||||
} else if (window.closeable) {
|
} else if (window.closeable) {
|
||||||
@@ -548,7 +548,7 @@ class DashboardController {
|
|||||||
void (async () => {
|
void (async () => {
|
||||||
for (const window of Array.from(shell.getWindows())) {
|
for (const window of Array.from(shell.getWindows())) {
|
||||||
if (!changed.includes(window.appId)) continue;
|
if (!changed.includes(window.appId)) continue;
|
||||||
await this.configureWindowSurface(window.surfaceId, window.windowId === shell.foregroundWindow()?.windowId, window.heightMode);
|
await this.configureWindowSurface(window.surfaceId, this.isForegroundWindow(window.windowId), window.heightMode);
|
||||||
window.relayout?.();
|
window.relayout?.();
|
||||||
}
|
}
|
||||||
shell.foregroundWindow()?.requestRender();
|
shell.foregroundWindow()?.requestRender();
|
||||||
@@ -560,12 +560,11 @@ class DashboardController {
|
|||||||
const position = verticalPositionSetting.get();
|
const position = verticalPositionSetting.get();
|
||||||
if (position === this.lastVerticalPosition) return;
|
if (position === this.lastVerticalPosition) return;
|
||||||
this.lastVerticalPosition = position;
|
this.lastVerticalPosition = position;
|
||||||
const foregroundWindowId = shell.foregroundWindow()?.windowId;
|
|
||||||
void (async () => {
|
void (async () => {
|
||||||
for (const window of shell.getWindows()) {
|
for (const window of shell.getWindows()) {
|
||||||
await this.configureWindowSurface(
|
await this.configureWindowSurface(
|
||||||
window.surfaceId,
|
window.surfaceId,
|
||||||
window.windowId === foregroundWindowId,
|
this.isForegroundWindow(window.windowId),
|
||||||
window.heightMode,
|
window.heightMode,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1021,7 +1020,13 @@ class DashboardController {
|
|||||||
return this.glassesDisplayLabel();
|
return this.glassesDisplayLabel();
|
||||||
}
|
}
|
||||||
if (this.silentMode && this.phase === "connected") {
|
if (this.silentMode && this.phase === "connected") {
|
||||||
return "Connected (Silent mode enabled)";
|
// Say how to leave it. Silent mode is entered and exited only by the
|
||||||
|
// same gesture on the glasses, the firmware ignores all input and blanks
|
||||||
|
// the display while it is on, and nothing here can turn it off -- there
|
||||||
|
// is no setter, only onSilentMode. So a user who triggered it by
|
||||||
|
// accident sees a connected pair of glasses that answers nothing, with
|
||||||
|
// no way to find out why. The instruction belongs where they are looking.
|
||||||
|
return "Connected (Silent mode — long-press both touchpads on the glasses to exit)";
|
||||||
}
|
}
|
||||||
// The preview compositor keeps the mirror live (including as a black
|
// The preview compositor keeps the mirror live (including as a black
|
||||||
// frame while the simulated screen is off), so never cover it.
|
// frame while the simulated screen is off), so never cover it.
|
||||||
@@ -1243,11 +1248,10 @@ class DashboardController {
|
|||||||
// loop re-applies the current dim from here.
|
// loop re-applies the current dim from here.
|
||||||
await target.setUnderlayDim(SHELL_SURFACE_Z_ORDER, 1);
|
await target.setUnderlayDim(SHELL_SURFACE_Z_ORDER, 1);
|
||||||
this.appliedUnderlayDim = 1;
|
this.appliedUnderlayDim = 1;
|
||||||
const foregroundWindowId = shell.foregroundWindow()?.windowId;
|
|
||||||
for (const window of shell.getWindows()) {
|
for (const window of shell.getWindows()) {
|
||||||
await this.configureWindowSurface(
|
await this.configureWindowSurface(
|
||||||
window.surfaceId,
|
window.surfaceId,
|
||||||
window.windowId === foregroundWindowId,
|
this.isForegroundWindow(window.windowId),
|
||||||
window.heightMode,
|
window.heightMode,
|
||||||
target,
|
target,
|
||||||
);
|
);
|
||||||
@@ -1532,11 +1536,10 @@ class DashboardController {
|
|||||||
await communicator.setUnderlayDim(SHELL_SURFACE_Z_ORDER, 1);
|
await communicator.setUnderlayDim(SHELL_SURFACE_Z_ORDER, 1);
|
||||||
this.appliedUnderlayDim = 1;
|
this.appliedUnderlayDim = 1;
|
||||||
await this.configureLockSurface(communicator);
|
await this.configureLockSurface(communicator);
|
||||||
const foregroundWindowId = shell.foregroundWindow()?.windowId;
|
|
||||||
for (const window of shell.getWindows()) {
|
for (const window of shell.getWindows()) {
|
||||||
await this.configureWindowSurface(
|
await this.configureWindowSurface(
|
||||||
window.surfaceId,
|
window.surfaceId,
|
||||||
window.windowId === foregroundWindowId,
|
this.isForegroundWindow(window.windowId),
|
||||||
window.heightMode,
|
window.heightMode,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -2270,8 +2273,7 @@ class DashboardController {
|
|||||||
reconfigureSurface: (heightMode) => {
|
reconfigureSurface: (heightMode) => {
|
||||||
// Resize the surface rect to the new band; a foreground window stays
|
// Resize the surface rect to the new band; a foreground window stays
|
||||||
// visible. The shell re-renders so the chrome (top bar) follows.
|
// visible. The shell re-renders so the chrome (top bar) follows.
|
||||||
const visible = shell.foregroundWindow()?.windowId === windowId;
|
void this.configureWindowSurface(surfaceId, this.isForegroundWindow(windowId), heightMode);
|
||||||
void this.configureWindowSurface(surfaceId, visible, heightMode);
|
|
||||||
this.requestShellRender();
|
this.requestShellRender();
|
||||||
},
|
},
|
||||||
onClosed: () => {
|
onClosed: () => {
|
||||||
@@ -2424,10 +2426,21 @@ class DashboardController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create/refresh a window surface on the compositor, if a display target exists. */
|
/**
|
||||||
|
* Create/refresh a window surface on the compositor, if a display target exists.
|
||||||
|
*
|
||||||
|
* `visible` may be a function, asked only after the surface is configured,
|
||||||
|
* right when the visibility call is queued. Callers that loop over windows
|
||||||
|
* or resize one in place must pass one (isForegroundWindow): the configure
|
||||||
|
* call yields, the foreground can change meanwhile, and a visibility decided
|
||||||
|
* before the await then lands AFTER the focus change's own calls, since the
|
||||||
|
* bridge runs Java calls in order. At startup, restoreOpenApps focuses
|
||||||
|
* windows while connect() registers surfaces, so a foreground read before
|
||||||
|
* that loop left the old window visible and the new foreground hidden.
|
||||||
|
*/
|
||||||
private async configureWindowSurface(
|
private async configureWindowSurface(
|
||||||
surfaceId: string,
|
surfaceId: string,
|
||||||
visible: boolean,
|
visible: boolean | (() => boolean),
|
||||||
heightMode: WindowHeightMode = "min",
|
heightMode: WindowHeightMode = "min",
|
||||||
// ensurePreviewDisplay passes its not-yet-published target explicitly.
|
// ensurePreviewDisplay passes its not-yet-published target explicitly.
|
||||||
target: DisplayTarget | null = this.display,
|
target: DisplayTarget | null = this.display,
|
||||||
@@ -2438,7 +2451,12 @@ class DashboardController {
|
|||||||
zOrder: 0,
|
zOrder: 0,
|
||||||
transparency: "opaque",
|
transparency: "opaque",
|
||||||
});
|
});
|
||||||
await target.setSurfaceVisible(surfaceId, visible);
|
await target.setSurfaceVisible(surfaceId, typeof visible === "function" ? visible() : visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A late answer to "is this window in front?", for configureWindowSurface. */
|
||||||
|
private isForegroundWindow(windowId: string): () => boolean {
|
||||||
|
return () => shell.foregroundWindow()?.windowId === windowId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeWindowSurface(surfaceId: string): void {
|
private removeWindowSurface(surfaceId: string): void {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export type FirmwareInfo = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** The Faceclaw firmware revision this build of the app needs. */
|
/** The Faceclaw firmware revision this build of the app needs. */
|
||||||
export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 34;
|
export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 35;
|
||||||
|
|
||||||
const FACECLAW_PREFIX = "Faceclaw/";
|
const FACECLAW_PREFIX = "Faceclaw/";
|
||||||
const LEGACY_PREFIX = "EVENCFW";
|
const LEGACY_PREFIX = "EVENCFW";
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ export type FirmwarePatchSet = {
|
|||||||
export const CFW_PATCH_SET: FirmwarePatchSet = {
|
export const CFW_PATCH_SET: FirmwarePatchSet = {
|
||||||
"base": "g2_2.3.0.24.bin",
|
"base": "g2_2.3.0.24.bin",
|
||||||
"baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979",
|
"baseSha256": "187ccf2bcc5c17a212106e8a376745511e8289c4232b634a7ea94b9bf25a0979",
|
||||||
"outputSha256": "7d8764f8b720252354dcd1695d23578b11f9b7cf5df9895d08b9f6668e9d0ee7",
|
"outputSha256": "d7971b68add0c5187fec81d1cb1ef8cc12322db426a98cb445f1b3a274272817",
|
||||||
"patches": [
|
"patches": [
|
||||||
{
|
{
|
||||||
"offset": 1045797,
|
"offset": 1045797,
|
||||||
"old": "38b584b0",
|
"old": "38b584b0",
|
||||||
"new": "5df3a9b8",
|
"new": "5df3b9b8",
|
||||||
"desc": "ring receiver entry: timestamped unfiltered reports under framebuffer lease"
|
"desc": "ring receiver entry: timestamped unfiltered reports under framebuffer lease"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -36,49 +36,49 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
|
|||||||
{
|
{
|
||||||
"offset": 1437923,
|
"offset": 1437923,
|
||||||
"old": "fef788ff",
|
"old": "fef788ff",
|
||||||
"new": "fdf2b8fd",
|
"new": "fdf2c8fd",
|
||||||
"desc": "cfw_ancs_event"
|
"desc": "cfw_ancs_event"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1437951,
|
"offset": 1437951,
|
||||||
"old": "fef7e8fb",
|
"old": "fef7e8fb",
|
||||||
"new": "fdf2f2fa",
|
"new": "fdf202fb",
|
||||||
"desc": "cfw_ancs_open"
|
"desc": "cfw_ancs_open"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1437969,
|
"offset": 1437969,
|
||||||
"old": "fef7e7fb",
|
"old": "fef7e7fb",
|
||||||
"new": "fdf209fb",
|
"new": "fdf219fb",
|
||||||
"desc": "cfw_ancs_close"
|
"desc": "cfw_ancs_close"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1388387,
|
"offset": 1388387,
|
||||||
"old": "39694d00",
|
"old": "39694d00",
|
||||||
"new": "59637d00",
|
"new": "79637d00",
|
||||||
"desc": "connection-bound ANCS EUS write callback"
|
"desc": "connection-bound ANCS EUS write callback"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 971497,
|
"offset": 971497,
|
||||||
"old": "fff717f8",
|
"old": "fff717f8",
|
||||||
"new": "6ff3d9f9",
|
"new": "6ff3e9f9",
|
||||||
"desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)"
|
"desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 971845,
|
"offset": 971845,
|
||||||
"old": "fef769ff",
|
"old": "fef769ff",
|
||||||
"new": "6ff32bf9",
|
"new": "6ff33bf9",
|
||||||
"desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)"
|
"desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 979579,
|
"offset": 979579,
|
||||||
"old": "fdf74ef8",
|
"old": "fdf74ef8",
|
||||||
"new": "6df310fa",
|
"new": "6df320fa",
|
||||||
"desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)"
|
"desc": "bl faceclaw_input_bridge_received (ring relay and ordered private transport before worker pool)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1428895,
|
"offset": 1428895,
|
||||||
"old": "f8f76cfd",
|
"old": "f8f76cfd",
|
||||||
"new": "fcf228fa",
|
"new": "fcf238fa",
|
||||||
"desc": "bl cfw_receive_packet (private SID-f0 probe before TPL reassembly)"
|
"desc": "bl cfw_receive_packet (private SID-f0 probe before TPL reassembly)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -108,145 +108,145 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
|
|||||||
{
|
{
|
||||||
"offset": 1248487,
|
"offset": 1248487,
|
||||||
"old": "d4f712fb",
|
"old": "d4f712fb",
|
||||||
"new": "2af3f2fa",
|
"new": "2af302fb",
|
||||||
"desc": "bl settings_send_wrapper (append caps field 100)"
|
"desc": "bl settings_send_wrapper (append caps field 100)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1246183,
|
"offset": 1246183,
|
||||||
"old": "f5f7e2f8",
|
"old": "f5f7e2f8",
|
||||||
"new": "2af376fc",
|
"new": "2af386fc",
|
||||||
"desc": "bl settings_decode_wrapper (Faceclaw lease field 101)"
|
"desc": "bl settings_decode_wrapper (Faceclaw lease field 101)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 975219,
|
"offset": 975219,
|
||||||
"old": "02f083fc",
|
"old": "02f083fc",
|
||||||
"new": "6cf3e2fc",
|
"new": "6cf3f2fc",
|
||||||
"desc": "bl faceclaw_display_start @ 0x467d68 (fail-open wake takeover)"
|
"desc": "bl faceclaw_display_start @ 0x467d68 (fail-open wake takeover)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 975411,
|
"offset": 975411,
|
||||||
"old": "02f023fc",
|
"old": "02f023fc",
|
||||||
"new": "6cf346fd",
|
"new": "6cf356fd",
|
||||||
"desc": "bl faceclaw_display_start_headup @ 0x467e28 (fail-open wake takeover)"
|
"desc": "bl faceclaw_display_start_headup @ 0x467e28 (fail-open wake takeover)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 975103,
|
"offset": 975103,
|
||||||
"old": "07f085fb",
|
"old": "07f085fb",
|
||||||
"new": "6ef3e2f9",
|
"new": "6ef3f2f9",
|
||||||
"desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)"
|
"desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 830549,
|
"offset": 830549,
|
||||||
"old": "19f03efb",
|
"old": "19f03efb",
|
||||||
"new": "91f391fb",
|
"new": "91f3a1fb",
|
||||||
"desc": "bl gesture_ring_press_mode (observe ring touch-down, preserve stock dispatch)"
|
"desc": "bl gesture_ring_press_mode (observe ring touch-down, preserve stock dispatch)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 830795,
|
"offset": 830795,
|
||||||
"old": "1ff071ff",
|
"old": "1ff071ff",
|
||||||
"new": "91f34afb",
|
"new": "91f35afb",
|
||||||
"desc": "bl gesture_press (owned event 9 before stock menu gate)"
|
"desc": "bl gesture_press (owned event 9 before stock menu gate)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 830887,
|
"offset": 830887,
|
||||||
"old": "1ff043ff",
|
"old": "1ff043ff",
|
||||||
"new": "91f344fb",
|
"new": "91f354fb",
|
||||||
"desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)"
|
"desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 831763,
|
"offset": 831763,
|
||||||
"old": "1ff08dfd",
|
"old": "1ff08dfd",
|
||||||
"new": "91f37af9",
|
"new": "91f38af9",
|
||||||
"desc": "bl gesture_release (owned event 10 before stock menu gate)"
|
"desc": "bl gesture_release (owned event 10 before stock menu gate)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1570209,
|
"offset": 1570209,
|
||||||
"old": "7fb50600",
|
"old": "7fb50600",
|
||||||
"new": "dbf283be",
|
"new": "dbf293be",
|
||||||
"desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline"
|
"desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1051545,
|
"offset": 1051545,
|
||||||
"old": "f6f787f9",
|
"old": "f6f787f9",
|
||||||
"new": "55f311f9",
|
"new": "55f321f9",
|
||||||
"desc": "bl display_copy_hook @ 0x47a78e (640x480 direct framebuffer)"
|
"desc": "bl display_copy_hook @ 0x47a78e (640x480 direct framebuffer)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1051861,
|
"offset": 1051861,
|
||||||
"old": "f6f7e9f8",
|
"old": "f6f7e9f8",
|
||||||
"new": "55f373f8",
|
"new": "55f383f8",
|
||||||
"desc": "bl display_copy_hook @ 0x47a8ca (640x480 direct framebuffer)"
|
"desc": "bl display_copy_hook @ 0x47a8ca (640x480 direct framebuffer)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1262237,
|
"offset": 1262237,
|
||||||
"old": "d9f7d0fd",
|
"old": "d9f7d0fd",
|
||||||
"new": "26f333fb",
|
"new": "26f343fb",
|
||||||
"desc": "bl faceclaw_send_wear_event @ 0x4ade92 (outside onboarding)"
|
"desc": "bl faceclaw_send_wear_event @ 0x4ade92 (outside onboarding)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1262337,
|
"offset": 1262337,
|
||||||
"old": "d9f79efd",
|
"old": "d9f79efd",
|
||||||
"new": "26f301fb",
|
"new": "26f311fb",
|
||||||
"desc": "bl faceclaw_send_wear_event @ 0x4adef6 (outside onboarding)"
|
"desc": "bl faceclaw_send_wear_event @ 0x4adef6 (outside onboarding)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1309405,
|
"offset": 1309405,
|
||||||
"old": "67f02dff",
|
"old": "67f02dff",
|
||||||
"new": "1af30bfc",
|
"new": "1af31bfc",
|
||||||
"desc": "bl compass_decode_capture (sample-matched GAF diagnostics)"
|
"desc": "bl compass_decode_capture (sample-matched GAF diagnostics)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1307865,
|
"offset": 1307865,
|
||||||
"old": "fff7c9fb",
|
"old": "fff7c9fb",
|
||||||
"new": "1af389ff",
|
"new": "1af399ff",
|
||||||
"desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)"
|
"desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 1300937,
|
"offset": 1300937,
|
||||||
"old": "00210170",
|
"old": "00210170",
|
||||||
"new": "1cf36ffc",
|
"new": "1cf37ffc",
|
||||||
"desc": "bl compass_preserve_accuracy (retain magnetic calibration under Faceclaw framebuffer lease)"
|
"desc": "bl compass_preserve_accuracy (retain magnetic calibration under Faceclaw framebuffer lease)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 4537963,
|
"offset": 4537963,
|
||||||
"old": "",
|
"old": "",
|
||||||
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc1b04ff62c484ef66c694ff29c5b1446cff6ff78ccf2ff09c2f2290b4ff6ff75002701260993cde90a0106e048f2a351c0f24501bff32f8f8847dbf800a0bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757007f0a6fa002800f0078241464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009086728583c583058445848584c584058545858585c585058645868586c586058745875be8001f51457ff436afbff35f8f4be8000121b15be8001f5145f8d02be70b99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847dbf80070bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757007f0caf9002800f02b8141464218463182f8d44382f8d54382f8d64382f8d74382f8d84382f8d94382f8da4382f8db4382f8dc4382f8dd4382f8de4382f8df4382f8e04382f8e14382f8e24382f8e34382f8e44382f8e54382f8e64382f8e74382f8e84382f8e94382f8ea4382f8eb4382f8ec4382f8ed4382f8ee4382f8ef4382f8f04382f8f14382f8f24382f8f34382f8f44382f8f54382f8f64382f8f74382f8f84382f8f94382f8fa4382f8fb4382f8fc4382f8fd4382f8fe4382f8ff4382f8004482f8014482f8024482f8034482f8044482f8054482f8064482f8074482f8084482f8094482f80a4482f80b4482f80c4482f80d4482f80e4482f80f4482f8104482f8114482f8124482f8134482f8144482f8154482f8164482f8174482f8184482f819447ff470afc0f8009086728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb9427ff436afbff35f8f4be8000121b15be8001fb942f8d02be7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f09d810b98002861d00a980778a7f1170002285bd80b980c2840f086810a9e7078b178084300f08081f0780138022800f27b81b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f01082172f40f02682002a40f06281fe2800f06d86812800f06086002840f0738651ea030040f0558100f0bdbe04460020b047e8b104f51d7151e800afbaf1000f0cd1bff35f8f00bf41e80002002a00f0f58051e800afbaf1000ff5d00021bff32f8f0029bff35f8f00f0e480824692e74ff0ff3737e147f6df40c0f24f008047002701240d97adf8387006e048f2a351c0f24501bff32f8f8847dbf80060bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0c1804ff4757007f070f8002800f0b98041464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009084728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb1427ff436afbff35f8f4be8000159b15be8001fb142f8d02be706f5a9718847ace6012110e700200a9999b10b9a8ab1097801f07f02b2f10b0618bf0126b2f11c0718bf01278a2924dc0b2926d01c2924d03fe009900ca804f097fa4ff0ff3701249df8390000280ca818bf4ff0ff3704f0d3fb054644b99df8380028b94af21f30c0f247004c3080470998002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010446884794f8641119b994f80413204669b14ff0ff3742f6f760c0f2440000f5807150468847384641b0bde8f08f09900ca806ea070404f055fa0a98017801f07f061e2e04d10b9908f076fb0746b5e71d2e01f07e0018bf1a2811d1dbf800100322cff680720a40b2f1005fbff35f8f0ad10a684a4504bf002281f8812303e0a6f115010129e9d90f2e0adc092e00f37381052e00f0ef82072e40f01c8300279ae0142e00f32182102e00f0eb82112e40f011830b98022841f0c6800a9908781Line truncated
|
"new": "b0b581ea00039b0701d0034637e0c2b110f0030315d000f1010ca2f1010e0023cc5c9e45c45403f1010404d0634413f003032346f4d121440319121b102a14d302e00346102a10d3d1f800c0d1f804e0cc688d68103adc609d60c3f804e043f810cb0f2a01f11001eed8042a07d300bf51f8045b043a032a43f8045bf8d8002a08bfb0bd0139013b11f8015f013a03f8015ff9d1b0bd00bf884218bf002a00d1704710b50b1a38bf431a934207d288420ad281ea00039b0726d0034669e0fff79fffbde81040704781ea000300eb020c9b0701eb020e42d15fea8c732bd0a0f1010c00bf8b1813f801ec8418531e04f801ec04d0624412f003021a46f2d101eb030e00eb030c17e0830736d0a2f1010c00f1010e002300bfcc5c9c45c45403f1010404d0734413f003032346f4d1121b2144031922e01346042b0ed3aef10402acf1040152f80449043b032b41f80449f8d802f1040e01f1040c1a4653b1aef10101acf1010300bf11f80149013a03f80149f9d1bde8104070470346042a06d351f8044b043a032a43f8044bf8d8002af0d00139013b00bf11f8014f013a03f8014ff9d1e6e700bf80b5002a18bf10f0030301d186460ce000f1010c864600bf013a0ef8011b04d01cf003030cf1010cf6d1102a11d35ffa81fc4ff001330cfb03fc00bf103acef80cc0cef808c0cef804c04ef810cb0f2af4d8042a0bd35ffa81fc4ff001330cfb03fc00bf043a032a4ef804cbfad8002a08bf80bdaef10103013a03f8011ffbd180bd00bf2de9f04fc5b04ff62c484ef66c694ff29c5b1446cff6ff78ccf2ff09c2f2290b4ff6ff75002701260d93cde90e0106e048f2a351c0f24501bff32f8f8847dbf800a0bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757007f0b6fa002800f0078241464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009086728583c583058445848584c584058545858585c585058645868586c586058745875be8001f51457ff436afbff35f8f4be8000121b15be8001f5145f8d02be70f99012641ea04410024c0f8701206e048f2a351c0f24501bff32f8f8847dbf80070bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0ba804ff4757007f0daf9002800f02b8141464218463182f8d44382f8d54382f8d64382f8d74382f8d84382f8d94382f8da4382f8db4382f8dc4382f8dd4382f8de4382f8df4382f8e04382f8e14382f8e24382f8e34382f8e44382f8e54382f8e64382f8e74382f8e84382f8e94382f8ea4382f8eb4382f8ec4382f8ed4382f8ee4382f8ef4382f8f04382f8f14382f8f24382f8f34382f8f44382f8f54382f8f64382f8f74382f8f84382f8f94382f8fa4382f8fb4382f8fc4382f8fd4382f8fe4382f8ff4382f8004482f8014482f8024482f8034482f8044482f8054482f8064482f8074482f8084482f8094482f80a4482f80b4482f80c4482f80d4482f80e4482f80f4482f8104482f8114482f8124482f8134482f8144482f8154482f8164482f8174482f8184482f819447ff470afc0f8009086728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb9427ff436afbff35f8f4be8000121b15be8001fb942f8d02be7d0f874a242f6f766c0f24406baf1000fbff35f8f4ad006f19a0250464ff0ff314ff0ff379047002840f09d810f98002861d00e980778a7f1170002285bd80f980c2840f086810e9e7078b178084300f08081f0780138022800f27b81b279f379747a42ea0322337a307942ea0342717942ea0463b27af67a192f42ea062200f01082172f40f02682002a40f06281fe2800f07786812800f06a86002840f07d8651ea030040f0558100f0c7be04460020b047e8b104f51d7151e800afbaf1000f0cd1bff35f8f00bf41e80002002a00f0f58051e800afbaf1000ff5d00021bff32f8f0029bff35f8f00f0e480824692e74ff0ff3737e147f6df40c0f24f008047002701241197adf8487006e048f2a351c0f24501bff32f8f8847dbf80060bff35f8fdbf800000321cff680710140b1f1005fbff35f8f03d10168494500f0c1804ff4757007f080f8002800f0b98041464218463182f8d47382f8d57382f8d67382f8d77382f8d87382f8d97382f8da7382f8db7382f8dc7382f8dd7382f8de7382f8df7382f8e07382f8e17382f8e27382f8e37382f8e47382f8e57382f8e67382f8e77382f8e87382f8e97382f8ea7382f8eb7382f8ec7382f8ed7382f8ee7382f8ef7382f8f07382f8f17382f8f27382f8f37382f8f47382f8f57382f8f67382f8f77382f8f87382f8f97382f8fa7382f8fb7382f8fc7382f8fd7382f8fe7382f8ff7382f8007482f8017482f8027482f8037482f8047482f8057482f8067482f8077482f8087482f8097482f80a7482f80b7482f80c7482f80d7482f80e7482f80f7482f8107482f8117482f8127482f8137482f8147482f8157482f8167482f8177482f8187482f819747ff470afc0f8009084728583c583058445848584c584058545858585c585058645868586c586058745875be8001fb1427ff436afbff35f8f4be8000159b15be8001fb142f8d02be706f5a9718847ace6012110e700200e9999b10f9a8ab1097801f07f02b2f10b0618bf0126b2f11c0718bf01278a2924dc0b2926d01c2924d03fe00d9010a804f0a7fa4ff0ff3701249df84900002810a818bf4ff0ff3704f0e3fb054644b99df8480028b94af21f30c0f247004c3080470d98002818bfc56013e09c2901d08b291bd160b14af21f31c0f247010446884794f8641119b994f80413204669b14ff0ff3742f6f760c0f2440000f5807150468847384645b0bde8f08f0d9010a806ea070404f065fa0e98017801f07f061e2e04d10f9908f086fb0746b5e71d2e01f07e0018bf1a2811d1dbf800100322cff680720a40b2f1005fbff35f8f0ad10a684a4504bf002281f8812303e0a6f115010129e9d90f2e0adc092e00f37381052e00f0ef82072e40f01c8300279ae0142e00f32182102e00f0eb82112e40f011830f98022841f0d5800e9908781Line truncated
|
||||||
"desc": "append injected blobs to main-app payload"
|
"desc": "append injected blobs to main-app payload"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 779123,
|
"offset": 779123,
|
||||||
"old": "805a3900",
|
"old": "805a3900",
|
||||||
"new": "e06a3a00",
|
"new": "34733a00",
|
||||||
"desc": "main-app subheader payload size (ps)"
|
"desc": "main-app subheader payload size (ps)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 152,
|
"offset": 152,
|
||||||
"old": "005b3900",
|
"old": "005b3900",
|
||||||
"new": "606b3a00",
|
"new": "b4733a00",
|
||||||
"desc": "main-app TOC entry size (ps + 128)"
|
"desc": "main-app TOC entry size (ps + 128)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 779243,
|
"offset": 779243,
|
||||||
"old": "805a3904",
|
"old": "805a3904",
|
||||||
"new": "e06a3a04",
|
"new": "34733a04",
|
||||||
"desc": "main-app preamble length (low 24 bits)"
|
"desc": "main-app preamble length (low 24 bits)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 779247,
|
"offset": 779247,
|
||||||
"old": "effdbcea",
|
"old": "effdbcea",
|
||||||
"new": "38f29188",
|
"new": "85d22153",
|
||||||
"desc": "[5] ota/s200_firmware_ota.bin preamble crc32"
|
"desc": "[5] ota/s200_firmware_ota.bin preamble crc32"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 156,
|
"offset": 156,
|
||||||
"old": "c0c6322a",
|
"old": "c0c6322a",
|
||||||
"new": "f8d63d83",
|
"new": "817b5baa",
|
||||||
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)"
|
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"offset": 779127,
|
"offset": 779127,
|
||||||
"old": "c0c6322a",
|
"old": "c0c6322a",
|
||||||
"new": "f8d63d83",
|
"new": "817b5baa",
|
||||||
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)"
|
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const list: DisplayList = {
|
|||||||
frame.drawDisplayList(list, 20, 30, 140, 20, 0);
|
frame.drawDisplayList(list, 20, 30, 140, 20, 0);
|
||||||
```
|
```
|
||||||
|
|
||||||
Supported calls in this first pass:
|
Supported calls:
|
||||||
|
|
||||||
- `ROUNDED_RECT`: literal or expression `x`/`y`, literal dimensions/radius, and
|
- `ROUNDED_RECT`: literal or expression `x`/`y`, literal dimensions/radius, and
|
||||||
4-bit colors (0–15). Border 16 means no border. Fill takes the maximum of the
|
4-bit colors (0–15). Border 16 means no border. Fill takes the maximum of the
|
||||||
@@ -38,6 +38,24 @@ Supported calls in this first pass:
|
|||||||
rejects the list. `SCREEN` reads the uncomposed frame; its source coordinates
|
rejects the list. `SCREEN` reads the uncomposed frame; its source coordinates
|
||||||
are also relative to this list's placement. Each call may add its own `depth`
|
are also relative to this list's placement. Each call may add its own `depth`
|
||||||
to the list's depth. A screen restore normally uses the negative of the list depth.
|
to the list's depth. A screen restore normally uses the negative of the list depth.
|
||||||
|
- `CLEAR` (revision 35 with a clip): fill with a 4-bit `color`. Under a clip it
|
||||||
|
fills just the clip rect, which is how to blank a region; without one it
|
||||||
|
fills the whole screen.
|
||||||
|
- `DRAWS` (bridge-only): replay glyph and icon draws offset by `x`/`y`, which
|
||||||
|
may be expressions. `records`/`count` come from glyph-wire's
|
||||||
|
`encodeReplayDraws(image.draws)`, which registers the rasters and returns null
|
||||||
|
unless every draw is a replayable glyph (atlas font, ASCII, ink inside the
|
||||||
|
line box) or plain image. Kotlin compiles them to firmware IMAGE calls on
|
||||||
|
ImageAtlas resources and TEXT runs on FontResourceAtlas fonts (one run per
|
||||||
|
line and color). `source` keeps the draws for software painting. If Kotlin
|
||||||
|
cannot resolve a record, the whole list draws nothing, so the frame's own
|
||||||
|
pixels show rather than content with a hole in it.
|
||||||
|
|
||||||
|
Any call may carry a `clip` (revision 35): a rect in list coordinates outside
|
||||||
|
which it draws nothing. It moves with the call's depth, like the call itself.
|
||||||
|
The firmware flag also nests (a clipped play-list call clips everything inside
|
||||||
|
it, intersected with the calls' own clips), but TS lists are inlined into the
|
||||||
|
root, so each call carries its own.
|
||||||
|
|
||||||
Kotlin allocates/cache-pins all image resources, resolves the local indices, applies
|
Kotlin allocates/cache-pins all image resources, resolves the local indices, applies
|
||||||
surface placement, and includes the calls in the root firmware display list. The
|
surface placement, and includes the calls in the root firmware display list. The
|
||||||
@@ -68,7 +86,9 @@ exclude the changing elapsed duration. Without a timeline, raw `time()` expressi
|
|||||||
start at each PRESENT. Native compilation strips the bridge-only elapsed opcode.
|
start at each PRESENT. Native compilation strips the bridge-only elapsed opcode.
|
||||||
|
|
||||||
`menu-selection-list.ts` authors both the rounded highlight and the transparent row
|
`menu-selection-list.ts` authors both the rounded highlight and the transparent row
|
||||||
image using this API. `menu-scroll-list.ts` authors a menu scroll or bounce: a
|
image using this API. `IconGrid` (app/ui/icon-grid.ts) animates a whole grid
|
||||||
|
this way: a clipped CLEAR of the grid box, the sliding highlight, then a DRAWS
|
||||||
|
of every row visible during the scroll, offset by the scroll expression. `menu-scroll-list.ts` authors a menu scroll or bounce: a
|
||||||
viewport-sized copy from a strip resource whose source y animates, then the
|
viewport-sized copy from a strip resource whose source y animates, then the
|
||||||
highlight. The bounce curve (`app/ui/menu-scroll-motion.ts`) needs no branches:
|
highlight. The bounce curve (`app/ui/menu-scroll-motion.ts`) needs no branches:
|
||||||
the easing ops clamp their input to 0..1, so `ease(t / p)` holds at 1 after the
|
the easing ops clamp their input to 0..1, so `ease(t / p)` holds at 1 after the
|
||||||
@@ -80,9 +100,13 @@ TypeScript. There is no animated-menu tag or menu animation policy in Kotlin.
|
|||||||
Tag 7 is followed by a little-endian u32 byte length and a bounded body:
|
Tag 7 is followed by a little-endian u32 byte length and a bounded body:
|
||||||
placement (i16 x/y, u16 width/height, i8 depth), timeline (u32 token/elapsed),
|
placement (i16 x/y, u16 width/height, i8 depth), timeline (u32 token/elapsed),
|
||||||
u16 resource count, gray8 images (u16 width/height followed by pixels), u16 call
|
u16 resource count, gray8 images (u16 width/height followed by pixels), u16 call
|
||||||
count, then calls. Calls start with the firmware opcode and an i16 relative depth;
|
count, then calls. Calls start with the opcode (bit 7 set when a clip follows)
|
||||||
operands otherwise use their fixed-width fields, except rounded x/y and rect-copy
|
and an i16 relative depth, then the clip if any (i16 x/y, u16 width/height);
|
||||||
x/y/dx/dy which use extended varints. Expressions use the firmware bytecode plus bridge-only
|
operands otherwise use their fixed-width fields, except rounded x/y, rect-copy
|
||||||
|
x/y/dx/dy and DRAWS x/y which use extended varints. CLEAR is a u8 color. DRAWS
|
||||||
|
(opcode 32) is followed by a u16 record count and the records, in the frame
|
||||||
|
draw-buffer formats: glyph `[0][fontId u16][encoding u32][penX s16][lineY s16][value u8]`
|
||||||
|
and image `[1][imageId u32][x s16][y s16]`. Expressions use the firmware bytecode plus bridge-only
|
||||||
`ELAPSED = 128`. Resource indices are local to this record, never firmware IDs.
|
`ELAPSED = 128`. Resource indices are local to this record, never firmware IDs.
|
||||||
Rect-copy source x/y are signed here to permit relative SCREEN coordinates.
|
Rect-copy source x/y are signed here to permit relative SCREEN coordinates.
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,31 @@
|
|||||||
import { DrawBytes, encodeValue, evaluate, integer, readValue, type DrawValue } from './draw-expression';
|
import { DrawBytes, encodeValue, evaluate, integer, readValue, type DrawValue } from './draw-expression';
|
||||||
|
import type { GrayImage } from './image';
|
||||||
|
|
||||||
/** Local resources are assigned firmware cache IDs by Kotlin. SCREEN reads the uncomposed frame. */
|
/** Local resources are assigned firmware cache IDs by Kotlin. SCREEN reads the uncomposed frame. */
|
||||||
export const SCREEN = 65535;
|
export const SCREEN = 65535;
|
||||||
export const DrawOp = { RECT_COPY: 2, IMAGE: 4, ROUNDED_RECT: 8 } as const;
|
/**
|
||||||
|
* Firmware opcodes, plus DRAWS: a bridge-only call that replays glyph and icon
|
||||||
|
* draws (from glyph-wire's encodeReplayDraws) as firmware image/text calls.
|
||||||
|
*/
|
||||||
|
export const DrawOp = { RECT_COPY: 2, IMAGE: 4, ROUNDED_RECT: 8, CLEAR: 9, DRAWS: 32 } as const;
|
||||||
export const DISPLAY_LIST_RECORD = 7;
|
export const DISPLAY_LIST_RECORD = 7;
|
||||||
|
/** Bridge opcode bit: a clip rect follows the call's depth. */
|
||||||
|
const CLIPPED = 128;
|
||||||
export type ListImage = { readonly width: number; readonly height: number; readonly pixels: Uint8Array };
|
export type ListImage = { readonly width: number; readonly height: number; readonly pixels: Uint8Array };
|
||||||
|
/** Revision 35: a call draws only inside its clip, in list coordinates (and moves with its depth). */
|
||||||
|
export type ListClip = { readonly x: number; readonly y: number; readonly width: number; readonly height: number };
|
||||||
export type ListCall = (
|
export type ListCall = (
|
||||||
| { op: typeof DrawOp.ROUNDED_RECT; x: DrawValue; y: DrawValue; width: number; height: number; radius: number; background: number; border: number }
|
| { op: typeof DrawOp.ROUNDED_RECT; x: DrawValue; y: DrawValue; width: number; height: number; radius: number; background: number; border: number }
|
||||||
| { op: typeof DrawOp.IMAGE; resource: number; x: number; y: number; transparent: boolean }
|
| { op: typeof DrawOp.IMAGE; resource: number; x: number; y: number; transparent: boolean }
|
||||||
| { op: typeof DrawOp.RECT_COPY; resource: number; x: DrawValue; y: DrawValue; width: number; height: number; dx: DrawValue; dy: DrawValue }
|
| { op: typeof DrawOp.RECT_COPY; resource: number; x: DrawValue; y: DrawValue; width: number; height: number; dx: DrawValue; dy: DrawValue }
|
||||||
) & { depth?: number };
|
/** Fill with a 4-bit color: the clip rect when there is one, else the whole screen. */
|
||||||
|
| { op: typeof DrawOp.CLEAR; color: number }
|
||||||
|
/**
|
||||||
|
* Glyph and icon draws offset by (x, y). `records`/`count` are the wire form;
|
||||||
|
* `source` holds the same draws for software painting (a decoded list has none).
|
||||||
|
*/
|
||||||
|
| { op: typeof DrawOp.DRAWS; x: DrawValue; y: DrawValue; records: Uint8Array; count: number; source?: GrayImage }
|
||||||
|
) & { depth?: number; clip?: ListClip };
|
||||||
export type DisplayList = {
|
export type DisplayList = {
|
||||||
readonly resources: readonly ListImage[];
|
readonly resources: readonly ListImage[];
|
||||||
readonly calls: readonly ListCall[];
|
readonly calls: readonly ListCall[];
|
||||||
@@ -45,12 +61,18 @@ export function encodeDisplayList(placed: PlacedDisplayList, now = Date.now()):
|
|||||||
}
|
}
|
||||||
integer(list.calls.length, 0, 4096); out.u16(list.calls.length);
|
integer(list.calls.length, 0, 4096); out.u16(list.calls.length);
|
||||||
for (const call of list.calls) {
|
for (const call of list.calls) {
|
||||||
out.u8(call.op); out.i16(call.depth ?? 0);
|
out.u8(call.op | (call.clip ? CLIPPED : 0)); out.i16(call.depth ?? 0);
|
||||||
integer(placed.depth + (call.depth ?? 0), -128, 127);
|
integer(placed.depth + (call.depth ?? 0), -128, 127);
|
||||||
|
if (call.clip) { out.i16(call.clip.x); out.i16(call.clip.y); out.u16(call.clip.width); out.u16(call.clip.height); }
|
||||||
if (call.op === DrawOp.ROUNDED_RECT) {
|
if (call.op === DrawOp.ROUNDED_RECT) {
|
||||||
out.raw(encodeValue(call.x)); out.raw(encodeValue(call.y));
|
out.raw(encodeValue(call.x)); out.raw(encodeValue(call.y));
|
||||||
out.u16(integer(call.width, 1, 640)); out.u16(integer(call.height, 1, 480)); out.u16(call.radius);
|
out.u16(integer(call.width, 1, 640)); out.u16(integer(call.height, 1, 480)); out.u16(call.radius);
|
||||||
out.u8(integer(call.background, 0, 15)); out.u8(integer(call.border, 0, 16));
|
out.u8(integer(call.background, 0, 15)); out.u8(integer(call.border, 0, 16));
|
||||||
|
} else if (call.op === DrawOp.CLEAR) {
|
||||||
|
out.u8(integer(call.color, 0, 15));
|
||||||
|
} else if (call.op === DrawOp.DRAWS) {
|
||||||
|
out.raw(encodeValue(call.x)); out.raw(encodeValue(call.y));
|
||||||
|
out.u16(call.count); out.raw(call.records);
|
||||||
} else {
|
} else {
|
||||||
if (call.resource !== SCREEN) integer(call.resource, 0, list.resources.length - 1);
|
if (call.resource !== SCREEN) integer(call.resource, 0, list.resources.length - 1);
|
||||||
if (call.op === DrawOp.RECT_COPY && call.resource !== SCREEN && [call.x, call.y].some(v => typeof v === 'number' && v < 0)) throw new Error('Negative image source coordinate');
|
if (call.op === DrawOp.RECT_COPY && call.resource !== SCREEN && [call.x, call.y].some(v => typeof v === 'number' && v < 0)) throw new Error('Negative image source coordinate');
|
||||||
@@ -68,6 +90,9 @@ export function encodeDisplayList(placed: PlacedDisplayList, now = Date.now()):
|
|||||||
return Uint8Array.from(header.bytes);
|
return Uint8Array.from(header.bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Replay-record sizes by tag, as in glyph-wire's frame draw buffer. */
|
||||||
|
const RECORD_BYTES: Record<number, number> = { 0: 12, 1: 9 };
|
||||||
|
|
||||||
export function readDisplayList(bytes: Uint8Array, offset: number, now = Date.now()): { placed: PlacedDisplayList; end: number } {
|
export function readDisplayList(bytes: Uint8Array, offset: number, now = Date.now()): { placed: PlacedDisplayList; end: number } {
|
||||||
const envelope = new DrawBytes(bytes.subarray(offset));
|
const envelope = new DrawBytes(bytes.subarray(offset));
|
||||||
if (envelope.u8() !== DISPLAY_LIST_RECORD) throw new Error('Invalid display-list record');
|
if (envelope.u8() !== DISPLAY_LIST_RECORD) throw new Error('Invalid display-list record');
|
||||||
@@ -79,11 +104,22 @@ export function readDisplayList(bytes: Uint8Array, offset: number, now = Date.no
|
|||||||
for (let i = 0; i < count; i++) { const width = r.u16(), height = r.u16(); resources.push({ width, height, pixels: r.take(width * height) }); }
|
for (let i = 0; i < count; i++) { const width = r.u16(), height = r.u16(); resources.push({ width, height, pixels: r.take(width * height) }); }
|
||||||
const calls: ListCall[] = [], callCount = r.u16(); integer(callCount, 0, 4096);
|
const calls: ListCall[] = [], callCount = r.u16(); integer(callCount, 0, 4096);
|
||||||
for (let i = 0; i < callCount; i++) {
|
for (let i = 0; i < callCount; i++) {
|
||||||
const op = r.u8(), depth = r.i16();
|
const header = r.u8(), op = header & ~CLIPPED, depth = r.i16();
|
||||||
if (op === DrawOp.ROUNDED_RECT) calls.push({ op, depth, x: readValue(r), y: readValue(r), width: r.u16(), height: r.u16(), radius: r.u16(), background: r.u8(), border: r.u8() });
|
const clip = header & CLIPPED ? { x: r.i16(), y: r.i16(), width: r.u16(), height: r.u16() } : undefined;
|
||||||
else if (op === DrawOp.IMAGE) calls.push({ op, depth, resource: r.u16(), x: r.i16(), y: r.i16(), transparent: (r.u8() & 16) !== 0 });
|
const common = clip ? { depth, clip } : { depth };
|
||||||
else if (op === DrawOp.RECT_COPY) calls.push({ op, depth, resource: r.u16(), x: readValue(r), y: readValue(r), width: r.u16(), height: r.u16(), dx: readValue(r), dy: readValue(r) });
|
if (op === DrawOp.ROUNDED_RECT) calls.push({ op, ...common, x: readValue(r), y: readValue(r), width: r.u16(), height: r.u16(), radius: r.u16(), background: r.u8(), border: r.u8() });
|
||||||
else throw new Error('Unsupported display-list call');
|
else if (op === DrawOp.IMAGE) calls.push({ op, ...common, resource: r.u16(), x: r.i16(), y: r.i16(), transparent: (r.u8() & 16) !== 0 });
|
||||||
|
else if (op === DrawOp.RECT_COPY) calls.push({ op, ...common, resource: r.u16(), x: readValue(r), y: readValue(r), width: r.u16(), height: r.u16(), dx: readValue(r), dy: readValue(r) });
|
||||||
|
else if (op === DrawOp.CLEAR) calls.push({ op, ...common, color: r.u8() });
|
||||||
|
else if (op === DrawOp.DRAWS) {
|
||||||
|
const x = readValue(r), y = readValue(r), records = r.u16(), start = r.offset;
|
||||||
|
for (let n = 0; n < records; n++) {
|
||||||
|
const size = RECORD_BYTES[r.bytes[r.offset]!];
|
||||||
|
if (!size) throw new Error('Unsupported display-list draw record');
|
||||||
|
r.take(size);
|
||||||
|
}
|
||||||
|
calls.push({ op, ...common, x, y, count: records, records: r.bytes.slice(start, r.offset) });
|
||||||
|
} else throw new Error('Unsupported display-list call');
|
||||||
}
|
}
|
||||||
if (r.offset !== length) throw new Error('Trailing display-list bytes');
|
if (r.offset !== length) throw new Error('Trailing display-list bytes');
|
||||||
const placed = { x, y, width, height, depth, displayList: { resources, calls, presentedAt: now, timeline: { token, startedAt: now - elapsed } } };
|
const placed = { x, y, width, height, depth, displayList: { resources, calls, presentedAt: now, timeline: { token, startedAt: now - elapsed } } };
|
||||||
@@ -92,13 +128,23 @@ export function readDisplayList(bytes: Uint8Array, offset: number, now = Date.no
|
|||||||
return { placed, end: offset + envelope.offset };
|
return { placed, end: offset + envelope.offset };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list at `factor` brightness. Replayed icons cannot be dimmed on the
|
||||||
|
* glasses, so a list with DRAWS calls becomes empty instead: the dimmed frame
|
||||||
|
* underneath then shows its final state.
|
||||||
|
*/
|
||||||
export function dimDisplayList(list: DisplayList, factor: number): DisplayList {
|
export function dimDisplayList(list: DisplayList, factor: number): DisplayList {
|
||||||
|
if (list.calls.some(c => c.op === DrawOp.DRAWS)) return { ...list, calls: [] };
|
||||||
const dim = (v: number) => v === 0 ? 0 : Math.max(1, Math.round(v * factor));
|
const dim = (v: number) => v === 0 ? 0 : Math.max(1, Math.round(v * factor));
|
||||||
return { ...list, resources: list.resources.map(r => ({ ...r, pixels: r.pixels.map(dim) })),
|
return { ...list, resources: list.resources.map(r => ({ ...r, pixels: r.pixels.map(dim) })),
|
||||||
calls: list.calls.map(c => c.op === DrawOp.ROUNDED_RECT ? { ...c, background: Math.min(15, Math.round(c.background * factor)), border: c.border === 16 ? 16 : Math.min(15, Math.round(c.border * factor)) } : c) };
|
calls: list.calls.map(c => c.op === DrawOp.ROUNDED_RECT ? { ...c, background: Math.min(15, Math.round(c.background * factor)), border: c.border === 16 ? 16 : Math.min(15, Math.round(c.border * factor)) }
|
||||||
|
: c.op === DrawOp.CLEAR ? { ...c, color: Math.min(15, Math.round(c.color * factor)) } : c) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Fallback compositor; native preview and glasses replay the compiled list with their existing timers. */
|
/**
|
||||||
|
* Fallback compositor; native preview and glasses replay the compiled list with their existing timers.
|
||||||
|
* A DRAWS call paints from its `source`, so a decoded list skips them.
|
||||||
|
*/
|
||||||
export function paintDisplayList(output: Uint8Array, screen: Uint8Array, width: number, height: number, placed: PlacedDisplayList, right = false, now = Date.now()): void {
|
export function paintDisplayList(output: Uint8Array, screen: Uint8Array, width: number, height: number, placed: PlacedDisplayList, right = false, now = Date.now()): void {
|
||||||
const q = (n: number) => Math.min(15, (n + 8) >> 4) * 16;
|
const q = (n: number) => Math.min(15, (n + 8) >> 4) * 16;
|
||||||
const list = placed.displayList;
|
const list = placed.displayList;
|
||||||
@@ -112,10 +158,20 @@ export function paintDisplayList(output: Uint8Array, screen: Uint8Array, width:
|
|||||||
};
|
};
|
||||||
for (const c of placed.displayList.calls) {
|
for (const c of placed.displayList.calls) {
|
||||||
const depth = placed.depth + (c.depth ?? 0), shift = right ? -Math.floor((depth + 1) / 2) : Math.floor(depth / 2);
|
const depth = placed.depth + (c.depth ?? 0), shift = right ? -Math.floor((depth + 1) / 2) : Math.floor(depth / 2);
|
||||||
if (c.op === DrawOp.ROUNDED_RECT) {
|
// Writable region in screen pixels: the clip moves with the call's depth, like its content.
|
||||||
|
const clip = c.clip ? { x: placed.x + c.clip.x + shift, y: placed.y + c.clip.y, width: c.clip.width, height: c.clip.height }
|
||||||
|
: { x: 0, y: 0, width, height };
|
||||||
|
const writable = (x: number, y: number) => x >= 0 && y >= 0 && x < width && y < height &&
|
||||||
|
x >= clip.x && y >= clip.y && x < clip.x + clip.width && y < clip.y + clip.height;
|
||||||
|
if (c.op === DrawOp.CLEAR) {
|
||||||
|
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) if (writable(x, y)) output[y * width + x] = c.color * 16;
|
||||||
|
} else if (c.op === DrawOp.DRAWS) {
|
||||||
|
const at = (v: DrawValue) => evaluate(v, elapsed, presentTime).value;
|
||||||
|
c.source?.paintReplayDraws(output, width, height, placed.x + at(c.x) + shift, placed.y + at(c.y), clip);
|
||||||
|
} else if (c.op === DrawOp.ROUNDED_RECT) {
|
||||||
const x = placed.x + evaluate(c.x, elapsed, presentTime).value + shift, y = placed.y + evaluate(c.y, elapsed, presentTime).value;
|
const x = placed.x + evaluate(c.x, elapsed, presentTime).value + shift, y = placed.y + evaluate(c.y, elapsed, presentTime).value;
|
||||||
for (let yy = 0; yy < c.height; yy++) for (let xx = 0; xx < c.width; xx++) {
|
for (let yy = 0; yy < c.height; yy++) for (let xx = 0; xx < c.width; xx++) {
|
||||||
if (x + xx < 0 || y + yy < 0 || x + xx >= width || y + yy >= height || !inside(xx, yy, c.width, c.height, c.radius)) continue;
|
if (!writable(x + xx, y + yy) || !inside(xx, yy, c.width, c.height, c.radius)) continue;
|
||||||
const p = (y + yy) * width + x + xx;
|
const p = (y + yy) * width + x + xx;
|
||||||
output[p] = c.border !== 16 && !inside(xx - 1, yy - 1, c.width - 2, c.height - 2, Math.max(0, c.radius - 1)) ? c.border * 16 : Math.max(output[p], c.background * 16);
|
output[p] = c.border !== 16 && !inside(xx - 1, yy - 1, c.width - 2, c.height - 2, Math.max(0, c.radius - 1)) ? c.border * 16 : Math.max(output[p], c.background * 16);
|
||||||
}
|
}
|
||||||
@@ -126,7 +182,7 @@ export function paintDisplayList(output: Uint8Array, screen: Uint8Array, width:
|
|||||||
const sx = c.op === DrawOp.IMAGE ? 0 : at(c.x) + (c.resource === SCREEN ? placed.x : 0), sy = c.op === DrawOp.IMAGE ? 0 : at(c.y) + (c.resource === SCREEN ? placed.y : 0);
|
const sx = c.op === DrawOp.IMAGE ? 0 : at(c.x) + (c.resource === SCREEN ? placed.x : 0), sy = c.op === DrawOp.IMAGE ? 0 : at(c.y) + (c.resource === SCREEN ? placed.y : 0);
|
||||||
const x = placed.x + (c.op === DrawOp.IMAGE ? c.x : at(c.dx)) + shift, y = placed.y + (c.op === DrawOp.IMAGE ? c.y : at(c.dy));
|
const x = placed.x + (c.op === DrawOp.IMAGE ? c.x : at(c.dx)) + shift, y = placed.y + (c.op === DrawOp.IMAGE ? c.y : at(c.dy));
|
||||||
for (let yy = 0; yy < h; yy++) for (let xx = 0; xx < w; xx++) {
|
for (let yy = 0; yy < h; yy++) for (let xx = 0; xx < w; xx++) {
|
||||||
if (x + xx < 0 || y + yy < 0 || x + xx >= width || y + yy >= height || sx + xx < 0 || sy + yy < 0 || sx + xx >= source.width || sy + yy >= source.height) continue;
|
if (!writable(x + xx, y + yy) || sx + xx < 0 || sy + yy < 0 || sx + xx >= source.width || sy + yy >= source.height) continue;
|
||||||
const v = q(source.pixels[(sy + yy) * source.width + sx + xx]);
|
const v = q(source.pixels[(sy + yy) * source.width + sx + xx]);
|
||||||
if (c.op !== DrawOp.IMAGE || !c.transparent || v !== 0) output[(y + yy) * width + x + xx] = v;
|
if (c.op !== DrawOp.IMAGE || !c.transparent || v !== 0) output[(y + yy) * width + x + xx] = v;
|
||||||
}
|
}
|
||||||
|
|||||||
+87
-28
@@ -21,7 +21,7 @@ import { DrawRecordKind, encodePresentation } from "./presentation-wire";
|
|||||||
* only means "no wire savings for this draw".
|
* only means "no wire savings for this draw".
|
||||||
*/
|
*/
|
||||||
import { Glyph } from "./bdffont";
|
import { Glyph } from "./bdffont";
|
||||||
import { GrayImage, type DeferredDraw, type GlyphFont, type PlacedFwText, type PlacedImage } from "./image";
|
import { GrayImage, type DeferredDraw, type GlyphFont, type PlacedFwText, type PlacedGlyph, type PlacedImage } from "./image";
|
||||||
|
|
||||||
import { textureAtlasAvailable, textureFontId, registerTextureGlyphs, registerFirmwareGlyphs, textureImageId } from "../native/texture-atlas";
|
import { textureAtlasAvailable, textureFontId, registerTextureGlyphs, registerFirmwareGlyphs, textureImageId } from "../native/texture-atlas";
|
||||||
|
|
||||||
@@ -167,15 +167,7 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer |
|
|||||||
if (!state || !representableGlyph(placed.font, placed.glyph)) continue;
|
if (!state || !representableGlyph(placed.font, placed.glyph)) continue;
|
||||||
if (!inRange16(placed.x) || !inRange16(placed.y)) continue;
|
if (!inRange16(placed.x) || !inRange16(placed.y)) continue;
|
||||||
bytes += GLYPH_RECORD_BYTES;
|
bytes += GLYPH_RECORD_BYTES;
|
||||||
if (state.registered.has(placed.glyph.encoding)) continue;
|
registration = queueRegistration(registration, state, placed);
|
||||||
state.registered.add(placed.glyph.encoding);
|
|
||||||
registration ??= new Map();
|
|
||||||
let group = registration.get(state);
|
|
||||||
if (!group) {
|
|
||||||
group = { font: placed.font, glyphs: [], aaGlyphs: [] };
|
|
||||||
registration.set(state, group);
|
|
||||||
}
|
|
||||||
(placed.glyph.coverage ? group.aaGlyphs : group.glyphs).push(placed.glyph);
|
|
||||||
} else if (placed.kind === "image") {
|
} else if (placed.kind === "image") {
|
||||||
if (!inRange16(placed.x) || !inRange16(placed.y)) continue;
|
if (!inRange16(placed.x) || !inRange16(placed.y)) continue;
|
||||||
if (placed.presentation) { const record = encodePresentation(placed); presentations.set(placed, record); bytes += record.length; }
|
if (placed.presentation) { const record = encodePresentation(placed); presentations.set(placed, record); bytes += record.length; }
|
||||||
@@ -186,12 +178,7 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer |
|
|||||||
if (ok) bytes += FWTEXT_HEADER_BYTES + placed.glyphs.length * FWTEXT_MEMBER_BYTES;
|
if (ok) bytes += FWTEXT_HEADER_BYTES + placed.glyphs.length * FWTEXT_MEMBER_BYTES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (registration) {
|
registerQueued(registration);
|
||||||
const plainBuffer = buildRegistrationBuffer(registration);
|
|
||||||
if (plainBuffer) registerTextureGlyphs(plainBuffer, false);
|
|
||||||
const aaBuffer = buildAaRegistrationBuffer(registration);
|
|
||||||
if (aaBuffer) registerTextureGlyphs(aaBuffer, true);
|
|
||||||
}
|
|
||||||
if (bytes === 0) return null;
|
if (bytes === 0) return null;
|
||||||
|
|
||||||
// Pass 2: the frame's draw records.
|
// Pass 2: the frame's draw records.
|
||||||
@@ -202,23 +189,13 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer |
|
|||||||
if (!inRange16(placed.x) || !inRange16(placed.y)) continue;
|
if (!inRange16(placed.x) || !inRange16(placed.y)) continue;
|
||||||
const state = fontWireState(placed.font);
|
const state = fontWireState(placed.font);
|
||||||
if (!state || !representableGlyph(placed.font, placed.glyph)) continue;
|
if (!state || !representableGlyph(placed.font, placed.glyph)) continue;
|
||||||
out.setUint8(offset, DrawRecordKind.GLYPH);
|
offset = writeGlyphRecord(out, offset, state, placed);
|
||||||
out.setUint16(offset + 1, state.fontId, true);
|
|
||||||
out.setUint32(offset + 3, placed.glyph.encoding, true);
|
|
||||||
out.setInt16(offset + 7, placed.x, true);
|
|
||||||
out.setInt16(offset + 9, placed.y, true);
|
|
||||||
out.setUint8(offset + 11, placed.value);
|
|
||||||
offset += GLYPH_RECORD_BYTES;
|
|
||||||
} else if (placed.kind === "image") {
|
} else if (placed.kind === "image") {
|
||||||
if (!inRange16(placed.x) || !inRange16(placed.y)) continue;
|
if (!inRange16(placed.x) || !inRange16(placed.y)) continue;
|
||||||
if (placed.presentation) { const bytes = presentations.get(placed)!; new Uint8Array(out.buffer).set(bytes, offset); offset += bytes.length; continue; }
|
if (placed.presentation) { const bytes = presentations.get(placed)!; new Uint8Array(out.buffer).set(bytes, offset); offset += bytes.length; continue; }
|
||||||
const id = imageId(placed);
|
const id = imageId(placed);
|
||||||
if (id === null) continue;
|
if (id === null) continue;
|
||||||
out.setUint8(offset, DrawRecordKind.TEXTURE_IMAGE);
|
offset = writeImageRecord(out, offset, id, placed);
|
||||||
out.setUint32(offset + 1, id, true);
|
|
||||||
out.setInt16(offset + 5, placed.x, true);
|
|
||||||
out.setInt16(offset + 7, placed.y, true);
|
|
||||||
offset += IMAGE_RECORD_BYTES;
|
|
||||||
} else {
|
} else {
|
||||||
if (!fwRunOk.get(placed)) continue;
|
if (!fwRunOk.get(placed)) continue;
|
||||||
out.setUint8(offset, DrawRecordKind.FIRMWARE_TEXT);
|
out.setUint8(offset, DrawRecordKind.FIRMWARE_TEXT);
|
||||||
@@ -238,6 +215,88 @@ export function prepareFrameDraws(draws: readonly DeferredDraw[]): ArrayBuffer |
|
|||||||
return out.buffer;
|
return out.buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode draws for replay inside a display list (DrawOp.DRAWS), registering
|
||||||
|
* unseen glyph rasters and images as prepareFrameDraws does, in its glyph and
|
||||||
|
* image record formats. Null unless every draw is a replayable glyph or plain
|
||||||
|
* image: a list must reproduce all of its content or none of it.
|
||||||
|
*/
|
||||||
|
export function encodeReplayDraws(draws: readonly DeferredDraw[]): { records: Uint8Array; count: number } | null {
|
||||||
|
if (!textureAtlasAvailable()) return null;
|
||||||
|
let bytes = 0;
|
||||||
|
for (const placed of draws) {
|
||||||
|
if (!inRange16(placed.x) || !inRange16(placed.y)) return null;
|
||||||
|
if (placed.kind === "glyph") {
|
||||||
|
if (!fontWireState(placed.font) || !representableGlyph(placed.font, placed.glyph)) return null;
|
||||||
|
bytes += GLYPH_RECORD_BYTES;
|
||||||
|
} else if (placed.kind === "image" && !placed.presentation && imageId(placed) !== null) {
|
||||||
|
bytes += IMAGE_RECORD_BYTES;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let registration: Map<FontWireState, RegistrationGroup> | null = null;
|
||||||
|
const out = new DataView(new ArrayBuffer(bytes));
|
||||||
|
let offset = 0;
|
||||||
|
for (const placed of draws) {
|
||||||
|
if (placed.kind === "glyph") {
|
||||||
|
const state = fontWireState(placed.font)!;
|
||||||
|
registration = queueRegistration(registration, state, placed);
|
||||||
|
offset = writeGlyphRecord(out, offset, state, placed);
|
||||||
|
} else if (placed.kind === "image") {
|
||||||
|
offset = writeImageRecord(out, offset, imageId(placed)!, placed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
registerQueued(registration);
|
||||||
|
return { records: new Uint8Array(out.buffer), count: draws.length };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** [0][fontId u16][encoding u32][penX s16][lineY s16][value u8] */
|
||||||
|
function writeGlyphRecord(out: DataView, offset: number, state: FontWireState, placed: PlacedGlyph): number {
|
||||||
|
out.setUint8(offset, DrawRecordKind.GLYPH);
|
||||||
|
out.setUint16(offset + 1, state.fontId, true);
|
||||||
|
out.setUint32(offset + 3, placed.glyph.encoding, true);
|
||||||
|
out.setInt16(offset + 7, placed.x, true);
|
||||||
|
out.setInt16(offset + 9, placed.y, true);
|
||||||
|
out.setUint8(offset + 11, placed.value);
|
||||||
|
return offset + GLYPH_RECORD_BYTES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** [1][imageId u32][x s16][y s16] */
|
||||||
|
function writeImageRecord(out: DataView, offset: number, id: number, placed: PlacedImage): number {
|
||||||
|
out.setUint8(offset, DrawRecordKind.TEXTURE_IMAGE);
|
||||||
|
out.setUint32(offset + 1, id, true);
|
||||||
|
out.setInt16(offset + 5, placed.x, true);
|
||||||
|
out.setInt16(offset + 7, placed.y, true);
|
||||||
|
return offset + IMAGE_RECORD_BYTES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Queue a glyph raster for registerQueued unless this JS context already registered it. */
|
||||||
|
function queueRegistration(
|
||||||
|
registration: Map<FontWireState, RegistrationGroup> | null,
|
||||||
|
state: FontWireState,
|
||||||
|
placed: PlacedGlyph,
|
||||||
|
): Map<FontWireState, RegistrationGroup> | null {
|
||||||
|
if (state.registered.has(placed.glyph.encoding)) return registration;
|
||||||
|
state.registered.add(placed.glyph.encoding);
|
||||||
|
registration ??= new Map();
|
||||||
|
let group = registration.get(state);
|
||||||
|
if (!group) {
|
||||||
|
group = { font: placed.font, glyphs: [], aaGlyphs: [] };
|
||||||
|
registration.set(state, group);
|
||||||
|
}
|
||||||
|
(placed.glyph.coverage ? group.aaGlyphs : group.glyphs).push(placed.glyph);
|
||||||
|
return registration;
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerQueued(registration: Map<FontWireState, RegistrationGroup> | null): void {
|
||||||
|
if (!registration) return;
|
||||||
|
const plainBuffer = buildRegistrationBuffer(registration);
|
||||||
|
if (plainBuffer) registerTextureGlyphs(plainBuffer, false);
|
||||||
|
const aaBuffer = buildAaRegistrationBuffer(registration);
|
||||||
|
if (aaBuffer) registerTextureGlyphs(aaBuffer, true);
|
||||||
|
}
|
||||||
|
|
||||||
type RegistrationGroup = {
|
type RegistrationGroup = {
|
||||||
font: GlyphFont;
|
font: GlyphFont;
|
||||||
/** 1bpp (BDF) glyphs for GlyphAtlas.register. */
|
/** 1bpp (BDF) glyphs for GlyphAtlas.register. */
|
||||||
|
|||||||
+32
-1
@@ -517,6 +517,34 @@ export class GrayImage {
|
|||||||
presentation: { radius, background, border, depth, displayList: menuSelectionList(baked, background, border, radius, animation) } });
|
presentation: { radius, background, border, depth, displayList: menuSelectionList(baked, background, border, radius, animation) } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paint this image's glyph and image draws onto a gray8 buffer at (dx, dy),
|
||||||
|
* inside `clip`, the way the glasses replay them from a display list (see
|
||||||
|
* DrawOp.DRAWS): glyphs firmware-exact, images skipping pixels whose 4-bit
|
||||||
|
* level is 0. Raster pixels and other draw kinds are not painted.
|
||||||
|
*/
|
||||||
|
paintReplayDraws(pixels: Uint8Array, width: number, height: number, dx: number, dy: number,
|
||||||
|
clip: { x: number; y: number; width: number; height: number }): void {
|
||||||
|
const left = Math.max(0, clip.x), top = Math.max(0, clip.y);
|
||||||
|
const right = Math.min(width, clip.x + clip.width), bottom = Math.min(height, clip.y + clip.height);
|
||||||
|
const sink: PixelSink = {
|
||||||
|
setPixel: (x, y, value) => {
|
||||||
|
if (x >= left && y >= top && x < right && y < bottom) pixels[y * width + x] = clampByte(value);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
for (const placed of this.drawList) {
|
||||||
|
if (placed.kind === "glyph") {
|
||||||
|
rasterizeGlyph(sink, placed.font, placed.glyph, placed.x + dx, placed.y + dy, placed.value);
|
||||||
|
} else if (placed.kind === "image" && !placed.presentation) {
|
||||||
|
const source = placed.source;
|
||||||
|
for (let y = 0; y < source.height; y++) for (let x = 0; x < source.width; x++) {
|
||||||
|
const level = grayToNibble(source.pixels[y * source.width + x]!);
|
||||||
|
if (level) sink.setPixel(placed.x + dx + x, placed.y + dy + y, level * 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Submit a retained list alongside this frame; coordinates are relative to x/y. */
|
/** Submit a retained list alongside this frame; coordinates are relative to x/y. */
|
||||||
drawDisplayList(displayList: DisplayList, x: number, y: number, width: number, height: number, depth = 0): void {
|
drawDisplayList(displayList: DisplayList, x: number, y: number, width: number, height: number, depth = 0): void {
|
||||||
this.drawList.push({ kind: "image", source: new GrayImage(width, height), x, y,
|
this.drawList.push({ kind: "image", source: new GrayImage(width, height), x, y,
|
||||||
@@ -661,9 +689,12 @@ export function grayToNibble(value: number): number {
|
|||||||
return value <= 0 ? 0 : Math.min(15, (value + 8) >> 4);
|
return value <= 0 ? 0 : Math.min(15, (value + 8) >> 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Where rasterizeGlyph writes: an image, or a clipped buffer (paintReplayDraws). */
|
||||||
|
type PixelSink = { setPixel(x: number, y: number, value: number): void };
|
||||||
|
|
||||||
/** Bake one glyph into an image's pixel buffer (y is the top of the line). */
|
/** Bake one glyph into an image's pixel buffer (y is the top of the line). */
|
||||||
function rasterizeGlyph(
|
function rasterizeGlyph(
|
||||||
target: GrayImage,
|
target: PixelSink,
|
||||||
font: GlyphFont,
|
font: GlyphFont,
|
||||||
glyph: Glyph,
|
glyph: Glyph,
|
||||||
x: number,
|
x: number,
|
||||||
|
|||||||
@@ -18,9 +18,14 @@ export type MenuScrollHighlight = {
|
|||||||
* started at `timelineStart` (the slide may have started before or after it).
|
* started at `timelineStart` (the slide may have started before or after it).
|
||||||
*/
|
*/
|
||||||
export function slidingHighlightY(y: number, motion: MenuHighlightAnimation | undefined, timelineStart: number): E<'i32'> {
|
export function slidingHighlightY(y: number, motion: MenuHighlightAnimation | undefined, timelineStart: number): E<'i32'> {
|
||||||
if (!motion?.dy) return E.i32(y);
|
return slidingCoordinate(y, motion?.dy ?? 0, motion, timelineStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** One coordinate of a highlight sliding by `delta` to rest at `value`; see slidingHighlightY. */
|
||||||
|
export function slidingCoordinate(value: number, delta: number, motion: MenuHighlightAnimation | undefined, timelineStart: number): E<'i32'> {
|
||||||
|
if (!motion || !delta) return E.i32(value);
|
||||||
return E.progress(motion.durationMs, motion.startedAt - timelineStart).ease()
|
return E.progress(motion.durationMs, motion.startedAt - timelineStart).ease()
|
||||||
.lerp(E.i32(y + motion.dy).toFloat(), E.i32(y).toFloat()).toInt();
|
.lerp(E.i32(value + delta).toFloat(), E.i32(value).toFloat()).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,18 +1,54 @@
|
|||||||
|
import { JavaDirectBuffer } from "./java-direct-buffer";
|
||||||
|
|
||||||
declare const com: any;
|
declare const com: any;
|
||||||
|
|
||||||
|
// Reused Java-side buffers for this isolate's frames: passing a JS ArrayBuffer
|
||||||
|
// to Java leaks it (java-direct-buffer.ts). Module state is per isolate, so
|
||||||
|
// each worker gets its own pair.
|
||||||
|
const framePixelsBuffer = new JavaDirectBuffer(640 * 480);
|
||||||
|
const frameDrawsBuffer = new JavaDirectBuffer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Java object a worker isolate submits surface frames to: the live BLE
|
* The display a worker isolate submits surface frames to: the live BLE
|
||||||
* communicator, or the preview-only compositor standing in when no glasses
|
* communicator, or the preview-only compositor standing in when no glasses
|
||||||
* are paired (both expose the same submitSurfaceFrame signature). Located
|
* are paired (both expose the same submitSurfaceFrame signature). Located
|
||||||
* through Java statics because those are shared across isolates, unlike any
|
* through Java statics because those are shared across isolates, unlike any
|
||||||
* JS-side state.
|
* JS-side state. Null when neither exists.
|
||||||
*
|
*
|
||||||
* Frame submission only. Buzzer effects use worker-buzzer, which routes to
|
* Frame submission only. Buzzer effects use worker-buzzer, which routes to
|
||||||
* the platform BLE session and skips playback when disconnected.
|
* the platform BLE session and skips playback when disconnected.
|
||||||
*/
|
*/
|
||||||
export function getActiveDisplay(): any {
|
export function getActiveDisplay(): typeof display | null {
|
||||||
|
return activeJavaDisplay() ? display : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function activeJavaDisplay(): any {
|
||||||
return (
|
return (
|
||||||
com.faceclaw.app.FaceclawBleCommunicator.getActive() ??
|
com.faceclaw.app.FaceclawBleCommunicator.getActive() ??
|
||||||
com.faceclaw.app.FaceclawPreviewCompositor.getActive()
|
com.faceclaw.app.FaceclawPreviewCompositor.getActive()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes the same ArrayBuffer arguments as the iOS active display and copies
|
||||||
|
* them into the reused Java buffers right before the synchronous Java call.
|
||||||
|
*/
|
||||||
|
const display = {
|
||||||
|
submitSurfaceFrame(buffer: ArrayBuffer, surfaceId: string, x: number, y: number, width: number, height: number,
|
||||||
|
fingerprint: string, paintMs: number, frameId: number, draws: ArrayBuffer | null = null): void {
|
||||||
|
const target = activeJavaDisplay();
|
||||||
|
if (!target) return;
|
||||||
|
target.submitSurfaceFrame(
|
||||||
|
framePixelsBuffer.load(new Uint8Array(buffer)),
|
||||||
|
surfaceId,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fingerprint,
|
||||||
|
paintMs,
|
||||||
|
frameId,
|
||||||
|
frameDrawsBuffer.loadOptional(draws),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { RingInput } from "../g2/ring-input";
|
import type { RingInput } from "../g2/ring-input";
|
||||||
import { ImageSource, Utils } from "@nativescript/core";
|
import { ImageSource, Utils } from "@nativescript/core";
|
||||||
import * as frameTimings from "./frame-timings";
|
import * as frameTimings from "./frame-timings";
|
||||||
|
import { JavaDirectBuffer } from "./java-direct-buffer";
|
||||||
|
|
||||||
declare const com: any;
|
declare const com: any;
|
||||||
|
|
||||||
@@ -132,6 +133,13 @@ export class FaceclawCommunicatorBridge {
|
|||||||
private javaCallQueue: Promise<void> = Promise.resolve();
|
private javaCallQueue: Promise<void> = Promise.resolve();
|
||||||
/** Calls waiting on javaCallQueue; 0 means enqueueJavaCall's fast path is safe. */
|
/** Calls waiting on javaCallQueue; 0 means enqueueJavaCall's fast path is safe. */
|
||||||
private queuedJavaCalls = 0;
|
private queuedJavaCalls = 0;
|
||||||
|
// Reused Java-side buffers for byte payloads; passing a JS ArrayBuffer to
|
||||||
|
// Java leaks it (see java-direct-buffer.ts). Loaded inside the queued call,
|
||||||
|
// immediately before the synchronous Java call that consumes them.
|
||||||
|
private readonly framePixelsBuffer = new JavaDirectBuffer(640 * 480);
|
||||||
|
private readonly frameDrawsBuffer = new JavaDirectBuffer();
|
||||||
|
private readonly shellSceneBuffer = new JavaDirectBuffer();
|
||||||
|
private readonly buzzerBuffer = new JavaDirectBuffer();
|
||||||
private readonly frameMetricWaiters = new Set<(metrics: FrameMetrics) => void>();
|
private readonly frameMetricWaiters = new Set<(metrics: FrameMetrics) => void>();
|
||||||
// Recent frame-finished outcomes from the Java side, so waitForFrameFinished
|
// Recent frame-finished outcomes from the Java side, so waitForFrameFinished
|
||||||
// does not race against finishes that land before the wait starts.
|
// does not race against finishes that land before the wait starts.
|
||||||
@@ -538,7 +546,10 @@ export class FaceclawCommunicatorBridge {
|
|||||||
*/
|
*/
|
||||||
async submitShellScene(bytes: Uint8Array, paintMs = 0, frameId = 0): Promise<void> {
|
async submitShellScene(bytes: Uint8Array, paintMs = 0, frameId = 0): Promise<void> {
|
||||||
const snapshot = new Uint8Array(bytes);
|
const snapshot = new Uint8Array(bytes);
|
||||||
await this.enqueueJavaCall(() => this.communicator.submitShellScene(snapshot.buffer, paintMs, frameId), true);
|
await this.enqueueJavaCall(
|
||||||
|
() => this.communicator.submitShellScene(this.shellSceneBuffer.load(snapshot), paintMs, frameId),
|
||||||
|
true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setUnderlayDim(belowZOrder: number, factor: number): Promise<void> {
|
async setUnderlayDim(belowZOrder: number, factor: number): Promise<void> {
|
||||||
@@ -594,15 +605,17 @@ export class FaceclawCommunicatorBridge {
|
|||||||
*/
|
*/
|
||||||
glyphs: ArrayBuffer | null = null,
|
glyphs: ArrayBuffer | null = null,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Snapshot because the Java call is deferred; the buffer is passed as an
|
// Snapshot because the Java call is deferred. The bytes reach Java as a
|
||||||
// ArrayBuffer, which NativeScript marshals to a ByteBuffer without the
|
// ByteBuffer (no ~150ms per-element copy, as a byte[] parameter would
|
||||||
// ~150ms per-element copy a byte[] parameter would need.
|
// need), but through a reused Java direct buffer rather than by passing
|
||||||
|
// the ArrayBuffer itself, which NativeScript never frees
|
||||||
|
// (java-direct-buffer.ts).
|
||||||
const snapshot = new Uint8Array(pixels8bpp);
|
const snapshot = new Uint8Array(pixels8bpp);
|
||||||
// inlineWhenIdle: this is the frame path, the Java side of it measures
|
// inlineWhenIdle: this is the frame path, the Java side of it measures
|
||||||
// ~5ms (composite + pack), and the caller awaits it either way.
|
// ~5ms (composite + pack), and the caller awaits it either way.
|
||||||
await this.enqueueJavaCall(() => {
|
await this.enqueueJavaCall(() => {
|
||||||
this.communicator.submitSurfaceFrame(
|
this.communicator.submitSurfaceFrame(
|
||||||
snapshot.buffer,
|
this.framePixelsBuffer.load(snapshot),
|
||||||
surfaceId,
|
surfaceId,
|
||||||
Math.round(rect.x),
|
Math.round(rect.x),
|
||||||
Math.round(rect.y),
|
Math.round(rect.y),
|
||||||
@@ -611,7 +624,7 @@ export class FaceclawCommunicatorBridge {
|
|||||||
fingerprint,
|
fingerprint,
|
||||||
Math.round(nonNegativeNumber(paintMs)),
|
Math.round(nonNegativeNumber(paintMs)),
|
||||||
Math.round(nonNegativeNumber(frameId)),
|
Math.round(nonNegativeNumber(frameId)),
|
||||||
glyphs,
|
this.frameDrawsBuffer.loadOptional(glyphs),
|
||||||
);
|
);
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
@@ -673,7 +686,7 @@ export class FaceclawCommunicatorBridge {
|
|||||||
async playBuzzerSequence(payload: Uint8Array): Promise<void> {
|
async playBuzzerSequence(payload: Uint8Array): Promise<void> {
|
||||||
const snapshot = new Uint8Array(payload);
|
const snapshot = new Uint8Array(payload);
|
||||||
await this.enqueueJavaCall(() => {
|
await this.enqueueJavaCall(() => {
|
||||||
this.communicator.playBuzzerSequence(snapshot.buffer);
|
this.communicator.playBuzzerSequence(this.buzzerBuffer.load(snapshot));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
* reasonable for a sideloaded personal tool).
|
* reasonable for a sideloaded personal tool).
|
||||||
*/
|
*/
|
||||||
import { Utils } from "@nativescript/core";
|
import { Utils } from "@nativescript/core";
|
||||||
|
import { copyToJavaByteBuffer } from "./java-direct-buffer";
|
||||||
|
|
||||||
declare const android: any;
|
declare const android: any;
|
||||||
declare const java: any;
|
declare const java: any;
|
||||||
@@ -150,10 +151,9 @@ export function writeBinaryFile(path: string, bytes: Uint8Array): boolean {
|
|||||||
if (parent) parent.mkdirs();
|
if (parent) parent.mkdirs();
|
||||||
const stream = new java.io.FileOutputStream(file);
|
const stream = new java.io.FileOutputStream(file);
|
||||||
try {
|
try {
|
||||||
// An ArrayBuffer marshals to java.nio.ByteBuffer (the same conversion
|
// Write through the channel from a Java direct buffer: a bulk copy, and
|
||||||
// submitSurfaceFrame relies on), so write through the channel.
|
// passing the ArrayBuffer itself would leak it (java-direct-buffer.ts).
|
||||||
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
stream.getChannel().write(copyToJavaByteBuffer(bytes));
|
||||||
stream.getChannel().write(buffer);
|
|
||||||
} finally {
|
} finally {
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
import { copyToJavaByteBuffer } from './java-direct-buffer'
|
||||||
|
|
||||||
declare const com: any
|
declare const com: any
|
||||||
export function firmwareSha256(buffer: ArrayBuffer): string { return String(com.faceclaw.app.FaceclawFirmwareUtil.sha256Hex(buffer)) }
|
|
||||||
export function writeFirmwareFile(path: string, buffer: ArrayBuffer): void { com.faceclaw.app.FaceclawFirmwareUtil.writeFile(path, buffer) }
|
// The image crosses as a fresh Java buffer: passing a JS ArrayBuffer to Java
|
||||||
|
// leaks it (java-direct-buffer.ts).
|
||||||
|
export function firmwareSha256(buffer: ArrayBuffer): string { return String(com.faceclaw.app.FaceclawFirmwareUtil.sha256Hex(copyToJavaByteBuffer(new Uint8Array(buffer)))) }
|
||||||
|
export function writeFirmwareFile(path: string, buffer: ArrayBuffer): void { com.faceclaw.app.FaceclawFirmwareUtil.writeFile(path, copyToJavaByteBuffer(new Uint8Array(buffer))) }
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
import { ImageSource } from "@nativescript/core";
|
import { ImageSource } from "@nativescript/core";
|
||||||
|
|
||||||
import { type GrayImage } from "../graphics/image";
|
import { type GrayImage } from "../graphics/image";
|
||||||
|
import { copyToJavaByteBuffer } from "./java-direct-buffer";
|
||||||
|
|
||||||
declare const com: any;
|
declare const com: any;
|
||||||
|
|
||||||
const PREVIEW_BRIGHTEN_GAMMA = 0.7;
|
const PREVIEW_BRIGHTEN_GAMMA = 0.7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the phone-UI preview for a frame. The pixel buffer is passed to Java
|
* Build the phone-UI preview for a frame. The pixels are copied into a Java
|
||||||
* as an ArrayBuffer (marshalled to a ByteBuffer) and expanded to ARGB there;
|
* direct ByteBuffer and expanded to ARGB there; doing the per-pixel work in JS
|
||||||
* doing the per-pixel work in JS or copying element-by-element across the
|
* or copying element-by-element across the bridge costs ~150ms per frame, and
|
||||||
* bridge costs ~150ms per frame.
|
* passing the ArrayBuffer itself would leak it (java-direct-buffer.ts).
|
||||||
*/
|
*/
|
||||||
export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
|
export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
|
||||||
if (!global.isAndroid) {
|
if (!global.isAndroid) {
|
||||||
@@ -19,7 +20,7 @@ export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
|
|||||||
|
|
||||||
const baked = image.withDrawsBaked();
|
const baked = image.withDrawsBaked();
|
||||||
const bitmap = com.faceclaw.app.PreviewBitmapUtil.fromGray(
|
const bitmap = com.faceclaw.app.PreviewBitmapUtil.fromGray(
|
||||||
baked.pixels.buffer,
|
copyToJavaByteBuffer(baked.pixels),
|
||||||
baked.width,
|
baked.width,
|
||||||
baked.height,
|
baked.height,
|
||||||
PREVIEW_BRIGHTEN_GAMMA,
|
PREVIEW_BRIGHTEN_GAMMA,
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { grayImageFromPacket } from './image-files'
|
import { grayImageFromPacket } from './image-files'
|
||||||
import { type GrayImage } from '../graphics/image'
|
import { type GrayImage } from '../graphics/image'
|
||||||
|
import { copyToJavaByteBuffer } from './java-direct-buffer'
|
||||||
declare const com: any
|
declare const com: any
|
||||||
|
|
||||||
|
/** The encoded bytes cross as a fresh Java buffer; passing the ArrayBuffer leaks it (java-direct-buffer.ts). */
|
||||||
export function decodeImageBytes(bytes: ArrayBuffer, width: number, height: number): GrayImage | null {
|
export function decodeImageBytes(bytes: ArrayBuffer, width: number, height: number): GrayImage | null {
|
||||||
return grayImageFromPacket(com.faceclaw.app.ImageFileLoader.loadGrayFromBytes(bytes, width, height))
|
return grayImageFromPacket(com.faceclaw.app.ImageFileLoader.loadGrayFromBytes(copyToJavaByteBuffer(new Uint8Array(bytes)), width, height))
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
/**
|
||||||
|
* Hands bytes to a Java `java.nio.ByteBuffer` parameter without leaking them.
|
||||||
|
*
|
||||||
|
* Why this exists: NativeScript Android (9.0.4 through at least 9.1.1)
|
||||||
|
* converts a JS ArrayBuffer or typed array passed to a Java method by wrapping
|
||||||
|
* its backing store in `NewDirectByteBuffer` and taking a JNI global ref that is
|
||||||
|
* never deleted (JsArgConverter.cpp, `buffer = env.NewGlobalRef(buffer)`). The
|
||||||
|
* ByteBuffer is also linked to the JS ArrayBuffer as its native counterpart.
|
||||||
|
* The leaked global ref keeps the ByteBuffer reachable forever, so the
|
||||||
|
* runtime's GC handshake (Runtime.makeInstanceWeakAndCheckIfAlive) always says
|
||||||
|
* "alive", the JS finalizer re-arms, and V8 never frees the ArrayBuffer. Every
|
||||||
|
* call leaked its whole buffer plus one global ref.
|
||||||
|
*
|
||||||
|
* On the frame path that meant a full surface (576x260, 640x452 or 640x480
|
||||||
|
* bytes) per submitted frame, including frames the Java side then discards as
|
||||||
|
* unchanged. Measured on a Galaxy Z Fold7, native-heap growth matched frame
|
||||||
|
* bytes submitted to within a few percent, and Samsung's Heimdall memory
|
||||||
|
* manager killed the app at about 6.4 GB. ART also aborts the process once
|
||||||
|
* 51,200 global refs are held, so the ref leak is a second ceiling behind the
|
||||||
|
* memory one.
|
||||||
|
*
|
||||||
|
* The workaround keeps the conversion out of the call: the bytes are copied
|
||||||
|
* into a Java-allocated direct ByteBuffer that is reused, through an
|
||||||
|
* ArrayBuffer view made once with `ArrayBuffer.from` (an external backing
|
||||||
|
* store over the Java memory, no global ref), and the Java ByteBuffer object
|
||||||
|
* itself is passed. A JS proxy for an existing Java object takes the ordinary
|
||||||
|
* object path, which does not leak.
|
||||||
|
*
|
||||||
|
* Contract: the buffer returned by load() is only valid until the next load()
|
||||||
|
* on the same instance, so the Java callee must consume it synchronously and
|
||||||
|
* not keep a reference. The Kotlin consumers (SurfaceCompositor via
|
||||||
|
* AndroidByteReader, playBuzzerSequence, ShellScene.decode) copy or parse
|
||||||
|
* before returning, which satisfies this. One instance belongs to one JS
|
||||||
|
* context (main thread or one worker); instances are not shared across
|
||||||
|
* isolates.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare const java: any;
|
||||||
|
|
||||||
|
/** Minimal surface of java.nio.ByteBuffer this module uses. */
|
||||||
|
export interface JavaByteBufferLike {
|
||||||
|
clear(): unknown;
|
||||||
|
limit(newLimit: number): unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** How to allocate a direct buffer and view its memory; injectable for tests. */
|
||||||
|
export interface DirectBufferBackend {
|
||||||
|
allocateDirect(capacity: number): JavaByteBufferLike;
|
||||||
|
viewOf(buffer: JavaByteBufferLike): Uint8Array;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nativeScriptBackend: DirectBufferBackend = {
|
||||||
|
allocateDirect: (capacity) => java.nio.ByteBuffer.allocateDirect(capacity),
|
||||||
|
viewOf: (buffer) => new Uint8Array((ArrayBuffer as any).from(buffer)),
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Capacity grows in steps of this many bytes, so a slowly growing payload does not reallocate every call. */
|
||||||
|
const CAPACITY_STEP_BYTES = 4096;
|
||||||
|
|
||||||
|
export class JavaDirectBuffer {
|
||||||
|
private javaBuffer: JavaByteBufferLike | null = null;
|
||||||
|
private view: Uint8Array | null = null;
|
||||||
|
/** Number of Java buffers allocated so far (a test and diagnostics hook). */
|
||||||
|
allocations = 0;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly initialCapacity = 0,
|
||||||
|
private readonly backend: DirectBufferBackend = nativeScriptBackend,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy `bytes` into the reused Java buffer and return it with position 0 and
|
||||||
|
* limit `bytes.length`, so `remaining()` equals the byte count. Valid until
|
||||||
|
* the next load() on this instance.
|
||||||
|
*/
|
||||||
|
load(bytes: Uint8Array): JavaByteBufferLike {
|
||||||
|
if (!this.javaBuffer || !this.view || this.view.length < bytes.length) {
|
||||||
|
const wanted = Math.max(bytes.length, this.initialCapacity, 1);
|
||||||
|
const capacity = Math.ceil(wanted / CAPACITY_STEP_BYTES) * CAPACITY_STEP_BYTES;
|
||||||
|
this.javaBuffer = this.backend.allocateDirect(capacity);
|
||||||
|
this.view = this.backend.viewOf(this.javaBuffer);
|
||||||
|
this.allocations++;
|
||||||
|
}
|
||||||
|
this.view.set(bytes);
|
||||||
|
this.javaBuffer.clear();
|
||||||
|
this.javaBuffer.limit(bytes.length);
|
||||||
|
return this.javaBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** As load(), for an optional ArrayBuffer (e.g. a frame's draw list); null stays null. */
|
||||||
|
loadOptional(buffer: ArrayBuffer | null | undefined): JavaByteBufferLike | null {
|
||||||
|
if (!buffer || buffer.byteLength === 0) return null;
|
||||||
|
return this.load(new Uint8Array(buffer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy `bytes` into a fresh Java direct buffer (position 0, limit
|
||||||
|
* `bytes.length`) for a one-off crossing such as an atlas registration or a
|
||||||
|
* file write. Unlike a JavaDirectBuffer nothing is pinned between calls: the
|
||||||
|
* Java buffer is an ordinary object, freed once the JS side drops it.
|
||||||
|
*/
|
||||||
|
export function copyToJavaByteBuffer(
|
||||||
|
bytes: Uint8Array,
|
||||||
|
backend: DirectBufferBackend = nativeScriptBackend,
|
||||||
|
): JavaByteBufferLike {
|
||||||
|
// A zero-capacity direct buffer may have no address to view.
|
||||||
|
const javaBuffer = backend.allocateDirect(Math.max(bytes.length, 1));
|
||||||
|
backend.viewOf(javaBuffer).set(bytes);
|
||||||
|
javaBuffer.limit(bytes.length);
|
||||||
|
return javaBuffer;
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { copyToJavaByteBuffer } from './java-direct-buffer'
|
||||||
|
|
||||||
declare const com: any
|
declare const com: any
|
||||||
|
|
||||||
/** Development-only checks of NativeScript metadata and bulk ByteBuffer crossings. */
|
/** Development-only checks of NativeScript metadata and bulk ByteBuffer crossings. */
|
||||||
@@ -10,11 +12,11 @@ export function runKotlinProtocolSmokeTest(): void {
|
|||||||
const compositor = new native.SurfaceCompositor()
|
const compositor = new native.SurfaceCompositor()
|
||||||
compositor.configureScreen(3, 2)
|
compositor.configureScreen(3, 2)
|
||||||
compositor.configureSurface('test', 0, 0, 3, 2, 0, 0)
|
compositor.configureSurface('test', 0, 0, 3, 2, 0, 0)
|
||||||
const pixels = new Uint8Array([0, 16, 255, 32, 48, 64])
|
const pixels = copyToJavaByteBuffer(new Uint8Array([0, 16, 255, 32, 48, 64]))
|
||||||
compositor.submitSurface('test', new native.AndroidByteReader(pixels.buffer), 0, 0, 3, 2, '1')
|
compositor.submitSurface('test', new native.AndroidByteReader(pixels), 0, 0, 3, 2, '1')
|
||||||
assert(hex(compositor.composite().gray) === '0010ff203040', 'composition/ByteBuffer')
|
assert(hex(compositor.composite().gray) === '0010ff203040', 'composition/ByteBuffer')
|
||||||
assert(hex(native.BmpUtil.pack4bppFromGray8(compositor.composite().gray, 3, 2)) === '01f02340', 'packing')
|
assert(hex(native.BmpUtil.pack4bppFromGray8(compositor.composite().gray, 3, 2)) === '01f02340', 'packing')
|
||||||
const id = native.ImageAtlas.ensure('kotlin-smoke', 3, 2, new native.AndroidByteReader(pixels.buffer))
|
const id = native.ImageAtlas.ensure('kotlin-smoke', 3, 2, new native.AndroidByteReader(pixels))
|
||||||
assert(id > 0 && native.ImageAtlas.get(id).width === 3, 'image atlas/reused buffer')
|
assert(id > 0 && native.ImageAtlas.get(id).width === 3, 'image atlas/reused buffer')
|
||||||
console.log('FACECLAW_KOTLIN_PROTOCOL_PASS Android')
|
console.log('FACECLAW_KOTLIN_PROTOCOL_PASS Android')
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ImageSource, Utils } from "@nativescript/core";
|
import { ImageSource, Utils } from "@nativescript/core";
|
||||||
import { dimFactor256, type FaceclawCommunicatorBridge, type SurfaceOptions } from "./faceclaw-communicator";
|
import { dimFactor256, type FaceclawCommunicatorBridge, type SurfaceOptions } from "./faceclaw-communicator";
|
||||||
|
import { JavaDirectBuffer } from "./java-direct-buffer";
|
||||||
|
|
||||||
declare const com: any;
|
declare const com: any;
|
||||||
declare const java: any;
|
declare const java: any;
|
||||||
@@ -49,6 +50,11 @@ function nonNegativeNumber(value: number): number {
|
|||||||
*/
|
*/
|
||||||
export class PreviewDisplayTarget implements DisplayTarget {
|
export class PreviewDisplayTarget implements DisplayTarget {
|
||||||
private readonly compositor: any;
|
private readonly compositor: any;
|
||||||
|
// Reused Java-side buffers: passing a JS ArrayBuffer to Java leaks it
|
||||||
|
// (java-direct-buffer.ts).
|
||||||
|
private readonly framePixelsBuffer = new JavaDirectBuffer(640 * 480);
|
||||||
|
private readonly frameDrawsBuffer = new JavaDirectBuffer();
|
||||||
|
private readonly shellSceneBuffer = new JavaDirectBuffer();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const context = Utils.android.getApplicationContext();
|
const context = Utils.android.getApplicationContext();
|
||||||
@@ -104,7 +110,7 @@ export class PreviewDisplayTarget implements DisplayTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async submitShellScene(bytes: Uint8Array, paintMs = 0, frameId = 0): Promise<void> {
|
async submitShellScene(bytes: Uint8Array, paintMs = 0, frameId = 0): Promise<void> {
|
||||||
this.compositor.submitShellScene(new Uint8Array(bytes).buffer, paintMs, frameId);
|
this.compositor.submitShellScene(this.shellSceneBuffer.load(bytes), paintMs, frameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setUnderlayDim(belowZOrder: number, factor: number): Promise<void> {
|
async setUnderlayDim(belowZOrder: number, factor: number): Promise<void> {
|
||||||
@@ -124,11 +130,11 @@ export class PreviewDisplayTarget implements DisplayTarget {
|
|||||||
frameId = 0,
|
frameId = 0,
|
||||||
glyphs: ArrayBuffer | null = null,
|
glyphs: ArrayBuffer | null = null,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Copy for the same reason the bridge does: the source may be a view on a
|
// Copied into a reused Java direct buffer, sized to exactly this view's
|
||||||
// larger buffer, and Java receives the backing ArrayBuffer.
|
// bytes; passing the ArrayBuffer itself would leak it
|
||||||
const snapshot = new Uint8Array(pixels8bpp);
|
// (java-direct-buffer.ts).
|
||||||
this.compositor.submitSurfaceFrame(
|
this.compositor.submitSurfaceFrame(
|
||||||
snapshot.buffer,
|
this.framePixelsBuffer.load(pixels8bpp),
|
||||||
surfaceId,
|
surfaceId,
|
||||||
Math.round(rect.x),
|
Math.round(rect.x),
|
||||||
Math.round(rect.y),
|
Math.round(rect.y),
|
||||||
@@ -137,7 +143,7 @@ export class PreviewDisplayTarget implements DisplayTarget {
|
|||||||
fingerprint,
|
fingerprint,
|
||||||
Math.round(nonNegativeNumber(paintMs)),
|
Math.round(nonNegativeNumber(paintMs)),
|
||||||
Math.round(nonNegativeNumber(frameId)),
|
Math.round(nonNegativeNumber(frameId)),
|
||||||
glyphs,
|
this.frameDrawsBuffer.loadOptional(glyphs),
|
||||||
);
|
);
|
||||||
// The Java side finishes the frame: the composite is the end of the line,
|
// The Java side finishes the frame: the composite is the end of the line,
|
||||||
// and worker isolates submit to the same object without coming through here.
|
// and worker isolates submit to the same object without coming through here.
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
|
import { copyToJavaByteBuffer } from './java-direct-buffer'
|
||||||
|
|
||||||
declare const com: any
|
declare const com: any
|
||||||
|
|
||||||
|
// Byte payloads cross as fresh Java buffers: passing a JS ArrayBuffer to Java
|
||||||
|
// leaks it (java-direct-buffer.ts).
|
||||||
|
|
||||||
/** Android bridge to the process-wide shared Kotlin atlases. */
|
/** Android bridge to the process-wide shared Kotlin atlases. */
|
||||||
export function textureAtlasAvailable(): boolean { return !!global.isAndroid }
|
export function textureAtlasAvailable(): boolean { return !!global.isAndroid }
|
||||||
export function textureFontId(key: string): number { return com.faceclaw.app.GlyphAtlas.fontId(key) }
|
export function textureFontId(key: string): number { return com.faceclaw.app.GlyphAtlas.fontId(key) }
|
||||||
export function registerTextureGlyphs(buffer: ArrayBuffer, aa: boolean): void {
|
export function registerTextureGlyphs(buffer: ArrayBuffer, aa: boolean): void {
|
||||||
const reader = new com.faceclaw.app.AndroidByteReader(buffer)
|
const reader = new com.faceclaw.app.AndroidByteReader(copyToJavaByteBuffer(new Uint8Array(buffer)))
|
||||||
if (aa) com.faceclaw.app.GlyphAtlas.registerAa(reader)
|
if (aa) com.faceclaw.app.GlyphAtlas.registerAa(reader)
|
||||||
else com.faceclaw.app.GlyphAtlas.register(reader)
|
else com.faceclaw.app.GlyphAtlas.register(reader)
|
||||||
}
|
}
|
||||||
export function registerFirmwareGlyphs(buffer: ArrayBuffer): void {
|
export function registerFirmwareGlyphs(buffer: ArrayBuffer): void {
|
||||||
com.faceclaw.app.FwGlyphAtlas.register(new com.faceclaw.app.AndroidByteReader(buffer))
|
com.faceclaw.app.FwGlyphAtlas.register(new com.faceclaw.app.AndroidByteReader(copyToJavaByteBuffer(new Uint8Array(buffer))))
|
||||||
}
|
}
|
||||||
export function textureImageId(key: string, width: number, height: number, pixels: Uint8Array): number {
|
export function textureImageId(key: string, width: number, height: number, pixels: Uint8Array): number {
|
||||||
const buffer = pixels.byteOffset === 0 && pixels.byteLength === pixels.buffer.byteLength ? pixels.buffer : pixels.slice().buffer
|
return com.faceclaw.app.ImageAtlas.ensure(key, width, height, new com.faceclaw.app.AndroidByteReader(copyToJavaByteBuffer(pixels)))
|
||||||
return com.faceclaw.app.ImageAtlas.ensure(key, width, height, new com.faceclaw.app.AndroidByteReader(buffer))
|
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
import type { WorkerAppReply } from "../ui/shell/worker-window";
|
import type { WorkerAppReply } from "../ui/shell/worker-window";
|
||||||
|
import { JavaDirectBuffer } from "./java-direct-buffer";
|
||||||
|
|
||||||
declare const com: any;
|
declare const com: any;
|
||||||
|
|
||||||
|
// Reused Java-side buffer for this isolate's tone payloads: passing a JS
|
||||||
|
// ArrayBuffer to Java leaks it (java-direct-buffer.ts).
|
||||||
|
const buzzerBuffer = new JavaDirectBuffer();
|
||||||
|
|
||||||
/** Workers use the main-thread BLE session on iOS and the native queue on Android. */
|
/** Workers use the main-thread BLE session on iOS and the native queue on Android. */
|
||||||
export function playWorkerBuzzerSequence(payload: Uint8Array): void {
|
export function playWorkerBuzzerSequence(payload: Uint8Array): void {
|
||||||
if (global.isIOS) {
|
if (global.isIOS) {
|
||||||
global.postMessage({ type: "buzzer-sequence", payload: Array.from(payload) } satisfies WorkerAppReply);
|
global.postMessage({ type: "buzzer-sequence", payload: Array.from(payload) } satisfies WorkerAppReply);
|
||||||
} else {
|
} else {
|
||||||
com.faceclaw.app.FaceclawBleCommunicator.getActive()?.playBuzzerSequence(new Uint8Array(payload).buffer);
|
com.faceclaw.app.FaceclawBleCommunicator.getActive()?.playBuzzerSequence(buzzerBuffer.load(payload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,573 @@
|
|||||||
|
import { DrawExpression as E } from "../graphics/draw-expression";
|
||||||
|
import { DrawOp, type DisplayList, type ListCall, type ListClip } from "../graphics/display-list";
|
||||||
|
import { encodeReplayDraws } from "../graphics/glyph-wire";
|
||||||
|
import { GrayImage, type UiFont } from "../graphics/image";
|
||||||
|
import { slidingCoordinate } from "../graphics/menu-scroll-list";
|
||||||
|
import { getDefaultSmallFont } from "../graphics/ui-fonts";
|
||||||
|
import { truncateText } from "../graphics/textwrap";
|
||||||
|
import { clamp } from "../util/numeric-util";
|
||||||
|
import { isWatchInput, type InputEvent } from "./gestures";
|
||||||
|
import type { LayerContext } from "./layers";
|
||||||
|
import { drawListScrollbar, drawSelectionHighlight, scrollToKeepSelectionVisible } from "./menu";
|
||||||
|
import { BOUNCE_FRACTION, MAX_BOUNCE, MENU_HIGHLIGHT_FILL, MENU_HIGHLIGHT_STROKE, type MenuBox } from "./menu-core";
|
||||||
|
import { MenuHighlightMotion, type MenuHighlightAnimation } from "./menu-highlight-motion";
|
||||||
|
import { MenuScrollMotion, scrollOffsetExpression, type MenuScrollAnimation } from "./menu-scroll-motion";
|
||||||
|
import { iconGridMinRowHeight } from "./metrics";
|
||||||
|
import { shell } from "./shell/shell";
|
||||||
|
|
||||||
|
/** Size of the square each grid cell reserves for its icon; render icons at this size. */
|
||||||
|
export const ICON_GRID_ICON_SIZE = 44;
|
||||||
|
const LABEL_GAP = 2;
|
||||||
|
const DEFAULT_COLUMNS = 5;
|
||||||
|
const DEFAULT_LABEL_VALUE = 210;
|
||||||
|
/** Wide rows: text inset from the grid's left and right edges. */
|
||||||
|
const WIDE_TEXT_X = 20;
|
||||||
|
/** The scrollbar's columns at the right edge, which animations leave alone. */
|
||||||
|
const SCROLLBAR_GUTTER = 5;
|
||||||
|
|
||||||
|
export type IconGridCell = {
|
||||||
|
label: string;
|
||||||
|
/**
|
||||||
|
* Icon for a grid cell (ignored for wide rows). Drawn as a deferred image,
|
||||||
|
* so it must be long-lived and never mutated: a memoized render, not a
|
||||||
|
* scratch buffer. Icons smaller than ICON_GRID_ICON_SIZE are centered in
|
||||||
|
* the square.
|
||||||
|
*/
|
||||||
|
icon?: GrayImage | null;
|
||||||
|
/** Label brightness. Default 210. */
|
||||||
|
labelValue?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type IconGridOptions<T> = {
|
||||||
|
/** The items to show, fetched fresh at every paint, input, and selection call. */
|
||||||
|
items: () => readonly T[];
|
||||||
|
/** Columns per grid row. Default 5. */
|
||||||
|
columns?: number;
|
||||||
|
/** How to draw an item. `selected` is true while it alone is selected (item mode, or a wide row). */
|
||||||
|
describe: (item: T, selected: boolean) => IconGridCell;
|
||||||
|
/**
|
||||||
|
* Items drawn as a full-width text row of their own (a notice or prompt)
|
||||||
|
* instead of a grid cell. Selection treats such a row as one item.
|
||||||
|
*/
|
||||||
|
isWide?: (item: T) => boolean;
|
||||||
|
/**
|
||||||
|
* Open an item. Return true when this left the grid (e.g. launched an app
|
||||||
|
* or yielded focus) rather than navigating within it; see onBack.
|
||||||
|
*/
|
||||||
|
onActivate: (item: T, index: number, ctx: LayerContext) => boolean | void | Promise<boolean | void>;
|
||||||
|
/**
|
||||||
|
* Back out one level: a ring double-click in row mode, or the watch's back
|
||||||
|
* or left swipe from the first column. Return true when this left the grid.
|
||||||
|
*
|
||||||
|
* After either callback the grid settles its mode: leaving puts it back in
|
||||||
|
* row mode, so a ring user returning finds it as they left it; staying
|
||||||
|
* with watch input keeps single-item selection (which the watch scheme
|
||||||
|
* always uses), even if the host reset the selection while navigating.
|
||||||
|
*/
|
||||||
|
onBack: (ctx: LayerContext) => boolean | void;
|
||||||
|
/** Draw a scrollbar at the right edge when rows overflow. Default false. */
|
||||||
|
scrollbar?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type GridRow<T> =
|
||||||
|
| { kind: "wide"; item: T; firstIndex: number }
|
||||||
|
| { kind: "cells"; items: T[]; firstIndex: number };
|
||||||
|
|
||||||
|
type GridMode = "row" | "item";
|
||||||
|
|
||||||
|
type GridLayout = { box: MenuBox; rowH: number; colW: number };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The selection highlight in image coordinates. `key` names what is
|
||||||
|
* selected for highlight motion: a flat item index, or -1 - row for a
|
||||||
|
* row-mode band.
|
||||||
|
*/
|
||||||
|
type Highlight = { key: number; x: number; y: number; width: number; height: number; radius: number };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An icon grid: items laid out as labeled icons in fixed-width columns, with
|
||||||
|
* optional full-width text rows (see isWide). Like Menu, it is independent of
|
||||||
|
* the Layer stack: the host paints it into a rect of its own image and
|
||||||
|
* forwards input, and keeps the rest (header, what items mean, where back
|
||||||
|
* goes).
|
||||||
|
*
|
||||||
|
* Rows are exactly as tall as their content (icon, label line, breathing
|
||||||
|
* room), so they grow smoothly with the font; they never stretch to fill the
|
||||||
|
* box, which would make the padding jump whenever a font step changed how
|
||||||
|
* many rows fit. Space left below the last full row shows the top of the
|
||||||
|
* next row, cut off at the box's edge, as a hint that there is more to scroll to.
|
||||||
|
*
|
||||||
|
* Ring input navigates on two levels, halving the scrolls to reach an item:
|
||||||
|
* in row mode scroll picks a row and a click drops into item mode on it,
|
||||||
|
* defaulting to the middle column; in item mode scroll traverses items
|
||||||
|
* linearly (continuing onto adjacent rows) and a click opens the item.
|
||||||
|
* Double-click backs out: item mode to row mode, then onBack. A wide row is
|
||||||
|
* opened by a click in either mode. Watch input skips row mode and moves one
|
||||||
|
* cell at a time in four directions: up/down (and the crown) between rows
|
||||||
|
* keeping the column, right/left within the row, and left from the first
|
||||||
|
* column (or a wide row) backs out, as does the watch's back.
|
||||||
|
*
|
||||||
|
* Navigation animates on the glasses as menus do: the highlight slides to
|
||||||
|
* the new selection, rows scroll into view, and moving past an end bounces.
|
||||||
|
* A grid is too big for Menu's pre-rendered strip, so the animation is a
|
||||||
|
* display list that clears the grid and redraws it from the rows' glyph and
|
||||||
|
* icon draws, offset by the animated scroll and clipped to the box
|
||||||
|
* (revision 35 firmware). Its last frame equals the static paint. When a
|
||||||
|
* row can't be replayed that way (a label outside ASCII, say), it snaps.
|
||||||
|
*/
|
||||||
|
export class IconGrid<T> {
|
||||||
|
private mode: GridMode = "row";
|
||||||
|
private selectedRow = 0;
|
||||||
|
private selectedCol = 0;
|
||||||
|
private scrollRow = 0;
|
||||||
|
/** Geometry of the last paint, for hitTest and bounces: what the phone mirror showed. */
|
||||||
|
private layout: GridLayout | null = null;
|
||||||
|
private readonly highlightMotion = new MenuHighlightMotion();
|
||||||
|
private readonly scrollMotion = new MenuScrollMotion();
|
||||||
|
|
||||||
|
constructor(private readonly options: IconGridOptions<T>) {}
|
||||||
|
|
||||||
|
private get columns(): number {
|
||||||
|
return this.options.columns ?? DEFAULT_COLUMNS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Back to row mode on the first row, scrolled to the top (e.g. after entering a directory). */
|
||||||
|
resetSelection(): void {
|
||||||
|
this.mode = "row";
|
||||||
|
this.selectedRow = 0;
|
||||||
|
this.selectedCol = 0;
|
||||||
|
this.scrollRow = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Drop from item mode to row mode, keeping the selected row. */
|
||||||
|
enterRowMode(): void {
|
||||||
|
this.mode = "row";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move the selection onto the item at a flat index (e.g. the directory
|
||||||
|
* just left), leaving the mode and scroll position alone; the next paint
|
||||||
|
* scrolls the minimum needed to show it.
|
||||||
|
*/
|
||||||
|
selectIndex(index: number): void {
|
||||||
|
const rows = this.buildRows();
|
||||||
|
const rowIndex = rows.findIndex((row) => index >= row.firstIndex && index < row.firstIndex + rowLength(row));
|
||||||
|
if (rowIndex < 0) return;
|
||||||
|
this.selectedRow = rowIndex;
|
||||||
|
this.selectedCol = index - rows[rowIndex]!.firstIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flat index of the item under the selection. In row mode on a grid row
|
||||||
|
* that is the cell at the remembered column, though no single item is
|
||||||
|
* selected yet (see selectedItem). Null when there are no items.
|
||||||
|
*/
|
||||||
|
get cursorIndex(): number | null {
|
||||||
|
const row = this.currentRow();
|
||||||
|
if (!row) return null;
|
||||||
|
return row.kind === "wide" ? row.firstIndex : row.firstIndex + clamp(this.selectedCol, 0, row.items.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The single selected item: a wide row, or a cell in item mode. Null in row mode on a grid row. */
|
||||||
|
get selectedItem(): T | null {
|
||||||
|
const row = this.currentRow();
|
||||||
|
if (!row) return null;
|
||||||
|
if (row.kind === "wide") return row.item;
|
||||||
|
if (this.mode !== "item") return null;
|
||||||
|
return row.items[clamp(this.selectedCol, 0, row.items.length - 1)] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Focus arriving from the watch goes straight to item selection: the watch
|
||||||
|
* has left/right swipes, so it never needs row mode, and starting there
|
||||||
|
* would paint a row band its scheme can't produce. Any other source enters
|
||||||
|
* in row mode.
|
||||||
|
*/
|
||||||
|
onFocus(lastInput: InputEvent | null): void {
|
||||||
|
if (lastInput && isWatchInput(lastInput)) {
|
||||||
|
this.mode = "item";
|
||||||
|
this.clampSelection(this.buildRows());
|
||||||
|
} else {
|
||||||
|
this.mode = "row";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
paint(image: GrayImage, box: MenuBox, focused: boolean): void {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
|
const rows = this.buildRows();
|
||||||
|
this.clampSelection(rows);
|
||||||
|
const rowH = iconGridMinRowHeight(font, ICON_GRID_ICON_SIZE, LABEL_GAP);
|
||||||
|
const fullRows = Math.max(1, Math.floor(box.height / rowH));
|
||||||
|
// Scroll to keep the selected row among the fully-visible rows.
|
||||||
|
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, this.selectedRow, fullRows, rows.length);
|
||||||
|
const layout: GridLayout = { box, rowH, colW: box.width / this.columns };
|
||||||
|
this.layout = layout;
|
||||||
|
|
||||||
|
const highlight = this.highlight(rows, layout, font, focused);
|
||||||
|
const bottom = box.y + box.height;
|
||||||
|
for (let rowIndex = this.scrollRow; rowIndex < rows.length; rowIndex++) {
|
||||||
|
const y = box.y + (rowIndex - this.scrollRow) * rowH;
|
||||||
|
if (y >= bottom) break;
|
||||||
|
if (highlight && rowIndex === this.selectedRow) {
|
||||||
|
drawSelectionHighlight(image, highlight.x, highlight.y, highlight.width, highlight.height, focused, highlight.radius);
|
||||||
|
}
|
||||||
|
this.drawRow(image, rows[rowIndex]!, rowIndex, box.x, y, layout, font, bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
const scrollbar = !!this.options.scrollbar && rows.length > fullRows;
|
||||||
|
if (scrollbar) {
|
||||||
|
drawListScrollbar(image, box.x + box.width - SCROLLBAR_GUTTER, box.y, box.height, this.scrollRow, fullRows, rows.length);
|
||||||
|
}
|
||||||
|
this.paintMotion(image, rows, layout, font, focused, highlight, scrollbar);
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||||
|
if (isWatchInput(event)) {
|
||||||
|
await this.handleWatchInput(event, ctx);
|
||||||
|
} else {
|
||||||
|
await this.handleRingInput(event, ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A touch on the phone's mirror: the item under it becomes the selection
|
||||||
|
* and opens, as a ring click on it would. Uses the last paint's geometry,
|
||||||
|
* so it lands on what the mirror showed.
|
||||||
|
*/
|
||||||
|
async hitTest(x: number, y: number, ctx: LayerContext): Promise<boolean> {
|
||||||
|
if (!this.layout) return false;
|
||||||
|
const { box, rowH, colW } = this.layout;
|
||||||
|
if (x < box.x || x >= box.x + box.width || y < box.y || y >= box.y + box.height) return false;
|
||||||
|
const rowIndex = this.scrollRow + Math.floor((y - box.y) / rowH);
|
||||||
|
const row = this.buildRows()[rowIndex];
|
||||||
|
if (!row) return false;
|
||||||
|
if (row.kind === "cells") {
|
||||||
|
const col = Math.floor((x - box.x) / colW);
|
||||||
|
if (col >= row.items.length) return false;
|
||||||
|
this.selectedCol = col;
|
||||||
|
}
|
||||||
|
this.selectedRow = rowIndex;
|
||||||
|
this.mode = "item";
|
||||||
|
await this.activateSelected(false, ctx);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The highlight for the current selection: a row band, a single cell in
|
||||||
|
* item mode, or a box around a wide row's text. While defocused with the
|
||||||
|
* watch as the last-used source, the cell outline is shown even in row
|
||||||
|
* mode: watch focus enters item mode directly (see onFocus), so the
|
||||||
|
* outline previews the cell a click would land on rather than a row band
|
||||||
|
* the watch scheme never shows. Every cell's box has the same width, so
|
||||||
|
* the highlight can slide between any two.
|
||||||
|
*/
|
||||||
|
private highlight(rows: readonly GridRow<T>[], layout: GridLayout, font: UiFont, focused: boolean): Highlight | null {
|
||||||
|
const row = rows[this.selectedRow];
|
||||||
|
if (!row) return null;
|
||||||
|
const { box, rowH, colW } = layout;
|
||||||
|
const y = box.y + (this.selectedRow - this.scrollRow) * rowH;
|
||||||
|
if (row.kind === "wide") {
|
||||||
|
const textY = y + wideTextOffset(rowH, font);
|
||||||
|
return { key: row.firstIndex, x: box.x + WIDE_TEXT_X - 6, y: textY - 2,
|
||||||
|
width: box.width - 2 * WIDE_TEXT_X + 12, height: font.lineHeight + 4, radius: 4 };
|
||||||
|
}
|
||||||
|
if (this.mode === "item" || (!focused && shell.lastInputWasWatch())) {
|
||||||
|
return { key: row.firstIndex + this.selectedCol, x: Math.round(box.x + this.selectedCol * colW) + 6, y: y + 2,
|
||||||
|
width: Math.round(colW) - 12, height: rowH - 4, radius: 6 };
|
||||||
|
}
|
||||||
|
return { key: -1 - this.selectedRow, x: box.x + 4, y: y + 2, width: box.width - 8, height: rowH - 4, radius: 6 };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw one row's icons and labels (not the highlight) with its top at y.
|
||||||
|
* A row crossing `clipBottom` goes through a scratch image cut off there,
|
||||||
|
* so the static peeking row matches an animation's clipped frames.
|
||||||
|
*/
|
||||||
|
private drawRow(target: GrayImage, row: GridRow<T>, rowIndex: number, x0: number, y: number,
|
||||||
|
layout: GridLayout, font: UiFont, clipBottom?: number): void {
|
||||||
|
const { rowH, colW } = layout;
|
||||||
|
if (clipBottom !== undefined && y + rowH > clipBottom) {
|
||||||
|
const scratch = new GrayImage(layout.box.width, rowH);
|
||||||
|
this.drawRow(scratch, row, rowIndex, 0, 0, layout, font);
|
||||||
|
target.bitBlt(scratch.withDrawsBaked(), x0, y, { height: clipBottom - y, transparentZero: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const rowSelected = rowIndex === this.selectedRow;
|
||||||
|
if (row.kind === "wide") {
|
||||||
|
const { label, labelValue = DEFAULT_LABEL_VALUE } = this.options.describe(row.item, rowSelected);
|
||||||
|
const width = layout.box.width - 2 * WIDE_TEXT_X;
|
||||||
|
target.drawText(font, x0 + WIDE_TEXT_X, y + wideTextOffset(rowH, font), truncateText(font, label, width), labelValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const blockTop = y + Math.max(2, (rowH - ICON_GRID_ICON_SIZE - font.lineHeight - LABEL_GAP) / 2);
|
||||||
|
for (let col = 0; col < row.items.length; col++) {
|
||||||
|
const cell = this.options.describe(row.items[col]!, rowSelected && this.mode === "item" && col === this.selectedCol);
|
||||||
|
const centerX = x0 + col * colW + colW / 2;
|
||||||
|
if (cell.icon) {
|
||||||
|
const icon = cell.icon;
|
||||||
|
target.drawImage(icon, Math.round(centerX - icon.width / 2),
|
||||||
|
Math.round(blockTop + Math.max(0, (ICON_GRID_ICON_SIZE - icon.height) / 2)));
|
||||||
|
}
|
||||||
|
const label = truncateText(font, cell.label, colW - 8);
|
||||||
|
target.drawText(font, Math.round(centerX - font.measureText(label) / 2), Math.round(blockTop + ICON_GRID_ICON_SIZE + LABEL_GAP),
|
||||||
|
label, cell.labelValue ?? DEFAULT_LABEL_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Track this paint's scroll offset and highlight, and while either is
|
||||||
|
* moving, retain the display list that animates them over the static paint.
|
||||||
|
*/
|
||||||
|
private paintMotion(image: GrayImage, rows: readonly GridRow<T>[], layout: GridLayout, font: UiFont,
|
||||||
|
focused: boolean, highlight: Highlight | null, scrollbar: boolean): void {
|
||||||
|
const now = Date.now();
|
||||||
|
const scrollOffset = this.scrollRow * layout.rowH;
|
||||||
|
const scroll = this.scrollMotion.paint(scrollOffset, layout.box, now);
|
||||||
|
const slide = highlight
|
||||||
|
? this.highlightMotion.paint(highlight.key, scrollOffset, highlight.x, highlight.y, highlight.width, highlight.height, now, !!scroll)
|
||||||
|
: undefined;
|
||||||
|
if (!scroll && !slide) return;
|
||||||
|
const { box } = layout;
|
||||||
|
const clip: ListClip = { x: 0, y: 0, width: box.width - (scrollbar ? SCROLLBAR_GUTTER : 0), height: box.height };
|
||||||
|
const list = this.motionList(rows, layout, font, focused, highlight, clip, scroll, slide);
|
||||||
|
if (!list) {
|
||||||
|
this.scrollMotion.cancel();
|
||||||
|
this.highlightMotion.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
image.drawDisplayList(list, box.x, box.y, clip.width, clip.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The animation, in box coordinates: clear the box, draw the highlight
|
||||||
|
* (sliding, and carried along by a bounce), then replay every row visible
|
||||||
|
* at any point of the scroll, offset by it. Null when those rows hold
|
||||||
|
* anything the glasses can't replay.
|
||||||
|
*/
|
||||||
|
private motionList(rows: readonly GridRow<T>[], layout: GridLayout, font: UiFont, focused: boolean,
|
||||||
|
highlight: Highlight | null, clip: ListClip, scroll: MenuScrollAnimation | undefined,
|
||||||
|
slide: MenuHighlightAnimation | undefined): DisplayList | null {
|
||||||
|
const { box, rowH } = layout;
|
||||||
|
const scrollOffset = this.scrollRow * rowH;
|
||||||
|
const offsets = scroll ? [scroll.from, scroll.to, scroll.peak ?? scroll.to] : [scrollOffset];
|
||||||
|
const firstRow = Math.max(0, Math.floor(Math.min(...offsets) / rowH));
|
||||||
|
const lastRow = Math.min(rows.length, Math.ceil((Math.max(...offsets) + box.height) / rowH));
|
||||||
|
const content = new GrayImage(box.width, Math.max(1, (lastRow - firstRow) * rowH));
|
||||||
|
for (let rowIndex = firstRow; rowIndex < lastRow; rowIndex++) {
|
||||||
|
this.drawRow(content, rows[rowIndex]!, rowIndex, 0, (rowIndex - firstRow) * rowH, layout, font);
|
||||||
|
}
|
||||||
|
if (content.pixels.some((value) => value !== 0)) return null;
|
||||||
|
const replay = encodeReplayDraws(content.draws);
|
||||||
|
if (!replay) return null;
|
||||||
|
|
||||||
|
// One timeline: the newer motion's. The other, if any, continues on it with a negative delay.
|
||||||
|
const timeline = scroll && (!slide || scroll.startedAt >= slide.startedAt) ? scroll : slide!;
|
||||||
|
const offset = scroll ? scrollOffsetExpression(scroll, timeline.startedAt) : E.i32(scrollOffset);
|
||||||
|
const calls: ListCall[] = [{ op: DrawOp.CLEAR, color: 0, clip }];
|
||||||
|
if (highlight) {
|
||||||
|
let y = slidingCoordinate(highlight.y - box.y, slide?.dy ?? 0, slide, timeline.startedAt);
|
||||||
|
// A bounce carries the highlight with its row.
|
||||||
|
if (scroll?.peak !== undefined) y = y.add(E.i32(scroll.to)).sub(offset);
|
||||||
|
const q = (gray: number) => Math.min(15, (gray + 8) >> 4);
|
||||||
|
calls.push({ op: DrawOp.ROUNDED_RECT, x: slidingCoordinate(highlight.x - box.x, slide?.dx ?? 0, slide, timeline.startedAt), y,
|
||||||
|
width: highlight.width, height: highlight.height, radius: highlight.radius,
|
||||||
|
background: focused ? q(MENU_HIGHLIGHT_FILL) : 0, border: q(MENU_HIGHLIGHT_STROKE), clip });
|
||||||
|
}
|
||||||
|
// Without a scroll the rows stay put; a literal keeps every compiled call small.
|
||||||
|
const rowsY = scroll ? E.i32(firstRow * rowH).sub(offset) : (firstRow - this.scrollRow) * rowH;
|
||||||
|
calls.push({ op: DrawOp.DRAWS, x: 0, y: rowsY, records: replay.records, count: replay.count, source: content, clip });
|
||||||
|
return { resources: [], timeline: { token: timeline.token, startedAt: timeline.startedAt }, calls };
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleRingInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||||
|
const rows = this.buildRows();
|
||||||
|
this.clampSelection(rows);
|
||||||
|
const row = rows[this.selectedRow];
|
||||||
|
const from = this.selectionKey(rows);
|
||||||
|
switch (event.type) {
|
||||||
|
case "scroll-up":
|
||||||
|
case "scroll-down": {
|
||||||
|
const delta = event.type === "scroll-down" ? 1 : -1;
|
||||||
|
if (this.mode === "row") {
|
||||||
|
const next = this.selectedRow + delta;
|
||||||
|
if (next < 0 || next >= rows.length) {
|
||||||
|
this.bounce(delta);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.selectedRow = next;
|
||||||
|
this.moved(from);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Past a row's edge, item selection continues onto the adjacent row
|
||||||
|
// (a wide row counts as a single item), stopping at the grid's ends.
|
||||||
|
if (row?.kind === "cells") {
|
||||||
|
const next = this.selectedCol + delta;
|
||||||
|
if (next >= 0 && next < row.items.length) {
|
||||||
|
this.selectedCol = next;
|
||||||
|
this.moved(from);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const adjacent = rows[this.selectedRow + delta];
|
||||||
|
if (!adjacent) {
|
||||||
|
this.bounce(delta);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.selectedRow += delta;
|
||||||
|
if (adjacent.kind === "cells") {
|
||||||
|
this.selectedCol = delta > 0 ? 0 : adjacent.items.length - 1;
|
||||||
|
}
|
||||||
|
this.moved(from);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case "click":
|
||||||
|
if (!row) return;
|
||||||
|
if (row.kind === "cells" && this.mode === "row") {
|
||||||
|
this.mode = "item";
|
||||||
|
this.selectedCol = Math.min(Math.floor(this.columns / 2), row.items.length - 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.activateSelected(false, ctx);
|
||||||
|
return;
|
||||||
|
case "double-click":
|
||||||
|
if (this.mode === "item") {
|
||||||
|
this.mode = "row";
|
||||||
|
} else {
|
||||||
|
this.settleAfter(this.options.onBack(ctx) === true, false);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleWatchInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||||
|
const rows = this.buildRows();
|
||||||
|
this.mode = "item";
|
||||||
|
this.clampSelection(rows);
|
||||||
|
const row = rows[this.selectedRow];
|
||||||
|
const from = this.selectionKey(rows);
|
||||||
|
const back = () => this.settleAfter(this.options.onBack(ctx) === true, true);
|
||||||
|
switch (event.type) {
|
||||||
|
case "swipe-up":
|
||||||
|
case "swipe-down":
|
||||||
|
case "scroll-up":
|
||||||
|
case "scroll-down": {
|
||||||
|
const delta = event.type === "swipe-down" || event.type === "scroll-down" ? 1 : -1;
|
||||||
|
const next = this.selectedRow + delta;
|
||||||
|
if (next < 0 || next >= rows.length) {
|
||||||
|
this.bounce(delta);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.selectedRow = next;
|
||||||
|
// Keep the column; a shorter row (or a wide one) clamps it.
|
||||||
|
this.clampSelection(rows);
|
||||||
|
this.moved(from);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case "swipe-right":
|
||||||
|
if (row?.kind === "cells" && this.selectedCol + 1 < row.items.length) {
|
||||||
|
this.selectedCol++;
|
||||||
|
this.moved(from);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
case "swipe-left":
|
||||||
|
if (row?.kind === "cells" && this.selectedCol > 0) {
|
||||||
|
this.selectedCol--;
|
||||||
|
this.moved(from);
|
||||||
|
} else {
|
||||||
|
back();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
case "click":
|
||||||
|
await this.activateSelected(true, ctx);
|
||||||
|
return;
|
||||||
|
case "double-click":
|
||||||
|
back();
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The highlight key (see Highlight) of the selection while focused. */
|
||||||
|
private selectionKey(rows: readonly GridRow<T>[]): number | null {
|
||||||
|
const row = rows[this.selectedRow];
|
||||||
|
if (!row) return null;
|
||||||
|
if (row.kind === "wide") return row.firstIndex;
|
||||||
|
return this.mode === "item" ? row.firstIndex + this.selectedCol : -1 - this.selectedRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The selection just moved by navigation, from `from`: the next paint animates the change. */
|
||||||
|
private moved(from: number | null): void {
|
||||||
|
if (from !== null) this.highlightMotion.navigate(from, false);
|
||||||
|
this.scrollMotion.navigate(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Navigation past an end: overshoot a little and come back, as menus do. */
|
||||||
|
private bounce(delta: -1 | 1): void {
|
||||||
|
const rowH = this.layout?.rowH;
|
||||||
|
if (!rowH) return;
|
||||||
|
this.scrollMotion.bounce(delta * Math.min(MAX_BOUNCE, Math.round(rowH * BOUNCE_FRACTION)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async activateSelected(watch: boolean, ctx: LayerContext): Promise<void> {
|
||||||
|
const index = this.cursorIndex;
|
||||||
|
if (index === null) return;
|
||||||
|
const item = this.options.items()[index];
|
||||||
|
if (item === undefined) return;
|
||||||
|
this.settleAfter((await this.options.onActivate(item, index, ctx)) === true, watch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The mode rule after a host callback; see IconGridOptions.onBack. */
|
||||||
|
private settleAfter(left: boolean, watch: boolean): void {
|
||||||
|
if (left) {
|
||||||
|
this.mode = "row";
|
||||||
|
} else if (watch) {
|
||||||
|
this.mode = "item";
|
||||||
|
this.clampSelection(this.buildRows());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private currentRow(): GridRow<T> | undefined {
|
||||||
|
const rows = this.buildRows();
|
||||||
|
return rows[clamp(this.selectedRow, 0, Math.max(0, rows.length - 1))];
|
||||||
|
}
|
||||||
|
|
||||||
|
private clampSelection(rows: readonly GridRow<T>[]): void {
|
||||||
|
this.selectedRow = clamp(this.selectedRow, 0, Math.max(0, rows.length - 1));
|
||||||
|
const row = rows[this.selectedRow];
|
||||||
|
this.selectedCol = row?.kind === "cells" ? clamp(this.selectedCol, 0, row.items.length - 1) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wide items get a row of their own; runs of other items are chunked into rows of `columns`. */
|
||||||
|
private buildRows(): GridRow<T>[] {
|
||||||
|
const items = this.options.items();
|
||||||
|
const isWide = this.options.isWide;
|
||||||
|
const rows: GridRow<T>[] = [];
|
||||||
|
let cells: Extract<GridRow<T>, { kind: "cells" }> | null = null;
|
||||||
|
for (let index = 0; index < items.length; index++) {
|
||||||
|
const item = items[index]!;
|
||||||
|
if (isWide?.(item)) {
|
||||||
|
rows.push({ kind: "wide", item, firstIndex: index });
|
||||||
|
cells = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!cells || cells.items.length >= this.columns) {
|
||||||
|
cells = { kind: "cells", items: [], firstIndex: index };
|
||||||
|
rows.push(cells);
|
||||||
|
}
|
||||||
|
cells.items.push(item);
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function rowLength<T>(row: GridRow<T>): number {
|
||||||
|
return row.kind === "wide" ? 1 : row.items.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A wide row's text top, relative to the row's top. */
|
||||||
|
function wideTextOffset(rowH: number, font: UiFont): number {
|
||||||
|
return ((rowH - font.lineHeight) / 2) | 0;
|
||||||
|
}
|
||||||
+2
-2
@@ -15,8 +15,8 @@ const SCROLLBAR_MIN_THUMB = 8;
|
|||||||
/** Largest packed scroll strip, in bytes: the firmware's per-resource limit. */
|
/** Largest packed scroll strip, in bytes: the firmware's per-resource limit. */
|
||||||
const MAX_SCROLL_STRIP_BYTES = 65536;
|
const MAX_SCROLL_STRIP_BYTES = 65536;
|
||||||
/** A bounce overshoots by this fraction of the end row's pitch, as if starting to reveal another row. */
|
/** A bounce overshoots by this fraction of the end row's pitch, as if starting to reveal another row. */
|
||||||
const BOUNCE_FRACTION = 0.4;
|
export const BOUNCE_FRACTION = 0.4;
|
||||||
const MAX_BOUNCE = 24;
|
export const MAX_BOUNCE = 24;
|
||||||
|
|
||||||
/** A rectangle in image coordinates. */
|
/** A rectangle in image coordinates. */
|
||||||
export type MenuBox = { x: number; y: number; width: number; height: number };
|
export type MenuBox = { x: number; y: number; width: number; height: number };
|
||||||
|
|||||||
@@ -38,4 +38,9 @@ export class MenuHighlightMotion {
|
|||||||
}
|
}
|
||||||
return this.animation && now - this.animation.startedAt < this.animation.durationMs ? this.animation : undefined;
|
return this.animation && now - this.animation.startedAt < this.animation.durationMs ? this.animation : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Cancel an animation in flight, e.g. when it cannot be drawn; the next change snaps from where it rests. */
|
||||||
|
cancel(): void {
|
||||||
|
this.animation = undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -32,13 +32,14 @@ export function scrollOffsetAt(animation: MenuScrollAnimation, t: number): numbe
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The offset as a draw expression on the animation's own timeline. The easing
|
* The offset as a draw expression, on a list timeline that started at
|
||||||
* ops clamp their input, which splits a bounce into its two phases without
|
* `timelineStart` (by default the animation's own start). The easing ops
|
||||||
|
* clamp their input, which splits a bounce into its two phases without
|
||||||
* comparisons: the return term stays 0 until the peak, the outward one stays 1 after.
|
* comparisons: the return term stays 0 until the peak, the outward one stays 1 after.
|
||||||
*/
|
*/
|
||||||
export function scrollOffsetExpression(animation: MenuScrollAnimation) {
|
export function scrollOffsetExpression(animation: MenuScrollAnimation, timelineStart = animation.startedAt) {
|
||||||
const { from, to, peak } = animation;
|
const { from, to, peak } = animation;
|
||||||
const t = () => E.progress(animation.durationMs);
|
const t = () => E.progress(animation.durationMs, animation.startedAt - timelineStart);
|
||||||
if (peak === undefined) return t().ease().lerp(E.i32(from).toFloat(), E.i32(to).toFloat()).toInt();
|
if (peak === undefined) return t().ease().lerp(E.i32(from).toFloat(), E.i32(to).toFloat()).toInt();
|
||||||
const out = t().mul(E.f32(1 / BOUNCE_PEAK)).ease(ExprOp.EASE_OUT_QUAD);
|
const out = t().mul(E.f32(1 / BOUNCE_PEAK)).ease(ExprOp.EASE_OUT_QUAD);
|
||||||
const back = t().sub(E.f32(BOUNCE_PEAK)).div(E.f32(1 - BOUNCE_PEAK)).ease();
|
const back = t().sub(E.f32(BOUNCE_PEAK)).div(E.f32(1 - BOUNCE_PEAK)).ease();
|
||||||
|
|||||||
+5
-4
@@ -100,10 +100,11 @@ export function menuTitleHeight(font: UiFont): number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minimum height of an icon-grid cell (icon, label line, breathing room).
|
* Height of an icon-grid row (icon, label line, breathing room). IconGrid
|
||||||
* Grid views divide their available height into as many rows of at least
|
* uses it as the row pitch directly, so cells grow smoothly with the font
|
||||||
* this height as fit, so cells grow with the font instead of the label
|
* instead of the label overflowing a fixed-height row. Don't stretch rows to
|
||||||
* overflowing a fixed-height row.
|
* fill the viewport: the padding would jump whenever a font step changes how
|
||||||
|
* many rows fit.
|
||||||
*/
|
*/
|
||||||
export function iconGridMinRowHeight(font: UiFont, iconSize: number, labelGap: number): number {
|
export function iconGridMinRowHeight(font: UiFont, iconSize: number, labelGap: number): number {
|
||||||
return iconSize + labelGap + font.lineHeight + 8;
|
return iconSize + labelGap + font.lineHeight + 8;
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { G2_LENS_WIDTH, type GrayImage } from "../../graphics/image";
|
import { G2_LENS_WIDTH, GrayImage, type UiFont } from "../../graphics/image";
|
||||||
import { wrapText, truncateText } from "../../graphics/textwrap";
|
import { wrapText, truncateText } from "../../graphics/textwrap";
|
||||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||||
import { Menu, type MenuDrawArgs } from "../menu-core";
|
import { Menu, type MenuDrawArgs } from "../menu-core";
|
||||||
import { listRowHeight } from "../metrics";
|
import { listRowHeight, textInkBounds } from "../metrics";
|
||||||
import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry";
|
import { MIN_WINDOW_HEIGHT, minWindowTop } from "./geometry";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The shared look of the shell's text dialogs (voice input, phone keyboard
|
* The shared look of the shell's text dialogs (voice input, phone keyboard
|
||||||
* input, and the assistant's reply): a solid box over whatever is on screen with a title line,
|
* input, and the assistant's reply): a solid box over whatever is on screen with a header
|
||||||
* a status line, the message so far, and either a menu of destinations at
|
* line (title, then status), the message so far, and either a menu of
|
||||||
* the bottom or a gesture hint.
|
* destinations at the bottom or a gesture hint.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const DIALOG_X = 40;
|
const DIALOG_X = 40;
|
||||||
@@ -27,6 +27,9 @@ const MENU_W = DIALOG_W - 24;
|
|||||||
const MENU_ROW_GAP = 2;
|
const MENU_ROW_GAP = 2;
|
||||||
const MENU_LABEL_INSET_X = 8;
|
const MENU_LABEL_INSET_X = 8;
|
||||||
const MENU_LABEL_INSET_Y = 4;
|
const MENU_LABEL_INSET_Y = 4;
|
||||||
|
const HEADER_STATUS_GAP = 10;
|
||||||
|
const HINT_VALUE = 100;
|
||||||
|
const HINT_DEPTH = 2;
|
||||||
|
|
||||||
/** Dialog top edge; band-relative, so computed per paint. */
|
/** Dialog top edge; band-relative, so computed per paint. */
|
||||||
function dialogY(): number {
|
function dialogY(): number {
|
||||||
@@ -89,15 +92,20 @@ export function paintInputDialog<T extends InputDialogRow>(image: GrayImage, con
|
|||||||
image.fillRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 1);
|
image.fillRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 1);
|
||||||
image.drawRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 90);
|
image.drawRect(DIALOG_X, top, DIALOG_W, DIALOG_H, 90);
|
||||||
|
|
||||||
|
// Title and status share one header line, the status in the space after the title.
|
||||||
const left = TEXT_LEFT;
|
const left = TEXT_LEFT;
|
||||||
image.drawText(font, left, top + 12, content.title, 220);
|
const headerY = top + 12;
|
||||||
image.drawText(font, left, top + 30, truncateText(font, content.status, TEXT_MAX_WIDTH), content.statusValue ?? 130);
|
image.drawText(font, left, headerY, content.title, 220);
|
||||||
|
const statusLeft = left + Math.ceil(font.measureText(content.title)) + HEADER_STATUS_GAP;
|
||||||
|
const statusWidth = TEXT_LEFT + TEXT_MAX_WIDTH - statusLeft;
|
||||||
|
image.drawText(font, statusLeft, headerY, truncateText(font, content.status, statusWidth), content.statusValue ?? 130);
|
||||||
|
|
||||||
const menu = content.menu;
|
const menu = content.menu;
|
||||||
const rowCount = menu?.items.length ?? 0;
|
const rowCount = menu?.items.length ?? 0;
|
||||||
// Reserve space for the actual number of rows this menu has.
|
// Reserve space for the actual number of rows this menu has, or one row for the hint.
|
||||||
const textBottom = rowCount > 0 ? top + DIALOG_H - rowCount * menuRowH - 8 : top + DIALOG_H - 8;
|
const reservedRows = rowCount > 0 ? rowCount : content.hint ? 1 : 0;
|
||||||
const textTop = top + 56;
|
const textBottom = top + DIALOG_H - reservedRows * menuRowH - 8;
|
||||||
|
const textTop = headerY + font.lineHeight + 12;
|
||||||
const maxLines = Math.max(1, ((textBottom - textTop) / 16) | 0);
|
const maxLines = Math.max(1, ((textBottom - textTop) / 16) | 0);
|
||||||
|
|
||||||
// The tail of a long message stays in view: it is what was said last (or
|
// The tail of a long message stays in view: it is what was said last (or
|
||||||
@@ -113,6 +121,19 @@ export function paintInputDialog<T extends InputDialogRow>(image: GrayImage, con
|
|||||||
const menuTop = top + DIALOG_H - rowCount * menuRowH - 4;
|
const menuTop = top + DIALOG_H - rowCount * menuRowH - 4;
|
||||||
menu.paint(image, { x: MENU_X, y: menuTop, width: MENU_W, height: rowCount * menuRowH - MENU_ROW_GAP }, true);
|
menu.paint(image, { x: MENU_X, y: menuTop, width: MENU_W, height: rowCount * menuRowH - MENU_ROW_GAP }, true);
|
||||||
} else if (content.hint) {
|
} else if (content.hint) {
|
||||||
image.drawText(font, left, top + DIALOG_H - 14, content.hint, 110 - font.lineHeight);
|
// On the line the last menu row's label would occupy, floating in front of the dialog.
|
||||||
|
drawDepthText(image, font, truncateText(font, content.hint, TEXT_MAX_WIDTH), left, top + DIALOG_H - menuRowH, HINT_VALUE, HINT_DEPTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw one line of text at stereo depth: rendered into its own image (sized
|
||||||
|
* to the font's ink, which can overshoot the line box) and replayed at depth.
|
||||||
|
*/
|
||||||
|
function drawDepthText(image: GrayImage, font: UiFont, text: string, x: number, y: number, value: number, depth: number): void {
|
||||||
|
const ink = textInkBounds(font);
|
||||||
|
const above = Math.max(0, -ink.top);
|
||||||
|
const source = new GrayImage(Math.ceil(font.measureText(text)) + 2, above + Math.max(font.lineHeight, ink.bottom));
|
||||||
|
source.drawText(font, 0, above, text, value);
|
||||||
|
image.drawDepthImage(source, x, y - above, depth);
|
||||||
|
}
|
||||||
@@ -52,11 +52,19 @@ export class ShellModalLayer implements Layer {
|
|||||||
this.stack.setBaseSize(interior);
|
this.stack.setBaseSize(interior);
|
||||||
// Flattening bakes the inner stack's planes (glyphs included) so the blit
|
// Flattening bakes the inner stack's planes (glyphs included) so the blit
|
||||||
// below transplants the finished modal content into this layer's plane.
|
// below transplants the finished modal content into this layer's plane.
|
||||||
const inner = flattenPlanes(this.stack.paint(), interior);
|
// The top plane's retained presentations (a menu's selection highlight
|
||||||
|
// and scroll strip) stay unbaked: they are display lists the glasses
|
||||||
|
// animate, and baking one freezes it on its first frame. Lower planes'
|
||||||
|
// are baked so the top plane's raster still covers them.
|
||||||
|
const planes = this.stack.paint();
|
||||||
|
const top = planes[planes.length - 1]!;
|
||||||
|
const inner = flattenPlanes(planes.map((plane) => plane === top ? { ...plane, image: plane.image.withDrawsBaked(false) } : plane), interior);
|
||||||
const rect = modalRect();
|
const rect = modalRect();
|
||||||
|
const innerX = rect.x + MODAL_PADDING, innerY = rect.y + MODAL_PADDING;
|
||||||
image.fillRect(rect.x, rect.y, rect.width, rect.height, SHELL_OPAQUE_BLACK);
|
image.fillRect(rect.x, rect.y, rect.width, rect.height, SHELL_OPAQUE_BLACK);
|
||||||
image.drawRect(rect.x, rect.y, rect.width, rect.height, 110);
|
image.drawRect(rect.x, rect.y, rect.width, rect.height, 110);
|
||||||
image.bitBlt(inner, rect.x + MODAL_PADDING, rect.y + MODAL_PADDING, { transparentZero: true });
|
image.bitBlt(inner, innerX, innerY, { transparentZero: true });
|
||||||
|
top.image.copyPresentationsInto(image, innerX + top.x, innerY + top.y);
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ export class WindowMenu {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the menu, or the shell's system menu when this window has no
|
* Open the menu, or the shell's system menu when this window has no
|
||||||
* entries. `items` overrides the window's own entries for an app that
|
* entries. `items` (and optionally `title`) override the window's own for
|
||||||
* reuses this host for another list (a per-row action menu).
|
* an app that reuses this host for another list (a per-row action menu).
|
||||||
*/
|
*/
|
||||||
open(items: MenuItem[] = this.options.items()): void {
|
open(items: MenuItem[] = this.options.items(), title: string = this.options.title()): void {
|
||||||
if (this.stack) return;
|
if (this.stack) return;
|
||||||
if (!items.length) {
|
if (!items.length) {
|
||||||
this.options.post({ type: "open-system-menu", windowId: this.options.windowId });
|
this.options.post({ type: "open-system-menu", windowId: this.options.windowId });
|
||||||
@@ -106,7 +106,7 @@ export class WindowMenu {
|
|||||||
handleInput: () => {},
|
handleInput: () => {},
|
||||||
};
|
};
|
||||||
const stack = new LayerStack(base, { ...noopLayerActions }, this.options.size, this.options.isFocused);
|
const stack = new LayerStack(base, { ...noopLayerActions }, this.options.size, this.options.isFocused);
|
||||||
stack.push(new WindowMenuLayer(this.options.title(), items));
|
stack.push(new WindowMenuLayer(title, items));
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
export const FACECLAW_VERSION = "0.7.2";
|
export const FACECLAW_VERSION = "0.8.0";
|
||||||
export const USER_AGENT = "Faceclaw/"+FACECLAW_VERSION;
|
export const USER_AGENT = "Faceclaw/"+FACECLAW_VERSION;
|
||||||
@@ -7,7 +7,9 @@ package com.faceclaw.app
|
|||||||
/** Common draw-call header bits. */
|
/** Common draw-call header bits. */
|
||||||
const val DRAW_FLAG_RESOURCE_TARGET = 1
|
const val DRAW_FLAG_RESOURCE_TARGET = 1
|
||||||
const val DRAW_FLAG_DEPTH = 2
|
const val DRAW_FLAG_DEPTH = 2
|
||||||
const val DRAW_FLAGS_MASK = DRAW_FLAG_RESOURCE_TARGET or DRAW_FLAG_DEPTH
|
/** Revision 35: an x/y s16, w/h u16 clip rect follows the depth byte. */
|
||||||
|
const val DRAW_FLAG_CLIP = 4
|
||||||
|
const val DRAW_FLAGS_MASK = DRAW_FLAG_RESOURCE_TARGET or DRAW_FLAG_DEPTH or DRAW_FLAG_CLIP
|
||||||
|
|
||||||
/** Bounding-box payload flag: u16 coordinates/sizes instead of aligned compact units. */
|
/** Bounding-box payload flag: u16 coordinates/sizes instead of aligned compact units. */
|
||||||
const val DRAW_BBOX_FLAG_U16 = 1
|
const val DRAW_BBOX_FLAG_U16 = 1
|
||||||
|
|||||||
+55
-20
@@ -1,6 +1,19 @@
|
|||||||
package com.faceclaw.app
|
package com.faceclaw.app
|
||||||
|
|
||||||
/** Revision 33 wire grammar, shared by scene planning and the local renderer. */
|
/**
|
||||||
|
* A draw call's clip rect (revision 35, DRAW_FLAG_CLIP), in the call's own
|
||||||
|
* coordinates: it moves with the call's depth, narrows any clip inherited
|
||||||
|
* from an enclosing play-list call, and is dropped by a target override.
|
||||||
|
*/
|
||||||
|
class DrawClip(val x: Int, val y: Int, val width: Int, val height: Int) {
|
||||||
|
init {
|
||||||
|
require(x in -32768..32767 && y in -32768..32767 && width in 0..65535 && height in 0..65535)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun translated(dx: Int, dy: Int) = DrawClip(x + dx, y + dy, width, height)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Revision 35 wire grammar, shared by scene planning and the local renderer. */
|
||||||
object DrawProtocol {
|
object DrawProtocol {
|
||||||
/** Mirrors g2flash/patches/zlib_glue.c. */
|
/** Mirrors g2flash/patches/zlib_glue.c. */
|
||||||
const val DRAW = CFW_MSG_DRAW_CALLS
|
const val DRAW = CFW_MSG_DRAW_CALLS
|
||||||
@@ -25,21 +38,29 @@ object DrawProtocol {
|
|||||||
|
|
||||||
private fun encode(write: DrawWriter.() -> Unit): ByteArray = DrawWriter().apply(write).toByteArray()
|
private fun encode(write: DrawWriter.() -> Unit): ByteArray = DrawWriter().apply(write).toByteArray()
|
||||||
|
|
||||||
fun call(op: Int, args: ByteArray, target: Int? = null, depth: Int? = null): ByteArray {
|
fun call(op: Int, args: ByteArray, target: Int? = null, depth: Int? = null, clip: DrawClip? = null): ByteArray {
|
||||||
require(depth == null || depth in -128..127)
|
require(depth == null || depth in -128..127)
|
||||||
val flags = (if (target == null) 0 else DRAW_FLAG_RESOURCE_TARGET) or
|
val flags = (if (target == null) 0 else DRAW_FLAG_RESOURCE_TARGET) or
|
||||||
(if (depth == null) 0 else DRAW_FLAG_DEPTH)
|
(if (depth == null) 0 else DRAW_FLAG_DEPTH) or
|
||||||
|
(if (clip == null) 0 else DRAW_FLAG_CLIP)
|
||||||
return encode {
|
return encode {
|
||||||
writeU8(op)
|
writeU8(op)
|
||||||
writeU8(flags)
|
writeU8(flags)
|
||||||
if (target != null) writeU16(target)
|
if (target != null) writeU16(target)
|
||||||
if (depth != null) writeS8(depth)
|
if (depth != null) writeS8(depth)
|
||||||
|
if (clip != null) {
|
||||||
|
writeS16(clip.x)
|
||||||
|
writeS16(clip.y)
|
||||||
|
writeU16(clip.width)
|
||||||
|
writeU16(clip.height)
|
||||||
|
}
|
||||||
writeBytes(args)
|
writeBytes(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun call(op: Int, target: Int? = null, depth: Int? = null, write: DrawWriter.() -> Unit): ByteArray =
|
private fun call(op: Int, target: Int? = null, depth: Int? = null, clip: DrawClip? = null,
|
||||||
call(op, encode(write), target, depth)
|
write: DrawWriter.() -> Unit): ByteArray =
|
||||||
|
call(op, encode(write), target, depth, clip)
|
||||||
|
|
||||||
fun depthOffset(depth: Int, right: Boolean): Int =
|
fun depthOffset(depth: Int, right: Boolean): Int =
|
||||||
if (right) -floorHalf(depth + 1) else floorHalf(depth)
|
if (right) -floorHalf(depth + 1) else floorHalf(depth)
|
||||||
@@ -53,11 +74,11 @@ object DrawProtocol {
|
|||||||
|
|
||||||
fun roundedRect(
|
fun roundedRect(
|
||||||
x: DrawValue, y: DrawValue, width: Int, height: Int, radius: Int, background: Int,
|
x: DrawValue, y: DrawValue, width: Int, height: Int, radius: Int, background: Int,
|
||||||
border: Int = DRAW_ROUNDED_RECT_NO_BORDER, depth: Int? = null,
|
border: Int = DRAW_ROUNDED_RECT_NO_BORDER, depth: Int? = null, clip: DrawClip? = null,
|
||||||
): ByteArray {
|
): ByteArray {
|
||||||
require(width in 1..640 && height in 1..480 && radius in 0..65535)
|
require(width in 1..640 && height in 1..480 && radius in 0..65535)
|
||||||
require(background in 0..15 && border in 0..DRAW_ROUNDED_RECT_NO_BORDER)
|
require(background in 0..15 && border in 0..DRAW_ROUNDED_RECT_NO_BORDER)
|
||||||
return call(DRAW_OP_ROUNDED_RECT, depth = depth) {
|
return call(DRAW_OP_ROUNDED_RECT, depth = depth, clip = clip) {
|
||||||
writeExtended(x)
|
writeExtended(x)
|
||||||
writeExtended(y)
|
writeExtended(y)
|
||||||
writeU16(width)
|
writeU16(width)
|
||||||
@@ -86,11 +107,17 @@ object DrawProtocol {
|
|||||||
|
|
||||||
fun image(
|
fun image(
|
||||||
id: Int, x: Int, y: Int, options: Int = CFW_TEXTURE_OPT_BRIGHTNESS_MASK,
|
id: Int, x: Int, y: Int, options: Int = CFW_TEXTURE_OPT_BRIGHTNESS_MASK,
|
||||||
target: Int? = null, depth: Int? = null,
|
target: Int? = null, depth: Int? = null, clip: DrawClip? = null,
|
||||||
): ByteArray = call(DRAW_OP_IMAGE, target, depth) {
|
): ByteArray = image(id, DrawValue.Integer(x), DrawValue.Integer(y), options, target, depth, clip)
|
||||||
|
|
||||||
|
/** Revision 35: x and y are extended values and may be expressions. */
|
||||||
|
fun image(
|
||||||
|
id: Int, x: DrawValue, y: DrawValue, options: Int = CFW_TEXTURE_OPT_BRIGHTNESS_MASK,
|
||||||
|
target: Int? = null, depth: Int? = null, clip: DrawClip? = null,
|
||||||
|
): ByteArray = call(DRAW_OP_IMAGE, target, depth, clip) {
|
||||||
writeU16(id)
|
writeU16(id)
|
||||||
writeS16(x)
|
writeExtended(x)
|
||||||
writeS16(y)
|
writeExtended(y)
|
||||||
writeU8(options)
|
writeU8(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,8 +130,8 @@ object DrawProtocol {
|
|||||||
/** Revision 29: source and destination coordinates may be expressions; the source rect must stay in bounds. */
|
/** Revision 29: source and destination coordinates may be expressions; the source rect must stay in bounds. */
|
||||||
fun rectCopy(
|
fun rectCopy(
|
||||||
source: Int, x: DrawValue, y: DrawValue, width: Int, height: Int, dx: DrawValue, dy: DrawValue,
|
source: Int, x: DrawValue, y: DrawValue, width: Int, height: Int, dx: DrawValue, dy: DrawValue,
|
||||||
target: Int? = null, depth: Int? = null,
|
target: Int? = null, depth: Int? = null, clip: DrawClip? = null,
|
||||||
): ByteArray = call(DRAW_OP_RECT_COPY, target, depth) {
|
): ByteArray = call(DRAW_OP_RECT_COPY, target, depth, clip) {
|
||||||
writeU16(source)
|
writeU16(source)
|
||||||
writeExtended(x)
|
writeExtended(x)
|
||||||
writeExtended(y)
|
writeExtended(y)
|
||||||
@@ -114,10 +141,13 @@ object DrawProtocol {
|
|||||||
writeExtended(dy)
|
writeExtended(dy)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Fill the whole target, ignoring depth. */
|
/**
|
||||||
fun clear(color: Int = 0, target: Int? = null): ByteArray {
|
* Fill the whole target, ignoring depth; under a clip (revision 35), just
|
||||||
|
* the clipped part. Depth still moves the clip rect, like any call's.
|
||||||
|
*/
|
||||||
|
fun clear(color: Int = 0, target: Int? = null, clip: DrawClip? = null, depth: Int? = null): ByteArray {
|
||||||
require(color in 0..15)
|
require(color in 0..15)
|
||||||
return call(DRAW_OP_CLEAR, target) { writeU8(color) }
|
return call(DRAW_OP_CLEAR, target, depth, clip) { writeU8(color) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,12 +169,17 @@ object DrawProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun text(id: Int, x: Int, y: Int, options: Int, text: ByteArray): ByteArray {
|
fun text(id: Int, x: Int, y: Int, options: Int, text: ByteArray): ByteArray =
|
||||||
|
text(id, DrawValue.Integer(x), DrawValue.Integer(y), options, text)
|
||||||
|
|
||||||
|
/** Revision 35: x and y are extended values and may be expressions. */
|
||||||
|
fun text(id: Int, x: DrawValue, y: DrawValue, options: Int, text: ByteArray, depth: Int? = null,
|
||||||
|
clip: DrawClip? = null): ByteArray {
|
||||||
require(text.size <= 255)
|
require(text.size <= 255)
|
||||||
return call(DRAW_OP_TEXT) {
|
return call(DRAW_OP_TEXT, depth = depth, clip = clip) {
|
||||||
writeU16(id)
|
writeU16(id)
|
||||||
writeS16(x)
|
writeExtended(x)
|
||||||
writeS16(y)
|
writeExtended(y)
|
||||||
writeU8(options)
|
writeU8(options)
|
||||||
writeU8(text.size)
|
writeU8(text.size)
|
||||||
writeBytes(text)
|
writeBytes(text)
|
||||||
|
|||||||
+48
-6
@@ -13,7 +13,9 @@ import kotlin.concurrent.Volatile
|
|||||||
* pairing prompt, and doing both here means both prompts appear at the start rather than one
|
* pairing prompt, and doing both here means both prompts appear at the start rather than one
|
||||||
* popping up half way through flashing the second lens. While connected, each arm's battery
|
* popping up half way through flashing the second lens. While connected, each arm's battery
|
||||||
* level is read (they are independent batteries) so the caller can refuse to flash on a low
|
* level is read (they are independent batteries) so the caller can refuse to flash on a low
|
||||||
* charge.
|
* charge. Before the prompt is shown, the right arm's settings are read once more so a lens
|
||||||
|
* that reports silent mode (which blanks the display and ignores input) is refused with the
|
||||||
|
* way out instead of a prompt nobody can see.
|
||||||
*
|
*
|
||||||
* With `skipPrompt` the on-glasses confirmation is not shown: the flow is just connect + auth +
|
* With `skipPrompt` the on-glasses confirmation is not shown: the flow is just connect + auth +
|
||||||
* battery read + result(approved). Used to re-check the battery after the user has already
|
* battery read + result(approved). Used to re-check the battery after the user has already
|
||||||
@@ -38,6 +40,15 @@ class FlashPromptFlow(
|
|||||||
const val LIST_CONTAINER_ID = 2
|
const val LIST_CONTAINER_ID = 2
|
||||||
// Index 0 = decline, index 1 = approve. Kept short for the ~50-col grid.
|
// Index 0 = decline, index 1 = approve. Kept short for the ~50-col grid.
|
||||||
val ITEMS = arrayOf("No, cancel", "Yes, flash")
|
val ITEMS = arrayOf("No, cancel", "Yes, flash")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shown instead of a bare "prompt page not acked" error. Silent mode is entered and left
|
||||||
|
* by the same gesture on the glasses and nothing here can clear it, so the instruction
|
||||||
|
* has to travel with the error.
|
||||||
|
*/
|
||||||
|
const val SILENT_MODE_MESSAGE =
|
||||||
|
"Your glasses are in silent mode, so they cannot show the confirmation prompt. " +
|
||||||
|
"Long-press both touchpads on the glasses to leave silent mode, then try again."
|
||||||
}
|
}
|
||||||
|
|
||||||
private val rightAddress = rightAddress.trim()
|
private val rightAddress = rightAddress.trim()
|
||||||
@@ -121,6 +132,11 @@ class FlashPromptFlow(
|
|||||||
session.sendPrelude(rightAddress, ": $rightAddress")
|
session.sendPrelude(rightAddress, ": $rightAddress")
|
||||||
|
|
||||||
if (!skipPrompt) {
|
if (!skipPrompt) {
|
||||||
|
// Ask before writing a page that cannot be answered: silent mode blanks the
|
||||||
|
// display and stops the firmware dispatching input while BLE stays up, so the
|
||||||
|
// create-prompt write is still acked and the user is left waiting on a prompt
|
||||||
|
// that never appears.
|
||||||
|
requireNotSilent(rightAddress)
|
||||||
showPrompt(rightAddress)
|
showPrompt(rightAddress)
|
||||||
startHeartbeat()
|
startHeartbeat()
|
||||||
listener.onState("prompting", "")
|
listener.onState("prompting", "")
|
||||||
@@ -238,23 +254,49 @@ class FlashPromptFlow(
|
|||||||
listener.onBattery(right, left)
|
listener.onBattery(right, left)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readBattery(address: String, arm: String): Int {
|
private fun readBattery(address: String, arm: String): Int = readSettingsSnapshot(address, arm)?.battery ?: -1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The sid-0x09 settings read behind both the battery gate and the silent-mode check; one
|
||||||
|
* ack carries both fields. Two attempts, since on 2.2.9 a request sent right after the
|
||||||
|
* prelude can be dropped. Null when the arm does not answer or the ack has no battery field.
|
||||||
|
*/
|
||||||
|
private fun readSettingsSnapshot(address: String, arm: String): BleProtocol.BatterySnapshot? {
|
||||||
var attempt = 0
|
var attempt = 0
|
||||||
while (attempt < 2 && !cancelled) {
|
while (attempt < 2 && !cancelled) {
|
||||||
val ack = session.readSettings(address, timings.batteryAckTimeoutMs)
|
val ack = session.readSettings(address, timings.batteryAckTimeoutMs)
|
||||||
if (ack == null) {
|
if (ack == null) {
|
||||||
emitLog("battery read attempt " + (attempt + 1) + " unacked: " + arm + " arm")
|
emitLog("settings read attempt " + (attempt + 1) + " unacked: " + arm + " arm")
|
||||||
attempt++
|
attempt++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val snapshot = BleProtocol.parseSettingsBattery(ack)
|
val snapshot = BleProtocol.parseSettingsBattery(ack)
|
||||||
if (snapshot != null) {
|
if (snapshot != null) {
|
||||||
return snapshot.battery
|
return snapshot
|
||||||
}
|
}
|
||||||
emitLog("battery read ack had no battery field: $arm arm")
|
emitLog("settings read ack had no battery field: $arm arm")
|
||||||
attempt++
|
attempt++
|
||||||
}
|
}
|
||||||
return -1
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refuse the prompt only when the arm POSITIVELY reports silent mode. An arm that does not
|
||||||
|
* answer, and firmware whose ack omits the field, both fall through to the prompt exactly as
|
||||||
|
* before, so a missing answer can never block a flash.
|
||||||
|
*/
|
||||||
|
private fun requireNotSilent(address: String) {
|
||||||
|
val snapshot = readSettingsSnapshot(address, "right")
|
||||||
|
val state = when {
|
||||||
|
snapshot == null -> "unknown (arm did not answer)"
|
||||||
|
snapshot.silentMode < 0 -> "unknown (ack omits the field)"
|
||||||
|
snapshot.silentMode > 0 -> "on"
|
||||||
|
else -> "off"
|
||||||
|
}
|
||||||
|
emitLog("silent mode before prompt: $state")
|
||||||
|
if (snapshot != null && snapshot.silentMode > 0) {
|
||||||
|
throw IllegalStateException(SILENT_MODE_MESSAGE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startHeartbeat() {
|
private fun startHeartbeat() {
|
||||||
|
|||||||
+2
-2
@@ -802,14 +802,14 @@ class TexturePlanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** How many 1..31 control bytes are needed to move the cursor by delta. */
|
/** How many 1..31 control bytes are needed to move the cursor by delta. */
|
||||||
private fun adjustByteCount(delta: Int): Int {
|
internal fun adjustByteCount(delta: Int): Int {
|
||||||
if ((delta == 0)) {
|
if ((delta == 0)) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return (if ((delta > 0)) ((delta + 19) / 20) else ((-delta + 9) / 10))
|
return (if ((delta > 0)) ((delta + 19) / 20) else ((-delta + 9) / 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun emitAdjust(out: ByteSink, delta: Int): Unit {
|
internal fun emitAdjust(out: ByteSink, delta: Int): Unit {
|
||||||
var delta = delta
|
var delta = delta
|
||||||
while ((delta != 0)) {
|
while ((delta != 0)) {
|
||||||
var step: Int = (if ((delta > 0)) minOf(delta, 20) else maxOf(delta, -10))
|
var step: Int = (if ((delta > 0)) minOf(delta, 20) else maxOf(delta, -10))
|
||||||
|
|||||||
+48
-10
@@ -8,12 +8,18 @@ class DisplayListRenderer(
|
|||||||
) {
|
) {
|
||||||
class BuiltinGlyph(val image: ByteArray, val advance: Int, val x: Int = 0, val y: Int = 0)
|
class BuiltinGlyph(val image: ByteArray, val advance: Int, val x: Int = 0, val y: Int = 0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [clip] (revision 35) is the writable [left, top, right, bottom) in
|
||||||
|
* shifted target pixels, or null for the whole target. Like the depth
|
||||||
|
* shift, it is inherited by nested lists and dropped by a target override.
|
||||||
|
*/
|
||||||
class Target(
|
class Target(
|
||||||
val bytes: ByteArray,
|
val bytes: ByteArray,
|
||||||
val width: Int,
|
val width: Int,
|
||||||
val height: Int,
|
val height: Int,
|
||||||
val offset: Int = 0,
|
val offset: Int = 0,
|
||||||
val shiftX: Int = 0,
|
val shiftX: Int = 0,
|
||||||
|
val clip: IntArray? = null,
|
||||||
) {
|
) {
|
||||||
val stride = (width + 1) / 2
|
val stride = (width + 1) / 2
|
||||||
|
|
||||||
@@ -26,11 +32,26 @@ class DisplayListRenderer(
|
|||||||
return (bytes[offset + y * stride + x / 2].toInt() ushr shift) and 15
|
return (bytes[offset + y * stride + x / 2].toInt() ushr shift) and 15
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shifted(dx: Int) = Target(bytes, width, height, offset, shiftX + dx)
|
fun shifted(dx: Int) = Target(bytes, width, height, offset, shiftX + dx, clip)
|
||||||
|
|
||||||
|
/** Narrow the clip to a rect in (unshifted) call coordinates. */
|
||||||
|
fun clipped(x: Int, y: Int, w: Int, h: Int): Target {
|
||||||
|
val left = x + shiftX
|
||||||
|
val rect = intArrayOf(left, y, left + w, y + h)
|
||||||
|
if (clip != null) {
|
||||||
|
rect[0] = maxOf(rect[0], clip[0]); rect[1] = maxOf(rect[1], clip[1])
|
||||||
|
rect[2] = minOf(rect[2], clip[2]); rect[3] = minOf(rect[3], clip[3])
|
||||||
|
}
|
||||||
|
return Target(bytes, width, height, offset, shiftX, rect)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun writable(x: Int, y: Int): Boolean =
|
||||||
|
x in 0 until width && y in 0 until height &&
|
||||||
|
(clip == null || (x >= clip[0] && y >= clip[1] && x < clip[2] && y < clip[3]))
|
||||||
|
|
||||||
fun put(localX: Int, y: Int, value: Int) {
|
fun put(localX: Int, y: Int, value: Int) {
|
||||||
val x = localX + shiftX
|
val x = localX + shiftX
|
||||||
if (x !in 0 until width || y !in 0 until height) return
|
if (!writable(x, y)) return
|
||||||
val index = offset + y * stride + x / 2
|
val index = offset + y * stride + x / 2
|
||||||
val old = bytes[index].toInt()
|
val old = bytes[index].toInt()
|
||||||
bytes[index] = if (x % 2 == 0) {
|
bytes[index] = if (x % 2 == 0) {
|
||||||
@@ -220,6 +241,9 @@ class DisplayListRenderer(
|
|||||||
if (flags and DRAW_FLAG_DEPTH != 0) {
|
if (flags and DRAW_FLAG_DEPTH != 0) {
|
||||||
target = target.shifted(DrawProtocol.depthOffset(reader.readS8(), rightLens))
|
target = target.shifted(DrawProtocol.depthOffset(reader.readS8(), rightLens))
|
||||||
}
|
}
|
||||||
|
if (flags and DRAW_FLAG_CLIP != 0) {
|
||||||
|
target = target.clipped(reader.readS16(), reader.readS16(), reader.readU16(), reader.readU16())
|
||||||
|
}
|
||||||
when (opcode) {
|
when (opcode) {
|
||||||
DRAW_OP_BOUNDING_BOX -> drawBoundingBox(reader, target, walk)
|
DRAW_OP_BOUNDING_BOX -> drawBoundingBox(reader, target, walk)
|
||||||
DRAW_OP_RECT_COPY -> drawRectCopy(reader, target, walk)
|
DRAW_OP_RECT_COPY -> drawRectCopy(reader, target, walk)
|
||||||
@@ -313,26 +337,31 @@ class DisplayListRenderer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Mirrors the firmware: far-off image/text coordinates draw nothing (before the depth shift can overflow). */
|
||||||
|
private fun offTarget(x: Int, y: Int) = x !in -65536..65536 || y !in -65536..65536
|
||||||
|
|
||||||
private fun drawImage(reader: DrawReader, target: Target, walk: Walk) {
|
private fun drawImage(reader: DrawReader, target: Target, walk: Walk) {
|
||||||
val id = reader.readU16()
|
val id = reader.readU16()
|
||||||
val x = reader.readS16()
|
val x = ExtendedVarint.evaluate(reader, walk.frame)
|
||||||
val y = reader.readS16()
|
val y = ExtendedVarint.evaluate(reader, walk.frame)
|
||||||
val options = reader.readU8()
|
val options = reader.readU8()
|
||||||
reader.requireDone()
|
reader.requireDone()
|
||||||
walk.references.add(id)
|
walk.references.add(id)
|
||||||
draw(image(resource(id)), target, x, y, options, walk.apply)
|
val image = image(resource(id))
|
||||||
|
if (!offTarget(x, y)) draw(image, target, x, y, options, walk.apply)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun drawText(reader: DrawReader, target: Target, walk: Walk) {
|
private fun drawText(reader: DrawReader, target: Target, walk: Walk) {
|
||||||
val id = reader.readU16()
|
val id = reader.readU16()
|
||||||
var x = reader.readS16()
|
var x = ExtendedVarint.evaluate(reader, walk.frame)
|
||||||
val y = reader.readS16()
|
val y = ExtendedVarint.evaluate(reader, walk.frame)
|
||||||
val options = reader.readU8()
|
val options = reader.readU8()
|
||||||
val text = reader.readBytes(reader.readU8())
|
val text = reader.readBytes(reader.readU8())
|
||||||
reader.requireDone()
|
reader.requireDone()
|
||||||
walk.references.add(id)
|
walk.references.add(id)
|
||||||
val data = resource(id)
|
val data = resource(id)
|
||||||
require(data.size >= 193 && data[0].toInt() == CFW_RESOURCE_TYPE_FONT)
|
require(data.size >= 193 && data[0].toInt() == CFW_RESOURCE_TYPE_FONT)
|
||||||
|
val apply = walk.apply && !offTarget(x, y)
|
||||||
for (byte in text) {
|
for (byte in text) {
|
||||||
val char = byte.toInt() and 255
|
val char = byte.toInt() and 255
|
||||||
if (char in 1..31) {
|
if (char in 1..31) {
|
||||||
@@ -343,7 +372,7 @@ class DisplayListRenderer(
|
|||||||
val offset = DrawProtocol.u16(data, 1 + (char - 32) * 2)
|
val offset = DrawProtocol.u16(data, 1 + (char - 32) * 2)
|
||||||
require(offset >= 193)
|
require(offset >= 193)
|
||||||
val glyph = image(data, offset)
|
val glyph = image(data, offset)
|
||||||
draw(glyph, target, x, y, options, walk.apply)
|
draw(glyph, target, x, y, options, apply)
|
||||||
x += glyph.width
|
x += glyph.width
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,7 +388,7 @@ class DisplayListRenderer(
|
|||||||
if (!walk.apply) return
|
if (!walk.apply) return
|
||||||
for (yy in y until y + height) for (xx in x until x + width) {
|
for (yy in y until y + height) for (xx in x until x + width) {
|
||||||
val tx = xx + target.shiftX
|
val tx = xx + target.shiftX
|
||||||
if (tx !in 0 until target.width) continue
|
if (!target.writable(tx, yy)) continue
|
||||||
val value = target.get(tx, yy)
|
val value = target.get(tx, yy)
|
||||||
val shift = if (value % 2 == 0) 4 else 0
|
val shift = if (value % 2 == 0) 4 else 0
|
||||||
// The even-parity table comes first; parity is of the shifted target pixel.
|
// The even-parity table comes first; parity is of the shifted target pixel.
|
||||||
@@ -371,7 +400,16 @@ class DisplayListRenderer(
|
|||||||
val color = reader.readU8()
|
val color = reader.readU8()
|
||||||
reader.requireDone()
|
reader.requireDone()
|
||||||
require(color <= 15)
|
require(color <= 15)
|
||||||
if (walk.apply) target.bytes.fill((color * 17).toByte(), target.offset, target.offset + target.stride * target.height)
|
if (!walk.apply) return
|
||||||
|
val clip = target.clip
|
||||||
|
if (clip == null) {
|
||||||
|
target.bytes.fill((color * 17).toByte(), target.offset, target.offset + target.stride * target.height)
|
||||||
|
} else {
|
||||||
|
// Revision 35: a clipped clear fills just the clip, which is in shifted pixels already.
|
||||||
|
for (y in maxOf(0, clip[1]) until minOf(target.height, clip[3])) {
|
||||||
|
for (x in maxOf(0, clip[0]) until minOf(target.width, clip[2])) target.put(x - target.shiftX, y, color)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun drawRoundedRect(reader: DrawReader, target: Target, walk: Walk) {
|
private fun drawRoundedRect(reader: DrawReader, target: Target, walk: Walk) {
|
||||||
|
|||||||
+119
-13
@@ -11,7 +11,17 @@ interface RetainedDrawing {
|
|||||||
internal fun readRetainedDrawing(reader: ByteReader, kind: Int): RetainedDrawing =
|
internal fun readRetainedDrawing(reader: ByteReader, kind: Int): RetainedDrawing =
|
||||||
if (kind == DrawRecordKind.DISPLAY_LIST) FrameDisplayList.read(reader) else MenuSelection.read(reader, kind)
|
if (kind == DrawRecordKind.DISPLAY_LIST) FrameDisplayList.read(reader) else MenuSelection.read(reader, kind)
|
||||||
|
|
||||||
/** Generic TS-authored calls. No menu or easing policy lives in this bridge. */
|
/**
|
||||||
|
* Generic TS-authored calls. No menu or easing policy lives in this bridge.
|
||||||
|
*
|
||||||
|
* Besides literal firmware calls, a record may carry a DRAWS call (bridge
|
||||||
|
* only): glyph and icon records in the frame draw-record format, whose atlas
|
||||||
|
* identities TS registered while painting. They compile to IMAGE calls on
|
||||||
|
* ImageAtlas resources, then TEXT runs on FontResourceAtlas fonts, all offset
|
||||||
|
* by the call's (possibly animated) x/y. When any record cannot be resolved,
|
||||||
|
* the whole list draws nothing: the frame's own pixels show instead, rather
|
||||||
|
* than content with a glyph missing.
|
||||||
|
*/
|
||||||
class FrameDisplayList private constructor(
|
class FrameDisplayList private constructor(
|
||||||
private val x: Int, private val y: Int, private val depth: Int,
|
private val x: Int, private val y: Int, private val depth: Int,
|
||||||
override val resources: List<CachedResource>, private val commands: List<Command>,
|
override val resources: List<CachedResource>, private val commands: List<Command>,
|
||||||
@@ -20,9 +30,11 @@ class FrameDisplayList private constructor(
|
|||||||
override val fingerprint: String get() = "$x,$y,$depth,$identity"
|
override val fingerprint: String get() = "$x,$y,$depth,$identity"
|
||||||
override fun translated(dx: Int, dy: Int) = FrameDisplayList(x + dx, y + dy, depth, resources, commands, startedAt, identity)
|
override fun translated(dx: Int, dy: Int) = FrameDisplayList(x + dx, y + dy, depth, resources, commands, startedAt, identity)
|
||||||
|
|
||||||
|
/** Image/text [values] are resource, x offset, y offset, options; the offsets add to [x]/[y]. */
|
||||||
private class Command(val op: Int, val depth: Int, val values: IntArray,
|
private class Command(val op: Int, val depth: Int, val values: IntArray,
|
||||||
val x: DrawValue = DrawValue.Integer(0), val y: DrawValue = DrawValue.Integer(0),
|
val x: DrawValue = DrawValue.Integer(0), val y: DrawValue = DrawValue.Integer(0),
|
||||||
val dx: DrawValue = DrawValue.Integer(0), val dy: DrawValue = DrawValue.Integer(0))
|
val dx: DrawValue = DrawValue.Integer(0), val dy: DrawValue = DrawValue.Integer(0),
|
||||||
|
val clip: DrawClip? = null, val text: ByteArray? = null)
|
||||||
|
|
||||||
override fun calls(ids: IntArray, nowMs: Long): List<ByteArray> {
|
override fun calls(ids: IntArray, nowMs: Long): List<ByteArray> {
|
||||||
require(ids.size == resources.size)
|
require(ids.size == resources.size)
|
||||||
@@ -30,14 +42,19 @@ class FrameDisplayList private constructor(
|
|||||||
fun resource(index: Int) = if (index == DrawProtocol.SCREEN) index else ids[index]
|
fun resource(index: Int) = if (index == DrawProtocol.SCREEN) index else ids[index]
|
||||||
return commands.map { c ->
|
return commands.map { c ->
|
||||||
val v = c.values
|
val v = c.values
|
||||||
|
val clip = c.clip?.translated(x, y)
|
||||||
when (c.op) {
|
when (c.op) {
|
||||||
DRAW_OP_ROUNDED_RECT -> DrawProtocol.roundedRect(bind(c.x, elapsed, x), bind(c.y, elapsed, y),
|
DRAW_OP_ROUNDED_RECT -> DrawProtocol.roundedRect(bind(c.x, elapsed, x), bind(c.y, elapsed, y),
|
||||||
v[0], v[1], v[2], v[3], v[4], depth + c.depth)
|
v[0], v[1], v[2], v[3], v[4], depth + c.depth, clip)
|
||||||
DRAW_OP_IMAGE -> DrawProtocol.image(resource(v[0]), x + v[1], y + v[2], v[3], depth = depth + c.depth)
|
DRAW_OP_IMAGE -> DrawProtocol.image(resource(v[0]), bind(c.x, elapsed, x + v[1]), bind(c.y, elapsed, y + v[2]),
|
||||||
|
v[3], depth = depth + c.depth, clip = clip)
|
||||||
|
DRAW_OP_TEXT -> DrawProtocol.text(resource(v[0]), bind(c.x, elapsed, x + v[1]), bind(c.y, elapsed, y + v[2]),
|
||||||
|
v[3], c.text!!, depth + c.depth, clip)
|
||||||
DRAW_OP_RECT_COPY -> DrawProtocol.rectCopy(resource(v[0]),
|
DRAW_OP_RECT_COPY -> DrawProtocol.rectCopy(resource(v[0]),
|
||||||
bind(c.x, elapsed, if (v[0] == DrawProtocol.SCREEN) x else 0),
|
bind(c.x, elapsed, if (v[0] == DrawProtocol.SCREEN) x else 0),
|
||||||
bind(c.y, elapsed, if (v[0] == DrawProtocol.SCREEN) y else 0),
|
bind(c.y, elapsed, if (v[0] == DrawProtocol.SCREEN) y else 0),
|
||||||
v[1], v[2], bind(c.dx, elapsed, x), bind(c.dy, elapsed, y), depth = depth + c.depth)
|
v[1], v[2], bind(c.dx, elapsed, x), bind(c.dy, elapsed, y), depth = depth + c.depth, clip = clip)
|
||||||
|
DRAW_OP_CLEAR -> DrawProtocol.clear(v[0], clip = clip, depth = if (clip == null) null else depth + c.depth)
|
||||||
else -> error("Unsupported frame display-list opcode")
|
else -> error("Unsupported frame display-list opcode")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,6 +64,11 @@ class FrameDisplayList private constructor(
|
|||||||
// Bridge-only constant binding, removed before a program reaches either renderer.
|
// Bridge-only constant binding, removed before a program reaches either renderer.
|
||||||
private const val ELAPSED = 128
|
private const val ELAPSED = 128
|
||||||
private const val MAX_RECORD_BYTES = 4 * 1024 * 1024
|
private const val MAX_RECORD_BYTES = 4 * 1024 * 1024
|
||||||
|
/** Bridge-only: replay glyph/icon draw records (see the class comment). */
|
||||||
|
private const val DRAWS = 32
|
||||||
|
/** Bridge opcode bit: an x/y s16, w/h u16 clip rect follows the call's depth. */
|
||||||
|
private const val CLIPPED = 128
|
||||||
|
private const val IMAGE_OPTIONS = CFW_TEXTURE_OPT_BRIGHTNESS_MASK or CFW_TEXTURE_OPT_TRANSPARENT
|
||||||
|
|
||||||
private fun bind(value: DrawValue, elapsed: Int, offset: Int): DrawValue {
|
private fun bind(value: DrawValue, elapsed: Int, offset: Int): DrawValue {
|
||||||
if (value is DrawValue.Integer) return DrawValue.Integer(value.value + offset)
|
if (value is DrawValue.Integer) return DrawValue.Integer(value.value + offset)
|
||||||
@@ -68,6 +90,57 @@ class FrameDisplayList private constructor(
|
|||||||
return DrawValue.Expression(program)
|
return DrawValue.Expression(program)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class GlyphRecord(val fontId: Int, val encoding: Int, val penX: Int, val lineY: Int, val value: Int)
|
||||||
|
private class ImageRecord(val imageId: Int, val x: Int, val y: Int)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile one DRAWS call into [out], adding atlas resources through
|
||||||
|
* [resource]. False when a record has no atlas entry, or its font
|
||||||
|
* snapshot cannot hold every glyph this call needs.
|
||||||
|
*/
|
||||||
|
private fun compileDraws(glyphs: List<GlyphRecord>, images: List<ImageRecord>, x: DrawValue, y: DrawValue,
|
||||||
|
depth: Int, clip: DrawClip?, resource: (CachedResource) -> Int, out: MutableList<Command>): Boolean {
|
||||||
|
for (image in images) {
|
||||||
|
val entry = ImageAtlas.get(image.imageId) ?: return false
|
||||||
|
out.add(Command(DRAW_OP_IMAGE, depth, intArrayOf(resource(entry.resource), image.x, image.y, IMAGE_OPTIONS),
|
||||||
|
x, y, clip = clip))
|
||||||
|
}
|
||||||
|
for ((fontId, fontGlyphs) in glyphs.groupBy { it.fontId }) {
|
||||||
|
val encodings = fontGlyphs.map { it.encoding }.toSet()
|
||||||
|
val font = FontResourceAtlas.get(fontId, encodings)
|
||||||
|
if (!font.encodings.containsAll(encodings)) return false
|
||||||
|
val fontIndex = resource(font.resource)
|
||||||
|
// One run per line and color, like TexturePlanner's: control
|
||||||
|
// bytes move the pen to each glyph's exact left edge.
|
||||||
|
val lines = fontGlyphs.groupBy { it.lineY to BmpUtil.nibbleForGray(it.value) }
|
||||||
|
for ((line, members) in lines) {
|
||||||
|
val placed = members.map { glyph ->
|
||||||
|
val atlas = GlyphAtlas.get(fontId, glyph.encoding) ?: return false
|
||||||
|
Triple(glyph.penX + atlas.bbxX, atlas.width, glyph.encoding)
|
||||||
|
}.sortedBy { it.first }
|
||||||
|
var start = 0
|
||||||
|
while (start < placed.size) {
|
||||||
|
val text = ByteSink()
|
||||||
|
var cursor = placed[start].first
|
||||||
|
var end = start
|
||||||
|
while (end < placed.size) {
|
||||||
|
val (left, width, encoding) = placed[end]
|
||||||
|
if (text.size() + TexturePlanner.adjustByteCount(left - cursor) + 1 > 255) break
|
||||||
|
TexturePlanner.emitAdjust(text, left - cursor)
|
||||||
|
text.write(encoding)
|
||||||
|
cursor = left + width
|
||||||
|
end++
|
||||||
|
}
|
||||||
|
out.add(Command(DRAW_OP_TEXT, depth,
|
||||||
|
intArrayOf(fontIndex, placed[start].first, line.first, line.second or CFW_TEXTURE_OPT_TRANSPARENT),
|
||||||
|
x, y, clip = clip, text = text.toByteArray()))
|
||||||
|
start = end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
fun read(input: ByteReader, nowMs: Long = drawAnimationTimeMs()): FrameDisplayList {
|
fun read(input: ByteReader, nowMs: Long = drawAnimationTimeMs()): FrameDisplayList {
|
||||||
val length = input.getInt()
|
val length = input.getInt()
|
||||||
require(length in 21..MAX_RECORD_BYTES && length <= input.remaining())
|
require(length in 21..MAX_RECORD_BYTES && length <= input.remaining())
|
||||||
@@ -81,12 +154,15 @@ class FrameDisplayList private constructor(
|
|||||||
val elapsed = r.readU16() or (r.readU16() shl 16)
|
val elapsed = r.readU16() or (r.readU16() shl 16)
|
||||||
require(elapsed >= 0)
|
require(elapsed >= 0)
|
||||||
val resourceCount = r.readU16(); require(resourceCount <= 256)
|
val resourceCount = r.readU16(); require(resourceCount <= 256)
|
||||||
val resources = List(resourceCount) {
|
val local = List(resourceCount) {
|
||||||
val w = r.readU16(); val h = r.readU16()
|
val w = r.readU16(); val h = r.readU16()
|
||||||
require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536)
|
require(w in 1..640 && h in 1..480 && 5 + (w + 1) / 2 * h <= 65536)
|
||||||
val gray = r.readBytes(w * h)
|
val gray = r.readBytes(w * h)
|
||||||
CachedResource(DrawProtocol.rawImage(w, h, BmpUtil.pack4bppFromGray8(gray, w, h)))
|
CachedResource(DrawProtocol.rawImage(w, h, BmpUtil.pack4bppFromGray8(gray, w, h)))
|
||||||
}
|
}
|
||||||
|
val resources = ArrayList(local)
|
||||||
|
val atlasIndices = HashMap<CachedResource, Int>()
|
||||||
|
fun atlasResource(cached: CachedResource): Int = atlasIndices.getOrPut(cached) { resources.add(cached); resources.size - 1 }
|
||||||
fun value(): DrawValue {
|
fun value(): DrawValue {
|
||||||
val first = r.readU8()
|
val first = r.readU8()
|
||||||
if (first != 255) return DrawValue.Integer(ExtendedVarint.read(r, true, first))
|
if (first != 255) return DrawValue.Integer(ExtendedVarint.read(r, true, first))
|
||||||
@@ -97,23 +173,27 @@ class FrameDisplayList private constructor(
|
|||||||
bind(it, Int.MAX_VALUE, Int.MAX_VALUE)
|
bind(it, Int.MAX_VALUE, Int.MAX_VALUE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun resource(): Int = r.readU16().also { require(it == DrawProtocol.SCREEN || it in resources.indices) }
|
fun resource(): Int = r.readU16().also { require(it == DrawProtocol.SCREEN || it in local.indices) }
|
||||||
val count = r.readU16(); require(count <= 4096)
|
val count = r.readU16(); require(count <= 4096)
|
||||||
val calls = List(count) {
|
val commands = ArrayList<Command>()
|
||||||
val op = r.readU8(); val d = r.readS16(); require(depth + d in -128..127)
|
var replayable = true
|
||||||
|
repeat(count) {
|
||||||
|
val header = r.readU8(); val op = header and CLIPPED.inv()
|
||||||
|
val d = r.readS16(); require(depth + d in -128..127)
|
||||||
|
val clip = if (header and CLIPPED != 0) DrawClip(r.readS16(), r.readS16(), r.readU16(), r.readU16()) else null
|
||||||
when (op) {
|
when (op) {
|
||||||
DRAW_OP_ROUNDED_RECT -> {
|
DRAW_OP_ROUNDED_RECT -> {
|
||||||
val xx = value(); val yy = value()
|
val xx = value(); val yy = value()
|
||||||
val w = r.readU16(); val h = r.readU16(); val radius = r.readU16()
|
val w = r.readU16(); val h = r.readU16(); val radius = r.readU16()
|
||||||
val background = r.readU8(); val border = r.readU8()
|
val background = r.readU8(); val border = r.readU8()
|
||||||
require(w in 1..640 && h in 1..480 && background in 0..15 && border in 0..16)
|
require(w in 1..640 && h in 1..480 && background in 0..15 && border in 0..16)
|
||||||
Command(op, d, intArrayOf(w, h, radius, background, border), xx, yy)
|
commands.add(Command(op, d, intArrayOf(w, h, radius, background, border), xx, yy, clip = clip))
|
||||||
}
|
}
|
||||||
DRAW_OP_IMAGE -> {
|
DRAW_OP_IMAGE -> {
|
||||||
val id = resource(); require(id != DrawProtocol.SCREEN)
|
val id = resource(); require(id != DrawProtocol.SCREEN)
|
||||||
val xx = r.readS16(); val yy = r.readS16(); val options = r.readU8()
|
val xx = r.readS16(); val yy = r.readS16(); val options = r.readU8()
|
||||||
require(options == 15 || options == 31)
|
require(options == 15 || options == 31)
|
||||||
Command(op, d, intArrayOf(id, xx, yy, options))
|
commands.add(Command(op, d, intArrayOf(id, xx, yy, options), clip = clip))
|
||||||
}
|
}
|
||||||
DRAW_OP_RECT_COPY -> {
|
DRAW_OP_RECT_COPY -> {
|
||||||
val id = resource(); val sx = value(); val sy = value()
|
val id = resource(); val sx = value(); val sy = value()
|
||||||
@@ -121,7 +201,29 @@ class FrameDisplayList private constructor(
|
|||||||
require(w in 1..640 && h in 1..480)
|
require(w in 1..640 && h in 1..480)
|
||||||
// Relative SCREEN sources may be negative until placement is added.
|
// Relative SCREEN sources may be negative until placement is added.
|
||||||
require(id == DrawProtocol.SCREEN || listOf(sx, sy).all { it !is DrawValue.Integer || it.value >= 0 })
|
require(id == DrawProtocol.SCREEN || listOf(sx, sy).all { it !is DrawValue.Integer || it.value >= 0 })
|
||||||
Command(op, d, intArrayOf(id, w, h), sx, sy, dx, dy)
|
commands.add(Command(op, d, intArrayOf(id, w, h), sx, sy, dx, dy, clip = clip))
|
||||||
|
}
|
||||||
|
DRAW_OP_CLEAR -> {
|
||||||
|
val color = r.readU8(); require(color in 0..15)
|
||||||
|
commands.add(Command(op, d, intArrayOf(color), clip = clip))
|
||||||
|
}
|
||||||
|
DRAWS -> {
|
||||||
|
val xx = value(); val yy = value()
|
||||||
|
val glyphs = ArrayList<GlyphRecord>(); val images = ArrayList<ImageRecord>()
|
||||||
|
repeat(r.readU16()) {
|
||||||
|
when (r.readU8()) {
|
||||||
|
DrawRecordKind.GLYPH -> {
|
||||||
|
val fontId = r.readU16(); val encoding = r.readU16() or (r.readU16() shl 16)
|
||||||
|
glyphs.add(GlyphRecord(fontId, encoding, r.readS16(), r.readS16(), r.readU8()))
|
||||||
|
}
|
||||||
|
DrawRecordKind.TEXTURE_IMAGE -> {
|
||||||
|
val imageId = r.readU16() or (r.readU16() shl 16)
|
||||||
|
images.add(ImageRecord(imageId, r.readS16(), r.readS16()))
|
||||||
|
}
|
||||||
|
else -> error("Unsupported display-list draw record")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (replayable) replayable = compileDraws(glyphs, images, xx, yy, d, clip, ::atlasResource, commands)
|
||||||
}
|
}
|
||||||
else -> error("Unsupported frame display-list opcode")
|
else -> error("Unsupported frame display-list opcode")
|
||||||
}
|
}
|
||||||
@@ -129,7 +231,11 @@ class FrameDisplayList private constructor(
|
|||||||
r.requireDone()
|
r.requireDone()
|
||||||
// Elapsed changes while the same timeline is resubmitted; it is not content identity.
|
// Elapsed changes while the same timeline is resubmitted; it is not content identity.
|
||||||
bytes.fill(0, 13, 17)
|
bytes.fill(0, 13, 17)
|
||||||
return FrameDisplayList(x, y, depth, resources, calls, nowMs - elapsed, CachedResource(bytes).hash.toString())
|
val identity = CachedResource(bytes).hash.toString()
|
||||||
|
if (!replayable || commands.size > 4096 || resources.size > 511) {
|
||||||
|
return FrameDisplayList(x, y, depth, emptyList(), emptyList(), nowMs - elapsed, identity)
|
||||||
|
}
|
||||||
|
return FrameDisplayList(x, y, depth, resources, commands, nowMs - elapsed, identity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Generated
+1
@@ -7,6 +7,7 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "faceclaw",
|
"name": "faceclaw",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@evenrealities/pretext": "^0.1.4",
|
"@evenrealities/pretext": "^0.1.4",
|
||||||
"@faceclaw/kotlin": "file:native/kotlin/plugin",
|
"@faceclaw/kotlin": "file:native/kotlin/plugin",
|
||||||
|
|||||||
@@ -30,10 +30,14 @@ test('iOS game worker forwards an immutable byte payload through its host and ig
|
|||||||
test('Android game bridge retains direct native playback and skips a missing communicator', () => {
|
test('Android game bridge retains direct native playback and skips a missing communicator', () => {
|
||||||
let active = null;
|
let active = null;
|
||||||
const played = [];
|
const played = [];
|
||||||
|
// Stands in for the reused Java direct buffer: the payload reaches Java as a
|
||||||
|
// copy, never as the caller's own ArrayBuffer.
|
||||||
|
const directBuffer = { JavaDirectBuffer: class { load(bytes) { return { bytes: bytes.slice() }; } } };
|
||||||
const bridge = loader({ global: { isIOS: false },
|
const bridge = loader({ global: { isIOS: false },
|
||||||
com: { faceclaw: { app: { FaceclawBleCommunicator: { getActive: () => active } } } } })('app/native/worker-buzzer.ts');
|
com: { faceclaw: { app: { FaceclawBleCommunicator: { getActive: () => active } } } } },
|
||||||
|
{ './java-direct-buffer': directBuffer })('app/native/worker-buzzer.ts');
|
||||||
bridge.playWorkerBuzzerSequence(payload);
|
bridge.playWorkerBuzzerSequence(payload);
|
||||||
active = { playBuzzerSequence: buffer => played.push(new Uint8Array(buffer)) };
|
active = { playBuzzerSequence: buffer => played.push(buffer.bytes) };
|
||||||
const backing = new Uint8Array(payload.length + 2); backing.set(payload, 1);
|
const backing = new Uint8Array(payload.length + 2); backing.set(payload, 1);
|
||||||
bridge.playWorkerBuzzerSequence(backing.subarray(1, -1)); backing.fill(0);
|
bridge.playWorkerBuzzerSequence(backing.subarray(1, -1)); backing.fill(0);
|
||||||
assert.deepEqual(played, [payload]);
|
assert.deepEqual(played, [payload]);
|
||||||
|
|||||||
@@ -24,12 +24,7 @@ const small = font(18), large = font(32);
|
|||||||
const diagnostics = { magneticAccuracy: 3, magneticAnomalies: 2, orientationSource: 3, flags: 0x8c, sampleTimeMs: 1234 };
|
const diagnostics = { magneticAccuracy: 3, magneticAnomalies: 2, orientationSource: 3, flags: 0x8c, sampleTimeMs: 1234 };
|
||||||
|
|
||||||
function compass(width = 576, height = 260) {
|
function compass(width = 576, height = 260) {
|
||||||
const settings = new Map();
|
let listener, window;
|
||||||
const debug = load('app/apps/compass/debug.ts', { '../../native/settings-store': {
|
|
||||||
getBooleanSetting: (key, fallback) => settings.get(key) ?? fallback,
|
|
||||||
setBooleanSetting: (key, value) => settings.set(key, value),
|
|
||||||
} });
|
|
||||||
let listener, window, renders = 0, pops = 0;
|
|
||||||
class RecordingImage extends graphics.GrayImage {
|
class RecordingImage extends graphics.GrayImage {
|
||||||
texts = [];
|
texts = [];
|
||||||
drawText(font, x, y, text, value) {
|
drawText(font, x, y, text, value) {
|
||||||
@@ -56,64 +51,62 @@ function compass(width = 576, height = 260) {
|
|||||||
'../../ui/shell/geometry': { screenCenterInViewportX: () => width / 2 - 32 },
|
'../../ui/shell/geometry': { screenCenterInViewportX: () => width / 2 - 32 },
|
||||||
'../../ui/shell/in-process-window': {
|
'../../ui/shell/in-process-window': {
|
||||||
YieldAtRootLayer: class { constructor(layer) { return layer; } },
|
YieldAtRootLayer: class { constructor(layer) { return layer; } },
|
||||||
createInProcessWindow: (options) => { window = options; return { requestRender: () => ++renders }; },
|
createInProcessWindow: (options) => { window = options; return { requestRender() {} }; },
|
||||||
},
|
},
|
||||||
'../../ui/shell/shell': { shell: { isWindowVisible: () => true } },
|
'../../ui/shell/shell': { shell: { isWindowVisible: () => true } },
|
||||||
'../../native/location-permissions': { hasLocationPermission: () => false },
|
'../../native/location-permissions': { hasLocationPermission: () => false },
|
||||||
'./calibration': calibration,
|
'./calibration': calibration,
|
||||||
'./calibration-layer': {}, './declination': { onDeclinationChanged: () => () => {} },
|
'./calibration-layer': {}, './declination': { onDeclinationChanged: () => () => {} },
|
||||||
'./heading': { getNorthReference: () => 'magnetic', resolveHeading: (v) => ({ displayDegrees: v }) },
|
'./heading': { getNorthReference: () => 'magnetic', resolveHeading: (v) => ({ displayDegrees: v }) },
|
||||||
'./debug': debug,
|
|
||||||
}, { setInterval: () => 1, clearInterval() {} });
|
}, { setInterval: () => 1, clearInterval() {} });
|
||||||
const ctx = { stack: { getBaseSize: () => ({ width, height }), pop: () => ++pops } };
|
const ctx = { stack: { getBaseSize: () => ({ width, height }), pop() {} } };
|
||||||
const open = () => app.createCompassAppWindow({ onClosed() {} }); open();
|
app.createCompassAppWindow({ onClosed() {} });
|
||||||
return { open, debug, settings, menu: () => window.menuItems(),
|
return { menu: () => window.menuItems(),
|
||||||
toggle: () => window.menuItems().find((item) => item.label.startsWith('Debug information:')).onSelect(ctx),
|
|
||||||
paint: () => window.baseLayer.paint(ctx),
|
paint: () => window.baseLayer.paint(ctx),
|
||||||
heading: (info) => listener({ command: 15, headingDegrees: 359, diagnostics: info }),
|
heading: (info) => listener({ command: 15, headingDegrees: 359, diagnostics: info }) };
|
||||||
renders: () => renders, pops: () => pops };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test('debug toggle defaults off, repaints, closes menu and survives reopening', () => {
|
const calibrationText = (image) => image.texts.find((t) => t.text.startsWith('Calibration:'));
|
||||||
const app = compass(); app.heading(diagnostics);
|
const overlaps = (a, b) => a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
|
||||||
assert.equal(app.debug.isCompassDebugEnabled(), false);
|
|
||||||
assert.ok(!app.paint().texts.some((t) => t.text.startsWith('Mag:')));
|
test('calibration readiness is always shown and the debug toggle is gone', () => {
|
||||||
const before = app.renders(); app.toggle();
|
const app = compass();
|
||||||
assert.equal(app.debug.isCompassDebugEnabled(), true);
|
assert.ok(!app.menu().some((item) => item.label.startsWith('Debug information')));
|
||||||
assert.ok(app.renders() > before && app.pops() === 1);
|
assert.equal(calibrationText(app.paint()).text, 'Calibration: --');
|
||||||
app.open(); assert.equal(app.debug.isCompassDebugEnabled(), true);
|
app.heading(diagnostics);
|
||||||
app.toggle(); assert.equal(app.debug.isCompassDebugEnabled(), false);
|
assert.equal(calibrationText(app.paint()).text, 'Calibration: ●●●');
|
||||||
|
assert.ok(!app.paint().texts.some((t) => /^(Mag|Anom|Src):/.test(t.text)));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('diagnostics sit to the right of the heading without overlap or clipping', () => {
|
test('calibration dots track firmware magnetic accuracy and never go stale', () => {
|
||||||
for (const width of [240, 320, 576, 640]) {
|
const app = compass();
|
||||||
const app = compass(width); app.toggle(); app.heading(diagnostics);
|
for (const [accuracy, dots] of [[0, '○○○'], [1, '●○○'], [2, '●●○'], [3, '●●●'], [4, '●●●'], [-1, '--']]) {
|
||||||
|
app.heading({ ...diagnostics, magneticAccuracy: accuracy });
|
||||||
|
assert.equal(calibrationText(app.paint()).text, `Calibration: ${dots}`, `accuracy ${accuracy}`);
|
||||||
|
}
|
||||||
|
app.heading(diagnostics);
|
||||||
|
// Legacy samples (no 0x80 flag) and missing diagnostics must replace the old value.
|
||||||
|
app.heading({ ...diagnostics, flags: 0 });
|
||||||
|
assert.equal(calibrationText(app.paint()).text, 'Calibration: --');
|
||||||
|
app.heading(diagnostics);
|
||||||
|
app.heading(undefined);
|
||||||
|
assert.equal(calibrationText(app.paint()).text, 'Calibration: --');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('calibration readout fits the viewport without overlapping the heading or status', () => {
|
||||||
|
for (const [width, height] of [[240, 260], [320, 260], [576, 260], [640, 260], [576, 288], [576, 140]]) {
|
||||||
|
const app = compass(width, height); app.heading({ ...diagnostics, magneticAccuracy: 2 });
|
||||||
const image = app.paint();
|
const image = app.paint();
|
||||||
const heading = image.texts.find((t) => t.text === '359° N');
|
const label = calibrationText(image);
|
||||||
for (const text of ['Mag: 3/3', 'Anom: 2', 'Src: RV']) {
|
assert.ok(label.x >= 0 && label.y >= 0, `${width}x${height}`);
|
||||||
const label = image.texts.find((t) => t.text === text);
|
assert.ok(label.x + label.width <= width && label.y + label.height <= image.height, `${width}x${height}`);
|
||||||
assert.ok(label, text);
|
for (const other of image.texts.filter((t) => t !== label)) {
|
||||||
assert.ok(label.x > heading.x + heading.width);
|
assert.ok(!overlaps(label, other), `${width}x${height}: overlaps "${other.text}"`);
|
||||||
assert.ok(label.x + label.width <= width && label.y + label.height <= image.height);
|
|
||||||
}
|
}
|
||||||
const status = image.texts.find((t) => t.text === 'Magnetic heading');
|
if (process.env.COMPASS_PREVIEW && width === 576 && height === 260) {
|
||||||
assert.ok(image.texts.filter((t) => t.text.startsWith('Src:')).every((t) => t.y + t.height < status.y));
|
|
||||||
if (process.env.COMPASS_PREVIEW && width === 576) {
|
|
||||||
fs.writeFileSync(process.env.COMPASS_PREVIEW, Buffer.concat([
|
fs.writeFileSync(process.env.COMPASS_PREVIEW, Buffer.concat([
|
||||||
Buffer.from(`P5\n${image.width} ${image.height}\n255\n`), Buffer.from(image.withDrawsBaked().pixels),
|
Buffer.from(`P5\n${image.width} ${image.height}\n255\n`), Buffer.from(image.withDrawsBaked().pixels),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('legacy and missing samples replace diagnostics instead of leaving stale values', () => {
|
|
||||||
const app = compass(); app.toggle(); app.heading(diagnostics);
|
|
||||||
assert.ok(app.paint().texts.some((t) => t.text === 'Mag: 3/3'));
|
|
||||||
app.heading(undefined);
|
|
||||||
assert.ok(app.paint().texts.some((t) => t.text === 'unavailable'));
|
|
||||||
assert.ok(!app.paint().texts.some((t) => t.text === 'Mag: 3/3'));
|
|
||||||
assert.deepEqual(Array.from(app.debug.compassDebugLines({ ...diagnostics, flags: 0 })), ['Sample data', 'unavailable']);
|
|
||||||
for (const [source, name] of [[1, 'GRV'], [2, 'GMRV'], [3, 'RV']]) {
|
|
||||||
assert.equal(app.debug.compassDebugLines({ ...diagnostics, orientationSource: source })[2], `Src: ${name}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -47,7 +47,6 @@ const compass = load('app/apps/compass/compass-app.ts', {
|
|||||||
'./calibration': calibration,
|
'./calibration': calibration,
|
||||||
'./calibration-layer': {},
|
'./calibration-layer': {},
|
||||||
'./compass-rose': rose,
|
'./compass-rose': rose,
|
||||||
'./debug': { compassDebugLines: () => [], isCompassDebugEnabled: () => false, setCompassDebugEnabled: () => {} },
|
|
||||||
'./declination': {},
|
'./declination': {},
|
||||||
'./heading': { getNorthReference: () => 'magnetic', resolveHeading: (n) => ({ displayDegrees: n }) },
|
'./heading': { getNorthReference: () => 'magnetic', resolveHeading: (n) => ({ displayDegrees: n }) },
|
||||||
}, `
|
}, `
|
||||||
@@ -149,7 +148,7 @@ test('heading updates reuse the texture; brightness, layout and clipping changes
|
|||||||
|
|
||||||
test('the background registers once and uses a nine-byte image reference on later frames', () => {
|
test('the background registers once and uses a nine-byte image reference on later frames', () => {
|
||||||
const registered = [];
|
const registered = [];
|
||||||
const atlas = load('app/native/texture-atlas.ts', {}, '', {
|
const atlas = load('app/native/texture-atlas.ts', { './java-direct-buffer': { copyToJavaByteBuffer: (bytes) => bytes } }, '', {
|
||||||
global: { isAndroid: true },
|
global: { isAndroid: true },
|
||||||
com: { faceclaw: { app: { AndroidByteReader: class { constructor(buffer) { this.buffer = buffer; } }, ImageAtlas: { ensure: (...args) => {
|
com: { faceclaw: { app: { AndroidByteReader: class { constructor(buffer) { this.buffer = buffer; } }, ImageAtlas: { ensure: (...args) => {
|
||||||
registered.push(args);
|
registered.push(args);
|
||||||
|
|||||||
@@ -85,3 +85,45 @@ test('frame submission supports resource-free lists and plain PRESENT-relative t
|
|||||||
paintDisplayList(output,screen,8,8,placed,false,1002);
|
paintDisplayList(output,screen,8,8,placed,false,1002);
|
||||||
assert.equal(output[2],240); assert.equal(output[0],0);
|
assert.equal(output[2],240); assert.equal(output[0],0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Also consumed by FrameDisplayListTest.kt, with 0xbeef / 0xcafebabe replaced by
|
||||||
|
// the font and image ids it registers: a clipped clear, a clipped rounded rect,
|
||||||
|
// and replayed glyph + icon draws clipped while sliding up. REPLAY_PIXELS is
|
||||||
|
// what the list paints over a nibble-1 screen, 16x8 at 4 bits per pixel.
|
||||||
|
const REPLAY = '0780000000020003000800040000070000006400000000000300890000000000000600040002880000010001000200020000000400030000000510a00000000000000600040000ff2502000080c002000000000180c8800180c8161101001732800180c81610300180c830234031020000efbe4100000000000000ff01bebafeca04000100';
|
||||||
|
const REPLAY_PIXELS = '11111111111111111111111111111111111111111111111111fff28f111111111125522211111111112552221111111111222222111111111111111111111111';
|
||||||
|
|
||||||
|
function replayList() {
|
||||||
|
// 'A' is 3x2 ink one row below a 4px line top; the icon is 2x2.
|
||||||
|
const font = { fingerprintId: 9001, atlasKey: 'stub-font', ascent: 3, lineHeight: 4 };
|
||||||
|
const glyph = { encoding: 65, bbxWidth: 3, bbxHeight: 2, bbxX: 0, bbxY: 0, bitmapRows: [0xa0, 0xe0] };
|
||||||
|
const icon = new GrayImage(2, 2); icon.pixels.set([255, 0, 128, 255]);
|
||||||
|
const source = new GrayImage(8, 4);
|
||||||
|
source.drawGlyph(font, glyph, 0, 0, 255);
|
||||||
|
source.drawImage(icon, 4, 1);
|
||||||
|
const records = Uint8Array.from([0, 0xef, 0xbe, 65, 0, 0, 0, 0, 0, 0, 0, 255, 1, 0xbe, 0xba, 0xfe, 0xca, 4, 0, 1, 0]);
|
||||||
|
const clip = { x: 0, y: 0, width: 6, height: 4 };
|
||||||
|
return { x: 2, y: 3, width: 8, height: 4, depth: 0, displayList: { resources: [], timeline: { token: 7, startedAt: 1000 }, calls: [
|
||||||
|
{ op: DrawOp.CLEAR, color: 2, clip },
|
||||||
|
{ op: DrawOp.ROUNDED_RECT, x: 0, y: 0, width: 4, height: 3, radius: 0, background: 5, border: 16, clip: { x: 1, y: 1, width: 2, height: 2 } },
|
||||||
|
{ op: DrawOp.DRAWS, x: 0, y: E.progress(200).lerp(E.f32(-4), E.f32(0)).toInt(), records, count: 2, source, clip },
|
||||||
|
] } };
|
||||||
|
}
|
||||||
|
|
||||||
|
test('clipped clears, rects and replayed draws encode, decode and paint', () => {
|
||||||
|
const placed = replayList();
|
||||||
|
const hex = Buffer.from(encodeDisplayList(placed, 1100)).toString('hex');
|
||||||
|
const output = new Uint8Array(16 * 8).fill(16);
|
||||||
|
paintDisplayList(output, output.slice(), 16, 8, placed, false, 1100);
|
||||||
|
const nibbles = Array.from(output, (v) => (Math.min(15, (v + 8) >> 4)).toString(16)).join('');
|
||||||
|
assert.equal(hex, REPLAY);
|
||||||
|
assert.equal(nibbles, REPLAY_PIXELS);
|
||||||
|
const decoded = readDisplayList(Buffer.from(REPLAY, 'hex'), 0, 1100).placed;
|
||||||
|
const [clear, rect, draws] = decoded.displayList.calls;
|
||||||
|
assert.deepEqual([clear.op, clear.color, clear.clip], [DrawOp.CLEAR, 2, { x: 0, y: 0, width: 6, height: 4 }]);
|
||||||
|
assert.deepEqual(rect.clip, { x: 1, y: 1, width: 2, height: 2 });
|
||||||
|
assert.equal(draws.count, 2);
|
||||||
|
assert.deepEqual(Array.from(draws.records), Array.from(placed.displayList.calls[2].records));
|
||||||
|
assert.equal(draws.source, undefined, 'decoded draws have no software source');
|
||||||
|
assert.throws(() => readDisplayList(Buffer.from(REPLAY.replace('01bebafeca', '05bebafeca'), 'hex'), 0, 1100), /draw record/);
|
||||||
|
});
|
||||||
@@ -0,0 +1,300 @@
|
|||||||
|
const test = require('node:test');
|
||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
const vm = require('node:vm');
|
||||||
|
const ts = require('typescript');
|
||||||
|
const build = (name) => require(`../.test-build/app/${name}.js`);
|
||||||
|
const metrics = build('ui/metrics');
|
||||||
|
const { GrayImage } = build('graphics/image');
|
||||||
|
const { DrawOp } = build('graphics/display-list');
|
||||||
|
const { MENU_HIGHLIGHT_DURATION_MS } = build('ui/menu-highlight-motion');
|
||||||
|
const { MENU_BOUNCE_DURATION_MS } = build('ui/menu-scroll-motion');
|
||||||
|
|
||||||
|
const LINE_HEIGHT = 21;
|
||||||
|
// icon 44 + label gap 2 + line 21 + 8 breathing room.
|
||||||
|
const ROW_H = 75;
|
||||||
|
|
||||||
|
/** A font whose every glyph is a 4x6 block, drawn as deferred glyph draws like a real atlas font. */
|
||||||
|
function stubFont() {
|
||||||
|
const glyphs = new Map();
|
||||||
|
const glyph = (cp) => {
|
||||||
|
if (!glyphs.has(cp)) glyphs.set(cp, { encoding: cp, bbxWidth: 4, bbxHeight: 6, bbxX: 0, bbxY: 0, bitmapRows: Array(6).fill(0xf0) });
|
||||||
|
return glyphs.get(cp);
|
||||||
|
};
|
||||||
|
const font = {
|
||||||
|
fingerprintId: 77, atlasKey: 'stub', ascent: 15, descent: 6, lineHeight: LINE_HEIGHT,
|
||||||
|
measureText: (text) => text.length * 6,
|
||||||
|
getGlyph: glyph,
|
||||||
|
hasGlyph: () => true,
|
||||||
|
drawText(image, x, y, text, value) {
|
||||||
|
let pen = x;
|
||||||
|
for (const ch of text) { image.drawGlyph(font, glyph(ch.codePointAt(0)), pen, y, value); pen += 6; }
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Transpile one module with its imports resolved from `deps`. */
|
||||||
|
function load(file, deps) {
|
||||||
|
const exports = {};
|
||||||
|
const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
|
||||||
|
vm.runInNewContext(ts.transpileModule(source, {
|
||||||
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
||||||
|
}).outputText, { exports, console, Date, require(name) {
|
||||||
|
assert.ok(name in deps, `Unexpected import ${name} in ${file}`);
|
||||||
|
return deps[name];
|
||||||
|
} });
|
||||||
|
return exports;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadIconGrid({ lastInputWasWatch = false } = {}) {
|
||||||
|
const font = stubFont();
|
||||||
|
const state = { replayable: true };
|
||||||
|
const common = {
|
||||||
|
'../graphics/image': build('graphics/image'),
|
||||||
|
'../graphics/textwrap': build('graphics/textwrap'),
|
||||||
|
'../graphics/ui-fonts': { getDefaultSmallFont: () => font },
|
||||||
|
'../util/numeric-util': build('util/numeric-util'),
|
||||||
|
'./gestures': build('ui/gestures'),
|
||||||
|
'./menu-core': build('ui/menu-core'),
|
||||||
|
'./metrics': metrics,
|
||||||
|
};
|
||||||
|
const menu = load('app/ui/menu.ts', { ...common, './layers': {} });
|
||||||
|
const grid = load('app/ui/icon-grid.ts', {
|
||||||
|
...common,
|
||||||
|
'../graphics/draw-expression': build('graphics/draw-expression'),
|
||||||
|
'../graphics/display-list': build('graphics/display-list'),
|
||||||
|
// Registration is native; any draws are replayable unless a test says not.
|
||||||
|
'../graphics/glyph-wire': { encodeReplayDraws: (draws) => state.replayable ? { records: new Uint8Array(0), count: draws.length } : null },
|
||||||
|
'../graphics/menu-scroll-list': build('graphics/menu-scroll-list'),
|
||||||
|
'./menu': menu,
|
||||||
|
'./menu-highlight-motion': build('ui/menu-highlight-motion'),
|
||||||
|
'./menu-scroll-motion': build('ui/menu-scroll-motion'),
|
||||||
|
'./shell/shell': { shell: { lastInputWasWatch: () => lastInputWasWatch } },
|
||||||
|
'./layers': {},
|
||||||
|
});
|
||||||
|
return { ...grid, state };
|
||||||
|
}
|
||||||
|
|
||||||
|
const ICON = new GrayImage(44, 44);
|
||||||
|
ICON.fillRect(10, 10, 24, 24, 200);
|
||||||
|
const ring = (type) => ({ type });
|
||||||
|
const watch = (type) => ({ type, source: 'watch' });
|
||||||
|
const BOX = { x: 0, y: 10, width: 500, height: 180 };
|
||||||
|
|
||||||
|
function makeGrid({ items = Array.from({ length: 12 }, (_, i) => `item${i}`), isWide, onActivate, onBack, watchLast } = {}) {
|
||||||
|
const { IconGrid, state } = loadIconGrid({ lastInputWasWatch: watchLast });
|
||||||
|
const log = { activated: [], backs: 0 };
|
||||||
|
const data = { items };
|
||||||
|
const grid = new IconGrid({
|
||||||
|
items: () => data.items,
|
||||||
|
isWide,
|
||||||
|
describe: (item) => ({ label: item, icon: ICON }),
|
||||||
|
onActivate: onActivate ?? ((item, index) => { log.activated.push({ item, index }); }),
|
||||||
|
onBack: onBack ?? (() => { log.backs++; return false; }),
|
||||||
|
});
|
||||||
|
return { grid, log, data, state };
|
||||||
|
}
|
||||||
|
|
||||||
|
function withClock(now, fn) {
|
||||||
|
const original = Date.now;
|
||||||
|
Date.now = () => now;
|
||||||
|
try { return fn(); } finally { Date.now = original; }
|
||||||
|
}
|
||||||
|
|
||||||
|
function paint(grid, now, box = BOX) {
|
||||||
|
return withClock(now, () => {
|
||||||
|
const image = new GrayImage(500, 200);
|
||||||
|
grid.paint(image, box, true);
|
||||||
|
return image;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const animation = (image) => image.draws.find((draw) => draw.presentation?.displayList)?.presentation.displayList;
|
||||||
|
|
||||||
|
/** What the glasses show at `at`, as 4-bit values. */
|
||||||
|
function shown(image, at) {
|
||||||
|
return withClock(at, () => Array.from(image.withDrawsBaked().pixels, (v) => Math.min(15, (v + 8) >> 4)));
|
||||||
|
}
|
||||||
|
|
||||||
|
test('rows keep their content height instead of stretching, and the next row peeks clipped', () => {
|
||||||
|
assert.equal(metrics.iconGridMinRowHeight({ lineHeight: LINE_HEIGHT }, 44, 2), ROW_H);
|
||||||
|
const { grid } = makeGrid({ items: Array.from({ length: 15 }, (_, i) => `item${i}`) });
|
||||||
|
const image = paint(grid, 1000);
|
||||||
|
const iconYs = [...new Set(image.draws.filter((d) => d.kind === 'image' && !d.presentation).map((d) => d.y))];
|
||||||
|
assert.deepEqual(iconYs, [14, 14 + ROW_H], 'full rows are deferred draws at the natural pitch');
|
||||||
|
const glyphYs = [...new Set(image.draws.filter((d) => d.kind === 'glyph').map((d) => d.y))];
|
||||||
|
assert.deepEqual(glyphYs, [60, 60 + ROW_H], 'labels of full rows only');
|
||||||
|
// The third row's top is baked into the raster, cut off at the box bottom (y 190).
|
||||||
|
const peekTop = 14 + 2 * ROW_H;
|
||||||
|
assert.ok(image.pixels[(peekTop + 15) * 500 + 60] > 0, 'the peeking icon shows');
|
||||||
|
for (let y = 190; y < 200; y++) for (let x = 0; x < 500; x++) assert.equal(image.pixels[y * 500 + x], 0, `nothing below the box at (${x}, ${y})`);
|
||||||
|
assert.equal(animation(image), undefined, 'a first paint does not animate');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the pitch only changes with the font, not with how many rows fit', () => {
|
||||||
|
const { grid } = makeGrid();
|
||||||
|
for (const height of [150, 180, 224]) {
|
||||||
|
const image = paint(grid, 1000, { x: 0, y: 0, width: 500, height });
|
||||||
|
const ys = [...new Set(image.draws.filter((d) => d.kind === 'image').map((d) => d.y))];
|
||||||
|
for (let i = 1; i < ys.length; i++) assert.equal(ys[i] - ys[i - 1], ROW_H, `height ${height}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('scrolling rows into view animates from the old paint to the new one', async () => {
|
||||||
|
const { grid } = makeGrid({ items: Array.from({ length: 15 }, (_, i) => `item${i}`) });
|
||||||
|
paint(grid, 500);
|
||||||
|
await grid.handleInput(ring('scroll-down'), null);
|
||||||
|
const before = paint(grid, 1000);
|
||||||
|
assert.equal(animation(before) !== undefined, true, 'moving the band animates its slide');
|
||||||
|
const settledBefore = paint(grid, 2000);
|
||||||
|
await grid.handleInput(ring('scroll-down'), null);
|
||||||
|
const moving = paint(grid, 3000);
|
||||||
|
const list = animation(moving);
|
||||||
|
assert.ok(list, 'the scroll is retained as a display list');
|
||||||
|
assert.deepEqual(Array.from(list.calls, (c) => c.op), [DrawOp.CLEAR, DrawOp.ROUNDED_RECT, DrawOp.DRAWS]);
|
||||||
|
assert.ok(list.calls.every((c) => c.clip && c.clip.width === 500 && c.clip.height === 180), 'every call is clipped to the box');
|
||||||
|
// First and last frames match the static paints on either side.
|
||||||
|
assert.deepEqual(shown(moving, 3000), shown(settledBefore, 2000));
|
||||||
|
const end = 3000 + MENU_HIGHLIGHT_DURATION_MS;
|
||||||
|
const settled = paint(grid, end);
|
||||||
|
assert.equal(animation(settled), undefined, 'the static paint takes over once the animation ends');
|
||||||
|
assert.deepEqual(shown(moving, end), shown(settled, end));
|
||||||
|
const middle = shown(moving, 3000 + MENU_HIGHLIGHT_DURATION_MS / 2);
|
||||||
|
assert.notDeepEqual(middle, shown(settled, end));
|
||||||
|
assert.notDeepEqual(middle, shown(settledBefore, 2000));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('item selection slides the highlight between cells without redrawing past the scrollbar gutter', async () => {
|
||||||
|
const { IconGrid } = loadIconGrid();
|
||||||
|
const grid = new IconGrid({
|
||||||
|
items: () => Array.from({ length: 30 }, (_, i) => `item${i}`),
|
||||||
|
describe: (item) => ({ label: item, icon: ICON }), onActivate: () => {}, onBack: () => false, scrollbar: true,
|
||||||
|
});
|
||||||
|
paint(grid, 500);
|
||||||
|
await grid.handleInput(ring('click'), null);
|
||||||
|
const before = paint(grid, 1000);
|
||||||
|
assert.equal(animation(before), undefined, 'entering item mode snaps');
|
||||||
|
await grid.handleInput(ring('scroll-down'), null);
|
||||||
|
const moving = paint(grid, 2000);
|
||||||
|
const list = animation(moving);
|
||||||
|
assert.ok(list);
|
||||||
|
assert.equal(list.calls[0].clip.width, 495, 'the scrollbar gutter is left to the static paint');
|
||||||
|
const rect = list.calls[1];
|
||||||
|
const { evaluate } = build('graphics/draw-expression');
|
||||||
|
assert.equal(evaluate(rect.x, 0).value, 200 + 6, 'starts on the middle cell');
|
||||||
|
assert.equal(evaluate(rect.x, MENU_HIGHLIGHT_DURATION_MS).value, 300 + 6, 'rests on the next cell');
|
||||||
|
assert.deepEqual(shown(moving, 2000), shown(before, 1000));
|
||||||
|
const end = 2000 + MENU_HIGHLIGHT_DURATION_MS;
|
||||||
|
assert.deepEqual(shown(moving, end), shown(paint(grid, end), end));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('navigating past an end bounces and comes back', async () => {
|
||||||
|
const { grid } = makeGrid();
|
||||||
|
const rest = paint(grid, 1000);
|
||||||
|
await grid.handleInput(ring('scroll-up'), null);
|
||||||
|
const bouncing = paint(grid, 2000);
|
||||||
|
const list = animation(bouncing);
|
||||||
|
assert.ok(list, 'a bounce at the top is animated');
|
||||||
|
assert.deepEqual(shown(bouncing, 2000), shown(rest, 1000));
|
||||||
|
const peak = shown(bouncing, 2000 + Math.round(MENU_BOUNCE_DURATION_MS * 0.35));
|
||||||
|
assert.notDeepEqual(peak, shown(rest, 1000), 'the rows move down past the top');
|
||||||
|
// The first icon row moved 24px down (0.4 of a row, capped); the highlight moved with it.
|
||||||
|
// Column 0's icon ink spans x 38..61 at 4-bit level 13.
|
||||||
|
const iconTop = (image) => { for (let y = 10; y < 200; y++) if (image[y * 500 + 50] === 13) return y; };
|
||||||
|
assert.equal(iconTop(peak) - iconTop(shown(rest, 1000)), 24);
|
||||||
|
assert.deepEqual(shown(bouncing, 2000 + MENU_BOUNCE_DURATION_MS), shown(rest, 1000));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('unreplayable rows, host navigation and taps snap', async () => {
|
||||||
|
const { grid, state } = makeGrid({ onBack: () => { grid.resetSelection(); return false; } });
|
||||||
|
paint(grid, 1000);
|
||||||
|
state.replayable = false;
|
||||||
|
await grid.handleInput(ring('scroll-down'), null);
|
||||||
|
assert.equal(animation(paint(grid, 2000)), undefined, 'rows that cannot be replayed snap');
|
||||||
|
state.replayable = true;
|
||||||
|
assert.equal(animation(paint(grid, 2100)), undefined, 'the cancelled motion does not resume');
|
||||||
|
await grid.handleInput(ring('double-click'), null);
|
||||||
|
assert.equal(animation(paint(grid, 3000)), undefined, 'a host reset is not navigation');
|
||||||
|
await grid.hitTest(250, 20 + ROW_H, null);
|
||||||
|
assert.equal(animation(paint(grid, 4000)), undefined, 'a tap selects without sliding');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('ring: row mode, then item mode at the middle column, linear traversal, back out', async () => {
|
||||||
|
const { grid, log } = makeGrid();
|
||||||
|
assert.equal(grid.selectedItem, null, 'row mode pins no item');
|
||||||
|
await grid.handleInput(ring('click'), null);
|
||||||
|
assert.equal(grid.selectedItem, 'item2', 'click enters item mode at the middle column');
|
||||||
|
await grid.handleInput(ring('scroll-down'), null);
|
||||||
|
await grid.handleInput(ring('scroll-down'), null);
|
||||||
|
await grid.handleInput(ring('scroll-down'), null);
|
||||||
|
assert.equal(grid.selectedItem, 'item5', 'item scrolling continues onto the next row');
|
||||||
|
await grid.handleInput(ring('scroll-up'), null);
|
||||||
|
assert.equal(grid.selectedItem, 'item4', 'and back onto the previous row at its end');
|
||||||
|
await grid.handleInput(ring('click'), null);
|
||||||
|
assert.deepEqual(log.activated, [{ item: 'item4', index: 4 }]);
|
||||||
|
await grid.handleInput(ring('double-click'), null);
|
||||||
|
assert.equal(grid.selectedItem, null, 'double-click drops to row mode');
|
||||||
|
assert.equal(log.backs, 0);
|
||||||
|
await grid.handleInput(ring('double-click'), null);
|
||||||
|
assert.equal(log.backs, 1, 'double-click in row mode backs out');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('watch: four-way cells, left from the first column backs out and stays in item mode', async () => {
|
||||||
|
const { grid, log, data } = makeGrid({
|
||||||
|
onBack: () => { log.backs++; grid.resetSelection(); return false; },
|
||||||
|
});
|
||||||
|
await grid.handleInput(watch('swipe-down'), null);
|
||||||
|
await grid.handleInput(watch('swipe-right'), null);
|
||||||
|
assert.equal(grid.selectedItem, 'item6', 'row 1, column 1');
|
||||||
|
await grid.handleInput(watch('swipe-down'), null);
|
||||||
|
assert.equal(grid.selectedItem, 'item11', 'a shorter row clamps the column');
|
||||||
|
await grid.handleInput(watch('swipe-left'), null);
|
||||||
|
assert.equal(grid.selectedItem, 'item10');
|
||||||
|
assert.equal(log.backs, 0);
|
||||||
|
await grid.handleInput(watch('swipe-left'), null);
|
||||||
|
assert.equal(log.backs, 1);
|
||||||
|
assert.equal(grid.selectedItem, 'item0', 'the host reset the selection, and the watch keeps a cell selected');
|
||||||
|
data.items = ['only'];
|
||||||
|
await grid.handleInput(watch('click'), null);
|
||||||
|
assert.deepEqual(log.activated, [{ item: 'only', index: 0 }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('activating or backing out of the grid returns it to row mode', async () => {
|
||||||
|
const { grid } = makeGrid({ onActivate: async () => true, onBack: () => true });
|
||||||
|
await grid.handleInput(watch('swipe-right'), null);
|
||||||
|
await grid.handleInput(watch('click'), null);
|
||||||
|
assert.equal(grid.selectedItem, null, 'a launch leaves row mode behind');
|
||||||
|
await grid.handleInput(ring('click'), null);
|
||||||
|
assert.notEqual(grid.selectedItem, null);
|
||||||
|
await grid.handleInput(watch('double-click'), null);
|
||||||
|
assert.equal(grid.selectedItem, null, 'leaving via the watch restores row mode too');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('wide items take their own row and count as one item', async () => {
|
||||||
|
const items = ['notice', 'a', 'b', 'c', 'd', 'e', 'f'];
|
||||||
|
const { grid, log } = makeGrid({ items, isWide: (item) => item === 'notice' });
|
||||||
|
assert.equal(grid.selectedItem, 'notice', 'a wide row is selected as a whole even in row mode');
|
||||||
|
await grid.handleInput(ring('click'), null);
|
||||||
|
assert.deepEqual(log.activated, [{ item: 'notice', index: 0 }], 'one click opens a wide row');
|
||||||
|
grid.selectIndex(6);
|
||||||
|
assert.equal(grid.cursorIndex, 6);
|
||||||
|
assert.equal(grid.selectedItem, null, 'selectIndex keeps row mode');
|
||||||
|
await grid.handleInput(ring('click'), null);
|
||||||
|
assert.equal(grid.selectedItem, 'f', 'the one-item row clamps the middle column');
|
||||||
|
await grid.handleInput(ring('scroll-up'), null);
|
||||||
|
assert.equal(grid.selectedItem, 'e', 'item traversal walks back through the full row');
|
||||||
|
for (let i = 0; i < 5; i++) await grid.handleInput(ring('scroll-up'), null);
|
||||||
|
assert.equal(grid.selectedItem, 'notice');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('hitTest opens the cell under the touch, including the peeking row', async () => {
|
||||||
|
const { grid, log } = makeGrid();
|
||||||
|
paint(grid, 1000);
|
||||||
|
assert.equal(await grid.hitTest(50, 10 + 2 * ROW_H + 5, null), true);
|
||||||
|
assert.deepEqual(log.activated, [{ item: 'item10', index: 10 }]);
|
||||||
|
assert.equal(grid.selectedItem, 'item10', 'the touched cell becomes the selection');
|
||||||
|
assert.equal(await grid.hitTest(250, 5, null), false, 'above the box');
|
||||||
|
assert.equal(await grid.hitTest(250, 10 + 2 * ROW_H + 5, null), false, 'past the last cell of a short row');
|
||||||
|
});
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
const test = require("node:test");
|
||||||
|
const assert = require("node:assert/strict");
|
||||||
|
|
||||||
|
const { JavaDirectBuffer, copyToJavaByteBuffer } = require("../.test-build/app/native/java-direct-buffer.js");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A stand-in for java.nio.ByteBuffer.allocateDirect: fixed capacity, a
|
||||||
|
* position and a limit, and the relative bulk get() SurfaceCompositor uses.
|
||||||
|
* viewOf() plays ArrayBuffer.from: a view over the same memory, not a copy.
|
||||||
|
*/
|
||||||
|
function fakeBackend() {
|
||||||
|
const allocated = [];
|
||||||
|
return {
|
||||||
|
allocated,
|
||||||
|
allocateDirect(capacity) {
|
||||||
|
const memory = new Uint8Array(capacity);
|
||||||
|
const buffer = {
|
||||||
|
memory,
|
||||||
|
position: 0,
|
||||||
|
limitValue: capacity,
|
||||||
|
clear() {
|
||||||
|
this.position = 0;
|
||||||
|
this.limitValue = capacity;
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
limit(newLimit) {
|
||||||
|
if (newLimit > capacity) throw new Error("limit past capacity");
|
||||||
|
this.limitValue = newLimit;
|
||||||
|
if (this.position > newLimit) this.position = newLimit;
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
remaining() {
|
||||||
|
return this.limitValue - this.position;
|
||||||
|
},
|
||||||
|
get(dst, offset, length) {
|
||||||
|
if (length > this.remaining()) throw new Error("BufferUnderflowException");
|
||||||
|
dst.set(memory.subarray(this.position, this.position + length), offset);
|
||||||
|
this.position += length;
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
allocated.push(buffer);
|
||||||
|
return buffer;
|
||||||
|
},
|
||||||
|
viewOf(buffer) {
|
||||||
|
return buffer.memory;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Consume the way SurfaceCompositor.applyAndComposite does: exact remaining(), then drain. */
|
||||||
|
function consume(buffer, expectedBytes) {
|
||||||
|
assert.equal(buffer.remaining(), expectedBytes);
|
||||||
|
const out = new Uint8Array(expectedBytes);
|
||||||
|
buffer.get(out, 0, expectedBytes);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function frame(length, seed) {
|
||||||
|
const bytes = new Uint8Array(length);
|
||||||
|
for (let i = 0; i < length; i++) bytes[i] = (i * 31 + seed) & 0xff;
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
test("a loaded buffer exposes exactly the payload bytes to a Java-style reader", () => {
|
||||||
|
const backend = fakeBackend();
|
||||||
|
const pool = new JavaDirectBuffer(640 * 480, backend);
|
||||||
|
const shell = frame(640 * 480, 1);
|
||||||
|
assert.deepEqual(consume(pool.load(shell), shell.length), shell);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("successive frames reuse one Java buffer, including smaller ones", () => {
|
||||||
|
const backend = fakeBackend();
|
||||||
|
const pool = new JavaDirectBuffer(640 * 480, backend);
|
||||||
|
for (let i = 0; i < 50; i++) {
|
||||||
|
const size = i % 2 === 0 ? 640 * 480 : 640 * 452;
|
||||||
|
const bytes = frame(size, i);
|
||||||
|
assert.deepEqual(consume(pool.load(bytes), size), bytes);
|
||||||
|
}
|
||||||
|
assert.equal(pool.allocations, 1);
|
||||||
|
assert.equal(backend.allocated.length, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a payload larger than the buffer allocates once more, then reuses", () => {
|
||||||
|
const backend = fakeBackend();
|
||||||
|
const pool = new JavaDirectBuffer(0, backend);
|
||||||
|
consume(pool.load(frame(10, 0)), 10);
|
||||||
|
consume(pool.load(frame(9000, 0)), 9000);
|
||||||
|
consume(pool.load(frame(8000, 0)), 8000);
|
||||||
|
consume(pool.load(frame(9000, 0)), 9000);
|
||||||
|
assert.equal(pool.allocations, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("loadOptional passes null through and loads a draw list", () => {
|
||||||
|
const backend = fakeBackend();
|
||||||
|
const pool = new JavaDirectBuffer(0, backend);
|
||||||
|
assert.equal(pool.loadOptional(null), null);
|
||||||
|
assert.equal(pool.loadOptional(undefined), null);
|
||||||
|
assert.equal(pool.loadOptional(new ArrayBuffer(0)), null);
|
||||||
|
assert.equal(backend.allocated.length, 0);
|
||||||
|
const draws = frame(36, 7);
|
||||||
|
assert.deepEqual(consume(pool.loadOptional(draws.buffer), 36), draws);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("a view on a larger buffer contributes only its own bytes", () => {
|
||||||
|
const backend = fakeBackend();
|
||||||
|
const pool = new JavaDirectBuffer(0, backend);
|
||||||
|
const whole = frame(100, 3);
|
||||||
|
const view = whole.subarray(10, 30);
|
||||||
|
assert.deepEqual(consume(pool.load(view), 20), whole.slice(10, 30));
|
||||||
|
});
|
||||||
|
|
||||||
|
test("copyToJavaByteBuffer gives each crossing its own exact-length buffer", () => {
|
||||||
|
const backend = fakeBackend();
|
||||||
|
const whole = frame(100, 5);
|
||||||
|
const first = copyToJavaByteBuffer(whole.subarray(10, 30), backend);
|
||||||
|
const second = copyToJavaByteBuffer(frame(7, 1), backend);
|
||||||
|
assert.notEqual(first, second);
|
||||||
|
assert.deepEqual(consume(first, 20), whole.slice(10, 30));
|
||||||
|
assert.deepEqual(consume(second, 7), frame(7, 1));
|
||||||
|
assert.equal(consume(copyToJavaByteBuffer(new Uint8Array(0), backend), 0).length, 0);
|
||||||
|
});
|
||||||
@@ -49,7 +49,7 @@ class DisplayListTest {
|
|||||||
val nested = listOf(DrawProtocol.image(11, -1, 0), DrawProtocol.bbox(hex("0c000000"), 2, 1, 0, 1, 1, 10))
|
val nested = listOf(DrawProtocol.image(11, -1, 0), DrawProtocol.bbox(hex("0c000000"), 2, 1, 0, 1, 1, 10))
|
||||||
resources[20]=DrawProtocol.displayList(nested)
|
resources[20]=DrawProtocol.displayList(nested)
|
||||||
val calls = listOf(DrawProtocol.call(DRAW_OP_DISPLAY_LIST,DrawProtocol.word(20)), DrawProtocol.image(10,3,1),
|
val calls = listOf(DrawProtocol.call(DRAW_OP_DISPLAY_LIST,DrawProtocol.word(20)), DrawProtocol.image(10,3,1),
|
||||||
DrawProtocol.call(DRAW_OP_TEXT,hex("0c00070003000f0141")), DrawProtocol.lut(8,4,128))
|
DrawProtocol.call(DRAW_OP_TEXT,hex("0c0007030f0141")), DrawProtocol.lut(8,4,128))
|
||||||
resources[21]=DrawProtocol.displayList(calls)
|
resources[21]=DrawProtocol.displayList(calls)
|
||||||
// Like the C harness, seed composition with the screen: this list has no screen copy.
|
// Like the C harness, seed composition with the screen: this list has no screen copy.
|
||||||
val screen=hex("123456789abcdef0123456789abcdef0"); val output=screen.copyOf()
|
val screen=hex("123456789abcdef0123456789abcdef0"); val output=screen.copyOf()
|
||||||
@@ -114,7 +114,7 @@ class DisplayListTest {
|
|||||||
@Test fun roundedRectsAndNestedOddNegativeDepthMatchFirmwareOnBothLenses() {
|
@Test fun roundedRectsAndNestedOddNegativeDepthMatchFirmwareOnBothLenses() {
|
||||||
val resources = mapOf(
|
val resources = mapOf(
|
||||||
40 to hex("0404000200f00f0ff0"),
|
40 to hex("0404000200f00f0ff0"),
|
||||||
41 to hex("0202000d0008020201010c0008000300040a0a000402022800050004001f"),
|
41 to hex("0202000d0008020201010c0008000300040a0800040202280005041f"),
|
||||||
42 to hex("02010005000702fd2900"))
|
42 to hex("02010005000702fd2900"))
|
||||||
val screen = hex("012345601234560112345601234560122345601234560123345601234560123445601234560123455601234f60123456601234560123456001234560123456011234560123456012234560123456012334560123456012344560123456012345")
|
val screen = hex("012345601234560112345601234560122345601234560123345601234560123445601234560123455601234f60123456601234560123456001234560123456011234560123456012234560123456012334560123456012344560123456012345")
|
||||||
val expected = listOf("01234560123456011aaaaaaaaaa56012aa45644444aa0123a4564444456a1234a564f44f564a2345a6444fff644a3456a4444456444a4560aa44456444aa56011aaaaaaaaaa56012234560123456012334560123456012344560123456012345", "012345601234560112aaaaaaaaaa60122aa56444445aa1233a5644444564a2344a644f44f644a3455a4444ff6444a4566a4444564444a5600aa44564444aa60112aaaaaaaaaa6012234560123456012334560123456012344560123456012345")
|
val expected = listOf("01234560123456011aaaaaaaaaa56012aa45644444aa0123a4564444456a1234a564f44f564a2345a6444fff644a3456a4444456444a4560aa44456444aa56011aaaaaaaaaa56012234560123456012334560123456012344560123456012345", "012345601234560112aaaaaaaaaa60122aa56444445aa1233a5644444564a2344a644f44f644a3455a4444ff6444a4566a4444564444a5600aa44564444aa60112aaaaaaaaaa6012234560123456012334560123456012344560123456012345")
|
||||||
@@ -267,4 +267,38 @@ class DisplayListTest {
|
|||||||
assertContentEquals(app,glasses.screen);assertContentEquals(app,glasses.composition)
|
assertContentEquals(app,glasses.screen);assertContentEquals(app,glasses.composition)
|
||||||
assertEquals(196608,ResourceCacheState.CACHE_SIZE)
|
assertEquals(196608,ResourceCacheState.CACHE_SIZE)
|
||||||
}
|
}
|
||||||
|
/** Revision 35. Same calls and expectations as ClipTest in g2flash/tests/test_display_list.py. */
|
||||||
|
@Test fun clipRectsNarrowEveryOpNestThroughListsAndMoveWithDepth() {
|
||||||
|
val font = ByteArray(198); font[0] = 1; font[1 + 33 * 2] = 193.toByte(); hex("000202ffff").copyInto(font, 193)
|
||||||
|
val resources = mutableMapOf(1 to hex("000404ffffffffffffffff"), 3 to font,
|
||||||
|
5 to hex("0202000700" + "0400010000000f" + "0f00" + "04040900000002000200010008000f"),
|
||||||
|
6 to hex("00040200000000"), 7 to hex("0201000e00080106000000040002000000" + "0f10"))
|
||||||
|
fun draw(call: String, right: Boolean = false): DisplayListRenderer.Target {
|
||||||
|
val target = DisplayListRenderer.Target(ByteArray(64) { 0x11 }, 16, 8)
|
||||||
|
DisplayListRenderer(resources, rightLens = right).execute(DrawProtocol.sequence(listOf(hex(call))), target)
|
||||||
|
return target
|
||||||
|
}
|
||||||
|
fun expect(target: DisplayListRenderer.Target, color: Int, inside: (Int, Int) -> Boolean) {
|
||||||
|
for (y in 0 until 8) for (x in 0 until 16) assertEquals(if (inside(x, y)) color else 1, target.get(x, y), "($x, $y)")
|
||||||
|
}
|
||||||
|
expect(draw("040403000200" + "0a000a00" + "0100" + "0201" + "0f"), 15) { x, y -> x in 3..5 && y in 2..4 }
|
||||||
|
expect(draw("0400" + "0100" + "ff020105" + "00" + "0f"), 15) { x, y -> x in 5..8 && y < 4 }
|
||||||
|
expect(draw("0504" + "0100000002000100" + "0300" + "0000" + "0f" + "02" + "4141"), 15) { x, y -> y == 0 && x in 1..2 }
|
||||||
|
expect(draw("0804" + "0400040004000200" + "0000" + "1000" + "0800" + "0000" + "0f10"), 15) { x, y -> x in 4..7 && y in 4..5 }
|
||||||
|
expect(draw("0904" + "fefffeff04000400" + "09"), 9) { x, y -> x < 2 && y < 2 }
|
||||||
|
expect(draw("0904" + "0300050003000100" + "09"), 9) { x, y -> y == 5 && x in 3..5 }
|
||||||
|
expect(draw("0604" + "0100010001000600" + "0000000010000800" + "77".repeat(16)), 7) { x, y -> x == 1 && y in 1..6 }
|
||||||
|
expect(draw("0204" + "0200020001000100" + "0100" + "0000" + "04000400" + "0000"), 15) { x, y -> x == 2 && y == 2 }
|
||||||
|
expect(draw("0104" + "0100010002000100" + "00" + "000001" + "01" + "8f"), 15) { x, y -> y == 1 && x in 1..2 }
|
||||||
|
expect(draw("0704" + "000000000a000300" + "0500"), 15) { x, y -> (x < 4 && y < 3) || (x == 9 && y < 2) }
|
||||||
|
val deep = "0806" + "02" + "0000000004000400" + "0000" + "1000" + "0800" + "0000" + "0f10"
|
||||||
|
expect(draw(deep), 15) { x, y -> x in 1..4 && y < 4 }
|
||||||
|
expect(draw(deep, right = true), 15) { x, y -> x < 3 && y < 4 }
|
||||||
|
// A target override starts unclipped: the whole resource fills, the screen stays.
|
||||||
|
expect(draw("0704" + "0000000001000100" + "0700"), 15) { _, _ -> false }
|
||||||
|
assertContentEquals(hex("000402ffffffff"), resources.getValue(6))
|
||||||
|
expect(draw("0804" + "0400040000000000" + "0000" + "1000" + "0800" + "0000" + "0f10"), 15) { _, _ -> false }
|
||||||
|
// Unknown flag bits, a truncated clip header, and the old s16 image layout all reject.
|
||||||
|
for (bad in listOf("090800", "0904000000000100", "04000100020001000f")) assertFails(bad) { draw(bad) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,15 +5,15 @@ import kotlin.test.*
|
|||||||
class DrawWireTest {
|
class DrawWireTest {
|
||||||
private fun hex(value: String) = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
private fun hex(value: String) = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||||
|
|
||||||
@Test fun encodersUseRevision29CoordinatesAndPreserveOtherWireBytes() {
|
@Test fun encodersUseRevision35CoordinatesAndPreserveOtherWireBytes() {
|
||||||
// Literal vectors pin the firmware grammar independently of the reader.
|
// Literal vectors pin the firmware grammar independently of the reader.
|
||||||
val calls = listOf(
|
val calls = listOf(
|
||||||
DrawProtocol.image(0x1234, -32768, 32767, 0x1f, target = 511, depth = -128) to
|
DrawProtocol.image(0x1234, -32768, 32767, 0x1f, target = 511, depth = -128) to
|
||||||
"0403ff018034120080ff7f1f",
|
"0403ff01803412df8000c07fff1f",
|
||||||
DrawProtocol.rectCopy(DrawProtocol.CURRENT, 1, 2, 3, 4, -5, -6) to
|
DrawProtocol.rectCopy(DrawProtocol.CURRENT, 1, 2, 3, 4, -5, -6) to
|
||||||
"0200feff0102030004007b7a",
|
"0200feff0102030004007b7a",
|
||||||
DrawProtocol.stockText(-1, 2, 15, hex("41c3a9")) to "0300ffff02000f0341c3a9",
|
DrawProtocol.stockText(-1, 2, 15, hex("41c3a9")) to "0300ffff02000f0341c3a9",
|
||||||
DrawProtocol.text(511, -2, 3, 31, hex("01417f")) to "0500ff01feff03001f0301417f",
|
DrawProtocol.text(511, -2, 3, 31, hex("01417f")) to "0500ff017e031f0301417f",
|
||||||
DrawProtocol.playList(511, depth = 127) to "07027fff01",
|
DrawProtocol.playList(511, depth = 127) to "07027fff01",
|
||||||
DrawProtocol.roundedRect(-1, 2, 640, 480, 65535, 15, 16) to
|
DrawProtocol.roundedRect(-1, 2, 640, 480, 65535, 15, 16) to
|
||||||
"08007f028002e001ffff0f10",
|
"08007f028002e001ffff0f10",
|
||||||
@@ -21,6 +21,9 @@ class DrawWireTest {
|
|||||||
DrawProtocol.bbox(hex("ffffffffffffffff"), 4, 0, 0, 8, 2) to "010000000002010f10",
|
DrawProtocol.bbox(hex("ffffffffffffffff"), 4, 0, 0, 8, 2) to "010000000002010f10",
|
||||||
DrawProtocol.bbox(hex("0f"), 1, 1, 0, 1, 1) to "01000101000000010001001f",
|
DrawProtocol.bbox(hex("0f"), 1, 1, 0, 1, 1) to "01000101000000010001001f",
|
||||||
DrawProtocol.clear(15, target = 511) to "0901ff010f",
|
DrawProtocol.clear(15, target = 511) to "0901ff010f",
|
||||||
|
// Revision 35: the clip rect follows target and depth.
|
||||||
|
DrawProtocol.clear(3, target = 511, clip = DrawClip(-1, 2, 3, 4)) to "0905ff01ffff02000300040003",
|
||||||
|
DrawProtocol.image(7, 1, 2, depth = 2, clip = DrawClip(0, 0, 640, 480)) to "040602000000008002e001070001020f",
|
||||||
)
|
)
|
||||||
for ((call, expected) in calls) assertContentEquals(hex(expected), call)
|
for ((call, expected) in calls) assertContentEquals(hex(expected), call)
|
||||||
assertContentEquals(hex("0100050007027fff01"), DrawProtocol.sequence(listOf(calls[4].first)))
|
assertContentEquals(hex("0100050007027fff01"), DrawProtocol.sequence(listOf(calls[4].first)))
|
||||||
@@ -38,8 +41,8 @@ class DrawWireTest {
|
|||||||
|
|
||||||
@Test fun optimizerFieldsAreReencodedAndOpaqueBytesArePreserved() {
|
@Test fun optimizerFieldsAreReencodedAndOpaqueBytesArePreserved() {
|
||||||
val records = listOf(
|
val records = listOf(
|
||||||
"1300020080ff7f1f" to "040000020080ff7f1f",
|
"1300020080ff7f1f" to "04000002df8000c07fff1f",
|
||||||
"14ff01ffff02000f0341017f" to "0500ff01ffff02000f0341017f",
|
"14ff01ffff02000f0341017f" to "0500ff017f020f0341017f",
|
||||||
"0fffff02001f0341c3a9" to "0300ffff02001f0341c3a9",
|
"0fffff02001f0341c3a9" to "0300ffff02001f0341c3a9",
|
||||||
"030001020134120f10" to "010000000102010f10",
|
"030001020134120f10" to "010000000102010f10",
|
||||||
"060f10" to "01000100000000080002000f10",
|
"060f10" to "01000100000000080002000f10",
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ class FrameDisplayListTest {
|
|||||||
private val menu = "077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f"
|
private val menu = "077e0000000300020002000200022a00000096000000010002000200ffffffff0200080000ff24017e30020000000001812c8001812c1611010017328001812c16103001812c3023414031ff24017c30020000000001812c8001812c1611010017328001812c16103001812c302341403102000200010001030400000000000000001f"
|
||||||
private val multi = "0744000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f0200000100000001000100020002feffffff7f00010001007f00"
|
private val multi = "0744000000030002000400010002000000000000000002000200010000ff010001006003000400000000000000001f0200000100000001000100020002feffffff7f00010001007f00"
|
||||||
private val scroll = "078a000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff250100300102300180f0800180f0161101001732800180f01610300180f0302341403101001102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103"
|
private val scroll = "078a000000030002000400020000070000009600000001000200040011223344556677880200020000000000ff250100300102300180f0800180f0161101001732800180f01610300180f0302341403101001102000200010008000000ff280101300100300180f0800180f0161101001732800180f01610300180f030234140310100170100160400020000000103"
|
||||||
|
// Clipped clear, clipped rounded rect, and replayed glyph + icon records with
|
||||||
|
// placeholder atlas ids 0xbeef / 0xcafebabe, plus what they paint over a
|
||||||
|
// nibble-1 16x8 screen (display-list-authoring.test.cjs).
|
||||||
|
private val replay = "0780000000020003000800040000070000006400000000000300890000000000000600040002880000010001000200020000000400030000000510a00000000000000600040000ff2502000080c002000000000180c8800180c8161101001732800180c81610300180c830234031020000efbe4100000000000000ff01bebafeca04000100"
|
||||||
|
private val replayPixels = "11111111111111111111111111111111111111111111111111fff28f111111111125522211111111112552221111111111222222111111111111111111111111"
|
||||||
private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
private fun hex(s: String) = s.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||||
private fun read(bytes: ByteArray, now: Long = 1150): FrameDisplayList {
|
private fun read(bytes: ByteArray, now: Long = 1150): FrameDisplayList {
|
||||||
val reader = ArrayByteReader(bytes)
|
val reader = ArrayByteReader(bytes)
|
||||||
@@ -107,4 +112,38 @@ class FrameDisplayListTest {
|
|||||||
trailing[1] = (trailing[1] + 1).toByte()
|
trailing[1] = (trailing[1] + 1).toByte()
|
||||||
assertFails { read(trailing) }
|
assertFails { read(trailing) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The TS golden's placeholder ids, replaced by ids registered in this process. */
|
||||||
|
private fun registeredReplay(imageKnown: Boolean = true): ByteArray {
|
||||||
|
val key = "stub-font".encodeToByteArray()
|
||||||
|
val glyph = byteArrayOf(key.size.toByte()) + key + byteArrayOf(4, 1, 0, 65, 0, 0, 0, 0, 1, 3, 2) +
|
||||||
|
byteArrayOf(0xa0.toByte(), 0, 0, 0, 0xe0.toByte(), 0, 0, 0)
|
||||||
|
GlyphAtlas.register(ArrayByteReader(glyph))
|
||||||
|
val fontId = GlyphAtlas.fontId("stub-font")
|
||||||
|
val imageId = if (imageKnown) ImageAtlas.ensure("stub-replay-icon", 2, 2,
|
||||||
|
ArrayByteReader(byteArrayOf(255.toByte(), 0, 128.toByte(), 255.toByte()))) else 0x7fffffff
|
||||||
|
fun le(value: Int, bytes: Int) = (0 until bytes).joinToString("") { ((value ushr (8 * it)) and 255).toString(16).padStart(2, '0') }
|
||||||
|
return hex(replay.replace("efbe", le(fontId, 2)).replace("bebafeca", le(imageId, 4)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun replayedDrawsCompileToClippedImageAndTextCallsThatPaintLikeTheSoftwareRenderer() {
|
||||||
|
val list = read(registeredReplay(), 1100)
|
||||||
|
assertEquals(2, list.resources.size, "the icon and a font snapshot")
|
||||||
|
val ids = intArrayOf(1, 2)
|
||||||
|
val calls = list.calls(ids, 1100)
|
||||||
|
assertEquals(listOf(DRAW_OP_CLEAR, DRAW_OP_ROUNDED_RECT, DRAW_OP_IMAGE, DRAW_OP_TEXT), calls.map { it[0].toInt() })
|
||||||
|
assertTrue(calls.all { it[1].toInt() and DRAW_FLAG_CLIP != 0 })
|
||||||
|
val resources = list.resources.withIndex().associate { (i, resource) -> ids[i] to resource.bytes }
|
||||||
|
val screen = ByteArray(64) { 0x11 }
|
||||||
|
val target = DisplayListRenderer.Target(screen, 16, 8)
|
||||||
|
DisplayListRenderer(resources).execute(DrawProtocol.sequence(calls), target)
|
||||||
|
val nibbles = (0 until 128).joinToString("") { target.get(it % 16, it / 16).toString(16) }
|
||||||
|
assertEquals(replayPixels, nibbles)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test fun replayWithAnUnknownRecordDrawsNothing() {
|
||||||
|
val list = read(registeredReplay(imageKnown = false), 1100)
|
||||||
|
assertTrue(list.resources.isEmpty())
|
||||||
|
assertTrue(list.calls(IntArray(0), 1100).isEmpty())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -60,11 +60,12 @@ private fun field(number: Int, text: String): ByteArray = field(number, text.enc
|
|||||||
private fun authSuccess(magic: Int) = BleProtocol.encodeVarintField(1, 4) + BleProtocol.encodeVarintField(2, magic) + field(3, ByteArray(0))
|
private fun authSuccess(magic: Int) = BleProtocol.encodeVarintField(1, 4) + BleProtocol.encodeVarintField(2, magic) + field(3, ByteArray(0))
|
||||||
private fun authPending(magic: Int) = BleProtocol.encodeVarintField(1, 4) + BleProtocol.encodeVarintField(2, magic) + field(3, BleProtocol.encodeVarintField(1, 1))
|
private fun authPending(magic: Int) = BleProtocol.encodeVarintField(1, 4) + BleProtocol.encodeVarintField(2, magic) + field(3, BleProtocol.encodeVarintField(1, 1))
|
||||||
private fun ack(magic: Int) = BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, magic)
|
private fun ack(magic: Int) = BleProtocol.encodeVarintField(1, 1) + BleProtocol.encodeVarintField(2, magic)
|
||||||
private fun settingsAck(magic: Int, battery: Int = -1, left: String = "", right: String = "", extension: String = ""): ByteArray {
|
private fun settingsAck(magic: Int, battery: Int = -1, left: String = "", right: String = "", extension: String = "", silentMode: Int = -1): ByteArray {
|
||||||
var request = ByteArray(0)
|
var request = ByteArray(0)
|
||||||
if (left.isNotEmpty()) request += field(5, left)
|
if (left.isNotEmpty()) request += field(5, left)
|
||||||
if (right.isNotEmpty()) request += field(6, right)
|
if (right.isNotEmpty()) request += field(6, right)
|
||||||
if (battery >= 0) request += BleProtocol.encodeVarintField(12, battery)
|
if (battery >= 0) request += BleProtocol.encodeVarintField(12, battery)
|
||||||
|
if (silentMode >= 0) request += BleProtocol.encodeVarintField(14, silentMode)
|
||||||
var pb = BleProtocol.encodeVarintField(1, 2) + BleProtocol.encodeVarintField(2, magic) + field(4, request)
|
var pb = BleProtocol.encodeVarintField(1, 2) + BleProtocol.encodeVarintField(2, magic) + field(4, request)
|
||||||
if (extension.isNotEmpty()) pb += field(100, extension)
|
if (extension.isNotEmpty()) pb += field(100, extension)
|
||||||
return pb
|
return pb
|
||||||
@@ -205,11 +206,11 @@ class StockFlowsTest {
|
|||||||
override fun onResult(approved: Boolean) { result = approved }
|
override fun onResult(approved: Boolean) { result = approved }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun promptResponder(link: FakeStockLink, selection: Int?, batteries: Map<String, Int>): (FakeStockLink.Written) -> Unit = { w ->
|
private fun promptResponder(link: FakeStockLink, selection: Int?, batteries: Map<String, Int>, silentMode: Int = -1): (FakeStockLink.Written) -> Unit = { w ->
|
||||||
when (w.sid) {
|
when (w.sid) {
|
||||||
BleProtocol.SID_SECURITY_AUTH -> link.notify(w.address, authSuccess(w.magic), w.sid)
|
BleProtocol.SID_SECURITY_AUTH -> link.notify(w.address, authSuccess(w.magic), w.sid)
|
||||||
BleProtocol.PRELUDE_ACK_SID -> link.notify(w.address, ack(BleProtocol.PRELUDE_ACK_MAGIC), w.sid)
|
BleProtocol.PRELUDE_ACK_SID -> link.notify(w.address, ack(BleProtocol.PRELUDE_ACK_MAGIC), w.sid)
|
||||||
BleProtocol.SID_UI_SETTING -> link.notify(w.address, settingsAck(w.magic, batteries[w.address] ?: -1), w.sid)
|
BleProtocol.SID_UI_SETTING -> link.notify(w.address, settingsAck(w.magic, batteries[w.address] ?: -1, silentMode = silentMode), w.sid)
|
||||||
BleProtocol.SID_EVENHUB -> {
|
BleProtocol.SID_EVENHUB -> {
|
||||||
val cmd = BleProtocol.readVarintFieldValue(BleProtocol.stripTrailingCrc(w.pb), 1, -1)
|
val cmd = BleProtocol.readVarintFieldValue(BleProtocol.stripTrailingCrc(w.pb), 1, -1)
|
||||||
link.notify(w.address, ack(w.magic), w.sid)
|
link.notify(w.address, ack(w.magic), w.sid)
|
||||||
@@ -275,6 +276,43 @@ class StockFlowsTest {
|
|||||||
assertEquals("disconnected:Lost connection to the glasses.", events.states.last())
|
assertEquals("disconnected:Lost connection to the glasses.", events.states.last())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun promptRefusesOnlyWhenTheLensReportsSilentMode() {
|
||||||
|
// Silent mode on: refused with the way out, before any page is written.
|
||||||
|
val silentOn = FakeStockLink()
|
||||||
|
silentOn.responder = promptResponder(silentOn, 1, mapOf(R to 85), silentMode = 1)
|
||||||
|
var events = PromptEvents()
|
||||||
|
FlashPromptFlow(silentOn, R, "", "w", false, events, fast, testPlatform()).run()
|
||||||
|
assertEquals(null, events.result)
|
||||||
|
assertEquals("error:${FlashPromptFlow.SILENT_MODE_MESSAGE}", events.states.last())
|
||||||
|
assertTrue(events.logs.any { it == "silent mode before prompt: on" })
|
||||||
|
assertFalse(silentOn.writes.any { it.sid == BleProtocol.SID_EVENHUB })
|
||||||
|
assertTrue(silentOn.closed)
|
||||||
|
|
||||||
|
// Silent mode off: the prompt is shown and answered as usual.
|
||||||
|
val silentOff = FakeStockLink()
|
||||||
|
silentOff.responder = promptResponder(silentOff, 1, mapOf(R to 85), silentMode = 0)
|
||||||
|
events = PromptEvents()
|
||||||
|
FlashPromptFlow(silentOff, R, "", "w", false, events, fast, testPlatform()).run()
|
||||||
|
assertEquals(true, events.result, events.logs.joinToString("\n"))
|
||||||
|
assertTrue(events.logs.any { it == "silent mode before prompt: off" })
|
||||||
|
|
||||||
|
// Firmware whose ack omits the field: unknown is not a refusal.
|
||||||
|
val omitted = FakeStockLink()
|
||||||
|
omitted.responder = promptResponder(omitted, 1, mapOf(R to 85))
|
||||||
|
events = PromptEvents()
|
||||||
|
FlashPromptFlow(omitted, R, "", "w", false, events, fast, testPlatform()).run()
|
||||||
|
assertEquals(true, events.result, events.logs.joinToString("\n"))
|
||||||
|
assertTrue(events.logs.any { it == "silent mode before prompt: unknown (ack omits the field)" })
|
||||||
|
|
||||||
|
// skipPrompt re-checks the battery only; silent mode does not block it.
|
||||||
|
val skipped = FakeStockLink()
|
||||||
|
skipped.responder = promptResponder(skipped, null, mapOf(R to 85), silentMode = 1)
|
||||||
|
events = PromptEvents()
|
||||||
|
FlashPromptFlow(skipped, R, "", "w", true, events, fast, testPlatform()).run()
|
||||||
|
assertEquals(true, events.result)
|
||||||
|
}
|
||||||
|
|
||||||
// ---- OTA ---------------------------------------------------------------
|
// ---- OTA ---------------------------------------------------------------
|
||||||
|
|
||||||
private fun putU32(buf: ByteArray, offset: Int, value: Long) { for (i in 0 until 4) buf[offset + i] = ((value ushr (8 * i)) and 0xff).toByte() }
|
private fun putU32(buf: ByteArray, offset: Int, value: Long) { for (i in 0 until 4) buf[offset + i] = ((value ushr (8 * i)) and 0xff).toByte() }
|
||||||
|
|||||||
@@ -112,3 +112,21 @@ test('unselected sidebar icons retain -2 depth through shell cropping, including
|
|||||||
state.selectedIndex=1;const next=new graphics.GrayImage(640,480);chrome.drawSidebar(next,state);
|
state.selectedIndex=1;const next=new graphics.GrayImage(640,480);chrome.drawSidebar(next,state);
|
||||||
assert.equal(next.draws.filter(d=>d.presentation).length,2);
|
assert.equal(next.draws.filter(d=>d.presentation).length,2);
|
||||||
});
|
});
|
||||||
|
test('shell modal carries its inner menu highlight animation instead of baking its first frame',async()=>{
|
||||||
|
const {ShellModalLayer}=load('app/ui/shell/modal-layer.ts',{
|
||||||
|
'../../graphics/image':graphics,'../../graphics/plane':planes,'../gestures':{},'../layers':load('app/ui/layers.ts',{
|
||||||
|
'../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()},
|
||||||
|
'./gestures':{isDirectionalInput:()=>false},
|
||||||
|
}),
|
||||||
|
'./geometry':{appViewportSize:()=>({width:120,height:110}),appViewportRect:()=>({x:10,y:20,width:120,height:110}),SHELL_OPAQUE_BLACK:1},
|
||||||
|
});
|
||||||
|
const modal=new ShellModalLayer(menu().layer,noopLayerActions),paint=()=>modal.paint({},()=>new graphics.GrayImage(200,200));
|
||||||
|
const bare=menu().paint().draws.find(d=>d.presentation),before=paint().draws.find(d=>d.presentation);
|
||||||
|
assert.equal(before.x,bare.x+28);assert.equal(before.y,bare.y+38); // translated into the box interior
|
||||||
|
await modal.handleInput({type:'scroll-down'},{});
|
||||||
|
const image=paint(),row=image.draws.find(d=>d.presentation);
|
||||||
|
assert.ok(row.y>before.y);assert.ok(row.presentation.displayList.timeline,'the slide stays a timed display list');
|
||||||
|
assert.ok(!image.withDrawsBaked(false).pixels.some(v=>v===255),'selected text is not baked into the modal surface');
|
||||||
|
const c=new SurfaceCompositor(200,200);c.setShellScene(encodeShellScene([{image,x:0,y:0,shellKey:9}]));
|
||||||
|
assert.ok(c.composite().some(v=>v===240));
|
||||||
|
});
|
||||||
+3
-1
@@ -27,6 +27,7 @@
|
|||||||
"../app/ui/metrics.ts",
|
"../app/ui/metrics.ts",
|
||||||
"../app/ui/menu-core.ts",
|
"../app/ui/menu-core.ts",
|
||||||
"../app/phone-ui/phone-gestures.ts",
|
"../app/phone-ui/phone-gestures.ts",
|
||||||
|
"../app/native/java-direct-buffer.ts",
|
||||||
"../app/g2/firmware-compat.ts",
|
"../app/g2/firmware-compat.ts",
|
||||||
"../app/g2/glasses-hardware-identity.ts",
|
"../app/g2/glasses-hardware-identity.ts",
|
||||||
"../app/g2/ble-proximity.ts",
|
"../app/g2/ble-proximity.ts",
|
||||||
@@ -47,6 +48,7 @@
|
|||||||
"../app/apps/timer/timer-model.ts",
|
"../app/apps/timer/timer-model.ts",
|
||||||
"../app/apps/teleprompter/script-tracker.ts",
|
"../app/apps/teleprompter/script-tracker.ts",
|
||||||
"../app/apps/nightscout/nightscout-alerts.ts",
|
"../app/apps/nightscout/nightscout-alerts.ts",
|
||||||
"../app/g2/brightness-curve.ts"
|
"../app/g2/brightness-curve.ts",
|
||||||
|
"../app/g2/events.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user