forked from Blendman974/faceclaw
Context menus are centered and include window title
This commit is contained in:
1 parent
5158bc86ff
commit
b1493a353d
14 files changed
+55
-18
No files matched your search
@@ -1,5 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
## 0.6.4 - Future
|
||||
* Context menus are centered and include window title
|
||||
|
||||
## 0.6.3 - 2026-09-01
|
||||
* Update custom firmware base version from 2.2.6 to 2.2.9
|
||||
* Add support for the short-then-long-press gesture
|
||||
|
||||
@@ -136,6 +136,7 @@ type GamePhase = "playing" | "paused" | "game-over";
|
||||
type BlocksWindow = {
|
||||
windowId: string;
|
||||
surfaceId: string;
|
||||
title: string;
|
||||
viewportWidth: number;
|
||||
viewportHeight: number;
|
||||
foreground: boolean;
|
||||
@@ -181,6 +182,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
const window: BlocksWindow = {
|
||||
windowId: message.windowId,
|
||||
surfaceId: message.surfaceId,
|
||||
title: message.title,
|
||||
viewportWidth: message.viewport.width,
|
||||
viewportHeight: message.viewport.height,
|
||||
foreground: false,
|
||||
@@ -303,6 +305,7 @@ function openWindowMenu(window: BlocksWindow): void {
|
||||
function windowMenu(window: BlocksWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
title: () => window.title,
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
|
||||
@@ -100,6 +100,7 @@ type Snapshot = {
|
||||
type FreecellWindow = {
|
||||
windowId: string;
|
||||
surfaceId: string;
|
||||
title: string;
|
||||
viewportWidth: number;
|
||||
viewportHeight: number;
|
||||
foreground: boolean;
|
||||
@@ -142,6 +143,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
const window: FreecellWindow = {
|
||||
windowId: message.windowId,
|
||||
surfaceId: message.surfaceId,
|
||||
title: message.title,
|
||||
viewportWidth: message.viewport.width,
|
||||
viewportHeight: message.viewport.height,
|
||||
foreground: false,
|
||||
@@ -256,6 +258,7 @@ function openWindowMenu(window: FreecellWindow): void {
|
||||
function windowMenu(window: FreecellWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
title: () => window.title,
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
|
||||
@@ -94,6 +94,7 @@ type GamePhase = "playing" | "paused" | "won" | "lost";
|
||||
type MinesweeperWindow = {
|
||||
windowId: string;
|
||||
surfaceId: string;
|
||||
title: string;
|
||||
viewportWidth: number;
|
||||
viewportHeight: number;
|
||||
foreground: boolean;
|
||||
@@ -146,6 +147,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
const window: MinesweeperWindow = {
|
||||
windowId: message.windowId,
|
||||
surfaceId: message.surfaceId,
|
||||
title: message.title,
|
||||
viewportWidth: message.viewport.width,
|
||||
viewportHeight: message.viewport.height,
|
||||
foreground: false,
|
||||
@@ -285,6 +287,7 @@ function openWindowMenu(window: MinesweeperWindow): void {
|
||||
function windowMenu(window: MinesweeperWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
title: () => window.title,
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
|
||||
@@ -59,6 +59,7 @@ type MapMode = "follow" | "overview";
|
||||
type NavWindow = {
|
||||
windowId: string;
|
||||
surfaceId: string;
|
||||
title: string;
|
||||
viewportWidth: number;
|
||||
viewportHeight: number;
|
||||
foreground: boolean;
|
||||
@@ -162,6 +163,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
window = {
|
||||
windowId: message.windowId,
|
||||
surfaceId: message.surfaceId,
|
||||
title: message.title,
|
||||
viewportWidth: message.viewport.width,
|
||||
viewportHeight: message.viewport.height,
|
||||
foreground: false,
|
||||
@@ -612,6 +614,7 @@ function describeRouteStatus(): string {
|
||||
function windowMenu(win: NavWindow): WindowMenu {
|
||||
if (!win.menu) {
|
||||
win.menu = new WindowMenu({
|
||||
title: () => win.title,
|
||||
size: { width: win.viewportWidth, height: win.viewportHeight },
|
||||
paintBase: () => paintContent(win),
|
||||
isFocused: () => win.focused,
|
||||
|
||||
@@ -242,6 +242,7 @@ type Flipper = {
|
||||
type PinballWindow = {
|
||||
windowId: string;
|
||||
surfaceId: string;
|
||||
title: string;
|
||||
viewportWidth: number;
|
||||
viewportHeight: number;
|
||||
foreground: boolean;
|
||||
@@ -301,6 +302,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
const window: PinballWindow = {
|
||||
windowId: message.windowId,
|
||||
surfaceId: message.surfaceId,
|
||||
title: message.title,
|
||||
viewportWidth: message.viewport.width,
|
||||
viewportHeight: message.viewport.height,
|
||||
foreground: false,
|
||||
@@ -469,6 +471,7 @@ function openWindowMenu(window: PinballWindow): void {
|
||||
function windowMenu(window: PinballWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
title: () => window.title,
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
|
||||
@@ -64,6 +64,7 @@ const smallFont = getDefaultSmallFont();
|
||||
type RoamWindow = {
|
||||
windowId: string;
|
||||
surfaceId: string;
|
||||
title: string;
|
||||
viewportWidth: number;
|
||||
viewportHeight: number;
|
||||
foreground: boolean;
|
||||
@@ -168,6 +169,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
window = {
|
||||
windowId: message.windowId,
|
||||
surfaceId: message.surfaceId,
|
||||
title: message.title,
|
||||
viewportWidth: message.viewport.width,
|
||||
viewportHeight: message.viewport.height,
|
||||
foreground: false,
|
||||
@@ -327,6 +329,7 @@ function maybeRefreshStalePage(): void {
|
||||
function windowMenu(win: RoamWindow): WindowMenu {
|
||||
if (!win.menu) {
|
||||
win.menu = new WindowMenu({
|
||||
title: () => win.title,
|
||||
size: { width: win.viewportWidth, height: win.viewportHeight },
|
||||
paintBase: () => paintContent(win),
|
||||
isFocused: () => win.focused,
|
||||
|
||||
@@ -88,6 +88,8 @@ const NEW_CONNECTION_DRAFT_KEY = "terminal.newConnectionDraft";
|
||||
type BaseWindow = {
|
||||
windowId: string;
|
||||
surfaceId: string;
|
||||
/** Shell-side window title, echoed back in the open-window message. */
|
||||
title: string;
|
||||
/** Content viewport from the shell's open-window message; grid = viewport / cell. */
|
||||
viewportWidth: number;
|
||||
viewportHeight: number;
|
||||
@@ -304,7 +306,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
const message = event.data;
|
||||
switch (message.type) {
|
||||
case "open-window":
|
||||
openWindow(message.windowId, message.surfaceId, message.viewport);
|
||||
openWindow(message.windowId, message.surfaceId, message.title, message.viewport);
|
||||
break;
|
||||
case "close-window":
|
||||
closeWindow(message.windowId);
|
||||
@@ -430,11 +432,11 @@ function cancelPendingReconnects(): void {
|
||||
}
|
||||
}
|
||||
|
||||
function openWindow(windowId: string, surfaceId: string, viewport: { width: number; height: number }): void {
|
||||
function openWindow(windowId: string, surfaceId: string, title: string, viewport: { width: number; height: number }): void {
|
||||
const pendingView = pendingViews.get(windowId);
|
||||
if (pendingView) {
|
||||
pendingViews.delete(windowId);
|
||||
windows.set(windowId, createViewWindow(windowId, surfaceId, viewport, pendingView));
|
||||
windows.set(windowId, createViewWindow(windowId, surfaceId, title, viewport, pendingView));
|
||||
renderHubWindows();
|
||||
return;
|
||||
}
|
||||
@@ -443,6 +445,7 @@ function openWindow(windowId: string, surfaceId: string, viewport: { width: numb
|
||||
kind: "hub",
|
||||
windowId,
|
||||
surfaceId,
|
||||
title,
|
||||
viewportWidth: viewport.width,
|
||||
viewportHeight: viewport.height,
|
||||
gridCols: Math.floor(viewport.width / hubCell.cellWidth),
|
||||
@@ -753,6 +756,7 @@ function noteSessionActivity(connectionId: string, socket: string): void {
|
||||
function createViewWindow(
|
||||
windowId: string,
|
||||
surfaceId: string,
|
||||
title: string,
|
||||
viewport: { width: number; height: number },
|
||||
view: PendingView,
|
||||
): ViewWindow {
|
||||
@@ -768,6 +772,7 @@ function createViewWindow(
|
||||
kind: "view",
|
||||
windowId,
|
||||
surfaceId,
|
||||
title,
|
||||
viewportWidth: viewport.width,
|
||||
viewportHeight: viewport.height,
|
||||
gridCols,
|
||||
@@ -900,6 +905,7 @@ function reconnectView(window: ViewWindow): void {
|
||||
function windowMenu(window: TerminalWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
title: () => window.title,
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
|
||||
@@ -42,6 +42,7 @@ type TimerView = "stopwatch" | "timers" | "editor";
|
||||
type TimerWindow = {
|
||||
windowId: string;
|
||||
surfaceId: string;
|
||||
title: string;
|
||||
viewportWidth: number;
|
||||
viewportHeight: number;
|
||||
foreground: boolean;
|
||||
@@ -132,6 +133,7 @@ global.onmessage = (event: { data: WorkerAppMessage }) => {
|
||||
windows.set(message.windowId, {
|
||||
windowId: message.windowId,
|
||||
surfaceId: message.surfaceId,
|
||||
title: message.title,
|
||||
viewportWidth: message.viewport.width,
|
||||
viewportHeight: message.viewport.height,
|
||||
foreground: false,
|
||||
@@ -296,6 +298,7 @@ function refreshWindowsAfterToolChange(): void {
|
||||
function windowMenu(window: TimerWindow): WindowMenu {
|
||||
if (!window.menu) {
|
||||
window.menu = new WindowMenu({
|
||||
title: () => window.title,
|
||||
size: { width: window.viewportWidth, height: window.viewportHeight },
|
||||
paintBase: () => paintContent(window),
|
||||
isFocused: () => window.focused,
|
||||
|
||||
+4
-2
@@ -17,7 +17,8 @@ const MENU_HIGHLIGHT_SELECTED_BACKGROUND_FILL = 15;
|
||||
const MENU_HIGHLIGHT_SELECTED_BORDER_STROKE = 45;
|
||||
|
||||
export type MenuLayout = {
|
||||
x: number;
|
||||
/** Left edge, or "center" to center horizontally on the painted surface. */
|
||||
x: number | "center";
|
||||
y: number;
|
||||
width: number;
|
||||
/** Whether to draw the rounded outline around the menu. Default: true. */
|
||||
@@ -200,7 +201,8 @@ export class MenuLayer implements Layer {
|
||||
const rowHeight = listRowHeight(font);
|
||||
const base = ctx.stack.getBaseSize();
|
||||
const image = this.layout.opaque ? new GrayImage(base.width, base.height, 0) : paintBelow();
|
||||
const { x, y, width } = this.layout;
|
||||
const { y, width } = this.layout;
|
||||
const x = this.layout.x === "center" ? ((image.width - width) / 2) | 0 : this.layout.x;
|
||||
const chromeTop = (this.title ? menuTitleHeight(font) : 0) + MENU_BODY_PADDING;
|
||||
const minHeight = this.layout.minHeight ?? DEFAULT_MENU_MIN_HEIGHT;
|
||||
// Cap to the surface being painted on: a window's stack image may be much
|
||||
|
||||
@@ -162,7 +162,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
||||
},
|
||||
});
|
||||
}
|
||||
stack.push(new WindowMenuLayer(items));
|
||||
stack.push(new WindowMenuLayer(options.title, items));
|
||||
};
|
||||
|
||||
const window: ShellWindow = {
|
||||
|
||||
@@ -171,13 +171,15 @@ const LONG_PRESS_ESCAPE_MENU_MS = 4000;
|
||||
class ShellOverlayMenuLayer extends MenuLayer {
|
||||
constructor(items: MenuItem[], private readonly onClosed: () => void) {
|
||||
// Aligned to the min-height window band (like the sidebar), wherever the
|
||||
// vertical position setting currently puts it; past the sidebar strip
|
||||
// where one reserves width (none in the full-panel mode).
|
||||
super(null, items, {
|
||||
x: sidebarWidth() + 8,
|
||||
// vertical position setting currently puts it; centered over the
|
||||
// application area, i.e. the part of the screen past the sidebar strip
|
||||
// (the whole screen in the full-panel mode, where the strip overlays).
|
||||
const width = 272;
|
||||
super("System", items, {
|
||||
x: sidebarWidth() + (((G2_LENS_WIDTH - sidebarWidth() - width) / 2) | 0),
|
||||
y: minWindowTop() + TOP_BAR_HEIGHT + 8,
|
||||
width: 272,
|
||||
minHeight: 0,
|
||||
width,
|
||||
minHeight: 150,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import { shell, type ShellWindow } from "./shell";
|
||||
* worker→Java directly.
|
||||
*/
|
||||
export type WorkerAppMessage =
|
||||
| { type: "open-window"; windowId: string; surfaceId: string; viewport: { width: number; height: number } }
|
||||
| { type: "open-window"; windowId: string; surfaceId: string; title: string; viewport: { width: number; height: number } }
|
||||
| { type: "close-window"; windowId: string }
|
||||
| { type: "input"; windowId: string; event: unknown; frameId: number; focused: boolean }
|
||||
| { type: "text-input"; windowId: string; text: string }
|
||||
@@ -303,6 +303,7 @@ export class WorkerAppHost {
|
||||
type: "open-window",
|
||||
windowId: spec.windowId,
|
||||
surfaceId,
|
||||
title: spec.title,
|
||||
viewport: appViewportSize(heightMode),
|
||||
});
|
||||
const window: ShellWindow = {
|
||||
|
||||
@@ -13,16 +13,18 @@ import type { WorkerAppReply } from "./shell/worker-window";
|
||||
* is held long enough, so an unresponsive app can always be closed.
|
||||
*/
|
||||
|
||||
/** Viewport-relative layout; visually matches the shell's escape menu position. */
|
||||
export const WINDOW_MENU_LAYOUT: MenuLayout = { x: 8, y: 8, width: 272, minHeight: 0 };
|
||||
/** Centered over the viewport; visually matches the shell's escape menu position. */
|
||||
export const WINDOW_MENU_LAYOUT: MenuLayout = { x: "center", y: 8, width: 272, minHeight: 150 };
|
||||
|
||||
export class WindowMenuLayer extends MenuLayer {
|
||||
constructor(items: MenuItem[]) {
|
||||
super(null, items, WINDOW_MENU_LAYOUT);
|
||||
constructor(title: string | null, items: MenuItem[]) {
|
||||
super(title, items, WINDOW_MENU_LAYOUT);
|
||||
}
|
||||
}
|
||||
|
||||
export type WindowMenuOptions = {
|
||||
/** Menu title: the window's title, read at open time. */
|
||||
title: () => string;
|
||||
/** Paint the window content the menu draws over (a fresh, mutable image). */
|
||||
paintBase: () => GrayImage;
|
||||
size: { width: number; height: number };
|
||||
@@ -53,7 +55,7 @@ export class WindowMenu {
|
||||
handleInput: () => {},
|
||||
};
|
||||
const stack = new LayerStack(base, { ...noopLayerActions }, this.options.size, this.options.isFocused);
|
||||
stack.push(new WindowMenuLayer(items));
|
||||
stack.push(new WindowMenuLayer(this.options.title(), items));
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user