Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/design/effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 12 additions & 3 deletions docs/user/animation.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ enabled = true
curve = "spring:1,900"

[animation.dim_unfocused]
enabled = false
enabled = true
dim = 0.0

[animation.layers]
Expand Down Expand Up @@ -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 |

Expand All @@ -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]
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docs/user/window-rules-appearance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions examples/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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$"
Expand Down
3 changes: 2 additions & 1 deletion src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -2008,9 +2008,10 @@ namespace umbriel {
rect.node, std::max(1, static_cast<int>(std::lround(rect.box.width * scaleX))),
std::max(1, static_cast<int>(std::lround(rect.box.height * scaleY)))
);
const int r = static_cast<int>(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<int>(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(
Expand Down
2 changes: 1 addition & 1 deletion src/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ namespace umbriel {
wlr_scene_rect* node = nullptr;
std::array<float, 4> color{};
wlr_box box{};
int radius = 0;
std::array<int, 4> radii{};
};
std::vector<Rect> m_rects;
struct Blur {
Expand Down
11 changes: 9 additions & 2 deletions src/view/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<bool> 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;
Expand Down
16 changes: 12 additions & 4 deletions src/view/view_animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ namespace umbriel {
? 1.0F
: static_cast<float>(m_ruleOpacity.current());
const float fade = fadeComposited() ? 1.0F : m_fadeAlpha;
return std::clamp(
fade * ruleOpacity * m_dragOpacity * m_overviewOpacity * static_cast<float>(m_focusDim.current()), 0.0F, 1.0F
);
return std::clamp(fade * ruleOpacity * m_dragOpacity * m_overviewOpacity, 0.0F, 1.0F);
}

bool View::fullscreenOpaque() const {
Expand Down Expand Up @@ -100,6 +98,7 @@ namespace umbriel {
if (m_ssdFrame != nullptr) {
m_ssdFrame->setAlphas(chromeAlpha(), blurAlpha());
}
syncFocusShade();
}

void View::setOverviewOpacity(float opacity) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
81 changes: 67 additions & 14 deletions src/view/view_chrome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "view/view.h"

#include <algorithm>
#include <array>
extern "C" {
#include <umbrielfx/render/effect.h>
}
Expand Down Expand Up @@ -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();
Expand All @@ -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<float>(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<float, 4> 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<float, 4> 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<bool> focused = std::exchange(m_deferredBorderFocus, std::nullopt)) {
setBorderFocused(*focused);
Expand Down Expand Up @@ -327,6 +380,7 @@ namespace umbriel {
},
&ctx
);
syncFocusShade();
}

void View::updateDimBehind() {
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/view/view_lifecycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Loading