diff --git a/clipdate/clipdate.lua b/clipdate/clipdate.lua new file mode 100644 index 0000000..617d83d --- /dev/null +++ b/clipdate/clipdate.lua @@ -0,0 +1,85 @@ +-- 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, +}) diff --git a/clipdate/init.lua b/clipdate/init.lua new file mode 120000 index 0000000..4425b40 --- /dev/null +++ b/clipdate/init.lua @@ -0,0 +1 @@ +clipdate.lua \ No newline at end of file diff --git a/rc.lua b/rc.lua index c5c6bfb..b67de73 100644 --- a/rc.lua +++ b/rc.lua @@ -20,6 +20,10 @@ require("debian.menu") local battery_widget = require("battery-widget") local battery = battery_widget({adapter = "BAT0",widget_text="${color_on}🔋${color_off}", limits={{10,"red"},{20,"orange"},{100,"white"}} }) +-- clipdate +local clipdate_widget = require("clipdate") +local clipdate = clipdate_widget() + -- {{{ Error handling -- Check if awesome encountered an error during startup and fell back to -- another config (This code will only ever execute for the fallback config) @@ -52,7 +56,7 @@ beautiful.init(awful.util.getdir("config") .. "themes/default/theme.lua") -- This is used later as the default terminal and editor to run. --terminal = "x-terminal-emulator" -terminal = "lxterminal" +terminal = "terminology" editor = os.getenv("EDITOR") or "editor" editor_cmd = terminal .. " -e " .. editor @@ -243,6 +247,7 @@ awful.screen.connect_for_each_screen(function(s) { -- Right widgets layout = wibox.layout.fixed.horizontal, --mykeyboardlayout, + clipdate.widget, wibox.widget.systray(), battery.widget, mytextclock --[[, XXX11