Allow to add group rules to hotkeys_popup default instance

This commit is contained in:
Jonathan 2017-04-03 12:07:30 +07:00 committed by Yauhen Kirylau
parent 63f78c29a4
commit c183588ba1
3 changed files with 50 additions and 2 deletions

View File

@ -0,0 +1,33 @@
local hotkeys_popup = require("awful.hotkeys_popup.widget")
local fire_rule = { class = { "Firefox" } }
for group_name, group_data in pairs({
["Firefox: tabs"] = { color = "#009F00", rule_any = fire_rule }
}) do
hotkeys_popup.add_group_rules(group_name, group_data)
end
local firefox_keys = {
["Firefox: tabs"] = {{
modifiers = { "Mod1" },
keys = {
["1..9"] = "go to tab"
}
}, {
modifiers = { "Ctrl" },
keys = {
t = "new tab",
w = 'close tab',
['Tab'] = "next tab"
}
}, {
modifiers = { "Ctrl", "Shift" },
keys = {
['Tab'] = "previous tab"
}
}}
}
hotkeys_popup.add_hotkeys(firefox_keys)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -17,7 +17,7 @@ for group_name, group_data in pairs({
["VIM: find"] = { color="#65cF9F", rule_any=vim_rule_any },
["VIM: scroll"] = { color="#659FdF", rule_any=vim_rule_any },
}) do
hotkeys_popup.group_rules[group_name] = group_data
hotkeys_popup.add_group_rules(group_name, group_data)
end

View File

@ -534,7 +534,6 @@ function widget.new(args)
end)
end
--- Add hotkey descriptions for third-party applications.
-- @tparam table hotkeys Table with bindings,
-- see `awful.hotkeys_popup.key.vim` as an example.
@ -556,6 +555,13 @@ function widget.new(args)
self:_sort_hotkeys(self._additional_hotkeys)
end
--- Add hotkey group rules for third-party applications.
-- @tparam group hotkeys group name,
-- @tparam data rule data for the group
-- see `awful.hotkeys_popup.key.vim` as an example.
function widget_instance:add_group_rules(group, data)
self.group_rules[group] = data
end
return widget_instance
end
@ -582,6 +588,15 @@ function widget.add_hotkeys(...)
return get_default_widget():add_hotkeys(...)
end
--- Add hotkey group rules for third-party applications
-- (default widget instance will be used).
-- @tparam string hotkeys group name,
-- @tparam table rule data for the group
-- see `awful.hotkeys_popup.key.vim` as an example.
function widget.add_group_rules(...)
return get_default_widget():add_group_rules(...)
end
return widget
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80