-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbottom_panel.lua
More file actions
188 lines (151 loc) · 4.71 KB
/
bottom_panel.lua
File metadata and controls
188 lines (151 loc) · 4.71 KB
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
-- SPDX-FileCopyrightText: Robert Ryszard Paciorek <rrp@opcode.eu.org>
-- SPDX-License-Identifier: MIT
-------------------------
--- Configuration ---
-------------------------
HIST_SIZE = 80
HWMON_CONFIG = nil -- use default (output of `hwmon_config.sh` script)
NETDEV = "eno1"
DISKDEV = "sda"
TIME_ZONES = {"UTC", "Europe/Warsaw"}
TIME_ZONES_MAX = 2
TOOLTIP_DELAY = 0.8
TERM = { W=132, H=55, X=2, Y=0, TOOLTIP_TIME=16 }
MEM = { W=72, H=55, X=TERM.X+TERM.W+1, Y=0, TOOLTIP_TIME=9 }
DISK = { W=72, H=55, X=MEM.X+MEM.W+1, Y=0, TOOLTIP_TIME=100 }
CPU = { W=72, H=55, X=DISK.X+DISK.W+1, Y=0, TOOLTIP_TIME=100 }
GPU = { W=72, H=55, X=CPU.X+CPU.W+1, Y=0, TOOLTIP_TIME=5 }
NET = { W=72, H=55, X=GPU.X+GPU.W+1, Y=0, TOOLTIP_TIME=8 }
CLOCK = { W=155, H=52, X=NET.X+NET.W+5, Y=0, TOOLTIP_TIME=5 }
WIN_WIDTH = 670
WIN_HEIGHT = 58
WIN_HEIGHT_BIG_MODE = 400
function set_default_font(cr, bold)
cairo_select_font_face(cr, "DejaVu Sans Mono", 0, bold)
cairo_set_font_size(cr, 13)
end
------------------------
--- Dependencies ---
------------------------
require "cairo"
package.path = debug.getinfo(1).source:match("@?(.*/)") .. "?.lua;" .. package.path
require "clock"
require "stats"
require "hwmon"
require "utils"
require "data_history"
------------------------
--- Globals ---
------------------------
updates = -1
te = nil
------------------------------------
--- Windows resize functions ---
------------------------------------
-- conky_window.width / height are not update while resize window via xdotool, so keep own globals
win_width = nil
win_height = nil
---------------------------------
--- Conky hooks functions ---
---------------------------------
function conky_draw()
if conky_window == nil then return end
local new_updates = tonumber(conky_parse("${updates}"))
if new_updates ~= updates then
updates = new_updates
-- update stats 2 times per second
-- (this function is called 4 times per second due to update clock)
if updates%2 == 0 then
local full_update = (updates%4 == 0)
update_data(full_update)
if full_update then
if (tooltip_visible == CPU) then
update_cpu_tooltip()
end
end
end
end
-- set window size
if not win_width or updates < 3 then
resize_window(WIN_WIDTH, WIN_HEIGHT)
end
-- cairo surface
local cs = cairo_xlib_surface_create(
conky_window.display, conky_window.drawable, conky_window.visual, win_width, win_height
)
local cr = cairo_create(cs)
te = cairo_text_extents_t:create()
tolua.takeownership(te)
cairo_set_antialias(cr, 1)
CLOCK.Y = win_height-CLOCK.H
NET.Y = win_height-NET.H
GPU.Y = NET.Y
CPU.Y = NET.Y
DISK.Y = NET.Y
MEM.Y = NET.Y
TERM.Y = NET.Y
if win_height ~= WIN_HEIGHT then
draw_big_window_widgets(cr)
end
draw_clock(cr, CLOCK)
draw_in_out(cr, NET, hist_down, hist_up)
draw_gpu(cr, GPU)
draw_cpu(cr, CPU)
draw_in_out(cr, DISK, hist_rd, hist_wr)
draw_mem(cr, MEM)
draw_term(cr, TERM)
draw_clock_tooltip(cr, CLOCK)
draw_in_out_tooltip(cr, NET, NETDEV .. " down", NETDEV .. " up", hist_down, hist_up)
draw_gpu_tooltip(cr, GPU)
draw_cpu_tooltip(cr, CPU)
draw_in_out_tooltip(cr, DISK, DISKDEV .. " read", DISKDEV .. " write", hist_rd, hist_wr)
draw_mem_tooltip(cr, MEM)
draw_term_tooltip(cr, TERM)
tolua.releaseownership(te)
cairo_text_extents_t:destroy(te)
cairo_destroy(cr)
cairo_surface_destroy(cs)
end
function event_handler(event)
if clock_event(event) then
return true
elseif event.type == "mouse_move" then
if (event.y > NET.Y and event.x > NET.X and event.x < NET.X + NET.W) then
tooltip_show(NET, event.x, event.y)
elseif (event.y > GPU.Y and event.x > GPU.X and event.x < GPU.X + GPU.W) then
tooltip_show(GPU, event.x, event.y)
elseif (event.y > CPU.Y and event.x > CPU.X and event.x < CPU.X + CPU.W) then
if tooltip_show(CPU, event.x, event.y) then
update_cpu_tooltip()
end
elseif (event.y > MEM.Y and event.x > MEM.X and event.x < MEM.X + MEM.W) then
tooltip_show(MEM, event.x, event.y)
elseif (event.y > DISK.Y and event.x > DISK.X and event.x < DISK.X + DISK.W) then
tooltip_show(DISK, event.x, event.y)
elseif (event.y > TERM.Y and event.x > TERM.X and event.x < TERM.X + TERM.W) then
tooltip_show(TERM, event.x, event.y)
else
tooltip_visible = nil
end
elseif event.type == "button_down" then
if win_height == WIN_HEIGHT then
resize_window(WIN_WIDTH, WIN_HEIGHT_BIG_MODE)
else
resize_window(WIN_WIDTH, WIN_HEIGHT)
end
else
tooltip_visible = nil
end
return true
end
----------------
--- Init ---
----------------
clock_set_tz(2)
-- TODO / WIP
function draw_big_window_widgets(cr)
cairo_set_source_rgba(cr, 1, 1, 1, 1)
cairo_move_to(cr, 0, 0)
cairo_line_to(cr, 50, 50)
cairo_stroke(cr)
end