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.
This commit is contained in:
parent
364d2101c9
commit
c006519fa0
7 changed files with 310 additions and 4 deletions
|
|
@ -305,6 +305,26 @@ export namespace Crafter {
|
|||
};
|
||||
std::vector<PollFd> pollFds;
|
||||
|
||||
// What the compositor says of the window's place on the screen, as
|
||||
// xdg_toplevel's states give it. `activated`: it counts as the
|
||||
// active window (no promise of keyboard or pointer focus).
|
||||
// `suspended`: it is not ordinarily being repainted — the
|
||||
// protocol's examples are a content covered by another window and
|
||||
// outputs switched off for a screen lock; the state came with
|
||||
// version 6 of xdg_wm_base, so under a compositor with an older
|
||||
// one it stays false. Which of the two a lock screen or another
|
||||
// window in front changes is the compositor's own choice, so a
|
||||
// consumer that asks whether the user is looking at the window
|
||||
// (is the message it shows read?) wants `activated && !suspended`.
|
||||
// Both are false until a configure sets them, which a new window's
|
||||
// first one need not do. onToplevelState fires after a configure
|
||||
// changed either, with both already set; the constructor takes the
|
||||
// first configure before a listener can be added, so a consumer
|
||||
// reads the two once after it.
|
||||
bool activated = false;
|
||||
bool suspended = false;
|
||||
Event<void> onToplevelState;
|
||||
|
||||
float scale = 1.0f;
|
||||
bool configured = false;
|
||||
// Pending size from the most recent xdg_toplevel.configure, in
|
||||
|
|
@ -312,6 +332,14 @@ export namespace Crafter {
|
|||
// via Resize(); 0 means "compositor has no preference, keep current".
|
||||
std::int32_t pendingLogicalWidth = 0;
|
||||
std::int32_t pendingLogicalHeight = 0;
|
||||
// The states of that configure, batched like its size:
|
||||
// ApplyToplevelState makes them the window's at the
|
||||
// xdg_surface.configure that ends the batch and fires
|
||||
// onToplevelState when that changed one, as the handler's last
|
||||
// step: it does nothing with the window after its listeners.
|
||||
bool pendingActivated = false;
|
||||
bool pendingSuspended = false;
|
||||
void ApplyToplevelState();
|
||||
xdg_toplevel* xdgToplevel = nullptr;
|
||||
zxdg_toplevel_decoration_v1* decoration = nullptr;
|
||||
wp_viewport* wpViewport = nullptr;
|
||||
|
|
@ -340,10 +368,18 @@ export namespace Crafter {
|
|||
static void xdg_toplevel_handle_close(void* data, xdg_toplevel*);
|
||||
static void xdg_surface_handle_configure(void* data, xdg_surface* xdg_surface, std::uint32_t serial);
|
||||
static void xdg_toplevel_configure(void*, xdg_toplevel*, std::int32_t, std::int32_t, wl_array*);
|
||||
static void xdg_toplevel_configure_bounds(void*, xdg_toplevel*, std::int32_t, std::int32_t);
|
||||
static void xdg_toplevel_wm_capabilities(void*, xdg_toplevel*, wl_array*);
|
||||
|
||||
constexpr static xdg_toplevel_listener xdg_toplevel_listener = {
|
||||
.configure = xdg_toplevel_configure,
|
||||
.close = xdg_toplevel_handle_close,
|
||||
// Events of versions 4 and 5 of xdg_wm_base, which the bind for
|
||||
// `suspended` brings with it. The window has no use for either,
|
||||
// but libwayland aborts the client at an event whose handler is
|
||||
// null.
|
||||
.configure_bounds = xdg_toplevel_configure_bounds,
|
||||
.wm_capabilities = xdg_toplevel_wm_capabilities,
|
||||
};
|
||||
constexpr static wl_callback_listener wl_callback_listener = {
|
||||
.done = wl_surface_frame_done,
|
||||
|
|
|
|||
Loading…
Reference in a new issue