Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

Notifications: hold toasts while a game fills their output

oxydizer78ad8ea90e2d
diff --git a/src/config/default.zig b/src/config/default.zig
index be25ef0..f3fb75a 100644
--- a/src/config/default.zig
+++ b/src/config/default.zig
@@ -340,6 +340,7 @@ pub const source =
\\
\\# [notifications]
\\# daemon = "dunst" # optional external daemon; restart required
+ \\# game_dnd = true # no toasts over a fullscreen or borderless game (critical still show)
\\
\\# [ipc]
\\# automation = true # IPC synthetic input and screen capture; restart required
diff --git a/src/config/loader.zig b/src/config/loader.zig
index f46d42e..9ea2835 100644
--- a/src/config/loader.zig
+++ b/src/config/loader.zig
@@ -324,6 +324,9 @@ pub const IdleConfig = struct {
pub const NotificationsConfig = struct {
daemon: []const u8 = "", // Empty selects the built-in daemon; changes require restart.
dnd: bool = false,
+ /// A game filling the output toasts appear on holds non-critical toasts
+ /// like DND (they still reach the history).
+ game_dnd: bool = true,
default_timeout_ms: u32 = 5000,
};
diff --git a/src/config/loader_fields.zig b/src/config/loader_fields.zig
index 12bfc88..93075e3 100644
--- a/src/config/loader_fields.zig
+++ b/src/config/loader_fields.zig
@@ -355,6 +355,8 @@ pub fn applyNotificationsKey(n: *NotificationsConfig, allocator: Allocator, key:
n.daemon = try parseString(allocator, value);
} else if (std.mem.eql(u8, key, "dnd")) {
n.dnd = try parseBool(value);
+ } else if (std.mem.eql(u8, key, "game_dnd")) {
+ n.game_dnd = try parseBool(value);
} else if (std.mem.eql(u8, key, "default_timeout_ms")) {
n.default_timeout_ms = try parseU32Range(value, 0, std.math.maxInt(u32));
} else {
diff --git a/src/notifications/manager.zig b/src/notifications/manager.zig
index e77840c..61eb0ee 100644
--- a/src/notifications/manager.zig
+++ b/src/notifications/manager.zig
@@ -9,6 +9,7 @@ const activation = @import("../session/activation.zig");
const settings_portal = @import("../session/settings_portal.zig");
const Server = @import("../Server.zig");
const Output = @import("../Output.zig");
+const game = @import("../output/game.zig");
const toast_mod = @import("toast.zig");
const image_mod = @import("image.zig");
const window_rules = @import("config").window_rules;
@@ -173,8 +174,9 @@ pub const Manager = struct {
}
}
- // DND policy: if DND is enabled, suppress toast unless critical (urgency=2) or bypassed
- const suppressed_by_dnd = self.dnd and !dnd_bypass and urgency != 2;
+ // DND policy: if DND is enabled, suppress toast unless critical (urgency=2) or bypassed.
+ // A game where toasts appear counts as DND.
+ const suppressed_by_dnd = (self.dnd or self.gameShown()) and !dnd_bypass and urgency != 2;
const should_show_toast = !muted and !suppressed_by_dnd;
// In-place update for replaces_id
@@ -258,6 +260,14 @@ pub const Manager = struct {
return id;
}
+ /// Whether a game (output/game.zig: the focused window filling the output,
+ /// fullscreen or borderless) is on the output toasts appear on.
+ fn gameShown(self: *Manager) bool {
+ if (!self.server.config.notifications.game_dnd) return false;
+ const output = self.server.getDefaultOutput() orelse return false;
+ return game.window(output) != null;
+ }
+
pub fn themeChanged(self: *Manager) void {
for (self.toasts.items) |toast| {
toast.buildTree() catch continue;
diff --git a/src/notifications_tests.zig b/src/notifications_tests.zig
index a8f0521..cb63a0c 100644
--- a/src/notifications_tests.zig
+++ b/src/notifications_tests.zig
@@ -30,7 +30,7 @@ test "notifications unit: replaces_id, urgency, DND, lock suppression" {
server.locker = null;
server.environ = std.process.Environ.empty;
server.config = undefined;
- server.config.notifications = .{ .dnd = false, .default_timeout_ms = 5000 };
+ server.config.notifications = .{ .dnd = false, .game_dnd = false, .default_timeout_ms = 5000 };
server.config.notification_rules = &.{};
server.ipc = null;
server.icon_service = null;
diff --git a/tests/notifications.py b/tests/notifications.py
index 310f9a8..5d03b57 100644
--- a/tests/notifications.py
+++ b/tests/notifications.py
@@ -10,6 +10,8 @@ import tempfile
import time
from ipc_client import IPCClient, ROOT, spawn_compositor, stop_process
+from desktop_zoom import build_client
+from xwayland_support import wayland_display_name
NAME = "org.freedesktop.Notifications"
PATH = "/org/freedesktop/Notifications"
@@ -312,6 +314,37 @@ dnd_bypass = true
timeout=3.0,
)
+ # A focused fullscreen window (a game) holds normal toasts like
+ # DND; critical ones still show, and leaving fullscreen ends it.
+ print("12b. Testing game_dnd with a fullscreen window...")
+ build_client(tmp_dir)
+ client_env = dict(os.environ, XDG_RUNTIME_DIR=str(tmp_dir),
+ WAYLAND_DISPLAY=wayland_display_name(tmp_dir))
+ client_env.pop("DISPLAY", None)
+ game = subprocess.Popen([str(tmp_dir / "client")], env=client_env,
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ try:
+ window = wait_for(lambda: next(iter(ipc.get_windows()), None), "game window mapped")
+ ipc.focus_window(window["id"])
+ ipc.fullscreen(window["id"])
+ wait_for(lambda: ipc.get_windows()[0]["placement"] == "fullscreen", "window fullscreen")
+ bus_call("Notify", "susssasa{sv}i", "chat_app", 0, "", "Game Chat", "held", 0, 0, 5000)
+ notifs = ipc.get_notifications()
+ assert not notifs["toasts"], notifs["toasts"]
+ assert any(h["summary"] == "Game Chat" for h in notifs["history"]), "held toast not in history"
+ bus_call("Notify", "susssasa{sv}i", "vip_app", 0, "", "Game VIP", "shown", 0, 0, 5000)
+ assert [t["summary"] for t in ipc.get_notifications()["toasts"]] == ["Game VIP"]
+ ipc.fullscreen(window["id"])
+ wait_for(lambda: ipc.get_windows()[0]["placement"] != "fullscreen", "window left fullscreen")
+ bus_call("Notify", "susssasa{sv}i", "chat_app", 0, "", "After Game", "shown", 0, 0, 5000)
+ assert "After Game" in [t["summary"] for t in ipc.get_notifications()["toasts"]]
+ finally:
+ game.terminate()
+ game.wait(timeout=5)
+ ipc.clear_notifications("all")
+ wait_for(lambda: not ipc.get_notifications()["toasts"], "toasts cleared after game_dnd", timeout=3.0)
+ wait_for(lambda: not ipc.get_windows(), "game window closed")
+
# Exercise the actual card and close hit target, plus expiry on an idle output.
print("13. Testing card rendering, pointer dismissal and idle expiry...")
bus_call("Notify", "susssasa{sv}i", "Downloads", 0,