diff --git a/src/output/output.cpp b/src/output/output.cpp index 6b9187f11..bf10a3086 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -1675,6 +1675,7 @@ namespace umbriel { wlr_box outputArea{}; wlr_output_effective_resolution(m_output, &outputArea.width, &outputArea.height); if (outputArea.width <= 0 || outputArea.height <= 0) { + m_arrangedUsableArea = {}; return; } @@ -1744,21 +1745,22 @@ namespace umbriel { m_server->scheduleIpcLayersEvent(); m_server->scheduleIpcOutputsEvent(); const wlr_box layoutUsableArea = this->usableArea(); - // Arrangement runs on every layer commit; only a changed result is worth a line. - const wlr_box& logged = m_loggedUsableArea; - if (layoutUsableArea.x != logged.x - || layoutUsableArea.y != logged.y - || layoutUsableArea.width != logged.width - || layoutUsableArea.height != logged.height) { - m_loggedUsableArea = layoutUsableArea; + // Arrangement runs on every layer commit. Only a changed usable area re-lays out the workspace: that arrange is + // unanimated, so running it for a layer that reserves nothing (an OSD) would land an in-flight scroll at once. + const wlr_box& arranged = m_arrangedUsableArea; + if (layoutUsableArea.x != arranged.x + || layoutUsableArea.y != arranged.y + || layoutUsableArea.width != arranged.width + || layoutUsableArea.height != arranged.height) { + m_arrangedUsableArea = layoutUsableArea; markDirty(Dirty::QuitConfirm); kLog.debug( "{} usable={}x{}+{}+{}", m_output->name, layoutUsableArea.width, layoutUsableArea.height, layoutUsableArea.x, layoutUsableArea.y ); - } - if (m_workspaceGroup != nullptr && m_workspaceGroup->active() != nullptr) { - m_workspaceGroup->active()->markArrange(false); + if (m_workspaceGroup != nullptr && m_workspaceGroup->active() != nullptr) { + m_workspaceGroup->active()->markArrange(false); + } } } diff --git a/src/output/output.h b/src/output/output.h index 410d97c35..35db1cbf7 100644 --- a/src/output/output.h +++ b/src/output/output.h @@ -303,7 +303,7 @@ namespace umbriel { wlr_scene_optimized_blur* m_optimizedBlur = nullptr; std::unique_ptr m_workspaceGroup; wlr_box m_localUsableArea{}; - wlr_box m_loggedUsableArea{}; + wlr_box m_arrangedUsableArea{}; int m_arrangedLayoutX = 0; int m_arrangedLayoutY = 0; diff --git a/tests/harness/checks/animation/layer_commit_keeps_scroll.sh b/tests/harness/checks/animation/layer_commit_keeps_scroll.sh new file mode 100755 index 000000000..0ca17eb4c --- /dev/null +++ b/tests/harness/checks/animation/layer_commit_keeps_scroll.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# A layer surface that maps without changing the usable area, such as an OSD shown as focus moves, must not re-arrange +# the workspace: that arrange is unanimated and, landing before the focus scroll is flushed, would carry the strip to its +# target in one frame. +set -euo pipefail +source "$UMBRIEL_HARNESS_LIB" + +readonly SHOT="$UMBRIEL_RUNTIME_DIR/layer-commit-keeps-scroll.png" +readonly LAYER_LOG="$UMBRIEL_RUNTIME_DIR/layer.log" +readonly GREEN='g > 0.8 && r < 0.2 && b < 0.2' + +# A slow refresh keeps the focus request and the layer's first commit inside one frame. +printf '\n[layout.scrolling]\ndefault_extent_fraction = 0.5\n\n[colors]\nbackdrop = "#000000FF"\n\n[output.HEADLESS-1]\nmode = "1280x720@10"\n' >> "$UMBRIEL_CONFIG" +"$UMBRIEL" msg config-reload > /dev/null +"$UMBRIEL" settle +"$UMBRIEL" clock-freeze + +spawn_client() { + FILL_COLOR=$2 RESIZE_FILL_COLOR=$2 "$UMBRIEL_UNMAP_CLIENT" "$1" 400 300 > "$UMBRIEL_RUNTIME_DIR/$1.log" 2>&1 & +} + +wait_for_windows() { + for _ in $(seq 60); do + [[ $("$UMBRIEL" windows --json | jq 'length') -eq $1 ]] && return 0 + sleep 0.25 + done + echo "timed out waiting for $1 windows, saw $("$UMBRIEL" windows --json | jq 'length')" + return 1 +} + +finish() { + "$UMBRIEL" clock-advance 10000 + "$UMBRIEL" settle +} + +green_box() { + grim "$SHOT" + "$UMBRIEL_PIXEL_PROBE" "$SHOT" bbox "$GREEN" +} + +spawn_client scroll-blue 0xFF0000FF +wait_for_windows 1 +spawn_client scroll-magenta 0xFFFF00FF +wait_for_windows 2 +spawn_client scroll-green 0xFF00FF00 +wait_for_windows 3 +"$UMBRIEL" msg window-focus-left > /dev/null +"$UMBRIEL" msg window-focus-left > /dev/null +finish +start=$(green_box) + +mkfifo "$UMBRIEL_RUNTIME_DIR/layer.fifo" +"$UMBRIEL_LAYER_CLIENT" HEADLESS-1 0 overlay-layer commit-on-stdin < "$UMBRIEL_RUNTIME_DIR/layer.fifo" \ + > "$LAYER_LOG" 2>&1 & +exec {layer_fd}> "$UMBRIEL_RUNTIME_DIR/layer.fifo" +await_lines "$LAYER_LOG" waiting 1 + +# The OSD maps right after the focus request, before the scroll it starts is flushed. +"$UMBRIEL" msg window-focus-right > /dev/null +"$UMBRIEL" msg window-focus-right > /dev/null +printf '\n' >&"$layer_fd" +await_lines "$LAYER_LOG" ready 1 +"$UMBRIEL" clock-advance 40 +midway=$(green_box) +finish +landed=$(green_box) + +if [[ $start == "$landed" ]]; then + echo "focusing the green column did not scroll the strip: green stayed at $landed" + exit 1 +fi +if [[ $midway == "$landed" ]]; then + echo "mapping a layer surface landed the focus scroll at once: green was at $landed 40 ms in (started at $start)" + exit 1 +fi diff --git a/tests/harness/clients/layer_client.cpp b/tests/harness/clients/layer_client.cpp index ad12a6bea..b6b6499e8 100644 --- a/tests/harness/clients/layer_client.cpp +++ b/tests/harness/clients/layer_client.cpp @@ -8,6 +8,8 @@ // LAYER_CONTROL enables stdin commands: frames LABEL COUNT, color LABEL AARRGGBB, child-color LABEL AARRGGBB, // child-move LABEL X Y, and margins LABEL TOP RIGHT BOTTOM LEFT. Each prints done after its frame callbacks arrive. // popup-resize LABEL WIDTH HEIGHT overlaps two reposition requests and waits for its own token before redrawing. +// `commit-on-stdin` prints waiting and holds the initial commit until a line arrives on stdin, so a check can map the +// surface right after another request, as a shell OSD does. #include @@ -594,7 +596,7 @@ int main(int argc, char** argv) { if (argc < 3) { std::println( "usage: layer-client [bottom-layer|overlay-layer] " - "[log-configures] " + "[log-configures] [commit-on-stdin] " "[keyboard=none|on-demand|exclusive] [release-on-escape] [popup-on-click|popup-on-release] " "[popup-color=]" ); @@ -611,6 +613,7 @@ int main(int argc, char** argv) { // A 200x200 bottom-layer square in the top-left corner, which the overview mirrors into every workspace preview. bool bottom = false; bool overlay = false; + bool commitOnStdin = false; for (int index = 3; index < argc; ++index) { const std::string option = argv[index]; if (option == "bottom-layer") { @@ -625,6 +628,8 @@ int main(int argc, char** argv) { state.keyboardInteractivity = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE; } else if (option == "release-on-escape") { state.releaseOnEscape = true; + } else if (option == "commit-on-stdin") { + commitOnStdin = true; } else if (option == "log-configures") { state.logConfigures = true; } else if (option == "popup-on-click") { @@ -722,6 +727,12 @@ int main(int argc, char** argv) { } } zwlr_layer_surface_v1_set_anchor(state.layerSurface, anchors); + if (commitOnStdin) { + std::println("waiting"); + char byte = 0; + while (read(STDIN_FILENO, &byte, 1) == 1 && byte != '\n') { + } + } wl_surface_commit(state.surface); const bool control = std::getenv("LAYER_CONTROL") != nullptr;