diff --git a/app/ui/layers.ts b/app/ui/layers.ts index a16a98ff..e55502b4 100644 --- a/app/ui/layers.ts +++ b/app/ui/layers.ts @@ -154,8 +154,12 @@ export class LayerStack { } private readonly shellKeys = new WeakMap(); private readonly ctx: LayerContext; - private baseWidth: number; - private baseHeight: number; + /** + * The base viewport's size, or null to follow the paired glasses' screen + * as it is now: the shell's own stack lives for the whole process, and + * re-pairing with the other glasses type changes the screen under it. + */ + private baseSize: { width: number; height: number } | null; private readonly focusedFn: () => boolean; private lastBaseDim: number | false = 1; @@ -173,8 +177,7 @@ export class LayerStack { stack: this, actions, }; - this.baseWidth = baseSize?.width ?? screenWidth(); - this.baseHeight = baseSize?.height ?? screenHeight(); + this.baseSize = baseSize ? { width: baseSize.width, height: baseSize.height } : null; this.focusedFn = isFocused; } @@ -245,13 +248,12 @@ export class LayerStack { } getBaseSize(): { width: number; height: number } { - return { width: this.baseWidth, height: this.baseHeight }; + return this.baseSize ? { ...this.baseSize } : { width: screenWidth(), height: screenHeight() }; } /** Resize the base viewport (e.g. an EvenHub window switching to the tall canvas). */ setBaseSize(size: { width: number; height: number }): void { - this.baseWidth = size.width; - this.baseHeight = size.height; + this.baseSize = { width: size.width, height: size.height }; } setActions(actions: Partial): void { @@ -322,7 +324,8 @@ export class LayerStack { layer.paint(this.ctx, () => { belowRequested = true; if (!canvas) { - canvas = new GrayImage(this.baseWidth, this.baseHeight, 0); + const { width, height } = this.getBaseSize(); + canvas = new GrayImage(width, height, 0); } return canvas; }), diff --git a/tests/menu-display-list.test.cjs b/tests/menu-display-list.test.cjs index 3e97d1a6..f8e25202 100644 --- a/tests/menu-display-list.test.cjs +++ b/tests/menu-display-list.test.cjs @@ -141,3 +141,25 @@ test('shell crop widens a fractional rect (TTF-measured status bar) to whole pix assert.deepEqual([crop.x,crop.y,crop.image.width,crop.image.height],[400,250,176,15]); assert.ok(crop.image.pixels.every(v=>v===7)); }); + +test('a stack without its own size follows the screen when the glasses type changes',()=>{ + // The shell's stack is built once per process; re-pairing a G2 after a + // RayNeo iO must not leave its overlays painting on a 540x220 canvas. + const screen={width:540,height:220}; + const {LayerStack}=load('app/ui/layers.ts',{ + '../graphics/image':graphics,'../graphics/plane':planes,'../native/frame-timings':{spanCurrent:(_name,fn)=>fn()}, + '../graphics/screen-size':{screenWidth:()=>screen.width,screenHeight:()=>screen.height},'./gestures':{}, + }); + const stack=new LayerStack({paint:()=>new graphics.GrayImage(screen.width,screen.height,0)},noopLayerActions); + stack.push({paint:(_ctx,below)=>below(),handleInput:async()=>{}}); + // JSON: the stack's arrays and objects come from the vm's realm. + const sizes=()=>JSON.parse(JSON.stringify(stack.paint().map(p=>[p.image.width,p.image.height]))); + assert.deepEqual(sizes(),[[540,220],[540,220]]); + screen.width=640;screen.height=480; + assert.deepEqual({...stack.getBaseSize()},{width:640,height:480}); + assert.deepEqual(sizes(),[[640,480],[640,480]]); + // An explicit size (a window's viewport, the modal's interior) stays put. + const sized=new LayerStack({paint:()=>new graphics.GrayImage(100,90,0)},noopLayerActions,{width:100,height:90}); + screen.width=540;screen.height=220; + assert.deepEqual({...sized.getBaseSize()},{width:100,height:90}); +});