clipdate
This commit is contained in:
85
clipdate/clipdate.lua
Normal file
85
clipdate/clipdate.lua
Normal file
@@ -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,
|
||||||
|
})
|
||||||
1
clipdate/init.lua
Symbolic link
1
clipdate/init.lua
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
clipdate.lua
|
||||||
7
rc.lua
7
rc.lua
@@ -20,6 +20,10 @@ require("debian.menu")
|
|||||||
local battery_widget = require("battery-widget")
|
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"}} })
|
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
|
-- {{{ Error handling
|
||||||
-- Check if awesome encountered an error during startup and fell back to
|
-- Check if awesome encountered an error during startup and fell back to
|
||||||
-- another config (This code will only ever execute for the fallback config)
|
-- 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.
|
-- This is used later as the default terminal and editor to run.
|
||||||
--terminal = "x-terminal-emulator"
|
--terminal = "x-terminal-emulator"
|
||||||
terminal = "lxterminal"
|
terminal = "terminology"
|
||||||
editor = os.getenv("EDITOR") or "editor"
|
editor = os.getenv("EDITOR") or "editor"
|
||||||
editor_cmd = terminal .. " -e " .. editor
|
editor_cmd = terminal .. " -e " .. editor
|
||||||
|
|
||||||
@@ -243,6 +247,7 @@ awful.screen.connect_for_each_screen(function(s)
|
|||||||
{ -- Right widgets
|
{ -- Right widgets
|
||||||
layout = wibox.layout.fixed.horizontal,
|
layout = wibox.layout.fixed.horizontal,
|
||||||
--mykeyboardlayout,
|
--mykeyboardlayout,
|
||||||
|
clipdate.widget,
|
||||||
wibox.widget.systray(),
|
wibox.widget.systray(),
|
||||||
battery.widget,
|
battery.widget,
|
||||||
mytextclock --[[, XXX11
|
mytextclock --[[, XXX11
|
||||||
|
|||||||
Reference in New Issue
Block a user