Skip to content

Commit ffe8891

Browse files
committed
fix(desktop): only skip thin macOS helper strips
A tall untitled window sharing the main window's width is a real window, not a helper. Cap skipped strips at a quarter of the largest window's height or width, which still covers the Chrome, Brave, and Zed helpers.
1 parent e26c54a commit ffe8891

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎apps/desktop/src/snapShot/ActiveWindow.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ it("skips untitled full-width strips stacked above the main window", async () =>
143143
assert.strictEqual((await activeWindow("darwin"))?.id, 71);
144144
});
145145

146+
it("keeps a tall untitled window that shares the main window's width", async () => {
147+
stubMacLookup(
148+
macLookup([
149+
{ id: 12, title: "", bounds: { x: 0, y: 0, width: 800, height: 900 } },
150+
{ id: 13, title: "Document", bounds: { x: 0, y: 0, width: 800, height: 1_000 } },
151+
]),
152+
);
153+
154+
assert.strictEqual((await activeWindow("darwin"))?.id, 12);
155+
});
156+
146157
it("keeps an untitled frontmost dialog ahead of a titled parent", async () => {
147158
stubMacLookup(
148159
macLookup([

‎apps/desktop/src/snapShot/ActiveWindow.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ const decodeMacActiveWindowLookup = Schema.decodeUnknownSync(
6060

6161
// CoreGraphics returns windows in front-to-back order, but some apps, such as
6262
// Chrome, Brave, and Zed, put transparent or untitled strip windows ahead of
63-
// their real window. Keep that order while ignoring untitled strips that span
64-
// the full width or height of the app's largest window.
63+
// their real window. Keep that order while ignoring untitled thin strips that
64+
// span the full width or height of the app's largest window.
6565
// Window titles need Screen Recording, which the snapshot service has already
6666
// requested by the time this runs.
67+
const MAC_HELPER_STRIP_MAX_THICKNESS_RATIO = 0.25;
6768
const MAC_LOOKUP_SCRIPT = `
6869
ObjC.import("CoreGraphics");
6970
ObjC.import("AppKit");
@@ -140,10 +141,10 @@ async function macActiveWindow(): Promise<ActiveWindow | undefined> {
140141
window.title.trim() === "" &&
141142
((window.bounds.x === largest.bounds.x &&
142143
window.bounds.width === largest.bounds.width &&
143-
window.bounds.height < largest.bounds.height) ||
144+
window.bounds.height <= largest.bounds.height * MAC_HELPER_STRIP_MAX_THICKNESS_RATIO) ||
144145
(window.bounds.y === largest.bounds.y &&
145146
window.bounds.height === largest.bounds.height &&
146-
window.bounds.width < largest.bounds.width));
147+
window.bounds.width <= largest.bounds.width * MAC_HELPER_STRIP_MAX_THICKNESS_RATIO));
147148
const window = visible.find((candidate) => !isAuxiliaryStrip(candidate));
148149
if (!window) return undefined;
149150
return {

0 commit comments

Comments
 (0)