river: make RuleList return deleted items

This commit is contained in:
Doclic 2023-10-19 01:21:52 +02:00
parent ad1e0aa752
commit 206bb2e713
2 changed files with 6 additions and 6 deletions

View File

@ -105,13 +105,13 @@ pub fn ruleDel(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
switch (action) {
.float, .@"no-float" => {
server.config.float_rules.del(.{
_ = server.config.float_rules.del(.{
.app_id_glob = app_id_glob,
.title_glob = title_glob,
});
},
.ssd, .csd => {
server.config.ssd_rules.del(.{
_ = server.config.ssd_rules.del(.{
.app_id_glob = app_id_glob,
.title_glob = title_glob,
});
@ -119,7 +119,7 @@ pub fn ruleDel(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
server.root.applyPending();
},
.tag => {
server.config.tag_rules.del(.{
_ = server.config.tag_rules.del(.{
.app_id_glob = app_id_glob,
.title_glob = title_glob,
});

View File

@ -82,17 +82,17 @@ pub fn RuleList(comptime T: type) type {
});
}
pub fn del(list: *Self, rule: struct { app_id_glob: []const u8, title_glob: []const u8 }) void {
pub fn del(list: *Self, rule: struct { app_id_glob: []const u8, title_glob: []const u8 }) ?T {
for (list.rules.items, 0..) |existing, i| {
if (mem.eql(u8, rule.app_id_glob, existing.app_id_glob) and
mem.eql(u8, rule.title_glob, existing.title_glob))
{
util.gpa.free(existing.app_id_glob);
util.gpa.free(existing.title_glob);
_ = list.rules.orderedRemove(i);
return;
return list.rules.orderedRemove(i).value;
}
}
return null;
}
/// Returns the value of the most specific rule matching the view.