forked from Blendman974/faceclaw
Dim the screen underneath when a context menu is open
This commit is contained in:
1 parent
83c3732ba7
commit
9234458dd6
13 files changed
+211
-14
No files matched your search
+34
-6
@@ -1,5 +1,5 @@
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
||||
import { type Plane } from "../graphics/plane";
|
||||
import { dimPlanes, type Plane } from "../graphics/plane";
|
||||
import { spanCurrent } from "../native/frame-timings";
|
||||
import { type ConfigSettingBoolean, type ConfigSettingString } from "./dashboard-settings";
|
||||
import { directionalFallback, isDirectionalInput, type InputEvent } from "./gestures";
|
||||
@@ -80,6 +80,15 @@ export interface LayerContext {
|
||||
|
||||
export interface Layer {
|
||||
readonly paintOverBase?: 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
|
||||
* (only meaningful for layers that call paintBelow). false, the default,
|
||||
* leaves the planes below as painted. For the shell's stack the factor also
|
||||
* reaches the window surfaces beneath the shell surface (see
|
||||
* LayerStack.baseDim).
|
||||
*/
|
||||
readonly dimUnderneath?: false | number;
|
||||
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage;
|
||||
handleInput(event: InputEvent, ctx: LayerContext): Promise<void> | void;
|
||||
/**
|
||||
@@ -110,6 +119,7 @@ export class LayerStack {
|
||||
private baseWidth: number;
|
||||
private baseHeight: number;
|
||||
private readonly focusedFn: () => boolean;
|
||||
private lastBaseDim: number | false = 1;
|
||||
|
||||
constructor(
|
||||
baseLayer: Layer,
|
||||
@@ -203,7 +213,19 @@ export class LayerStack {
|
||||
* PaintBelow). All planes share the stack's base size at offset (0, 0).
|
||||
*/
|
||||
paint(): Plane[] {
|
||||
return this.paintLayer(this.layers.length - 1);
|
||||
this.lastBaseDim = false;
|
||||
return this.paintLayer(this.layers.length - 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* The brightness factor the last paint applied to the base plane: 1 when
|
||||
* nothing dims it, a smaller factor under a layer with dimUnderneath, and
|
||||
* false when the base was not painted at all (a stacked layer replaced it).
|
||||
* A stack whose base is transparent over something else (the shell chrome
|
||||
* over the window surfaces) forwards this to what lies beneath.
|
||||
*/
|
||||
baseDim(): number | false {
|
||||
return this.lastBaseDim;
|
||||
}
|
||||
|
||||
async handleInput(event: InputEvent): Promise<void> {
|
||||
@@ -235,7 +257,8 @@ export class LayerStack {
|
||||
}
|
||||
|
||||
|
||||
private paintLayer(index: number): Plane[] {
|
||||
/** Paint layer `index`; `dimSoFar` is the factor the layers above apply to it. */
|
||||
private paintLayer(index: number, dimSoFar: number): Plane[] {
|
||||
const layer = this.layers[index]!;
|
||||
let canvas: GrayImage | null = null;
|
||||
let belowRequested = false;
|
||||
@@ -249,10 +272,15 @@ export class LayerStack {
|
||||
}),
|
||||
);
|
||||
const ownPlane: Plane = { image, x: 0, y: 0 };
|
||||
if (index <= 0 || !belowRequested) {
|
||||
if (index <= 0) {
|
||||
this.lastBaseDim = dimSoFar;
|
||||
return [ownPlane];
|
||||
}
|
||||
const below = layer.paintOverBase ? this.paintLayer(0) : this.paintLayer(index - 1);
|
||||
return [...below, ownPlane];
|
||||
if (!belowRequested) {
|
||||
return [ownPlane];
|
||||
}
|
||||
const dim = layer.dimUnderneath || 1;
|
||||
const below = this.paintLayer(layer.paintOverBase ? 0 : index - 1, dimSoFar * dim);
|
||||
return [...(dim < 1 ? dimPlanes(below, dim) : below), ownPlane];
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -31,9 +31,11 @@ export type MenuLayout = {
|
||||
maxHeight?: number;
|
||||
/**
|
||||
* Dim hint line pinned to the bottom edge inside the box, below the items
|
||||
* (gesture help such as "●- system menu"). Takes a line off the item area.
|
||||
* (gesture help such as "●— system menu"). Takes a line off the item area.
|
||||
*/
|
||||
footer?: string;
|
||||
/** Brightness factor for everything beneath the menu (see Layer.dimUnderneath). Default: none. */
|
||||
dimUnderneath?: number;
|
||||
/**
|
||||
* Paint as a standalone page: the layers below stay in the stack for back
|
||||
* navigation but are not composited underneath. Default: false — the menu
|
||||
@@ -182,10 +184,17 @@ export function drawRightValueMenuItem(
|
||||
image.drawText(font, valueX, y + LIST_ROW_TEXT_INSET, value, 220);
|
||||
}
|
||||
|
||||
/** How far context menus (window and system) dim the content beneath them. */
|
||||
export const CONTEXT_MENU_DIM = 0.25;
|
||||
|
||||
export class MenuLayer implements Layer {
|
||||
private selectedIndex = 0;
|
||||
private scrollRow = 0;
|
||||
|
||||
get dimUnderneath(): false | number {
|
||||
return this.layout.dimUnderneath ?? false;
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly title: string | null,
|
||||
private readonly items: MenuItem[],
|
||||
|
||||
+13
-1
@@ -15,7 +15,7 @@ import {
|
||||
makeInputEvent,
|
||||
} from "../gestures";
|
||||
import { Layer, LayerActions, LayerContext, LayerStack, noopLayerActions } from "../layers";
|
||||
import { MenuLayer, type MenuItem } from "../menu";
|
||||
import { CONTEXT_MENU_DIM, MenuLayer, type MenuItem } from "../menu";
|
||||
import { VoiceInputLayer, type VoiceSendTarget } from "./voice-input";
|
||||
import { voiceActivity } from "./voice-activity";
|
||||
import { AssistantLayer } from "./assistant";
|
||||
@@ -206,6 +206,7 @@ class ShellOverlayMenuLayer extends MenuLayer {
|
||||
width,
|
||||
minHeight: 150,
|
||||
footer,
|
||||
dimUnderneath: CONTEXT_MENU_DIM,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -603,6 +604,17 @@ class Shell {
|
||||
return this.stack.paint();
|
||||
}
|
||||
|
||||
/**
|
||||
* The brightness factor a shell overlay (a context menu) currently applies
|
||||
* to what lies beneath the shell surface, i.e. the window surfaces: 1 when
|
||||
* nothing dims them. Read after paintSurface; the controller forwards it to
|
||||
* the compositor, which cannot see the shell's layer stack.
|
||||
*/
|
||||
underlayDim(): number {
|
||||
const dim = this.stack.baseDim();
|
||||
return this.screenOn && dim !== false ? dim : 1;
|
||||
}
|
||||
|
||||
async receiveInput(event: InputEvent, frameId = 0): Promise<ShellInputOutcome> {
|
||||
const previous = this.lastInput;
|
||||
this.lastInput = event;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { GrayImage } from "../graphics/image";
|
||||
import { singlePlane, type Plane } from "../graphics/plane";
|
||||
import { GESTURE_LONG_PRESS, gestureHints, type InputEvent } from "./gestures";
|
||||
import { type Layer, LayerStack, noopLayerActions } from "./layers";
|
||||
import { MenuLayer, type MenuItem, type MenuLayout } from "./menu";
|
||||
import { CONTEXT_MENU_DIM, MenuLayer, type MenuItem, type MenuLayout } from "./menu";
|
||||
import type { WorkerAppReply } from "./shell/worker-window";
|
||||
|
||||
/**
|
||||
@@ -23,6 +23,7 @@ export const WINDOW_MENU_LAYOUT: MenuLayout = {
|
||||
width: 272,
|
||||
minHeight: 150,
|
||||
footer: gestureHints([[GESTURE_LONG_PRESS, "system menu"]]),
|
||||
dimUnderneath: CONTEXT_MENU_DIM,
|
||||
};
|
||||
|
||||
export class WindowMenuLayer extends MenuLayer {
|
||||
|
||||
Reference in new issue
Block a user