RcrdBrt

Untitled

Jul 16th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. baticon = wibox.widget.imagebox()
  2. baticon:set_image(beautiful.widget_battery)
  3.  
  4. function batstate()
  5.  
  6. local file = io.open("/sys/class/power_supply/BAT0/status", "r")
  7.  
  8. if (file == nil) then
  9. return "Cable plugged"
  10. end
  11.  
  12. local batstate = file:read("*line")
  13. file:close()
  14.  
  15. if (batstate == 'Discharging' or batstate == 'Charging') then
  16. return batstate
  17. else
  18. return "Fully charged"
  19. end
  20. end
  21.  
  22. batwidget = wibox.widget.textbox()
  23. vicious.register(batwidget, vicious.widgets.bat,
  24. function (widget, args)
  25. -- plugged
  26. if (batstate() == 'Cable plugged') then
  27. baticon:set_image(beautiful.widget_ac)
  28. return ''
  29. -- critical
  30. elseif (args[2] <= 5 and batstate() == 'Discharging') then
  31. baticon:set_image(beautiful.widget_battery_empty)
  32. naughty.notify({
  33. text = "sto per spegnermi...",
  34. title = "Carica quasi esaurita!",
  35. position = "top_right",
  36. timeout = 1,
  37. fg="#000000",
  38. bg="#ffffff",
  39. screen = 1,
  40. ontop = true,
  41. })
  42. -- low
  43. elseif (args[2] <= 20 and batstate() == 'Discharging') then
  44. baticon:set_image(beautiful.widget_battery_low)
  45. naughty.notify({
  46. text = "attacca il cavo!",
  47. title = "Carica bassa",
  48. position = "top_right",
  49. timeout = 1,
  50. fg="#ffffff",
  51. bg="#262729",
  52. screen = 1,
  53. ontop = true,
  54. })
  55. else baticon:set_image(beautiful.widget_battery)
  56. end
  57. return gray .. "Bat " .. coldef .. white .. args[2] .. " " .. coldef
  58. end, 1, 'BAT0')
Advertisement
Add Comment
Please, Sign In to add comment