1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
local awful = require "awful"
local beautiful = require "beautiful"
local qstore = require "quarrel.store"
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._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 = awful.screen.focused().geometry.height / 2,
minimum_width = awful.screen.focused().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(qstore.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
|