local awful = require "awful" local beautiful = require "beautiful" local gtable = require "gears.table" local qtable = require "quarrel.table" local qui = require "quarrel.ui" local qvars = require "quarrel.vars" local rubato = require "lib.rubato" local wibox = require "wibox" local btn = awful.button.names local first_time = true local mouse = "󰍽 " local insightful = {} insightful._toggled = false insightful._bindings = {} insightful._selected_group = "" insightful._selected_group_index = 1 insightful._keymap = { Control = "Control", Mod1 = "Alt", ISO_Level3_Shift = "Alt Gr", Mod4 = "Super", Insert = "Insert", Delete = "Delete", Next = "Page Up", Prior = "Page Down", Left = "", Up = "", Right = "", Down = "", KP_End = "1", KP_Down = "#2", KP_Next = "#3", KP_Left = "#4", KP_Begin = "#5", KP_Right = "#6", KP_Home = "#7", KP_Up = "#8", KP_Prior = "#9", KP_Insert = "#0", KP_Delete = "#.", KP_Divide = "#/", KP_Multiply = "#*", KP_Subtract = "#-", KP_Add = "#+", KP_Enter = "#Enter", Escape = "Esc", Tab = "Tab", space = "Space", Return = "Enter", dead_acute = "´", dead_circumflex = "^", dead_grave = "`", XF86MonBrightnessUp = "🔆+", XF86MonBrightnessDown = "🔅-", XF86AudioRaiseVolume = "ﱛ", XF86AudioLowerVolume = "ﱜ", XF86AudioMute = "ﱝ", XF86AudioPlay = "⏯", XF86AudioPrev = "⏮", XF86AudioNext = "⏭", XF86AudioStop = "⏹", [tostring(btn.LEFT)] = mouse .. "Left", [tostring(btn.MIDDLE)] = mouse .. "Middle", [tostring(btn.RIGHT)] = mouse .. "Right" } insightful._widget = qui.popup { visible = false, ontop = true, placement = function(d) awful.placement.top(d, { margins = { top = beautiful.useless_gap * 2 } }) end, minimum_height = screen[1].geometry.height / 2, minimum_width = screen[1].geometry.width / 2, widget = { layout = wibox.layout.fixed.vertical, spacing = qvars.big_padding, id = "layout_container" } } function insightful:_generate() local grouped_binds = {} local layout_container = insightful._widget.widget.layout_container for _, keybind in ipairs(self._bindings) do local group = keybind.group or "general" local group_exists = grouped_binds[group] ~= nil if not group_exists then grouped_binds[group] = {} end table.insert(grouped_binds[group], { mods = keybind.mods, triggers = keybind.triggers, desc = keybind.desc }) end for group, keybinds in qtable.opairs(grouped_binds) do local group_layout = { spacing = qvars.padding, layout = wibox.layout.fixed.vertical } for _, keybind in ipairs(keybinds) do local key_layout = { layout = wibox.layout.fixed.horizontal } local key_and_desc_layout = { nil, -- key nil, nil, -- description? layout = wibox.layout.align.horizontal } for _, mod in ipairs(keybind.mods) do table.insert(key_layout, 1, qui.styled { widget = wibox.container.background, bg = qvars.colors.bright.black, border_width = 0, { widget = wibox.container.margin, margins = qvars.padding, { widget = wibox.widget.textbox, text = insightful._keymap[mod] or mod } } }) table.insert(key_layout, 2, { widget = wibox.widget.textbox, text = " + " }) end if type(keybind.triggers) == "string" or type(keybind.triggers) == "number" then table.insert(key_layout, { widget = wibox.widget.textbox, text = insightful._keymap[tostring(keybind.triggers)] or keybind.triggers }) elseif type(keybind.triggers) == "table" then local display_trigger = {} for _, trigger in ipairs(keybind.triggers) do table.insert(display_trigger, insightful._keymap[trigger[1]] or trigger[1]) end table.insert(key_layout, { widget = wibox.widget.textbox, text = table.concat(display_trigger, "/") }) end if keybind.desc then key_and_desc_layout[3] = { widget = wibox.container.background, fg = qvars.colors.dim.fg, { widget = wibox.widget.textbox, text = keybind.desc } } end key_and_desc_layout[1] = key_layout table.insert(group_layout, key_and_desc_layout) end layout_container:add { { { widget = wibox.container.background, bg = qvars.colors.yellow, fg = qvars.colors.bg, shape = qvars.shape, { widget = wibox.container.margin, margins = qvars.padding, { widget = wibox.widget.textbox, text = group } } }, nil, layout = wibox.layout.align.horizontal }, group_layout, spacing = qvars.padding, layout = wibox.layout.fixed.vertical } end end local timed = rubato.timed { duration = qvars.anim_duration, intro = qvars.anim_intro, pos = 0, subscribed = function(pos) insightful._widget.opacity = pos if pos == 0 then insightful._widget.visible = false else insightful._widget.visible = true end end } function insightful:toggle() if first_time then insightful:_generate() first_time = false end timed.target = insightful._toggled and 0 or 1 insightful._toggled = not insightful._toggled end return insightful