| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
e1b36b9257 |
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. |
|||
|
61f2698d13 |
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
|
|||
|
e1ca2fdb54 |
fix(window): a Window constructor that throws leaves nothing of the window behind
The native constructor registered the window before the steps that can throw: on Wayland it put the window in Device::windows and gave its xdg_surface, its xdg_toplevel and its fractional scale the window as listener data, and on Win32 it made the HWND, whose WM_NCCREATE puts the window in GWLP_USERDATA, and showed it. When a later step threw (a Vulkan error, a surface that offers no storage-writable format), the window had not been constructed, so ~Window did not run: all of that kept pointing at it after the exception, and the Vulkan surface, once made, leaked. #169 has what an application that catches the error and carries on then reads and writes. Window: the constructor delegates to the default constructor, which makes nothing. The body of a delegating constructor runs once its target has returned, and an exception that leaves it invokes the object's destructor ([except.ctor]). So ~Window, the window's one teardown, now also releases what a constructor that threw had made, before the exception reaches the caller. It was already written for members that were never made, which are null or empty and release nothing. That does what the guard the issue suggests would, by the language's own rule: ~Window runs unless construction completes, with nothing of it factored out or repeated in the constructor, and no function-try-block is needed, whose handler may not touch the members. ~Window now runs after a Vulkan command has failed, and the specification leaves such a command's outputs without a defined value ("Error Codes", in its fundamentals: undefined contents, poison ones since 1.4.369), so the Vulkan surface, the swapchain, its image views, the fences and the acquire semaphores are made into a local and go into their members once made. The command buffers still go into theirs directly: an allocation that fails sets every entry to null. The render-finished semaphores went through a local already; their vector now has room for all of them before the first is made, as a push_back that grew it and threw would have left the semaphore just made in no member. CreateSwapchain serves the rebuilds as well, where a vkCreateSwapchainKHR that fails now leaves the member as it was. Tests: WindowConstructorThrow (new, Wayland) makes a window beside another and fails its swapchain's capabilities query, through a function of its own in Device::vkGetPhysicalDeviceSurfaceCapabilities2KHR with Device::surfaceMaintenance1Supported set. It checks that the constructor throws that error; that Device::windows then holds the other window alone; that the failed window's Vulkan surface (the test defines vkDestroySurfaceKHR, which the library calls by name, and passes each call on to the loader) and each of its Wayland objects (read off a WAYLAND_DEBUG log, between the failure and the catch) were destroyed before the exception reached the test; that the compositor raised no protocol error; and that a window made after it renders and closes. The checks of the failed window come before the test dispatches the connection's events again, which without the fix can bring an enter event that walks Device::windows with the freed window in it. WindowConstructorThrowWin32 (new) does the same on Win32 for the HWND and the Vulkan surface, and makes a window after it; it needs Wine, as PointerWin32 does. Under Wine 11.20 it passes. Without the fix both fail: WindowConstructorThrow its checks of Device::windows, of the Vulkan surface and of each Wayland object, and WindowConstructorThrowWin32 those of the HWND and the Vulkan surface. Docs: the README, the constructors' comment in the interface and the consumer notes say that a constructor that throws leaves nothing of the window behind; AGENTS.template.md lists the two tests. |
|||
|
148ed01952 |
fix(wayland): keys come without text while no keymap has loaded, and a keymap that loads frees the one before
Device::keyboard_keymap made no state for a keymap of another format than xkb_v1 or one it could not map: after such a first keymap the state stayed null, and keyboard_modifiers and keyboard_key passed it unchecked to libxkbcommon. For a keymap that did not compile, first or later, keyboard_keymap called xkb_state_new on the null keymap, which crashed (SIGSEGV) in the handler itself. Each keymap that loaded also made a context, a keymap and a state of its own, and released none of the earlier ones (#167). Device, keyboard_keymap: a keymap that does not load is ignored, which leaves the keymap and state there were. #167 has the earlier ones go once new ones exist, and the handler already left them for a keymap of another format or one it could not map; a context or a state that libxkbcommon fails to make is ignored the same way. A keymap that loads replaces the keymap and state and releases the earlier ones. Every keymap is compiled in one context, made with the first that is mapped: Device::xkb_context no longer gets one from a static initializer, and is null before that. Device, keyboard_key and keyboard_modifiers: without a state the key brings no text and the modifiers are only kept, so a key still fires onRawKeyDown and onRawKeyUp with the kernel's code, and only its onTextInput is lost. Device, the modifiers: a new state is set from the modifiers and group the compositor last sent. wayland.xml (1.26) keeps them in wl_keyboard's logical state, which the keymap is no part of: the modifiers event sets them and a leave resets them to zero. A state made for a keymap that came without a modifiers event started from none, so a Caps Lock that was on stopped typing capitals until the next modifiers event. keyboard_modifiers now keeps the values it was sent, keyboard_keymap sets a new state from them, and keyboard_leave zeroes them and sets the state from those zeros. Device, the statics: Device::xkb_keymap and xkb_state are freed when the next keymap loads, where the earlier ones leaked, so an application that reads them reads them at each use. Their comment and AGENTS.consumer.md say so, and when they are null. Tests: KeyboardKeymap (new) drives the wl_keyboard callbacks directly, with keymaps in memfds, on a default-constructed Window, each case in a child process. A first keymap of the no_keymap format, one whose fd cannot be mapped (a pipe's) and one that does not compile each have their fd closed and make no state, and a key after modifiers then fires onRawKeyDown and onRawKeyUp without text. After a keymap that loaded, each of the three leaves it in place, until one loads. A second keymap replaces the first in the same context, and on glibc 100 more leave less than 16 KiB more on the heap. Caps Lock carries into the state of a keymap that comes without modifiers, a leave clears it from the state and a state made after the leave has none, and modifiers sent before the first keymap apply to it. Run against the handlers before this change, with libxkbcommon 1.13.2, all seven cases fail: five die of signal 11 (SIGSEGV), the 100 keymaps leave 769056 bytes more on the heap and are not compiled in the first one's context, and the Caps Lock is kept through the leave and lost to the next keymap. Docs: the consumer notes say what a key brings without a keymap, that a keymap that does not load is ignored, and when Device::xkb_keymap and xkb_state are null and when they are freed. AGENTS.template.md names KeyboardKeymap among the tests that drive the Wayland listeners directly. |
|||
|
594e1612f7 |
fix(device): stop requiring samplerAnisotropy, and remove SamplerVulkan, the class it was required for
Device::Initialize counted samplerAnisotropy among the library's own
features because SamplerVulkan turned anisotropic filtering on (#168).
Nothing in this repository has made a SamplerVulkan since
|
|||
|
a9ce1a02e8 |
feat(wayland): SetTextInput takes text-input-v3's purposes and its version 1 hints, and enables anew for a field of another kind
Window::SetTextInput knew two purposes, Normal and Phone, and
Device::ApplyTextInput chose the content hints from them: none for
Phone, and completion, spellcheck and auto_capitalization for Normal.
Nothing could send another purpose, or hidden_text or sensitive_data:
a password field was Normal, with those three hints, or Phone.
Types: TextInputPurpose has the fourteen content purposes of the
bundled text-input-v3 protocol, in its order, so that the enumerators
have the protocol's values; Phone was 1 and is 4. kTextInputHintNone
and the ten kTextInputHint* bits are the content hints of version 1
of the protocol, the version Device binds the text input's manager
at, with the protocol's values, and kTextInputHintMask is the ten
together. TextInputDefaultHints(purpose) is what a field gets when
the caller names no hints: the three Normal had, hidden_text and
sensitive_data for Password and Pin, none for the other eleven. For
Normal and Phone without hints that is the content type they had
before.
Window: SetTextInput takes the hints as a last, defaulted
std::optional<std::uint32_t>, which tells kTextInputHintNone (no
hints) from no argument (the purpose's defaults). It keeps only the
bits of kTextInputHintMask: version 2's hints are not in version 1's
enum. On Win32 and in the browser the call still does nothing.
Device, ApplyTextInput: it sends the window's purpose and hints as
they are. For a window whose field is enabled it compares them with
the ones the enable in force went out with, which the window now
keeps, and when either differs it sends an enable before the content
type, where it sent the content type without one. The protocol, as
bundled in lib/text-input-unstable-v3-client-protocol.h, says of
set_content_type's values that "Subsequent attempts to update them
may have no effect" and that they "remain valid until the next
committed enable or disable request", and of enable that it "must be
issued every time the focused text input changes to a new one,
including within the current surface". The same text has an enable
reset "the state associated with preedit_string, commit_string, and
delete_surrounding_text events", so such an enable clears the pending
flags and the record of the composing text the window was last told,
as the disable path does (
|
|||
|
89111e0d65 |
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. |
|||
|
c006519fa0 |
feat(wayland): keep xdg_toplevel's activated and suspended states on the window
A consumer could not tell a window somebody is looking at from one that merely exists. The compositor's word on it comes with every xdg_toplevel configure — the `activated` state, and since version 6 of xdg_wm_base `suspended`, "not ordinarily being repainted", for example for a content covered by another window or outputs switched off for a screen lock — and the window dropped the states array. A messenger built on it took a conversation left open behind a lock screen or another application for one that was being read: its texts were marked read and never notified. Window: `activated` and `suspended` hold the two states, and onToplevelState fires after a configure changed either, with both already set. They are batched as the size is: xdg_toplevel.configure leaves them pending and the xdg_surface.configure that ends the batch applies them (ApplyToplevelState) last, so the handler does nothing with the window after its listeners. The constructor takes the first configure before a listener can be added, so a consumer reads the two once after it. Both are reported and the library combines nothing: which of the two a lock screen or another window in front changes is the compositor's choice, so a consumer that asks whether the user is looking at the window wants `activated && !suspended`, and the consumer notes say so. The members are the Wayland backend's; the Win32 and DOM backends keep no such state. Device: xdg_wm_base is bound at the version the compositor offers, up to 6, where it was bound at 1: `suspended` does not exist below 6 (`activated` is version 1's). Every request the windows make is version 1's. Besides `suspended`, the higher versions bring the window state values it passes over (the tiled ones, 2) and two events, xdg_toplevel's configure_bounds (4) and wm_capabilities (5), which the toplevel's listener takes and drops, since libwayland aborts a client at an event whose handler is null. Tests: ToplevelState feeds the two configure callbacks of a window whose surfaces are proxies on a wl_display over a socketpair, as TitleWayland makes them, and reads the bind off the wire: the states pending until the surface's configure, the last toplevel configure of a batch applied, one event for a batch that changes both, none for a repeat or for other states, an empty array clearing both; an offer of 7, 6, 5 and 1 bound at 6, 6, 5 and 1; a handler in the xdg_wm_base, xdg_surface and xdg_toplevel listeners for every event of the bundled protocol. |
|||
|
364d2101c9 |
feat(wayland): add Window::lastInputTime, the compositor's time of a pointer or touch event
The pointer and touch handlers received wl_pointer's and wl_touch's `time` and dropped it, so a consumer could date an event only by its own clock at dispatch. Events queued while the consumer's loop is busy are dispatched together when it comes back, so by that clock a swipe's backlog is a burst, and a press and its release that both waited out a stall happen at one time. Window::lastInputTime is the compositor's time of the pointer, touch or scroll event a listener is being invoked for — milliseconds from an undefined base, wrapping at 2^32 — set before the event fires: the button events, a motion's onMouseMove, onMouseScroll, onTouchDown, onTouchMove and onTouchUp, and the pointer events the first finger stands in for. An event the compositor sends without a time keeps the last one's: an enter's onMouseEnter and the move that follows it, onMouseLeave, and a touch_cancel's release and onTouchCancel. A listener that dispatches Wayland events itself (it makes a Window, or calls Clipboard::GetText) runs the handlers of what is queued behind its event, and they set the time too: for that listener from there on, and for the listeners of its event that come after it. The click, move and release the first finger stands in for fire after the touch event's listeners, so the touch handlers set the time again before them. The member is the Wayland backend's alone: the Win32 and DOM handlers set no such time, and design rule 1 keeps the library from "inventing a shared signature that is a no-op on one side". Those builds have no such member, and the consumer notes say so. Tests: InputTime drives the wl_pointer and wl_touch handlers directly, as MouseScroll and PointerEnterLeave do, and reads lastInputTime in every listener: 0 before the first event; each event's own time for a motion, the four button events, a scroll and a touch's down, motion and up; the touch's time for the first finger's click, move and release, also when a listener of the touch event has run another handler in between, as a dispatch from inside it would; the last event's time for an enter and its move, a leave, and a cancel's release and onTouchCancel; a time past 2^31 and the one after the wrap as they came. |
|||
|
005b04b183 |
added review | |||
|
8c9a588083 |
test(win32): drop the __libc_single_threaded stand-in, which crafter-build 5.0.0 made unneeded
Tests - Win32Link linked under the Flatpak only with a C file defining __libc_single_threaded. crafter-build gave clang the host's /usr as the MinGW sysroot, which put glibc's headers on the include path, and libstdc++'s shared_ptr, inlined from nlohmann/json in Crafter.Asset's GLB loader, then read the symbol. crafter-build 5.0.0 shows clang only the mingw-w64 parts of /usr (Catcrafts/Crafter.Build#43), so nothing references it any more. Under 5.0.0 Win32Link links without it, and so does examples/HelloUI, which no stand-in covered. The native crafter-build on the host, which never had the problem, still builds PointerWin32, TextWin32 and Win32Link and runs them under Wine. Docs - AGENTS.template.md and AGENTS.consumer.md: linking for Win32 under the Flatpak needs crafter-build 5.0.0, and the workaround is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
|||
|
e0b1cf7b9e |
switched to agents.md template |
Renamed from AGENTS.md (Browse further)