mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Merge stock EvenHub canvas preservation
This commit is contained in:
3 files changed
+110
-13
No files matched your search
@@ -4,7 +4,7 @@
|
||||
* makes the content area exactly the 576x288 surface EvenHub apps expect.
|
||||
*/
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { EVENHUB_SCREEN_WIDTH } from "./compositor";
|
||||
import { EVENHUB_SCREEN_WIDTH, EVENHUB_SCREEN_HEIGHT } from "./compositor";
|
||||
import { directionalFallback, isDirectionalInput, type InputEvent } from "../../ui/gestures";
|
||||
import { type Layer, type LayerContext } from "../../ui/layers";
|
||||
import {
|
||||
@@ -24,21 +24,26 @@ class EvenHubAppLayer implements Layer {
|
||||
* extension's source field should see that they came from the watch.
|
||||
*/
|
||||
readonly acceptsDirectional = true;
|
||||
private tallCanvas = false;
|
||||
|
||||
constructor(private readonly session: EvenHubSession) {}
|
||||
|
||||
setTallCanvas(tall: boolean): void {
|
||||
this.tallCanvas = tall;
|
||||
}
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const size = ctx.stack.getBaseSize();
|
||||
// EvenHub apps lay out for the stock 576-wide surface. In the Full
|
||||
// Screen display mode the window is 640 wide; paint at stock width and
|
||||
// centre it rather than leaving all the slack on the right.
|
||||
if (size.width > EVENHUB_SCREEN_WIDTH) {
|
||||
const content = this.session.paint({ width: EVENHUB_SCREEN_WIDTH, height: size.height }, ctx.stack.isFocused());
|
||||
const image = new GrayImage(size.width, size.height, 0);
|
||||
content.composeInto(image, Math.floor((size.width - EVENHUB_SCREEN_WIDTH) / 2), 0);
|
||||
return image;
|
||||
}
|
||||
return this.session.paint(size, ctx.stack.isFocused());
|
||||
// Host full screen hides chrome; it does not enlarge the stock app canvas.
|
||||
// Only the app's explicit Faceclaw extended-layout request opts into height.
|
||||
const canvas = { width: EVENHUB_SCREEN_WIDTH, height: this.tallCanvas ? size.height : EVENHUB_SCREEN_HEIGHT };
|
||||
const content = this.session.paint(canvas, ctx.stack.isFocused());
|
||||
if (size.width === canvas.width && size.height === canvas.height) return content;
|
||||
const image = new GrayImage(size.width, size.height, 0);
|
||||
// Clip text to its logical canvas before placing it in the larger host window.
|
||||
image.bitBlt(content.withDrawsBaked(), Math.max(0, Math.floor((size.width - canvas.width) / 2)),
|
||||
Math.max(0, Math.floor((size.height - canvas.height) / 2)));
|
||||
return image;
|
||||
}
|
||||
|
||||
handleInput(event: InputEvent): void {
|
||||
@@ -60,6 +65,7 @@ export function createEvenHubWindow(
|
||||
requestShellRender: () => void,
|
||||
): InProcessWindow {
|
||||
const fallbackIcon = windowIcon("package", session.manifest.name.charAt(0).toUpperCase() || "E");
|
||||
const appLayer = new EvenHubAppLayer(session);
|
||||
const created = createInProcessWindow({
|
||||
appId,
|
||||
windowId,
|
||||
@@ -91,7 +97,7 @@ export function createEvenHubWindow(
|
||||
{ label: "Show phone UI", onSelect: (ctx: LayerContext) => { ctx.stack.pop(); onShowPhone(); } },
|
||||
],
|
||||
actions: options.actions,
|
||||
baseLayer: new EvenHubAppLayer(session),
|
||||
baseLayer: appLayer,
|
||||
submitFrame: options.submitFrame,
|
||||
setSurfaceVisible: options.setSurfaceVisible,
|
||||
removeSurface: options.removeSurface,
|
||||
@@ -109,7 +115,10 @@ export function createEvenHubWindow(
|
||||
pushOverlay: (layer) => created.stack.push(layer),
|
||||
// The extended layout uses the full 576x452 app area ("max"); stock apps
|
||||
// stay in the 576x288 band ("medium").
|
||||
setTallCanvas: (tall) => created.setHeightMode(tall ? "max" : "medium"),
|
||||
setTallCanvas: (tall) => {
|
||||
appLayer.setTallCanvas(tall);
|
||||
created.setHeightMode(tall ? "max" : "medium");
|
||||
},
|
||||
setAttention: (attention) => shell.setWindowAttention(windowId, attention),
|
||||
// Only while the app listens for text: otherwise the shell's Type Into App
|
||||
// destinations (voice dialog, phone keyboard, watch) would send into a void.
|
||||
|
||||
@@ -7,6 +7,13 @@ Full screen fills the 640x480 panel, hides chrome while the app has focus, and
|
||||
resizes existing in-process and worker windows without restarting the app.
|
||||
The switcher remains accessible through the system menu.
|
||||
|
||||
Stock EvenHub apps retain their logical 576x288 canvas in every host display
|
||||
mode, including full screen. Content is centered at native pixel scale and
|
||||
clipped to that canvas; extra space does not change wrapping or layout.
|
||||
Only an app's explicit Faceclaw extended-layout request enables a taller canvas.
|
||||
Regression tests compare the complete stock raster against its centered
|
||||
full-screen placement, including text crossing the logical canvas boundary.
|
||||
|
||||
Keep screen awake is a separate On/Off switch immediately after the full-screen
|
||||
action in the system menu. It defaults off and persists per app independently
|
||||
of full screen. Existing full-screen preferences remain unchanged and do not
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
const { GrayImage } = require('../.test-build/app/graphics/image.js');
|
||||
|
||||
function fixture() {
|
||||
let options, hooks;
|
||||
const paints = [], heights = [];
|
||||
const session = {
|
||||
manifest: { name: 'Test', packageId: 'test.app' },
|
||||
renderWindowIcon() {}, contextMenuItems: () => [], keepsScreenOn: () => false,
|
||||
attachWindow(value) { hooks = value; },
|
||||
paint(size, focused) {
|
||||
paints.push({ ...size, focused });
|
||||
const image = new GrayImage(size.width, size.height);
|
||||
image.setPixel(0, 0, 255);
|
||||
image.setPixel(size.width - 1, size.height - 1, 120);
|
||||
// Deliberately overflow a deferred text run: stock clips it at 576x288.
|
||||
image.drawFwText({ bakeFwTextRun(target, run, dx, dy) {
|
||||
target.fillRect(run.x + dx, run.y + dy, 20, 20, run.value);
|
||||
} }, 570, 280, 200, [{}]);
|
||||
return image;
|
||||
},
|
||||
};
|
||||
const load = loader({}, {
|
||||
'../../graphics/image': { GrayImage },
|
||||
'./compositor': { EVENHUB_SCREEN_WIDTH: 576, EVENHUB_SCREEN_HEIGHT: 288 },
|
||||
'../../ui/gestures': {}, '../../ui/shell/shell': { shell: {} }, './session': {},
|
||||
'../../ui/shell/chrome-layer': { windowIcon: () => () => null, makeImageWindowIcon: () => () => null },
|
||||
'./installed-apps': {},
|
||||
'../../ui/shell/in-process-window': { createInProcessWindow(value) {
|
||||
options = value;
|
||||
return { window: {}, stack: {}, requestRender() {}, setHeightMode(mode) { heights.push(mode); } };
|
||||
} },
|
||||
});
|
||||
load('app/apps/evenhub/evenhub-window.ts').createEvenHubWindow('test', 'test', session, {}, () => {}, () => {});
|
||||
return { paints, heights, hooks: () => hooks,
|
||||
paint(width, height, focused = true) {
|
||||
return options.baseLayer.paint({ stack: { getBaseSize: () => ({ width, height }), isFocused: () => focused } });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test('stock EvenHub canvas remains 576x288 through full-screen entry, resize and exit', () => {
|
||||
const f = fixture();
|
||||
for (const [width, height] of [[576, 288], [640, 480], [576, 452], [640, 480], [576, 288]]) {
|
||||
const image = f.paint(width, height);
|
||||
assert.deepEqual(f.paints.at(-1), { width: 576, height: 288, focused: true });
|
||||
assert.equal(image.width, width);
|
||||
assert.equal(image.height, height);
|
||||
}
|
||||
});
|
||||
|
||||
test('full screen centers stock pixels at native scale and clips overflowing text to the stock canvas', () => {
|
||||
const f = fixture();
|
||||
const stock = f.paint(576, 288).withDrawsBaked();
|
||||
const full = f.paint(640, 480).withDrawsBaked();
|
||||
for (let y = 0; y < 480; y++) {
|
||||
for (let x = 0; x < 640; x++) {
|
||||
const expected = x >= 32 && x < 608 && y >= 96 && y < 384 ? stock.getPixel(x - 32, y - 96) : 0;
|
||||
assert.equal(full.getPixel(x, y), expected);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('only an explicit extended-layout request opts into the taller canvas', () => {
|
||||
const f = fixture();
|
||||
f.paint(640, 480, false);
|
||||
assert.deepEqual(f.paints.at(-1), { width: 576, height: 288, focused: false });
|
||||
f.hooks().setTallCanvas(true);
|
||||
assert.deepEqual(f.heights, ['max']);
|
||||
f.paint(576, 452);
|
||||
assert.equal(f.paints.at(-1).height, 452);
|
||||
f.paint(640, 480);
|
||||
assert.equal(f.paints.at(-1).width, 576);
|
||||
assert.equal(f.paints.at(-1).height, 480);
|
||||
f.hooks().setTallCanvas(false);
|
||||
f.paint(640, 480);
|
||||
assert.deepEqual(f.heights, ['max', 'medium']);
|
||||
assert.equal(f.paints.at(-1).height, 288);
|
||||
});
|
||||
Reference in new issue
Block a user