optimize title and menubar redraw

This commit is contained in:
2026-08-29 15:27:31 +02:00
parent b20b3aeb5a
commit 1fff449547
2 changed files with 87 additions and 14 deletions
+32 -14
View File
@@ -183,13 +183,29 @@ fn onTabBar(self: *Window) bool {
return out.state().layout == .tabbed;
}
fn setString(self: *Window, field: *?[]u8, value: ?[*:0]const u8) void {
/// Replace an owned string field, returning whether the value actually
/// changed. Clients re-send strings that have not moved — a terminal animating
/// a spinner in its title re-sets the same text several times a second — and
/// the caller can use the answer to skip the IPC broadcast and the tab bar
/// redraw those no-op updates would otherwise trigger.
fn setString(self: *Window, field: *?[]u8, value: ?[*:0]const u8) bool {
const gpa = self.wm.gpa;
const new: ?[]const u8 = if (value) |v| std.mem.span(v) else null;
const same = if (field.*) |old|
if (new) |n| std.mem.eql(u8, old, n) else false
else
new == null;
if (same) return false;
if (field.*) |old| gpa.free(old);
field.* = null;
if (value) |v| {
field.* = gpa.dupe(u8, std.mem.span(v)) catch null;
if (new) |n| {
// A failed dupe leaves the field null, which compares unequal to the
// next event carrying the same text, so the copy is retried then.
field.* = gpa.dupe(u8, n) catch null;
}
return true;
}
fn onEvent(_: *river.WindowV1, event: river.WindowV1.Event, self: *Window) void {
@@ -227,23 +243,25 @@ fn onEvent(_: *river.WindowV1, event: river.WindowV1.Event, self: *Window) void
},
.app_id => |ev| {
self.setString(&self.app_id, ev.app_id);
self.applyRules();
self.wm.ipcDirty();
if (self.setString(&self.app_id, ev.app_id)) {
self.applyRules();
self.wm.ipcDirty();
}
},
.title => |ev| {
self.setString(&self.title, ev.title);
self.applyRules();
self.wm.ipcDirty();
// The tab bar has this title painted into it, so a window that is
// wearing a tab needs the strip redrawn. Terminals retitle
// themselves constantly, so ask only when it will show.
if (self.onTabBar()) self.wm.needsManage();
if (self.setString(&self.title, ev.title)) {
self.applyRules();
self.wm.ipcDirty();
// The tab bar has this title painted into it, so a window that
// is wearing a tab needs the strip redrawn. Terminals retitle
// themselves constantly, so ask only when it will show.
if (self.onTabBar()) self.wm.needsManage();
}
},
.identifier => |ev| {
self.setString(&self.identifier, ev.identifier);
_ = self.setString(&self.identifier, ev.identifier);
},
.parent => |ev| {