2019-01-15 15:14:29 +11:00
|
|
|
;;; widget/textclock.fnl --- Configurable text clock widget
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; More modular than the standard library
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(local beautiful (require :beautiful))
|
|
|
|
(local gears (require :gears))
|
|
|
|
(local glib (. (require :lgi) :GLib))
|
|
|
|
(local wibox (require :wibox))
|
|
|
|
(local DateTime glib.DateTime)
|
|
|
|
(local TimeZone glib.TimeZone)
|
|
|
|
|
|
|
|
;;;
|
|
|
|
;; Functions
|
|
|
|
|
|
|
|
(fn calc-timeout [real-timeout]
|
|
|
|
(% (- real-timeout (os.time)) real-timeout))
|
|
|
|
|
|
|
|
(fn textclock [format timeout timezone font]
|
|
|
|
(let [format (or format " %a %b %d, %H:%M ")
|
|
|
|
timeout (or timeout 60)
|
|
|
|
timezone (or (and timezone (TimeZone.new timezone))
|
|
|
|
(TimeZone.new_local))
|
2019-01-15 21:34:04 +11:00
|
|
|
font (or font beautiful.textclock_font beautiful.font)
|
2019-01-15 15:14:29 +11:00
|
|
|
w (wibox.widget.textbox)]
|
|
|
|
(var t nil)
|
|
|
|
|
|
|
|
(tset w :font font)
|
|
|
|
|
|
|
|
(fn w._private.textclock_update_cb []
|
|
|
|
(: w :set_markup (: (DateTime.new_now timezone) :format format))
|
|
|
|
(tset t :timeout (calc-timeout timeout))
|
|
|
|
(: t :again)
|
|
|
|
true)
|
|
|
|
|
|
|
|
(set t (gears.timer.weak_start_new timeout w._private.textclock_update_cb))
|
|
|
|
(: t :emit_signal :timeout)
|
|
|
|
w))
|
|
|
|
|
|
|
|
textclock
|
|
|
|
;;; widget/textclock.fnl ends here
|