Skip to content

hyprland: hold the last frame across a rotation, then turn it in as Android does - #446

Closed
angelrenefm wants to merge 2 commits into
derekross:mainfrom
angelrenefm:hyprland-rotation-hold
Closed

angelrenefm wants to merge 2 commits into
derekross:mainfrom
angelrenefm:hyprland-rotation-hold

Conversation

@angelrenefm

Copy link
Copy Markdown
Contributor

When the phone turns, Hyprland lays the layer surfaces out again at once, but each client draws at its new size only when it gets to it. Until then Hyprland draws their old buffers stretched over the turned output. On a Pixel 7 with the phone shell that showed for 200 ms to a second on every turn: stripes, half-empty pages, the home screen's icons squeezed into a column. Nothing here is panther-specific, so I'd expect the 7 Pro to show it too.

This adds 0002-render-hold-the-last-frame-across-a-rotation.patch to packages/hyprland (src/render/Renderer.cpp, src/render/OpenGL.cpp).

The hold. After a transform change nothing is rendered until every mapped layer surface on the monitor has drawn at its new size, or 500 ms have passed, so the panel keeps its last frame. "Drawn" is three checks, each added after the phone showed why the one before wasn't enough:

  1. the surface's size matches its new geometry;
  2. its buffer matches too (Qt resizes the viewport first, with the old buffer stretched into it, and commits the new buffer afterwards);
  3. a layer that had to redraw has sent a second buffer at the new size, or its first has stood for 50 ms (Qt's first frame at a new size can still be laid out for the old one, which showed as a black bar; Omarchy's dock sends one buffer and stops, so waiting for a second alone ran into the deadline).

While holding, layers and the active workspaces get their frame callbacks once per refresh. Without them Qt clients never drew, and every hold ran to the deadline.

The turn. Before the hold, the output's last buffer is copied into a framebuffer of the panel's size, because the swapchain reuses it within a few frames. When the hold ends, the final copy to the output in CHyprOpenGLImpl::end() draws, over black:

  • the new frame, turning in from where the old one sat on the glass to upright over 283 ms on a (0.2, 0, 0, 1) curve;
  • the old frame, turning with it and fading out over 116 ms.

The values are AOSP's (core/res/res/anim/screen_rotate_*_enter/exit.xml, config_screen_rotation_*, interpolator/screen_rotation.xml). One difference: the new frame is opaque from the start. Android fades it in over black, and on the phone that read as a dip to black.

Tested on a Pixel 7 (panther, 90 Hz) only, on the home screen, turning between transform 0 and 1:

  • Holds of 106 to 228 ms over six turns, all ended by the layers and none by the deadline.
  • Watched on the phone: no stretched frames, no black bar, and a smooth turn.

For the test I cross-built Hyprland 0.57.0 from this patch (and the four already in the package) against the phone's own libraries and swapped it in for /usr/bin/Hyprland.

Not checked:

  • makepkg / tools/build-packages with this PKGBUILD. The patch applies with --fuzz=0 after the other four, and reproduces the source I built.
  • Transform 3 (the other landscape side) and 2 (a half turn): the angle for them is derived, not seen.
  • App windows: only layer surfaces are waited for, so a window that redraws late can still show stretched for a moment.
  • A 120 Hz panel (your 7 Pro), more than one monitor, and a monitor without layer-shell clients.
  • screencopy can't be used to check the turn, because it copies the frame before end()'s final copy. Only the screen shows it.

Version and pkgrel are yours to set.

I used AI help (Claude) to work on this.

@angelrenefm

Copy link
Copy Markdown
Contributor Author

One item off the "not checked" list: turning to the other landscape side (transform 3, and back to 0) was watched on the Pixel 7 too, and turns in correctly, the same as transform 1. The half turn (2) is still unchecked; autorotate on the phone doesn't use it.

I used AI help (Claude) to work on this.

@derekross

Copy link
Copy Markdown
Owner

Thank you, @angelrenefm, this is lovely work. Stretched frames on every turn were one of the things that made rotation feel broken, and reading AOSP for the timings, then dropping the fade-in when it looked worse on the phone, is the right kind of judgement. I applied your patch with the other four to the 0.57.0 source at --fuzz=0 and it goes in cleanly, and the checksum in the PKGBUILD matches.

