From f306bd41bd2930a8039ec5dc582051998166f172 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:50:05 -0500 Subject: [PATCH 1/4] fix(gpui): mirror the teleprompter script when Mirror text is on --- apps/desktop-gpui/README.md | 4 +- apps/desktop-gpui/patches/zed-mirror.patch | 139 +++++++++++++++++++ apps/desktop-gpui/src/teleprompter_window.rs | 110 ++++++++++++--- apps/desktop-gpui/src/ui/text_input.rs | 63 +++++++++ scripts/prepare-gpui-dependency.sh | 1 + scripts/prepare-gpui-dependency.test.mjs | 2 + 6 files changed, 300 insertions(+), 19 deletions(-) create mode 100644 apps/desktop-gpui/patches/zed-mirror.patch diff --git a/apps/desktop-gpui/README.md b/apps/desktop-gpui/README.md index d13e0114602..17a4c49a243 100644 --- a/apps/desktop-gpui/README.md +++ b/apps/desktop-gpui/README.md @@ -651,7 +651,7 @@ Sizes are the Tauri app's, from `apps/desktop/src-tauri/src/windows.rs`. | Settings → Feedback → Diagnostic Report | — | **Done, with deviations** — the A/V sync self-test driven as a `cap selftest av-sync --progress-json` subprocess (it needs the process main thread gpui owns), a mode segmented control and a Test microphone toggle, live per-stage progress and Cancel, a PASS/WARN/FAIL/INCONCLUSIVE verdict chip with the run's summary, the full `cap_recording::diagnostics` environment report written to `/diagnostics/` and pruned to five, and Send to Cap / Show File. Upload Logs under Debug Information is live too, now that the app writes a rolling `cap-gpui.log`. Deviations: fixed 20s duration, no `--mic-name`, no in-flight-recording guard, inline status instead of a toast — see below | | Upgrade | 950×850 | Not started | | Onboarding | dynamic, 860–1080 wide | Not started | -| Teleprompter | 560×320 | **Done, with deviations** — resizable to the 420×220 floor, level 101 on all Spaces, the `"teleprompter"` material at radius 22, traffic lights at (14, 11) — the Tauri `(14, 14)` is a `position_window_controls` inset, not a top-left, auto-scroll from the ported `teleprompter-utils` maths, the full footer and settings popover, native window opacity, the `teleprompter` store section, capture exclusion + content protection. The script editor is a real multi-line field and Mirror is inert — see below | +| Teleprompter | 560×320 | **Done, with deviations** — resizable to the 420×220 floor, level 101 on all Spaces, the `"teleprompter"` material at radius 22, traffic lights at (14, 11) — the Tauri `(14, 14)` is a `position_window_controls` inset, not a top-left, auto-scroll from the ported `teleprompter-utils` maths, the full footer and settings popover, native window opacity, the `teleprompter` store section, capture exclusion + content protection. The script editor is a real multi-line field, and Mirror flips the script the way `scale-x-[-1]` did (see below) | | Editor | 1275×800 | **E1–E5 done — window, shell, playback, timeline, editing, config sidebar.** The real 1275×800 window with the traffic lights at (20, 20) — the Tauri `(20, 32)` is a `position_window_controls` inset, not a top-left, the header, the letterboxed player, the 260px timeline strip and the 416px config sidebar with its six-tab rail; a real project through `EditorInstance`; play/pause (button + Space), a 60fps live playhead and clock, real audio, click/drag seeking, end-of-media stop; the timeline at 1:1 — all nine track types from the project's own config, waveforms, the ruler's resolution ladder, minimap, edge fade, hover ghost, zoom (keys, buttons, slider, wheel, pinch) and pan; and **timeline editing**: selection (single, ⌘-multi, ⇧-range, ⌘A), trim, move, split (S + C, with snapping), zoom-segment create/resize/move, delete, undo/redo and the debounced write back to `project-config.json`. and **the config sidebar in full**: the six-tab rail, the scroll body, selection routing, all six tabs at 1:1, the shared colour-correction section on both its targets, and the eight per-segment panels with multi-select where the source has it. Crop and export are the remaining units | | Screenshot editor | 1240×800 (min 800×600) | **Done, with deviations** — the real window (native traffic lights, resizable to the 800×600 floor), one editor per bundle keyed like the video editor's registry, opened from capture, Recents, the settings Screenshots page, the tray's Previous and image import. The still renders through the same GPU path the Tauri instance uses (`FrameRenderer::render_immediate`, `preserve_screen_alpha`, no camera) on a config watch, painted with `paint_image` instead of shipped over the frame websocket; edits publish to the renderer live, ride the 1000ms debounced `project-config.json` write, and walk a real undo history (⌘Z / ⌘⇧Z / ⌘Y, a drag's sixty intermediate values collapsed into one entry). Styling: background source tabs (color swatches, gradient presets, wallpaper grid with theme tabs and cached thumbnails, image picker), hex fields, blur/padding/rounding/shadow sliders at the popovers' ranges plus the advanced-shadow collapsible, squircle/rounded corner style, border toggle + width/color/opacity, aspect-ratio menu. Annotations: the full engine — all seven tools with their single-key shortcuts, the frame-space geometry of `layout.ts`/`arrow.ts` verbatim, selection handles, the per-type config bar (stroke/fill swatches with the colour popover, width/opacity/mask-level/text-size sliders), the layers panel with drag reorder, blur/pixelate masks resampled live off the rendered frame, inline text editing, ⌘C/⌘V duplicate, delete. Crop dialog: the `editor_crop` engine wholesale over `original.png` (`screenshot_crop.rs`) — Size/Position number boxes, the round ratio button and its options menu (right-click opens the same one at the cursor) with the snap-to-ratio toggle persisted in the shared store, Full/Reset, arrow-key nudges, one history entry on Save, Escape/backdrop cancel. Export: Copy/Save/Share all bake the annotations in (`screenshot_export.rs` — the `renderScreenshotExportCanvas` pass: masks re-filtered at export scale from an unmodified copy, shapes via tiny-skia, text via cosmic-text at the preview's Helvetica baseline, the output expanded to the union of image and annotation boxes with the source's white-fill rules); Copy composites over white and lands PNG on the clipboard, Save writes PNG, Share fingerprints the config (`sha256` over recursively key-sorted JSON), short-circuits to the stored link on a hash match, and otherwise uploads JPEG-0.9 (PNG when transparency is actually needed) through create-or-get + presigned PUT — reusing `sharing.id` so the link survives edits — then persists `SharingMeta { id, link, content_hash }`, with Tauri's exact auth gates and toast ladder; reveal, delete behind a native confirm. Deviations: no OCR text-selection overlay (Vision OCR feeding an invisible DOM-style selectable text layer has no gpui equivalent yet; the layer is invisible in the Tauri editor too, so zero visual impact); the colour swatches are inert — no native colour panel is wired to this window, the hex fields are the input; the skeleton's Cap logo is drawn still (the app ships no bare glyph to spin, only the full lockup); the crop options menu has no separator row (`ui::Menu` has none, so its two groups sit adjacent); no `PendingScreenshots` in-memory hand-off (the PNG is on disk before the editor opens) | | Tray (status item) | menu bar | **Done, with deviations** — a native `NSStatusItem` (no gpui API exists for one; built on AppKit with the color-panel channel discipline), menu in `build_menu`'s own grouping: Open Main Window; the current mode as the group label (an `NSMenu` section header reading e.g. `Studio` plus a palette item with the mode icons on macOS 14+ (the header follows the palette's highlight in italic), a ✓-ticked `Recording Mode ▸` submenu on older macOS and on Windows); Record Display/Window/Area + Take a Screenshot (screenshot-mode relabels); Previous ▸ (clock glyph) with 32px cover-cropped thumbnails and the 🎬⚡📷 prefixes, View all recordings / screenshots; Import Media…, Settings (⌘,), Upload Logs; Quit Cap with the version as a trailing section header on macOS and as a disabled row above Quit elsewhere. The four record rows, Previous ▸, Import Media… and Settings each carry an SF Symbol (`display`, `interface.window` (`macwindow` below macOS 26), `rectangle.dashed`, `camera.on.rectangle`, `clock.arrow.circlepath`, `square.and.arrow.down`, `gear`) drawn straight from the system catalog on macOS 11+ with no fallback — an unresolvable name leaves the row bare — while Windows draws the cached 32×32 raster of the same SVG their in-app buttons use (`ROW_ICON_SOURCES` / `svg_icon_png`); the macOS glyphs are template images the menu tints, and Previous's own rows keep their photo thumbnails; the chrome rows (Open Main Window, View all …, Upload Logs, Quit) stay bare. The icon follows the mode and becomes the stop icon while recording, when clicking the item stops the capture (the menu is detached so the button's action can fire). The mode picker writes the same `recording_settings.mode` store key the Tauri app reads. Take a Screenshot captures the display under the cursor and Import Media… routes video/image imports; a Previous screenshot opens the screenshot editor. Deviations: Upload Logs renders disabled (no log-upload infrastructure yet) | @@ -1135,7 +1135,7 @@ Teleprompter-specific deviations: | | | |---|---| | **The script editor keeps its own selection wash** | It is `ui::TextInput` in its multi-line shape now (see [Text input](#text-input)) — wrapping, click-to-position, arrow and word motion, selection, the clipboard, undo. The one deliberate difference from the rest of the app is the selection colour: bare glass takes `gray-12` at 25 % rather than the macOS-blue accent the settings fields use, because there is no accent token on this surface. `state.script` stays the mirror the word count, the auto-scroll maths and the debounced store write read. | -| **Mirror is persisted but inert** | `scale-x-[-1]` needs a flip transform on painted *text*, and this gpui rev has none. (The camera bubble solved its version of this with a `VTPixelRotationSession` on the pixel buffers, but the teleprompter mirrors glyphs, not a surface.) The toggle stores `mirror` so the setting survives for the shipping app; nothing on screen changes. | +| **Mirror flips glyphs, not the hit test** | `scale-x-[-1]` mirrors the script about its centre. `patches/zed-mirror.patch` adds `Window::with_mirrored_x`, which paints glyphs through the sprite transformation every renderer already supports, and reflects quads (caret, selection) and text decorations. Hit testing stays unmirrored, so the script field reflects pointer positions and its IME candidate box itself (`TextInputState::set_mirrored`). Colour emoji sit at their mirrored place but keep their own orientation, since polychrome sprites carry no transformation. | | **The vignette is a wash, not a mask** | The script area's `mask-image` fades the *glyphs'* alpha to 0.4 at the top and bottom. With no mask hook, two `gray-1` gradient layers over the same 34% / 66% stops stand in. Over vibrancy that is nearly the same picture; over Liquid Glass it tints the backdrop instead of the text. | | **No backdrop blur** | The settings popover is `bg-gray-1/80` *plus* `backdrop-blur-2xl`, and the footer pills add their own `backdrop-blur-xl`. The washes are here, the blur is not — the same missing hook as the header's `backdrop-filter` and the recording overlay's `backdrop-blur-xs`. | | **No letter-spacing** | The script is `tracking-[-0.025em]` in the TSX; this gpui rev exposes no letter-spacing, so it renders at the font's own tracking. | diff --git a/apps/desktop-gpui/patches/zed-mirror.patch b/apps/desktop-gpui/patches/zed-mirror.patch new file mode 100644 index 00000000000..aef7d7235ef --- /dev/null +++ b/apps/desktop-gpui/patches/zed-mirror.patch @@ -0,0 +1,139 @@ +diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs +--- a/crates/gpui/src/window.rs ++++ b/crates/gpui/src/window.rs +@@ -1188,6 +1188,7 @@ + pub(crate) rendered_entity_stack: Vec, + pub(crate) element_offset_stack: Vec>, + pub(crate) element_opacity: f32, ++ pub(crate) element_mirror_x: Option, + pub(crate) edge_fade: Option, + pub(crate) content_mask_stack: Vec>, + pub(crate) requested_autoscroll: Option>, +@@ -1928,6 +1929,7 @@ + element_offset_stack: Vec::new(), + content_mask_stack: Vec::new(), + element_opacity: 1.0, ++ element_mirror_x: None, + edge_fade: None, + requested_autoscroll: None, + rendered_frame: Frame::new(DispatchTree::new(cx.keymap.clone(), cx.actions.clone())), +@@ -3623,6 +3625,41 @@ + let result = f(self); + self.element_offset_stack.pop(); + result ++ } ++ ++ /// Paints `f` mirrored left to right about the vertical line at `axis`, in ++ /// window coordinates, the way CSS `scale-x: -1` mirrors an element about ++ /// its centre. Glyphs are flipped; quads, underlines and strikethroughs ++ /// are reflected; emoji are placed mirrored but keep their orientation. ++ /// Hit testing is not mirrored, so an element that maps pointer positions ++ /// to content must reflect them itself. Nested calls do not compose: the ++ /// innermost axis applies. ++ pub fn with_mirrored_x( ++ &mut self, ++ axis: Option, ++ f: impl FnOnce(&mut Self) -> R, ++ ) -> R { ++ let Some(axis) = axis else { ++ return f(self); ++ }; ++ let previous = self.element_mirror_x.replace(axis); ++ let result = f(self); ++ self.element_mirror_x = previous; ++ result ++ } ++ ++ /// The mirror axis doubled, in device pixels and whole, so a reflected ++ /// glyph or quad that was pixel-aligned stays pixel-aligned. ++ fn mirror_span_scaled(&self) -> Option { ++ self.element_mirror_x ++ .map(|axis| ScaledPixels((axis.0 * 2. * self.scale_factor()).round())) ++ } ++ ++ fn mirror_x(&self, x: Pixels, width: Pixels) -> Pixels { ++ match self.mirror_span_scaled() { ++ Some(span) => Pixels(span.0 / self.scale_factor()) - x - width, ++ None => x, ++ } + } + + pub(crate) fn with_element_opacity( +@@ -4273,8 +4310,20 @@ + /// Note that the `quad.corner_radii` are allowed to exceed the bounds, creating sharp corners + /// where the circular arcs meet. This will not display well when combined with dashed borders. + /// Use `Corners::clamp_radii_for_quad_size` if the radii should fit within the bounds. +- pub fn paint_quad(&mut self, quad: PaintQuad) { ++ pub fn paint_quad(&mut self, mut quad: PaintQuad) { + self.invalidator.debug_assert_paint(); ++ ++ if self.element_mirror_x.is_some() { ++ quad.bounds.origin.x = self.mirror_x(quad.bounds.origin.x, quad.bounds.size.width); ++ let radii = quad.corner_radii.clone(); ++ quad.corner_radii = Corners { ++ top_left: radii.top_right, ++ top_right: radii.top_left, ++ bottom_right: radii.bottom_left, ++ bottom_left: radii.bottom_right, ++ }; ++ std::mem::swap(&mut quad.border_widths.left, &mut quad.border_widths.right); ++ } + + // Scoped edge fades apply PER PIXEL in the fragment shader + // ([`Quad::fade`]); only the uniform element opacity bakes into the +@@ -4395,6 +4444,7 @@ + ) { + self.invalidator.debug_assert_paint(); + ++ let origin = point(self.mirror_x(origin.x, width), origin.y); + let scale_factor = self.scale_factor(); + let thickness = self.snap_stroke(style.thickness); + let height = if style.wavy { +@@ -4430,6 +4480,7 @@ + ) { + self.invalidator.debug_assert_paint(); + ++ let origin = point(self.mirror_x(origin.x, width), origin.y); + let scale_factor = self.scale_factor(); + let height = style.thickness; + let bounds = Bounds { +@@ -4535,8 +4586,9 @@ + size: tile.bounds.size.map(Into::into), + }; + let content_mask = self.snapped_content_mask(); ++ let mirror = self.mirror_span_scaled(); + +- if subpixel_rendering { ++ if subpixel_rendering && mirror.is_none() { + self.next_frame.scene.insert_primitive(SubpixelSprite { + order: 0, + pad: 0, +@@ -4554,7 +4606,12 @@ + content_mask, + color: color.opacity(element_opacity), + tile, +- transformation: TransformationMatrix::unit(), ++ transformation: mirror.map_or_else(TransformationMatrix::unit, |span| { ++ TransformationMatrix { ++ rotation_scale: [[-1., 0.], [0., 1.]], ++ translation: [span.0, 0.], ++ } ++ }), + }); + } + } +@@ -4621,10 +4678,13 @@ + })? + .expect("Callback above only errors or returns Some"); + +- let bounds = Bounds { ++ let mut bounds = Bounds { + origin: integer_origin + raster_bounds.origin.map(Into::into), + size: tile.bounds.size.map(Into::into), + }; ++ if let Some(span) = self.mirror_span_scaled() { ++ bounds.origin.x = span - bounds.origin.x - bounds.size.width; ++ } + let content_mask = self.snapped_content_mask(); + let opacity = self.element_opacity(); + diff --git a/apps/desktop-gpui/src/teleprompter_window.rs b/apps/desktop-gpui/src/teleprompter_window.rs index 8be2fdb22c7..f65d1012b0b 100644 --- a/apps/desktop-gpui/src/teleprompter_window.rs +++ b/apps/desktop-gpui/src/teleprompter_window.rs @@ -576,8 +576,10 @@ fn stepped(fraction: f32, minimum: f32, maximum: f32, step: f32) -> f32 { impl Render for TeleprompterWindow { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { self.sync_appearance(window, cx); + let mirrored = self.state.mirror; self.script_input.update(cx, |input, _| { - input.set_placeholder(tr::dialog::teleprompter::placeholder()) + input.set_placeholder(tr::dialog::teleprompter::placeholder()); + input.set_mirrored(mirrored); }); let theme = self.theme; @@ -719,19 +721,22 @@ impl TeleprompterWindow { // box and measures its own height from the row count, // so the scroller and the auto-scroll maths see exactly // the content height they did before. - div().w_full().px(px(32.)).child( - ui::TextInput::bare(&theme, "script", &self.script_input) - .align(gpui::TextAlign::Center) - .font_weight(FontWeight::MEDIUM) - .text_size(px(state.font_size)) - .line_height(px(state.font_size * state.line_height)) - .text_color(Hsla::from(theme.gray_12)) - // `placeholder:text-gray-8/70` - .placeholder_color(Theme::with_alpha(theme.gray_8, 0.7)) - // Bare glass: `gray-12` at 25 %, the same wash - // the other teleprompter controls use rather - // than the settings accent. - .selection_color(Theme::with_alpha(theme.gray_12, 0.25)), + MirrorX::new( + state.mirror, + div().w_full().px(px(32.)).child( + ui::TextInput::bare(&theme, "script", &self.script_input) + .align(gpui::TextAlign::Center) + .font_weight(FontWeight::MEDIUM) + .text_size(px(state.font_size)) + .line_height(px(state.font_size * state.line_height)) + .text_color(Hsla::from(theme.gray_12)) + // `placeholder:text-gray-8/70` + .placeholder_color(Theme::with_alpha(theme.gray_8, 0.7)) + // Bare glass: `gray-12` at 25 %, the same wash + // the other teleprompter controls use rather + // than the settings accent. + .selection_color(Theme::with_alpha(theme.gray_12, 0.25)), + ), ), ) .child(div().h(px(spacer)).flex_shrink_0()), @@ -1046,9 +1051,6 @@ impl TeleprompterWindow { tr::dialog::teleprompter::mirror(), self.state.mirror, cx.listener(|this, _, window, cx| { - // Persisted, but inert: this gpui rev has no flip - // transform (the camera window's mirror button is - // disabled for the same reason). README deviation. this.state.mirror = !this.state.mirror; this.touch(TeleprompterState::MIRROR, window, cx); cx.notify(); @@ -1106,6 +1108,80 @@ impl TeleprompterWindow { } } +/// `scale-x-[-1]`: paints its child mirrored left to right about its own +/// centre. Hit testing stays unmirrored, so the script field reflects +/// pointer positions itself (`TextInputState::set_mirrored`). +struct MirrorX { + enabled: bool, + child: gpui::AnyElement, +} + +impl MirrorX { + fn new(enabled: bool, child: impl IntoElement) -> Self { + Self { + enabled, + child: child.into_any_element(), + } + } +} + +impl IntoElement for MirrorX { + type Element = Self; + + fn into_element(self) -> Self::Element { + self + } +} + +impl gpui::Element for MirrorX { + type RequestLayoutState = (); + type PrepaintState = (); + + fn id(&self) -> Option { + None + } + + fn source_location(&self) -> Option<&'static core::panic::Location<'static>> { + None + } + + fn request_layout( + &mut self, + _id: Option<&gpui::GlobalElementId>, + _inspector_id: Option<&gpui::InspectorElementId>, + window: &mut Window, + cx: &mut gpui::App, + ) -> (gpui::LayoutId, Self::RequestLayoutState) { + (self.child.request_layout(window, cx), ()) + } + + fn prepaint( + &mut self, + _id: Option<&gpui::GlobalElementId>, + _inspector_id: Option<&gpui::InspectorElementId>, + _bounds: Bounds, + _request_layout: &mut Self::RequestLayoutState, + window: &mut Window, + cx: &mut gpui::App, + ) -> Self::PrepaintState { + self.child.prepaint(window, cx); + } + + fn paint( + &mut self, + _id: Option<&gpui::GlobalElementId>, + _inspector_id: Option<&gpui::InspectorElementId>, + bounds: Bounds, + _request_layout: &mut Self::RequestLayoutState, + _prepaint: &mut Self::PrepaintState, + window: &mut Window, + cx: &mut gpui::App, + ) { + let axis = self.enabled.then(|| bounds.center().x); + window.with_mirrored_x(axis, |window| self.child.paint(window, cx)); + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/apps/desktop-gpui/src/ui/text_input.rs b/apps/desktop-gpui/src/ui/text_input.rs index dfbe702caca..c19b8a257bf 100644 --- a/apps/desktop-gpui/src/ui/text_input.rs +++ b/apps/desktop-gpui/src/ui/text_input.rs @@ -538,6 +538,9 @@ pub struct TextInputState { layout: Rc>>, /// Bounds of the *text* (inside the field's padding), in window space. text_bounds: Option>, + /// Painted mirrored about the text's centre (`Window::with_mirrored_x`), + /// so pointer positions are reflected back before they are mapped. + mirrored: bool, line_height: Pixels, /// Single-line fields scroll horizontally to keep the caret visible. scroll_x: Pixels, @@ -576,6 +579,7 @@ impl TextInputState { disabled: false, layout: Rc::new(RefCell::new(None)), text_bounds: None, + mirrored: false, line_height: px(16.), scroll_x: px(0.), drag: None, @@ -628,6 +632,21 @@ impl TextInputState { self.content.is_empty() } + /// For a field painted inside `Window::with_mirrored_x` about its own + /// centre: clicks, drags and the IME's candidate window follow the + /// mirrored text. + pub fn set_mirrored(&mut self, mirrored: bool) { + self.mirrored = mirrored; + } + + fn reflect_x(&self, x: Pixels, bounds: Bounds) -> Pixels { + if self.mirrored { + bounds.left() + bounds.right() - x + } else { + x + } + } + pub fn set_placeholder(&mut self, placeholder: impl Into) { self.placeholder = placeholder.into(); } @@ -1161,6 +1180,7 @@ impl TextInputState { let Some(bounds) = self.text_bounds else { return 0; }; + let position = point(self.reflect_x(position.x, bounds), position.y); let layout = self.layout.borrow(); let Some(layout) = layout.as_ref() else { return 0; @@ -1432,6 +1452,14 @@ impl EntityInputHandler for TextInputState { let end_x = bounds.left() + align + layout.x_for_offset(range.end, self.line_height) - self.scroll_x; let top = bounds.top() + self.line_height * row as f32; + let (start_x, end_x) = if self.mirrored { + ( + self.reflect_x(end_x, bounds), + self.reflect_x(start_x, bounds), + ) + } else { + (start_x, end_x) + }; Some(Bounds::from_corners( point(start_x, top), point(end_x.max(start_x), top + self.line_height), @@ -3137,6 +3165,41 @@ mod tests { } } + #[gpui::test] + fn a_mirrored_field_maps_pointer_and_ime_positions_through_the_mirror( + cx: &mut gpui::TestAppContext, + ) { + cx.add_empty_window().update(|window, cx| { + let body = measurement_body("mirror me", window, cx); + body.ensure_layout(body.layout_key(window, cx), Some(px(400.)), window, cx); + let bounds = Bounds::new(point(px(100.), px(20.)), size(px(400.), px(45.))); + let x = body + .layout + .borrow() + .as_ref() + .unwrap() + .x_for_offset(3, px(45.)); + body.state.update(cx, |state, _| { + state.text_bounds = Some(bounds); + state.line_height = px(45.); + }); + let offset_at = |x: Pixels, cx: &mut App| { + body.state.read(cx).offset_for_position(point(x, px(30.))) + }; + assert_eq!(offset_at(bounds.left() + x, cx), 3); + body.state.update(cx, |state, _| state.set_mirrored(true)); + assert_eq!(offset_at(bounds.right() - x, cx), 3); + let ime = body + .state + .update(cx, |state, cx| { + state.bounds_for_range(0..3, bounds, window, cx) + }) + .unwrap(); + assert_eq!(ime.right(), bounds.right()); + assert_eq!(ime.left(), bounds.right() - x); + }); + } + #[gpui::test] fn measurement_preserves_rows_across_width_probes(cx: &mut gpui::TestAppContext) { cx.add_empty_window().update(|window, cx| { diff --git a/scripts/prepare-gpui-dependency.sh b/scripts/prepare-gpui-dependency.sh index a2ec5858a5b..5af0c2aaafa 100755 --- a/scripts/prepare-gpui-dependency.sh +++ b/scripts/prepare-gpui-dependency.sh @@ -15,6 +15,7 @@ patch_paths=( "apps/desktop-gpui/patches/zed-glass.patch" "apps/desktop-gpui/patches/zed-perf.patch" "apps/desktop-gpui/patches/zed-device-lost.patch" + "apps/desktop-gpui/patches/zed-mirror.patch" ) patch_files=("${patch_paths[@]/#/$repo_root/}") base_revision="5d1f83d9f27a19bec1fb241dc33b42238af9cf8d" diff --git a/scripts/prepare-gpui-dependency.test.mjs b/scripts/prepare-gpui-dependency.test.mjs index 1b3e774a958..568558efdd3 100644 --- a/scripts/prepare-gpui-dependency.test.mjs +++ b/scripts/prepare-gpui-dependency.test.mjs @@ -158,6 +158,8 @@ test("dependency verification handles overlapping patches without changing the c patch("zed-perf.patch"); writeFileSync(path.join(upstream, "recovery.rs"), "one instance\n"); patch("zed-device-lost.patch"); + writeFileSync(path.join(upstream, "mirror.rs"), "mirrored text\n"); + patch("zed-mirror.patch"); const script = path.join(cap, "scripts/prepare-gpui-dependency.sh"); writeFileSync( script, From bc1b3e4fa2647a971e1feead2be5611fa85d7021 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:56:21 -0500 Subject: [PATCH 2/4] test(gpui): paint mirrored quads and decorations, and check the glyph flip --- apps/desktop-gpui/patches/zed-mirror.patch | 165 ++++++++++++++++++--- 1 file changed, 145 insertions(+), 20 deletions(-) diff --git a/apps/desktop-gpui/patches/zed-mirror.patch b/apps/desktop-gpui/patches/zed-mirror.patch index aef7d7235ef..516103b18ec 100644 --- a/apps/desktop-gpui/patches/zed-mirror.patch +++ b/apps/desktop-gpui/patches/zed-mirror.patch @@ -17,12 +17,10 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs edge_fade: None, requested_autoscroll: None, rendered_frame: Frame::new(DispatchTree::new(cx.keymap.clone(), cx.actions.clone())), -@@ -3623,6 +3625,41 @@ - let result = f(self); - self.element_offset_stack.pop(); +@@ -3625,6 +3627,49 @@ result -+ } -+ + } + + /// Paints `f` mirrored left to right about the vertical line at `axis`, in + /// window coordinates, the way CSS `scale-x: -1` mirrors an element about + /// its centre. Glyphs are flipped; quads, underlines and strikethroughs @@ -51,15 +49,25 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs + .map(|axis| ScaledPixels((axis.0 * 2. * self.scale_factor()).round())) + } + ++ /// The sprite transformation that flips a glyph about the mirror axis. ++ fn mirror_sprite_transformation(&self) -> Option { ++ self.mirror_span_scaled().map(|span| TransformationMatrix { ++ rotation_scale: [[-1., 0.], [0., 1.]], ++ translation: [span.0, 0.], ++ }) ++ } ++ + fn mirror_x(&self, x: Pixels, width: Pixels) -> Pixels { + match self.mirror_span_scaled() { + Some(span) => Pixels(span.0 / self.scale_factor()) - x - width, + None => x, + } - } - ++ } ++ pub(crate) fn with_element_opacity( -@@ -4273,8 +4310,20 @@ + &mut self, + opacity: Option, +@@ -4273,8 +4318,20 @@ /// Note that the `quad.corner_radii` are allowed to exceed the bounds, creating sharp corners /// where the circular arcs meet. This will not display well when combined with dashed borders. /// Use `Corners::clamp_radii_for_quad_size` if the radii should fit within the bounds. @@ -81,7 +89,7 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs // Scoped edge fades apply PER PIXEL in the fragment shader // ([`Quad::fade`]); only the uniform element opacity bakes into the -@@ -4395,6 +4444,7 @@ +@@ -4395,6 +4452,7 @@ ) { self.invalidator.debug_assert_paint(); @@ -89,7 +97,7 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs let scale_factor = self.scale_factor(); let thickness = self.snap_stroke(style.thickness); let height = if style.wavy { -@@ -4430,6 +4480,7 @@ +@@ -4430,6 +4488,7 @@ ) { self.invalidator.debug_assert_paint(); @@ -97,32 +105,27 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs let scale_factor = self.scale_factor(); let height = style.thickness; let bounds = Bounds { -@@ -4535,8 +4586,9 @@ +@@ -4535,8 +4594,9 @@ size: tile.bounds.size.map(Into::into), }; let content_mask = self.snapped_content_mask(); -+ let mirror = self.mirror_span_scaled(); ++ let mirror = self.mirror_sprite_transformation(); - if subpixel_rendering { + if subpixel_rendering && mirror.is_none() { self.next_frame.scene.insert_primitive(SubpixelSprite { order: 0, pad: 0, -@@ -4554,7 +4606,12 @@ +@@ -4554,7 +4614,7 @@ content_mask, color: color.opacity(element_opacity), tile, - transformation: TransformationMatrix::unit(), -+ transformation: mirror.map_or_else(TransformationMatrix::unit, |span| { -+ TransformationMatrix { -+ rotation_scale: [[-1., 0.], [0., 1.]], -+ translation: [span.0, 0.], -+ } -+ }), ++ transformation: mirror.unwrap_or_else(TransformationMatrix::unit), }); } } -@@ -4621,10 +4678,13 @@ +@@ -4621,10 +4681,13 @@ })? .expect("Callback above only errors or returns Some"); @@ -137,3 +140,125 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs let content_mask = self.snapped_content_mask(); let opacity = self.element_opacity(); +@@ -7512,3 +7575,121 @@ + assert_eq!(seen.take(), Some(first)); + } + } ++ ++#[cfg(test)] ++mod mirror_tests { ++ use crate::{ ++ Bounds, Corners, Edges, Hsla, Pixels, ScaledPixels, StrikethroughStyle, TestAppContext, ++ UnderlineStyle, Window, canvas, fill, point, px, size, ++ }; ++ ++ fn paint( ++ cx: &mut TestAppContext, ++ axis: Option, ++ ) -> (Vec, Vec, f32) { ++ let cx = cx.add_empty_window(); ++ cx.draw(point(px(0.), px(0.)), size(px(400.), px(200.)), move |_, _| { ++ canvas( ++ |_, _, _| (), ++ move |_, _, window: &mut Window, _| { ++ window.with_mirrored_x(axis, |window| { ++ let mut quad = fill( ++ Bounds::new(point(px(10.), px(20.)), size(px(30.), px(40.))), ++ Hsla::red(), ++ ); ++ quad.corner_radii = Corners { ++ top_left: px(1.), ++ top_right: px(2.), ++ bottom_right: px(3.), ++ bottom_left: px(4.), ++ }; ++ quad.border_widths = Edges { ++ top: px(0.), ++ right: px(3.), ++ bottom: px(0.), ++ left: px(1.), ++ }; ++ window.paint_quad(quad); ++ window.paint_underline( ++ point(px(50.), px(80.)), ++ px(60.), ++ &UnderlineStyle { ++ thickness: px(1.), ++ ..Default::default() ++ }, ++ ); ++ window.paint_strikethrough( ++ point(px(50.), px(90.)), ++ px(60.), ++ &StrikethroughStyle { ++ thickness: px(1.), ++ ..Default::default() ++ }, ++ ); ++ }); ++ }, ++ ) ++ }); ++ cx.update(|window, _| { ++ let scene = &window.next_frame.scene; ++ ( ++ scene.quads.clone(), ++ scene.underlines.clone(), ++ window.scale_factor(), ++ ) ++ }) ++ } ++ ++ #[crate::test] ++ fn mirror_reflects_quads_and_decorations_about_the_axis(cx: &mut TestAppContext) { ++ let (plain_quads, plain_lines, scale) = paint(cx, None); ++ let (quads, lines, _) = paint(cx, Some(px(100.))); ++ let s = |value: f32| ScaledPixels(value * scale); ++ ++ let quad = &plain_quads[0]; ++ assert_eq!(quad.bounds.origin.x, s(10.)); ++ assert_eq!(quad.corner_radii.top_left, s(1.)); ++ ++ let quad = &quads[0]; ++ assert_eq!(quad.bounds.origin.x, s(200. - 10. - 30.)); ++ assert_eq!(quad.bounds.origin.y, s(20.)); ++ assert_eq!(quad.bounds.size.width, s(30.)); ++ assert_eq!(quad.corner_radii.top_left, s(2.)); ++ assert_eq!(quad.corner_radii.top_right, s(1.)); ++ assert_eq!(quad.corner_radii.bottom_left, s(3.)); ++ assert_eq!(quad.corner_radii.bottom_right, s(4.)); ++ assert_eq!(quad.border_widths.left.0.round(), s(3.).0.round()); ++ assert_eq!(quad.border_widths.right.0.round(), s(1.).0.round()); ++ ++ assert_eq!(plain_lines.len(), 2); ++ for (plain, mirrored) in plain_lines.iter().zip(&lines) { ++ assert_eq!(plain.bounds.origin.x, s(50.)); ++ assert_eq!(mirrored.bounds.origin.x, s(200. - 50. - 60.)); ++ assert_eq!(mirrored.bounds.size, plain.bounds.size); ++ } ++ } ++ ++ #[crate::test] ++ fn mirror_flips_glyph_sprites_onto_the_reflected_box(cx: &mut TestAppContext) { ++ let cx = cx.add_empty_window(); ++ cx.update(|window, _| { ++ assert!(window.mirror_sprite_transformation().is_none()); ++ let scale = window.scale_factor(); ++ window.with_mirrored_x(Some(px(100.)), |window| { ++ let matrix = window.mirror_sprite_transformation().unwrap(); ++ let apply = |x: f32, y: f32| { ++ let m = matrix.rotation_scale; ++ ( ++ m[0][0] * x + m[0][1] * y + matrix.translation[0], ++ m[1][0] * x + m[1][1] * y + matrix.translation[1], ++ ) ++ }; ++ let (left, top) = (10. * scale, 20. * scale); ++ let (right, bottom) = (left + 8. * scale, top + 12. * scale); ++ assert_eq!(apply(left, top), (200. * scale - left, top)); ++ assert_eq!(apply(right, bottom), (200. * scale - right, bottom)); ++ }); ++ assert!(window.mirror_sprite_transformation().is_none()); ++ }); ++ } ++} From e7257350cad011f2814b5add3c5de0ddd3858421 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:56:21 -0500 Subject: [PATCH 3/4] ci: run the GPUI mirror patch tests --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6ec1a24fa7..679fc92c34a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -458,6 +458,7 @@ jobs: GPUI_REQUIRE_TEST_DEVICE: "1" run: | cargo +1.95.0 test -p gpui --lib stream + cargo +1.95.0 test -p gpui --lib mirror_tests if [[ "$RUNNER_OS" == "Linux" ]]; then WGPU_BACKEND=vulkan cargo +1.95.0 test -p gpui_wgpu --lib wgpu_atlas -- --nocapture WGPU_BACKEND=gl cargo +1.95.0 test -p gpui_wgpu --lib wgpu_atlas -- --nocapture From 36b57756820f0d6ce7c0a8c24418029714e665a1 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sat, 14 Nov 2026 01:51:32 -0500 Subject: [PATCH 4/4] test(gpui): read the mirror test's primitives while they are painted --- apps/desktop-gpui/patches/zed-mirror.patch | 54 +++++++++++++--------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/apps/desktop-gpui/patches/zed-mirror.patch b/apps/desktop-gpui/patches/zed-mirror.patch index 516103b18ec..2c7f51d1077 100644 --- a/apps/desktop-gpui/patches/zed-mirror.patch +++ b/apps/desktop-gpui/patches/zed-mirror.patch @@ -17,10 +17,13 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs edge_fade: None, requested_autoscroll: None, rendered_frame: Frame::new(DispatchTree::new(cx.keymap.clone(), cx.actions.clone())), -@@ -3625,6 +3627,49 @@ - result - } - +@@ -3622,9 +3624,52 @@ + self.element_offset_stack.push(offset); + let result = f(self); + self.element_offset_stack.pop(); ++ result ++ } ++ + /// Paints `f` mirrored left to right about the vertical line at `axis`, in + /// window coordinates, the way CSS `scale-x: -1` mirrors an element about + /// its centre. Glyphs are flipped; quads, underlines and strikethroughs @@ -39,7 +42,7 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs + let previous = self.element_mirror_x.replace(axis); + let result = f(self); + self.element_mirror_x = previous; -+ result + result + } + + /// The mirror axis doubled, in device pixels and whole, so a reflected @@ -47,8 +50,8 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs + fn mirror_span_scaled(&self) -> Option { + self.element_mirror_x + .map(|axis| ScaledPixels((axis.0 * 2. * self.scale_factor()).round())) -+ } -+ + } + + /// The sprite transformation that flips a glyph about the mirror axis. + fn mirror_sprite_transformation(&self) -> Option { + self.mirror_span_scaled().map(|span| TransformationMatrix { @@ -67,14 +70,14 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs pub(crate) fn with_element_opacity( &mut self, opacity: Option, -@@ -4273,8 +4318,20 @@ +@@ -4273,9 +4318,21 @@ /// Note that the `quad.corner_radii` are allowed to exceed the bounds, creating sharp corners /// where the circular arcs meet. This will not display well when combined with dashed borders. /// Use `Corners::clamp_radii_for_quad_size` if the radii should fit within the bounds. - pub fn paint_quad(&mut self, quad: PaintQuad) { + pub fn paint_quad(&mut self, mut quad: PaintQuad) { self.invalidator.debug_assert_paint(); -+ + + if self.element_mirror_x.is_some() { + quad.bounds.origin.x = self.mirror_x(quad.bounds.origin.x, quad.bounds.size.width); + let radii = quad.corner_radii.clone(); @@ -86,9 +89,10 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs + }; + std::mem::swap(&mut quad.border_widths.left, &mut quad.border_widths.right); + } - ++ // Scoped edge fades apply PER PIXEL in the fragment shader // ([`Quad::fade`]); only the uniform element opacity bakes into the + // colors here. (A CPU-side gradient rewrite used to approximate the @@ -4395,6 +4452,7 @@ ) { self.invalidator.debug_assert_paint(); @@ -140,7 +144,7 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs let content_mask = self.snapped_content_mask(); let opacity = self.element_opacity(); -@@ -7512,3 +7575,121 @@ +@@ -7512,3 +7575,127 @@ assert_eq!(seen.take(), Some(first)); } } @@ -148,15 +152,21 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs +#[cfg(test)] +mod mirror_tests { + use crate::{ -+ Bounds, Corners, Edges, Hsla, Pixels, ScaledPixels, StrikethroughStyle, TestAppContext, -+ UnderlineStyle, Window, canvas, fill, point, px, size, ++ Bounds, Corners, Edges, Hsla, Pixels, ScaledPixels, StrikethroughStyle, Styled as _, ++ TestAppContext, UnderlineStyle, Window, canvas, fill, point, px, size, + }; ++ use std::{cell::RefCell, rc::Rc}; ++ ++ type Painted = (Vec, Vec, f32); + + fn paint( + cx: &mut TestAppContext, + axis: Option, -+ ) -> (Vec, Vec, f32) { ++ ) -> Painted { ++ let painted: Rc>> = Rc::default(); ++ let out = painted.clone(); + let cx = cx.add_empty_window(); ++ cx.simulate_resize(size(px(400.), px(200.))); + cx.draw(point(px(0.), px(0.)), size(px(400.), px(200.)), move |_, _| { + canvas( + |_, _, _| (), @@ -196,17 +206,17 @@ diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs + }, + ); + }); ++ let scene = &window.next_frame.scene; ++ *out.borrow_mut() = Some(( ++ scene.quads.clone(), ++ scene.underlines.clone(), ++ window.scale_factor(), ++ )); + }, + ) ++ .size_full() + }); -+ cx.update(|window, _| { -+ let scene = &window.next_frame.scene; -+ ( -+ scene.quads.clone(), -+ scene.underlines.clone(), -+ window.scale_factor(), -+ ) -+ }) ++ painted.take().expect("the canvas painted") + } + + #[crate::test]