Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 36 additions & 29 deletions openless-all/app/src-tauri/src/tauri_coordinator_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn capsule_transcript_rail_position(
translation_active: bool,
transcript_visible: bool,
) -> Option<CapsuleTranscriptRailPosition> {
if !transcript_visible && (!translation_active || style == CapsuleStyle::Siri) {
if !transcript_visible && (!translation_active || matches!(style, CapsuleStyle::Siri | CapsuleStyle::Classic)) {
return None;
}
match style {
Expand All @@ -76,16 +76,9 @@ fn capsule_transcript_rail_position(
const BODY_HEIGHT: f64 = 32.0;
const RAIL_HEIGHT: f64 = 52.0;
const RAIL_GAP: f64 = 24.0;
const BADGE_HEIGHT: f64 = 28.0;
const BADGE_GAP: f64 = 8.0;
let body_top = HOST_HEIGHT - BODY_BOTTOM_INSET - BODY_HEIGHT;
let gap = RAIL_GAP;
let height = if transcript_visible { RAIL_HEIGHT } else { 0.0 }
+ if translation_active {
BADGE_HEIGHT + if transcript_visible { BADGE_GAP } else { 0.0 }
} else {
0.0
};
let height = RAIL_HEIGHT;
let top_offset = body_top - RAIL_GAP - height;
Some(CapsuleTranscriptRailPosition {
width: 460.0,
Expand Down Expand Up @@ -180,14 +173,21 @@ fn capsule_control_hit_rect(
),
CapsuleStyle::Siri => unreachable!(),
};
let _ = transcript_visible;
let scale =
(window_width as f64 / logical_host_width).min(window_height as f64 / logical_host_height);
// Windows clips the native input region as well as CSS. Include the language
// picker only while translation is active; the transcript remains click-through.
// picker (at the top above any transcript rail) only while translation is
// active; the transcript itself remains in the click-through rail HWND.
let picker_visible = style == CapsuleStyle::Classic && translation_active;
let interactive_width = if picker_visible { 260.0 } else { logical_body_width };
let interactive_height = logical_body_height + if picker_visible { 36.0 } else { 0.0 };
let interactive_height = if picker_visible {
logical_body_height
+ 24.0
+ 28.0
+ if transcript_visible { 52.0 + 8.0 } else { 0.0 }
Comment on lines +181 to +185

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the transcript lane outside the capsule input region

On Windows, recording a translation with the live transcript visible now expands the interactive capsule region across the entire transcript lane: at 1× scale it spans x=100..360 and y=12..156, including the rail at y=48..100. Although the separate rail HWND ignores cursor events, the capsule HWND underneath does not: capsule_hit_test_subclass_proc passes hits inside this rectangle to DefSubclassProc. Consequently, clicking the center of the transcript or the transparent gap below it no longer reaches the application underneath. Use separate badge and body regions, with matching hit testing, rather than making the intervening transcript lane interactive.

Useful? React with 👍 / 👎.

} else {
logical_body_height
};
let scale =
(window_width as f64 / logical_host_width).min(window_height as f64 / logical_host_height);
let body_width = (interactive_width * scale).round() as i32;
let body_height = (interactive_height * scale).round() as i32;
let bottom_inset = (logical_bottom_inset * scale).round() as i32;
Expand Down Expand Up @@ -3030,8 +3030,8 @@ mod tests {
capsule_transcript_rail_position(CapsuleStyle::Classic, true, true),
Some(CapsuleTranscriptRailPosition {
width: 460.0,
height: 88.0,
top_offset: 12.0,
height: 52.0,
top_offset: 48.0,
gap: 24.0,
})
);
Expand Down Expand Up @@ -3060,21 +3060,10 @@ mod tests {
] {
assert_eq!(capsule_transcript_rail_position(style, false, false), None);
}
let classic_badge =
capsule_transcript_rail_position(CapsuleStyle::Classic, true, false).unwrap();
assert_eq!(
(classic_badge.height, classic_badge.top_offset),
(28.0, 72.0)
capsule_transcript_rail_position(CapsuleStyle::Classic, true, false),
None
);
let body_top = 172.0 - 16.0 - 32.0;
let body_bottom = 172.0 - 16.0;
let lobe_top = body_top - 8.0 - 10.0;
let lobe_bottom = lobe_top + 20.0;
let badge_bottom = classic_badge.top_offset + classic_badge.height;
assert_eq!((body_top, body_bottom), (124.0, 156.0));
assert_eq!(body_top - badge_bottom, 24.0);
assert!(badge_bottom <= lobe_top, "the badge must clear the processing lobe");
assert_eq!(lobe_bottom - body_top, 2.0);
let typeless_badge =
capsule_transcript_rail_position(CapsuleStyle::Typeless, true, false).unwrap();
assert!((typeless_badge.height - 20.0 * 0.447).abs() < 1e-12);
Expand Down Expand Up @@ -3106,6 +3095,24 @@ mod tests {
bottom: 156,
})
);
assert_eq!(
capsule_control_hit_rect(CapsuleStyle::Classic, false, true, 460, 172),
Some(CapsuleHitTestRect {
left: 100,
right: 360,
top: 72,
bottom: 156,
})
);
assert_eq!(
capsule_control_hit_rect(CapsuleStyle::Classic, true, true, 460, 172),
Some(CapsuleHitTestRect {
left: 100,
right: 360,
top: 12,
bottom: 156,
})
);
let typeless = capsule_control_hit_rect(CapsuleStyle::Typeless, true, true, 206, 65)
.expect("translation typeless hit rect");
assert_eq!((typeless.left, typeless.right), (51, 155));
Expand Down
51 changes: 28 additions & 23 deletions openless-all/app/src/lib/capsuleLayout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ assertEqual(
);
assertEqual(
getClassicTranslationBadgeOffset(true, false),
0,
'Classic external rail uses its own badge lane instead of same-window offset',
60,
'Classic external rail keeps the same top badge offset as macOS',
);
const classicExternalGeometry = getClassicCapsuleGeometry('win', true, true, false);
assertEqual(classicExternalGeometry.hostHeight, 172, 'Classic external rail uses the 172px host');
Expand All @@ -153,21 +153,21 @@ assertEqual(
);
assertEqual(
classicExternalGeometry.railTop,
12,
'Classic external rail clears the translation badge lane',
48,
'Classic external rail keeps the middle rail anchor below the badge',
);
assertEqual(classicExternalGeometry.badgeTop, 72, 'Classic external badge sits above the pill');
assertEqual(classicExternalGeometry.badgeTop, 12, 'Classic external badge sits at the very top');
assertEqual(
classicExternalGeometry.badgeBottom,
100,
'Classic external badge leaves a 24px body gap for the processing lobe',
40,
'Classic external badge clears the 52px transcript rail and 8px gap',
);
if (
classicExternalGeometry.badgeBottom + 8 > classicExternalGeometry.railTop! ||
classicExternalGeometry.railTop! + classicExternalGeometry.railHeight >
classicExternalGeometry.badgeTop ||
classicExternalGeometry.badgeBottom > classicExternalGeometry.bodyTop
classicExternalGeometry.bodyTop
) {
throw new Error('Classic external rail and translation badge must not overlap');
throw new Error('Classic external badge, rail, and body must not overlap');
}
const classicSameWindowGeometry = getClassicCapsuleGeometry('win', true, true, true);
assertEqual(
Expand All @@ -178,12 +178,17 @@ assertEqual(
assertEqual(classicSameWindowGeometry.badgeBottom, 40, 'Classic same-window badge clears the rail');
for (const os of ['mac', 'win'] as const) {
const external = getClassicCapsuleGeometry(os, true, true, false);
if (
external.railTop! + external.railHeight > external.badgeTop ||
external.badgeBottom > external.bodyTop
) {
throw new Error(`${os}: external Classic rail and badge overlap`);
}
const sameWindow = getClassicCapsuleGeometry(os, true, true, true);
assertEqual(
external.badgeTop,
sameWindow.badgeTop,
`${os}: external and same-window Classic badgeTop must match`,
);
assertEqual(
external.railTop,
sameWindow.railTop,
`${os}: external and same-window Classic railTop must match`,
);
}
assertEqual(
getClassicProcessingLabel(false),
Expand Down Expand Up @@ -212,20 +217,20 @@ assertEqual(
);
assertEqual(
getCapsuleTranscriptRailPosition('classic', true, true)?.topOffset,
12,
'Classic translation external rail clears the explicit badge lane',
48,
'Classic translation external rail stays at 48px below the top badge',
);
const typelessCompactRail = getCapsuleTranscriptRailPosition('typeless', false, true);
const typelessTranslationRail = getCapsuleTranscriptRailPosition('typeless', true, true);
assertEqual(
getCapsuleTranscriptRailPosition('classic', true, false)?.height,
28,
'Classic translation remains in the click-through overlay with transcript disabled',
getCapsuleTranscriptRailPosition('classic', true, false),
null,
'Classic hides the click-through rail when transcript is not visible',
);
assertEqual(
getCapsuleTranscriptRailPosition('classic', true, true)?.height,
88,
'Classic overlay includes both the rail and the translation badge',
52,
'Classic overlay only hosts the 52px transcript rail',
);
assertClose(
getCapsuleTranscriptRailPosition('typeless', true, false)?.height ?? 0,
Expand Down
32 changes: 12 additions & 20 deletions openless-all/app/src/lib/capsuleLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ export interface ClassicCapsuleGeometry {

/**
* Classic uses one 172px layout coordinate system on desktop. The body, badge
* lane, and a sibling rail each get an explicit vertical anchor so an external
* rail is not treated as a missing same-window rail.
* lane, and transcript rail keep the exact same vertical stacking on macOS and
* Windows: translation badge at the very top, transcript rail in the middle,
* and the capsule body at the bottom.
*/
export function getClassicCapsuleGeometry(
os: OS,
Expand All @@ -69,22 +70,16 @@ export function getClassicCapsuleGeometry(
transcriptInSameWindow: boolean,
): ClassicCapsuleGeometry {
void os;
void transcriptInSameWindow;
const pillHeight = 32;
const hostHeight = CLASSIC_CAPSULE_HOST_HEIGHT;
const bodyBottom = hostHeight - CLASSIC_CAPSULE_BOTTOM_INSET;
const bodyTop = bodyBottom - pillHeight;
const railHeight = getCapsuleTranscriptRailHeight('classic');
const sameWindowRail = transcriptVisible && transcriptInSameWindow;
const externalBadgeLane = transcriptVisible && !transcriptInSameWindow && translationActive;
const railTop = transcriptVisible
? bodyTop -
CLASSIC_CAPSULE_RAIL_GAP -
railHeight -
(externalBadgeLane ? CLASSIC_CAPSULE_BADGE_HEIGHT + CLASSIC_CAPSULE_BADGE_GAP : 0)
: null;
const railTop = transcriptVisible ? bodyTop - CLASSIC_CAPSULE_RAIL_GAP - railHeight : null;
const badgeBottom =
bodyTop -
(sameWindowRail && translationActive
(transcriptVisible && translationActive
? CLASSIC_CAPSULE_BADGE_GAP + railHeight + CLASSIC_CAPSULE_RAIL_GAP
: CLASSIC_CAPSULE_RAIL_GAP);
const badgeTop = badgeBottom - CLASSIC_CAPSULE_BADGE_HEIGHT;
Expand All @@ -104,8 +99,8 @@ export function getCapsuleTranscriptRailHeight(style: CapsuleStyle): number {
return CAPSULE_TRANSCRIPT_RAIL_HEIGHTS[style];
}

/** Classic's translating badge lives above the body and must also clear the
* external 52px rail when the rail is hosted in a sibling HWND. */
/** Classic's translating badge lives at the top above the body and clears the
* 52px transcript rail (plus its 8px gap) whenever the rail is visible. */
export function getClassicTranslationBadgeOffset(
transcriptVisible: boolean,
transcriptInSameWindow = true,
Expand Down Expand Up @@ -151,7 +146,8 @@ export function getCapsuleTranscriptRailPosition(
translationActive: boolean,
transcriptVisible: boolean,
): CapsuleTranscriptRailPosition | null {
if (!transcriptVisible && (!translationActive || style === 'siri')) return null;
if (!transcriptVisible && (!translationActive || style === 'siri' || style === 'classic'))
return null;
if (style === 'siri') {
const bodyTop = 0;
const railHeight = 40;
Expand All @@ -163,12 +159,8 @@ export function getCapsuleTranscriptRailPosition(
const gap = CLASSIC_CAPSULE_RAIL_GAP;
return {
width: 460,
height:
(transcriptVisible ? geometry.railHeight : 0) +
(translationActive
? CLASSIC_CAPSULE_BADGE_HEIGHT + (transcriptVisible ? CLASSIC_CAPSULE_BADGE_GAP : 0)
: 0),
topOffset: geometry.railTop ?? geometry.badgeTop,
height: geometry.railHeight,
topOffset: geometry.railTop!,
gap,
};
}
Expand Down
Loading