2015-09-20 16:42:24 +02:00
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
--- Popup widget which shows current hotkeys and their descriptions.
|
|
|
|
|
--
|
2020-03-06 14:09:29 +01:00
|
|
|
|
-- It's easy to add hotkeys for your favorite application. Below is how to add
|
|
|
|
|
-- hotkeys for firefox to the previously created `hotkeys_popup` in `rc.lua`.
|
|
|
|
|
--
|
|
|
|
|
-- -- Create the rule that we will use to match for the application.
|
|
|
|
|
-- local fire_rule = { class = { "firefox", "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
|
|
|
|
|
--
|
|
|
|
|
-- -- Table with all of our hotkeys
|
|
|
|
|
-- 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)
|
|
|
|
|
--
|
2022-03-21 18:09:49 +01:00
|
|
|
|
--
|
|
|
|
|
-- Example of having different types of hotkey popups:
|
|
|
|
|
--
|
|
|
|
|
-- awful.keyboard.append_global_keybindings({
|
|
|
|
|
-- awful.key({modkey}, "/", function()
|
|
|
|
|
-- hotkeys_popup.show_help()
|
|
|
|
|
-- end, nil, {
|
|
|
|
|
-- description = "show help (all)", group="HELP"
|
|
|
|
|
-- }),
|
|
|
|
|
-- awful.key({"Shift", modkey}, "/", function()
|
|
|
|
|
-- hotkeys_popup.show_help(nil, nil, {show_awesome_keys=false})
|
|
|
|
|
-- end, nil, {
|
|
|
|
|
-- description = "show help for current app", group="HELP"
|
|
|
|
|
-- }),
|
|
|
|
|
-- awful.key({altkey, modkey}, "/", function()
|
|
|
|
|
-- hotkeys_popup.show_help({}, nil, {show_awesome_keys=true})
|
|
|
|
|
-- end, nil, {
|
|
|
|
|
-- description = "show help for awesome only", group="HELP"
|
|
|
|
|
-- })
|
|
|
|
|
-- -- (more hotkeys go here)
|
|
|
|
|
-- })
|
|
|
|
|
--
|
|
|
|
|
--
|
2015-09-20 16:42:24 +02:00
|
|
|
|
-- @author Yauheni Kirylau <yawghen@gmail.com>
|
|
|
|
|
-- @copyright 2014-2015 Yauheni Kirylau
|
2019-06-06 08:44:00 +02:00
|
|
|
|
-- @popupmod awful.hotkeys_popup.widget
|
2015-09-20 16:42:24 +02:00
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local capi = {
|
|
|
|
|
screen = screen,
|
|
|
|
|
client = client,
|
|
|
|
|
}
|
|
|
|
|
local awful = require("awful")
|
2017-03-08 21:18:33 +01:00
|
|
|
|
local gtable = require("gears.table")
|
2017-03-12 00:57:32 +01:00
|
|
|
|
local gstring = require("gears.string")
|
2015-09-20 16:42:24 +02:00
|
|
|
|
local wibox = require("wibox")
|
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
|
local dpi = beautiful.xresources.apply_dpi
|
|
|
|
|
|
2020-01-19 08:36:33 +01:00
|
|
|
|
local matcher = require("gears.matcher")()
|
2015-09-20 16:42:24 +02:00
|
|
|
|
|
|
|
|
|
-- Stripped copy of this module https://github.com/copycat-killer/lain/blob/master/util/markup.lua:
|
|
|
|
|
local markup = {}
|
|
|
|
|
-- Set the font.
|
|
|
|
|
function markup.font(font, text)
|
|
|
|
|
return '<span font="' .. tostring(font) .. '">' .. tostring(text) ..'</span>'
|
|
|
|
|
end
|
|
|
|
|
-- Set the foreground.
|
|
|
|
|
function markup.fg(color, text)
|
|
|
|
|
return '<span foreground="' .. tostring(color) .. '">' .. tostring(text) .. '</span>'
|
|
|
|
|
end
|
|
|
|
|
-- Set the background.
|
|
|
|
|
function markup.bg(color, text)
|
|
|
|
|
return '<span background="' .. tostring(color) .. '">' .. tostring(text) .. '</span>'
|
|
|
|
|
end
|
|
|
|
|
|
2017-02-10 19:50:10 +01:00
|
|
|
|
local function join_plus_sort(modifiers)
|
|
|
|
|
if #modifiers<1 then return "none" end
|
|
|
|
|
table.sort(modifiers)
|
|
|
|
|
return table.concat(modifiers, '+')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function get_screen(s)
|
|
|
|
|
return s and capi.screen[s]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2017-01-17 10:13:26 +01:00
|
|
|
|
local widget = {
|
2016-03-23 01:15:16 +01:00
|
|
|
|
group_rules = {},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
--- Don't show hotkeys without descriptions.
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @tfield boolean widget.hide_without_description
|
|
|
|
|
-- @param boolean
|
2017-01-17 10:13:26 +01:00
|
|
|
|
widget.hide_without_description = true
|
2016-03-23 01:15:16 +01:00
|
|
|
|
|
|
|
|
|
--- Merge hotkey records into one if they have the same modifiers and
|
2020-02-19 02:48:39 +01:00
|
|
|
|
-- description. Records with five or more keys will abbreviate them.
|
2020-02-21 00:07:52 +01:00
|
|
|
|
--
|
|
|
|
|
-- This property only affects hotkey records added via `awful.key` keybindings.
|
|
|
|
|
-- Cheatsheets for external programs are static and will present merged records
|
|
|
|
|
-- regardless of the value of this property.
|
2019-06-08 06:15:59 +02:00
|
|
|
|
-- @tfield boolean widget.merge_duplicates
|
|
|
|
|
-- @param boolean
|
2017-01-17 10:13:26 +01:00
|
|
|
|
widget.merge_duplicates = true
|
|
|
|
|
|
2022-03-21 18:09:49 +01:00
|
|
|
|
--- Labels used for displaying human-readable keynames.
|
|
|
|
|
-- @tfield table widget.labels
|
|
|
|
|
-- @param table
|
|
|
|
|
widget.labels = {
|
|
|
|
|
Control = "Ctrl",
|
|
|
|
|
Mod1 = "Alt",
|
|
|
|
|
ISO_Level3_Shift = "Alt Gr",
|
|
|
|
|
Mod4 = "Super",
|
|
|
|
|
Insert = "Ins",
|
|
|
|
|
Delete = "Del",
|
|
|
|
|
Next = "PgDn",
|
|
|
|
|
Prior = "PgUp",
|
|
|
|
|
Left = "←",
|
|
|
|
|
Up = "↑",
|
|
|
|
|
Right = "→",
|
|
|
|
|
Down = "↓",
|
|
|
|
|
KP_End = "Num1",
|
|
|
|
|
KP_Down = "Num2",
|
|
|
|
|
KP_Next = "Num3",
|
|
|
|
|
KP_Left = "Num4",
|
|
|
|
|
KP_Begin = "Num5",
|
|
|
|
|
KP_Right = "Num6",
|
|
|
|
|
KP_Home = "Num7",
|
|
|
|
|
KP_Up = "Num8",
|
|
|
|
|
KP_Prior = "Num9",
|
|
|
|
|
KP_Insert = "Num0",
|
|
|
|
|
KP_Delete = "Num.",
|
|
|
|
|
KP_Divide = "Num/",
|
|
|
|
|
KP_Multiply = "Num*",
|
|
|
|
|
KP_Subtract = "Num-",
|
|
|
|
|
KP_Add = "Num+",
|
|
|
|
|
KP_Enter = "NumEnter",
|
|
|
|
|
-- Some "obvious" entries are necessary for the Escape sequence
|
|
|
|
|
-- and whitespace characters:
|
|
|
|
|
Escape = "Esc",
|
|
|
|
|
Tab = "Tab",
|
|
|
|
|
space = "Space",
|
|
|
|
|
Return = "Enter",
|
|
|
|
|
-- Dead keys aren't distinct from non-dead keys because no sane
|
|
|
|
|
-- layout should have both of the same kind:
|
|
|
|
|
dead_acute = "´",
|
|
|
|
|
dead_circumflex = "^",
|
|
|
|
|
dead_grave = "`",
|
|
|
|
|
-- Basic multimedia keys:
|
|
|
|
|
XF86MonBrightnessUp = "🔆+",
|
|
|
|
|
XF86MonBrightnessDown = "🔅-",
|
|
|
|
|
XF86AudioRaiseVolume = "Vol+",
|
|
|
|
|
XF86AudioLowerVolume = "Vol-",
|
|
|
|
|
XF86AudioMute = "Mute",
|
|
|
|
|
XF86AudioPlay = "⏯",
|
|
|
|
|
XF86AudioPrev = "⏮",
|
|
|
|
|
XF86AudioNext = "⏭",
|
|
|
|
|
}
|
2017-02-10 19:50:10 +01:00
|
|
|
|
--- Hotkeys widget background color.
|
|
|
|
|
-- @beautiful beautiful.hotkeys_bg
|
|
|
|
|
-- @tparam color hotkeys_bg
|
|
|
|
|
|
|
|
|
|
--- Hotkeys widget foreground color.
|
|
|
|
|
-- @beautiful beautiful.hotkeys_fg
|
|
|
|
|
-- @tparam color hotkeys_fg
|
|
|
|
|
|
|
|
|
|
--- Hotkeys widget border width.
|
|
|
|
|
-- @beautiful beautiful.hotkeys_border_width
|
|
|
|
|
-- @tparam int hotkeys_border_width
|
|
|
|
|
|
|
|
|
|
--- Hotkeys widget border color.
|
|
|
|
|
-- @beautiful beautiful.hotkeys_border_color
|
|
|
|
|
-- @tparam color hotkeys_border_color
|
|
|
|
|
|
|
|
|
|
--- Hotkeys widget shape.
|
|
|
|
|
-- @beautiful beautiful.hotkeys_shape
|
|
|
|
|
-- @tparam[opt] gears.shape hotkeys_shape
|
|
|
|
|
-- @see gears.shape
|
|
|
|
|
|
|
|
|
|
--- Foreground color used for hotkey modifiers (Ctrl, Alt, Super, etc).
|
|
|
|
|
-- @beautiful beautiful.hotkeys_modifiers_fg
|
|
|
|
|
-- @tparam color hotkeys_modifiers_fg
|
|
|
|
|
|
|
|
|
|
--- Background color used for miscellaneous labels of hotkeys widget.
|
|
|
|
|
-- @beautiful beautiful.hotkeys_label_bg
|
|
|
|
|
-- @tparam color hotkeys_label_bg
|
|
|
|
|
|
|
|
|
|
--- Foreground color used for hotkey groups and other labels.
|
|
|
|
|
-- @beautiful beautiful.hotkeys_label_fg
|
|
|
|
|
-- @tparam color hotkeys_label_fg
|
|
|
|
|
|
|
|
|
|
--- Main hotkeys widget font.
|
|
|
|
|
-- @beautiful beautiful.hotkeys_font
|
|
|
|
|
-- @tparam string|lgi.Pango.FontDescription hotkeys_font
|
|
|
|
|
|
|
|
|
|
--- Font used for hotkeys' descriptions.
|
|
|
|
|
-- @beautiful beautiful.hotkeys_description_font
|
|
|
|
|
-- @tparam string|lgi.Pango.FontDescription hotkeys_description_font
|
|
|
|
|
|
|
|
|
|
--- Margin between hotkeys groups.
|
|
|
|
|
-- @beautiful beautiful.hotkeys_group_margin
|
|
|
|
|
-- @tparam int hotkeys_group_margin
|
|
|
|
|
|
|
|
|
|
|
2017-01-17 10:13:26 +01:00
|
|
|
|
--- Create an instance of widget with hotkeys help.
|
2017-02-10 19:50:10 +01:00
|
|
|
|
-- @tparam[opt] table args Configuration options for the widget.
|
|
|
|
|
-- @tparam[opt] boolean args.hide_without_description Don't show hotkeys without descriptions.
|
|
|
|
|
-- @tparam[opt] boolean args.merge_duplicates Merge hotkey records into one if
|
2020-02-19 02:48:39 +01:00
|
|
|
|
-- they have the same modifiers and description. Records with five keys or more
|
|
|
|
|
-- will abbreviate them.
|
2017-02-10 19:50:10 +01:00
|
|
|
|
-- @tparam[opt] int args.width Widget width.
|
|
|
|
|
-- @tparam[opt] int args.height Widget height.
|
|
|
|
|
-- @tparam[opt] color args.bg Widget background color.
|
|
|
|
|
-- @tparam[opt] color args.fg Widget foreground color.
|
|
|
|
|
-- @tparam[opt] int args.border_width Border width.
|
|
|
|
|
-- @tparam[opt] color args.border_color Border color.
|
|
|
|
|
-- @tparam[opt] gears.shape args.shape Widget shape.
|
|
|
|
|
-- @tparam[opt] string|lgi.Pango.FontDescription args.font Main widget font.
|
|
|
|
|
-- @tparam[opt] string|lgi.Pango.FontDescription args.description_font Font used for hotkeys' descriptions.
|
|
|
|
|
-- @tparam[opt] color args.modifiers_fg Foreground color used for hotkey
|
|
|
|
|
-- modifiers (Ctrl, Alt, Super, etc).
|
|
|
|
|
-- @tparam[opt] color args.label_bg Background color used for miscellaneous labels.
|
|
|
|
|
-- @tparam[opt] color args.label_fg Foreground color used for group and other
|
|
|
|
|
-- labels.
|
|
|
|
|
-- @tparam[opt] int args.group_margin Margin between hotkeys groups.
|
|
|
|
|
-- @tparam[opt] table args.labels Labels used for displaying human-readable keynames.
|
|
|
|
|
-- @tparam[opt] table args.group_rules Rules for showing 3rd-party hotkeys. @see `awful.hotkeys_popup.keys.vim`.
|
|
|
|
|
-- @return Widget instance.
|
2019-06-07 20:59:34 +02:00
|
|
|
|
-- @constructorfct awful.widget.hotkeys_popup.widget.new
|
2017-02-10 19:50:10 +01:00
|
|
|
|
function widget.new(args)
|
|
|
|
|
args = args or {}
|
2017-01-17 10:13:26 +01:00
|
|
|
|
local widget_instance = {
|
2017-02-10 19:50:10 +01:00
|
|
|
|
hide_without_description = (
|
|
|
|
|
args.hide_without_description == nil
|
|
|
|
|
) and widget.hide_without_description or args.hide_without_description,
|
|
|
|
|
merge_duplicates = (
|
|
|
|
|
args.merge_duplicates == nil
|
|
|
|
|
) and widget.merge_duplicates or args.merge_duplicates,
|
2017-03-08 21:18:33 +01:00
|
|
|
|
group_rules = args.group_rules or gtable.clone(widget.group_rules),
|
2020-02-27 01:10:33 +01:00
|
|
|
|
-- For every key in every `awful.key` binding, the first non-nil result
|
|
|
|
|
-- in this lists is chosen as a human-readable name:
|
|
|
|
|
-- * the value corresponding to its keysym in this table;
|
2020-03-08 19:03:36 +01:00
|
|
|
|
-- * the UTF-8 representation as decided by awful.keyboard.get_key_name();
|
2020-02-27 01:10:33 +01:00
|
|
|
|
-- * the keysym name itself;
|
|
|
|
|
-- If no match is found, the key name will not be translated, and will
|
|
|
|
|
-- be presented to the user as-is. (This is useful for cheatsheets for
|
|
|
|
|
-- external programs.)
|
2022-03-21 18:09:49 +01:00
|
|
|
|
labels = args.labels or widget.labels,
|
2017-02-10 19:50:10 +01:00
|
|
|
|
_additional_hotkeys = {},
|
|
|
|
|
_cached_wiboxes = {},
|
2018-10-17 04:59:11 +02:00
|
|
|
|
_cached_awful_keys = {},
|
2017-02-10 19:50:10 +01:00
|
|
|
|
_colors_counter = {},
|
|
|
|
|
_group_list = {},
|
|
|
|
|
_widget_settings_loaded = false,
|
2020-02-19 02:48:39 +01:00
|
|
|
|
_keygroups = {},
|
2017-01-17 10:13:26 +01:00
|
|
|
|
}
|
2020-02-19 02:48:39 +01:00
|
|
|
|
for k, v in pairs(awful.key.keygroups) do
|
|
|
|
|
widget_instance._keygroups[k] = {}
|
|
|
|
|
for k2, v2 in pairs(v) do
|
2020-03-08 19:03:36 +01:00
|
|
|
|
local keysym, keyprint = awful.keyboard.get_key_name(v2[1])
|
2020-02-27 01:10:33 +01:00
|
|
|
|
widget_instance._keygroups[k][k2] =
|
|
|
|
|
widget_instance.labels[keysym] or keyprint or keysym or v2[1]
|
2020-02-19 02:48:39 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
|
2017-02-10 19:50:10 +01:00
|
|
|
|
|
|
|
|
|
function widget_instance:_load_widget_settings()
|
|
|
|
|
if self._widget_settings_loaded then return end
|
|
|
|
|
self.width = args.width or dpi(1200)
|
|
|
|
|
self.height = args.height or dpi(800)
|
|
|
|
|
self.bg = args.bg or
|
|
|
|
|
beautiful.hotkeys_bg or beautiful.bg_normal
|
|
|
|
|
self.fg = args.fg or
|
|
|
|
|
beautiful.hotkeys_fg or beautiful.fg_normal
|
|
|
|
|
self.border_width = args.border_width or
|
|
|
|
|
beautiful.hotkeys_border_width or beautiful.border_width
|
|
|
|
|
self.border_color = args.border_color or
|
|
|
|
|
beautiful.hotkeys_border_color or self.fg
|
|
|
|
|
self.shape = args.shape or beautiful.hotkeys_shape
|
|
|
|
|
self.modifiers_fg = args.modifiers_fg or
|
|
|
|
|
beautiful.hotkeys_modifiers_fg or beautiful.bg_minimize or "#555555"
|
|
|
|
|
self.label_bg = args.label_bg or
|
|
|
|
|
beautiful.hotkeys_label_bg or self.fg
|
|
|
|
|
self.label_fg = args.label_fg or
|
|
|
|
|
beautiful.hotkeys_label_fg or self.bg
|
|
|
|
|
self.opacity = args.opacity or
|
|
|
|
|
beautiful.hotkeys_opacity or 1
|
|
|
|
|
self.font = args.font or
|
|
|
|
|
beautiful.hotkeys_font or "Monospace Bold 9"
|
|
|
|
|
self.description_font = args.description_font or
|
|
|
|
|
beautiful.hotkeys_description_font or "Monospace 8"
|
|
|
|
|
self.group_margin = args.group_margin or
|
|
|
|
|
beautiful.hotkeys_group_margin or dpi(6)
|
|
|
|
|
self.label_colors = beautiful.xresources.get_current_theme()
|
|
|
|
|
self._widget_settings_loaded = true
|
|
|
|
|
end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
|
|
|
|
|
|
2017-02-10 19:50:10 +01:00
|
|
|
|
function widget_instance:_get_next_color(id)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
id = id or "default"
|
2017-02-10 19:50:10 +01:00
|
|
|
|
if self._colors_counter[id] then
|
|
|
|
|
self._colors_counter[id] = math.fmod(self._colors_counter[id] + 1, 15) + 1
|
2017-01-17 10:13:26 +01:00
|
|
|
|
else
|
2017-02-10 19:50:10 +01:00
|
|
|
|
self._colors_counter[id] = 1
|
2017-01-17 10:13:26 +01:00
|
|
|
|
end
|
2017-02-10 19:50:10 +01:00
|
|
|
|
return self.label_colors["color"..tostring(self._colors_counter[id], 15)]
|
2015-09-20 16:42:24 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2017-02-10 19:50:10 +01:00
|
|
|
|
function widget_instance:_add_hotkey(key, data, target)
|
|
|
|
|
if self.hide_without_description and not data.description then return end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
|
2017-01-17 10:13:26 +01:00
|
|
|
|
local readable_mods = {}
|
|
|
|
|
for _, mod in ipairs(data.mod) do
|
2017-02-10 19:50:10 +01:00
|
|
|
|
table.insert(readable_mods, self.labels[mod] or mod)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
end
|
|
|
|
|
local joined_mods = join_plus_sort(readable_mods)
|
|
|
|
|
|
|
|
|
|
local group = data.group or "none"
|
2017-02-10 19:50:10 +01:00
|
|
|
|
self._group_list[group] = true
|
2017-01-17 10:13:26 +01:00
|
|
|
|
if not target[group] then target[group] = {} end
|
2020-03-08 19:03:36 +01:00
|
|
|
|
local keysym, keyprint = awful.keyboard.get_key_name(key)
|
2020-02-27 01:10:33 +01:00
|
|
|
|
local keylabel = self.labels[keysym] or keyprint or keysym or key
|
2017-01-17 10:13:26 +01:00
|
|
|
|
local new_key = {
|
2020-02-27 01:10:33 +01:00
|
|
|
|
key = keylabel,
|
|
|
|
|
keylist = {keylabel},
|
2017-01-17 10:13:26 +01:00
|
|
|
|
mod = joined_mods,
|
|
|
|
|
description = data.description
|
|
|
|
|
}
|
|
|
|
|
local index = data.description or "none" -- or use its hash?
|
|
|
|
|
if not target[group][index] then
|
|
|
|
|
target[group][index] = new_key
|
2016-02-04 12:55:54 +01:00
|
|
|
|
else
|
2017-02-10 19:50:10 +01:00
|
|
|
|
if self.merge_duplicates and joined_mods == target[group][index].mod then
|
2017-01-17 10:13:26 +01:00
|
|
|
|
target[group][index].key = target[group][index].key .. "/" .. new_key.key
|
2020-02-19 02:48:39 +01:00
|
|
|
|
table.insert(target[group][index].keylist, new_key.key)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
else
|
|
|
|
|
while target[group][index] do
|
|
|
|
|
index = index .. " "
|
|
|
|
|
end
|
|
|
|
|
target[group][index] = new_key
|
2016-02-04 12:55:54 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
|
|
|
|
|
|
2017-02-10 19:50:10 +01:00
|
|
|
|
function widget_instance:_sort_hotkeys(target)
|
|
|
|
|
for group, _ in pairs(self._group_list) do
|
2017-01-17 10:13:26 +01:00
|
|
|
|
if target[group] then
|
|
|
|
|
local sorted_table = {}
|
|
|
|
|
for _, key in pairs(target[group]) do
|
|
|
|
|
table.insert(sorted_table, key)
|
|
|
|
|
end
|
|
|
|
|
table.sort(
|
|
|
|
|
sorted_table,
|
2019-11-18 08:03:51 +01:00
|
|
|
|
function(a,b)
|
|
|
|
|
local k1, k2 = a.key or a.keys[1][1], b.key or b.keys[1][1]
|
|
|
|
|
return (a.mod or '')..k1<(b.mod or '')..k2 end
|
2017-01-17 10:13:26 +01:00
|
|
|
|
)
|
|
|
|
|
target[group] = sorted_table
|
2016-02-04 12:55:54 +01:00
|
|
|
|
end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2020-02-19 02:48:39 +01:00
|
|
|
|
function widget_instance:_abbreviate_awful_keys()
|
|
|
|
|
-- This method is intended to abbreviate the keys of a merged entry (not
|
|
|
|
|
-- the modifiers) if and only if the entry consists of five or more
|
|
|
|
|
-- correlative keys from the same keygroup.
|
|
|
|
|
--
|
|
|
|
|
-- For simplicity, it checks only the first keygroup which contains the
|
|
|
|
|
-- first key. If any of the keys in the merged entry is not in this
|
|
|
|
|
-- keygroup, or there are any gaps between the keys (e.g. the entry
|
|
|
|
|
-- contains the 2nd, 3rd, 5th, 6th, and 7th key in
|
|
|
|
|
-- awful.key.keygroups.numrow, but not the 4th) this method does not try
|
|
|
|
|
-- to abbreviate the entry.
|
|
|
|
|
--
|
|
|
|
|
-- Cheatsheets for external programs are abbreviated by hand where
|
|
|
|
|
-- applicable: they do not need this method.
|
|
|
|
|
for _, keys in pairs(self._cached_awful_keys) do
|
|
|
|
|
for _, params in pairs(keys) do
|
|
|
|
|
if #params.keylist > 4 then
|
|
|
|
|
-- assuming here keygroups will never overlap;
|
|
|
|
|
-- if they ever do, another for loop will be necessary:
|
|
|
|
|
local keygroup = gtable.find_first_key(self._keygroups, function(_, v)
|
|
|
|
|
return not not gtable.hasitem(v, params.keylist[1])
|
|
|
|
|
end)
|
|
|
|
|
local first, last, count, tally = nil, nil, 0, {}
|
|
|
|
|
for _, k in ipairs(params.keylist) do
|
|
|
|
|
local i = gtable.hasitem(self._keygroups[keygroup], k)
|
|
|
|
|
if i and not tally[i] then
|
|
|
|
|
tally[i] = k
|
|
|
|
|
if (not first) or (i < first) then first = i end
|
|
|
|
|
if (not last) or (i > last) then last = i end
|
|
|
|
|
count = count + 1
|
|
|
|
|
elseif not i then
|
|
|
|
|
count = 0
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
-- this conditional can only be true if there are more than
|
|
|
|
|
-- four actual keys (discounting duplicates) and ALL of
|
|
|
|
|
-- these keys can be found one after another in a keygroup:
|
|
|
|
|
if count > 4 and last - first + 1 == count then
|
|
|
|
|
params.key = tally[first] .. "…" .. tally[last]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2017-02-10 19:50:10 +01:00
|
|
|
|
function widget_instance:_import_awful_keys()
|
2018-10-17 04:59:11 +02:00
|
|
|
|
if next(self._cached_awful_keys) then
|
2017-01-17 10:13:26 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
for _, data in pairs(awful.key.hotkeys) do
|
2019-11-18 08:03:51 +01:00
|
|
|
|
for _, key_pair in ipairs(data.keys) do
|
|
|
|
|
self:_add_hotkey(key_pair[1], data, self._cached_awful_keys)
|
|
|
|
|
end
|
2017-01-17 10:13:26 +01:00
|
|
|
|
end
|
2017-02-10 19:50:10 +01:00
|
|
|
|
self:_sort_hotkeys(self._cached_awful_keys)
|
2020-02-19 02:48:39 +01:00
|
|
|
|
if self.merge_duplicates then
|
|
|
|
|
self:_abbreviate_awful_keys()
|
|
|
|
|
end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2017-02-10 19:50:10 +01:00
|
|
|
|
function widget_instance:_group_label(group, color)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
local textbox = wibox.widget.textbox(
|
2017-02-10 19:50:10 +01:00
|
|
|
|
markup.font(self.font,
|
2017-01-17 10:13:26 +01:00
|
|
|
|
markup.bg(
|
2017-02-10 19:50:10 +01:00
|
|
|
|
color or (self.group_rules[group] and
|
|
|
|
|
self.group_rules[group].color or self:_get_next_color("group_title")
|
2017-01-17 10:13:26 +01:00
|
|
|
|
),
|
2017-02-10 19:50:10 +01:00
|
|
|
|
markup.fg(self.label_fg, " "..group.." ")
|
2017-01-17 10:13:26 +01:00
|
|
|
|
)
|
2015-09-20 16:42:24 +02:00
|
|
|
|
)
|
|
|
|
|
)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
local margin = wibox.container.margin()
|
|
|
|
|
margin:set_widget(textbox)
|
2017-02-10 19:50:10 +01:00
|
|
|
|
margin:set_top(self.group_margin)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
return margin
|
|
|
|
|
end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
|
2019-01-01 21:30:33 +01:00
|
|
|
|
function widget_instance:_create_group_columns(column_layouts, group, keys, s, wibox_height)
|
2020-09-03 04:20:05 +02:00
|
|
|
|
local line_height = math.max(
|
|
|
|
|
beautiful.get_font_height(self.font),
|
|
|
|
|
beautiful.get_font_height(self.description_font)
|
|
|
|
|
)
|
2019-01-01 21:30:33 +01:00
|
|
|
|
local group_label_height = line_height + self.group_margin
|
|
|
|
|
-- -1 for possible pagination:
|
|
|
|
|
local max_height_px = wibox_height - group_label_height
|
|
|
|
|
|
|
|
|
|
local joined_descriptions = ""
|
|
|
|
|
for i, key in ipairs(keys) do
|
|
|
|
|
joined_descriptions = joined_descriptions .. key.description .. (i~=#keys and "\n" or "")
|
|
|
|
|
end
|
|
|
|
|
-- +1 for group label:
|
|
|
|
|
local items_height = gstring.linecount(joined_descriptions) * line_height + group_label_height
|
|
|
|
|
local current_column
|
|
|
|
|
local available_height_px = max_height_px
|
|
|
|
|
local add_new_column = true
|
|
|
|
|
for i, column in ipairs(column_layouts) do
|
|
|
|
|
if ((column.height_px + items_height) < max_height_px) or
|
|
|
|
|
(i == #column_layouts and column.height_px < max_height_px / 2)
|
|
|
|
|
then
|
|
|
|
|
current_column = column
|
|
|
|
|
add_new_column = false
|
|
|
|
|
available_height_px = max_height_px - current_column.height_px
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
local overlap_leftovers
|
|
|
|
|
if items_height > available_height_px then
|
|
|
|
|
local new_keys = {}
|
|
|
|
|
overlap_leftovers = {}
|
|
|
|
|
-- +1 for group title and +1 for possible hyphen (v):
|
|
|
|
|
local available_height_items = (available_height_px - group_label_height*2) / line_height
|
|
|
|
|
for i=1,#keys do
|
|
|
|
|
table.insert(((i<available_height_items) and new_keys or overlap_leftovers), keys[i])
|
|
|
|
|
end
|
|
|
|
|
keys = new_keys
|
2021-04-23 07:33:22 +02:00
|
|
|
|
table.insert(keys, {key="▽", description=""})
|
2019-01-01 21:30:33 +01:00
|
|
|
|
end
|
|
|
|
|
if not current_column then
|
|
|
|
|
current_column = {layout=wibox.layout.fixed.vertical()}
|
|
|
|
|
end
|
|
|
|
|
current_column.layout:add(self:_group_label(group))
|
|
|
|
|
|
|
|
|
|
local function insert_keys(_keys, _add_new_column)
|
|
|
|
|
local max_label_width = 0
|
|
|
|
|
local joined_labels = ""
|
|
|
|
|
for i, key in ipairs(_keys) do
|
|
|
|
|
local modifiers = key.mod
|
|
|
|
|
if not modifiers or modifiers == "none" then
|
|
|
|
|
modifiers = ""
|
|
|
|
|
else
|
|
|
|
|
modifiers = markup.fg(self.modifiers_fg, modifiers.."+")
|
|
|
|
|
end
|
2020-09-26 04:43:12 +02:00
|
|
|
|
local key_label = ""
|
|
|
|
|
if key.keylist and #key.keylist > 1 then
|
|
|
|
|
for each_key_idx, each_key in ipairs(key.keylist) do
|
2021-04-23 07:33:22 +02:00
|
|
|
|
key_label = key_label .. gstring.xml_escape(each_key)
|
2020-09-26 04:43:12 +02:00
|
|
|
|
if each_key_idx ~= #key.keylist then
|
|
|
|
|
key_label = key_label .. markup.fg(self.modifiers_fg, '/')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elseif key.key then
|
2021-04-23 07:33:22 +02:00
|
|
|
|
key_label = gstring.xml_escape(key.key)
|
2020-09-26 04:43:12 +02:00
|
|
|
|
end
|
2019-01-01 21:30:33 +01:00
|
|
|
|
local rendered_hotkey = markup.font(self.font,
|
2020-09-26 04:43:12 +02:00
|
|
|
|
modifiers .. key_label .. " "
|
2019-01-01 21:30:33 +01:00
|
|
|
|
) .. markup.font(self.description_font,
|
|
|
|
|
key.description or ""
|
|
|
|
|
)
|
2020-09-03 04:07:53 +02:00
|
|
|
|
local label_width = wibox.widget.textbox.get_markup_geometry(rendered_hotkey, s).width
|
|
|
|
|
if label_width > max_label_width then
|
|
|
|
|
max_label_width = label_width
|
2019-01-01 21:30:33 +01:00
|
|
|
|
end
|
|
|
|
|
joined_labels = joined_labels .. rendered_hotkey .. (i~=#_keys and "\n" or "")
|
|
|
|
|
end
|
|
|
|
|
current_column.layout:add(wibox.widget.textbox(joined_labels))
|
2020-09-03 04:07:53 +02:00
|
|
|
|
local max_width = max_label_width + self.group_margin
|
|
|
|
|
if not current_column.max_width or (max_width > current_column.max_width) then
|
2019-01-01 21:30:33 +01:00
|
|
|
|
current_column.max_width = max_width
|
|
|
|
|
end
|
|
|
|
|
-- +1 for group label:
|
|
|
|
|
current_column.height_px = (current_column.height_px or 0) +
|
|
|
|
|
gstring.linecount(joined_labels)*line_height + group_label_height
|
|
|
|
|
if _add_new_column then
|
|
|
|
|
table.insert(column_layouts, current_column)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
insert_keys(keys, add_new_column)
|
|
|
|
|
if overlap_leftovers then
|
|
|
|
|
current_column = {layout=wibox.layout.fixed.vertical()}
|
|
|
|
|
insert_keys(overlap_leftovers, true)
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-09-11 08:07:00 +02:00
|
|
|
|
|
2018-10-17 04:59:11 +02:00
|
|
|
|
function widget_instance:_create_wibox(s, available_groups, show_awesome_keys)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
s = get_screen(s)
|
|
|
|
|
local wa = s.workarea
|
2019-01-01 21:30:33 +01:00
|
|
|
|
local wibox_height = (self.height < wa.height) and self.height or
|
2017-02-10 19:50:10 +01:00
|
|
|
|
(wa.height - self.border_width * 2)
|
2019-01-01 21:30:33 +01:00
|
|
|
|
local wibox_width = (self.width < wa.width) and self.width or
|
2017-02-10 19:50:10 +01:00
|
|
|
|
(wa.width - self.border_width * 2)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
|
|
|
|
|
-- arrange hotkey groups into columns
|
|
|
|
|
local column_layouts = {}
|
|
|
|
|
for _, group in ipairs(available_groups) do
|
2018-10-17 04:59:11 +02:00
|
|
|
|
local keys = gtable.join(
|
|
|
|
|
show_awesome_keys and self._cached_awful_keys[group] or nil,
|
|
|
|
|
self._additional_hotkeys[group]
|
|
|
|
|
)
|
2019-01-01 21:30:33 +01:00
|
|
|
|
if #keys > 0 then
|
|
|
|
|
self:_create_group_columns(column_layouts, group, keys, s, wibox_height)
|
2015-09-20 16:42:24 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-01-17 10:13:26 +01:00
|
|
|
|
-- arrange columns into pages
|
2019-01-01 21:30:33 +01:00
|
|
|
|
local available_width_px = wibox_width
|
2017-01-17 10:13:26 +01:00
|
|
|
|
local pages = {}
|
|
|
|
|
local columns = wibox.layout.fixed.horizontal()
|
|
|
|
|
local previous_page_last_layout
|
|
|
|
|
for _, item in ipairs(column_layouts) do
|
|
|
|
|
if item.max_width > available_width_px then
|
|
|
|
|
previous_page_last_layout:add(
|
2017-02-10 19:50:10 +01:00
|
|
|
|
self:_group_label("PgDn - Next Page", self.label_bg)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
)
|
|
|
|
|
table.insert(pages, columns)
|
|
|
|
|
columns = wibox.layout.fixed.horizontal()
|
2019-01-01 21:30:33 +01:00
|
|
|
|
available_width_px = wibox_width - item.max_width
|
2017-01-17 10:13:26 +01:00
|
|
|
|
item.layout:insert(
|
2017-02-10 19:50:10 +01:00
|
|
|
|
1, self:_group_label("PgUp - Prev Page", self.label_bg)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
available_width_px = available_width_px - item.max_width
|
|
|
|
|
end
|
|
|
|
|
local column_margin = wibox.container.margin()
|
|
|
|
|
column_margin:set_widget(item.layout)
|
2017-02-10 19:50:10 +01:00
|
|
|
|
column_margin:set_left(self.group_margin)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
columns:add(column_margin)
|
|
|
|
|
previous_page_last_layout = item.layout
|
2015-09-20 16:42:24 +02:00
|
|
|
|
end
|
2017-01-17 10:13:26 +01:00
|
|
|
|
table.insert(pages, columns)
|
|
|
|
|
|
2020-03-05 15:37:56 +01:00
|
|
|
|
-- Function to place the widget in the center and account for the
|
|
|
|
|
-- workarea. This will be called in the placement field of the
|
|
|
|
|
-- awful.popup constructor.
|
|
|
|
|
local place_func = function(c)
|
|
|
|
|
awful.placement.centered(c, {honor_workarea = true})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Construct the popup with the widget
|
|
|
|
|
local mypopup = awful.popup {
|
|
|
|
|
widget = pages[1],
|
2017-01-17 10:13:26 +01:00
|
|
|
|
ontop = true,
|
2017-02-10 19:50:10 +01:00
|
|
|
|
bg=self.bg,
|
|
|
|
|
fg=self.fg,
|
|
|
|
|
opacity = self.opacity,
|
|
|
|
|
border_width = self.border_width,
|
|
|
|
|
border_color = self.border_color,
|
|
|
|
|
shape = self.shape,
|
2020-03-05 15:37:56 +01:00
|
|
|
|
placement = place_func,
|
|
|
|
|
minimum_width = wibox_width,
|
|
|
|
|
minimum_height = wibox_height,
|
2020-09-09 07:10:21 +02:00
|
|
|
|
screen = s,
|
2020-03-05 15:37:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-17 16:27:09 +01:00
|
|
|
|
local widget_obj = {
|
|
|
|
|
current_page = 1,
|
2020-03-05 15:37:56 +01:00
|
|
|
|
popup = mypopup,
|
2018-12-17 16:27:09 +01:00
|
|
|
|
}
|
2020-03-05 15:37:56 +01:00
|
|
|
|
|
|
|
|
|
-- Set up the mouse buttons to hide the popup
|
|
|
|
|
-- Any keybinding except what the keygrabber wants wil hide the popup
|
|
|
|
|
-- too
|
|
|
|
|
mypopup.buttons = {
|
2018-12-28 09:06:03 +01:00
|
|
|
|
awful.button({ }, 1, function () widget_obj:hide() end),
|
|
|
|
|
awful.button({ }, 3, function () widget_obj:hide() end)
|
|
|
|
|
}
|
2017-01-17 10:13:26 +01:00
|
|
|
|
|
2017-02-10 19:50:10 +01:00
|
|
|
|
function widget_obj.page_next(_self)
|
|
|
|
|
if _self.current_page == #pages then return end
|
|
|
|
|
_self.current_page = _self.current_page + 1
|
2020-03-05 15:37:56 +01:00
|
|
|
|
_self.popup:set_widget(pages[_self.current_page])
|
2017-01-17 10:13:26 +01:00
|
|
|
|
end
|
2017-02-10 19:50:10 +01:00
|
|
|
|
function widget_obj.page_prev(_self)
|
|
|
|
|
if _self.current_page == 1 then return end
|
|
|
|
|
_self.current_page = _self.current_page - 1
|
2020-03-05 15:37:56 +01:00
|
|
|
|
_self.popup:set_widget(pages[_self.current_page])
|
2017-01-17 10:13:26 +01:00
|
|
|
|
end
|
2017-02-10 19:50:10 +01:00
|
|
|
|
function widget_obj.show(_self)
|
2020-03-05 15:37:56 +01:00
|
|
|
|
_self.popup.visible = true
|
2017-01-17 10:13:26 +01:00
|
|
|
|
end
|
2017-02-10 19:50:10 +01:00
|
|
|
|
function widget_obj.hide(_self)
|
2020-03-05 15:37:56 +01:00
|
|
|
|
_self.popup.visible = false
|
2018-12-17 16:27:09 +01:00
|
|
|
|
if _self.keygrabber then
|
|
|
|
|
awful.keygrabber.stop(_self.keygrabber)
|
|
|
|
|
end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-01-17 10:13:26 +01:00
|
|
|
|
return widget_obj
|
|
|
|
|
end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
|
|
|
|
|
|
2017-01-17 10:13:26 +01:00
|
|
|
|
--- Show popup with hotkeys help.
|
|
|
|
|
-- @tparam[opt] client c Client.
|
|
|
|
|
-- @tparam[opt] screen s Screen.
|
2018-10-17 04:59:11 +02:00
|
|
|
|
-- @tparam[opt] table show_args Additional arguments.
|
|
|
|
|
-- @tparam[opt=true] boolean show_args.show_awesome_keys Show AwesomeWM hotkeys.
|
|
|
|
|
-- When set to `false` only app-specific hotkeys will be shown.
|
2019-06-08 01:08:05 +02:00
|
|
|
|
-- @method show_help
|
2018-10-17 04:59:11 +02:00
|
|
|
|
function widget_instance:show_help(c, s, show_args)
|
|
|
|
|
show_args = show_args or {}
|
|
|
|
|
local show_awesome_keys = show_args.show_awesome_keys ~= false
|
|
|
|
|
|
2017-02-10 19:50:10 +01:00
|
|
|
|
self:_import_awful_keys()
|
|
|
|
|
self:_load_widget_settings()
|
|
|
|
|
|
2017-01-17 10:13:26 +01:00
|
|
|
|
c = c or capi.client.focus
|
|
|
|
|
s = s or (c and c.screen or awful.screen.focused())
|
|
|
|
|
|
|
|
|
|
local available_groups = {}
|
2017-02-10 19:50:10 +01:00
|
|
|
|
for group, _ in pairs(self._group_list) do
|
2017-01-17 10:13:26 +01:00
|
|
|
|
local need_match
|
2017-02-10 19:50:10 +01:00
|
|
|
|
for group_name, data in pairs(self.group_rules) do
|
2017-01-17 10:13:26 +01:00
|
|
|
|
if group_name==group and (
|
|
|
|
|
data.rule or data.rule_any or data.except or data.except_any
|
|
|
|
|
) then
|
2020-01-19 08:36:33 +01:00
|
|
|
|
if not c or not matcher:matches_rule(c, {
|
2017-01-17 10:13:26 +01:00
|
|
|
|
rule=data.rule,
|
|
|
|
|
rule_any=data.rule_any,
|
|
|
|
|
except=data.except,
|
|
|
|
|
except_any=data.except_any
|
|
|
|
|
}) then
|
|
|
|
|
need_match = true
|
|
|
|
|
break
|
|
|
|
|
end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-01-17 10:13:26 +01:00
|
|
|
|
if not need_match then table.insert(available_groups, group) end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
end
|
|
|
|
|
|
2018-10-17 04:59:11 +02:00
|
|
|
|
local joined_groups = join_plus_sort(available_groups)..tostring(show_awesome_keys)
|
2017-02-10 19:50:10 +01:00
|
|
|
|
if not self._cached_wiboxes[s] then
|
|
|
|
|
self._cached_wiboxes[s] = {}
|
2015-09-20 16:42:24 +02:00
|
|
|
|
end
|
2017-02-10 19:50:10 +01:00
|
|
|
|
if not self._cached_wiboxes[s][joined_groups] then
|
2018-10-17 04:59:11 +02:00
|
|
|
|
self._cached_wiboxes[s][joined_groups] = self:_create_wibox(s, available_groups, show_awesome_keys)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
end
|
2017-02-10 19:50:10 +01:00
|
|
|
|
local help_wibox = self._cached_wiboxes[s][joined_groups]
|
2017-01-17 10:13:26 +01:00
|
|
|
|
help_wibox:show()
|
|
|
|
|
|
2018-12-17 16:27:09 +01:00
|
|
|
|
help_wibox.keygrabber = awful.keygrabber.run(function(_, key, event)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
if event == "release" then return end
|
|
|
|
|
if key then
|
|
|
|
|
if key == "Next" then
|
|
|
|
|
help_wibox:page_next()
|
|
|
|
|
elseif key == "Prior" then
|
|
|
|
|
help_wibox:page_prev()
|
|
|
|
|
else
|
|
|
|
|
help_wibox:hide()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end)
|
2018-12-17 16:27:09 +01:00
|
|
|
|
return help_wibox.keygrabber
|
2017-01-17 10:13:26 +01:00
|
|
|
|
end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
|
2017-01-17 10:13:26 +01:00
|
|
|
|
--- Add hotkey descriptions for third-party applications.
|
|
|
|
|
-- @tparam table hotkeys Table with bindings,
|
|
|
|
|
-- see `awful.hotkeys_popup.key.vim` as an example.
|
2019-06-08 01:08:05 +02:00
|
|
|
|
-- @method add_hotkeys
|
2017-02-10 19:50:10 +01:00
|
|
|
|
function widget_instance:add_hotkeys(hotkeys)
|
2017-01-17 10:13:26 +01:00
|
|
|
|
for group, bindings in pairs(hotkeys) do
|
|
|
|
|
for _, binding in ipairs(bindings) do
|
|
|
|
|
local modifiers = binding.modifiers
|
|
|
|
|
local keys = binding.keys
|
|
|
|
|
for key, description in pairs(keys) do
|
2017-02-10 19:50:10 +01:00
|
|
|
|
self:_add_hotkey(key, {
|
2017-01-17 10:13:26 +01:00
|
|
|
|
mod=modifiers,
|
|
|
|
|
description=description,
|
|
|
|
|
group=group},
|
2017-02-10 19:50:10 +01:00
|
|
|
|
self._additional_hotkeys
|
2017-01-17 10:13:26 +01:00
|
|
|
|
)
|
|
|
|
|
end
|
2015-09-20 16:42:24 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2017-02-10 19:50:10 +01:00
|
|
|
|
self:_sort_hotkeys(self._additional_hotkeys)
|
2015-09-20 16:42:24 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-04-03 07:07:30 +02:00
|
|
|
|
--- Add hotkey group rules for third-party applications.
|
2017-04-08 11:15:03 +02:00
|
|
|
|
-- @tparam string group hotkeys group name,
|
|
|
|
|
-- @tparam table data rule data for the group
|
2017-04-03 07:07:30 +02:00
|
|
|
|
-- see `awful.hotkeys_popup.key.vim` as an example.
|
2019-06-08 01:08:05 +02:00
|
|
|
|
-- @method add_group_rules
|
2017-04-03 07:07:30 +02:00
|
|
|
|
function widget_instance:add_group_rules(group, data)
|
|
|
|
|
self.group_rules[group] = data
|
|
|
|
|
end
|
2016-02-04 12:55:54 +01:00
|
|
|
|
|
2017-01-17 10:13:26 +01:00
|
|
|
|
return widget_instance
|
2016-03-23 01:15:16 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function get_default_widget()
|
2017-01-17 10:13:26 +01:00
|
|
|
|
if not widget.default_widget then
|
|
|
|
|
widget.default_widget = widget.new()
|
2016-03-23 01:15:16 +01:00
|
|
|
|
end
|
2017-01-17 10:13:26 +01:00
|
|
|
|
return widget.default_widget
|
2016-03-23 01:15:16 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- Show popup with hotkeys help (default widget instance will be used).
|
|
|
|
|
-- @tparam[opt] client c Client.
|
|
|
|
|
-- @tparam[opt] screen s Screen.
|
2018-10-17 04:59:11 +02:00
|
|
|
|
-- @tparam[opt] table args Additional arguments.
|
|
|
|
|
-- @tparam[opt=true] boolean args.show_awesome_keys Show AwesomeWM hotkeys.
|
|
|
|
|
-- When set to `false` only app-specific hotkeys will be shown.
|
2019-06-08 01:08:05 +02:00
|
|
|
|
-- @staticfct awful.hotkeys_popup.widget.show_help
|
2017-01-17 10:13:26 +01:00
|
|
|
|
function widget.show_help(...)
|
2017-02-10 19:50:10 +01:00
|
|
|
|
return get_default_widget():show_help(...)
|
2016-03-23 01:15:16 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- Add hotkey descriptions for third-party applications
|
|
|
|
|
-- (default widget instance will be used).
|
|
|
|
|
-- @tparam table hotkeys Table with bindings,
|
|
|
|
|
-- see `awful.hotkeys_popup.key.vim` as an example.
|
2019-06-08 01:08:05 +02:00
|
|
|
|
-- @staticfct awful.hotkeys_popup.widget.add_hotkeys
|
2017-01-17 10:13:26 +01:00
|
|
|
|
function widget.add_hotkeys(...)
|
2017-02-10 19:50:10 +01:00
|
|
|
|
return get_default_widget():add_hotkeys(...)
|
2016-03-23 01:15:16 +01:00
|
|
|
|
end
|
|
|
|
|
|
2017-04-03 07:07:30 +02:00
|
|
|
|
--- Add hotkey group rules for third-party applications
|
|
|
|
|
-- (default widget instance will be used).
|
2017-04-08 11:15:03 +02:00
|
|
|
|
-- @tparam string group rule group name,
|
|
|
|
|
-- @tparam table data rule data for the group
|
2017-04-03 07:07:30 +02:00
|
|
|
|
-- see `awful.hotkeys_popup.key.vim` as an example.
|
2019-06-08 01:08:05 +02:00
|
|
|
|
-- @staticfct awful.hotkeys_popup.widget.add_group_rules
|
2017-04-08 11:15:03 +02:00
|
|
|
|
function widget.add_group_rules(group, data)
|
|
|
|
|
return get_default_widget():add_group_rules(group, data)
|
2017-04-03 07:07:30 +02:00
|
|
|
|
end
|
|
|
|
|
|
2017-01-17 10:13:26 +01:00
|
|
|
|
return widget
|
2015-09-20 16:42:24 +02:00
|
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|