Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/shoji_wm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,14 @@ export type {
AutomaticEffectInvalidationPolicyHandle,
LabelProps,
ManagedWindowProps,
ManagedWindowAnimationEasing,
ManagedWindowAnimationMode,
ManagedWindowPoint,
ManagedWindowPointAnimationOptions,
ManagedWindowRect,
ManagedWindowRectAnimationOptions,
ManagedWindowScalarAnimationOptions,
ManagedWindowScheduleAnimationOptions,
ManagedWindowState,
ManagedWindowTransform,
MaybeSignal,
Expand Down
59 changes: 59 additions & 0 deletions tests/node-test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Types for the Node APIs these tests use. They run under `node --import tsx
// --test`, and @types/node cannot be the source: its global `process` clashes
// with the one in packages/shoji_wm/src/runtime-globals.d.ts, which every test
// reaches through the SDK index. The signatures mirror @types/node's, so a
// wrong call fails here as it would there. Add to this file when a test needs
// more. The root tsconfig excludes it, so a `node:` import in the runtime or
// the config still fails to typecheck.

declare module "node:test" {
type TestFn = () => void | Promise<void>;
type HookFn = () => void | Promise<void>;

export function test(name: string, fn: TestFn): Promise<void>;
export function beforeEach(fn: HookFn): void;
export function afterEach(fn: HookFn): void;
}

declare module "node:assert/strict" {
type AssertPredicate =
| RegExp
| (new (...args: any[]) => object)
| ((thrown: unknown) => boolean)
| object
| Error;

function assert(value: unknown, message?: string | Error): asserts value;
namespace assert {
function ok(value: unknown, message?: string | Error): asserts value;
function equal<T>(
actual: unknown,
expected: T,
message?: string | Error,
): asserts actual is T;
function deepEqual<T>(
actual: unknown,
expected: T,
message?: string | Error,
): asserts actual is T;
function throws(block: () => unknown, message?: string | Error): void;
function throws(
block: () => unknown,
error: AssertPredicate,
message?: string | Error,
): void;
function doesNotThrow(block: () => unknown, message?: string | Error): void;
function rejects(
block: (() => Promise<unknown>) | Promise<unknown>,
message?: string | Error,
): Promise<void>;
function rejects(
block: (() => Promise<unknown>) | Promise<unknown>,
error: AssertPredicate,
message?: string | Error,
): Promise<void>;
}
export default assert;
}

declare function setImmediate(callback: () => void): unknown;
11 changes: 7 additions & 4 deletions tests/output-direct-scanout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import {

test("directScanout reaches the compositor with an output's config, and only when set", () => {
updateOutputState({
"DP-1": { name: "DP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [] },
"eDP-1": { name: "eDP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [] },
"DP-1": { name: "DP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [], hdrSupported: false },
"eDP-1": { name: "eDP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [], hdrSupported: false },
});
configureOutputs(() => ({
"DP-1": { mode: "extend", directScanout: false },
"eDP-1": { mode: "extend" },
}));
const config = takePendingDisplayConfig();
assert.equal(config?.["DP-1"]?.directScanout, false);
assert.equal(config?.["eDP-1"]?.directScanout, undefined);
const dp1 = config?.["DP-1"];
const edp1 = config?.["eDP-1"];
assert.ok(dp1?.mode === "extend" && edp1?.mode === "extend");
assert.equal(dp1.directScanout, false);
assert.equal(edp1.directScanout, undefined);
assert.equal(JSON.stringify(config?.["eDP-1"]).includes("directScanout"), false);
});
11 changes: 7 additions & 4 deletions tests/output-vrr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import {

test("vrr reaches the compositor with an output's config, and only when set", () => {
updateOutputState({
"DP-1": { name: "DP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [] },
"eDP-1": { name: "eDP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [] },
"DP-1": { name: "DP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [], hdrSupported: false },
"eDP-1": { name: "eDP-1", position: { x: 0, y: 0 }, scale: 1, availableModes: [], hdrSupported: false },
});
configureOutputs(() => ({
"DP-1": { mode: "extend", vrr: true },
"eDP-1": { mode: "extend" },
}));
const config = takePendingDisplayConfig();
assert.equal(config?.["DP-1"]?.vrr, true);
assert.equal(config?.["eDP-1"]?.vrr, undefined);
const dp1 = config?.["DP-1"];
const edp1 = config?.["eDP-1"];
assert.ok(dp1?.mode === "extend" && edp1?.mode === "extend");
assert.equal(dp1.vrr, true);
assert.equal(edp1.vrr, undefined);
assert.equal(JSON.stringify(config?.["eDP-1"]).includes("vrr"), false);
});
5 changes: 5 additions & 0 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../tsconfig.json",
"include": ["*.ts"],
"exclude": []
}
46 changes: 34 additions & 12 deletions tools/decoration-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,7 @@ interface WindowStateRequestSuccess {
workspaceConfig?: WorkspaceConfigPayload;
keyBindingConfig?: { entries: RuntimeKeyBindingConfigEntry[] };
pointerConfig?: RuntimePointerConfig;
inputConfig?: { config: InputConfigDraft };
eventConfig?: RuntimeEventConfig;
processConfig?: { entries: RuntimeProcessConfigEntry[] };
processActions?: RuntimeProcessSpawnAction[];
Expand Down Expand Up @@ -1121,6 +1122,7 @@ interface StartCloseSuccess {
workspaceConfig?: WorkspaceConfigPayload;
keyBindingConfig?: { entries: RuntimeKeyBindingConfigEntry[] };
pointerConfig?: RuntimePointerConfig;
inputConfig?: { config: InputConfigDraft };
eventConfig?: RuntimeEventConfig;
processConfig?: { entries: RuntimeProcessConfigEntry[] };
processActions?: RuntimeProcessSpawnAction[];
Expand Down Expand Up @@ -1178,6 +1180,7 @@ interface EvaluateLayerEffectsSuccess {
workspaceConfig?: WorkspaceConfigPayload;
keyBindingConfig?: { entries: RuntimeKeyBindingConfigEntry[] };
pointerConfig?: RuntimePointerConfig;
inputConfig?: { config: InputConfigDraft };
eventConfig?: RuntimeEventConfig;
processConfig?: { entries: RuntimeProcessConfigEntry[] };
processActions?: RuntimeProcessSpawnAction[];
Expand Down Expand Up @@ -1207,6 +1210,7 @@ interface LifecycleEnableSuccess {
workspaceConfig?: WorkspaceConfigPayload;
keyBindingConfig?: { entries: RuntimeKeyBindingConfigEntry[] };
pointerConfig?: RuntimePointerConfig;
inputConfig?: { config: InputConfigDraft };
eventConfig?: RuntimeEventConfig;
processConfig?: { entries: RuntimeProcessConfigEntry[] };
processActions?: RuntimeProcessSpawnAction[];
Expand Down Expand Up @@ -1656,7 +1660,7 @@ async function main(configPath: string, embeddedBridge: EmbeddedRuntimeBridge) {
for await (const request of readEmbeddedMessages(embeddedBridge)) {
activeRequest = ++requestSerial;
try {
if ("displayState" in request) {
if ("displayState" in request && request.displayState) {
updateOutputState(request.displayState);
}
if ("inputState" in request) {
Expand Down Expand Up @@ -2093,7 +2097,7 @@ async function main(configPath: string, embeddedBridge: EmbeddedRuntimeBridge) {
const inputConfig = pendingInputConfigPayload();
const processConfig = pendingProcessConfigPayload();
const processActions = pendingProcessActionsPayload();
const response: EvaluateSuccess = {
const response: StartCloseSuccess = {
requestId: request.requestId,
ok: true,
kind: "startClose",
Expand Down Expand Up @@ -2565,10 +2569,15 @@ async function main(configPath: string, embeddedBridge: EmbeddedRuntimeBridge) {
processActions,
});
} else {
// The pointerMove and gestureSwipe requests each carry two kinds,
// and narrowing on `kind === a || kind === b` cannot drop a
// union member whose kind is itself a union, so only
// invokeHandler is left here at runtime but not to the checker.
const handlerRequest = request as InvokeHandlerRequest;
const result = invokeHandler(
effectConfig,
request.windowId,
request.handlerId,
handlerRequest.windowId,
handlerRequest.handlerId,
);
const keyBindingConfig = pendingKeyBindingConfigPayload();
const pointerConfig = pendingPointerConfigPayload();
Expand All @@ -2580,7 +2589,7 @@ async function main(configPath: string, embeddedBridge: EmbeddedRuntimeBridge) {
ok: true,
kind: "invokeHandler",
...result,
effectTargetId: request.windowId,
effectTargetId: handlerRequest.windowId,
displayConfig: pendingDisplayConfigPayload(),
workspaceConfig: pendingWorkspaceConfigPayload(),
keyBindingConfig,
Expand Down Expand Up @@ -3191,7 +3200,7 @@ function numericUniformSnapshot(
}
const flattened: number[] = [];
for (const element of value.values) {
const entries = width === 1 ? [element] : element;
const entries: unknown = width === 1 ? [element] : element;
if (
!Array.isArray(entries) ||
entries.length !== width ||
Expand Down Expand Up @@ -3569,6 +3578,7 @@ function evaluateWindowDecorationPolicy(
fullscreen: unsupportedAction,
unfullscreen: unsupportedAction,
focus: unsupportedAction,
unfocus: unsupportedAction,
scheduleAnimation: unsupportedAction,
cancelAnimation: unsupportedAction,
setCloseAnimationDuration: unsupportedAction,
Expand Down Expand Up @@ -3978,7 +3988,9 @@ function layerUsableAreaChanged(
read(layer.outputName) !== snapshot.outputName ||
read(layer.exclusiveEdge) !== snapshot.exclusiveEdge ||
currentExclusiveZone.mode !== nextExclusiveZone.mode ||
currentExclusiveZone.size !== nextExclusiveZone.size ||
(currentExclusiveZone.mode === "exclusive" &&
nextExclusiveZone.mode === "exclusive" &&
currentExclusiveZone.size !== nextExclusiveZone.size) ||
currentAnchor.top !== nextAnchor.top ||
currentAnchor.right !== nextAnchor.right ||
currentAnchor.bottom !== nextAnchor.bottom ||
Expand Down Expand Up @@ -4075,6 +4087,7 @@ function identityManagedWindow(): ManagedWindowState {
idle: false,
interactive: true,
forceRectSize: false,
tiled: false,
zIndex: 0,
transform: identityTransform(),
};
Expand Down Expand Up @@ -4511,6 +4524,7 @@ function processSchedulerTick(tickOutput: string | undefined): {
dirtyWindowIds: string[];
dirtyManagedWindowIds?: string[];
dirtyWindowNodeIds?: Record<string, string[]>;
dirtyLayerIds?: string[];
dirtyLayerNodeIds?: Record<string, string[]>;
actions: RuntimeWindowAction[];
nextPollInMs?: number;
Expand Down Expand Up @@ -5112,7 +5126,7 @@ function countSerializedNodes(node: unknown): number {
const record = node as { children?: unknown[] };
return (
1 +
(record.children ?? []).reduce(
(record.children ?? []).reduce<number>(
(sum, child) => sum + countSerializedNodes(child),
0,
)
Expand Down Expand Up @@ -5327,7 +5341,7 @@ const nativeCachedResponseView = new DataView(

function tryWriteNativeCachedResponse(
output: EmbeddedRuntimeBridge,
response: EvaluateSuccess,
response: EvaluateSuccess | StartCloseSuccess,
updates: PendingRuntimeResponseUpdates,
windowId: string,
): boolean {
Expand Down Expand Up @@ -5383,12 +5397,13 @@ function tryWriteNativeCachedResponse(
if (managedWindow.confinePointer) flags |= 1 << 13;

const rect = managedWindow.rect;
const origin = read(transform.origin);
const fields = [
response.requestId,
response.nextPollInMs ?? -1,
flags,
transform.origin.x,
transform.origin.y,
origin.x,
origin.y,
transform.translateX,
transform.translateY,
transform.scaleX,
Expand All @@ -5400,7 +5415,14 @@ function tryWriteNativeCachedResponse(
rect?.height ?? 0,
managedWindow.zIndex ?? 0,
];
if (fields.some((value) => !Number.isFinite(value))) {
// The transform is a snapshot of plain numbers; anything else (a signal
// that was never read) falls back to the JSON response.
if (
!fields.every(
(value): value is number =>
typeof value === "number" && Number.isFinite(value),
)
) {
return false;
}
for (let index = 0; index < fields.length; index++) {
Expand Down
9 changes: 5 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
"jsxImportSource": "shoji_wm",
"strict": true,
"verbatimModuleSyntax": true,
"allowImportingTsExtensions": true,
"noEmit": true,
"types": [],
"baseUrl": ".",
"paths": {
"shoji_wm": [
"packages/shoji_wm/src/index.ts"
"./packages/shoji_wm/src/index.ts"
],
"shoji_wm/*": [
"packages/shoji_wm/src/*"
"./packages/shoji_wm/src/*"
]
}
}
},
"exclude": ["node_modules", "target", "docs", "tests/*.test.ts", "tests/node-test.d.ts"]
}