Skip to content

Add previous and next buttons to the video Pip window - #31281

Open
meh7an wants to merge 1 commit into
telegramdesktop:devfrom
meh7an:feature/pip-navigation-buttons
Open

meh7an wants to merge 1 commit into
telegramdesktop:devfrom
meh7an:feature/pip-navigation-buttons

Conversation

@meh7an

@meh7an meh7an commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

The Picture-in-Picture window has no way to move between items in an album. Keyboard navigation does not reach it either, since it has no focus handling, so once a video opens there the only ways onward are closing the window or pressing Enlarge.

This adds Previous and Next buttons to the Pip window.

Changes

  • Two new OverState values and two Buttons, centred on the left and right edges, reusing the existing Pip button style and hover fade. They are painted and hit-tested only when a neighbour exists, so no dead arrow appears at either end of an album.
  • Pip::Delegate gains pipCanNavigate(int) and pipNavigate(int). The window answers them from its own navigation context, not from the viewer.
  • The window keeps its own context in PipWrap::Navigation: its message, topic, monoforum peer and media list. switchToPip() fills it while the viewer still shows the video, and the window then follows its shared media list through a SharedMediaWithLastViewer subscription of its own, on the video's key and session. Instant View and link preview collage lists don't change, so a copy with the index is enough. PipWrap::entity() resolves the neighbour from that context, so opening, browsing or closing other media in the viewer meanwhile does not change where the buttons lead, and the viewer clears everything on hide, as on dev.
  • pipNavigate() hands the neighbour back to the viewer with the same show(OpenRequest(...)) that Enlarge uses, carrying the window's own opener window, topic, monoforum peer and draw button state, with _reShow set so a viewer that already shows that message is not toggled closed. A photo opens in the viewer, and a video goes back into a new Pip window because _showAsPip stays set. The click arrives from inside the Pip mouse handler, so the handoff is queued, and a _pipGeneration counter turns a click queued behind a jump into a no-op.
  • Pip::navigationChanged() repaints the window and recomputes the hover state under a resting cursor when its list loads or changes, so a button that appears under the cursor works on the first click.
  • _showAsPip stays set as before, so after a jump that lands on a photo, which Pip cannot display, the next video, whether reached with the viewer's arrows or opened from a chat, goes back into the window. Only Enlarge ends that, as on dev.
  • A new Pip takes over the hover state from the cursor position before its first paint, through the same handleMouseMove() a real hover uses, then finishes the controls fade at once. A window created under a cursor that is not moving receives no mouse move event, so its controls stayed hidden, faded back in and showed the default cursor until the mouse moved. Every jump builds a new window under the cursor, so a jump now looks like the same window changing its video.
  • kControlsCount goes from 7 to 9 in the OpenGL and RHI Pip renderers, with the two icons appended to their atlases at indices 7 and 8. The software renderer needs no atlas change.

Pip holds its document through a const pointer, so continuing in the window means building a new Pip rather than re-pointing the existing one. The request arrives from inside the Pip mouse handler, so the teardown is deferred until that handler has returned.

Testing

Built Debug on macOS against this base. Exercised by hand on both the OpenGL and the RHI renderer: video to video staying in the window, video to photo handing off to the viewer, returning to the window on a later video, and the controls remaining visible across a jump. The software renderer was not exercised, though it needs no atlas change.

After the second review: Pip of a video in the middle of an album, then a photo from another chat opened and closed: the buttons still lead to the video's neighbours, and Next opens the item after the video. The same with the photo taken from the video's own chat, far from it. With the photo opened from a chat in a second window, the item Next opens stays tied to the main window. A window created before its list arrived, or kept paused under the cursor while the list changed, updates its buttons without moving the mouse, and a newly shown Next works on the first click. Video to video by repeated clicks without moving the mouse, video to photo, Enlarge, and closing the window with its button and clicking the same video again (it reopens as a Pip window, as on dev) re-checked.

Screenshot


2026-09-11_08-04-49
@meh7an meh7an closed this Sep 10, 2026
@meh7an meh7an reopened this Sep 10, 2026
@meh7an
meh7an marked this pull request as draft September 10, 2026 19:43
@meh7an
meh7an force-pushed the feature/pip-navigation-buttons branch from 3fe2c9b to bafb166 Compare September 10, 2026 23:05
@meh7an
meh7an marked this pull request as ready for review September 10, 2026 23:08
@meh7an
meh7an force-pushed the feature/pip-navigation-buttons branch 3 times, most recently from 2d21f99 to fdcf6f9 Compare September 16, 2026 15:10
@meh7an
meh7an marked this pull request as draft September 16, 2026 15:12
@meh7an
meh7an force-pushed the feature/pip-navigation-buttons branch from fdcf6f9 to 77142a9 Compare September 16, 2026 15:57
@meh7an
meh7an marked this pull request as ready for review September 16, 2026 16:02
@23rd

23rd commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Unfortunately we **do not merge** any pull requests that have new feature implementations, translations to new languages and those which introduce any new user interface elements.

@23rd 23rd closed this Sep 22, 2026
@john-preston john-preston reopened this Oct 1, 2026
@john-preston

Copy link
Copy Markdown
Member

Bind PiP navigation to the PiP video’s own message, session, and media collection instead of the main viewer’s mutable navigation state. Playing video A in PiP and then opening photo B currently redirects PiP’s arrows to B’s neighbours; closing B preserves that incorrect context. Keep the contexts separate or provide an explicit handoff, and verify that opening and closing unrelated photos does not change PiP’s navigation targets.

@meh7an
meh7an force-pushed the feature/pip-navigation-buttons branch from 77142a9 to 396ab20 Compare October 4, 2026 09:53
@john-preston

john-preston commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Opening another window’s video directly into PiP can retain the previous window’s context, making subsequent “Go to message” navigation target the wrong window.

The window keeps its own message, topic and media list, taken from
the viewer when the video moves into it and followed by its own
subscription, so media opened or closed in the viewer meanwhile does
not change where the buttons lead. A jump hands the neighbour to the
viewer through a regular open request: a photo shows in the viewer
and a video goes back into the window.
@meh7an
meh7an force-pushed the feature/pip-navigation-buttons branch from 396ab20 to 87cd4a5 Compare October 22, 2026 15:20
@meh7an

meh7an commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Opening another window’s video directly into PiP can retain the previous window’s context, making subsequent “Go to message” navigation target the wrong window.

Thanks, fixed. When PiP was already active, a video opened from another window went straight into PiP before the viewer had switched to that window, so the PiP kept the previous one. Now a PiP created while opening a video takes the window that video was opened from, so PiP navigation and "Go to message" go there, while an existing PiP still keeps its own context when unrelated media is opened.

This branch has not been deployed

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

Labels

None yet

3 participants