gears.matcher: Add `fallback` rules.

Right now, all rules are additive, they are squashed into one big
array of properties. This is normally fine, but sometime you want
explicit rules for some objects, but also default rules if nothing
matches.

While this can be expressed in the current system by overriding
*all* properties, this require more effort than having "special"
and "fallback" rules.
This commit is contained in:
Emmanuel Lepage Vallee 2021-10-22 15:25:01 -07:00
parent 005c2d61a0
commit 9db62b824c
1 changed files with 14 additions and 1 deletions

View File

@ -324,7 +324,20 @@ function matcher:add_property_setter(name, f)
end
local function default_rules_callback(self, o, props, callbacks, rules)
for _, entry in ipairs(self:matching_rules(o, rules)) do
-- Get all matching rules.
local matches = self:matching_rules(o, rules)
-- Split the main ones from the fallback ones.
local main, fallback = {}, {}
for _, match in ipairs(matches) do
table.insert(match.fallback and fallback or main, match)
end
-- Select which set to use.
matches = #main > 0 and main or fallback
for _, entry in ipairs(matches) do
gtable.crush(props, entry.properties or {})
if entry.callback then