Commits

Nikolaj Sjujskij  committed 8a3aaea

widgets: implement convoluted textclock

  • Participants
  • Parent commits 8560a51

Comments (0)

Files changed (2)

 -- }}}
 
 -- {{{ Wibox
--- Create a textclock widget
-mytextclock = awful.widget.textclock(" %a, %d %b | %H:%M ", 13)
 
 -- Keyboard layout widget
 kbdwidget = wibox.widget.textbox()
     local right_layout = wibox.layout.fixed.horizontal()
     if s == 1 then right_layout:add(wibox.widget.systray()) end
     right_layout:add(kbdwidget)
-    right_layout:add(mytextclock)
+    right_layout:add(widgets.mytextclock)
     right_layout:add(mylayoutbox[s])
     for _, wdgt in pairs(custom_widgets) do
         right_layout:add(wdgt)
 local beautiful = require("beautiful")
 local awful = require("awful")
 local gears = require("gears")
+local os = os
+local tonumber = tonumber
 local widget_fun = require("widget_fun")
 local vicious = require("vicious")
 module("widgets")
 cpubar:set_ticks(true)
 vicious.register(cpubar, vicious.widgets.cpu, "$1", 1)
 
+-- Correct textclock, updated only when needed
+mytextclock = wibox.widget.textbox()
+local format = " %a, %d %b | %H:%M "
+mytextclock.set_time = function() mytextclock:set_markup(os.date(format)) end
+mytextclock.set_time()
+local secs = 60 - tonumber(os.date("%S"))
+mytextclock.timer = timer { timeout = secs }
+mytextclock.timer:connect_signal("timeout", function()
+                            mytextclock.set_time()
+                            mytextclock.timer:stop()
+                            mytextclock.timer = timer { timeout = 60 }
+                            mytextclock.timer:connect_signal("timeout",
+                                                        mytextclock.set_time)
+                            mytextclock.timer:start() end
+                            )
+mytextclock.timer:start()
+
 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80