-- Battery widget local awful = require("awful") local gears = require("gears") local wibox = require("wibox") local timer = gears.timer or timer local watch = awful.spawn and awful.spawn.with_line_callback ------------------------------------------ -- Private utility functions ------------------------------------------ ------------------------------------------ -- Battery widget interface ------------------------------------------ local clipdate_widget= {} function clipdate_widget:new(args) return setmetatable({}, {__index = self}):init(args) end function clipdate_widget:init(args) self.widget = wibox.widget.textbox() self.widget.set_align("right") self.tooltip = awful.tooltip({objects={self.widget}}) self.widget:buttons(awful.util.table.join( awful.button({ }, 1, function() self:update() end), awful.button({ }, 3, function() self:update() end) )) self.timer = timer({ timeout = 1 }) self.timer:connect_signal("timeout", function() self:update() end) self.timer:start() self:update() awesome.connect_signal("exit", function() awesome.kill(self.listener, 9) end) return self end function run(cmd) local f = io.popen(cmd,'r') local s = f:read('*a') f:close() return s end function getDate(cmd) local clipboard = run(cmd) local match = string.match(clipboard,'^%d%d%d%d%d%d%d%d%d%d%d%d%d$') if ( match == nil ) then return nil else local ms = tonumber(match) local s = math.floor((ms+500)/1000) return os.date("%Y-%m-%d %H:%M:%S",s) end end function clipdate_widget:update() local text = "" local tooltip = "" local s = getDate("xsel -o") if ( s == nil ) then s = getDate("xsel -o -b") end if ( s == nil ) then else text = "["..s.."]" tooltip = s end self.widget:set_markup(text) self.tooltip:set_text(tooltip) end return setmetatable(clipdate_widget, { __call = clipdate_widget.new, })