awesome/widget/textclock.fnl

44 lines
1.1 KiB
Plaintext
Raw Normal View History

;;; 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))
font (or font beautiful.textclock_font beautiful.font)
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