My Awesome Config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.9KB

  1. local awful = require("awful")
  2. local wibox = require("wibox")
  3. local beautiful = require("beautiful")
  4. local vicious = require("vicious")
  5. local naughty = require("naughty")
  6. ----< Battery >-------------------------------------------------------
  7. --
  8. local bat_state = ""
  9. local bat_charge = 0
  10. local bat_time = 0
  11. local blink = true
  12. baticon = wibox.widget.imagebox()
  13. baticon:set_image(beautiful.widget_batfull)
  14. -- Charge %
  15. batpct = wibox.widget.textbox()
  16. vicious.register(batpct, vicious.widgets.bat, function(widget, args)
  17. bat_state = args[1]
  18. bat_charge = args[2]
  19. bat_time = args[3]
  20. if args[1] == "−" then
  21. if bat_charge > 70 then
  22. baticon:set_image(beautiful.widget_batfull)
  23. elseif bat_charge > 30 then
  24. baticon:set_image(beautiful.widget_batmed)
  25. elseif bat_charge > 10 then
  26. baticon:set_image(beautiful.widget_batlow)
  27. else
  28. baticon:set_image(beautiful.widget_batempty)
  29. end
  30. else
  31. baticon:set_image(beautiful.widget_ac)
  32. if args[1] == "+" then
  33. blink = not blink
  34. if blink then
  35. baticon:set_image(beautiful.widget_acblink)
  36. end
  37. end
  38. end
  39. return args[2] .. "% "
  40. end, nil, "BAT0")
  41. function popup_bat()
  42. local state = ""
  43. if bat_state == "↯" then
  44. state = "Full"
  45. elseif bat_state == "↯" then
  46. state = "Charged"
  47. elseif bat_state == "+" then
  48. state = "Charging"
  49. elseif bat_state == "-" then
  50. state = "Discharging"
  51. elseif bat_state == "⌁" then
  52. state = "Not charging"
  53. else
  54. state = "Unknown"
  55. end
  56. naughty.notify { text = "Charge : " .. bat_charge .. "%\nState : " .. state ..
  57. " (" .. bat_time .. ")", timeout = 5, hover_timeout = 0.5 }
  58. end
  59. function show_powertop ()
  60. os.execute ("pgrep powertop || urxvt -e sudo powertop &")
  61. end
  62. batpct:buttons(awful.util.table.join(awful.button({ }, 1, popup_bat), awful.button({ }, 3, show_powertop)))
  63. baticon:buttons(batpct:buttons())