Skip to content

Windows: left- and top-edge resizes shift the whole page; owning the DirectComposition visual would hold it still #101

Closed as duplicate

Description

@zAcherttp

Follows #47, which covers the right and bottom edges.

What happens

Dragging a window's left or top edge, the whole page jumps sideways (or up) by the drag distance on each step, then snaps back when the new frame lands. The gap opens at the opposite edge, the one not being dragged. Right and bottom edges don't do this. Same machine as #47 (Windows 11, RTX 4070, 239 Hz).

Cause

  • A left or top drag moves the window's origin. Until the app presents a frame at the new size, DWM shows the last frame pinned to the client area's new top-left, so the old frame moves with the edge.
  • Drawing each step sooner (Windows: live resize lags and stretches on every edge #47) shortens this but can't remove it: the shifted frame is visible in the moment between DWM moving the window and the new present.
  • Rune can't correct it, because wgpu owns the composition tree. With Dx12SwapchainKind::DxgiFromVisual, wgpu-hal creates its own IDCompositionDevice, target and root visual for the HWND (wgpu-hal 30, dx12/dcomp.rs, InnerState::init) and never exposes them.

Proposed approach (researched, not prototyped)

  1. Rune owns the tree. Create the IDCompositionDevice, a target for the HWND, a root visual and a content visual, and make the surface with wgpu::SurfaceTargetUnsafe::CompositionVisual(content) (wgpu 30, DX12 only). Behaviour, screenshots and transparency should stay identical; this step only moves ownership.
  2. Offset during a left/top drag. In the size-move subclass (platform/win32/dpi_drag.rs already watches WM_ENTERSIZEMOVE / WM_EXITSIZEMOVE), read WM_SIZING's edge (WMSZ_LEFT, WMSZ_TOP and the corners). For each step:
    • set the content visual's offset to the origin's movement since the last presented frame (SetOffsetX(+dx), SetOffsetY(+dy)), so the old frame stays where it was on screen, and Commit() before returning;
    • when the frame at the new size presents, reset the offsets to 0 and Commit() again.
  3. Keep Windows: live resize lags and stretches on every edge #47's pieces: draw in Resized during the loop, one oversized drawable for the drag, and clearing to the page colour.

Risk to verify first

The window move (applied by DWM) and the visual offset (a DirectComposition commit) must land in the same composed frame. If they are a frame apart, the page wobbles by one step instead of jumping, which is still visible. Check this before building the rest: a test window that moves its origin and offsets a solid-colour visual in the same step, watched at 240 Hz or captured with PresentMon. If the commit lands late, IDCompositionDevice::WaitForCommitCompletion or committing from WM_WINDOWPOSCHANGING (before the move is applied) are the next things to try.

Scope

  • DX12 only. Vulkan keeps the HWND swapchain and today's behaviour.
  • The same tree is what Mica/Acrylic backdrops and native video visuals need. research/11-platform-shells.md already plans an IDCompositionDevice / target / visual tree for the Windows shell, after gpui_windows.

Acceptance

  • Dragging the left or top edge (or a corner) at full speed, the page doesn't move on screen; only the uncovered strip at the dragged edge shows the page colour.
  • Right and bottom edges, transparent windows, overlays and screenshots are unchanged.
  • No extra frame of lag in step time against Windows: live resize lags and stretches on every edge #47's numbers.

I can test any change on this machine (NVIDIA RTX 4070, plus the Intel iGPU via WGPU_ADAPTER_NAME=intel).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions