diff --git a/blinkenlicht/README.md b/blinkenlicht/README.md index b950ab6..b1ea491 100644 --- a/blinkenlicht/README.md +++ b/blinkenlicht/README.md @@ -12,7 +12,7 @@ you are happy to exert that control in a Lua-based Lisp language. Not quite dogfood-ready yet, but fast approaching. -* bl.fnl is an example +* bl.fnl is an example, using licht.css for its styling * blinkenlicht.fnl is the module that parses `bar` and `indicator` forms and does all the UI diff --git a/blinkenlicht/bl.fnl b/blinkenlicht/bl.fnl index c9fc6e5..db42e6f 100644 --- a/blinkenlicht/bl.fnl +++ b/blinkenlicht/bl.fnl @@ -1,4 +1,6 @@ -(local {: bar : indicator : run} (require :blinkenlicht)) +(local {: bar : indicator : stylesheet : run} (require :blinkenlicht)) + +(stylesheet "licht.css") (fn loadavg [] (with-open [f (io.open "/proc/loadavg" :r)] @@ -34,6 +36,7 @@ { :anchor [:top :right] :orientation :horizontal + :classes ["hey"] :indicators [ (indicator { @@ -47,6 +50,7 @@ ;; })) (indicator { :interval (* 10 1000) + :classes ["yellow"] :text #(let [{:power-supply-energy-full full :power-supply-energy-now now :power-supply-status status} (battery-status) diff --git a/blinkenlicht/blinkenlicht.fnl b/blinkenlicht/blinkenlicht.fnl index 93f15d3..6082ff4 100644 --- a/blinkenlicht/blinkenlicht.fnl +++ b/blinkenlicht/blinkenlicht.fnl @@ -11,6 +11,14 @@ (local HEIGHT 48) +(fn load-styles [pathname] + (let [style-provider (Gtk.CssProvider)] + (style-provider:load_from_path pathname) + (Gtk.StyleContext.add_provider_for_screen + (Gdk.Screen.get_default) + style-provider + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION))) + (fn resolve [f] (match (type f) "string" f @@ -57,13 +65,21 @@ (button:show_all) )) +(fn add-css-classes [widget classes] + (let [context (widget:get_style_context)] + (each [_ c (ipairs classes)] + (context:add_class c)))) + (fn indicator [{: interval : icon : poll : text + : classes : on-click}] (var last-update -1) - (let [button (Gtk.Button { :relief Gtk.ReliefStyle.NONE}) + (let [button (doto (Gtk.Button { :relief Gtk.ReliefStyle.NONE}) + (add-css-classes ["indicator"]) + (add-css-classes (or classes []))) update (fn [now] (when (and interval (> now (+ last-update interval))) (update-button button icon text) @@ -96,12 +112,16 @@ (local bars []) -(fn bar [{ : anchor : orientation : indicators }] +(fn bar [{ : anchor : orientation : indicators : classes }] (let [window (Gtk.Window {} ) orientation (match orientation :vertical Gtk.Orientation.VERTICAL :horizontal Gtk.Orientation.HORIZONTAL) box (Gtk.Box { :orientation orientation})] + (doto box + (add-css-classes ["bar"]) + (add-css-classes (or classes []))) + (table.insert bars { : window : anchor : indicators }) (each [_ i (ipairs indicators)] (box:pack_start i.button false false 0)) @@ -132,4 +152,5 @@ : bar : indicator : run + :stylesheet load-styles } diff --git a/blinkenlicht/licht.css b/blinkenlicht/licht.css new file mode 100644 index 0000000..d0c5f99 --- /dev/null +++ b/blinkenlicht/licht.css @@ -0,0 +1,10 @@ +.indicator { + background-color: #ff00ff; +} +.indicator.yellow { + background-color: #ff0; +} + +box.hey { + font-size: 18px; +}