forked from Blendman974/faceclaw
Performance optimizations; add TerminusV variable-width font
This commit is contained in:
1 parent
ff447d5161
commit
b2c90bc043
16 files changed
+4267
-217
No files matched your search
@@ -7,3 +7,8 @@ and the sherpa-onnx KWS Zipformer GigaSpeech model published by the k2-fsa/sherp
|
|||||||
community.
|
community.
|
||||||
|
|
||||||
G2 microphone LC3 decoding uses Google's liblc3: https://github.com/google/liblc3
|
G2 microphone LC3 decoding uses Google's liblc3: https://github.com/google/liblc3
|
||||||
|
|
||||||
|
The optional TerminusV proportional font is by ohnonot, derived from Dimitar
|
||||||
|
Zhekov's Terminus: https://framagit.org/ohnonot/terv-terc
|
||||||
|
It is distributed under the SIL Open Font License; see
|
||||||
|
app/fonts/terminusv/LICENSE.
|
||||||
@@ -1004,7 +1004,14 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
enqueueFirmwareDebugFlagsLocked();
|
enqueueFirmwareDebugFlagsLocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (messageToPrewrite == null && handleHeartbeat()) {
|
// A frame ready to send right now: don't inject a fresh
|
||||||
|
// heartbeat in front of it (the image's own ack resets the
|
||||||
|
// firmware heartbeat timer, so the heartbeat is redundant).
|
||||||
|
boolean imageWaiting = !shutdownRequested && fixedLayoutCreated && warmedUp
|
||||||
|
&& pendingMessages.isEmpty() && inFlightMessages.isEmpty()
|
||||||
|
&& now >= imageRetryAfterMs
|
||||||
|
&& !getDesiredFingerprint().equals(displayedFingerprint);
|
||||||
|
if (messageToPrewrite == null && handleHeartbeat(imageWaiting)) {
|
||||||
return ConnectionOptions.IDLE_SLEEP_MS;
|
return ConnectionOptions.IDLE_SLEEP_MS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1086,7 +1093,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
return message.message.length + 2 > 232;
|
return message.message.length + 2 > 232;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleHeartbeat() {
|
private boolean handleHeartbeat(boolean imageWaiting) {
|
||||||
long now = SystemClock.elapsedRealtime();
|
long now = SystemClock.elapsedRealtime();
|
||||||
boolean heartbeatEligible = !shutdownRequested && warmedUp && fixedLayoutCreated;
|
boolean heartbeatEligible = !shutdownRequested && warmedUp && fixedLayoutCreated;
|
||||||
boolean heartbeatPending = heartbeatEligible && hasPendingOrInflightKindLocked("heartbeat");
|
boolean heartbeatPending = heartbeatEligible && hasPendingOrInflightKindLocked("heartbeat");
|
||||||
@@ -1096,6 +1103,14 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
boolean heartbeatBlocksLeftWrites = heartbeatReady || heartbeatPending;
|
boolean heartbeatBlocksLeftWrites = heartbeatReady || heartbeatPending;
|
||||||
|
|
||||||
if (heartbeatReady && !heartbeatPending && inFlightMessages.isEmpty()) {
|
if (heartbeatReady && !heartbeatPending && inFlightMessages.isEmpty()) {
|
||||||
|
if (imageWaiting && !heartbeatUrgent) {
|
||||||
|
// Defer to the waiting frame: sending it now satisfies the
|
||||||
|
// firmware heartbeat deadline (its ack resets the timer), and
|
||||||
|
// the heartbeat still fires once we reach the URGENT threshold
|
||||||
|
// if rendering goes quiet again. Preserves the pending-heartbeat
|
||||||
|
// inter-lens-sync invariant below (that path is untouched).
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Log.i(TAG, "Writing heartbeat");
|
Log.i(TAG, "Writing heartbeat");
|
||||||
OutboundMessage heartbeatMessage = createHeartbeatMessage();
|
OutboundMessage heartbeatMessage = createHeartbeatMessage();
|
||||||
lastHeartbeatSentAtMs = now;
|
lastHeartbeatSentAtMs = now;
|
||||||
@@ -1479,9 +1494,11 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
// known-displayed; displayedBmp is cleared on connect/reset/timeout
|
// known-displayed; displayedBmp is cleared on connect/reset/timeout
|
||||||
// paths, so a non-empty value means display state is trusted.
|
// paths, so a non-empty value means display state is trusted.
|
||||||
byte[] incrementalPayload = null;
|
byte[] incrementalPayload = null;
|
||||||
|
BleImageOptimizer.IncrementalPlan incrementalPlan = null;
|
||||||
if (connectionOptions.INCREMENTAL_FRAMES && displayedBmp.length > 0) {
|
if (connectionOptions.INCREMENTAL_FRAMES && displayedBmp.length > 0) {
|
||||||
incrementalPayload = BleImageOptimizer.buildIncrementalImagePayload(displayedBmp, bmp, nextImageFrameId);
|
incrementalPlan = BleImageOptimizer.buildIncrementalImagePayload(displayedBmp, bmp, nextImageFrameId);
|
||||||
if (incrementalPayload != null) {
|
if (incrementalPlan != null) {
|
||||||
|
incrementalPayload = incrementalPlan.payload;
|
||||||
// advance only when a delta is actually emitted, so consecutive
|
// advance only when a delta is actually emitted, so consecutive
|
||||||
// deltas carry consecutive ids (CFW skip/reorder detection)
|
// deltas carry consecutive ids (CFW skip/reorder detection)
|
||||||
nextImageFrameId = nextImageFrameId >= 0xfffe ? 1 : nextImageFrameId + 1;
|
nextImageFrameId = nextImageFrameId >= 0xfffe ? 1 : nextImageFrameId + 1;
|
||||||
@@ -1493,9 +1510,15 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
|||||||
plan.fragments = BleImageOptimizer.planImageFragments(plan.payload, ConnectionOptions.IMAGE_FRAGMENT_SIZE);
|
plan.fragments = BleImageOptimizer.planImageFragments(plan.payload, ConnectionOptions.IMAGE_FRAGMENT_SIZE);
|
||||||
FrameTimings.getInstance().spanEnd(frameId, "compress-and-plan");
|
FrameTimings.getInstance().spanEnd(frameId, "compress-and-plan");
|
||||||
if (incrementalPayload != null) {
|
if (incrementalPayload != null) {
|
||||||
|
// changed/box are packed-byte counts (2px each); clusters>1 with
|
||||||
|
// changed<<box means distant small edits merged into an oversized
|
||||||
|
// box (see BleImageOptimizer.IncrementalPlan) — the prime suspect
|
||||||
|
// for a delta spilling into a second, serialized BLE message.
|
||||||
FrameTimings.getInstance().log(frameId, "incremental update bbox="
|
FrameTimings.getInstance().log(frameId, "incremental update bbox="
|
||||||
+ ((incrementalPayload[3] & 0xff) * 4) + "x" + ((incrementalPayload[4] & 0xff) * 2)
|
+ ((incrementalPayload[3] & 0xff) * 4) + "x" + ((incrementalPayload[4] & 0xff) * 2)
|
||||||
+ "+" + ((incrementalPayload[1] & 0xff) * 4) + "+" + ((incrementalPayload[2] & 0xff) * 2));
|
+ "+" + ((incrementalPayload[1] & 0xff) * 4) + "+" + ((incrementalPayload[2] & 0xff) * 2)
|
||||||
|
+ " changed=" + incrementalPlan.changedBytes + "/" + incrementalPlan.boxBytes + "B"
|
||||||
|
+ " clusters=" + incrementalPlan.clusterCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
int updateId = nextImageUpdateId++;
|
int updateId = nextImageUpdateId++;
|
||||||
|
|||||||
+41
-12
@@ -115,7 +115,29 @@ public final class BleImageOptimizer {
|
|||||||
* skipped or duplicated deltas (its diagnostic overlay); the caller advances
|
* skipped or duplicated deltas (its diagnostic overlay); the caller advances
|
||||||
* it by 1 per emitted delta so consecutive deltas are consecutive.
|
* it by 1 per emitted delta so consecutive deltas are consecutive.
|
||||||
*/
|
*/
|
||||||
public static byte[] buildIncrementalImagePayload(byte[] previousBmp, byte[] newBmp, int frameId) {
|
/**
|
||||||
|
* A mode-3 incremental payload plus diagnostics about how tightly the
|
||||||
|
* bounding box fit the actual change. {@code changedBytes} is how many
|
||||||
|
* packed bytes actually differ; {@code boxBytes} is how many the box sends.
|
||||||
|
* A large box with few changed bytes / multiple clusters means distant
|
||||||
|
* small edits were merged into one oversized box (which can spill past the
|
||||||
|
* fragment size into an extra serialized BLE message).
|
||||||
|
*/
|
||||||
|
public static final class IncrementalPlan {
|
||||||
|
public final byte[] payload;
|
||||||
|
public final int changedBytes;
|
||||||
|
public final int boxBytes;
|
||||||
|
public final int clusterCount;
|
||||||
|
|
||||||
|
IncrementalPlan(byte[] payload, int changedBytes, int boxBytes, int clusterCount) {
|
||||||
|
this.payload = payload;
|
||||||
|
this.changedBytes = changedBytes;
|
||||||
|
this.boxBytes = boxBytes;
|
||||||
|
this.clusterCount = clusterCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IncrementalPlan buildIncrementalImagePayload(byte[] previousBmp, byte[] newBmp, int frameId) {
|
||||||
int width = BmpUtil.readBmpWidth(newBmp);
|
int width = BmpUtil.readBmpWidth(newBmp);
|
||||||
int height = BmpUtil.readBmpHeight(newBmp);
|
int height = BmpUtil.readBmpHeight(newBmp);
|
||||||
if (width <= 0 || height <= 0
|
if (width <= 0 || height <= 0
|
||||||
@@ -130,34 +152,41 @@ public final class BleImageOptimizer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changed bounding box in packed-byte coordinates (1 byte = 2 pixels).
|
// Full diff scan in packed-byte coordinates (1 byte = 2 pixels): the
|
||||||
|
// changed bounding box plus diagnostics (total changed bytes, and how
|
||||||
|
// many disjoint horizontal column-clusters the change splits into).
|
||||||
int minByteX = stride;
|
int minByteX = stride;
|
||||||
int maxByteX = -1;
|
int maxByteX = -1;
|
||||||
int minY = height;
|
int minY = height;
|
||||||
int maxY = -1;
|
int maxY = -1;
|
||||||
|
int changedBytes = 0;
|
||||||
|
boolean[] columnChanged = new boolean[stride];
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
int rowOffset = y * stride;
|
int rowOffset = y * stride;
|
||||||
for (int x = 0; x < stride; x++) {
|
for (int x = 0; x < stride; x++) {
|
||||||
if (previous[rowOffset + x] != next[rowOffset + x]) {
|
if (previous[rowOffset + x] != next[rowOffset + x]) {
|
||||||
|
changedBytes++;
|
||||||
|
columnChanged[x] = true;
|
||||||
if (x < minByteX) minByteX = x;
|
if (x < minByteX) minByteX = x;
|
||||||
if (x > maxByteX) maxByteX = x;
|
if (x > maxByteX) maxByteX = x;
|
||||||
if (y < minY) minY = y;
|
if (y < minY) minY = y;
|
||||||
maxY = y;
|
maxY = y;
|
||||||
// The rest of the row only matters for maxByteX; scan from
|
|
||||||
// the right end to finish this row quickly.
|
|
||||||
for (int rx = stride - 1; rx > maxByteX; rx--) {
|
|
||||||
if (previous[rowOffset + rx] != next[rowOffset + rx]) {
|
|
||||||
maxByteX = rx;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (maxY < 0) {
|
if (maxY < 0) {
|
||||||
return null; // identical
|
return null; // identical
|
||||||
}
|
}
|
||||||
|
int clusterCount = 0;
|
||||||
|
boolean inCluster = false;
|
||||||
|
for (int x = minByteX; x <= maxByteX; x++) {
|
||||||
|
if (columnChanged[x]) {
|
||||||
|
if (!inCluster) clusterCount++;
|
||||||
|
inCluster = true;
|
||||||
|
} else {
|
||||||
|
inCluster = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pixel-space box, aligned: left/width to multiples of 4, top/height to
|
// Pixel-space box, aligned: left/width to multiples of 4, top/height to
|
||||||
// multiples of 2, clamped to the frame.
|
// multiples of 2, clamped to the frame.
|
||||||
@@ -186,7 +215,7 @@ public final class BleImageOptimizer {
|
|||||||
out[5] = (byte) (frameId & 0xff); // fid_lo
|
out[5] = (byte) (frameId & 0xff); // fid_lo
|
||||||
out[6] = (byte) ((frameId >> 8) & 0xff); // fid_hi
|
out[6] = (byte) ((frameId >> 8) & 0xff); // fid_hi
|
||||||
System.arraycopy(compressed, 0, out, 7, compressed.length);
|
System.arraycopy(compressed, 0, out, 7, compressed.length);
|
||||||
return out;
|
return new IncrementalPlan(out, changedBytes, region.length, clusterCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ public class ConnectionOptions {
|
|||||||
|
|
||||||
final boolean sendImagesToLeft = true;
|
final boolean sendImagesToLeft = true;
|
||||||
final boolean skipSessionIds = true;
|
final boolean skipSessionIds = true;
|
||||||
final int WINDOW_SIZE = 1;
|
final int WINDOW_SIZE = 2;
|
||||||
// Send changed-region (mode 3 bounding box) updates instead of full frames
|
// Send changed-region (mode 3 bounding box) updates instead of full frames
|
||||||
// when the previous frame is known to be displayed. Requires firmware with
|
// when the previous frame is known to be displayed. Requires firmware with
|
||||||
// the experimental bbox-incremental mode. Disabled: the firmware-side
|
// the experimental bbox-incremental mode. Disabled: the firmware-side
|
||||||
|
|||||||
@@ -10,11 +10,19 @@ final class InterruptibleSleep {
|
|||||||
long delayMs = Math.max(1, ms);
|
long delayMs = Math.max(1, ms);
|
||||||
long deadline = SystemClock.elapsedRealtime() + delayMs;
|
long deadline = SystemClock.elapsedRealtime() + delayMs;
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
interrupted = false;
|
// Consume (do not clear-and-ignore) an interrupt delivered before this
|
||||||
while (!interrupted) {
|
// sleep began. interrupt() runs on other threads with no lock held by
|
||||||
|
// the sleeper between driveSession() returning and sleep() starting, so
|
||||||
|
// clearing the flag at entry lost that wake and forced the worker to
|
||||||
|
// sleep the full interval — up to 250ms per idle frame. Honoring it
|
||||||
|
// costs at most one extra (cheap) driveSession pass.
|
||||||
|
if (interrupted) {
|
||||||
|
interrupted = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
long remaining = deadline - SystemClock.elapsedRealtime();
|
long remaining = deadline - SystemClock.elapsedRealtime();
|
||||||
if (remaining <= 0) {
|
if (remaining <= 0) {
|
||||||
interrupted = false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -23,9 +31,11 @@ final class InterruptibleSleep {
|
|||||||
interrupted = false;
|
interrupted = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (interrupted) {
|
||||||
|
interrupted = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
interrupted = false;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
SIL OPEN FONT LICENSE
|
||||||
|
|
||||||
|
Version 1.1 - 26 February 2007
|
||||||
|
|
||||||
|
PREAMBLE
|
||||||
|
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||||
|
development of collaborative font projects, to support the font creation
|
||||||
|
efforts of academic and linguistic communities, and to provide a free and
|
||||||
|
open framework in which fonts may be shared and improved in partnership
|
||||||
|
with others.
|
||||||
|
|
||||||
|
The OFL allows the licensed fonts to be used, studied, modified and
|
||||||
|
redistributed freely as long as they are not sold by themselves. The
|
||||||
|
fonts, including any derivative works, can be bundled, embedded,
|
||||||
|
redistributed and/or sold with any software provided that any reserved
|
||||||
|
names are not used by derivative works. The fonts and derivatives,
|
||||||
|
however, cannot be released under any other type of license. The
|
||||||
|
requirement for fonts to remain under this license does not apply
|
||||||
|
to any document created using the fonts or their derivatives.
|
||||||
|
|
||||||
|
DEFINITIONS
|
||||||
|
"Font Software" refers to the set of files released by the Copyright
|
||||||
|
Holder(s) under this license and clearly marked as such. This may
|
||||||
|
include source files, build scripts and documentation.
|
||||||
|
|
||||||
|
"Reserved Font Name" refers to any names specified as such after the
|
||||||
|
copyright statement(s).
|
||||||
|
|
||||||
|
"Original Version" refers to the collection of Font Software components as
|
||||||
|
distributed by the Copyright Holder(s).
|
||||||
|
|
||||||
|
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||||
|
or substituting — in part or in whole — any of the components of the
|
||||||
|
Original Version, by changing formats or by porting the Font Software to a
|
||||||
|
new environment.
|
||||||
|
|
||||||
|
"Author" refers to any designer, engineer, programmer, technical
|
||||||
|
writer or other person who contributed to the Font Software.
|
||||||
|
|
||||||
|
PERMISSION & CONDITIONS
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||||
|
redistribute, and sell modified and unmodified copies of the Font
|
||||||
|
Software, subject to the following conditions:
|
||||||
|
|
||||||
|
1) Neither the Font Software nor any of its individual components,
|
||||||
|
in Original or Modified Versions, may be sold by itself.
|
||||||
|
|
||||||
|
2) Original or Modified Versions of the Font Software may be bundled,
|
||||||
|
redistributed and/or sold with any software, provided that each copy
|
||||||
|
contains the above copyright notice and this license. These can be
|
||||||
|
included either as stand-alone text files, human-readable headers or
|
||||||
|
in the appropriate machine-readable metadata fields within text or
|
||||||
|
binary files as long as those fields can be easily viewed by the user.
|
||||||
|
|
||||||
|
3) No Modified Version of the Font Software may use the Reserved Font
|
||||||
|
Name(s) unless explicit written permission is granted by the corresponding
|
||||||
|
Copyright Holder. This restriction only applies to the primary font name as
|
||||||
|
presented to the users.
|
||||||
|
|
||||||
|
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||||
|
Software shall not be used to promote, endorse or advertise any
|
||||||
|
Modified Version, except to acknowledge the contribution(s) of the
|
||||||
|
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
5) The Font Software, modified or unmodified, in part or in whole,
|
||||||
|
must be distributed entirely under this license, and must not be
|
||||||
|
distributed under any other license. The requirement for fonts to
|
||||||
|
remain under this license does not apply to any document created
|
||||||
|
using the Font Software.
|
||||||
|
|
||||||
|
TERMINATION
|
||||||
|
This license becomes null and void if any of the above conditions are
|
||||||
|
not met.
|
||||||
|
|
||||||
|
DISCLAIMER
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||||
|
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||||
|
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||||
|
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||||
|
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# TerminusV (Variable Width) & TerminusC (Fixed Width Condensed)
|
||||||
|
|
||||||
|
Two Bitmap Fonts, based on the original Terminus font.
|
||||||
|
|
||||||
|
Only glyphs for iso8859-1 (a.k.a. Western or Latin-1) are implemented, and only two rather small sizes (9 and 12 pixel).
|
||||||
|
|
||||||
|
Published under the [Open Font License][1].
|
||||||
|
|
||||||
|
Thanks go to Dimitar Zhekov for creating the original Terminus font,
|
||||||
|
explaining what an Open Font License is and not minding me messing around with his work
|
||||||
|
or having the original font name in its name.
|
||||||
|
|
||||||
|
Comparison to the regular Terminus font:
|
||||||
|
![Screenshot][2]
|
||||||
|
|
||||||
|
## PCF fonts
|
||||||
|
|
||||||
|
### Manual Installation
|
||||||
|
|
||||||
|
Copy all files inside `pcf` to an _existing_ folder that is in Xorg's font path, usually `/usr/share/fonts/misc` or `/usr/share/fonts/local`, but you could also have added a folder under your `$HOME`, e.g. `xset fp+ ~/.local/share/fonts/terv-terc`.
|
||||||
|
|
||||||
|
Open a terminal in the folder you just copied the files into and enter:
|
||||||
|
|
||||||
|
mkfontdir
|
||||||
|
fc-cache -f
|
||||||
|
xset fp rehash
|
||||||
|
|
||||||
|
This should be enough for the Xserver's database, but other graphical applications
|
||||||
|
may not see the fonts until you log out/in.
|
||||||
|
|
||||||
|
### Automatic installation
|
||||||
|
|
||||||
|
Run the script `install_pcf.sh`, it will go through the same steps described above
|
||||||
|
and install the fonts to existing system directories.
|
||||||
|
It relies on `sudo`.
|
||||||
|
|
||||||
|
## OTB fonts
|
||||||
|
|
||||||
|
It should be enough to copy the `otb` folder to one of the standard fontconfig locations, e.g. `~/.local/share/fonts/` or `/usr/share/fonts/`.
|
||||||
|
|
||||||
|
You might need to run `fc-cache -f` afterwards.
|
||||||
|
|
||||||
|
## Other Information
|
||||||
|
|
||||||
|
If you haven't been using PCF or BDF bitfonts/pixelfonts on your desktop until now, [here's what you need to do first](https://iamfuss.deviantart.com/journal/How-to-install-artwiz-pixel-fonts-in-Ubuntu-226000883).
|
||||||
|
|
||||||
|
Additionally, you might want to
|
||||||
|
|
||||||
|
- disable bitmap font scaling (because it's ugly) by deleting `*-scale-bitmap-fonts.conf` from `/etc/fonts/conf.d`
|
||||||
|
- disable creation of artificial italic/bold fonts by deleting `*-synthetic.conf` from `/etc/fonts/conf.d`
|
||||||
|
|
||||||
|
Forum thread:
|
||||||
|
https://bbs.archlinux.org/viewtopic.php?id=173065
|
||||||
|
|
||||||
|
[1]: https://scripts.sil.org/OFL
|
||||||
|
[2]: https://dt.iki.fi/stuff/blog/terv-compare.png
|
||||||
File diff suppressed because it is too large.
Load diff
+95
-22
@@ -1,4 +1,5 @@
|
|||||||
import { knownFolders } from "@nativescript/core";
|
import { knownFolders } from "@nativescript/core";
|
||||||
|
import { getStringSetting, onSettingsStoreChanged } from "~/native/settings-store";
|
||||||
|
|
||||||
export type Glyph = {
|
export type Glyph = {
|
||||||
encoding: number;
|
encoding: number;
|
||||||
@@ -15,6 +16,14 @@ export class BdfFont {
|
|||||||
readonly descent: number;
|
readonly descent: number;
|
||||||
readonly lineHeight: number;
|
readonly lineHeight: number;
|
||||||
readonly defaultChar: number;
|
readonly defaultChar: number;
|
||||||
|
/**
|
||||||
|
* Font consulted for code points this font has no glyph for. Used so a
|
||||||
|
* partial-coverage face (e.g. TerminusV, which only ships ISO-8859-1) can
|
||||||
|
* borrow glyphs from a full-coverage face of the same pixel height. The
|
||||||
|
* fallback's glyphs are drawn with *this* font's ascent, so the two must
|
||||||
|
* share a baseline (ascent/descent) for the result to line up.
|
||||||
|
*/
|
||||||
|
private readonly fallback?: BdfFont;
|
||||||
private readonly glyphs: Map<number, Glyph>;
|
private readonly glyphs: Map<number, Glyph>;
|
||||||
|
|
||||||
constructor(opts: {
|
constructor(opts: {
|
||||||
@@ -22,15 +31,18 @@ export class BdfFont {
|
|||||||
descent: number;
|
descent: number;
|
||||||
defaultChar: number;
|
defaultChar: number;
|
||||||
glyphs: Map<number, Glyph>;
|
glyphs: Map<number, Glyph>;
|
||||||
|
fallback?: BdfFont;
|
||||||
}) {
|
}) {
|
||||||
this.ascent = opts.ascent;
|
this.ascent = opts.ascent;
|
||||||
this.descent = opts.descent;
|
this.descent = opts.descent;
|
||||||
this.lineHeight = opts.ascent + opts.descent;
|
this.lineHeight = opts.ascent + opts.descent;
|
||||||
this.defaultChar = opts.defaultChar;
|
this.defaultChar = opts.defaultChar;
|
||||||
this.glyphs = opts.glyphs;
|
this.glyphs = opts.glyphs;
|
||||||
|
this.fallback = opts.fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
static parse(source: string): BdfFont {
|
static parse(source: string, opts: { fallback?: BdfFont; minEncoding?: number } = {}): BdfFont {
|
||||||
|
const minEncoding = opts.minEncoding ?? 0;
|
||||||
const lines = source.replace(/\r/g, "").split("\n");
|
const lines = source.replace(/\r/g, "").split("\n");
|
||||||
let ascent = 10;
|
let ascent = 10;
|
||||||
let descent = 2;
|
let descent = 2;
|
||||||
@@ -92,7 +104,7 @@ export class BdfFont {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (inner === "ENDCHAR") {
|
if (inner === "ENDCHAR") {
|
||||||
if (encoding >= 0) {
|
if (encoding >= minEncoding) {
|
||||||
glyphs.set(encoding, {
|
glyphs.set(encoding, {
|
||||||
encoding,
|
encoding,
|
||||||
dwidthX: dwidthX || bbxWidth,
|
dwidthX: dwidthX || bbxWidth,
|
||||||
@@ -108,15 +120,25 @@ export class BdfFont {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BdfFont({ ascent, descent, defaultChar, glyphs });
|
return new BdfFont({ ascent, descent, defaultChar, glyphs, fallback: opts.fallback });
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Exact lookup for a single code point, with no default-char substitution. */
|
||||||
|
private getExactGlyph(codePoint: number): Glyph | undefined {
|
||||||
|
return this.glyphs.get(codePoint) ?? this.fallback?.getExactGlyph(codePoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
getGlyph(codePoint: number): Glyph | undefined {
|
getGlyph(codePoint: number): Glyph | undefined {
|
||||||
return this.glyphs.get(codePoint) ?? this.glyphs.get(this.defaultChar) ?? this.glyphs.get(63);
|
return (
|
||||||
|
this.getExactGlyph(codePoint) ??
|
||||||
|
this.glyphs.get(this.defaultChar) ??
|
||||||
|
this.glyphs.get(63) ??
|
||||||
|
this.fallback?.getGlyph(codePoint)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasGlyph(codePoint: number): boolean {
|
hasGlyph(codePoint: number): boolean {
|
||||||
return this.glyphs.has(codePoint);
|
return this.glyphs.has(codePoint) || (this.fallback?.hasGlyph(codePoint) ?? false);
|
||||||
}
|
}
|
||||||
|
|
||||||
measureText(text: string): number {
|
measureText(text: string): number {
|
||||||
@@ -128,34 +150,85 @@ export class BdfFont {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cachedEmbeddedFonts = new Map<string, BdfFont>();
|
|
||||||
|
|
||||||
function loadEmbeddedFont(path: string): BdfFont {
|
|
||||||
const cached = cachedEmbeddedFonts.get(path);
|
|
||||||
if (cached) {
|
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
const file = knownFolders.currentApp().getFile(path);
|
|
||||||
const text = file.readTextSync();
|
|
||||||
const font = BdfFont.parse(text);
|
|
||||||
cachedEmbeddedFonts.set(path, font);
|
|
||||||
return font;
|
|
||||||
}
|
|
||||||
|
|
||||||
const embeddedFonts = {
|
const embeddedFonts = {
|
||||||
"terminus12": "fonts/terminus/ter-u12n.bdf",
|
"terminus12": "fonts/terminus/ter-u12n.bdf",
|
||||||
"terminus16": "fonts/terminus/ter-u16n.bdf",
|
"terminus16": "fonts/terminus/ter-u16n.bdf",
|
||||||
"terminus24": "fonts/terminus/ter-u24n.bdf",
|
"terminus24": "fonts/terminus/ter-u24n.bdf",
|
||||||
"terminus32": "fonts/terminus/ter-u32n.bdf",
|
"terminus32": "fonts/terminus/ter-u32n.bdf",
|
||||||
}
|
// TerminusV is a proportional (variable-width) Terminus derivative that only
|
||||||
|
// covers ISO-8859-1. At 12px it shares Terminus's baseline, so we fall back
|
||||||
|
// to Terminus 12 for any code point outside Latin-1. minEncoding 32 drops
|
||||||
|
// TerminusV's private low-encoding drawing glyphs so control code points fall
|
||||||
|
// through to Terminus too.
|
||||||
|
"terminusv12": "fonts/terminusv/terv12n.bdf",
|
||||||
|
} as const;
|
||||||
type EmbeddedFontName = keyof typeof embeddedFonts;
|
type EmbeddedFontName = keyof typeof embeddedFonts;
|
||||||
|
|
||||||
|
const fontFallbacks: Partial<Record<EmbeddedFontName, EmbeddedFontName>> = {
|
||||||
|
terminusv12: "terminus12",
|
||||||
|
};
|
||||||
|
const fontMinEncoding: Partial<Record<EmbeddedFontName, number>> = {
|
||||||
|
terminusv12: 32,
|
||||||
|
};
|
||||||
|
|
||||||
|
const cachedEmbeddedFonts = new Map<EmbeddedFontName, BdfFont>();
|
||||||
|
|
||||||
|
function loadEmbeddedFont(name: EmbeddedFontName): BdfFont {
|
||||||
|
const cached = cachedEmbeddedFonts.get(name);
|
||||||
|
if (cached) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
const file = knownFolders.currentApp().getFile(embeddedFonts[name]);
|
||||||
|
const text = file.readTextSync();
|
||||||
|
const fallbackName = fontFallbacks[name];
|
||||||
|
const font = BdfFont.parse(text, {
|
||||||
|
fallback: fallbackName ? loadEmbeddedFont(fallbackName) : undefined,
|
||||||
|
minEncoding: fontMinEncoding[name],
|
||||||
|
});
|
||||||
|
cachedEmbeddedFonts.set(name, font);
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
export function getFont(font: EmbeddedFontName): BdfFont {
|
export function getFont(font: EmbeddedFontName): BdfFont {
|
||||||
return loadEmbeddedFont(embeddedFonts[font]);
|
return loadEmbeddedFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
|
// User-selectable UI typeface. Only the small (12px) font has an alternative,
|
||||||
|
// since TerminusV ships no larger sizes; medium/large stay Terminus. The
|
||||||
|
// storage key and values are re-used by the settings UI in dashboard-settings.
|
||||||
|
export const UI_FONT_SETTING_KEY = "display.uiFont";
|
||||||
|
export const UI_FONT_VALUES = ["terminus", "terminusv"] as const;
|
||||||
|
export type UiFontChoice = (typeof UI_FONT_VALUES)[number];
|
||||||
|
|
||||||
|
const SMALL_FONT_FOR_CHOICE: Record<UiFontChoice, EmbeddedFontName> = {
|
||||||
|
terminus: "terminus12",
|
||||||
|
terminusv: "terminusv12",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Reading the setting hits a JNI bridge, and getDefaultSmallFont() is called
|
||||||
|
// once per menu item per paint, so cache the resolved choice and invalidate it
|
||||||
|
// when the setting changes (in any isolate).
|
||||||
|
let cachedSmallFontChoice: UiFontChoice | null = null;
|
||||||
|
let smallFontListenerInstalled = false;
|
||||||
|
|
||||||
|
function currentSmallFontName(): EmbeddedFontName {
|
||||||
|
if (!smallFontListenerInstalled) {
|
||||||
|
onSettingsStoreChanged((key) => {
|
||||||
|
if (key === UI_FONT_SETTING_KEY) cachedSmallFontChoice = null;
|
||||||
|
});
|
||||||
|
smallFontListenerInstalled = true;
|
||||||
|
}
|
||||||
|
if (cachedSmallFontChoice === null) {
|
||||||
|
const raw = getStringSetting(UI_FONT_SETTING_KEY, "terminus");
|
||||||
|
cachedSmallFontChoice = (UI_FONT_VALUES as readonly string[]).includes(raw)
|
||||||
|
? (raw as UiFontChoice)
|
||||||
|
: "terminus";
|
||||||
|
}
|
||||||
|
return SMALL_FONT_FOR_CHOICE[cachedSmallFontChoice];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDefaultSmallFont(): BdfFont {
|
export function getDefaultSmallFont(): BdfFont {
|
||||||
return getFont("terminus12");
|
return getFont(currentSmallFontName());
|
||||||
}
|
}
|
||||||
export function getDefaultMediumFont(): BdfFont {
|
export function getDefaultMediumFont(): BdfFont {
|
||||||
return getFont("terminus16");
|
return getFont("terminus16");
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ export class GrayImage {
|
|||||||
text: string;
|
text: string;
|
||||||
value: number;
|
value: number;
|
||||||
}): void {
|
}): void {
|
||||||
const lines = wrapText(font, text, this.width);
|
const lines = wrapText(font, text, width);
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
this.drawText(font, x, y + i * font.lineHeight, lines[i]!, value);
|
this.drawText(font, x, y + i * font.lineHeight, lines[i]!, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,13 @@ import { toUint8Array } from "../util/array-util";
|
|||||||
declare const com: any;
|
declare const com: any;
|
||||||
|
|
||||||
const ICON_SIZE = 24;
|
const ICON_SIZE = 24;
|
||||||
const ICON_CACHE_MS = 5_000;
|
// Backstop TTL only: the icon caches are invalidated eagerly whenever a
|
||||||
|
// notification is posted or dismissed (see invalidateIconCaches callers), so
|
||||||
|
// the tray is kept fresh by invalidation, not by expiry. A short TTL just
|
||||||
|
// forced a blocking main-thread re-fetch (~40-100ms of Java icon
|
||||||
|
// rasterization) every few seconds — usually producing a no-change frame that
|
||||||
|
// was then discarded. A long backstop keeps that off the render hot path.
|
||||||
|
const ICON_CACHE_MS = 60_000;
|
||||||
|
|
||||||
let cachedIcons: GrayImage[] = [];
|
let cachedIcons: GrayImage[] = [];
|
||||||
let cachedAtMs = 0;
|
let cachedAtMs = 0;
|
||||||
|
|||||||
@@ -6,7 +6,12 @@ import {
|
|||||||
setBooleanSetting,
|
setBooleanSetting,
|
||||||
setStringSetting,
|
setStringSetting,
|
||||||
} from "~/native/settings-store";
|
} from "~/native/settings-store";
|
||||||
import { getDefaultSmallFont } from "~/graphics/bdffont";
|
import {
|
||||||
|
getDefaultSmallFont,
|
||||||
|
UI_FONT_SETTING_KEY,
|
||||||
|
UI_FONT_VALUES,
|
||||||
|
type UiFontChoice,
|
||||||
|
} from "~/graphics/bdffont";
|
||||||
import { wrapText } from "~/graphics/textwrap";
|
import { wrapText } from "~/graphics/textwrap";
|
||||||
import { drawRightValueMenuItem, drawToggleMenuItem, MenuItem, MenuLayer } from "./menu";
|
import { drawRightValueMenuItem, drawToggleMenuItem, MenuItem, MenuLayer } from "./menu";
|
||||||
import { DashboardInputEvent, Layer, type LayerContext } from "./layers";
|
import { DashboardInputEvent, Layer, type LayerContext } from "./layers";
|
||||||
@@ -180,6 +185,15 @@ export const batteryDisplayModeSetting = new ConfigSettingEnum<BatteryDisplayMod
|
|||||||
formatValue: batteryDisplayModeLabel,
|
formatValue: batteryDisplayModeLabel,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const uiFontSetting = new ConfigSettingEnum<UiFontChoice>({
|
||||||
|
id: "uiFont",
|
||||||
|
label: "Font",
|
||||||
|
storageKey: UI_FONT_SETTING_KEY,
|
||||||
|
defaultValue: "terminus",
|
||||||
|
values: UI_FONT_VALUES,
|
||||||
|
formatValue: uiFontLabel,
|
||||||
|
});
|
||||||
|
|
||||||
export const timeFormatSetting = new ConfigSettingEnum<TimeFormat>({
|
export const timeFormatSetting = new ConfigSettingEnum<TimeFormat>({
|
||||||
id: "timeFormat",
|
id: "timeFormat",
|
||||||
label: "Time format",
|
label: "Time format",
|
||||||
@@ -322,6 +336,10 @@ export function timeFormatLabel(value: TimeFormat): string {
|
|||||||
return value === "12h" ? "12-hour" : "24-hour";
|
return value === "12h" ? "12-hour" : "24-hour";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function uiFontLabel(value: UiFontChoice): string {
|
||||||
|
return value === "terminusv" ? "TerminusV" : "Terminus";
|
||||||
|
}
|
||||||
|
|
||||||
export function loadNightscoutSettings(): NightscoutSettings {
|
export function loadNightscoutSettings(): NightscoutSettings {
|
||||||
return {
|
return {
|
||||||
siteUrl: nightscoutSiteUrlSetting.get(),
|
siteUrl: nightscoutSiteUrlSetting.get(),
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
import { getDefaultSmallFont } from "~/graphics/bdffont";
|
|
||||||
import { GrayImage } from "~/graphics/image";
|
|
||||||
import { getDashboardLogo } from "~/graphics/logo";
|
|
||||||
import { DashboardInputEvent, Layer, LayerContext, LayerStack } from "../layers";
|
|
||||||
|
|
||||||
export class AboutPage implements Layer {
|
|
||||||
paint(ctx: LayerContext): GrayImage {
|
|
||||||
// Sized to the hosting stack (the Settings app viewport).
|
|
||||||
const { width, height } = ctx.stack.getBaseSize();
|
|
||||||
const image = new GrayImage(width, height, 0);
|
|
||||||
const logo = getDashboardLogo();
|
|
||||||
const dashboardFont = getDefaultSmallFont();
|
|
||||||
image.drawText(dashboardFont, 22, 16, "About Faceclaw", 220);
|
|
||||||
if (logo) {
|
|
||||||
image.bitBlt(logo, 22, 42, { transparentZero: true });
|
|
||||||
}
|
|
||||||
image.drawText(dashboardFont, 108, 48, "Faceclaw", 220);
|
|
||||||
image.drawText(dashboardFont, 108, 64, "Dashboard prototype", 180);
|
|
||||||
|
|
||||||
image.drawTextWrapped({
|
|
||||||
font: dashboardFont,
|
|
||||||
x: 22, y: 128,
|
|
||||||
width: width - 44,
|
|
||||||
text: "By James Babcock. Distributed under the GNU General Public License, version 3. Version 0.1.0. Too much of an early janky development prototype to have proper numbered releases.",
|
|
||||||
value: 180
|
|
||||||
});
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
handleInput(event: DashboardInputEvent, ctx: { stack: LayerStack }): void {
|
|
||||||
if (event.type === "double-click") {
|
|
||||||
ctx.stack.pop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+112
-131
@@ -1,139 +1,120 @@
|
|||||||
import { APP_VIEWPORT } from "../shell/geometry";
|
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||||
import { MenuLayer, type MenuLayout } from "../menu";
|
import { getDashboardLogo } from "../../graphics/logo";
|
||||||
import { shell } from "../shell/shell";
|
import { shell } from "../shell/shell";
|
||||||
import { batteryDisplayModeSetting, elevenLabsApiKeySetting, enumSettingMenuItem, firmwareDebugFlagsSetting, rawScreenshotsEnabledSetting, saveVoiceRecordingsSetting, terminalAuthTokenSetting, terminalHostSetting, terminalPortSetting, textSettingMenuItem, timeFormatSetting, toggleSettingMenuItem, voiceProviderSetting, nightscoutSiteUrlSetting, nightscoutApiTokenSetting, screenTimeoutSetting } from "../dashboard-settings";
|
import {
|
||||||
import { AboutPage } from "./about-page";
|
batteryDisplayModeSetting,
|
||||||
|
elevenLabsApiKeySetting,
|
||||||
|
enumSettingMenuItem,
|
||||||
|
firmwareDebugFlagsSetting,
|
||||||
|
rawScreenshotsEnabledSetting,
|
||||||
|
saveVoiceRecordingsSetting,
|
||||||
|
terminalAuthTokenSetting,
|
||||||
|
terminalHostSetting,
|
||||||
|
terminalPortSetting,
|
||||||
|
textSettingMenuItem,
|
||||||
|
timeFormatSetting,
|
||||||
|
toggleSettingMenuItem,
|
||||||
|
uiFontSetting,
|
||||||
|
voiceProviderSetting,
|
||||||
|
nightscoutSiteUrlSetting,
|
||||||
|
nightscoutApiTokenSetting,
|
||||||
|
screenTimeoutSetting,
|
||||||
|
} from "../dashboard-settings";
|
||||||
|
import { openSettingsSubMenu, SettingsPanelLayer, type SettingsSection } from "./settings-panel";
|
||||||
|
|
||||||
// Rendered in the Settings app window (viewport-sized); cap height to it.
|
/** The Settings app's master-detail panel (sections on the left, contents on the right). */
|
||||||
const SETTINGS_MENU_LAYOUT: MenuLayout = { x: 8, y: 8, width: 272, maxHeight: APP_VIEWPORT.height - 16 };
|
export function createSettingsPanelLayer(): SettingsPanelLayer {
|
||||||
|
return new SettingsPanelLayer(settingsSections());
|
||||||
export function createSettingsMenuLayer(): MenuLayer {
|
|
||||||
return new MenuLayer(
|
|
||||||
"Settings",
|
|
||||||
[
|
|
||||||
{
|
|
||||||
label: "Display",
|
|
||||||
onSelect: (ctx) => {
|
|
||||||
ctx.stack.push(createDisplaySettingsMenuLayer());
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Voice",
|
|
||||||
onSelect: (ctx) => {
|
|
||||||
ctx.stack.push(createVoiceSettingsMenuLayer());
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Integrations",
|
|
||||||
onSelect: (ctx) => {
|
|
||||||
ctx.stack.push(createIntegrationsMenuLayer());
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Terminal",
|
|
||||||
onSelect: (ctx) => {
|
|
||||||
ctx.stack.push(createTerminalSettingsMenuLayer());
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Developer",
|
|
||||||
onSelect: (ctx) => {
|
|
||||||
ctx.stack.push(createDeveloperSettingsMenuLayer());
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "About",
|
|
||||||
onSelect: (ctx) => {
|
|
||||||
ctx.stack.push(new AboutPage());
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Quit / Disconnect",
|
|
||||||
onSelect: async (ctx) => {
|
|
||||||
ctx.stack.clearToBase();
|
|
||||||
await ctx.actions.disconnect();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
SETTINGS_MENU_LAYOUT,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTerminalSettingsMenuLayer(): MenuLayer {
|
function settingsSections(): SettingsSection[] {
|
||||||
return new MenuLayer(
|
return [
|
||||||
"Settings > Terminal",
|
{
|
||||||
[
|
label: "Display",
|
||||||
textSettingMenuItem(terminalHostSetting),
|
items: [
|
||||||
textSettingMenuItem(terminalPortSetting),
|
enumSettingMenuItem(screenTimeoutSetting, {
|
||||||
textSettingMenuItem(terminalAuthTokenSetting),
|
onChange: () => {
|
||||||
],
|
shell.noteUserActivity();
|
||||||
SETTINGS_MENU_LAYOUT,
|
},
|
||||||
);
|
}),
|
||||||
}
|
// Controls the top-bar battery indicators (icon vs percentage).
|
||||||
|
enumSettingMenuItem(batteryDisplayModeSetting),
|
||||||
function createDeveloperSettingsMenuLayer(): MenuLayer {
|
// Controls the top-bar clock (24-hour vs 12-hour).
|
||||||
return new MenuLayer(
|
enumSettingMenuItem(timeFormatSetting),
|
||||||
"Settings > Developer",
|
// Selects the UI body typeface (Terminus vs proportional TerminusV).
|
||||||
[
|
enumSettingMenuItem(uiFontSetting),
|
||||||
toggleSettingMenuItem(rawScreenshotsEnabledSetting),
|
],
|
||||||
toggleSettingMenuItem(saveVoiceRecordingsSetting),
|
},
|
||||||
toggleSettingMenuItem(firmwareDebugFlagsSetting),
|
{
|
||||||
],
|
label: "Voice",
|
||||||
SETTINGS_MENU_LAYOUT,
|
items: [enumSettingMenuItem(voiceProviderSetting), textSettingMenuItem(elevenLabsApiKeySetting)],
|
||||||
);
|
},
|
||||||
}
|
{
|
||||||
|
label: "Integrations",
|
||||||
function createDisplaySettingsMenuLayer(): MenuLayer {
|
items: [
|
||||||
return new MenuLayer(
|
{
|
||||||
"Settings > Display",
|
label: "Nightscout",
|
||||||
[
|
onSelect: (ctx) => {
|
||||||
enumSettingMenuItem(screenTimeoutSetting, {
|
openSettingsSubMenu(ctx, "Nightscout", [
|
||||||
onChange: () => {
|
textSettingMenuItem(nightscoutSiteUrlSetting),
|
||||||
shell.noteUserActivity();
|
textSettingMenuItem(nightscoutApiTokenSetting),
|
||||||
|
]);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}),
|
],
|
||||||
// Controls the top-bar battery indicators (icon vs percentage).
|
},
|
||||||
enumSettingMenuItem(batteryDisplayModeSetting),
|
{
|
||||||
// Controls the top-bar clock (24-hour vs 12-hour).
|
label: "Terminal",
|
||||||
enumSettingMenuItem(timeFormatSetting),
|
items: [
|
||||||
],
|
textSettingMenuItem(terminalHostSetting),
|
||||||
SETTINGS_MENU_LAYOUT,
|
textSettingMenuItem(terminalPortSetting),
|
||||||
);
|
textSettingMenuItem(terminalAuthTokenSetting),
|
||||||
}
|
],
|
||||||
|
},
|
||||||
function createVoiceSettingsMenuLayer(): MenuLayer {
|
{
|
||||||
return new MenuLayer(
|
label: "Developer",
|
||||||
"Settings > Voice",
|
items: [
|
||||||
[
|
toggleSettingMenuItem(rawScreenshotsEnabledSetting),
|
||||||
enumSettingMenuItem(voiceProviderSetting),
|
toggleSettingMenuItem(saveVoiceRecordingsSetting),
|
||||||
textSettingMenuItem(elevenLabsApiKeySetting),
|
toggleSettingMenuItem(firmwareDebugFlagsSetting),
|
||||||
],
|
],
|
||||||
SETTINGS_MENU_LAYOUT,
|
},
|
||||||
);
|
{
|
||||||
}
|
label: "About",
|
||||||
|
items: [],
|
||||||
function createIntegrationsMenuLayer(): MenuLayer {
|
renderDetail: renderAbout,
|
||||||
return new MenuLayer(
|
},
|
||||||
"Settings > Integrations",
|
{
|
||||||
[
|
label: "Quit",
|
||||||
{
|
items: [
|
||||||
label: "Nightscout",
|
{
|
||||||
onSelect: (ctx) => {
|
label: "Disconnect from glasses",
|
||||||
ctx.stack.push(createNightscoutSettingsMenuLayer());
|
onSelect: async (ctx) => {
|
||||||
|
ctx.stack.clearToBase();
|
||||||
|
await ctx.actions.disconnect();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
],
|
||||||
],
|
},
|
||||||
SETTINGS_MENU_LAYOUT,
|
];
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createNightscoutSettingsMenuLayer(): MenuLayer {
|
function renderAbout(args: { image: import("../../graphics/image").GrayImage; x: number; y: number; width: number }): void {
|
||||||
return new MenuLayer(
|
const { image, x, y, width } = args;
|
||||||
"Settings > Integrations > Nightscout",
|
const font = getDefaultSmallFont();
|
||||||
[
|
const logo = getDashboardLogo();
|
||||||
textSettingMenuItem(nightscoutSiteUrlSetting),
|
if (logo) {
|
||||||
textSettingMenuItem(nightscoutApiTokenSetting),
|
image.bitBlt(logo, x, y + 4, { transparentZero: true });
|
||||||
],
|
}
|
||||||
SETTINGS_MENU_LAYOUT,
|
const textX = logo ? x + logo.width + 12 : x;
|
||||||
);
|
image.drawText(font, textX, y + 8, "Faceclaw", 220);
|
||||||
}
|
image.drawText(font, textX, y + 24, "Dashboard prototype", 170);
|
||||||
|
image.drawTextWrapped({
|
||||||
|
font,
|
||||||
|
x,
|
||||||
|
y: y + 64,
|
||||||
|
width,
|
||||||
|
text: "By James Babcock. Distributed under the GNU General Public License, version 3. Version 0.1.0. Too much of an early janky development prototype to have proper numbered releases.",
|
||||||
|
value: 170,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||||
|
import { GrayImage } from "../../graphics/image";
|
||||||
|
import { clamp } from "../../util/numeric-util";
|
||||||
|
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK, GESTURE_SCROLL } from "../gestures";
|
||||||
|
import { DashboardInputEvent, Layer, LayerContext } from "../layers";
|
||||||
|
import { drawSelectionHighlight, MenuItem, MenuLayer, type MenuLayout } from "../menu";
|
||||||
|
import { shell } from "../shell/shell";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One left-column entry. `items` are the right-column rows (reusing the shared
|
||||||
|
* MenuItem builders). `renderDetail`, when set, replaces the row list with
|
||||||
|
* custom informational content (e.g. About) and makes the pane non-interactive.
|
||||||
|
*/
|
||||||
|
export type SettingsSection = {
|
||||||
|
label: string;
|
||||||
|
items: MenuItem[];
|
||||||
|
renderDetail?: (args: {
|
||||||
|
image: GrayImage;
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
ctx: LayerContext;
|
||||||
|
}) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const PAD = 8;
|
||||||
|
const ROW_H = 20;
|
||||||
|
const LEFT_W = 150;
|
||||||
|
// A throwaway menu to satisfy MenuItem.onSelect's second parameter; the
|
||||||
|
// settings items never use it (they act via ctx only).
|
||||||
|
const NO_MENU = new MenuLayer(null, []);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Two-column (master-detail) settings UI. The left column lists sections; the
|
||||||
|
* right column previews the highlighted section's contents. A tap moves focus
|
||||||
|
* into the right column, a double-tap moves it back out (and from the left
|
||||||
|
* column, out to the sidebar). Third-level menus open as centered modals.
|
||||||
|
*/
|
||||||
|
export class SettingsPanelLayer implements Layer {
|
||||||
|
private leftIndex = 0;
|
||||||
|
private rightIndex = 0;
|
||||||
|
private focus: "left" | "right" = "left";
|
||||||
|
private leftScroll = 0;
|
||||||
|
private rightScroll = 0;
|
||||||
|
|
||||||
|
constructor(private readonly sections: SettingsSection[]) {}
|
||||||
|
|
||||||
|
private section(): SettingsSection {
|
||||||
|
return this.sections[clamp(this.leftIndex, 0, this.sections.length - 1)]!;
|
||||||
|
}
|
||||||
|
|
||||||
|
paint(ctx: LayerContext): GrayImage {
|
||||||
|
const font = getDefaultSmallFont();
|
||||||
|
const { width, height } = ctx.stack.getBaseSize();
|
||||||
|
const image = new GrayImage(width, height, 0);
|
||||||
|
const appFocused = ctx.stack.isFocused();
|
||||||
|
|
||||||
|
this.leftIndex = clamp(this.leftIndex, 0, this.sections.length - 1);
|
||||||
|
const section = this.section();
|
||||||
|
const rightItems = section.items;
|
||||||
|
this.rightIndex = clamp(this.rightIndex, 0, Math.max(0, rightItems.length - 1));
|
||||||
|
|
||||||
|
const top = PAD;
|
||||||
|
const listBottom = height - PAD - 12; // leave a row for the gesture hint
|
||||||
|
|
||||||
|
// Left column: section labels.
|
||||||
|
const leftRows = Math.max(1, ((listBottom - top) / ROW_H) | 0);
|
||||||
|
this.leftScroll = clampScroll(this.leftIndex, this.leftScroll, leftRows, this.sections.length);
|
||||||
|
for (let i = this.leftScroll; i < Math.min(this.sections.length, this.leftScroll + leftRows); i++) {
|
||||||
|
const rowY = top + (i - this.leftScroll) * ROW_H;
|
||||||
|
const selected = i === this.leftIndex;
|
||||||
|
if (selected) {
|
||||||
|
drawSelectionHighlight(image, PAD - 2, rowY, LEFT_W, ROW_H - 2, appFocused && this.focus === "left", 6);
|
||||||
|
}
|
||||||
|
image.drawText(font, PAD + 8, rowY + 4, this.sections[i]!.label, selected ? 255 : 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Column divider (a light rule, not a full border).
|
||||||
|
const divX = PAD + LEFT_W + 6;
|
||||||
|
image.drawLine(divX, top, divX, listBottom, 40);
|
||||||
|
|
||||||
|
// Right column: the highlighted section's contents.
|
||||||
|
const rightX = divX + 14;
|
||||||
|
const rightW = width - rightX - PAD;
|
||||||
|
if (section.renderDetail) {
|
||||||
|
section.renderDetail({ image, x: rightX, y: top, width: rightW, height: listBottom - top, ctx });
|
||||||
|
} else if (rightItems.length) {
|
||||||
|
const rightRows = Math.max(1, ((listBottom - top) / ROW_H) | 0);
|
||||||
|
this.rightScroll = clampScroll(this.rightIndex, this.rightScroll, rightRows, rightItems.length);
|
||||||
|
for (let i = this.rightScroll; i < Math.min(rightItems.length, this.rightScroll + rightRows); i++) {
|
||||||
|
const item = rightItems[i]!;
|
||||||
|
const rowY = top + (i - this.rightScroll) * ROW_H;
|
||||||
|
// A selection only appears once focus is in the right column; before
|
||||||
|
// that the pane is a preview of what tapping would open.
|
||||||
|
const selected = this.focus === "right" && i === this.rightIndex;
|
||||||
|
if (selected) {
|
||||||
|
drawSelectionHighlight(image, rightX - 2, rowY, rightW + 2, ROW_H - 2, appFocused, 6);
|
||||||
|
}
|
||||||
|
if (item.render) {
|
||||||
|
item.render({ image, x: rightX + 8, y: rowY, width: rightW - 16, height: ROW_H - 3, selected, text: item.label, ctx });
|
||||||
|
} else {
|
||||||
|
image.drawText(font, rightX + 8, rowY + 4, item.label, selected ? 255 : 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const hint =
|
||||||
|
this.focus === "left"
|
||||||
|
? `${GESTURE_SCROLL} section ${GESTURE_CLICK} open ${GESTURE_DOUBLE_CLICK} exit`
|
||||||
|
: `${GESTURE_SCROLL} item ${GESTURE_CLICK} select ${GESTURE_DOUBLE_CLICK} back`;
|
||||||
|
image.drawText(font, PAD, height - 10, hint, 110);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
|
||||||
|
if (this.focus === "left") {
|
||||||
|
switch (event.type) {
|
||||||
|
case "scroll-up":
|
||||||
|
this.leftIndex = (this.leftIndex + this.sections.length - 1) % this.sections.length;
|
||||||
|
this.resetRight();
|
||||||
|
return;
|
||||||
|
case "scroll-down":
|
||||||
|
this.leftIndex = (this.leftIndex + 1) % this.sections.length;
|
||||||
|
this.resetRight();
|
||||||
|
return;
|
||||||
|
case "click":
|
||||||
|
// Only enter sections that have something interactive on the right.
|
||||||
|
if (this.section().items.length) {
|
||||||
|
this.focus = "right";
|
||||||
|
this.resetRight();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
case "double-click":
|
||||||
|
shell.yieldFocusToSidebar();
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const items = this.section().items;
|
||||||
|
switch (event.type) {
|
||||||
|
case "scroll-up":
|
||||||
|
if (items.length) this.rightIndex = (this.rightIndex + items.length - 1) % items.length;
|
||||||
|
return;
|
||||||
|
case "scroll-down":
|
||||||
|
if (items.length) this.rightIndex = (this.rightIndex + 1) % items.length;
|
||||||
|
return;
|
||||||
|
case "click":
|
||||||
|
if (items.length) await items[clamp(this.rightIndex, 0, items.length - 1)]!.onSelect(ctx, NO_MENU);
|
||||||
|
return;
|
||||||
|
case "double-click":
|
||||||
|
this.focus = "left";
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private resetRight(): void {
|
||||||
|
this.rightIndex = 0;
|
||||||
|
this.rightScroll = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open a third-level menu as a centered, bordered modal over the panel. Reuses
|
||||||
|
* MenuLayer (which draws the border and self-closes on double-click).
|
||||||
|
*/
|
||||||
|
export function openSettingsSubMenu(ctx: LayerContext, title: string, items: MenuItem[]): void {
|
||||||
|
const { width, height } = ctx.stack.getBaseSize();
|
||||||
|
const menuW = Math.min(320, width - 40);
|
||||||
|
const menuH = 16 + PAD + items.length * ROW_H + PAD;
|
||||||
|
const layout: MenuLayout = {
|
||||||
|
x: ((width - menuW) / 2) | 0,
|
||||||
|
y: ((height - menuH) / 2) | 0,
|
||||||
|
width: menuW,
|
||||||
|
minHeight: menuH,
|
||||||
|
maxHeight: menuH,
|
||||||
|
};
|
||||||
|
ctx.stack.push(new MenuLayer(title, items, layout));
|
||||||
|
}
|
||||||
|
|
||||||
|
function clampScroll(selected: number, scroll: number, visible: number, count: number): number {
|
||||||
|
if (selected < scroll) {
|
||||||
|
scroll = selected;
|
||||||
|
} else if (selected >= scroll + visible) {
|
||||||
|
scroll = selected - visible + 1;
|
||||||
|
}
|
||||||
|
return clamp(scroll, 0, Math.max(0, count - visible));
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { GrayImage } from "../../graphics/image";
|
import { GrayImage } from "../../graphics/image";
|
||||||
import { LayerActions } from "../layers";
|
import { LayerActions } from "../layers";
|
||||||
import { EditTextSettingLayer } from "../dashboard-settings";
|
import { EditTextSettingLayer } from "../dashboard-settings";
|
||||||
import { createSettingsMenuLayer } from "../dashboard/settings-menus";
|
import { createSettingsPanelLayer } from "../dashboard/settings-menus";
|
||||||
import { createInProcessWindow, YieldAtRootLayer } from "./in-process-window";
|
import { createInProcessWindow } from "./in-process-window";
|
||||||
import { type ShellWindow } from "./shell";
|
import { type ShellWindow } from "./shell";
|
||||||
|
|
||||||
export const SETTINGS_WINDOW_ID = "settings";
|
export const SETTINGS_WINDOW_ID = "settings";
|
||||||
@@ -40,7 +40,9 @@ export function createSettingsAppWindow(options: SettingsAppOptions): SettingsAp
|
|||||||
icon: "settings",
|
icon: "settings",
|
||||||
closeable: true,
|
closeable: true,
|
||||||
actions: options.actions,
|
actions: options.actions,
|
||||||
baseLayer: new YieldAtRootLayer(createSettingsMenuLayer()),
|
// Not wrapped in YieldAtRootLayer: the panel routes double-click itself
|
||||||
|
// (right column -> left column, then left column -> sidebar).
|
||||||
|
baseLayer: createSettingsPanelLayer(),
|
||||||
submitFrame: options.submitFrame,
|
submitFrame: options.submitFrame,
|
||||||
setSurfaceVisible: options.setSurfaceVisible,
|
setSurfaceVisible: options.setSurfaceVisible,
|
||||||
removeSurface: options.removeSurface,
|
removeSurface: options.removeSurface,
|
||||||
|
|||||||
Reference in new issue
Block a user