The thing I can't get past right now: our Hyprland package is the Pixel 7 Pro's compositor too, and this changes every rotation there, at 120 Hz, with a different shell layout. Nobody has run it on a 7 Pro, and I can't test that phone at the moment. The way we handle shared code is that it leaves the 7 Pro as it is until it has run there. So could you put the hold and the turn behind a switch that the Pixel 7 turns on? For example, an environment variable read once at startup (OMAMOBILE_ROTATION_HOLD=1), set by a small environment.d file in device-panther (the shell package already ships two). When I can try it on the 7 Pro, we flip it on there too, and later make it the default.

Two package details: the build needs a new release number, pkgrel=3.2, since 3.1 is already published, and the pkgdesc still says "DPMS retry" only.

A few things I noticed reading the patch, none blocking:

  • The 50 ms "first buffer has stood" check only runs when something else asks for a frame. A layer that sends one buffer and goes quiet ends the hold at the next unrelated redraw, or at the 500 ms deadline. Arming your timer for the rest of those 50 ms would end it on time.
  • Lock-screen surfaces aren't layer surfaces, so the hold doesn't wait for them or send them frames. Could you try a rotation with the lock screen up?
  • If autorotate turns the output while the screen is off, the first frame after wake would animate out whatever was on the panel before it went off. Worth one look.
  • The per-monitor state is never removed when a monitor goes away. That's harmless on a phone; just a tidy-up.

Thanks for listing what you didn't test so plainly; it made this much easier to review.

A monitor transform change lays the layer surfaces out again at once,
but each client draws at its new size only when it gets to it. Until
then Hyprland drew their old buffers stretched over the turned output:
stripes, half-empty pages, the home screen's icons in a column, for
200 ms to a second on a Pixel 7 running the phone shell.

0002-render-hold-the-last-frame-across-a-rotation.patch (Renderer.cpp
and OpenGL.cpp):

- After a transform change, nothing is rendered until every mapped
  layer surface on the monitor has drawn at its new size, or 500 ms
  have passed, so the panel keeps its last frame. "Drawn" means the
  surface's size and its buffer match the new geometry, and a layer
  that had to redraw has sent a second buffer at that size, or its first
  has stood for 50 ms. Each check comes from what showed on the phone:
  Qt resizes the viewport before it commits the new buffer, and its
  first frame at a new size can still be laid out for the old one.
  Layers and the active workspaces get their frame callbacks once per
  refresh while holding, or Qt clients never draw.
