Fix size of the notification modal after switching glasses-model mid-session

This commit is contained in:
James Babcock committed 2026-11-01 23:43:32 -08:00
1 parent 9ddd4c4d03
commit dff8608a63
2 files changed
+33 -8

No files matched your search

+11 -8
View File
@@ -154,8 +154,12 @@ export class LayerStack {
}
private readonly shellKeys = new WeakMap<Layer, number>();
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<LayerActions>): 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;
}),
+22
View File
@@ -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});
});