-
Notifications
You must be signed in to change notification settings - Fork 1
/
i3_workspace_indicator.lua
134 lines (120 loc) · 4.03 KB
/
i3_workspace_indicator.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
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
local json = require 'json'
local i3bar_util = require 'util'
-- i3-wm workspace indicator
-- for i3 wm configured with 10 total workspaces (i3's default)
return function (opt)
local xpos = opt.x
local ypos = opt.y
-- text color
local r, g, b, a
-- fetch i3 wm workspace information
local workspacesData = conky_parse('${exec i3-msg -t get_workspaces}')
local new_workspaces = json.decode(workspacesData) or {}
local workspaces = {}
local present_workspace_number = 0
for i = 1, 10 do
workspaces[i] = nil
end
for i, w in ipairs(new_workspaces) do
workspaces[w['num']] = {
['num'] = w['num'],
['visible'] = w['visible'],
['urgent'] = w['urgent']
}
end
-- draw small text 'workspace'
ypos = ypos + 16
r, g, b, a = 0.9, 0.9, 0.9, 0.9
cairo_move_to(opt.cr, xpos, ypos)
cairo_select_font_face(
opt.cr,
opt.primary_font,
opt.primary_font_slant,
opt.primary_font_face)
cairo_set_font_size(opt.cr, 9)
cairo_set_source_rgba(opt.cr, r, g, b, a)
cairo_show_text(opt.cr, 'workspace')
cairo_stroke(opt.cr)
xpos = xpos + 48
ypos = ypos - 14
i3bar_util.draw_svg({cr = opt.cr,
x = xpos, y = ypos,
file = opt.RESOURCE_PATH .. 'workspace-frame.svg'})
xpos = xpos + 34
-- upper indicator
for i = 1,5 do
-- shift right
xpos = xpos + 9
if workspaces[i] == nil then
-- empty workspace
i3bar_util.draw_svg({cr = opt.cr,
x = xpos, y = ypos,
file = opt.RESOURCE_PATH .. 'workspace-upper_empty.svg'})
else
if workspaces[i]['urgent'] == true then
-- urgent
i3bar_util.draw_svg({cr = opt.cr,
x = xpos, y = ypos,
file = opt.RESOURCE_PATH .. 'workspace-upper_urgent.svg'})
elseif workspaces[i]['visible'] == true then
-- present
present_workspace_number = i
i3bar_util.draw_svg({cr = opt.cr,
x = xpos, y = ypos,
file = opt.RESOURCE_PATH .. 'workspace-upper_present.svg'})
else
-- normal
i3bar_util.draw_svg({cr = opt.cr,
x = xpos, y = ypos,
file = opt.RESOURCE_PATH .. 'workspace-upper_normal.svg'})
end
end
end
xpos = xpos - 46
ypos = ypos + 14
-- lower indicator
for i = 6,10 do
xpos = xpos + 9
if workspaces[i] == nil then
-- empty workspace
i3bar_util.draw_svg({cr = opt.cr,
x = xpos, y = ypos,
file = opt.RESOURCE_PATH .. 'workspace-lower_empty.svg'})
else
if workspaces[i]['urgent'] == true then
-- urgent
i3bar_util.draw_svg({cr = opt.cr,
x = xpos, y = ypos,
file = opt.RESOURCE_PATH .. 'workspace-lower_urgent.svg'})
elseif workspaces[i]['visible'] == true then
-- present
present_workspace_number = i
i3bar_util.draw_svg({cr = opt.cr,
x = xpos, y = ypos,
file = opt.RESOURCE_PATH .. 'workspace-lower_present.svg'})
else
-- normal
i3bar_util.draw_svg({cr = opt.cr,
x = xpos, y = ypos,
file = opt.RESOURCE_PATH .. 'workspace-lower_normal.svg'})
end
end
end
xpos = xpos - 53
ypos = ypos + 3
-- display workspace 10 as workspace 0
if present_workspace_number == 10 then
present_workspace_number = 0
end
r, g, b, a = 1, 1, 1, 1
cairo_move_to(opt.cr, xpos, ypos)
cairo_select_font_face(
opt.cr,
opt.primary_font,
opt.primary_font_slant,
opt.primary_font_face)
cairo_set_font_size(opt.cr, opt.primary_font_size)
cairo_set_source_rgba(opt.cr, r, g, b, a)
cairo_show_text(opt.cr, present_workspace_number)
cairo_stroke(opt.cr)
end