From 13e9124ec6d8482ed3cf5b4549e28551743b2e97 Mon Sep 17 00:00:00 2001 From: JD Date: Sat, 28 Nov 2026 18:33:57 -0600 Subject: [PATCH] feat(animation): make dim_unfocused darken unfocused windows --- docs/design/effects.md | 2 +- docs/user/animation.md | 15 +- docs/user/window-rules-appearance.md | 2 +- examples/config.toml | 5 + src/config/config.h | 3 +- src/server/server.cpp | 9 +- src/server/server.h | 2 +- src/view/view.h | 11 +- src/view/view_animation.cpp | 16 +- src/view/view_chrome.cpp | 81 ++++++++-- src/view/view_lifecycle.cpp | 5 + .../harness/checks/animation/dim_unfocused.sh | 143 ++++++++++++++++++ tests/unit/config_load.cpp | 16 ++ 13 files changed, 279 insertions(+), 31 deletions(-) create mode 100644 tests/harness/checks/animation/dim_unfocused.sh diff --git a/docs/design/effects.md b/docs/design/effects.md index e53ecce06..bfe50590b 100644 --- a/docs/design/effects.md +++ b/docs/design/effects.md @@ -173,7 +173,7 @@ Effect state is attached through scene-node addons, preserving the scene ABI. Th | `overview` | Per-output overview tree when entering or leaving overview and zoom/row settling | | `scratchpad` | View show/hide fade and separate dim/blur backdrop targets | | `border` | Border tree and focus-color animation | -| `dim_unfocused` | View tree and focus-opacity animation | +| `dim_unfocused` | View tree and unfocused shade animation | | `layers` | Layer tree or close snapshot and map/unmap fade | The renderer captures contiguous descendants from the scene's paint-ordered render list into an alpha framebuffer, recursively processes inner effects, then runs each enclosing shader once. Subsurfaces therefore share the window's effect rather than restarting it. Overview cards reuse the source view's animation state. Window shadows sit beside the animated content tree, never inside it. diff --git a/docs/user/animation.md b/docs/user/animation.md index b066f2be1..1abc0f158 100644 --- a/docs/user/animation.md +++ b/docs/user/animation.md @@ -57,7 +57,7 @@ enabled = true curve = "spring:1,900" [animation.dim_unfocused] -enabled = false +enabled = true dim = 0.0 [animation.layers] @@ -88,7 +88,7 @@ Each event other than `windows_drag` also accepts `enabled`, `duration_ms`, and | `[animation.scratchpad]` | `dim`, `blur` | Scratchpad show and hide, and its backdrop | | `[animation.dialogs]` | `dim`, and no `effect` | Shade over a window while a modal dialog is attached to it | | `[animation.border]` | none | Focus-border color | -| `[animation.dim_unfocused]` | `dim` | Unfocused-window opacity | +| `[animation.dim_unfocused]` | `dim` | Unfocused window dimming | | `[animation.layers]` | none | Layer-shell map and unmap | | `[animation.windows_drag]` | `physics` (default `false`) plus the drag-physics tuning keys below | Drag physics | @@ -110,7 +110,7 @@ Dialogs `dim` works the same way: it is the opacity, 0.0 to 1.0 and `0.3` by def `[animation.windows_opacity]` fades between the opacity and window and title-bar blur defined by window rules when focus changes. It is enabled by default and uses the same default timing as `[animation.border]`: `curve = "spring:1,900"`, with a 250 ms fallback for duration-based curves. Explicit top-level `[animation] duration_ms` and `curve` values supply defaults just as they do for the other event tables. Each table can override them independently. -Use `enabled = false` for immediate focus changes. With a non-spring curve, `duration_ms` sets the fade length. A spring derives its own duration. Refocusing during a fade starts from the current appearance. Border colors keep using `[animation.border]`; disabling that table does not disable opacity or blur fades. `[animation.dim_unfocused]` adds its own opacity multiplier independently of window rules. +Use `enabled = false` for immediate focus changes. With a non-spring curve, `duration_ms` sets the fade length. A spring derives its own duration. Refocusing during a fade starts from the current appearance. Border colors keep using `[animation.border]`; disabling that table does not disable opacity or blur fades. `[animation.dim_unfocused]` darkens unfocused windows independently of window rules; see [Unfocused dimming](#unfocused-dimming). ```toml [animation.windows_opacity] @@ -119,6 +119,15 @@ duration_ms = 200 curve = "easeinoutcubic" ``` +## Unfocused dimming + +```toml +[animation.dim_unfocused] +dim = 0.3 +``` + +`[animation.dim_unfocused]` `dim`, 0.0 to 1.0 (`0.0` by default), is the opacity of a black shade over each unfocused window, like the shade dialogs `dim` draws. The window gets darker without turning transparent, so nothing behind it shows through and backdrop blur does not turn on. Borders, the title bar, popups, and an attached dialog stay undimmed, and overview cards show windows without the shade. The shade fades when focus changes. `enabled = false` turns it off, and with animation disabled it applies without a fade. For translucent unfocused windows, set window-rule `opacity` with `match.is_focused = false` instead (see [Fade unfocused windows](window-rules-appearance.md#fade-unfocused-windows)). + ## Curves Use a built-in curve such as `linear`, `ease`, `easeout`, `snappy`, `bounce`, or `elastic`; a cubic Bézier string; or a spring: diff --git a/docs/user/window-rules-appearance.md b/docs/user/window-rules-appearance.md index 55f79789f..cd79e6192 100644 --- a/docs/user/window-rules-appearance.md +++ b/docs/user/window-rules-appearance.md @@ -59,7 +59,7 @@ match.is_focused = true opacity = 1.0 ``` -Opacity and blur fade when focus changes. The fade timing is set in [Window opacity](animation.md#window-opacity). +Opacity and blur fade when focus changes. The fade timing is set in [Window opacity](animation.md#window-opacity). To darken unfocused windows without making them transparent, use [Unfocused dimming](animation.md#unfocused-dimming). ## Borders that show window state diff --git a/examples/config.toml b/examples/config.toml index ad9b743ad..8797ac653 100644 --- a/examples/config.toml +++ b/examples/config.toml @@ -499,6 +499,11 @@ action = "overview-open" # [animation.dialogs] # dim = 0.3 +# Darken unfocused windows. For translucent unfocused windows, use a window rule +# with match.is_focused = false and opacity instead. +# [animation.dim_unfocused] +# dim = 0.2 + # Darken the output below a launcher while it is visible: # [[layer_rule]] # match.namespace = "^vicinae$" diff --git a/src/config/config.h b/src/config/config.h index 301e6694b..d7baf44f6 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -968,9 +968,10 @@ namespace umbriel { bool operator==(const WindowsOpacity&) const = default; } windowsOpacity; + // The black shade over unfocused windows. `enabled = false` removes it; with animation off it applies unfaded. struct DimUnfocused { std::string effect; - bool enabled = false; + bool enabled = true; int durationMs = 250; AnimationCurve curve{.easing = Easing::EaseOutCubic}; double dim = 0.0; diff --git a/src/server/server.cpp b/src/server/server.cpp index 4a97406fe..bf57baaee 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -1907,7 +1907,7 @@ namespace umbriel { {rect, {rect->color[0], rect->color[1], rect->color[2], rect->color[3]}, {node->x, node->y, rect->width, rect->height}, - rect->corners.top_left} + {rect->corners.top_left, rect->corners.top_right, rect->corners.bottom_right, rect->corners.bottom_left}} ); } else if (node->type == WLR_SCENE_NODE_BLUR) { auto* blur = wlr_scene_blur_from_node(node); @@ -2008,9 +2008,10 @@ namespace umbriel { rect.node, std::max(1, static_cast(std::lround(rect.box.width * scaleX))), std::max(1, static_cast(std::lround(rect.box.height * scaleY))) ); - const int r = static_cast(std::lround(rect.radius * std::min(scaleX, scaleY))); - const bool background = rect.box.y == -m_topExtension && rect.box.width == m_captured.width; - wlr_scene_rect_set_corner_radii(rect.node, background ? corner_radii_new(r, r, 0, 0) : corner_radii_all(r)); + const auto radius = [&](size_t corner) { + return static_cast(std::lround(rect.radii[corner] * std::min(scaleX, scaleY))); + }; + wlr_scene_rect_set_corner_radii(rect.node, corner_radii_new(radius(0), radius(1), radius(2), radius(3))); } for (const Blur& blur : m_blurs) { wlr_scene_node_set_position( diff --git a/src/server/server.h b/src/server/server.h index 04e8fe3ef..02b737da8 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -924,7 +924,7 @@ namespace umbriel { wlr_scene_rect* node = nullptr; std::array color{}; wlr_box box{}; - int radius = 0; + std::array radii{}; }; std::vector m_rects; struct Blur { diff --git a/src/view/view.h b/src/view/view.h index 75088e8f2..18a97dda0 100644 --- a/src/view/view.h +++ b/src/view/view.h @@ -679,7 +679,7 @@ namespace umbriel { // presentation consumers must not infer their size independently from the committed geometry. void trackPresentedSize(int width, int height); // Re-apply compositor-owned opacity to surface buffers. With opaque_fullscreen, fullscreen bypasses window-rule - // opacity, while fades, drag opacity, focus dimming, and client-provided alpha remain active. + // opacity, while fades, drag opacity, and client-provided alpha remain active. float effectiveOpacity() const; // A fullscreen window in this state hides everything behind it: it draws over the backdrop and skips blur. Without // opaque_fullscreen, rule opacity below 1, client alpha below 1, or an opaque region short of the window geometry @@ -857,6 +857,10 @@ namespace umbriel { // Fade the shade in while a dialog is attached and out once none is; animation.dialogs times it. void retargetModalShade(); void syncModalShade(); + // Head the unfocused shade for the current focus, fading it on a focus change and snapping it otherwise; + // animation.dim_unfocused times it. + void retargetFocusShade(bool focusChanged); + void syncFocusShade(); void releaseDialog(); [[nodiscard]] bool inheritScratchpadFromParent(bool restoreTiled); void syncTransientSceneParent(); @@ -1012,6 +1016,9 @@ namespace umbriel { wlr_scene_rect* m_modalShade = nullptr; // 0 to 1 of animation.dialogs.dim. AnimatedValue m_modalShadeAlpha{0.0}; + // Darkens the client content while unfocused: directly above the root surface tree in the content tree, so it + // travels with content effects while popups, borders, and the title bar stay above it. + wlr_scene_rect* m_focusShade = nullptr; // A separate scene containing only client-owned surfaces. Window capture // must never sample the composited desktop behind translucent content. wlr_scene* m_captureScene = nullptr; @@ -1149,11 +1156,11 @@ namespace umbriel { bool m_customFade = false; AnimatedColor m_borderColorAnim; AnimatedColor m_outerBorderColorAnim; + // The brightness m_focusShade leaves: 1 when focused, 1 - animation.dim_unfocused.dim when unfocused. AnimatedValue m_focusDim{1.0}; float m_fadeAlpha = 1.0F; bool m_borderFocusedState = false; std::optional m_deferredBorderFocus; - bool m_focusDimInitialized = false; // Opening identity can settle independently. The first title and first // non-none content type each get one chance to add one-shot rule effects. bool m_initialTitleRulesSettled = false; diff --git a/src/view/view_animation.cpp b/src/view/view_animation.cpp index 5d7d52449..47e5316d5 100644 --- a/src/view/view_animation.cpp +++ b/src/view/view_animation.cpp @@ -53,9 +53,7 @@ namespace umbriel { ? 1.0F : static_cast(m_ruleOpacity.current()); const float fade = fadeComposited() ? 1.0F : m_fadeAlpha; - return std::clamp( - fade * ruleOpacity * m_dragOpacity * m_overviewOpacity * static_cast(m_focusDim.current()), 0.0F, 1.0F - ); + return std::clamp(fade * ruleOpacity * m_dragOpacity * m_overviewOpacity, 0.0F, 1.0F); } bool View::fullscreenOpaque() const { @@ -100,6 +98,7 @@ namespace umbriel { if (m_ssdFrame != nullptr) { m_ssdFrame->setAlphas(chromeAlpha(), blurAlpha()); } + syncFocusShade(); } void View::setOverviewOpacity(float opacity) { @@ -1103,7 +1102,7 @@ namespace umbriel { openingFinished = m_mapped && !m_inScratchpad && !m_fade.animating() && m_fade.target() > m_fade.from(); } if (m_focusDim.tick(nowMsec)) { - setFadeAlpha(m_fadeAlpha); + syncFocusShade(); active = active || m_focusDim.animating(); } const bool opacityChanged = m_ruleOpacity.tick(nowMsec); @@ -1307,6 +1306,15 @@ namespace umbriel { wlr_scene_node_destroy(&snap->node); return kInvalidCloseSnapshot; } + // The copy keeps the unfocused shade, so a window closing unfocused does not brighten as it goes. + if (m_focusShade != nullptr && m_focusShade->node.enabled) { + if (wlr_scene_rect* shade = + wlr_scene_rect_create(content, m_focusShade->width, m_focusShade->height, m_focusShade->color)) { + shade->accepts_input = false; + wlr_scene_node_set_position(&shade->node, m_focusShade->node.x, m_focusShade->node.y); + wlr_scene_rect_set_corner_radii(shade, m_focusShade->corners); + } + } wlr_scene_node_copy_animations_for_snapshot(&snap->node, &m_contentTree->node); // Window and overlay effects live on the surface tree; the snapshot's content tree takes them over with time diff --git a/src/view/view_chrome.cpp b/src/view/view_chrome.cpp index bc1180d68..1a01c5241 100644 --- a/src/view/view_chrome.cpp +++ b/src/view/view_chrome.cpp @@ -13,6 +13,7 @@ #include "view/view.h" #include +#include extern "C" { #include } @@ -178,19 +179,7 @@ namespace umbriel { m_ssdFrame->setFocused(focused); } - const auto& animation = config().animation; - const auto& dim = animation.dimUnfocused; - if (focusChanged || !m_focusDimInitialized) { - m_focusDimInitialized = true; - const double target = focused || !m_mapped || !animation.enabled || !dim.enabled ? 1.0 : 1.0 - dim.dim; - if (m_mapped && focusChanged && animation.enabled && dim.enabled) { - m_focusDim.retarget(target, dim.durationMs, dim.curve); - scheduleFrame(); - } else { - m_focusDim.snap(target); - } - setFadeAlpha(m_fadeAlpha); - } + retargetFocusShade(focusChanged); if (focusChanged && m_mapped) { applyDynamicRules(); @@ -199,6 +188,70 @@ namespace umbriel { } } + void View::retargetFocusShade(bool focusChanged) { + const auto& animation = config().animation; + const auto& dim = animation.dimUnfocused; + const double target = m_borderFocusedState || !m_mapped || !dim.enabled ? 1.0 : 1.0 - dim.dim; + const bool fades = m_mapped && animation.enabled && dim.enabled; + // A running fade lands at once when a reload turns fading off. + if (!focusChanged && target == m_focusDim.target() && (fades || !m_focusDim.animating())) { + return; + } + // A preset on the event plays on every focus change, even one that leaves the shade where it is. + const bool moves = + target != m_focusDim.current() || effectRegistry().animationEffect(AnimationEvent::DimUnfocused) != nullptr; + if (focusChanged && fades && moves) { + m_focusDim.retarget(target, dim.durationMs, dim.curve); + scheduleFrame(); + } else { + m_focusDim.snap(target); + } + syncFocusShade(); + } + + void View::syncFocusShade() { + if (m_sceneTree == nullptr || m_contentTree == nullptr) { + return; + } + // Overshooting curves can push the brightness past [0, 1]. The shade fades with the window it covers. A fully + // opaque shade would cull the surface below it, and a window that stays presented gets no frame callbacks from + // anywhere else, so the shade stops one step short of opaque, which still draws black. + static constexpr float kDarkest = 1.0F - 0x1p-24F; + const float alpha = + std::min(static_cast(std::clamp(1.0 - m_focusDim.current(), 0.0, 1.0)) * effectiveOpacity(), kDarkest); + // The content tree outlives an unmap, and only the shade's place directly above the surface keeps popups, borders, + // and title-bar chrome undimmed above it. + wlr_scene_node* surface = + m_mapped && alpha > 0.0F ? view_detail::toplevelSurfaceTreeNode(m_contentTree, rootSurface()) : nullptr; + if (surface == nullptr) { + if (m_focusShade != nullptr) { + wlr_scene_node_set_enabled(&m_focusShade->node, false); + } + return; + } + if (m_focusShade == nullptr) { + static constexpr std::array kClear{0.0F, 0.0F, 0.0F, 0.0F}; + m_focusShade = wlr_scene_rect_create(m_contentTree, 0, 0, kClear.data()); + if (m_focusShade == nullptr) { + return; + } + // Hidden until it is placed and sized, so creation damages nothing. Presses reach the client below it. + wlr_scene_node_set_enabled(&m_focusShade->node, false); + m_focusShade->accepts_input = false; + } + wlr_scene_node_place_above(&m_focusShade->node, surface); + const ClientSize size = chromeContentSize(); + const int radius = surfaceRadius(); + const std::array color{0.0F, 0.0F, 0.0F, alpha}; + wlr_scene_rect_set_color(m_focusShade, color.data()); + wlr_scene_rect_set_size(m_focusShade, std::max(size.width, 0), std::max(size.height, 0)); + // Content meets the title bar along a square seam. + wlr_scene_rect_set_corner_radii( + m_focusShade, titleBarHeight() > 0 ? corner_radii_new(0, 0, radius, radius) : corner_radii_all(radius) + ); + wlr_scene_node_set_enabled(&m_focusShade->node, true); + } + void View::applyDeferredBorderFocus() { if (const std::optional focused = std::exchange(m_deferredBorderFocus, std::nullopt)) { setBorderFocused(*focused); @@ -327,6 +380,7 @@ namespace umbriel { }, &ctx ); + syncFocusShade(); } void View::updateDimBehind() { @@ -472,7 +526,6 @@ namespace umbriel { if (m_chromeAttachment != nullptr) { m_chromeAttachment->reloadConfig(); } - m_focusDimInitialized = false; // Temporary unfocus would consume pool selections during an unrelated reload. setBorderFocused(m_borderFocusedState); updateBorderGeometry(); diff --git a/src/view/view_lifecycle.cpp b/src/view/view_lifecycle.cpp index d76adf856..6e06af12b 100644 --- a/src/view/view_lifecycle.cpp +++ b/src/view/view_lifecycle.cpp @@ -619,6 +619,8 @@ namespace umbriel { // Replay their shared structure now that this member is visible again. m_server->scheduleDisplacedViewRestore(); } + // A window that maps without focus takes its shade at once; focus changes before now found it unmapped. + retargetFocusShade(false); // Opening rules resolve before default_floating and default_pinned move the window, so the state selectors may // pick a different set of dynamic effects than the ones applied above. applyDynamicRules(); @@ -800,6 +802,9 @@ namespace umbriel { const bool hadRuntimeEffects = m_effects.slot(EffectKind::Border).runtimeSelector.has_value() || m_effects.slot(EffectKind::Window).runtimeSelector.has_value(); m_mapped = false; + // The close snapshot already carries the shade. Unfocusing on the way out may have started a fade. + m_focusDim.snap(1.0); + syncFocusShade(); m_floatedByStackingLayout = false; if (m_workspace != nullptr) { m_workspace->syncFloatingStack(this); diff --git a/tests/harness/checks/animation/dim_unfocused.sh b/tests/harness/checks/animation/dim_unfocused.sh new file mode 100644 index 000000000..865cbe9e7 --- /dev/null +++ b/tests/harness/checks/animation/dim_unfocused.sh @@ -0,0 +1,143 @@ +#!/usr/bin/env bash +# animation.dim_unfocused darkens an unfocused window toward black rather than letting what lies behind it show +# through. The shade fades with the focus change, leaves the window's popups bright, still applies at once when +# animation is disabled, leaves no shade after unmap, blacks out at dim = 1.0 without stalling frame callbacks, and +# goes away when the table is disabled. +set -euo pipefail +source "$UMBRIEL_HARNESS_LIB" +readonly FRAME="$UMBRIEL_RUNTIME_DIR/shade.png" + +cat >> "$UMBRIEL_CONFIG" <<'CONFIG' +[animation] +enabled = true +curve = "linear" +[animation.windows_in] +enabled = false +[animation.windows_out] +enabled = false +[animation.windows_move] +enabled = false +[animation.border] +enabled = false +[animation.dim_unfocused] +enabled = true +dim = 0.5 +duration_ms = 1000 +[appearance] +border_width = 0 +outer_border_width = 0 +corner_radius = 0 +[appearance.title_bar] +mode = "off" +[appearance.shadow] +enabled = false +[appearance.blur] +enabled = false + +[[window_rule]] +match.title = "^(popup-focus-regression|shade-white|shade-opaque|shade-home)$" +default_floating = true +[[window_rule]] +match.title = "^popup-focus-regression$" +default_position = { x = 0, y = 0, anchor = "top_left" } +[[window_rule]] +match.title = "^(shade-white|shade-opaque)$" +default_floating_size_px = { width = 300, height = 200 } +default_position = { x = 400, y = 200, anchor = "top_left" } +[[window_rule]] +match.title = "^shade-home$" +default_floating_size_px = { width = 200, height = 150 } +default_position = { x = 900, y = 450, anchor = "top_left" } +CONFIG +"$UMBRIEL" msg config-reload > /dev/null + +# A 1260x700 #5577AA window at the output origin, whose popup is #EEAA33 at (20, 20) to (140, 100). The popup opens +# before the window loses focus, so the shade arrives in a content tree that already holds it. The window then stays +# unfocused below the others. Not `umbriel settle`: this client acks configures without committing. +mkfifo "$UMBRIEL_RUNTIME_DIR/popup.fifo" +"$UMBRIEL_POPUP_CLIENT" --popup-on-stdin < "$UMBRIEL_RUNTIME_DIR/popup.fifo" > "$UMBRIEL_RUNTIME_DIR/popup.log" 2>&1 & +exec {popup_fd}> "$UMBRIEL_RUNTIME_DIR/popup.fifo" +await_lines "$UMBRIEL_RUNTIME_DIR/popup.log" ready 1 +echo popup >&"$popup_fd" +await_lines "$UMBRIEL_RUNTIME_DIR/popup.log" popup-mapped 1 +FILL_COLOR=0xFFFFFFFF "$UMBRIEL_UNMAP_CLIENT" shade-white 300 200 > "$UMBRIEL_RUNTIME_DIR/white.log" 2>&1 & +await_window shade-white +FILL_COLOR=0xFF00FF00 "$UMBRIEL_UNMAP_CLIENT" shade-home 200 150 > "$UMBRIEL_RUNTIME_DIR/home.log" 2>&1 & +await_window shade-home +white=$(window_by_title shade-white | jq -r .id) +home=$(window_by_title shade-home | jq -r .id) + +focus() { "$UMBRIEL" msg window-focus "$1" > /dev/null; } +shot() { grim "$FRAME"; } +assert_pixel() { assert_region_rgb "$FRAME" "10x10+$1+$2" "$3" "$4" "$5" "$6"; } + +"$UMBRIEL" clock-freeze > /dev/null +focus "$white" +"$UMBRIEL" clock-advance 2000 > /dev/null +shot +assert_pixel 545 295 255 255 255 'focused window stays bright' +assert_pixel 195 495 43 60 85 'unfocused window darkens by dim' +assert_pixel 75 55 238 170 51 'popup of an unfocused window stays bright' + +focus "$home" +shot +assert_pixel 545 295 255 255 255 'losing focus starts from full brightness' +"$UMBRIEL" clock-advance 500 > /dev/null +shot +read -r r g b < <("$UMBRIEL_PIXEL_PROBE" "$FRAME" mean 10x10+545+295) +if (( r <= 140 || r >= 240 || g < r - 2 || g > r + 2 || b < r - 2 || b > r + 2 )); then + echo "shade did not fade toward black with the focus change: got $r $g $b" + exit 1 +fi +"$UMBRIEL" clock-advance 1000 > /dev/null +shot +assert_pixel 545 295 128 128 128 'unfocused window darkens toward black, not toward what lies behind it' + +focus "$white" +"$UMBRIEL" clock-advance 1000 > /dev/null +shot +assert_pixel 545 295 255 255 255 'refocused window returns to full brightness' + +# The master switch drops the fade, not the shade. +sed -i '/^\[animation\]$/,/^curve = /s/^enabled = true$/enabled = false/' "$UMBRIEL_CONFIG" +"$UMBRIEL" msg config-reload > /dev/null +focus "$home" +shot +assert_pixel 545 295 128 128 128 'without animation the shade applies at once' +focus "$white" +shot +assert_pixel 545 295 255 255 255 'without animation focus clears the shade at once' + +# This client unmaps on a close request but keeps its toplevel. Its shade must leave with it, uncovering the shaded +# window below rather than staying behind over it. +focus "$home" +"$UMBRIEL" msg window-close "$white" > /dev/null +await_lines "$UMBRIEL_RUNTIME_DIR/white.log" unmapped 1 +for _ in $(seq 80); do + shot + assert_pixel 545 295 43 60 85 unmapped > /dev/null && break + sleep 0.025 +done +assert_pixel 545 295 43 60 85 'an unmapped window leaves no shade behind' + +# At dim = 1.0 an unfocused opaque window turns black, but the shade must not count as an opaque cover that culls +# the surface underneath and leaves the client waiting forever for a frame callback. +sed -i '/^\[animation\.dim_unfocused\]$/,/^duration_ms = /s/^dim = 0\.5$/dim = 1.0/' "$UMBRIEL_CONFIG" +"$UMBRIEL" msg config-reload > /dev/null +mkfifo "$UMBRIEL_RUNTIME_DIR/repaint.fifo" +exec {repaint_fd}<> "$UMBRIEL_RUNTIME_DIR/repaint.fifo" +OPAQUE_BUFFER=1 REPAINT_ON_STDIN=1 FILL_COLOR=0xFFFFFFFF "$UMBRIEL_UNMAP_CLIENT" shade-opaque 300 200 \ + <&"$repaint_fd" > "$UMBRIEL_RUNTIME_DIR/opaque.log" 2>&1 & +await_window shade-opaque +focus "$home" +shot +assert_pixel 545 295 0 0 0 'dim = 1.0 turns an unfocused window black' +echo R >&"$repaint_fd" +await_lines "$UMBRIEL_RUNTIME_DIR/opaque.log" repainted 1 + +# Disabling the table removes the shade from windows that are already unfocused. +sed -i '/^\[animation.dim_unfocused\]$/,/^duration_ms = /s/^enabled = true$/enabled = false/' "$UMBRIEL_CONFIG" +"$UMBRIEL" msg config-reload > /dev/null +shot +assert_pixel 195 495 85 119 170 'disabling dim_unfocused removes the shade' +echo "unfocused windows darken toward black by dim, fade with focus, keep popups bright, unshade on unmap, keep frame callbacks at dim = 1.0, and turn off" diff --git a/tests/unit/config_load.cpp b/tests/unit/config_load.cpp index 4dbae12ac..58aea44bc 100644 --- a/tests/unit/config_load.cpp +++ b/tests/unit/config_load.cpp @@ -3742,6 +3742,22 @@ UMBRIEL_TEST(tabletConfigDefaults) { CHECK(!tablet.calibrationMatrix.has_value()); } +// `dim` alone shades unfocused windows: the table is enabled by default and shades nothing until `dim` is set. +UMBRIEL_TEST(dimUnfocusedDimAloneShadesWithTheDefaultFade) { + const umbriel::Config defaults; + CHECK(defaults.animation.dimUnfocused.enabled); + CHECK_EQ(defaults.animation.dimUnfocused.dim, 0.0); + + const TempConfig file; + file.write("[animation.dim_unfocused]\ndim = 0.35\n"); + ConfigStore& store = umbriel::configStore(); + store.setRootPath(file.path(), true); + CHECK(store.reload().success); + const auto& dim = store.config().animation.dimUnfocused; + CHECK(dim.enabled); + CHECK_EQ(dim.dim, 0.35); +} + UMBRIEL_TEST(animationEffectsResolveIncludedPresetsAcrossAllEventsAndTrackContentChanges) { const TempConfigTree tree; const std::array sections{"windows_in", "windows_out", "windows_move", "workspaces", "overview",