Add an option to move the app switcher to the right or bottom, and adjust screen depth if bottom

This commit is contained in:
James Babcock committed 2026-10-01 02:40:13 -07:00
1 parent 46fded856a
commit 8f99779f98
21 files changed
+827 -286

No files matched your search

+4 -1
View File
@@ -261,7 +261,10 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
'../notifications': {}, '../dashboard-settings': settings, './ambient-cards': {},
'./chrome-layer': { ShellChromeLayer: class {} }, './modal-layer': {}, './tool-debug-layer': {},
'./brightness-picker-layer': {},
'../../assistant/tool-registry': {}, './geometry': { sidebarWidth: () => 64, minWindowTop: () => 96, TOP_BAR_HEIGHT: 28 },
'../../assistant/tool-registry': {}, './geometry': {
sidebarWidth: () => 64, minWindowTop: () => 96, switcherPosition: () => 'left', uiDepth: () => 0,
appViewportRect: () => ({ x: 64, y: 124, width: 576, height: 260 }),
},
});
const { createInProcessWindow } = load('app/ui/shell/in-process-window.ts', {
'../../graphics/image': images, '../../native/frame-timings': timings,
+63 -11
View File
@@ -14,6 +14,7 @@ function geometry() {
displayModeSetting: '576x288', verticalPositionSetting: 'middle',
navigateDisplayModeSetting: 'global', navigateVerticalPositionSetting: 'global',
terminalDisplayModeSetting: 'default', terminalVerticalPositionSetting: 'global',
appSwitcherPositionSetting: 'left', uiDepthSetting: '0',
}).map(([name, value]) => [name, { value, get() { return this.value; } }]));
const context = { exports: {}, require: (name) => {
if (name === '../../graphics/image') return { G2_LENS_WIDTH: 640, G2_LENS_HEIGHT: 480 };
@@ -65,23 +66,74 @@ test('Terminal can disable its tall default, inherit position or override both d
test('all explicit size/position combinations stay within the display and align content below the bar', () => {
const g = geometry();
for (const globalMode of ['576x288', '576x480', '640x480']) {
g.settings.displayModeSetting.value = globalMode;
for (const appId of ['navigate', 'terminal']) {
for (const mode of ['global', '576x288', '576x480', '640x480']) {
g.settings[`${appId}DisplayModeSetting`].value = mode;
for (const position of ['global', 'top', 'upper', 'middle', 'lower', 'bottom']) {
g.settings[`${appId}VerticalPositionSetting`].value = position;
const rect = g.rect('max', appId);
assert.equal(rect.x + rect.width, 640);
assert.equal(rect.y, g.windowTop('max', appId) + g.TOP_BAR_HEIGHT);
assert.ok(rect.y >= 28 && rect.y + rect.height <= 480);
for (const switcher of ['left', 'right', 'bottom']) {
g.settings.appSwitcherPositionSetting.value = switcher;
for (const globalMode of ['576x288', '576x480', '640x480']) {
g.settings.displayModeSetting.value = globalMode;
for (const appId of ['navigate', 'terminal']) {
for (const mode of ['global', '576x288', '576x480', '640x480']) {
g.settings[`${appId}DisplayModeSetting`].value = mode;
for (const position of ['global', 'top', 'upper', 'middle', 'lower', 'bottom']) {
g.settings[`${appId}VerticalPositionSetting`].value = position;
for (const heightMode of ['min', 'medium', 'max']) {
const rect = g.rect(heightMode, appId);
const fullPanel = g.displayMode(appId) === '640x480';
assert.equal(rect.x + rect.width, fullPanel ? 640 : { left: 640, right: 576, bottom: 608 }[switcher]);
assert.equal(rect.y, g.windowTop(heightMode, appId) + g.TOP_BAR_HEIGHT);
assert.ok(rect.y >= 28 && rect.y + rect.height <= 480 - g.switcherRowHeight(appId));
const row = g.switcherRect(heightMode, appId);
assert.ok(row.y + row.height <= 480);
// A reserved bottom row hangs right under the window, as wide as it.
if (g.switcherRowHeight(appId)) assert.deepEqual([row.x, row.y, row.width], [rect.x, rect.y + rect.height, rect.width]);
}
}
}
}
}
}
});
test('the app switcher can sit on the right edge', () => {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = 'right';
assert.deepEqual(g.rect('min'), { x: 0, y: 124, width: 576, height: 260 });
assert.deepEqual({ ...g.switcherRect('max') }, { x: 576, y: 96, width: 64, height: 288 });
assert.equal(g.screenCenterInViewportX(), 320);
assert.equal(g.isOnSwitcherEdge(600, 10, 'min'), true);
assert.equal(g.isOnSwitcherEdge(10, 200, 'min'), false);
// Depth needs the bottom row's side margins.
g.settings.uiDepthSetting.value = '32';
assert.equal(g.uiDepth(), 0);
g.settings.displayModeSetting.value = '640x480';
assert.deepEqual(g.rect('max'), { x: 0, y: 28, width: 640, height: 452 });
});
test('a bottom app switcher centres 576-wide windows and hangs one tall tab under them', () => {
const g = geometry();
g.settings.appSwitcherPositionSetting.value = 'bottom';
assert.equal(g.SWITCHER_ROW_HEIGHT, 36);
assert.deepEqual(g.rect('max', 'terminal'), { x: 32, y: 28, width: 576, height: 416 });
assert.deepEqual({ ...g.switcherRect('max', 'terminal') }, { x: 32, y: 444, width: 576, height: 36 });
// Band and row share the slack: no gap under a band shorter than the screen.
assert.deepEqual(g.rect('min'), { x: 32, y: 106, width: 576, height: 260 });
assert.deepEqual({ ...g.switcherRect('min') }, { x: 32, y: 366, width: 576, height: 36 });
assert.equal(g.isOnSwitcherEdge(10, 370, 'min'), true);
assert.equal(g.isOnSwitcherEdge(10, 360, 'min'), false);
g.settings.verticalPositionSetting.value = 'bottom';
assert.equal(g.switcherRect('min').y, 444);
// The true centre is the viewport's own with the window centred.
assert.equal(g.screenCenterInViewportX(), 288);
// Depth applies only here.
g.settings.uiDepthSetting.value = '-48';
assert.equal(g.uiDepth(), -48);
// Full panel: windows fill the panel and the row overlays the bottom edge while focused.
g.settings.displayModeSetting.value = '640x480';
assert.deepEqual(g.rect('max'), { x: 0, y: 28, width: 640, height: 452 });
assert.deepEqual({ ...g.switcherRect('max') }, { x: 0, y: 444, width: 640, height: 36 });
assert.equal(g.sidebarStripVisible('window'), false);
assert.equal(g.sidebarStripVisible('sidebar'), true);
});
// Exercise the real worker message handler with platform work stubbed out.
function resizeHandler(file, globals) {
const source = ts.createSourceFile(file, read(file), ts.ScriptTarget.Latest, true);
@@ -299,6 +299,48 @@ class DisplayListTest {
assertEquals(0, output.get(if (right) 639 else 0, 240)) // cleared, not stale
}
}
@Test fun addedDepthJoinsOrInsertsTheDepthField() {
val copy = DrawProtocol.rectCopy(DrawProtocol.SCREEN, 0, 0, 4, 4, 0, 0)
assertContentEquals(DrawProtocol.rectCopy(DrawProtocol.SCREEN, 0, 0, 4, 4, 0, 0, depth = 8), DrawProtocol.withAddedDepth(copy, 8))
val targeted = DrawProtocol.image(3, 1, 2, target = 5, depth = -2)
assertContentEquals(DrawProtocol.image(3, 1, 2, target = 5, depth = 6), DrawProtocol.withAddedDepth(targeted, 8))
assertSame(copy, DrawProtocol.withAddedDepth(copy, 0))
assertContentEquals(DrawProtocol.image(3, 1, 2, depth = 127), DrawProtocol.withAddedDepth(DrawProtocol.image(3, 1, 2, depth = 120), 16))
}
/** The bottom switcher's Depth setting: the shell scene's depth moves the screen, shell layers and selections together. */
@Test fun shellSceneDepthShiftsTheWholePresentationButNotDimming() {
val c = SurfaceCompositor()
c.configureScreen(640, 480)
c.configureSurface("app", 32, 0, 576, 480, 0, 0)
c.submitSurface("app", ArrayByteReader(ByteArray(576 * 480) { if (it % 576 in 100 until 110) 255.toByte() else 0 }),
0, 0, 576, 480, "stripe")
// One white 2x1 shell layer at (200, 10), dimming what is under it, at layer depth -2; scene depth 8.
val header = listOf(1, 1, 200, 10, 2, 1, 128, 0, -2).flatMap { listOf(it.toByte(), (it shr 8).toByte()) }.toByteArray()
c.setShellScene(ArrayByteReader(header + byteArrayOf(-1, -1) + DrawProtocol.word(8)))
val composite = c.composite()
assertEquals(8, composite.shellScene.screenDepth)
val calls = composite.shellScene.calls(640, 480, intArrayOf(1), IntArray(0))
assertTrue(calls.any { it.contentEquals(DrawProtocol.lut(640, 480, 128)) }) // the dim stays whole-screen
val screen = BmpUtil.pack4bppFromGray8(composite.screenGray, 640, 480)
for (right in listOf(false, true)) {
val glasses = Glasses(right)
glasses.apply(ScenePlanner(ResourceCacheState()).plan(screen, 640, 480, null, composite.shellScene, 1).commands)
val output = DisplayListRenderer.Target(glasses.composition, 640, 480)
// Screen: half of 8 per lens. Layer: depth -2 + 8, so one pixel less than the screen's shift on each lens.
val shift = if (right) -4 else 4
val layerShift = if (right) -3 else 3
assertEquals(0, output.get(131 + shift, 200)); assertTrue(output.get(132 + shift, 200) > 0)
assertTrue(output.get(141 + shift, 200) > 0); assertEquals(0, output.get(142 + shift, 200))
assertEquals(15, output.get(200 + layerShift, 10)); assertEquals(15, output.get(201 + layerShift, 10))
}
// The phone mirror shows the scene unshifted, so touches land where they look.
val preview = assertNotNull(c.previewComposite()).gray
assertEquals(0, preview[131].toInt() and 255); assertTrue((preview[132].toInt() and 255) > 0)
// A covering surface's own depth still wins over the scene's.
c.configureSurface("glance", 0, 0, 640, 480, 900, 0)
c.setSurfaceDepth("glance", -16)
assertEquals(-16, c.composite().shellScene.screenDepth)
}
@Test fun noisyFramesRemainBoundedAndResourceBudgetIs192KiB() {
val cache=ResourceCacheState();val planner=ScenePlanner(cache);val glasses=Glasses()
val app=ByteArray(640*480/2){(it*37).toByte()}
@@ -98,7 +98,7 @@ class FrameDisplayListTest {
// One opaque 1x1 shell layer, with one generic list after its pixels.
val layer = DrawProtocol.word(1) + DrawProtocol.word(1) + DrawProtocol.word(0) + DrawProtocol.word(0) +
DrawProtocol.word(1) + DrawProtocol.word(1) + DrawProtocol.word(256) + DrawProtocol.word(1) +
DrawProtocol.word(0) + byteArrayOf(32) + hex(multi)
DrawProtocol.word(0) + byteArrayOf(32) + hex(multi) + DrawProtocol.word(0)
val shell = ShellScene.decode(ArrayByteReader(layer))
assertEquals(2, shell.retainedResources.size)
assertEquals(240, shell.preview(ByteArray(64) { 32 }, 8, 8)[21].toInt() and 255)
@@ -43,7 +43,7 @@ class PreviewPackingTest {
compositor.configureSurface("app", 0, 0, 3, 2, 0, SurfaceCompositor.TRANSPARENCY_OPAQUE)
// One white 2x1 shell layer at (0,0), with no dimming or selection.
val header = listOf(1, 1, 0, 0, 2, 1, 256, 0, 0).flatMap { listOf(it.toByte(), (it shr 8).toByte()) }.toByteArray()
compositor.setShellScene(ArrayByteReader(header + byteArrayOf(-16, -16)))
compositor.setShellScene(ArrayByteReader(header + byteArrayOf(-16, -16) + DrawProtocol.word(0)))
val wire = compositor.applyAndComposite("app", ArrayByteReader(ByteArray(6) { 32 }), 0, 0, 3, 2, "first")
assertSame(wire.screenGray, wire.gray) // ShellScene.preview allocates its own pixels.
assertContentEquals(ByteArray(6) { 32 }, wire.screenGray)
+2 -1
View File
@@ -79,7 +79,8 @@ test('unselected sidebar icons retain -2 depth through shell cropping, including
'../../native/notification-icons':{},'../../native/phone-battery':{},'../../util/render-freshness':{},
'../../graphics/icons':{},'../dashboard-settings':{},'../clock-format':{},'../../graphics/bdffont':{},
'../layers':{LayerStack},'../menu':{scrollToKeepSelectionVisible:()=>0},'../metrics':{},
'./geometry':{MIN_WINDOW_HEIGHT:280,minWindowTop:()=>0,windowTop:()=>0,SHELL_OPAQUE_BLACK:1,SIDEBAR_WIDTH:64,TOP_BAR_HEIGHT:24},
'./geometry':{MIN_WINDOW_HEIGHT:280,minWindowTop:()=>0,windowTop:()=>0,SHELL_OPAQUE_BLACK:1,SIDEBAR_WIDTH:64,TOP_BAR_HEIGHT:24,
SWITCHER_ROW_HEIGHT:36,switcherPosition:()=>'left',switcherRect:()=>({x:0,y:0,width:64,height:280})},
});
const state={selectedIndex:0,focus:'sidebar',windows:[0,1,2].map(n=>({attention:n===1,drawIcon:(image,x,y)=>image.fillRect(x,y,4,4,240)}))};
const chrome=new ShellChromeLayer(()=>state),image=new graphics.GrayImage(640,480);