RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
glass: derive an effect's scale from the outputs it overlaps
oxydizer723110558dbc
diff --git a/AGENTS.md b/AGENTS.mdindex 3d133fc..87fc762 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -42,8 +42,12 @@ the one for the directory you work in: `src/files`, `src/editor`,stays): persist raster sizes; test with `REDIWM_TEST_RENDERER=gles2`.* **Glass** samples `wlr_client_buffer_get(buffer)->texture` and trackssource-surface damage per effect. Empty commits and buffer rotation keep the- blur. Drags may hold titlebar blur at ≥ 0.98 opacity, so every path ending a- move schedules a frame.+ blur. Drags may hold titlebar blur at ≥ 0.98 opacity (the default theme is+ 0.80, so it follows), so every path ending a move schedules a frame. An+ effect's scale comes from the outputs its target overlaps (`effect_scale`),+ never from the output being updated: it is in the effect's hash, and an+ output-dependent value made outputs of different scales re-blur and damage+ each other forever (`glass_hold.py`).* **Commit only via `Output.commitFrameState`**, never`wlr_output_commit_state`. `commitIsRedundant` skips commits with no damage,colour change, attach-render lock or cursor change; register anything newdiff --git a/src/Output.zig b/src/Output.zigindex b15eb00..ffcd46d 100644--- a/src/Output.zig+++ b/src/Output.zig@@ -1285,7 +1285,7 @@ fn runFrame(output: *Output) void {false;glass.Engine.hold(output.server.glass_engine, output.server.input.heldGlass());glass.Engine.holdAll(output.server.glass_engine, output.server.world.holdingGlass());- glass.Engine.update(output.server.glass_engine, scene_output, output.wlr_output.scale);+ glass.Engine.update(output.server.glass_engine, scene_output);stats.global_stats.glass_cpu.record(stats.nowNs() -% glass_started);var captured = false;if (output.server.screenshot_mgr) |sm| {diff --git a/src/glass.c b/src/glass.cindex 00ec4bb..af38c5b 100644--- a/src/glass.c+++ b/src/glass.c@@ -1024,19 +1024,50 @@ void rediwm_glass_project(struct glass_engine *engine, struct rediwm_projectioneffect->zoom = node ? rediwm_projection_node_zoom(node) : 1;}}-static void update_tree(struct glass_engine *engine, struct wlr_scene_tree *tree, float scale)+// The highest scale among the outputs showing the effect's target, or among all+// outputs when it is on none. A scene node shows one buffer, so the blur is+// rendered once for every output it spans, at the sharpest scale. It must not+// depend on which output is being updated: the scale is part of the effect's+// hash, so with outputs of different scales each output's update used to see a+// new scale, re-render the blur and damage the others, and such a desktop never+// went idle.+static float effect_scale(struct glass_engine *engine, struct glass_effect *effect)+{+ struct wlr_scene_buffer *target =+ effect->projected_node && effect->projected_target ? effect->projected_target : effect->target;+ struct wlr_box box = {0};+ int x = 0, y = 0;+ if (wlr_scene_node_coords(&target->node, &x, &y))+ box = (struct wlr_box){x, y, target->dst_width, target->dst_height};+ float shown = 0, any = 0;+ struct wlr_scene_output *out;+ wl_list_for_each(out, &engine->scene->outputs, link)+ {+ if (!out->output->enabled)+ continue;+ float scale = out->output->scale;+ any = fmaxf(any, scale);+ int width, height;+ wlr_output_effective_resolution(out->output, &width, &height);+ struct wlr_box area = {out->x, out->y, width, height}, overlap;+ if (!wlr_box_empty(&box) && wlr_box_intersection(&overlap, &box, &area))+ shown = fmaxf(shown, scale);+ }+ return shown > 0 ? shown : any > 0 ? any : 1;+}+static void update_tree(struct glass_engine *engine, struct wlr_scene_tree *tree){struct wlr_scene_node *node;wl_list_for_each(node, &tree->children, link){struct glass_effect *effect = effect_for(engine, node);if (effect)- update_effect(effect, scale);+ update_effect(effect, effect_scale(engine, effect));else if (node->enabled && node->type == WLR_SCENE_NODE_TREE)- update_tree(engine, wlr_scene_tree_from_node(node), scale);+ update_tree(engine, wlr_scene_tree_from_node(node));}}-void rediwm_glass_update(struct glass_engine *engine, struct wlr_scene_output *output, float scale)+void rediwm_glass_update(struct glass_engine *engine, struct wlr_scene_output *output){if (!engine || engine->failed)return;@@ -1064,5 +1095,5 @@ void rediwm_glass_update(struct glass_engine *engine, struct wlr_scene_output *oengine->bounds = (struct wlr_box){x, y, right - x, bottom - y};}}- update_tree(engine, &engine->scene->tree, scale);+ update_tree(engine, &engine->scene->tree);}diff --git a/src/glass.zig b/src/glass.zigindex aec586b..e5cddaa 100644--- a/src/glass.zig+++ b/src/glass.zig@@ -18,7 +18,7 @@ pub const Engine = opaque {pub const hold = rediwm_glass_hold;extern fn rediwm_glass_hold_all(engine: ?*Engine, hold: bool) void;pub const holdAll = rediwm_glass_hold_all;- extern fn rediwm_glass_update(engine: ?*Engine, output: *wlr.SceneOutput, scale: f32) void;+ extern fn rediwm_glass_update(engine: ?*Engine, output: *wlr.SceneOutput) void;pub const update = rediwm_glass_update;extern fn rediwm_glass_project(engine: ?*Engine, projection: ?*anyopaque, zoom: f32) void;pub const project = rediwm_glass_project;diff --git a/tests/glass_hold.py b/tests/glass_hold.pyindex a0586c9..abdde9b 100644--- a/tests/glass_hold.py+++ b/tests/glass_hold.py@@ -15,7 +15,7 @@ import timefrom PIL import Image, ImageChopsfrom desktop_zoom import ROOT, build_client, wait_for-from ipc_client import IPCClient+from ipc_client import IPCClient, spawn_compositor, stop_processSCALE = 1.5TITLEBAR_HEIGHT = 55 # chrome.titlebar_height@@ -103,12 +103,66 @@ def differs(a, b):return ImageChops.difference(a, b).getbbox() is not None+def mixed_scale_idle():+ """Outputs of different scales share glass effects; a static desktop must stay idle.++ The effect's scale is part of its hash, so rendering it for whichever output+ was updating made each output re-blur it and damage the other, forever.+ """+ with tempfile.TemporaryDirectory(prefix="rediwm-glass-mixed-") as directory:+ tmp = Path(directory)+ build_client(tmp)+ config = ('[compositor]\nxwayland = false\n[[outputs]]\nname = "HEADLESS-1"\nscale = 1\n'+ '[[outputs]]\nname = "HEADLESS-2"\nscale = 1.5\n')+ process, log = spawn_compositor(+ tmp, scale="auto", outputs="2", config_content=config,+ renderer=os.environ.get("REDIWM_TEST_RENDERER", "gles2"),+ env_extra={"DBUS_SESSION_BUS_ADDRESS": "", "REDIWM_THEME": str(tmp / "rediwm-config.toml")})+ client = None+ try:+ with IPCClient(tmp) as ipc:+ ipc.wait_for("wallpaper_presented", timeout_ms=10000)+ outputs = sorted(ipc.get_outputs(), key=lambda out: out["x"])+ assert sorted(out["scale"] for out in outputs) == [1, 1.5], outputs+ display = wait_for(lambda: next((p.name for p in tmp.glob("wayland-*")+ if not p.name.endswith(".lock")), None), "display unavailable")+ client = subprocess.Popen([str(tmp / "client")], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,+ env=dict(os.environ, XDG_RUNTIME_DIR=str(tmp), WAYLAND_DISPLAY=display,+ REDIWM_TEST_DECORATION="server"))+ win = wait_for(lambda: next(iter(ipc.get_windows()), None), "window unavailable")+ # Straddle the boundary so its titlebar glass is seen by both outputs.+ ipc.action("move_window_to", {"id": win["id"], "x": outputs[1]["x"] - 200, "y": 120})+ time.sleep(1.0)+ ipc.wait_for_frame()+ ipc.reset_perf()+ time.sleep(1.5)+ perf = ipc.get_perf()+ assert perf["output_commits"] == 0, ("mixed-scale desktop keeps repainting", perf["output_commits"])+ print("PASS: outputs of different scales settle with a glass window across both")+ except Exception:+ print(log_text(tmp))+ raise+ finally:+ if client is not None and client.poll() is None:+ client.terminate()+ client.wait(timeout=3)+ stop_process(process)+ log.close()+++def log_text(tmp):+ path = tmp / "compositor.log"+ return path.read_text()[-3000:] if path.exists() else ""++def run():+ mixed_scale_idle()with tempfile.TemporaryDirectory(prefix="rediwm-glass-hold-") as directory:tmp = Path(directory)build_client(tmp)- # 250/255 is the nearest hex alpha at or above the 98% threshold.- for window_bg, holds in ((None, True), ("#101215fa", True), ("rgba(16,18,21,0.90)", False)):+ # 250/255 is the nearest hex alpha at or above the 98% threshold. The default+ # theme is 80% opaque, so it follows the backdrop like the 90% case.+ for window_bg, holds in ((None, False), ("#101215fa", True), ("rgba(16,18,21,0.90)", False)):moved, drag = session(tmp, window_bg, None, holds)placed, reference = session(tmp, window_bg, moved)assert (placed["x"], placed["y"]) == (moved["x"], moved["y"]), (placed, moved)