Crafter.Graphics/tests/ConfigureResize/main.cpp

1594 lines
85 KiB
C++
Raw Permalink Normal View History

fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
//SPDX-License-Identifier: LGPL-3.0-only
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
// Issue #199: a size the compositor configures is answered by the frame drawn
// at it. The configure listener used to make the swapchain again on the spot,
// acknowledge the configure, send the viewport's destination for the new size
// and commit the surface. The destination is the surface's size, and that
// commit applied it to the buffer still attached: the old frame was shown
// scaled to the new size until the consumer's next frame brought a buffer of
// that size. The acknowledgement had named the old frame as the answer to
// the configure, and the rebuild's Vulkan calls ran, and threw, inside
// libwayland's dispatch (#200).
//
// Now the listener keeps the size and the serial, and Render() does the rest
// at its boundaries: RebuildIfDeferred takes the size (TakeDeferredSize) and
// makes the swapchain again, and SendFrameSurfaceState sends the destination
// and the acknowledgement right before the present, whose commit applies
// them with the frame's buffer. The surface's size is state of the window
// for that (logicalWidth, logicalHeight): a size the compositor configured
// is sent as the destination unchanged, and is not worked back from the
// pixels and a scale that may have changed since. This test drives those
// pieces without a swapchain: the window is default-constructed with a
// made-up swapchain handle, its surfaces are proxies on a wl_display
// connected to one end of a socketpair, as in ToplevelState, and the test
// calls the listener callbacks itself and reads the requests off the other
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// end. `Begin`, `Present` and `End` below stand for Render()'s start, its
// present and its end after the present; ResizeViewport runs the real one
// against a compositor. Asserts:
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
//
// - a configure for a new size sends one bare commit: no destination, no
// acknowledgement, and no Vulkan call (there is no device here, and the
// old listener's rebuild would have crashed on it). The size and the
// serial wait, the window's size stays the swapchain's, and onFrameOwed
// fires
// - the frame takes the size and sends the destination and the
// acknowledgement before its present, once
// - several configures before a frame cost one rebuild and one
// acknowledgement, of the last serial, and a configure without a size
// among them waits with the others
// - a configure that asks for nothing new while nothing is owed is
// acknowledged in the listener, before its commit, and fires nothing
// - a configure back to the size the window has takes the wait away: it
// is acknowledged at once, and the serial that waited never is, which
// would be a protocol error after a later one
// - a frame being recorded when a size comes does not acknowledge it
// - a window's first frame brings the destination (the constructor sends
// none), and so does the first frame at any new size; a configure that
// comes before that frame waits for it
// - a configure for the size a rebuild that threw is still pending for
// waits for the frame as well, and so does one that comes after a
// present that found the swapchain out of date, whose surface state is
// not sent a second time
// - without a viewport the acknowledgement still waits for the frame
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// - the size is turned into pixels with the scale the compositor has asked
// for by the moment the frame takes it, and the destination is the
// configured size whatever the scale does: when it changes before the
// frame, between the frame's start and its present (a listener that
// dispatches events), and when the new size at the new scale comes to
// the pixels the swapchain has, in either order of the two events. That
// last frame makes no swapchain and still brings the surface its size. A
// scale that changes during a frame is taken at the boundary after its
// present
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
// - on a fractional scale the destination is the configured size and not a
// pixel more, and a window configured at the size it has is left alone
// (the numbers of #201's phone trace)
fix(wayland): round a configured size's pixels half away from zero, and work both sizes out exactly from the scale's 120ths A size the compositor configured became the buffers' size as ceil(size * scale), in float. The protocol, as bundled in lib/fractional-scale-v1.h, has the buffer's size as the surface's times the scale, and says that "For toplevel surfaces, the size is rounded halfway away from zero": wherever the product's fraction is below a half, rounding up gave a pixel more than that. 89111e0 left this as the rest of #201, and the comment on #165 asks for it. And the sum was done in float, with the scale as a float, which a scale that is no whole number of eighths is not exactly: a product that is a whole number of pixels could come out just above it, and rounding up then went a pixel past it, as 50 at 1.2 came to 61. The other way, the surface's size for a window the application sized, ceil(pixels / scale), had the same trouble: 171 pixels at 2.85 came to 61, where they are 60. Window: ScaledPixels rounds half away from zero, and both it and SurfaceLength work in 64-bit integers from the 120ths the compositor sends: MatchSizesToScale from those of the scale the window draws at, which a new member, drawnScale_, keeps beside scale, as they are not preferredScale while a new scale waits, and the tests of whether a scale gives the window new pixels from preferredScale. SurfaceLength still rounds up, so that the surface of a window the application sized is no smaller than its pixels at the scale. ScaledPixels never gives less than one pixel: below a scale of a half a length of one rounds to none, where rounding up gave one, and a swapchain cannot be made 0 wide or high. Nor more than the largest 32-bit value, which a configured length can pass at a scale above 2 (2^30 at 4 comes to 2^32), where the cast to 32 bits would wrap it, to none in that case; and SurfaceLength stops at the largest int32, which a length worked out from 32-bit pixels can pass. The configure listener's test for a configure at the size the window has uses the same sum, so a configured size the window took is found to be the one it has, and so do the tests, in TakeDeferredSize after a present and in MatchSizesToScale, of whether a size or a scale comes to new pixels; and the listener tells that no new scale waits from the 120ths, preferredScale against drawnScale_, where 61f2698 compared the two scales as floats. So 392x796 at 2.85, the size in #201's phone trace, takes 1117x2269 pixels where it took 1118x2269. A window of 320x240 pixels at 1.75, shown at 183x138, takes 320x242 for a configure of that size, where it took 321x242. Docs: the consumer notes say how a configured size's pixels are rounded, and that the surface of a window the application sized is rounded up; the guide's gotchas, that both are worked out in integers from the 120ths; both, that the pixels are never fewer than one nor more than the largest 32-bit value, and that the surface's length never passes the largest int32. The gotcha and the interface's comment on logicalWidth give, as a reason not to work the surface's size back from the pixels, that a configured size worked back from them lands above itself wherever its product with the scale is not whole. That held while both roundings went up; now it lands above where that product has a fraction of a half or more, short of the 32-bit limits the two sums stop at, and both say so. Tests: ConfigureResize takes the new numbers in its cases of #201's trace and of the window at 1.75, and adds the protocol's own example (100x50 at 1.5 is 150x75), halves that go up (853x101 at 1.5 is 1280x152), fractions below a half that go down (101x853 at 1.25 is 126x1066, which rounding up made 127x1067), and whole numbers the sum in float came out above (50x25 at 1.2 is 60x30, which came to 61x31), each acknowledged in the listener when it is configured again; a configure of 1x300 at 0.4, whose width rounds to no pixel, taken as 1x120; a configure of 2^30x300 at 4, whose width is the largest 32-bit value, and pixels of that value at a half, whose surface is the largest int32 wide; and a window of 342x171 pixels at 2.85, whose surface is 120x60, which came to 121x61. And it works configured sizes into pixels and back with a window's own MatchSizesToScale: 853x101 at 1.5 comes back as 854x102, and 392x796 at 2.85 as 392x797. ResizeViewport works the pixels and the surface's size out as the window now does, and its comments say which way each is rounded.
2026-11-27 10:07:37 +01:00
// - a configured size's pixels are the size times the scale rounded half
// away from zero, as fractional-scale-v1 has it for a toplevel, worked
// out exactly from the scale's 120ths: the protocol's own 100x50 at 1.5,
// halves that go up, less than halves that go down where rounding up
// gave a pixel more, and whole numbers the sum in float came out above.
// The pixels are never fewer than one, where the protocol's rounding
// gives none: a length of one below a scale of a half; nor more than
// the largest 32-bit value, which 2^30 at 4 comes past, where the cast
// would wrap them to none. A surface's length worked out from pixels
// stops at the largest int32 in the same way. A window the
// application sized has its surface's size rounded up from its pixels,
// exactly too. Worked back from its pixels, a configured size short
// of the 32-bit limits the two sums stop at lands above itself where
// its product with the scale has a fraction of a half or more, and,
// from a scale of a half up, on itself below that
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
// - a swapchain made for another reason after the scale changed: a window
// the compositor sized keeps the surface's size and takes the pixels for
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// it at the new scale, which it draws at from that swapchain on, the
// next frame boundary having nothing left to take; one the application
// sized keeps its pixels and takes no scale there, as nothing of that
// swapchain needs it, and until the next frame's start takes it a motion
// is still at the pixels of the scale before, also where the swapchain
// is made after a present that found it out of date
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
// - of a Resize from a listener of the frame and a configured size, the
// one asked for last is taken, also when it is the size the window has
// - onFrameOwed fires after onToplevelState, with the states set, and not
// at all for a window an onToplevelState listener destroyed
// - every acknowledgement names a later serial than the one before
//
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// Issue #165: a scale the compositor asks for by itself, with no configure
// (a window that goes to an output of another scale). Its listener used to
// set Window::scale and nothing else: the buffers and the surface kept the
// old scale until something resized the window, while the pointer, the
// touches and the caret were converted with the new one. Asserts:
//
// - the listener sends nothing, leaves `scale` and both sizes as they
// are, and fires onFrameOwed; until a frame boundary takes the scale, a
// motion or a touch at the surface's middle is at the middle of the
// buffers drawn at the scale before, and a caret given in their pixels
// goes to the text input converted with that scale too
// - the next frame boundary takes it. A window the compositor sized keeps
// its surface's size and takes the pixels for it at the new scale, so
// the frame makes the swapchain; the surface is sent nothing. One the
// application sized keeps its pixels and makes no swapchain, and its
// surface takes the size they come to, which the frame sends. From then
// the pointer, the touches and the caret are converted with the new
// scale, and what the window held in pixels of the scale before is
// taken to it: a pointer and a finger that rest are where their
// surface-local places come to at the new scale, and the boundary sends
// the caret again, converted, with no SetTextInput; an Input::Map
// attached to the window and ticked across the boundary reads no delta
// for a pointer that rests, nor across two boundaries between two Ticks,
// and fires no event there
// - input whose listener takes a scale that waits (as a SetPresentMode
// outside a frame does for a window the compositor sized, at the new
// pixels the scale gives it): the click a finger stands in
// for, the finger's move and the move after an enter are in the pixels
// of that scale
// - a scale that comes while a frame is being recorded leaves that frame
// at the scale it began with, and the boundary after its present takes
// it only where it gives the window new pixels: a window the compositor
// sized whose surface comes to other pixels at it. Where it gives none
// (a window the application sized, one the compositor sized that it
// leaves at its pixels, a configure that comes with it to the pixels the
// window has), it waits, with the configure, for the start of the next
// frame, the
// one that sends the surface its new size: until then a motion is still
// at the pixels of the scale before and the caret is not sent again, as
// the compositor maps the surface as before until that frame's commit
// - a scale that comes back to the one the window draws at before a frame
// owes nothing, and fires nothing
// - a configure without a size while a scale waits is acknowledged in the
// listener, as the scale itself is answered by no acknowledgement; one
// for the size the surface has waits for the frame that takes the
// scale, also where its pixels at that scale are the window's, and the
// window does not become one the compositor sized before then
// - before the window has its first swapchain the listener only keeps the
// scale, which the constructor's MatchSizesToScale takes; a scale of 0
// is not taken
//
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
// No compositor and no GPU. Needs the Wayland backend, hence Linux only.
#include <wayland-client.h>
#include <sys/socket.h>
#include <unistd.h>
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include "../../lib/xdg-shell-client-protocol.h"
#include "../../lib/viewporter.h"
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
#include "../../lib/text-input-unstable-v3-client-protocol.h"
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
import Crafter.Graphics;
import Crafter.Event;
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
import Crafter.Math;
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
import std;
using namespace Crafter;
namespace {
int failures = 0;
void Check(bool ok, std::string_view what) {
std::println("{} {}", ok ? "PASS" : "FAIL", what);
if (!ok) ++failures;
}
using Requests = std::vector<std::string>;
// `got` against `expected`, printing what came when they differ.
void Expect(const Requests& got, const Requests& expected, std::string_view what) {
Check(got == expected, what);
if (got != expected) {
std::println(" sent: {}", got);
std::println(" expected: {}", expected);
}
}
Requests Sorted(Requests requests) {
std::ranges::sort(requests);
return requests;
}
// Every acknowledgement the test read off the wire, in order.
std::vector<std::uint32_t> acknowledged;
// A compositor's serials: one counter, never reused.
std::uint32_t lastSerial = 100;
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// The text input whose caret Sent() reports, 0 while there is none.
std::uint32_t textInputId = 0;
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
// A window as its constructor leaves it: the first configure taken, a
// swapchain made, no frame presented yet. The swapchain is a handle nothing
// dereferences and a generation; the surface, the xdg_surface, the toplevel
// and the viewport are proxies nothing answers.
struct Fixture {
wl_display* display;
int peer;
std::optional<Window> holder;
std::uint32_t surfaceId = 0;
std::uint32_t xdgSurfaceId = 0;
std::uint32_t viewportId = 0;
int owed = 0;
std::optional<EventListener<void>> owedSub;
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// `scale` in 120ths, as the compositor names it.
Fixture(wl_display* display, wl_registry* registry, int peer, std::uint32_t scale, std::uint32_t width, std::uint32_t height, bool viewport = true)
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
: display(display), peer(peer) {
Window& window = holder.emplace();
window.surface = static_cast<wl_surface*>(wl_registry_bind(registry, 1, &wl_surface_interface, 1));
window.xdgSurface = static_cast<xdg_surface*>(wl_registry_bind(registry, 2, &xdg_surface_interface, 1));
window.xdgToplevel = static_cast<xdg_toplevel*>(wl_registry_bind(registry, 3, &xdg_toplevel_interface, 1));
if (viewport) {
window.wpViewport = static_cast<wp_viewport*>(wl_registry_bind(registry, 4, &wp_viewport_interface, 1));
viewportId = wl_proxy_get_id(reinterpret_cast<wl_proxy*>(window.wpViewport));
}
surfaceId = wl_proxy_get_id(reinterpret_cast<wl_proxy*>(window.surface));
xdgSurfaceId = wl_proxy_get_id(reinterpret_cast<wl_proxy*>(window.xdgSurface));
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// The scale the compositor named while the constructor waited.
window.preferredScale = scale;
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
window.width = width;
window.height = height;
// The configure the constructor waits for, before there is a swapchain.
Configure(0, 0);
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// The scale the window draws at, and the surface's size, from the
// constructor's pixels.
window.MatchSizesToScale(true);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
window.swapChain = reinterpret_cast<decltype(window.swapChain)>(static_cast<std::uintptr_t>(0x1));
window.swapchainGeneration = 1;
// Where the constructor lists it, and where the handler looks for a
// window that outlived its listeners.
Device::windows.push_back(&window);
owedSub.emplace(&window.onFrameOwed, [this] { ++owed; });
Sent();
}
~Fixture() {
// ~Window destroys the proxies; without a device it leaves the
// swapchain handle alone.
holder.reset();
Sent();
}
Window& window() { return *holder; }
// The compositor's two events of one batch. Returns the serial.
std::uint32_t Configure(std::int32_t width, std::int32_t height, std::initializer_list<std::uint32_t> states = {}) {
Window& window = *holder;
wl_array array;
wl_array_init(&array);
for (std::uint32_t state : states) {
*static_cast<std::uint32_t*>(wl_array_add(&array, sizeof(state))) = state;
}
// The handles before the calls: the second may destroy the window.
xdg_surface* const surface = window.xdgSurface;
Window::xdg_toplevel_configure(&window, window.xdgToplevel, width, height, &array);
wl_array_release(&array);
const std::uint32_t serial = ++lastSerial;
Window::xdg_surface_handle_configure(&window, surface, serial);
return serial;
}
// What RebuildSwapchain does besides its Vulkan calls: the window's two
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// sizes at the scale it draws at, which takes a new one only where it
// gives the window new pixels, and a swapchain, which CreateSwapchain
// numbers, after which none waits to be made.
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
void Rebuild() {
Window& window = *holder;
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
window.MatchSizesToScale(false);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
++window.swapchainGeneration;
window.swapchainRebuildPending = false;
}
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// A frame boundary of Render(), which is RebuildIfDeferred: the size
// that waits becomes the window's, and new pixels, or a rebuild that
// waited, make a new swapchain. True when one was made.
bool Boundary(Window::FrameBoundary boundary) {
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
Window& window = *holder;
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
if (!window.TakeDeferredSize(boundary) && !window.swapchainRebuildPending) return false;
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
Rebuild();
return true;
}
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// The start of Render().
bool Begin() { return Boundary(Window::FrameBoundary::Start); }
// The surface state for the frame, then the present, after which the
// surface shows this swapchain.
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
void Present() {
Window& window = *holder;
window.SendFrameSurfaceState();
window.presentedGeneration = window.swapchainGeneration;
}
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// The end of Render(), after the present: what the frame's listeners
// asked for while it was being recorded.
bool End() { return Boundary(Window::FrameBoundary::AfterPresent); }
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
// A whole frame.
void Frame() {
Begin();
Present();
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
End();
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
}
// What the window has sent to its surface, its xdg_surface and its
// viewport since the last call, in order: "commit", "ack <serial>",
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// "destination <w>x<h>", and the caret it gave the text input, "caret
// <x>,<y> <w>x<h>". A request is its object id, then its size and
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
// opcode in one word, then its arguments.
Requests Sent() {
wl_display_flush(display);
std::vector<std::uint8_t> wire;
std::uint8_t chunk[4096];
for (ssize_t n; (n = recv(peer, chunk, sizeof(chunk), MSG_DONTWAIT)) > 0;) {
wire.insert(wire.end(), chunk, chunk + n);
}
Requests requests;
for (std::size_t at = 0; at + 8 <= wire.size();) {
std::uint32_t header[2];
std::memcpy(header, wire.data() + at, sizeof(header));
const std::uint32_t size = header[1] >> 16;
const std::uint32_t opcode = header[1] & 0xFFFF;
if (size < 8 || at + size > wire.size()) break;
const auto argument = [&](std::size_t index) {
std::int32_t value = 0;
if (8 + 4 * (index + 1) <= size) std::memcpy(&value, wire.data() + at + 8 + 4 * index, sizeof(value));
return value;
};
if (header[0] == surfaceId && opcode == WL_SURFACE_COMMIT) {
requests.push_back("commit");
} else if (header[0] == xdgSurfaceId && opcode == XDG_SURFACE_ACK_CONFIGURE) {
requests.push_back(std::format("ack {}", static_cast<std::uint32_t>(argument(0))));
acknowledged.push_back(static_cast<std::uint32_t>(argument(0)));
} else if (viewportId != 0 && header[0] == viewportId && opcode == WP_VIEWPORT_SET_DESTINATION) {
requests.push_back(std::format("destination {}x{}", argument(0), argument(1)));
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
} else if (textInputId != 0 && header[0] == textInputId && opcode == ZWP_TEXT_INPUT_V3_SET_CURSOR_RECTANGLE) {
requests.push_back(std::format("caret {},{} {}x{}", argument(0), argument(1), argument(2), argument(3)));
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
}
at += size;
}
return requests;
}
};
bool NothingWaits(const Window& window) {
return window.deferredLogicalWidth == 0 && window.deferredLogicalHeight == 0 && !window.unackedConfigure
&& window.presentedGeneration == window.swapchainGeneration
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
&& window.sentLogicalWidth == window.logicalWidth && window.sentLogicalHeight == window.logicalHeight
&& window.scale == window.preferredScale / 120.0f;
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
}
// The scale as the compositor names it, in 120ths.
void Scale(Window& window, std::uint32_t scale120) {
Window::xdg_surface_handle_preferred_scale(&window, nullptr, scale120);
}
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// Where the pointer is in the window's pixels after a motion to (x, y) on
// its surface, as the compositor reports it, in surface-local units.
Vector<float, 2> Motion(Window& window, double x, double y) {
Device::focusedWindow = &window;
Device::PointerListenerHandleMotion(nullptr, nullptr, 0, wl_fixed_from_double(x), wl_fixed_from_double(y));
return window.currentMousePos;
}
// Whether `position` is (x, y), saying where it is when it is not.
void CheckAt(Vector<float, 2> position, float x, float y, std::string_view what) {
Check(position.x == x && position.y == y, what);
if (position.x != x || position.y != y) std::println(" at {},{}, where {},{} was expected", position.x, position.y, x, y);
}
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
} // namespace
int main() {
int fds[2];
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fds) != 0) {
std::println("FAIL socketpair: {}", std::strerror(errno));
return EXIT_FAILURE;
}
// The display owns fds[0] from here.
wl_display* display = wl_display_connect_to_fd(fds[0]);
if (display == nullptr) {
std::println("FAIL wl_display_connect_to_fd: {}", std::strerror(errno));
return EXIT_FAILURE;
}
// libwayland makes whatever proxy it is asked to bind; nothing answers.
wl_registry* registry = wl_display_get_registry(display);
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
const auto fixture = [&](std::uint32_t scale, std::uint32_t width, std::uint32_t height, bool viewport = true) {
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
return Fixture(display, registry, fds[1], scale, width, height, viewport);
};
// The window's first frame: the constructor sends no destination, the
// frame does. Every fixture after this one has it behind it.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Present();
Expect(f.Sent(), { "destination 320x240" }, "a window's first frame brings the viewport's destination");
Check(NothingWaits(f.window()), "after it nothing is owed");
f.Frame();
Expect(f.Sent(), {}, "the frames after it send nothing");
}
// A new size, and the frame that answers it.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
const std::uint32_t serial = f.Configure(400, 300);
Expect(f.Sent(), { "commit" },
"a configure for a new size: one bare commit, with neither the surface's new size nor an acknowledgement");
Check(window.width == 640 && window.height == 480,
std::format("the window's size is still the swapchain's ({}x{})", window.width, window.height));
Check(window.deferredLogicalWidth == 400 && window.deferredLogicalHeight == 300 && window.unackedConfigure == serial,
"the size and the serial wait for a frame");
Check(f.owed == 1, std::format("onFrameOwed fired once ({})", f.owed));
Check(f.Begin(), "the next frame takes the size");
Check(window.width == 800 && window.height == 600 && window.deferredLogicalWidth == 0 && window.deferredLogicalHeight == 0,
std::format("the window has it in pixels ({}x{} at scale 2), and no size waits", window.width, window.height));
Expect(f.Sent(), {}, "taking it sends nothing");
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 400x300" }),
"before its present the frame sends the destination and the acknowledgement, and does not commit");
Check(NothingWaits(window), "after the frame nothing is owed");
f.Frame();
Expect(f.Sent(), {}, "the frames after it send neither again");
Check(f.owed == 1, "onFrameOwed fired for the configure only");
}
// Several configures before a frame.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(120, 320, 240);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
f.Configure(400, 300);
f.Configure(500, 350);
const std::uint32_t last = f.Configure(0, 0, { XDG_TOPLEVEL_STATE_ACTIVATED });
Expect(f.Sent(), { "commit", "commit", "commit" }, "three configures before a frame: three bare commits");
Check(window.deferredLogicalWidth == 500 && window.deferredLogicalHeight == 350,
"the last size asked for waits, through a configure without a size");
Check(window.unackedConfigure == last, "the last serial waits, the one without a size");
Check(f.owed == 3, std::format("onFrameOwed fired for each ({})", f.owed));
Check(f.Begin() && window.width == 500 && window.height == 350, "one frame takes the last size");
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", last), "destination 500x350" }),
"and sends one destination and one acknowledgement, of the last serial");
Check(NothingWaits(window), "after the frame nothing is owed");
}
// Nothing new while nothing is owed: answered in the listener, as before.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
const std::uint32_t none = f.Configure(0, 0, { XDG_TOPLEVEL_STATE_ACTIVATED });
Expect(f.Sent(), { std::format("ack {}", none), "commit" },
"a configure without a size while nothing is owed: acknowledged in the listener, before its commit");
const std::uint32_t same = f.Configure(320, 240);
Expect(f.Sent(), { std::format("ack {}", same), "commit" },
"a configure for the size the window has: the same");
Check(NothingWaits(window) && f.owed == 0, "neither leaves a frame owed or fires onFrameOwed");
Check(!f.Begin(), "and the next frame makes no swapchain");
f.Present();
Expect(f.Sent(), {}, "nor sends anything");
}
// The compositor goes back to the size the window has before a frame.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(120, 320, 240);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
const std::uint32_t first = f.Configure(400, 300);
f.Sent();
const std::uint32_t back = f.Configure(320, 240);
Expect(f.Sent(), { std::format("ack {}", back), "commit" },
"a configure back to the window's size: acknowledged at once, as the surface shows that size");
Check(NothingWaits(window), "the size and the serial that waited are gone");
Check(!f.Begin(), "the next frame makes no swapchain");
f.Present();
Expect(f.Sent(), {}, std::format("and never acknowledges {}, the serial before the one acknowledged", first));
}
// A size that comes while a frame is being recorded.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(120, 320, 240);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
f.Begin();
const std::uint32_t serial = f.Configure(400, 300);
f.Present();
Expect(f.Sent(), { "commit" },
"a frame being recorded when a size comes: its present sends neither a destination nor an acknowledgement");
Check(window.unackedConfigure == serial && window.deferredLogicalWidth == 400, "the size and the serial wait on");
Check(f.Begin() && window.width == 400 && window.height == 300, "the frame after it takes the size");
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 400x300" }), "and answers the configure");
}
// A configure before the window's first frame.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
const std::uint32_t serial = f.Configure(0, 0, { XDG_TOPLEVEL_STATE_ACTIVATED });
Expect(f.Sent(), { "commit" }, "a configure before the window's first frame: not acknowledged in the listener");
Check(f.owed == 1, "onFrameOwed fired for it");
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 320x240" }),
"the first frame brings the destination and the acknowledgement");
}
// A swapchain made between frames, as Resize makes one outside a frame:
// its first frame brings the destination, and a configure before that
// frame waits for it.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
window.width = 800;
window.height = 500;
window.logicalConfigured = false;
f.Rebuild();
Expect(f.Sent(), {}, "a swapchain made at a new size sends the surface nothing");
const std::uint32_t serial = f.Configure(0, 0);
Expect(f.Sent(), { "commit" }, "a configure while a new swapchain waits for its first frame: not acknowledged in the listener");
Check(!f.Begin(), "no size waits for the frame");
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 400x250" }),
"the swapchain's first frame brings its destination and the acknowledgement");
// The same size again, as SetPresentMode makes a swapchain: the
// surface has its size, and a configure still waits for a buffer of
// the swapchain there is.
f.Rebuild();
const std::uint32_t second = f.Configure(400, 250);
Expect(f.Sent(), { "commit" }, "a configure for the window's size while a swapchain waits for its first frame: not acknowledged in the listener either");
Check(!f.Begin(), "nor is there a size for the frame to take");
f.Present();
Expect(f.Sent(), { std::format("ack {}", second) }, "that frame acknowledges it and sends no destination: the surface's size is the one it has");
}
// A rebuild that threw leaves the window's sizes ahead of the swapchain
// and stays pending for the next Render(). A configure for that size is
// not answered by what the surface shows: it waits for the frame too.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
// A size is taken and its rebuild throws: RebuildSwapchain has set
// its flag and made nothing.
f.Configure(400, 300);
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Check(window.TakeDeferredSize(Window::FrameBoundary::Start) && window.width == 800 && window.height == 600, "a size is taken, and the rebuild for it throws");
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
window.swapchainRebuildPending = true;
f.Sent();
const std::uint32_t serial = f.Configure(400, 300);
Expect(f.Sent(), { "commit" },
"a configure for the size a pending rebuild is for: not acknowledged in the listener, though the window's size says so already");
Check(window.deferredLogicalWidth == 0 && window.unackedConfigure == serial && f.owed == 2,
"no size waits, the serial does, and onFrameOwed fired");
Check(f.Begin() && window.width == 800 && window.height == 600 && !window.swapchainRebuildPending,
"the next frame makes the swapchain that waited");
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 400x300" }),
"the frame of the swapchain made at last brings the destination and the acknowledgement");
}
// A present that finds the swapchain out of date queues nothing, and
// Render() makes the swapchain again after it. What went out before
// that present is not sent a second time, and a configure that comes in
// between waits for the first frame of the swapchain made after it.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
const std::uint32_t serial = f.Configure(400, 300);
f.Sent();
Check(f.Begin(), "a frame takes a size");
// The present that follows returns VK_ERROR_OUT_OF_DATE_KHR:
// presentedGeneration stays, and a rebuild waits.
window.SendFrameSurfaceState();
window.swapchainRebuildPending = true;
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 400x300" }),
"its destination and acknowledgement go out before its present, which finds the swapchain out of date");
const std::uint32_t next = f.Configure(400, 300);
Expect(f.Sent(), { "commit" }, "a configure for that size before the swapchain is made again: not acknowledged in the listener");
Check(f.Begin(), "the next frame makes the swapchain");
f.Present();
Expect(f.Sent(), { std::format("ack {}", next) }, "and acknowledges, without sending the destination a second time");
Check(NothingWaits(window), "after it nothing is owed");
}
// Without wp_viewporter there is no destination, and the scale is 1.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(120, 320, 240, false);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
Expect(f.Sent(), {}, "without a viewport the first frame sends nothing");
Window& window = f.window();
const std::uint32_t serial = f.Configure(400, 300);
Expect(f.Sent(), { "commit" }, "without a viewport: a configure for a new size still waits for its frame");
Check(f.Begin() && window.width == 400 && window.height == 300, "the frame takes the size");
f.Present();
Expect(f.Sent(), { std::format("ack {}", serial) }, "and acknowledges, with no destination");
}
// The scale that counts for the pixels is the one of the moment the frame
// takes the size. The destination is the configured size whatever the
// scale does.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
const std::uint32_t serial = f.Configure(400, 300);
Scale(window, 180);
Check(f.Begin() && window.width == 600 && window.height == 450,
std::format("a scale that changes before the frame: the size is taken at the new one ({}x{} at 1.5)", window.width, window.height));
f.Sent();
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 400x300" }),
"and the destination is the size the compositor configured");
}
// The scale changes between the frame's start and its present: a
// listener of the frame dispatched the event (it made a window, or read
// the clipboard). The swapchain was made for the old scale, and the
// destination is still the configured size, not that swapchain's pixels
// over the new scale (534x400).
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
const std::uint32_t serial = f.Configure(400, 300);
Check(f.Begin() && window.width == 800 && window.height == 600, "the frame takes a size at scale 2");
Scale(window, 180);
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Check(window.scale == 2.0f && window.width == 800 && window.height == 600,
"a scale that changes while the frame is recorded: the frame goes on at the one it began with");
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Sent();
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 400x300" }),
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
"its present still sends the configured size");
Check(!window.unackedConfigure && window.deferredLogicalWidth == 0 && window.scale == 2.0f,
"and answers the configure, with the scale still waiting");
Check(f.End() && window.width == 600 && window.height == 450 && window.scale == 1.5f,
std::format("the boundary after the present takes the scale: {}x{} for 400x300 at 1.5", window.width, window.height));
Check(!f.Begin(), "the next frame's start finds nothing left to take, and makes no swapchain");
f.Present();
Expect(f.Sent(), {}, "and the frame drawn at it sends the surface nothing, as its size is the one it has");
Check(NothingWaits(window), "after it nothing is owed");
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
}
// A new size and a new scale that together come to the pixels the
// swapchain has: an output whose scale changes under a window that fills
// it. No swapchain is made, and the surface still has to be told its new
// size, in the commit that acknowledges the configure. First the
// configure, then the scale.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
Expect(f.Sent(), { "destination 320x240" }, "a window of 640x480 pixels at scale 2 is 320x240");
Window& window = f.window();
const std::uint32_t serial = f.Configure(640, 480);
Expect(f.Sent(), { "commit" }, "a configure for 640x480 at scale 2: a new size, which waits");
Check(f.owed == 1, "onFrameOwed fired");
Scale(window, 120);
Check(!f.Begin() && window.width == 640 && window.height == 480,
"the scale becomes 1 before the frame: the size comes to the pixels the swapchain has, and none is made");
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 640x480" }),
"the frame brings the surface its new size with the acknowledgement");
Check(NothingWaits(window), "after it nothing is owed");
const std::uint32_t again = f.Configure(640, 480);
Expect(f.Sent(), { std::format("ack {}", again), "commit" }, "and the same configure again is answered by what the surface shows");
}
// The other order: the scale first, then the configure, whose size is in
// pixels the one the swapchain has.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(180, 600, 450);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
Expect(f.Sent(), { "destination 400x300" }, "a window of 600x450 pixels at scale 1.5 is 400x300");
Window& window = f.window();
Scale(window, 240);
const std::uint32_t serial = f.Configure(300, 225);
Expect(f.Sent(), { "commit" },
"the scale becomes 2, then a configure for 300x225, the pixels the swapchain has: not acknowledged in the listener, as the surface is 400x300");
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Check(window.deferredLogicalWidth == 300 && window.deferredLogicalHeight == 225 && f.owed == 2,
std::format("the size waits, and onFrameOwed fired for the scale and for the configure ({})", f.owed));
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
Check(!f.Begin() && window.width == 600 && window.height == 450, "the frame makes no swapchain");
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 300x225" }),
"and brings the surface its new size with the acknowledgement");
}
// The size the surface has, after the scale changed: the buffers are
// made again for the new scale, and the surface is sent nothing.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
Scale(window, 180);
const std::uint32_t serial = f.Configure(320, 240);
Expect(f.Sent(), { "commit" }, "a configure for the surface's size after the scale changed: it waits for buffers at the new scale");
Check(f.Begin() && window.width == 480 && window.height == 360,
std::format("the frame makes the swapchain again for the scale ({}x{} at 1.5)", window.width, window.height));
f.Present();
Expect(f.Sent(), { std::format("ack {}", serial) }, "and acknowledges, with no destination: the surface's size is the one it has");
}
// A fractional scale, with the numbers of #201's trace: a phone at 2.85
// whose maximized window is configured 392x796. The destination is that
// size, where it used to be worked back from the 1118x2269 pixels to
// 393x797, and the window is left alone when the compositor configures
// it at the size it has, where it used to grow with each such configure
fix(wayland): round a configured size's pixels half away from zero, and work both sizes out exactly from the scale's 120ths A size the compositor configured became the buffers' size as ceil(size * scale), in float. The protocol, as bundled in lib/fractional-scale-v1.h, has the buffer's size as the surface's times the scale, and says that "For toplevel surfaces, the size is rounded halfway away from zero": wherever the product's fraction is below a half, rounding up gave a pixel more than that. 89111e0 left this as the rest of #201, and the comment on #165 asks for it. And the sum was done in float, with the scale as a float, which a scale that is no whole number of eighths is not exactly: a product that is a whole number of pixels could come out just above it, and rounding up then went a pixel past it, as 50 at 1.2 came to 61. The other way, the surface's size for a window the application sized, ceil(pixels / scale), had the same trouble: 171 pixels at 2.85 came to 61, where they are 60. Window: ScaledPixels rounds half away from zero, and both it and SurfaceLength work in 64-bit integers from the 120ths the compositor sends: MatchSizesToScale from those of the scale the window draws at, which a new member, drawnScale_, keeps beside scale, as they are not preferredScale while a new scale waits, and the tests of whether a scale gives the window new pixels from preferredScale. SurfaceLength still rounds up, so that the surface of a window the application sized is no smaller than its pixels at the scale. ScaledPixels never gives less than one pixel: below a scale of a half a length of one rounds to none, where rounding up gave one, and a swapchain cannot be made 0 wide or high. Nor more than the largest 32-bit value, which a configured length can pass at a scale above 2 (2^30 at 4 comes to 2^32), where the cast to 32 bits would wrap it, to none in that case; and SurfaceLength stops at the largest int32, which a length worked out from 32-bit pixels can pass. The configure listener's test for a configure at the size the window has uses the same sum, so a configured size the window took is found to be the one it has, and so do the tests, in TakeDeferredSize after a present and in MatchSizesToScale, of whether a size or a scale comes to new pixels; and the listener tells that no new scale waits from the 120ths, preferredScale against drawnScale_, where 61f2698 compared the two scales as floats. So 392x796 at 2.85, the size in #201's phone trace, takes 1117x2269 pixels where it took 1118x2269. A window of 320x240 pixels at 1.75, shown at 183x138, takes 320x242 for a configure of that size, where it took 321x242. Docs: the consumer notes say how a configured size's pixels are rounded, and that the surface of a window the application sized is rounded up; the guide's gotchas, that both are worked out in integers from the 120ths; both, that the pixels are never fewer than one nor more than the largest 32-bit value, and that the surface's length never passes the largest int32. The gotcha and the interface's comment on logicalWidth give, as a reason not to work the surface's size back from the pixels, that a configured size worked back from them lands above itself wherever its product with the scale is not whole. That held while both roundings went up; now it lands above where that product has a fraction of a half or more, short of the 32-bit limits the two sums stop at, and both say so. Tests: ConfigureResize takes the new numbers in its cases of #201's trace and of the window at 1.75, and adds the protocol's own example (100x50 at 1.5 is 150x75), halves that go up (853x101 at 1.5 is 1280x152), fractions below a half that go down (101x853 at 1.25 is 126x1066, which rounding up made 127x1067), and whole numbers the sum in float came out above (50x25 at 1.2 is 60x30, which came to 61x31), each acknowledged in the listener when it is configured again; a configure of 1x300 at 0.4, whose width rounds to no pixel, taken as 1x120; a configure of 2^30x300 at 4, whose width is the largest 32-bit value, and pixels of that value at a half, whose surface is the largest int32 wide; and a window of 342x171 pixels at 2.85, whose surface is 120x60, which came to 121x61. And it works configured sizes into pixels and back with a window's own MatchSizesToScale: 853x101 at 1.5 comes back as 854x102, and 392x796 at 2.85 as 392x797. ResizeViewport works the pixels and the surface's size out as the window now does, and its comments say which way each is rounded.
2026-11-27 10:07:37 +01:00
// until it was 400x800. The pixels are 392x796 at 2.85 rounded half away
// from zero, 1117.2 and 2268.6, where they were rounded up to 1118x2269.
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(342, 1140, 2280);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
Expect(f.Sent(), { "destination 400x800" }, "a window of 1140x2280 pixels at scale 2.85 is 400x800");
Window& window = f.window();
const std::uint32_t serial = f.Configure(392, 796);
f.Sent();
fix(wayland): round a configured size's pixels half away from zero, and work both sizes out exactly from the scale's 120ths A size the compositor configured became the buffers' size as ceil(size * scale), in float. The protocol, as bundled in lib/fractional-scale-v1.h, has the buffer's size as the surface's times the scale, and says that "For toplevel surfaces, the size is rounded halfway away from zero": wherever the product's fraction is below a half, rounding up gave a pixel more than that. 89111e0 left this as the rest of #201, and the comment on #165 asks for it. And the sum was done in float, with the scale as a float, which a scale that is no whole number of eighths is not exactly: a product that is a whole number of pixels could come out just above it, and rounding up then went a pixel past it, as 50 at 1.2 came to 61. The other way, the surface's size for a window the application sized, ceil(pixels / scale), had the same trouble: 171 pixels at 2.85 came to 61, where they are 60. Window: ScaledPixels rounds half away from zero, and both it and SurfaceLength work in 64-bit integers from the 120ths the compositor sends: MatchSizesToScale from those of the scale the window draws at, which a new member, drawnScale_, keeps beside scale, as they are not preferredScale while a new scale waits, and the tests of whether a scale gives the window new pixels from preferredScale. SurfaceLength still rounds up, so that the surface of a window the application sized is no smaller than its pixels at the scale. ScaledPixels never gives less than one pixel: below a scale of a half a length of one rounds to none, where rounding up gave one, and a swapchain cannot be made 0 wide or high. Nor more than the largest 32-bit value, which a configured length can pass at a scale above 2 (2^30 at 4 comes to 2^32), where the cast to 32 bits would wrap it, to none in that case; and SurfaceLength stops at the largest int32, which a length worked out from 32-bit pixels can pass. The configure listener's test for a configure at the size the window has uses the same sum, so a configured size the window took is found to be the one it has, and so do the tests, in TakeDeferredSize after a present and in MatchSizesToScale, of whether a size or a scale comes to new pixels; and the listener tells that no new scale waits from the 120ths, preferredScale against drawnScale_, where 61f2698 compared the two scales as floats. So 392x796 at 2.85, the size in #201's phone trace, takes 1117x2269 pixels where it took 1118x2269. A window of 320x240 pixels at 1.75, shown at 183x138, takes 320x242 for a configure of that size, where it took 321x242. Docs: the consumer notes say how a configured size's pixels are rounded, and that the surface of a window the application sized is rounded up; the guide's gotchas, that both are worked out in integers from the 120ths; both, that the pixels are never fewer than one nor more than the largest 32-bit value, and that the surface's length never passes the largest int32. The gotcha and the interface's comment on logicalWidth give, as a reason not to work the surface's size back from the pixels, that a configured size worked back from them lands above itself wherever its product with the scale is not whole. That held while both roundings went up; now it lands above where that product has a fraction of a half or more, short of the 32-bit limits the two sums stop at, and both say so. Tests: ConfigureResize takes the new numbers in its cases of #201's trace and of the window at 1.75, and adds the protocol's own example (100x50 at 1.5 is 150x75), halves that go up (853x101 at 1.5 is 1280x152), fractions below a half that go down (101x853 at 1.25 is 126x1066, which rounding up made 127x1067), and whole numbers the sum in float came out above (50x25 at 1.2 is 60x30, which came to 61x31), each acknowledged in the listener when it is configured again; a configure of 1x300 at 0.4, whose width rounds to no pixel, taken as 1x120; a configure of 2^30x300 at 4, whose width is the largest 32-bit value, and pixels of that value at a half, whose surface is the largest int32 wide; and a window of 342x171 pixels at 2.85, whose surface is 120x60, which came to 121x61. And it works configured sizes into pixels and back with a window's own MatchSizesToScale: 853x101 at 1.5 comes back as 854x102, and 392x796 at 2.85 as 392x797. ResizeViewport works the pixels and the surface's size out as the window now does, and its comments say which way each is rounded.
2026-11-27 10:07:37 +01:00
Check(f.Begin() && window.width == 1117 && window.height == 2269,
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
std::format("392x796 at scale 2.85 is taken as {}x{} pixels", window.width, window.height));
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 392x796" }),
"and the destination is 392x796, the configured size itself");
for (int i = 0; i < 3; ++i) {
const std::uint32_t again = f.Configure(392, 796);
Expect(f.Sent(), { std::format("ack {}", again), "commit" }, "the compositor configures the window at the size it has: acknowledged at once");
fix(wayland): round a configured size's pixels half away from zero, and work both sizes out exactly from the scale's 120ths A size the compositor configured became the buffers' size as ceil(size * scale), in float. The protocol, as bundled in lib/fractional-scale-v1.h, has the buffer's size as the surface's times the scale, and says that "For toplevel surfaces, the size is rounded halfway away from zero": wherever the product's fraction is below a half, rounding up gave a pixel more than that. 89111e0 left this as the rest of #201, and the comment on #165 asks for it. And the sum was done in float, with the scale as a float, which a scale that is no whole number of eighths is not exactly: a product that is a whole number of pixels could come out just above it, and rounding up then went a pixel past it, as 50 at 1.2 came to 61. The other way, the surface's size for a window the application sized, ceil(pixels / scale), had the same trouble: 171 pixels at 2.85 came to 61, where they are 60. Window: ScaledPixels rounds half away from zero, and both it and SurfaceLength work in 64-bit integers from the 120ths the compositor sends: MatchSizesToScale from those of the scale the window draws at, which a new member, drawnScale_, keeps beside scale, as they are not preferredScale while a new scale waits, and the tests of whether a scale gives the window new pixels from preferredScale. SurfaceLength still rounds up, so that the surface of a window the application sized is no smaller than its pixels at the scale. ScaledPixels never gives less than one pixel: below a scale of a half a length of one rounds to none, where rounding up gave one, and a swapchain cannot be made 0 wide or high. Nor more than the largest 32-bit value, which a configured length can pass at a scale above 2 (2^30 at 4 comes to 2^32), where the cast to 32 bits would wrap it, to none in that case; and SurfaceLength stops at the largest int32, which a length worked out from 32-bit pixels can pass. The configure listener's test for a configure at the size the window has uses the same sum, so a configured size the window took is found to be the one it has, and so do the tests, in TakeDeferredSize after a present and in MatchSizesToScale, of whether a size or a scale comes to new pixels; and the listener tells that no new scale waits from the 120ths, preferredScale against drawnScale_, where 61f2698 compared the two scales as floats. So 392x796 at 2.85, the size in #201's phone trace, takes 1117x2269 pixels where it took 1118x2269. A window of 320x240 pixels at 1.75, shown at 183x138, takes 320x242 for a configure of that size, where it took 321x242. Docs: the consumer notes say how a configured size's pixels are rounded, and that the surface of a window the application sized is rounded up; the guide's gotchas, that both are worked out in integers from the 120ths; both, that the pixels are never fewer than one nor more than the largest 32-bit value, and that the surface's length never passes the largest int32. The gotcha and the interface's comment on logicalWidth give, as a reason not to work the surface's size back from the pixels, that a configured size worked back from them lands above itself wherever its product with the scale is not whole. That held while both roundings went up; now it lands above where that product has a fraction of a half or more, short of the 32-bit limits the two sums stop at, and both say so. Tests: ConfigureResize takes the new numbers in its cases of #201's trace and of the window at 1.75, and adds the protocol's own example (100x50 at 1.5 is 150x75), halves that go up (853x101 at 1.5 is 1280x152), fractions below a half that go down (101x853 at 1.25 is 126x1066, which rounding up made 127x1067), and whole numbers the sum in float came out above (50x25 at 1.2 is 60x30, which came to 61x31), each acknowledged in the listener when it is configured again; a configure of 1x300 at 0.4, whose width rounds to no pixel, taken as 1x120; a configure of 2^30x300 at 4, whose width is the largest 32-bit value, and pixels of that value at a half, whose surface is the largest int32 wide; and a window of 342x171 pixels at 2.85, whose surface is 120x60, which came to 121x61. And it works configured sizes into pixels and back with a window's own MatchSizesToScale: 853x101 at 1.5 comes back as 854x102, and 392x796 at 2.85 as 392x797. ResizeViewport works the pixels and the surface's size out as the window now does, and its comments say which way each is rounded.
2026-11-27 10:07:37 +01:00
Check(!f.Begin() && window.width == 1117 && window.height == 2269, "and the window does not grow");
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Present();
Expect(f.Sent(), {}, "nor is the surface sent anything");
}
}
// A window the application sized, whose pixels do not come to a whole
// surface-local size: 320x240 at 1.75 is shown at 183x138. When the
// compositor configures that size, the window takes the pixels for it
fix(wayland): round a configured size's pixels half away from zero, and work both sizes out exactly from the scale's 120ths A size the compositor configured became the buffers' size as ceil(size * scale), in float. The protocol, as bundled in lib/fractional-scale-v1.h, has the buffer's size as the surface's times the scale, and says that "For toplevel surfaces, the size is rounded halfway away from zero": wherever the product's fraction is below a half, rounding up gave a pixel more than that. 89111e0 left this as the rest of #201, and the comment on #165 asks for it. And the sum was done in float, with the scale as a float, which a scale that is no whole number of eighths is not exactly: a product that is a whole number of pixels could come out just above it, and rounding up then went a pixel past it, as 50 at 1.2 came to 61. The other way, the surface's size for a window the application sized, ceil(pixels / scale), had the same trouble: 171 pixels at 2.85 came to 61, where they are 60. Window: ScaledPixels rounds half away from zero, and both it and SurfaceLength work in 64-bit integers from the 120ths the compositor sends: MatchSizesToScale from those of the scale the window draws at, which a new member, drawnScale_, keeps beside scale, as they are not preferredScale while a new scale waits, and the tests of whether a scale gives the window new pixels from preferredScale. SurfaceLength still rounds up, so that the surface of a window the application sized is no smaller than its pixels at the scale. ScaledPixels never gives less than one pixel: below a scale of a half a length of one rounds to none, where rounding up gave one, and a swapchain cannot be made 0 wide or high. Nor more than the largest 32-bit value, which a configured length can pass at a scale above 2 (2^30 at 4 comes to 2^32), where the cast to 32 bits would wrap it, to none in that case; and SurfaceLength stops at the largest int32, which a length worked out from 32-bit pixels can pass. The configure listener's test for a configure at the size the window has uses the same sum, so a configured size the window took is found to be the one it has, and so do the tests, in TakeDeferredSize after a present and in MatchSizesToScale, of whether a size or a scale comes to new pixels; and the listener tells that no new scale waits from the 120ths, preferredScale against drawnScale_, where 61f2698 compared the two scales as floats. So 392x796 at 2.85, the size in #201's phone trace, takes 1117x2269 pixels where it took 1118x2269. A window of 320x240 pixels at 1.75, shown at 183x138, takes 320x242 for a configure of that size, where it took 321x242. Docs: the consumer notes say how a configured size's pixels are rounded, and that the surface of a window the application sized is rounded up; the guide's gotchas, that both are worked out in integers from the 120ths; both, that the pixels are never fewer than one nor more than the largest 32-bit value, and that the surface's length never passes the largest int32. The gotcha and the interface's comment on logicalWidth give, as a reason not to work the surface's size back from the pixels, that a configured size worked back from them lands above itself wherever its product with the scale is not whole. That held while both roundings went up; now it lands above where that product has a fraction of a half or more, short of the 32-bit limits the two sums stop at, and both say so. Tests: ConfigureResize takes the new numbers in its cases of #201's trace and of the window at 1.75, and adds the protocol's own example (100x50 at 1.5 is 150x75), halves that go up (853x101 at 1.5 is 1280x152), fractions below a half that go down (101x853 at 1.25 is 126x1066, which rounding up made 127x1067), and whole numbers the sum in float came out above (50x25 at 1.2 is 60x30, which came to 61x31), each acknowledged in the listener when it is configured again; a configure of 1x300 at 0.4, whose width rounds to no pixel, taken as 1x120; a configure of 2^30x300 at 4, whose width is the largest 32-bit value, and pixels of that value at a half, whose surface is the largest int32 wide; and a window of 342x171 pixels at 2.85, whose surface is 120x60, which came to 121x61. And it works configured sizes into pixels and back with a window's own MatchSizesToScale: 853x101 at 1.5 comes back as 854x102, and 392x796 at 2.85 as 392x797. ResizeViewport works the pixels and the surface's size out as the window now does, and its comments say which way each is rounded.
2026-11-27 10:07:37 +01:00
// once, and is then left alone. 183x138 at 1.75 is 320.25x241.5, so
// the width stays and the height goes to 242.
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(210, 320, 240);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
Expect(f.Sent(), { "destination 183x138" }, "a window of 320x240 pixels at scale 1.75 is shown at 183x138");
Window& window = f.window();
const std::uint32_t serial = f.Configure(183, 138);
f.Sent();
fix(wayland): round a configured size's pixels half away from zero, and work both sizes out exactly from the scale's 120ths A size the compositor configured became the buffers' size as ceil(size * scale), in float. The protocol, as bundled in lib/fractional-scale-v1.h, has the buffer's size as the surface's times the scale, and says that "For toplevel surfaces, the size is rounded halfway away from zero": wherever the product's fraction is below a half, rounding up gave a pixel more than that. 89111e0 left this as the rest of #201, and the comment on #165 asks for it. And the sum was done in float, with the scale as a float, which a scale that is no whole number of eighths is not exactly: a product that is a whole number of pixels could come out just above it, and rounding up then went a pixel past it, as 50 at 1.2 came to 61. The other way, the surface's size for a window the application sized, ceil(pixels / scale), had the same trouble: 171 pixels at 2.85 came to 61, where they are 60. Window: ScaledPixels rounds half away from zero, and both it and SurfaceLength work in 64-bit integers from the 120ths the compositor sends: MatchSizesToScale from those of the scale the window draws at, which a new member, drawnScale_, keeps beside scale, as they are not preferredScale while a new scale waits, and the tests of whether a scale gives the window new pixels from preferredScale. SurfaceLength still rounds up, so that the surface of a window the application sized is no smaller than its pixels at the scale. ScaledPixels never gives less than one pixel: below a scale of a half a length of one rounds to none, where rounding up gave one, and a swapchain cannot be made 0 wide or high. Nor more than the largest 32-bit value, which a configured length can pass at a scale above 2 (2^30 at 4 comes to 2^32), where the cast to 32 bits would wrap it, to none in that case; and SurfaceLength stops at the largest int32, which a length worked out from 32-bit pixels can pass. The configure listener's test for a configure at the size the window has uses the same sum, so a configured size the window took is found to be the one it has, and so do the tests, in TakeDeferredSize after a present and in MatchSizesToScale, of whether a size or a scale comes to new pixels; and the listener tells that no new scale waits from the 120ths, preferredScale against drawnScale_, where 61f2698 compared the two scales as floats. So 392x796 at 2.85, the size in #201's phone trace, takes 1117x2269 pixels where it took 1118x2269. A window of 320x240 pixels at 1.75, shown at 183x138, takes 320x242 for a configure of that size, where it took 321x242. Docs: the consumer notes say how a configured size's pixels are rounded, and that the surface of a window the application sized is rounded up; the guide's gotchas, that both are worked out in integers from the 120ths; both, that the pixels are never fewer than one nor more than the largest 32-bit value, and that the surface's length never passes the largest int32. The gotcha and the interface's comment on logicalWidth give, as a reason not to work the surface's size back from the pixels, that a configured size worked back from them lands above itself wherever its product with the scale is not whole. That held while both roundings went up; now it lands above where that product has a fraction of a half or more, short of the 32-bit limits the two sums stop at, and both say so. Tests: ConfigureResize takes the new numbers in its cases of #201's trace and of the window at 1.75, and adds the protocol's own example (100x50 at 1.5 is 150x75), halves that go up (853x101 at 1.5 is 1280x152), fractions below a half that go down (101x853 at 1.25 is 126x1066, which rounding up made 127x1067), and whole numbers the sum in float came out above (50x25 at 1.2 is 60x30, which came to 61x31), each acknowledged in the listener when it is configured again; a configure of 1x300 at 0.4, whose width rounds to no pixel, taken as 1x120; a configure of 2^30x300 at 4, whose width is the largest 32-bit value, and pixels of that value at a half, whose surface is the largest int32 wide; and a window of 342x171 pixels at 2.85, whose surface is 120x60, which came to 121x61. And it works configured sizes into pixels and back with a window's own MatchSizesToScale: 853x101 at 1.5 comes back as 854x102, and 392x796 at 2.85 as 392x797. ResizeViewport works the pixels and the surface's size out as the window now does, and its comments say which way each is rounded.
2026-11-27 10:07:37 +01:00
Check(f.Begin() && window.width == 320 && window.height == 242,
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
std::format("configured at 183x138, it takes the pixels for that size ({}x{})", window.width, window.height));
f.Present();
Expect(f.Sent(), { std::format("ack {}", serial) }, "and the surface, which has that size, is sent no destination");
const std::uint32_t again = f.Configure(183, 138);
Expect(f.Sent(), { std::format("ack {}", again), "commit" }, "the same configure again is acknowledged at once");
fix(wayland): round a configured size's pixels half away from zero, and work both sizes out exactly from the scale's 120ths A size the compositor configured became the buffers' size as ceil(size * scale), in float. The protocol, as bundled in lib/fractional-scale-v1.h, has the buffer's size as the surface's times the scale, and says that "For toplevel surfaces, the size is rounded halfway away from zero": wherever the product's fraction is below a half, rounding up gave a pixel more than that. 89111e0 left this as the rest of #201, and the comment on #165 asks for it. And the sum was done in float, with the scale as a float, which a scale that is no whole number of eighths is not exactly: a product that is a whole number of pixels could come out just above it, and rounding up then went a pixel past it, as 50 at 1.2 came to 61. The other way, the surface's size for a window the application sized, ceil(pixels / scale), had the same trouble: 171 pixels at 2.85 came to 61, where they are 60. Window: ScaledPixels rounds half away from zero, and both it and SurfaceLength work in 64-bit integers from the 120ths the compositor sends: MatchSizesToScale from those of the scale the window draws at, which a new member, drawnScale_, keeps beside scale, as they are not preferredScale while a new scale waits, and the tests of whether a scale gives the window new pixels from preferredScale. SurfaceLength still rounds up, so that the surface of a window the application sized is no smaller than its pixels at the scale. ScaledPixels never gives less than one pixel: below a scale of a half a length of one rounds to none, where rounding up gave one, and a swapchain cannot be made 0 wide or high. Nor more than the largest 32-bit value, which a configured length can pass at a scale above 2 (2^30 at 4 comes to 2^32), where the cast to 32 bits would wrap it, to none in that case; and SurfaceLength stops at the largest int32, which a length worked out from 32-bit pixels can pass. The configure listener's test for a configure at the size the window has uses the same sum, so a configured size the window took is found to be the one it has, and so do the tests, in TakeDeferredSize after a present and in MatchSizesToScale, of whether a size or a scale comes to new pixels; and the listener tells that no new scale waits from the 120ths, preferredScale against drawnScale_, where 61f2698 compared the two scales as floats. So 392x796 at 2.85, the size in #201's phone trace, takes 1117x2269 pixels where it took 1118x2269. A window of 320x240 pixels at 1.75, shown at 183x138, takes 320x242 for a configure of that size, where it took 321x242. Docs: the consumer notes say how a configured size's pixels are rounded, and that the surface of a window the application sized is rounded up; the guide's gotchas, that both are worked out in integers from the 120ths; both, that the pixels are never fewer than one nor more than the largest 32-bit value, and that the surface's length never passes the largest int32. The gotcha and the interface's comment on logicalWidth give, as a reason not to work the surface's size back from the pixels, that a configured size worked back from them lands above itself wherever its product with the scale is not whole. That held while both roundings went up; now it lands above where that product has a fraction of a half or more, short of the 32-bit limits the two sums stop at, and both say so. Tests: ConfigureResize takes the new numbers in its cases of #201's trace and of the window at 1.75, and adds the protocol's own example (100x50 at 1.5 is 150x75), halves that go up (853x101 at 1.5 is 1280x152), fractions below a half that go down (101x853 at 1.25 is 126x1066, which rounding up made 127x1067), and whole numbers the sum in float came out above (50x25 at 1.2 is 60x30, which came to 61x31), each acknowledged in the listener when it is configured again; a configure of 1x300 at 0.4, whose width rounds to no pixel, taken as 1x120; a configure of 2^30x300 at 4, whose width is the largest 32-bit value, and pixels of that value at a half, whose surface is the largest int32 wide; and a window of 342x171 pixels at 2.85, whose surface is 120x60, which came to 121x61. And it works configured sizes into pixels and back with a window's own MatchSizesToScale: 853x101 at 1.5 comes back as 854x102, and 392x796 at 2.85 as 392x797. ResizeViewport works the pixels and the surface's size out as the window now does, and its comments say which way each is rounded.
2026-11-27 10:07:37 +01:00
Check(!f.Begin() && window.width == 320 && window.height == 242, "and changes nothing");
}
// The rounding of the pixels, as fractional-scale-v1 has it for a
// toplevel: a configured size times the scale, rounded half away from
// zero, worked out exactly. Its own example is 100x50 at 1.5, which is
// 150x75. A half goes up: 853x101 at 1.5 is 1279.5x151.5. Less than a
// half goes down, where rounding up gave a pixel more: 101x853 at 1.25
// is 126.25x1066.25. And a whole number stays one, where the sum in
// float came out above it and was rounded up past it: 50x25 at 1.2 is
// 60x30, and came to 61x31.
{
struct Case { std::uint32_t scale; std::int32_t width, height; std::uint32_t pixelsWidth, pixelsHeight; };
for (const Case& c : { Case{ 180, 100, 50, 150, 75 }, Case{ 180, 853, 101, 1280, 152 }, Case{ 150, 101, 853, 126, 1066 },
Case{ 144, 50, 25, 60, 30 } }) {
Fixture f = fixture(c.scale, 640, 480);
f.Frame();
f.Sent();
Window& window = f.window();
const std::uint32_t serial = f.Configure(c.width, c.height);
f.Sent();
Check(f.Begin() && window.width == c.pixelsWidth && window.height == c.pixelsHeight,
std::format("{}x{} at {} is taken as {}x{} pixels ({}x{})", c.width, c.height, c.scale / 120.0f, c.pixelsWidth, c.pixelsHeight,
window.width, window.height));
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), std::format("destination {}x{}", c.width, c.height) }),
"and the frame brings the surface that size");
const std::uint32_t again = f.Configure(c.width, c.height);
Expect(f.Sent(), { std::format("ack {}", again), "commit" }, "the same configure again is acknowledged at once, as the pixels are those");
}
}
// The other way, for a window the application sized: the surface is its
// pixels over the scale, rounded up, and worked out exactly too. 342x171
// at 2.85 is 120x60, which the sum in float came out above and was
// rounded up past to 121x61.
{
Fixture f = fixture(342, 342, 171);
f.Frame();
Expect(f.Sent(), { "destination 120x60" }, "a window of 342x171 pixels at scale 2.85 is 120x60");
}
// Never below one pixel: at 0.4, 48 120ths, a length of one is 0.4 of a
// pixel, which rounds to none, and a swapchain cannot be 0 wide. 1x300
// at 0.4 is taken as 1x120.
{
Fixture f = fixture(48, 640, 480);
f.Frame();
f.Sent();
Window& window = f.window();
const std::uint32_t serial = f.Configure(1, 300);
f.Sent();
Check(f.Begin() && window.width == 1 && window.height == 120,
std::format("1x300 at 0.4 is taken as 1x120 pixels, one pixel and not none for the width ({}x{})", window.width, window.height));
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 1x300" }), "and the frame brings the surface 1x300");
const std::uint32_t again = f.Configure(1, 300);
Expect(f.Sent(), { std::format("ack {}", again), "commit" }, "the same configure again is acknowledged at once, as the pixels are those");
}
// Nor past the largest 32-bit value: a configured length of 2^30 at a
// scale of 4 comes to 2^32 pixels, which the cast to 32 bits would wrap
// to none. And the surface's length worked out from pixels of the
// largest 32-bit value at a half stops at the largest int32, where the
// cast would wrap it.
{
Fixture f = fixture(480, 640, 480);
f.Frame();
f.Sent();
Window& window = f.window();
f.Configure(1073741824, 300);
Check(f.Begin() && window.width == std::numeric_limits<std::uint32_t>::max() && window.height == 1200,
std::format("a configure of 2^30x300 at 4 takes {}x{} pixels, the largest 32-bit value and not none", window.width, window.height));
f.Present();
f.Sent();
}
{
// Value-initialized, as below: the scale it takes converts the
// positions it holds.
Window window{};
window.preferredScale = 60;
window.width = std::numeric_limits<std::uint32_t>::max();
window.height = 100;
window.MatchSizesToScale(true);
Check(window.logicalWidth == std::numeric_limits<std::int32_t>::max() && window.logicalHeight == 200,
std::format("pixels of the largest 32-bit value at a half come to a surface {} wide, the largest int32", window.logicalWidth));
}
// A configured size worked back from its pixels, as nothing in the
// window does any more, the surface's size being state of its own:
// short of the 32-bit limits the two sums stop at, it lands above itself
// where its product with the scale has a fraction of a half or more,
// and, from a scale of a half up, on itself below that.
// 853x101 at 1.5 is 1279.5x151.5, so 1280x152 pixels, which come to
// 854x102; 392x796 at 2.85 is 1117.2x2268.6, so 1117x2269 pixels, which
// come to 392x797. The window's own sums: the pixels as for a configured
// size, then the surface's size as for a window the application sized at
// those pixels.
{
struct Case { std::uint32_t scale; std::int32_t width, height, backWidth, backHeight; };
for (const Case& c : { Case{ 180, 853, 101, 854, 102 }, Case{ 342, 392, 796, 392, 797 } }) {
// Value-initialized: the scale it takes converts the positions
// it holds, which a default-initialized window has none of.
Window window{};
window.preferredScale = c.scale;
window.logicalWidth = c.width;
window.logicalHeight = c.height;
window.logicalConfigured = true;
window.MatchSizesToScale(true);
const std::uint32_t pixelsWidth = window.width;
const std::uint32_t pixelsHeight = window.height;
window.logicalConfigured = false;
window.MatchSizesToScale(true);
Check(window.logicalWidth == c.backWidth && window.logicalHeight == c.backHeight,
std::format("{}x{} at {} is {}x{} pixels, which come to {}x{} ({}x{})", c.width, c.height, c.scale / 120.0f,
pixelsWidth, pixelsHeight, c.backWidth, c.backHeight, window.logicalWidth, window.logicalHeight));
}
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
}
// A swapchain made for another reason (a present mode, a swapchain out
// of date) after the scale changed, with no configure in between. A
// window the compositor sized keeps the surface's size and takes the
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
// pixels for it at the new scale. One the application sized keeps its
// pixels and takes no scale: nothing of that swapchain needs it, and
// until the next frame, which sends the surface its new size, the
// compositor maps the surface as before.
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Configure(400, 300);
f.Frame();
f.Sent();
Window& window = f.window();
Check(window.width == 800 && window.height == 600 && window.logicalConfigured, "a window the compositor sized, 400x300 at scale 2");
Scale(window, 180);
f.Rebuild();
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Check(window.width == 600 && window.height == 450 && window.logicalWidth == 400 && window.logicalHeight == 300 && window.scale == 1.5f,
std::format("a swapchain made after the scale became 1.5: the pixels for 400x300 at it ({}x{}), and the window draws at it", window.width, window.height));
Check(!f.Begin(), "the next frame boundary finds nothing left to take");
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Present();
Expect(f.Sent(), {}, "and the surface, still 400x300, is sent nothing");
}
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
Check(!window.logicalConfigured, "a window the application sized, 640x480 pixels at scale 2");
Scale(window, 120);
f.Rebuild();
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Check(window.width == 640 && window.height == 480 && window.scale == 2.0f && window.logicalWidth == 320 && window.logicalHeight == 240,
"a swapchain made after the scale became 1 keeps the pixels and takes no scale: the window still draws at 2, its surface still 320x240");
CheckAt(Motion(window, 160, 120), 320, 240,
"until the next frame a motion to the surface's middle is at the middle of the frame on screen, drawn at 2");
Check(!f.Begin() && window.scale == 1.0f && window.logicalWidth == 640 && window.logicalHeight == 480,
"the next frame's start takes the scale, with no swapchain");
CheckAt(window.currentMousePos, 160, 120, "the pointer, which has not moved, is where its surface-local (160,120) comes to at 1");
f.Present();
Expect(f.Sent(), { "destination 640x480" }, "and the surface takes the size the pixels come to at it with that frame");
}
// The same with the swapchain made after a present that found it out of
// date, while a scale that came during the frame waited, and with a
// configure as well that comes with that scale to the pixels the window
// has: the boundary after the present makes the swapchain again and
// takes neither, and the next frame's start takes both.
{
Fixture f = fixture(240, 640, 480);
f.Frame();
f.Sent();
Window& window = f.window();
f.Begin();
Scale(window, 120);
f.Present();
window.swapchainRebuildPending = true;
Check(f.End() && window.scale == 2.0f && window.logicalWidth == 320 && window.logicalHeight == 240,
"a present out of date after a scale came during its frame: the boundary after it makes the swapchain again and takes no scale");
CheckAt(Motion(window, 160, 120), 320, 240,
"until the next frame a motion to the surface's middle is at the middle of the frame on screen, drawn at 2");
Check(!f.Begin() && window.scale == 1.0f && window.logicalWidth == 640 && window.logicalHeight == 480, "the next frame's start takes it");
f.Present();
Expect(f.Sent(), { "destination 640x480" }, "and its frame brings the surface its size");
f.Begin();
Scale(window, 192);
const std::uint32_t serial = f.Configure(400, 300);
f.Present();
f.Sent();
window.swapchainRebuildPending = true;
Check(f.End() && window.scale == 1.0f && window.width == 640 && window.height == 480 && window.deferredLogicalWidth == 400,
"a scale of 1.6 and a configure of 400x300 that come to those 640x480 pixels, and a present out of date: the swapchain is made again at them, and neither is taken");
Check(!f.Begin() && window.scale == 1.6f && window.width == 640 && window.height == 480 && window.logicalWidth == 400 && window.logicalHeight == 300,
"the next frame's start takes both, with no swapchain");
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 400x300" }),
"and its frame brings the surface its size and the acknowledgement");
Check(NothingWaits(window), "after it nothing is owed");
}
// Issue #165: a scale the compositor asks for by itself, with no
// configure, as when a window goes to an output of another scale. Its
// listener used to set the scale and nothing else, so the buffers and
// the surface kept the old one until something resized the window,
// while the pointer, the touches and the caret were converted with the
// new one. Now the listener only keeps it, the window draws at the scale
// it has and converts with that one until a frame boundary takes the
// new one, as it takes a configured size, and onFrameOwed fires. A
// window the compositor sized keeps its surface's size and takes new
// pixels for it: the frame makes the swapchain.
{
Fixture f = fixture(240, 640, 480);
f.Frame();
f.Configure(400, 300);
f.Frame();
f.Sent();
f.owed = 0;
Window& window = f.window();
Check(window.logicalConfigured && window.width == 800 && window.height == 600, "#165: a window the compositor sized, 400x300 at scale 2");
// The caret goes to a text input the compositor gave this window.
zwp_text_input_v3* input = static_cast<zwp_text_input_v3*>(wl_registry_bind(registry, 5, &zwp_text_input_v3_interface, 1));
textInputId = wl_proxy_get_id(reinterpret_cast<wl_proxy*>(input));
Device::display = f.display;
Device::textInput = input;
Device::textInputWindow = &window;
Scale(window, 180);
Expect(f.Sent(), {}, "a scale from the compositor: its listener sends nothing");
Check(window.scale == 2.0f && window.width == 800 && window.height == 600 && window.logicalWidth == 400 && window.logicalHeight == 300
&& window.preferredScale == 180,
"the window still draws at 2, at 800x600 for its 400x300, and the scale waits");
Check(f.owed == 1, std::format("onFrameOwed fired once ({})", f.owed));
CheckAt(Motion(window, 200, 150), 400, 300, "a motion to the surface's middle is at the middle of the 800x600 buffers drawn at 2");
window.SetTextInput(true, 120, 240, 6, 48);
Expect(f.Sent(), { "caret 60,120 3x24" }, "a caret given in those buffers' pixels goes to the text input at 2");
Check(f.Begin() && window.width == 600 && window.height == 450 && window.scale == 1.5f && window.logicalWidth == 400 && window.logicalHeight == 300,
std::format("the next frame takes the scale, with the pixels for 400x300 at 1.5 ({}x{}), and makes the swapchain at them", window.width, window.height));
CheckAt(window.currentMousePos, 300, 225,
"the pointer, which has not moved, is at the middle of the 600x450 buffers: the boundary took its position to the new scale");
Expect(f.Sent(), { "caret 80,160 4x32" }, "and sent the caret given in the pixels of 2 again, at 1.5, with no SetTextInput");
CheckAt(Motion(window, 200, 150), 300, 225, "from there the motion to the surface's middle is at the middle of the 600x450 buffers");
window.SetTextInput(true, 120, 240, 6, 48);
Expect(f.Sent(), { "caret 80,160 4x32" }, "and a caret given in their pixels goes to the text input at 1.5");
f.Present();
Expect(f.Sent(), {}, "the frame sends the surface nothing, as its size is the one it had");
Check(NothingWaits(window) && f.owed == 1, "after it nothing is owed");
window.SetTextInput(false);
f.Sent();
Device::textInputWindow = nullptr;
Device::textInput = nullptr;
Device::display = nullptr;
zwp_text_input_v3_destroy(input);
textInputId = 0;
}
// A window the application sized keeps its pixels: no swapchain is made,
// and the surface takes the size they come to at the new scale, which
// the frame sends with its buffer. A finger that goes down while the
// scale waits and moves after the frame took it is at the buffers'
// middle both times.
{
Fixture f = fixture(240, 640, 480);
f.Frame();
f.Sent();
Window& window = f.window();
std::vector<Vector<float, 2>> touches;
std::vector<Vector<float, 2>> lifts;
EventListener<TouchPoint> downSub(&window.onTouchDown, [&](TouchPoint point) { if (point.id == 0) touches.push_back(point.position); });
EventListener<TouchPoint> moveSub(&window.onTouchMove, [&](TouchPoint point) { if (point.id == 0) touches.push_back(point.position); });
EventListener<TouchPoint> upSub(&window.onTouchUp, [&](TouchPoint point) { if (point.id == 1) lifts.push_back(point.position); });
zwp_text_input_v3* input = static_cast<zwp_text_input_v3*>(wl_registry_bind(registry, 5, &zwp_text_input_v3_interface, 1));
textInputId = wl_proxy_get_id(reinterpret_cast<wl_proxy*>(input));
Device::display = f.display;
Device::textInput = input;
Device::textInputWindow = &window;
window.SetTextInput(true, 120, 240, 6, 48);
Expect(f.Sent(), { "caret 60,120 3x24" }, "a caret given in the 640x480 pixels at 2 goes to the text input as such");
Scale(window, 120);
Expect(f.Sent(), {}, "a scale for a window the application sized: its listener sends nothing");
Check(window.scale == 2.0f && window.width == 640 && window.height == 480 && window.logicalWidth == 320 && window.logicalHeight == 240
&& f.owed == 1,
"the window still draws at 2, at 640x480 for its 320x240, and onFrameOwed fired");
CheckAt(Motion(window, 160, 120), 320, 240, "a motion to the surface's middle is at the middle of the 640x480 buffers");
Device::touch_down(nullptr, nullptr, 1, 0, window.surface, 0, wl_fixed_from_double(160), wl_fixed_from_double(120));
Check(touches.size() == 1, "a finger goes down");
if (!touches.empty()) CheckAt(touches.back(), 320, 240, "at the surface's middle, which is the buffers' middle");
Device::touch_down(nullptr, nullptr, 2, 0, window.surface, 1, wl_fixed_from_double(80), wl_fixed_from_double(60));
Check(!f.Begin() && window.width == 640 && window.height == 480 && window.scale == 1.0f && window.logicalWidth == 640 && window.logicalHeight == 480,
std::format("the next frame takes the scale with no swapchain: the pixels stay, and the surface is the {}x{} they come to at 1", window.logicalWidth, window.logicalHeight));
CheckAt(window.currentMousePos, 160, 120,
"the pointer the first finger stands in for, which has not moved, is where its surface-local (160,120) comes to at 1");
Expect(f.Sent(), { "caret 120,240 6x48" }, "taking the scale sends the caret again, at 1, with no SetTextInput, and nothing else");
f.Present();
Expect(f.Sent(), { "destination 640x480" }, "the frame brings the surface that size with its buffer");
Device::touch_up(nullptr, nullptr, 3, 0, 1);
Check(lifts.size() == 1, "a second finger, down before the boundary, lifts after it without moving");
if (!lifts.empty()) CheckAt(lifts.back(), 80, 60, "where its surface-local (80,60) comes to at 1");
CheckAt(Motion(window, 320, 240), 320, 240, "and a motion to its middle is at the buffers' middle");
Device::touch_motion(nullptr, nullptr, 0, 0, wl_fixed_from_double(320), wl_fixed_from_double(240));
Check(touches.size() == 2, "the finger moves");
if (touches.size() == 2) CheckAt(touches.back(), 320, 240, "to the surface's middle, which is the buffers' middle");
Device::touch_up(nullptr, nullptr, 4, 0, 0);
Check(NothingWaits(window) && f.owed == 1, "after the frame nothing is owed");
window.SetTextInput(false);
f.Sent();
Device::textInputWindow = nullptr;
Device::textInput = nullptr;
Device::display = nullptr;
zwp_text_input_v3_destroy(input);
textInputId = 0;
}
// An Input::Map attached to the window keeps a last position of its own
// for MouseDeltaBind. Ticked across a boundary that takes a new scale, it
// reads no delta for a pointer that rests, and then the motion in the
// new pixels: 10 units at 1.5 are 15, read through a binding of a
// sixteenth, as the Map clamps an axis to 1.
{
Fixture f = fixture(240, 640, 480);
f.Frame();
f.Configure(400, 300);
f.Frame();
f.Sent();
Window& window = f.window();
Input::Map map;
Input::Action& look = map.AddAction("Look", Input::ActionType::Vector2);
look.bindings = { Input::MouseDeltaBind{ 1.0f / 16.0f } };
map.Attach(window);
Motion(window, 200, 150);
map.Tick();
Scale(window, 180);
Check(f.Begin() && window.scale == 1.5f, "an Input::Map's window takes a scale of 1.5 at a boundary");
map.Tick();
CheckAt(look.vector2, 0, 0, "the Map ticked across it reads no delta for the pointer, which rests");
Motion(window, 210, 150);
map.Tick();
CheckAt(look.vector2, 15.0f / 16.0f, 0, "and a motion of 10 units after it as 15 pixels, a sixteenth of which is 0.9375");
map.Detach();
f.Present();
}
// The same Map across two boundaries between two of its Ticks, on a
// window the compositor sized, 1.75 taken by a swapchain made outside a
// frame at the pixels it gives the window and 1 by the next frame's
// start, with the pointer resting at surface 100.25: no delta and no
// event, where a position taken along to each scale comes back with a
// float residue.
{
Fixture f = fixture(120, 640, 480);
f.Frame();
f.Configure(640, 480);
f.Frame();
f.Sent();
Window& window = f.window();
Input::Map map;
Input::Action& look = map.AddAction("Look", Input::ActionType::Vector2);
look.bindings = { Input::MouseDeltaBind{} };
int changed = 0;
EventListener<Vector<float, 2>> changedSub(&look.onVector2Changed, [&](Vector<float, 2>) { ++changed; });
map.Attach(window);
Motion(window, 100.25, 80);
map.Tick();
Scale(window, 210);
f.Rebuild();
Scale(window, 120);
f.Begin();
Check(window.scale == 1.0f, "a scale of 1.75 taken by a swapchain, and 1 again by a frame boundary, between two Ticks");
map.Tick();
CheckAt(look.vector2, 0, 0, "the Map reads no delta for the pointer, which rests");
Check(changed == 0, std::format("and fires no onVector2Changed ({})", changed));
map.Detach();
f.Present();
}
// Input whose listener takes a scale that waits, as a SetPresentMode
// outside a frame does for a window the compositor sized, through the
// swapchain it makes at the new pixels: the position the handler stores
// after the listener is in the pixels of that scale. A finger's down and
// the click of the pointer it stands in for, its move, and the move
// after an enter.
{
Fixture f = fixture(240, 640, 480);
f.Frame();
f.Configure(320, 240);
f.Frame();
f.Sent();
Window& window = f.window();
bool rebuild = false;
const auto takes = [&] { if (rebuild) { rebuild = false; f.Rebuild(); } };
std::vector<Vector<float, 2>> at;
EventListener<TouchPoint> downSub(&window.onTouchDown, [&](TouchPoint) { takes(); });
EventListener<TouchPoint> moveSub(&window.onTouchMove, [&](TouchPoint) { takes(); });
EventListener<void> enterSub(&window.onMouseEnter, [&] { takes(); });
EventListener<void> clickSub(&window.onMouseLeftClick, [&] { at.push_back(window.currentMousePos); });
EventListener<void> pointerSub(&window.onMouseMove, [&] { at.push_back(window.currentMousePos); });
Scale(window, 120);
rebuild = true;
Device::touch_down(nullptr, nullptr, 1, 0, window.surface, 0, wl_fixed_from_double(160), wl_fixed_from_double(120));
Check(window.scale == 1.0f && at.size() == 1, "a listener of onTouchDown takes a scale of 1 that waited");
if (at.size() == 1) CheckAt(at.back(), 160, 120, "the click is where the finger's surface-local (160,120) comes to at 1");
Scale(window, 240);
rebuild = true;
Device::touch_motion(nullptr, nullptr, 0, 0, wl_fixed_from_double(100), wl_fixed_from_double(50));
Check(window.scale == 2.0f && at.size() == 2, "a listener of onTouchMove takes a scale of 2 that waited");
if (at.size() == 2) CheckAt(at.back(), 200, 100, "the move is where (100,50) comes to at 2");
Device::touch_up(nullptr, nullptr, 2, 0, 0);
Scale(window, 180);
rebuild = true;
Device::PointerListenerHandleEnter(nullptr, nullptr, 3, window.surface, wl_fixed_from_double(100), wl_fixed_from_double(50));
Check(window.scale == 1.5f && at.size() == 3, "a listener of onMouseEnter takes a scale of 1.5 that waited");
if (at.size() == 3) CheckAt(at.back(), 150, 75, "the move after the enter is where (100,50) comes to at 1.5");
Device::PointerListenerHandleLeave(nullptr, nullptr, 4, window.surface);
}
// A scale that comes back to the one the window draws at before a frame
// took the one between: nothing is owed any more.
{
Fixture f = fixture(240, 640, 480);
f.Frame();
f.Sent();
Window& window = f.window();
Scale(window, 180);
Scale(window, 240);
Check(f.owed == 1 && window.preferredScale == 240, std::format("onFrameOwed fired for the new scale and not for the one back ({})", f.owed));
Check(!f.Begin() && window.scale == 2.0f && window.width == 640 && window.height == 480 && window.logicalWidth == 320,
"the next frame takes nothing");
f.Present();
Expect(f.Sent(), {}, "and sends nothing");
Check(NothingWaits(window), "nothing is owed");
}
// A scale that comes while a frame is being recorded, as when a listener
// of the frame dispatched the event: the frame goes on at the scale it
// began with. A window the compositor sized takes the new one at the
// boundary after the present, with the pixels it needs, which the
// swapchain is made at there.
{
Fixture f = fixture(240, 640, 480);
f.Frame();
f.Configure(400, 300);
f.Frame();
f.Sent();
Window& window = f.window();
f.Begin();
Scale(window, 180);
Check(window.scale == 2.0f && window.width == 800 && window.height == 600,
"a scale while a frame of a window the compositor sized is being recorded: the frame goes on at 2");
f.Present();
Expect(f.Sent(), {}, "its present sends nothing for the scale");
Check(f.End() && window.scale == 1.5f && window.width == 600 && window.height == 450 && window.logicalWidth == 400 && window.logicalHeight == 300,
"the boundary after its present takes it, with the pixels for 400x300 at 1.5, and makes the swapchain at them");
CheckAt(Motion(window, 200, 150), 300, 225, "from there a motion to the surface's middle is at the middle of the 600x450 buffers");
Check(!f.Begin(), "the next frame's start finds nothing left to take, and makes no swapchain");
f.Present();
Expect(f.Sent(), {}, "and the next frame sends the surface nothing, as its size is the one it had");
Check(NothingWaits(window), "after it nothing is owed");
}
// One the application sized takes it at the start of the next frame,
// the one that sends its surface the size it comes to, and not after the
// present, where it gives the window no new pixels: until that frame's
// commit the compositor maps the surface by the destination it has, so a
// motion in between is still at the pixels the scale before gives,
// those of the frame on screen, and the caret is not sent again before
// then.
{
Fixture f = fixture(240, 640, 480);
f.Frame();
f.Sent();
Window& window = f.window();
zwp_text_input_v3* input = static_cast<zwp_text_input_v3*>(wl_registry_bind(registry, 5, &zwp_text_input_v3_interface, 1));
textInputId = wl_proxy_get_id(reinterpret_cast<wl_proxy*>(input));
Device::display = f.display;
Device::textInput = input;
Device::textInputWindow = &window;
window.SetTextInput(true, 120, 240, 6, 48);
Expect(f.Sent(), { "caret 60,120 3x24" }, "a caret given in the 640x480 pixels at 2 goes to the text input as such");
f.Begin();
Scale(window, 120);
Check(window.scale == 2.0f && window.logicalWidth == 320 && window.logicalHeight == 240,
"a scale while a frame of a window the application sized is being recorded: the frame goes on at 2, its surface 320x240");
f.Present();
Expect(f.Sent(), {}, "its present sends nothing for the scale");
Check(!f.End() && window.scale == 2.0f && window.logicalWidth == 320 && window.logicalHeight == 240,
"the boundary after its present takes nothing: the window still draws at 2, and its surface is still 320x240");
Expect(f.Sent(), {}, "and sends nothing, the caret neither");
CheckAt(Motion(window, 160, 120), 320, 240,
"until the next frame a motion to the surface's middle is at the middle of the frame on screen, drawn at 2");
Check(!f.Begin() && window.scale == 1.0f && window.logicalWidth == 640 && window.logicalHeight == 480,
"the next frame's start takes it, with no swapchain: the surface is the 640x480 the pixels come to at 1");
CheckAt(window.currentMousePos, 160, 120, "the pointer, which has not moved, is where its surface-local (160,120) comes to at 1");
Expect(f.Sent(), { "caret 120,240 6x48" }, "and the caret goes to the text input again, at 1");
f.Present();
Expect(f.Sent(), { "destination 640x480" }, "the frame drawn at 1 brings the surface its size");
Check(NothingWaits(window), "after it nothing is owed");
window.SetTextInput(false);
f.Sent();
Device::textInputWindow = nullptr;
Device::textInput = nullptr;
Device::display = nullptr;
zwp_text_input_v3_destroy(input);
textInputId = 0;
}
// A configure and a scale that come while a frame is being recorded and
// together come to the pixels the window has (an output's scale changed
// under a window that fills it): they give the window no new pixels, so
// the boundary after the present takes neither, and the next frame's start
// takes both, that frame bringing the surface its size and the
// acknowledgement. Until then a motion is still at the pixels of the
// frame on screen, and the caret is not sent again.
{
Fixture f = fixture(240, 640, 480);
f.Frame();
f.Sent();
Window& window = f.window();
zwp_text_input_v3* input = static_cast<zwp_text_input_v3*>(wl_registry_bind(registry, 5, &zwp_text_input_v3_interface, 1));
textInputId = wl_proxy_get_id(reinterpret_cast<wl_proxy*>(input));
Device::display = f.display;
Device::textInput = input;
Device::textInputWindow = &window;
window.SetTextInput(true, 120, 240, 6, 48);
Expect(f.Sent(), { "caret 60,120 3x24" }, "a caret given in the 640x480 pixels at 2 goes to the text input as such");
f.Begin();
Scale(window, 192);
const std::uint32_t serial = f.Configure(400, 300);
f.Present();
Expect(f.Sent(), { "commit" }, "a scale of 1.6 and a configure of 400x300 during a frame: the configure's listener commits, and the present sends nothing");
Check(!f.End() && window.scale == 2.0f && window.width == 640 && window.height == 480 && window.logicalWidth == 320 && window.logicalHeight == 240
&& window.deferredLogicalWidth == 400 && window.deferredLogicalHeight == 300 && window.unackedConfigure == serial,
"they come to the 640x480 pixels the window has: the boundary after the present takes neither, and the configure waits");
Expect(f.Sent(), {}, "and sends nothing, the caret neither");
CheckAt(Motion(window, 160, 120), 320, 240,
"until the next frame a motion to the surface's middle is at the middle of the frame on screen, drawn at 2");
Check(!f.Begin() && window.scale == 1.6f && window.width == 640 && window.height == 480 && window.logicalWidth == 400 && window.logicalHeight == 300
&& window.logicalConfigured,
"the next frame's start takes both, with no swapchain: 400x300 at 1.6 is the 640x480 the window has");
CheckAt(window.currentMousePos, 256, 192, "the pointer, which has not moved, is where its surface-local (160,120) comes to at 1.6");
Expect(f.Sent(), { "caret 75,150 3x30" }, "and the caret goes to the text input again, at 1.6");
f.Present();
Expect(Sorted(f.Sent()), Sorted({ std::format("ack {}", serial), "destination 400x300" }),
"the frame drawn at 1.6 brings the surface its size and the acknowledgement");
Check(NothingWaits(window), "after it nothing is owed");
window.SetTextInput(false);
f.Sent();
Device::textInputWindow = nullptr;
Device::textInput = nullptr;
Device::display = nullptr;
zwp_text_input_v3_destroy(input);
textInputId = 0;
}
// A window the compositor sized that a new scale leaves at its pixels,
// as it can one this small: the scale gives it no new pixels either, so
// it waits for the next frame's start too.
{
Fixture f = fixture(240, 640, 480);
f.Frame();
f.Configure(50, 50);
f.Frame();
f.Sent();
Window& window = f.window();
Check(window.logicalConfigured && window.width == 100 && window.height == 100, "a window the compositor sized, 50x50 at 2");
f.Begin();
Scale(window, 239);
f.Present();
Check(!f.End() && window.scale == 2.0f && window.width == 100 && window.height == 100,
"a scale during its frame that leaves its 100x100 pixels: the boundary after the present takes nothing");
Check(!f.Begin() && window.scale == 239 / 120.0f && window.width == 100 && window.height == 100 && window.logicalWidth == 50,
"the next frame's start takes it, with no swapchain");
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Present();
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Expect(f.Sent(), {}, "and the frame sends the surface nothing, as its size is the one it had");
Check(NothingWaits(window), "after it nothing is owed");
}
// A configure without a size while a scale waits asks for nothing new,
// and is acknowledged in the listener as before: the scale is not the
// compositor's to be answered.
{
Fixture f = fixture(240, 640, 480);
f.Frame();
f.Sent();
Window& window = f.window();
Scale(window, 180);
const std::uint32_t none = f.Configure(0, 0, { XDG_TOPLEVEL_STATE_ACTIVATED });
Expect(f.Sent(), { std::format("ack {}", none), "commit" }, "a configure without a size while a scale waits: acknowledged in the listener");
Check(!f.Begin() && window.scale == 1.5f && window.logicalWidth == 427 && window.logicalHeight == 320,
std::format("the next frame takes the scale: 640x480 pixels at 1.5 are {}x{}", window.logicalWidth, window.logicalHeight));
f.Present();
Expect(f.Sent(), { "destination 427x320" }, "which it sends with its buffer");
}
// A configure for the size the surface has while a new scale waits,
// where its pixels at that scale are the ones the window has: 101x101
// pixels at 2 are a surface of 51x51, which at 237/120 comes to 101x101
// again, and at 2 to 102x102. It is no configure at the size the window
// has, since the window draws at the scale before: it waits for the
// frame that takes the scale and takes its size with it, and the window
// stays one the application sized until then, its pixels those of the
// surface it has at the scale it draws at.
{
Fixture f = fixture(240, 101, 101);
f.Frame();
f.Sent();
Window& window = f.window();
Check(!window.logicalConfigured && window.logicalWidth == 51 && window.logicalHeight == 51,
"a window the application sized, 101x101 pixels at 2, its surface 51x51");
Scale(window, 237);
const std::uint32_t serial = f.Configure(51, 51);
Expect(f.Sent(), { "commit" }, "a configure for 51x51 while a scale of 237/120 waits: not acknowledged in the listener");
Check(!window.logicalConfigured && window.deferredLogicalWidth == 51 && window.deferredLogicalHeight == 51
&& window.unackedConfigure == serial && window.scale == 2.0f && window.width == 101 && window.height == 101,
"it waits, and the window stays one the application sized, at 101x101 drawn at 2");
Check(!f.Begin() && window.logicalConfigured && window.scale == 237 / 120.0f && window.width == 101 && window.height == 101
&& window.logicalWidth == 51 && window.logicalHeight == 51,
"the next frame's start takes both, with no swapchain: 51x51 at 237/120 is the 101x101 the window has");
f.Present();
Expect(f.Sent(), { std::format("ack {}", serial) }, "and its frame acknowledges the configure, sending no destination: the surface's size is the one it has");
Check(NothingWaits(window), "after it nothing is owed");
}
// Before the window has its first swapchain, as while the constructor
// waits for its first configure (KWin names the scale then): the
// listener keeps the scale and fires nothing, and the constructor takes
// it before it makes the swapchain. A scale of 0 is not taken at all.
{
// Value-initialized: the scale it takes converts the positions it
// holds, which a default-initialized window has none of.
Window window{};
int owed = 0;
EventListener<void> owedSub(&window.onFrameOwed, [&] { ++owed; });
Scale(window, 0);
Check(window.preferredScale == 120, "a scale of 0 is not taken");
Scale(window, 210);
Check(window.preferredScale == 210 && window.scale == 1.0f && owed == 0,
"a scale named before the window has a swapchain is kept, and fires nothing");
window.width = 640;
window.height = 480;
window.MatchSizesToScale(true);
Check(window.scale == 1.75f && window.logicalWidth == 366 && window.logicalHeight == 275,
std::format("the constructor takes it before its first swapchain: 640x480 pixels at 1.75 are {}x{}", window.logicalWidth, window.logicalHeight));
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
}
// A Resize from a listener of the frame waits in pixels, for that
// frame's present.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
window.recording = true;
window.Resize(1000, 700);
window.recording = false;
Check(window.width == 640 && window.deferredWidth == 1000, "a Resize during a frame waits");
Check(f.Begin() && window.width == 1000 && window.height == 700 && window.deferredWidth == 0 && window.deferredHeight == 0,
"and is taken at the frame boundary");
f.Present();
Expect(f.Sent(), { "destination 500x350" }, "the first frame at it brings the surface the size the pixels come to");
}
// Of a Resize and a configured size, the one asked for last is taken.
// The Resize first: the compositor's later size takes its place.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
window.recording = true;
window.Resize(1200, 800);
window.recording = false;
f.Configure(400, 300);
Check(window.deferredWidth == 0 && window.deferredHeight == 0 && window.deferredLogicalWidth == 400,
"a configure after a Resize that waits: the compositor's size waits in its place");
Check(f.Begin() && window.width == 800 && window.height == 600,
std::format("and is the one taken ({}x{})", window.width, window.height));
Check(!f.Begin(), "a second take finds nothing");
}
// The same when the compositor's later size is the one the window has:
// the Resize is dropped then too, and the window stays as it is. The
// configure comes while the frame is being recorded, as the Resize did.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(120, 800, 600);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
window.recording = true;
window.Resize(1000, 700);
const std::uint32_t serial = f.Configure(800, 600);
Expect(f.Sent(), { std::format("ack {}", serial), "commit" },
"a configure for the size the window has, after a Resize that waits: acknowledged at once, as the surface shows that size");
Check(window.deferredWidth == 0 && window.deferredHeight == 0, "the Resize waits no more");
f.Present();
window.recording = false;
Check(!f.Begin() && window.width == 800 && window.height == 600,
std::format("after the frame the window is still the size the compositor configured ({}x{})", window.width, window.height));
Expect(f.Sent(), {}, "and nothing more is sent");
}
// The configure first, then a Resize in the same frame: the
// application's later size takes the compositor's place. The serial is
// acknowledged by the frame being recorded, which no size waits behind
// any more.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
window.recording = true;
const std::uint32_t serial = f.Configure(400, 300);
window.Resize(1000, 700);
Check(window.deferredLogicalWidth == 0 && window.deferredLogicalHeight == 0 && window.deferredWidth == 1000,
"a Resize after a configure that waits: the application's size waits in its place");
f.Sent();
f.Present();
window.recording = false;
Expect(f.Sent(), { std::format("ack {}", serial) }, "the frame acknowledges the configure");
Check(f.Begin() && window.width == 1000 && window.height == 700 && !window.logicalConfigured,
std::format("and the size taken after it is the application's ({}x{})", window.width, window.height));
f.Present();
Expect(f.Sent(), { "destination 500x350" }, "which the surface takes with its first frame");
}
// And a Resize outside a frame to the size the window has: the
// compositor's size that waited is dropped, and nothing is rebuilt.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(240, 640, 480);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
const std::uint32_t serial = f.Configure(400, 300);
f.Sent();
window.Resize(640, 480);
Check(window.deferredLogicalWidth == 0 && window.deferredLogicalHeight == 0 && window.unackedConfigure == serial,
"a Resize to the size the window has, after a configure that waits: the size waits no more, the serial does");
Check(!f.Begin() && window.width == 640 && window.height == 480, "the next frame makes no swapchain");
f.Present();
Expect(f.Sent(), { std::format("ack {}", serial) }, "and acknowledges the configure");
}
// The events: onToplevelState first, then onFrameOwed with the states set.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(120, 320, 240);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
Window& window = f.window();
std::vector<std::string> order;
EventListener<void> stateSub(&window.onToplevelState, [&] { order.push_back("state"); });
EventListener<void> owedSub(&window.onFrameOwed, [&] { order.push_back(window.activated ? "owed, activated" : "owed"); });
f.Configure(400, 300, { XDG_TOPLEVEL_STATE_ACTIVATED });
Check(order == std::vector<std::string>{ "state", "owed, activated" },
"onFrameOwed fires after onToplevelState, with the configure's states set");
if (order != std::vector<std::string>{ "state", "owed, activated" }) std::println(" fired: {}", order);
}
// A listener of onToplevelState destroys the window: the handler fires
// nothing more on it. Another window is made in its place, at the same
// address, so an event fired through the old pointer would show.
{
fix(wayland): take a new preferred scale at a frame boundary, and convert input with the scale the window draws at xdg_surface_handle_preferred_scale set Window::scale and did nothing else (#165). The buffers' size and the surface's follow the scale only where the window works one out from the other, which it did when it made a swapchain and when a frame took a configured size. So a scale that changed by itself, with no configure (the issue's case is a window moved to an output of another scale), reached them only at the next of those, and until then the window drew at the old scale. The pointer's and the touches' positions are turned into pixels with Window::scale, and the text input's caret back into surface-local units with it, so those were converted with the new scale while the frames were still drawn at the old one. The issue suggests making the swapchain again in the listener. That predates 89111e0, which moved the configure's rebuild out of its listener into Render() for #199 and #200; the scale takes the same way. Window: the listener keeps the scale in a new member, preferredScale, as wp_fractional_scale_v1 sends it, in 120ths, and Window::scale is the scale the window draws at. MatchSizesToScale, where the window works out the size it was not given from the one it was, sets it from preferredScale where it takes a new scale, and nothing else in the library sets it. TakeDeferredSize takes a preferredScale that is not the scale the window draws at, at a frame boundary of Render(), as it takes a configured size, and with one where one waits. A window the compositor sized keeps its surface's size and takes the pixels for it at the new scale, so Render() makes the swapchain again there and onResize fires where those pixels differ. One the application sized keeps its pixels and makes no swapchain, and its surface takes the size they come to at the new scale, which the next frame sends with its buffer (SendFrameSurfaceState). Before the start of the next frame the scale is taken only with a swapchain made where it gives the window new pixels: a window the compositor sized whose surface comes to other pixels at it, as after a present or with the swapchain a SetPresentMode makes outside a frame. Anywhere else it would change only the conversions and the size the surface is to take, which goes out with the next frame, and until that frame's commit the compositor maps the surface, and the pointer and the touches on it, by the destination it has: a click in between would be converted for a frame not drawn yet, landing where the new scale puts it on the one drawn at the old scale, and the onResize of a swapchain made for another reason at the pixels the window has would not tell the application of the scale. So a scale that leaves the pixels as they are waits for the start of the next frame (for a window the application sized, whose pixels are its own, and one the compositor sized that it leaves at its pixels), also where a present mode, a rebuild that waited or a Resize makes a swapchain before then, and so does a configured size that comes to the pixels the window has with it (an output's scale changed under a window that fills it). TakeDeferredSize and RebuildIfDeferred are told which of the two boundaries they run at (FrameBoundary), and MatchSizesToScale whether it takes the scale whatever it does to the pixels (takeScale), as at a frame's start and in the constructor. The listener sends no request and makes no Vulkan call, so the window goes on drawing at the old scale, and converting with it, until then; a scale that a listener of a frame dispatched is taken at the boundary after its present where it gives the window new pixels, and at the start of the next frame otherwise. From the window's first swapchain on, the listener fires onFrameOwed where the scale is not the one the window draws at, so that a window that draws on demand learns that a frame is owed, as it does from a configure; for a window the application sized no onResize comes. Before the first swapchain the listener only keeps the scale, which the constructor takes before it makes the swapchain, as it did. A scale of 0, with which no size can be worked out, is not taken. Where MatchSizesToScale changes the scale, it takes what the window holds in pixels of the scale before to the new one: currentMousePos, lastMousePos and mouseDelta, and the touch slots of the window's fingers. The compositor gives those in surface-local units and sends nothing for a pointer or a finger that rests, so a pointer resting over the window would otherwise stand at the old scale's pixels in the frames drawn at the new one until it moved, and the next delta would be the change of grid. The pointer's position as the compositor gave it is kept beside, in surface-local units, in a new member, surfaceMousePos, which no scale moves. And it sends the caret SetTextInput was given again, converted with the new scale, as the window does when the keyboard focus comes back: for a window the application sized, the surface changes size around pixels that stay, and the rectangle the input method holds would otherwise stay in the old units. The configure listener's test for a configure at the size the window has compares the buffers with the pixels for that size at preferredScale, the scale the frame takes with the size, as it compared them at Window::scale while the listener set that. While a new scale waits it finds no configure at the size the window has: one for the size the surface has waits for the frame that takes the scale and takes its size with it, so that the window is not made one the compositor sized while it draws at the scale before, at pixels that are not that size's at the scale it draws at. Input: Map took its delta for MouseDeltaBind from currentMousePos and a last position of its own, which the window's conversion does not reach, so a pointer that rests would read the change of grid as a delta at the Map's next Tick, which a camera bound to MouseDeltaBind turns by. On Wayland it takes it from surfaceMousePos, as the surface-local motion since its last Tick in the window's pixels of now: none for a pointer that rests, whatever scales the window took in between, where a last position taken along to each new scale would come back with a float residue through two of them. A position the application writes into currentMousePos itself does not reach it there. Device: the pointer's and the touches' handlers keep the position the compositor gave in surfaceMousePos (the first finger's for the pointer it stands in for), and touch_down, touch_motion and an enter's move work it into the pixels they store with the scale in force at the store. They store after listeners, of onTouchDown, onTouchMove and onMouseEnter, that may take a new scale (a SetPresentMode outside a frame for a window the compositor sized, the Render() of a frame callback one of them dispatched), and a position worked out before those listeners would be in the pixels of the scale before. The conversions read Window::scale, which is now the scale of the frames drawn since the boundary that took it. Docs: the README, the consumer notes and the guide's gotchas say what scale and preferredScale are and when a scale is taken; the first two said that scale could be newer than the sizes (#165). The README, the consumer notes and the comment on SetTextInput say what goes to the new scale with it, and that the caret is sent again; the consumer notes name surfaceMousePos, the Map's delta from it, and that a position the application writes into currentMousePos does not reach the Map. The bug-prover lens section names preferredScale as what changes in any dispatch, and the scale among what waits for a frame boundary, and that before the next frame's start it is taken only where it gives the window new pixels; the consumer notes, that a size configured during a frame waits with a new scale where the two come to the pixels the window has. Tests: ConfigureResize names the scale in 120ths, as the compositor does, and drives the scale's listener on a window whose surfaces are proxies. The listener sends nothing, leaves the scale and both sizes as they are, and fires onFrameOwed. Until a frame boundary takes the scale, a pointer motion to the surface's middle is at the middle of the buffers drawn at the scale before, and so is a finger that goes down there on the window the application sized; a caret given in the pixels of the window the compositor sized goes to a text input proxy converted with that scale. The next boundary takes it: a window the compositor sized keeps 400x300 and goes from 800x600 to 600x450 pixels at 1.5, which makes the swapchain, and its surface is sent nothing; one the application sized keeps its 640x480 pixels and makes no swapchain, and its surface goes from 320x240 to 640x480 at 1, sent with the frame. After it the motion, the finger's move and the caret are converted with the new scale. And before any new motion or call, the boundary has taken what the window held to the new scale: the pointer of the window the compositor sized is at the middle of the new buffers, the one the first finger stands in for on the other window is where its surface-local place comes to, a second finger that went down before the boundary lifts after it where its surface-local place comes to, and each boundary sends the caret again, converted, with no SetTextInput. An Input::Map attached to the window and ticked across a boundary that takes 1.5 reads no delta for a pointer that rests, and a motion of 10 units after it as 15 pixels; ticked across two boundaries between two Ticks on a window the compositor sized, 1.75 taken by a swapchain made outside a frame at the pixels it gives the window and 1 again by a frame's start, with the pointer resting at surface 100.25, it reads no delta and fires no event. On a window the compositor sized, a listener of onTouchDown, of onTouchMove and of onMouseEnter that takes a scale that waits has the click the finger stands in for, the finger's move and the move after the enter in the pixels of that scale. A scale that comes back before a frame owes nothing; one that comes while a frame is being recorded leaves that frame at the scale it began with, and the window the compositor sized takes it at the boundary after the present, with its new pixels, where the one the application sized takes it at the next frame's start: the boundary after the present takes nothing, a motion after it is still at the pixels of the frame on screen, and the caret is sent again only at the next frame's start (the fixture steps the boundary after the present, End, apart from the next frame's start, Begin); a configure that comes with it to the pixels the window has waits for that start as well, which takes the two together, the frame bringing the surface its size and the acknowledgement, and so does a scale that leaves a small window the compositor sized at its pixels; a configure without a size while a scale waits is acknowledged in the listener, and one for the size the surface has waits for the frame that takes the scale, also where its pixels at that scale are the window's (101x101 pixels at 2, a surface of 51x51, a scale of 237/120); before the first swapchain the listener only keeps the scale, which MatchSizesToScale takes, and a scale of 0 is not taken. In the cases there were, the check that nothing is owed counts a scale that waits as well, the frame whose scale changes while it is recorded is followed to the boundary that takes it, a swapchain made between frames is checked to leave no scale waiting for a window the compositor sized, and for one the application sized to take none, a motion until the next frame's start landing at the pixels of the frame on screen, also where the swapchain is made after a present that found it out of date, with a configure that comes with the scale to the window's pixels waiting too, and the case of a scale and then a configure counts onFrameOwed for both. ResizeViewport drives the scale against the compositor, where it has the fractional scale and the viewporter: on its window as the application sized it, and maximized where the compositor configures a size for that, it calls the listener with a scale the window does not draw at and then with the compositor's own. Each time it checks that the listener rebuilds nothing and fires onFrameOwed, that the next Render() takes the scale, with no swapchain and no onResize for the application's size and with a new swapchain and one onResize from inside Render() for the maximized one, and that a pointer motion to the surface's middle is at the buffers' middle, to within the rounding of one size from the other, before that Render() and after it, and that the pointer, resting across that Render(), is where its surface-local place comes to at the new scale. The log's checks hold each of those commits to its buffer at the scales the marks name.
2026-11-27 10:07:37 +01:00
Fixture f = fixture(120, 320, 240);
fix(wayland): the surface takes a new size with the first frame drawn at it, and a configure's rebuild waits for Render At a resize RebuildSwapchain sent wp_viewport.set_destination for the new size at once, and the configure listener, which had called it, acknowledged the configure and committed the surface. The destination is the surface's size, and it is state the next wl_surface.commit applies whatever buffer is attached then. That commit was the listener's, or the one a consumer makes to ask for a frame callback, and it put the old frame at the new size, where it stayed until the consumer's next frame brought a buffer of that size (#199). The acknowledgement named that commit as the answer to the configure. And the rebuild ran inside libwayland's dispatch: the consumer's loop stood still in it, each new size before a frame cost a swapchain, and a Vulkan error there was thrown from inside the dispatch, where the `try` a consumer has around Update() does not cover it (#200). Window: the configure listener keeps a new size (deferredLogicalWidth and Height, surface-local) and, where a frame is owed, the serial (unackedConfigure), and makes no Vulkan call. Render() takes what waits at its two boundaries (RebuildIfDeferred) and makes the swapchain again where that calls for one: first thing, for what came since the last frame, and after its present, as before, for what its listeners and the present asked for, and now for a size configured while they ran. Right before its present a frame sends what the surface is to take with its buffer (SendFrameSurfaceState): the destination, when the surface's size is not the one last sent (sentLogicalWidth and Height), and the acknowledgement of the configure it answers, the last one when several came. The present's commit then applies them together with the buffer. The constructor sends no destination: the window's first frame does. The surface's size is state of the window for that, beside the buffers' (logicalWidth and Height; logicalConfigured says which of the two sizes the window was given). TakeDeferredSize makes a configured size the surface's, unchanged, and works the pixels out of it with the scale of that moment. MatchSizesToScale does the same before every swapchain is made, and for a window the application sized (the constructor's size, Resize) works the surface's size out of the pixels, which is what RebuildSwapchain and the constructor did when they sent the destination. The destination is that state as it is and not ceil(width / scale) at the present, because the scale is the compositor's to change in any dispatch: between a configure and the frame that takes it, and in the middle of a frame, when a listener reads the clipboard or makes a window. And a size and a scale that change together can come to the pixels the swapchain has: then no swapchain is made, and the frame still brings the surface its size with the acknowledgement. With that the destination of a configured size is the size itself, where it was worked back from the pixels and could come out larger (392x796 at 2.85 came back as 393x797), and a configure at the size the surface has leaves a window the compositor sized alone while the scale stays what it was, where it could make the window grow again (#201). A window the application sized, configured at the size its surface has, takes the pixels for that size once where its own do not come to it (320x240 at 1.75, shown at 183x138, becomes 321x242), and is then left alone in the same way. That much of #201 comes with this change, since the state it asks for is the one this needs. The buffers' size is still rounded up, where the protocol rounds half away from zero: the rest of #201. A swapchain RebuildSwapchain made for another reason after the scale changed (a present mode, a present that found the swapchain out of date) applied the new scale by working the destination out again from the pixels. It still does for a window the application sized. A window the compositor sized keeps the surface's size and takes the pixels for it. The acquire's OUT_OF_DATE path repeated four of RebuildSwapchain's lines and sent no destination: it calls RebuildSwapchain now, and so settles the two sizes as the other rebuilds do. Of a Resize and a configured size the one asked for last is taken, as when the listener resized on the spot: a configure with a size clears a Resize that waits for its frame's present, also when its size is the one the window has, and Resize clears a configured size that waits. A configure that asks for nothing new while nothing is owed is acknowledged in the listener, as before. One that comes while a size waits, or while the surface does not show the window as it is (a swapchain still to be made, one that has presented no frame yet, a size not sent yet), waits for that frame. One for the size the window has, when nothing else is owed, is acknowledged at once and takes the wait away with it, as an acknowledgement of a serial older than the last is a protocol error. A frame being recorded when a size comes does not acknowledge it while that size waits; when a Resize later in the frame takes the size's place, that frame does. The listener still commits, which applies whatever else is pending on the surface, such as a request for a frame callback that StartUpdate made after a frame. For consumers: onResize for a compositor's resize fires from inside Render(), before the onUpdate of the frame that brings the size, with the queue idle and no frame being recorded, as Resize fires it; until that frame the window keeps its old size on screen. A window that draws on demand took onResize as its cue to ask for a frame, and gets onFrameOwed for it: the Wayland backend's alone, fired from the configure after onToplevelState, and only for a window that is still there after that event's listeners, whenever the configure leaves a frame owed. A size the surface does not have yet that comes to the pixels the window has (the scale changed with it) fires onFrameOwed and no onResize. Resize and SetPresentMode outside a frame rebuild at once as they did, and there too the surface takes the new size with the next frame. A rebuild that throws stays pending, since RebuildSwapchain clears swapchainRebuildPending only once the swapchain is made, and the next Render() tries it again. The README, the consumer notes and the guide's gotchas say so, and the bug-prover lens section lists the pending surface state and the scale among the re-entry contexts. Examples: InputSystem and the native mains of VulkanTriangle, RTVolume and Sponza drew one frame and then only ran the event loop, so nothing would have answered a compositor's resize of their windows. They call StartUpdate after that frame, as the examples that draw every frame do. Not changed: a scale that changes by itself still reaches the buffers and the surface only with the next swapchain or the next configured size (#165); the first configure's size (#166); and Win32's WM_SIZE, which still rebuilds from the window procedure. A window under StartUpdate on the compositor's clock still draws from its frame callback, so for it the rebuild, like every frame's Vulkan call, stays inside libwayland's dispatch; one on its own clock is updated by StartSync's loop after the dispatch, as before. #200 is answered for a consumer that calls Update() itself. A present that fails after SendFrameSurfaceState leaves what that sent pending for the surface's next commit, whoever makes it. Tests: ConfigureResize feeds the configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as ToplevelState does, with a made-up swapchain handle and no device, steps the two ends of a frame, and reads the requests off the wire: a configure for a new size sends one bare commit; the frame sends the destination and the acknowledgement before its present, once; several configures before a frame cost one of each, of the last serial; a configure for nothing new, or back to the window's size, is acknowledged in the listener, and the serial that waited never is; a frame being recorded when a size comes does not acknowledge it while the size waits, and does once a Resize has taken its place; the window's first frame and the first at any new size of the surface bring the destination, and a configure before it waits, and so does one for the size a rebuild that threw is still pending for, and one that comes after a present that found the swapchain out of date, whose surface state is not sent a second time; without a viewport the acknowledgement still waits. The destination is the configured size when the scale changes before the frame, when it changes between the frame's start and its present, and when the size and the scale together come to the swapchain's pixels, in either order of the two events, which makes no swapchain; with the numbers of #201's trace, 392x796 at 2.85, it is that size, and three more configures at it change nothing. A swapchain made after the scale changed keeps a configured window's surface size and an application-sized window's pixels. Of a Resize and a configured size the later one is taken, also when it is the size the window has. onFrameOwed fires after onToplevelState and not for a window its listener destroyed; every acknowledgement names a later serial than the one before. ResizeViewport runs a window against the compositor with WAYLAND_DEBUG set and stderr in a file, and replays the log, which has the driver's attach and commit too: at every commit the destination in effect belongs to the buffer in effect, to within a surface-local pixel, and every acknowledgement of a configure that asked for a size, once the surface has a buffer, is committed with a buffer of that size in effect and with that size itself as the destination, through a Resize with a commit before the next frame, a size the compositor configures (the window asks to be maximized), and one it configures while the frame loop of StartUpdate runs (the window asks to be restored), which that loop takes and answers by itself. Where the compositor configures no other size at that request, the step is a SKIP, and the test holds the log to it: no configure for another size came. `ResizeViewport --keyboard` is the manual probe for a phone: it asks for text input and takes it back three times (SetTextInput), which is what brings a phone's on-screen keyboard up and down, and holds the resizes that makes to the same checks.
2026-11-19 04:47:00 +01:00
f.Frame();
f.Sent();
int firedOnReplacement = 0;
std::optional<EventListener<void>> replacementSub;
EventListener<void> stateSub(&f.window().onToplevelState, [&] {
f.holder.reset();
Window& replacement = f.holder.emplace();
replacementSub.emplace(&replacement.onFrameOwed, [&] { ++firedOnReplacement; });
});
f.Configure(400, 300, { XDG_TOPLEVEL_STATE_ACTIVATED });
Check(firedOnReplacement == 0 && f.owed == 0,
"a window destroyed from onToplevelState: onFrameOwed does not fire through the handler's pointer");
replacementSub.reset();
}
Check(std::ranges::adjacent_find(acknowledged, std::greater_equal{}) == acknowledged.end() && !acknowledged.empty(),
std::format("each of the {} acknowledgements names a later serial than the one before", acknowledged.size()));
const int error = wl_display_get_error(display);
Check(error == 0, "the display took every request");
if (error != 0) std::println(" the display failed: {}", std::strerror(error));
wl_registry_destroy(registry);
wl_display_disconnect(display);
close(fds[1]);
if (failures != 0) {
std::println("{} check(s) failed", failures);
return EXIT_FAILURE;
}
std::println("all checks passed");
return EXIT_SUCCESS;
}