Skip to content

Instantly share code, notes, and snippets.

@mortymacs
Last active February 16, 2017 17:37
Show Gist options
  • Select an option

  • Save mortymacs/7ba4260cc20ebba36122c87f7b84a644 to your computer and use it in GitHub Desktop.

Select an option

Save mortymacs/7ba4260cc20ebba36122c87f7b84a644 to your computer and use it in GitHub Desktop.
Textbattery for awesome awful widget (modified version of textclock widget)
---------------------------------------------------------------------------
-- @copyright 2009 Julien Danjou
---------------------------------------------------------------------------
local setmetatable = setmetatable
local os = os
local textbox = require("wibox.widget.textbox")
local capi = { timer = timer }
--- Text battery widget.
-- awful.widget.textbattery
local textbattery = { mt = {} }
--- Create a textbattery widget. It draws the battery state it is in a textbox.
function textbattery.new()
local timeout = 30
local w = textbox()
local timer = capi.timer { timeout = timeout }
timer:connect_signal("timeout", function() x=io.popen("acpitool -b | awk '{print $4,$5}'");b=x:read("*a");w:set_markup(string.sub(b, 0, string.len(b)-2)) end)
timer:start()
timer:emit_signal("timeout")
return w
end
function textbattery.mt:__call(...)
return textbattery.new(...)
end
return setmetatable(textbattery, textbattery.mt)
@mortymacs
Copy link
Copy Markdown
Author

mortymacs commented Feb 16, 2017

Note: this widget requires acpitool program. so install it before any action: sudo apt install acpitool

Now copy this widget in /usr/share/awesome/lib/awful/widget/ then import it in init.lua file and then use it in your rc.lua like so:

mytextbattery = awful.widget.textbattery()
right_layout:add(mytextbattery)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment