graphs_rc.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. local gears = require("gears")
  2. local awful = require("awful")
  3. awful.rules = require("awful.rules")
  4. require("awful.autofocus")
  5. local wibox = require("wibox")
  6. local beautiful = require("beautiful")
  7. local naughty = require("naughty")
  8. local menubar = require("menubar")
  9. if awesome.startup_errors then
  10. naughty.notify({ preset = naughty.config.presets.critical,
  11. title = "Oops, there were errors during startup!",
  12. text = awesome.startup_errors })
  13. end
  14. do
  15. local in_error = false
  16. awesome.connect_signal("debug::error", function (err)
  17. -- Make sure we don't go into an endless error loop
  18. if in_error then return end
  19. in_error = true
  20. naughty.notify({ preset = naughty.config.presets.critical,
  21. title = "Oops, an error happened!",
  22. text = err })
  23. in_error = false
  24. end)
  25. end
  26. -- }}}
  27. user_dir = os.getenv("HOME")
  28. beautiful.init(user_dir .. "/.config/awesome/blingbling/config_example/graphs_test/theme.lua")
  29. terminal = "topinambour"
  30. editor = os.getenv("EDITOR") or "nvim"
  31. editor_cmd = terminal .. " -e " .. editor
  32. modkey = "Mod4"
  33. local layouts =
  34. {
  35. awful.layout.suit.floating,
  36. }
  37. for s = 1, screen.count() do
  38. gears.wallpaper.maximized(user_dir .. "/.config/awesome/blingbling/config_example/tiles_grey.png", s, true)
  39. end
  40. tags = {}
  41. for s = 1, screen.count() do
  42. tags[s] = awful.tag({ 1, 2 }, s, layouts[1])
  43. end
  44. myawesomemenu = {
  45. { "edit config", editor_cmd .. " " .. awesome.conffile },
  46. { "restart", awesome.restart },
  47. { "quit", awesome.quit }
  48. }
  49. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  50. { "open terminal", terminal }
  51. }
  52. })
  53. -- Menubar configuration
  54. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  55. -- }}}
  56. -- {{{ Wibox
  57. -- Create a textclock widget
  58. mytextclock = awful.widget.textclock()
  59. -- Create a wibox for each screen and add it
  60. mywibox = {}
  61. mypromptbox = {}
  62. mylayoutbox = {}
  63. mytaglist = {}
  64. mytaglist.buttons = awful.util.table.join(
  65. awful.button({ }, 1, awful.tag.viewonly),
  66. awful.button({ modkey }, 1, awful.client.movetotag),
  67. awful.button({ }, 3, awful.tag.viewtoggle),
  68. awful.button({ modkey }, 3, awful.client.toggletag),
  69. awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  70. awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  71. )
  72. mytasklist = {}
  73. mytasklist.buttons = awful.util.table.join(
  74. awful.button({ }, 1, function (c)
  75. if c == client.focus then
  76. c.minimized = true
  77. else
  78. -- Without this, the following
  79. -- :isvisible() makes no sense
  80. c.minimized = false
  81. if not c:isvisible() then
  82. awful.tag.viewonly(c:tags()[1])
  83. end
  84. -- This will also un-minimize
  85. -- the client, if needed
  86. client.focus = c
  87. c:raise()
  88. end
  89. end),
  90. awful.button({ }, 3, function ()
  91. if instance then
  92. instance:hide()
  93. instance = nil
  94. else
  95. instance = awful.menu.clients({
  96. theme = { width = 250 }
  97. })
  98. end
  99. end),
  100. awful.button({ }, 4, function ()
  101. awful.client.focus.byidx(1)
  102. if client.focus then client.focus:raise() end
  103. end),
  104. awful.button({ }, 5, function ()
  105. awful.client.focus.byidx(-1)
  106. if client.focus then client.focus:raise() end
  107. end))
  108. for s = 1, screen.count() do
  109. -- Create a promptbox for each screen
  110. mypromptbox[s] = awful.widget.prompt()
  111. -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  112. -- We need one layoutbox per screen.
  113. mylayoutbox[s] = awful.widget.layoutbox(s)
  114. mylayoutbox[s]:buttons(awful.util.table.join(
  115. awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  116. awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  117. awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  118. awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  119. -- Create a taglist widget
  120. mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  121. -- Create a tasklist widget
  122. mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  123. -- Create the wibox
  124. mywibox[s] = awful.wibox({ position = "top", screen = s })
  125. -- Widgets that are aligned to the left
  126. local left_layout = wibox.layout.fixed.horizontal()
  127. left_layout:add(mytaglist[s])
  128. left_layout:add(mypromptbox[s])
  129. -- Widgets that are aligned to the right
  130. local right_layout = wibox.layout.fixed.horizontal()
  131. if s == 1 then right_layout:add(wibox.widget.systray()) end
  132. right_layout:add(mytextclock)
  133. right_layout:add(mylayoutbox[s])
  134. -- Now bring it all together (with the tasklist in the middle)
  135. local layout = wibox.layout.align.horizontal()
  136. layout:set_left(left_layout)
  137. layout:set_middle(mytasklist[s])
  138. layout:set_right(right_layout)
  139. mywibox[s]:set_widget(layout)
  140. end
  141. -- }}}
  142. -- {{{ Mouse bindings
  143. root.buttons(awful.util.table.join(
  144. awful.button({ }, 3, function () mymainmenu:toggle() end),
  145. awful.button({ }, 4, awful.tag.viewnext),
  146. awful.button({ }, 5, awful.tag.viewprev)
  147. ))
  148. -- }}}
  149. -- {{{ Key bindings
  150. globalkeys = awful.util.table.join(
  151. awful.key({ modkey, }, "Left", awful.tag.viewprev ),
  152. awful.key({ modkey, }, "Right", awful.tag.viewnext ),
  153. awful.key({ modkey, }, "Escape", awful.tag.history.restore),
  154. awful.key({ modkey, }, "j",
  155. function ()
  156. awful.client.focus.byidx( 1)
  157. if client.focus then client.focus:raise() end
  158. end),
  159. awful.key({ modkey, }, "k",
  160. function ()
  161. awful.client.focus.byidx(-1)
  162. if client.focus then client.focus:raise() end
  163. end),
  164. awful.key({ modkey, }, "w", function () mymainmenu:show() end),
  165. -- Layout manipulation
  166. awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
  167. awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
  168. awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  169. awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  170. awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
  171. awful.key({ modkey, }, "Tab",
  172. function ()
  173. awful.client.focus.history.previous()
  174. if client.focus then
  175. client.focus:raise()
  176. end
  177. end),
  178. -- Standard program
  179. awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
  180. awful.key({ modkey, "Control" }, "r", awesome.restart),
  181. awful.key({ modkey, "Shift" }, "q", awesome.quit),
  182. awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
  183. awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
  184. awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
  185. awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
  186. awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
  187. awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
  188. awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
  189. awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
  190. awful.key({ modkey, "Control" }, "n", awful.client.restore),
  191. -- Prompt
  192. awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
  193. awful.key({ modkey }, "x",
  194. function ()
  195. awful.prompt.run({ prompt = "Run Lua code: " },
  196. mypromptbox[mouse.screen].widget,
  197. awful.util.eval, nil,
  198. awful.util.getdir("cache") .. "/history_eval")
  199. end),
  200. -- Menubar
  201. awful.key({ modkey }, "p", function() menubar.show() end)
  202. )
  203. clientkeys = awful.util.table.join(
  204. awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
  205. awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
  206. awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
  207. awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  208. awful.key({ modkey, }, "o", awful.client.movetoscreen ),
  209. awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
  210. awful.key({ modkey, }, "n",
  211. function (c)
  212. -- The client currently has the input focus, so it cannot be
  213. -- minimized, since minimized clients can't have the focus.
  214. c.minimized = true
  215. end),
  216. awful.key({ modkey, }, "m",
  217. function (c)
  218. c.maximized_horizontal = not c.maximized_horizontal
  219. c.maximized_vertical = not c.maximized_vertical
  220. end)
  221. )
  222. -- Bind all key numbers to tags.
  223. -- Be careful: we use keycodes to make it works on any keyboard layout.
  224. -- This should map on the top row of your keyboard, usually 1 to 9.
  225. for i = 1, 9 do
  226. globalkeys = awful.util.table.join(globalkeys,
  227. -- View tag only.
  228. awful.key({ modkey }, "#" .. i + 9,
  229. function ()
  230. local screen = mouse.screen
  231. local tag = awful.tag.gettags(screen)[i]
  232. if tag then
  233. awful.tag.viewonly(tag)
  234. end
  235. end),
  236. -- Toggle tag.
  237. awful.key({ modkey, "Control" }, "#" .. i + 9,
  238. function ()
  239. local screen = mouse.screen
  240. local tag = awful.tag.gettags(screen)[i]
  241. if tag then
  242. awful.tag.viewtoggle(tag)
  243. end
  244. end),
  245. -- Move client to tag.
  246. awful.key({ modkey, "Shift" }, "#" .. i + 9,
  247. function ()
  248. if client.focus then
  249. local tag = awful.tag.gettags(client.focus.screen)[i]
  250. if tag then
  251. awful.client.movetotag(tag)
  252. end
  253. end
  254. end),
  255. -- Toggle tag.
  256. awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  257. function ()
  258. if client.focus then
  259. local tag = awful.tag.gettags(client.focus.screen)[i]
  260. if tag then
  261. awful.client.toggletag(tag)
  262. end
  263. end
  264. end))
  265. end
  266. clientbuttons = awful.util.table.join(
  267. awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  268. awful.button({ modkey }, 1, awful.mouse.client.move),
  269. awful.button({ modkey }, 3, awful.mouse.client.resize))
  270. -- Set keys
  271. root.keys(globalkeys)
  272. -- }}}
  273. -- {{{ Rules
  274. -- Rules to apply to new clients (through the "manage" signal).
  275. awful.rules.rules = {
  276. -- All clients will match this rule.
  277. { rule = { },
  278. properties = { border_width = beautiful.border_width,
  279. border_color = beautiful.border_normal,
  280. focus = awful.client.focus.filter,
  281. raise = true,
  282. keys = clientkeys,
  283. buttons = clientbuttons } },
  284. { rule = { class = "MPlayer" },
  285. properties = { floating = true } },
  286. { rule = { class = "pinentry" },
  287. properties = { floating = true } },
  288. { rule = { class = "gimp" },
  289. properties = { floating = true } },
  290. -- Set Firefox to always map on tags number 2 of screen 1.
  291. -- { rule = { class = "Firefox" },
  292. -- properties = { tag = tags[1][2] } },
  293. }
  294. -- }}}
  295. -- {{{ Signals
  296. -- Signal function to execute when a new client appears.
  297. client.connect_signal("manage", function (c, startup)
  298. -- Enable sloppy focus
  299. c:connect_signal("mouse::enter", function(c)
  300. if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  301. and awful.client.focus.filter(c) then
  302. client.focus = c
  303. end
  304. end)
  305. if not startup then
  306. -- Set the windows at the slave,
  307. -- i.e. put it at the end of others instead of setting it master.
  308. -- awful.client.setslave(c)
  309. -- Put windows in a smart way, only if they does not set an initial position.
  310. if not c.size_hints.user_position and not c.size_hints.program_position then
  311. awful.placement.no_overlap(c)
  312. awful.placement.no_offscreen(c)
  313. end
  314. end
  315. local titlebars_enabled = false
  316. if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  317. -- buttons for the titlebar
  318. local buttons = awful.util.table.join(
  319. awful.button({ }, 1, function()
  320. client.focus = c
  321. c:raise()
  322. awful.mouse.client.move(c)
  323. end),
  324. awful.button({ }, 3, function()
  325. client.focus = c
  326. c:raise()
  327. awful.mouse.client.resize(c)
  328. end)
  329. )
  330. -- Widgets that are aligned to the left
  331. local left_layout = wibox.layout.fixed.horizontal()
  332. left_layout:add(awful.titlebar.widget.iconwidget(c))
  333. left_layout:buttons(buttons)
  334. -- Widgets that are aligned to the right
  335. local right_layout = wibox.layout.fixed.horizontal()
  336. right_layout:add(awful.titlebar.widget.floatingbutton(c))
  337. right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  338. right_layout:add(awful.titlebar.widget.stickybutton(c))
  339. right_layout:add(awful.titlebar.widget.ontopbutton(c))
  340. right_layout:add(awful.titlebar.widget.closebutton(c))
  341. -- The title goes in the middle
  342. local middle_layout = wibox.layout.flex.horizontal()
  343. local title = awful.titlebar.widget.titlewidget(c)
  344. title:set_align("center")
  345. middle_layout:add(title)
  346. middle_layout:buttons(buttons)
  347. -- Now bring it all together
  348. local layout = wibox.layout.align.horizontal()
  349. layout:set_left(left_layout)
  350. layout:set_right(right_layout)
  351. layout:set_middle(middle_layout)
  352. awful.titlebar(c):set_widget(layout)
  353. end
  354. end)
  355. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  356. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  357. grid_box = wibox({height = 500, width = 800, ontop = true, x = 200, y = 200})
  358. grid_box.visible = true
  359. local vicious = require("vicious")
  360. local blingbling = require("blingbling")
  361. grid = blingbling.grid()
  362. local line = 0
  363. local title = wibox.widget.textbox()
  364. title:set_text("System Informations & monitors")
  365. title:set_align("center")
  366. title:set_font("Sans bold 14")
  367. line = line + 1
  368. grid:add_child(title, 1, line, 2, 2)
  369. -- Second column first
  370. local cpu_mem_label = wibox.widget.textbox()
  371. cpu_mem_label:set_text("Cpus & memory:")
  372. line = line + 2
  373. grid:add_child(cpu_mem_label, 2, line, 1, 1)
  374. local nb_cores = blingbling.helpers.get_nb_cores()
  375. local cpu_graphs = {}
  376. for i =1, nb_cores do
  377. cpu_graphs[i]= blingbling.line_graph({
  378. show_text = true,
  379. label = "Core " .. tostring(i) ..": $percent %",
  380. rounded_size = 0.3,
  381. graph_background_color = "#00000033"
  382. })
  383. vicious.register(cpu_graphs[i], vicious.widgets.cpu,'$' .. i+1,2)
  384. line = line + 1
  385. grid:add_child(cpu_graphs[i], 2 , line , 1, 1)
  386. end
  387. local memory = blingbling.line_graph({
  388. show_text = true,
  389. label = "Memory: $percent %",
  390. rounded_size = 0.3,
  391. graph_background_color = "#00000033"
  392. })
  393. vicious.register(memory, vicious.widgets.mem,'$1',2)
  394. line = line + 1
  395. grid:add_child(memory, 2, line, 1, 1)
  396. local fs_label = wibox.widget.textbox()
  397. fs_label:set_text("Mounted File Systems usage")
  398. line = line + 2
  399. grid:add_child(fs_label, 2, line, 1, 1)
  400. local devices = blingbling.helpers.get_mounted_devices()
  401. local devices_graphs = {}
  402. local n=0
  403. for i,v in ipairs(devices) do
  404. devices_graphs[i] = blingbling.progress_graph({
  405. show_text = true,
  406. label = devices[i].dev .." -> " .. devices[i].mnt .." Usage: $percent %",
  407. horizontal = true,
  408. rounded_size = 0.3,
  409. graph_background_color = "#00000033"
  410. })
  411. vicious.register(devices_graphs[i], vicious.widgets.fs, "${" .. devices[i].mnt .." used_p}",120)
  412. line = line + 1
  413. grid:add_child(devices_graphs[i], 2, line, 1, 1)
  414. end
  415. -- First column
  416. local os_infos = blingbling.helpers.get_os_release_informations()
  417. line = 2 -- After the title line which is 2 line height
  418. for _,v in ipairs(os_infos) do
  419. local tbox = wibox.widget.textbox()
  420. tbox:set_markup("<span color=\"white\">"..v.key..": </span><span color=\""..beautiful.bg_focus.."\">"..v.value.."</span>" )
  421. line = line + 1
  422. grid:add_child(tbox, 1, line, 1, 1)
  423. end
  424. local cpu_info = wibox.widget.textbox()
  425. cpu_info:set_markup("<span color=\"white\">Cpu: </span><span color=\""..beautiful.bg_focus.."\">"..blingbling.helpers.get_cpu_name().."</span>" )
  426. line = line + 1
  427. grid:add_child(cpu_info, 1, line, 1, 1)
  428. local mem_info = wibox.widget.textbox()
  429. mem_info:set_markup("<span color=\"white\">Ram: </span><span color=\""..beautiful.bg_focus.."\">"..math.ceil(blingbling.helpers.get_total_mem_in_kb()/(1024*1024)).." G</span>" )
  430. line = line + 1
  431. grid:add_child(mem_info, 1, line, 1, 1)
  432. local input_devices = blingbling.helpers.get_input_devices()
  433. for k,v in pairs(input_devices) do
  434. local tbox = wibox.widget.textbox()
  435. tbox:set_markup("<span color=\"white\">".. k ..": </span><span color=\""..beautiful.bg_focus.."\">"..v.."</span>" )
  436. line = line + 1
  437. grid:add_child(tbox, 1, line, 1, 1)
  438. end
  439. grid_box:set_widget(grid)