forked from Blendman974/faceclaw
Crop screenshots
This commit is contained in:
1 parent
0f4adb0e86
commit
1ec6b3ff83
5 files changed
+85
-10
No files matched your search
@@ -511,6 +511,31 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
return ScreenshotUtil.savePngScreenshot(appContext, composite.gray, composite.width, composite.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the current composite cropped to the given screen rect (the region
|
||||
* the shell says is actually occupied). The rect is clamped to the screen;
|
||||
* a degenerate rect falls back to the full screen.
|
||||
*/
|
||||
public String saveCompositePngScreenshot(int cropX, int cropY, int cropWidth, int cropHeight)
|
||||
throws java.io.IOException {
|
||||
SurfaceCompositor.Composite composite = compositor.previewComposite();
|
||||
if (composite == null) {
|
||||
return "";
|
||||
}
|
||||
int x = Math.max(0, cropX);
|
||||
int y = Math.max(0, cropY);
|
||||
int width = Math.min(composite.width - x, cropWidth - (x - cropX));
|
||||
int height = Math.min(composite.height - y, cropHeight - (y - cropY));
|
||||
if (width <= 0 || height <= 0 || (x == 0 && y == 0 && width == composite.width && height == composite.height)) {
|
||||
return ScreenshotUtil.savePngScreenshot(appContext, composite.gray, composite.width, composite.height);
|
||||
}
|
||||
byte[] cropped = new byte[width * height];
|
||||
for (int row = 0; row < height; row++) {
|
||||
System.arraycopy(composite.gray, (y + row) * composite.width + x, cropped, row * width, width);
|
||||
}
|
||||
return ScreenshotUtil.savePngScreenshot(appContext, cropped, width, height);
|
||||
}
|
||||
|
||||
// Active animated-GIF screen recording, or null when idle. Frames are
|
||||
// pushed by recordScreenFrame(), which the TS side calls at each
|
||||
// phone-preview flush.
|
||||
|
||||
@@ -726,9 +726,9 @@ class DashboardController {
|
||||
void this.communicator.setBrightness(level === null, level ?? 0).catch(() => {});
|
||||
}
|
||||
|
||||
/** Save the current composited screen as a 4-bit grayscale PNG. */
|
||||
/** Save the occupied part of the composited screen as a 4-bit grayscale PNG. */
|
||||
saveScreenshot(): string {
|
||||
const path = this.communicator?.saveScreenshot() ?? "";
|
||||
const path = this.communicator?.saveScreenshot(shell.screenshotCropRect()) ?? "";
|
||||
this.appendLog(path ? `screenshot saved: ${path}` : "screenshot skipped: not connected");
|
||||
return path;
|
||||
}
|
||||
|
||||
@@ -429,9 +429,17 @@ export class FaceclawCommunicatorBridge {
|
||||
}
|
||||
|
||||
/** Save the current composite as a 4-bit grayscale PNG; returns the path (empty if none). */
|
||||
saveScreenshot(): string {
|
||||
saveScreenshot(crop?: { x: number; y: number; width: number; height: number }): string {
|
||||
if (!global.isAndroid) return "";
|
||||
return String(this.communicator.saveCompositePngScreenshot());
|
||||
if (!crop) return String(this.communicator.saveCompositePngScreenshot());
|
||||
return String(
|
||||
this.communicator.saveCompositePngScreenshot(
|
||||
Math.round(crop.x),
|
||||
Math.round(crop.y),
|
||||
Math.round(crop.width),
|
||||
Math.round(crop.height),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/** Begin collecting composite frames for an animated-GIF screen recording. */
|
||||
|
||||
@@ -25,6 +25,24 @@ const ICON_MARGIN_X = ((SIDEBAR_COLUMN_WIDTH - ICON_SIZE) / 2) | 0;
|
||||
/** Column index of the rightmost sidebar column (the one that fills first). */
|
||||
const FIRST_COLUMN = SIDEBAR_COLUMNS - 1;
|
||||
const ICON_SPACING = 8;
|
||||
const ICON_STRIDE = ICON_SIZE + ICON_SPACING;
|
||||
/** Icon list top/bottom margins within the sidebar band, below the top bar. */
|
||||
const LIST_MARGIN = 10;
|
||||
/** Icon rows that fit in one sidebar column. */
|
||||
const ROWS_PER_COLUMN = Math.max(
|
||||
1,
|
||||
((MIN_WINDOW_HEIGHT - TOP_BAR_HEIGHT - 2 * LIST_MARGIN + ICON_SPACING) / ICON_STRIDE) | 0,
|
||||
);
|
||||
|
||||
/**
|
||||
* Whether the sidebar's left (overflow) column holds any icons. Icons fill
|
||||
* the right column first; scrolling never shows fewer than a full right
|
||||
* column, so the left column is populated exactly when there are more
|
||||
* windows than one column holds.
|
||||
*/
|
||||
export function sidebarLeftColumnUsed(windowCount: number): boolean {
|
||||
return windowCount > ROWS_PER_COLUMN;
|
||||
}
|
||||
const NOTIFICATION_ICON_SIZE = 24;
|
||||
const BORDER_VALUE = 40;
|
||||
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
||||
@@ -128,10 +146,9 @@ export class ShellChromeLayer implements Layer {
|
||||
// windows off-screen above/below. Icons fill the right column top to
|
||||
// bottom, then overflow into the left one, so a visible slot's column is
|
||||
// decided by its position within the scrolled window.
|
||||
const listTop = bandTop + TOP_BAR_HEIGHT + 10;
|
||||
const itemStride = ICON_SIZE + ICON_SPACING;
|
||||
const listHeight = bandBottom - listTop - 10;
|
||||
const rowsPerColumn = Math.max(1, ((listHeight + ICON_SPACING) / itemStride) | 0);
|
||||
const listTop = bandTop + TOP_BAR_HEIGHT + LIST_MARGIN;
|
||||
const itemStride = ICON_STRIDE;
|
||||
const rowsPerColumn = ROWS_PER_COLUMN;
|
||||
const visibleCount = rowsPerColumn * SIDEBAR_COLUMNS;
|
||||
const count = state.windows.length;
|
||||
this.scrollRow = scrollToKeepSelectionVisible(this.scrollRow, state.selectedIndex, visibleCount, count);
|
||||
|
||||
+27
-2
@@ -24,11 +24,19 @@ import {
|
||||
timeFormatSetting,
|
||||
wakeWordActionSetting,
|
||||
} from "../dashboard-settings";
|
||||
import { ShellChromeLayer, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer";
|
||||
import { ShellChromeLayer, sidebarLeftColumnUsed, type ShellChromeState, type ShellChromeWindow } from "./chrome-layer";
|
||||
import { ShellModalLayer } from "./modal-layer";
|
||||
import { ToolDebugMenuLayer } from "./tool-debug-layer";
|
||||
import { toolRegistry } from "../../assistant/tool-registry";
|
||||
import { minWindowTop, SIDEBAR_WIDTH, TOP_BAR_HEIGHT, type WindowHeightMode } from "./geometry";
|
||||
import {
|
||||
MIN_WINDOW_HEIGHT,
|
||||
minWindowTop,
|
||||
SIDEBAR_COLUMN_WIDTH,
|
||||
SIDEBAR_WIDTH,
|
||||
TOP_BAR_HEIGHT,
|
||||
windowTop,
|
||||
type WindowHeightMode,
|
||||
} from "./geometry";
|
||||
|
||||
/**
|
||||
* The shell: owns the window registry, focus, screen on/off, and the shell
|
||||
@@ -573,6 +581,23 @@ class Shell {
|
||||
return this.windows[this.selectedIndex] ?? this.windows[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Screen rect actually occupied by content, for cropping screenshots: the
|
||||
* foreground window's band (full screen for a max-height window, the
|
||||
* vertical-position-dependent 288px band otherwise), minus the sidebar's
|
||||
* left column when no icons have overflowed into it.
|
||||
*/
|
||||
screenshotCropRect(): { x: number; y: number; width: number; height: number } {
|
||||
const heightMode = this.foregroundWindow()?.heightMode ?? "min";
|
||||
const x = sidebarLeftColumnUsed(this.windows.length) ? 0 : SIDEBAR_COLUMN_WIDTH;
|
||||
return {
|
||||
x,
|
||||
y: windowTop(heightMode),
|
||||
width: G2_LENS_WIDTH - x,
|
||||
height: heightMode === "max" ? G2_LENS_HEIGHT : MIN_WINDOW_HEIGHT,
|
||||
};
|
||||
}
|
||||
|
||||
/** Whether a window is the current input target (foreground + focus in-window). */
|
||||
isWindowFocused(windowId: string): boolean {
|
||||
return this.screenOn && this.focus === "window" && this.foregroundWindow()?.windowId === windowId;
|
||||
|
||||
Reference in new issue
Block a user