forked from zackpete/hints
-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.lua
91 lines (76 loc) · 2.78 KB
/
init.lua
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
local awful = require("awful")
local client = client
local keygrabber= keygrabber
local naughty = require("naughty")
local pairs = pairs
local beautiful = require("beautiful")
local wibox = require("wibox")
local hints = {}
charorder = "jkluiopyhnmfdsatgvcewqzx1234567890"
hintbox = {} -- Table of letter wiboxes with characters as the keys
function debuginfo( message )
nid = naughty.notify({ text = message, timeout = 10 })
end
-- Create the wiboxes, but don't show them
function hints.init()
hintsize = 60
local fontcolor = beautiful.fg_normal
local letterbox = {}
for i = 1, #charorder do
local char = charorder:sub(i,i)
hintbox[char] = wibox({fg=beautiful.fg_normal, bg=beautiful.bg_focus, border_color=beautiful.border_focus, border_width=beautiful.border_width})
hintbox[char].ontop = true
hintbox[char].width = hintsize
hintbox[char].height = hintsize
letterbox[char] = wibox.widget.textbox()
letterbox[char]:set_markup("<span color=\"" .. beautiful.fg_normal.."\"" .. ">" .. char.upper(char) .. "</span>")
letterbox[char]:set_font("dejavu sans mono 40")
letterbox[char]:set_align("center")
hintbox[char]:set_widget(letterbox[char])
end
end
function hints.focus()
local hintindex = {} -- Table of visible clients with the hint letter as the keys
local clientlist = awful.client.visible()
for i,thisclient in pairs(clientlist) do -- Move wiboxes to center of visible windows and populate hintindex
local char = charorder:sub(i,i)
if char and char ~= '' then
hintindex[char] = thisclient
local geom = thisclient:geometry()
hintbox[char].visible = true
hintbox[char].x = math.floor(geom['x'] + geom['width']/2 - hintsize/2)
hintbox[char].y = math.floor(geom.y + geom.height/2 - hintsize/2)
hintbox[char].screen = thisclient.screen
end
end
keygrabber.run( function(mod,key,event)
if event == "release" then return true end
keygrabber.stop()
if hintindex[key] then
client.focus = hintindex[key]
awful.screen.focus(hintindex[key].screen)
hintindex[key]:raise()
end
for i,j in pairs(hintindex) do
hintbox[i].visible = false
end
end)
end
--function debuginfo( message )
--if type(message) == "table" then
--for k,v in pairs(message) do
--naughty.notify({ text = "key: "..k.." value: "..tostring(message), timeout = 10 })
--end
--else
--nid = naughty.notify({ text = message, timeout = 10 })
--end
--end
local function debuginfo( message )
mm = message
if not message then
mm = "false"
end
nid = naughty.notify({ text = tostring(mm), timeout = 10 })
end
setmetatable(hints, { __call = function(_, ...) return hints.focus(...) end })
return hints