A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Windows/Linux: keep Mochi whole after a monitor change
ZouaouiB852df6f5729f
diff --git a/windows/src/desktop/main.ts b/windows/src/desktop/main.tsindex 8fb9b5be..aa8ac39e 100644--- a/windows/src/desktop/main.ts+++ b/windows/src/desktop/main.ts@@ -210,6 +210,11 @@ class DesktopMochi {engine.setDancing(this.snap.dancing && !this.asleep);engine.update(dt);const dpr = this.dpr();+ // Dragged onto a monitor of another scale, the bitmap follows the ratio.+ if (this.canvas.width !== Math.round(PANEL_SIZE * dpr)) {+ this.canvas.width = Math.round(PANEL_SIZE * dpr);+ this.canvas.height = Math.round(PANEL_SIZE * dpr);+ }ctx.setTransform(dpr, 0, 0, dpr, SIDE * dpr, 0);ctx.clearRect(-SIDE, 0, PANEL_SIZE, PANEL_SIZE);ctx.save();diff --git a/windows/src/island/island.ts b/windows/src/island/island.tsindex 13158dca..9248cce0 100644--- a/windows/src/island/island.ts+++ b/windows/src/island/island.ts@@ -85,6 +85,8 @@ export class Island {private lastFrame = 0;private dirty = true;private canvasPx = 0;+ /** The pixel ratio Mochi's bitmap was sized for: it changes with the monitor. */+ private canvasDpr = 0;// Rust starts the window at full size so the launch greeting has room.private collapsed = false;@@ -1015,6 +1017,10 @@ export class Island {const gctx = this.greetingCanvas.getContext("2d");if (gctx) {const dpr = Math.min(2, window.devicePixelRatio || 1);+ if (this.greetingCanvas.width !== Math.round(EXPANDED_W * dpr)) {+ this.greetingCanvas.width = Math.round(EXPANDED_W * dpr);+ this.greetingCanvas.height = Math.round(150 * dpr);+ }gctx.setTransform(dpr, 0, 0, dpr, 0, 0);this.greeting.draw(gctx);}@@ -1091,8 +1097,11 @@ export class Island {const hCss = w + BOT_OVERHANG;const wCss = w + BOT_SIDE * 2;const dpr = Math.min(2, window.devicePixelRatio || 1);- if (this.canvasPx !== w) {+ // Drawn at the current ratio, so a bitmap sized for another monitor's+ // would show Mochi too big and cut, or too small.+ if (this.canvasPx !== w || this.canvasDpr !== dpr) {this.canvasPx = w;+ this.canvasDpr = dpr;this.botCanvas.width = Math.round(wCss * dpr);this.botCanvas.height = Math.round(hCss * dpr);this.botCanvas.style.width = `${wCss}px`;diff --git a/windows/src/main.ts b/windows/src/main.tsindex b199a83c..0a4f48e2 100644--- a/windows/src/main.ts+++ b/windows/src/main.ts@@ -108,10 +108,22 @@ async function main() {await onEvent<null>("screen-changed", async () => {await checkZoom();void Bridge.reposition();+ island.ensureRunning();});- const mediaQuery = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);- mediaQuery.addEventListener?.("change", () => void checkZoom());+ // A query only matches the ratio it was made for: once it changes, watch the+ // new one, or the next monitor's scale goes unnoticed and the zoom stays wrong.+ // One frame redraws Mochi at the new ratio, even while the loop is idle.+ const watchRatio = () => {+ window+ .matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`)+ .addEventListener?.("change", () => {+ watchRatio();+ void checkZoom();+ island.ensureRunning();+ }, { once: true });+ };+ watchRatio();window.addEventListener("wheel",diff --git a/windows/src/mochi/minibots.ts b/windows/src/mochi/minibots.tsindex f166b823..f904d066 100644--- a/windows/src/mochi/minibots.ts+++ b/windows/src/mochi/minibots.ts@@ -81,6 +81,12 @@ export function tickMiniBots(dt: number) {if (!ctx) continue;mb.engine.setDancing(mb.dancing?.() ?? false);mb.engine.update(dt);+ // Sized at creation: the island may have moved to a monitor of another scale.+ const px = Math.round(mb.cssSize * dpr);+ if (mb.canvas.width !== px) {+ mb.canvas.width = px;+ mb.canvas.height = px;+ }ctx.setTransform(dpr, 0, 0, dpr, 0, 0);ctx.clearRect(0, 0, mb.cssSize, mb.cssSize);ctx.save();diff --git a/windows/src/views/wardrobe.ts b/windows/src/views/wardrobe.tsindex 2395804e..226d6896 100644--- a/windows/src/views/wardrobe.ts+++ b/windows/src/views/wardrobe.ts@@ -35,6 +35,7 @@ export function buildWardrobe(actions: ViewActions): ViewHost {let hovered: OutfitSelection | null = null;let drawnSeason: Outfit | null = null;let drawnLanguage = language();+ let drawnDpr = 0;const items = new Map<OutfitSelection, { button: HTMLButtonElement; canvas: HTMLCanvasElement }>();const updateNote = () => {@@ -67,11 +68,13 @@ export function buildWardrobe(actions: ViewActions): ViewHost {/** Icons are drawn once; only "auto" changes, with the season and its badge's language. */const drawIcons = () => {const season = seasonalOutfit(new Date());- if (season === drawnSeason && drawnLanguage === language()) return;- const first = drawnSeason == null;+ const dpr = Math.min(2, window.devicePixelRatio || 1);+ if (season === drawnSeason && drawnLanguage === language() && drawnDpr === dpr) return;+ // On a monitor of another scale every icon is drawn again, sharp and whole.+ const first = drawnSeason == null || drawnDpr !== dpr;drawnSeason = season;drawnLanguage = language();- const dpr = Math.min(2, window.devicePixelRatio || 1);+ drawnDpr = dpr;for (const [sel, { canvas }] of items) {if (!first && sel !== "auto") continue;canvas.width = Math.round(ICON * dpr);