- Then the new frame turns in from where the old one sat on the glass
  over 283 ms on a (0.2, 0, 0, 1) curve, while the old frame (copied
  from the output's buffer before the hold) turns with it and fades out
  over 116 ms: AOSP's screen rotation values. The new frame is opaque
  from the start; Android's fade in over black read as a dip to black.

Tested on a Pixel 7 (panther, 90 Hz) only, with Hyprland cross-built
from this patch against the phone's own libraries and swapped in for
/usr/bin/Hyprland, not built with makepkg. Turns between transform 0
and 1, on the home screen: holds of 106 to 228 ms, all ended by the
layers, none by the deadline; watched on the phone, no stretched frames
or black bar, and a smooth turn. Not checked: transform 3 and 2 (the
other landscape side and a half turn), app windows (only layer
surfaces are waited for), a 120 Hz panel, and a monitor without layer
shell clients. screencopy can't show the turn: it copies the frame
before end()'s final copy.

I used AI help (Claude) to work on this.
The hold and the turn now run only with OMAMOBILE_ROTATION_HOLD=1 in
Hyprland's environment, read once at startup; without it nothing is
copied, held or animated, and Hyprland rotates as before. The Pixel 7
Pro keeps that until the hold has run on it.

omamobile-device-panther turns it on with
/usr/lib/environment.d/40-omamobile-rotation.conf (environment.d values
reach Hyprland under uwsm, as the shell package's do).

pkgrel 3.2, since 3.1 is published, and the pkgdesc names the rotation
hold too.

I used AI help (Claude) to work on this.
@angelrenefm

Copy link
Copy Markdown
Contributor Author

Thanks, @derekross. The hold is behind a switch now, and the branch is rebased onto today's main.

The switch. OMAMOBILE_ROTATION_HOLD=1, read once when Hyprland starts. Without it nothing is copied, held or animated: holdFrameForRotation() returns at once and the snapshot is never taken, so end() has nothing to draw. omamobile-device-panther sets it in /usr/lib/environment.d/40-omamobile-rotation.conf, with a line in its README and a check in test/all.

The package. pkgrel=3.2, the pkgdesc names the rotation hold, and the PKGBUILD header and README say it's off unless a device turns it on. The new patch applies to the 0.57.0 source at --fuzz=0 after the other four and gives the tree I built.

On the Pixel 7. Hyprland built from that tree, the conf file in place, then a reboot:

  • /proc/<Hyprland>/environ has OMAMOBILE_ROTATION_HOLD=1, so environment.d reaches Hyprland under uwsm, as the shell package's two files do.
  • 13 rotations (transforms 0 and 3) looked the same as before: held, then turned in, no stretched buffers.

Lock screen and screen off. Here omamobile-autorotate keeps the screen at transform 0 while the shell is locked, and applies the phone's orientation on unlock. Turning the phone with the lock screen up, or with the screen off (the power key locks), didn't rotate the output, so the hold never ran with a lock surface up or across a wake. A phone whose autorotate turns a locked screen would still meet both cases.

Not done yet (your non-blocking points): arming the timer for the rest of the 50 ms, and dropping a monitor's state when it goes away. I'd rather do them as a follow-up once this has run on the 7 Pro.

Not checked: the switch off on a phone (Hyprland's own rotation, as on the 7 Pro), a makepkg build (I cross-built the same tree), 120 Hz, and transform 2.

I used AI help (Claude) to work on this.

@angelrenefm
angelrenefm force-pushed the hyprland-rotation-hold branch from 10db93f to 82d5502 Compare November 7, 2026 15:18
@derekross

Copy link
Copy Markdown
Owner

Thank you, @angelrenefm. The switch is just what I had in mind. I read the patch again with it off: holdFrameForRotation() returns before it does anything, the snapshot is never taken, and end() falls through to Hyprland's own drawing. So the 7 Pro gets exactly what it has today, and the Pixel 7 gets the hold. I applied all five patches to the 0.57.0 source at --fuzz=0 again, and the checksums match. Thanks also for checking /proc/<pid>/environ on the phone, and for the clear answer on the lock screen. It's good to know autorotate already keeps the hold out of that path.

Deferring the 50 ms timer and the per-monitor cleanup until it has run on the 7 Pro is fine with me.

I'll set device-panther's version when I merge, since the branch still reads 0.1.10, which main already ships, and a few Pixel 7 PRs are landing today. I'll write the squash message with the Hyprland and device-panther versions in it. Thanks again, this makes rotation on the Pixel 7 feel much more finished.

derekross added a commit that referenced this pull request Nov 7, 2026
…s a rotation on the Pixel 7 (#446) (#487)

A rotation on the Pixel 7 used to show stretched frames while the shell redrew. Hyprland now holds the last frame across the turn and hands it over AOSP-style once the layer surfaces have redrawn, with a 500 ms deadline. It runs only when OMAMOBILE_ROTATION_HOLD=1, which device-panther sets in an environment.d drop-in; with the switch off (every other phone, the Pixel 7 Pro included) the hold returns at once and Hyprland draws as before. The patch applies to the 0.57.0 tarball at --fuzz=0, and it was cross-built and booted on the contributor's Pixel 7.

Co-Authored-By: Ángel René <17342133+angelrenefm@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derekross

Copy link
Copy Markdown
Owner

Merged through #487 as hyprland 0.57.0-3.2 and device-panther 0.1.12, with you credited as co-author. Thank you, @angelrenefm! The nightly builds Hyprland for development tonight.

@derekross derekross closed this Nov 7, 2026
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…s a rotation on the Pixel 7 (derekross#446) (derekross#487)

A rotation on the Pixel 7 used to show stretched frames while the shell redrew. Hyprland now holds the last frame across the turn and hands it over AOSP-style once the layer surfaces have redrawn, with a 500 ms deadline. It runs only when OMAMOBILE_ROTATION_HOLD=1, which device-panther sets in an environment.d drop-in; with the switch off (every other phone, the Pixel 7 Pro included) the hold returns at once and Hyprland draws as before. The patch applies to the 0.57.0 tarball at --fuzz=0, and it was cross-built and booted on the contributor's Pixel 7.

Co-Authored-By: Ángel René <17342133+angelrenefm@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants