mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Fix double-dimming when app menu submenus are open
This commit is contained in:
1 parent
a82184316e
commit
79ea7858ca
4 files changed
+43
-5
No files matched your search
+12
-1
@@ -102,6 +102,15 @@ export interface Layer {
|
||||
readonly depth?: number;
|
||||
paintParts?(): Plane[];
|
||||
readonly paintOverBase?: boolean;
|
||||
/**
|
||||
* True when this layer stands in for `below`, a stacked layer directly
|
||||
* beneath it (or beneath another layer it stands in for): when this layer
|
||||
* calls paintBelow, the stack skips `below` and paints what is under it
|
||||
* instead. A submenu replacing the menu it opened from uses this, so the
|
||||
* hidden menu costs no plane and its dimUnderneath doesn't dim the content
|
||||
* a second time; popping the submenu still returns to it.
|
||||
*/
|
||||
replacesLayerBelow?(below: Layer): boolean;
|
||||
/**
|
||||
* Dim everything painted beneath this layer: a 0..1 brightness factor
|
||||
* applied to the pixels and glyphs of every plane below it in the stack
|
||||
@@ -326,7 +335,9 @@ export class LayerStack {
|
||||
return [ownPlane];
|
||||
}
|
||||
const dim = layer.dimUnderneath || 1;
|
||||
const below = this.paintLayer(layer.paintOverBase ? 0 : index - 1, dimSoFar * dim, raw);
|
||||
let belowIndex = layer.paintOverBase ? 0 : index - 1;
|
||||
while (belowIndex > 0 && layer.replacesLayerBelow?.(this.layers[belowIndex]!)) belowIndex--;
|
||||
const below = this.paintLayer(belowIndex, dimSoFar * dim, raw);
|
||||
return [...(!raw && dim < 1 ? dimPlanes(below, dim) : below), ownPlane];
|
||||
}
|
||||
}
|
||||
@@ -192,12 +192,13 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
||||
drawIcon: options.drawIcon ?? windowIcon(options.icon, options.iconLetter),
|
||||
handleInput: async (event, frameId) => {
|
||||
// The shell opened its system menu over this window; close our own
|
||||
// context menu so the two never stack. Never forwarded to app layers.
|
||||
// context menu (and any window submenus open from it) so the two never
|
||||
// stack. Never forwarded to app layers.
|
||||
if (event.type === "system-menu-opened") {
|
||||
options.onSystemMenuOpened?.();
|
||||
if (stack.popIfTop((layer) => layer instanceof WindowMenuLayer)) {
|
||||
requestRender();
|
||||
}
|
||||
let closedMenu = false;
|
||||
while (stack.popIfTop((layer) => layer instanceof WindowMenuLayer)) closedMenu = true;
|
||||
if (closedMenu) requestRender();
|
||||
return;
|
||||
}
|
||||
// The default tap-then-hold response: the window menu (or the system
|
||||
|
||||
@@ -33,6 +33,16 @@ export class WindowMenuLayer extends MenuLayer {
|
||||
? { ...WINDOW_MENU_LAYOUT, footer: gestureHints([[GESTURE_SHORT_THEN_LONG_PRESS, "system menu"]]) }
|
||||
: WINDOW_MENU_LAYOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* A window submenu (Settings, Spotify, ...) opens in place of the window
|
||||
* menu it came from, which it would mostly cover anyway: the window content
|
||||
* shows beneath it, dimmed once, rather than the parent menu dimming it a
|
||||
* second time and costing a plane of its own.
|
||||
*/
|
||||
replacesLayerBelow(below: Layer): boolean {
|
||||
return below instanceof WindowMenuLayer;
|
||||
}
|
||||
}
|
||||
|
||||
export type WindowMenuOptions = {
|
||||
|
||||
@@ -64,6 +64,22 @@ test('context menu surface and selected row both use +4 without changing the app
|
||||
assert.deepEqual(closed.image.pixels,base.pixels);
|
||||
assert.deepEqual(wire.presentationRecords(prepareFrameDraws(closed.draws)),[]);
|
||||
});
|
||||
test('a submenu that replaces its parent menu skips the parent plane and dims the content once',()=>{
|
||||
const base=new graphics.GrayImage(100,90,200);
|
||||
const stack=new LayerStack({paint:()=>base},noopLayerActions,{width:100,height:90});
|
||||
const layout={x:10,y:8,width:80,minHeight:70,maxHeight:70,dimUnderneath:0.5};
|
||||
class SubmenuLayer extends MenuLayer { replacesLayerBelow(below) { return below instanceof MenuLayer; } }
|
||||
const parent=new MenuLayer('PARENT',[{label:'SUB',onSelect(){}}],layout);
|
||||
stack.push(parent);
|
||||
stack.push(new SubmenuLayer('CHILD',[{label:'ITEM',onSelect(){}}],layout));
|
||||
stack.push(new SubmenuLayer('GRANDCHILD',[{label:'ITEM',onSelect(){}}],layout));
|
||||
const painted=stack.paint();
|
||||
assert.equal(painted.length,2);
|
||||
assert.equal(painted[0].image.pixels[0],100);
|
||||
assert.equal(stack.baseDim(),0.5);
|
||||
stack.pop();stack.pop();
|
||||
assert.equal(stack.paint().length,2);
|
||||
});
|
||||
test('text page paints at the stack size, not the lens size',()=>{
|
||||
// An app window's stack is its viewport; a lens-sized plane is rejected by
|
||||
// the compositor as larger than the window surface.
|
||||
|
||||
Reference in new issue
Block a user