-
Notifications
You must be signed in to change notification settings - Fork 1
/
menubar.lua
64 lines (49 loc) · 1.82 KB
/
menubar.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
-- menubar
dofile(zwm.spoonPath.."utilities.lua")
menubar = hs.menubar.new()
function set_workspaces()
local c = zwm.config
local all_spaces = get_spaces()
local current = spaces.activeSpace()
local inactive_before_text = ""
local inactive_after_text = ""
local separator = ""
local active_text = ""
local color_active = hex_to_rgb(c.ui.bar.color_active)
local color_inactive = hex_to_rgb(c.ui.bar.color_inactive)
if c.ui.bar.separator then
separator = c.ui.bar.separator
end
local i = 0
for i in ipairs(all_spaces) do
t = replace_identifier(tostring(i))
if all_spaces[i] == current then
active_text = t .. separator
else
if active_text:len() == 0 then
inactive_before_text = inactive_before_text .. t .. separator
else
inactive_after_text = inactive_after_text .. t .. separator
end
end
end
-- fontawesome
local font = {name = "FontAwesome", size = c.ui.bar.fontsize}
local active = hs.styledtext.new(active_text, {font = font, color = { red = color_active.r, green = color_active.g, blue = color_active.b}})
local inactive_before = hs.styledtext.new(inactive_before_text, {font = font, color = { red = color_inactive.r, green = color_inactive.g, blue = color_inactive.b}})
local inactive_after = hs.styledtext.new(inactive_after_text, {font = font, color = { red = color_inactive.r, green = color_inactive.g, blue = color_inactive.b}})
local g_str = inactive_before .. active .. inactive_after
menubar:setTitle(g_str)
end
function replace_identifier(index)
local c = zwm.config.spaces
local match = match_item(index, c.tags)
if match == nil then
return index
else
return tostring(match.f)
end
end
-- change menubar on normal space change
local watcher = hs.spaces.watcher.new(set_workspaces)
watcher:start()