support user stylesheet and customisable css class names
This commit is contained in:
parent
c687b4d3b8
commit
fcd5aee103
@ -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.
|
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`
|
* blinkenlicht.fnl is the module that parses `bar` and `indicator`
|
||||||
forms and does all the UI
|
forms and does all the UI
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
(local {: bar : indicator : run} (require :blinkenlicht))
|
(local {: bar : indicator : stylesheet : run} (require :blinkenlicht))
|
||||||
|
|
||||||
|
(stylesheet "licht.css")
|
||||||
|
|
||||||
(fn loadavg []
|
(fn loadavg []
|
||||||
(with-open [f (io.open "/proc/loadavg" :r)]
|
(with-open [f (io.open "/proc/loadavg" :r)]
|
||||||
@ -34,6 +36,7 @@
|
|||||||
{
|
{
|
||||||
:anchor [:top :right]
|
:anchor [:top :right]
|
||||||
:orientation :horizontal
|
:orientation :horizontal
|
||||||
|
:classes ["hey"]
|
||||||
:indicators
|
:indicators
|
||||||
[
|
[
|
||||||
(indicator {
|
(indicator {
|
||||||
@ -47,6 +50,7 @@
|
|||||||
;; }))
|
;; }))
|
||||||
(indicator {
|
(indicator {
|
||||||
:interval (* 10 1000)
|
:interval (* 10 1000)
|
||||||
|
:classes ["yellow"]
|
||||||
:text #(let [{:power-supply-energy-full full
|
:text #(let [{:power-supply-energy-full full
|
||||||
:power-supply-energy-now now
|
:power-supply-energy-now now
|
||||||
:power-supply-status status} (battery-status)
|
:power-supply-status status} (battery-status)
|
||||||
|
@ -11,6 +11,14 @@
|
|||||||
|
|
||||||
(local HEIGHT 48)
|
(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]
|
(fn resolve [f]
|
||||||
(match (type f)
|
(match (type f)
|
||||||
"string" f
|
"string" f
|
||||||
@ -57,13 +65,21 @@
|
|||||||
(button:show_all)
|
(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
|
(fn indicator [{: interval
|
||||||
: icon
|
: icon
|
||||||
: poll
|
: poll
|
||||||
: text
|
: text
|
||||||
|
: classes
|
||||||
: on-click}]
|
: on-click}]
|
||||||
(var last-update -1)
|
(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]
|
update (fn [now]
|
||||||
(when (and interval (> now (+ last-update interval)))
|
(when (and interval (> now (+ last-update interval)))
|
||||||
(update-button button icon text)
|
(update-button button icon text)
|
||||||
@ -96,12 +112,16 @@
|
|||||||
|
|
||||||
(local bars [])
|
(local bars [])
|
||||||
|
|
||||||
(fn bar [{ : anchor : orientation : indicators }]
|
(fn bar [{ : anchor : orientation : indicators : classes }]
|
||||||
(let [window (Gtk.Window {} )
|
(let [window (Gtk.Window {} )
|
||||||
orientation (match orientation
|
orientation (match orientation
|
||||||
:vertical Gtk.Orientation.VERTICAL
|
:vertical Gtk.Orientation.VERTICAL
|
||||||
:horizontal Gtk.Orientation.HORIZONTAL)
|
:horizontal Gtk.Orientation.HORIZONTAL)
|
||||||
box (Gtk.Box { :orientation orientation})]
|
box (Gtk.Box { :orientation orientation})]
|
||||||
|
(doto box
|
||||||
|
(add-css-classes ["bar"])
|
||||||
|
(add-css-classes (or classes [])))
|
||||||
|
|
||||||
(table.insert bars { : window : anchor : indicators })
|
(table.insert bars { : window : anchor : indicators })
|
||||||
(each [_ i (ipairs indicators)]
|
(each [_ i (ipairs indicators)]
|
||||||
(box:pack_start i.button false false 0))
|
(box:pack_start i.button false false 0))
|
||||||
@ -132,4 +152,5 @@
|
|||||||
: bar
|
: bar
|
||||||
: indicator
|
: indicator
|
||||||
: run
|
: run
|
||||||
|
:stylesheet load-styles
|
||||||
}
|
}
|
||||||
|
10
blinkenlicht/licht.css
Normal file
10
blinkenlicht/licht.css
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.indicator {
|
||||||
|
background-color: #ff00ff;
|
||||||
|
}
|
||||||
|
.indicator.yellow {
|
||||||
|
background-color: #ff0;
|
||||||
|
}
|
||||||
|
|
||||||
|
box.hey {
|
||||||
|
font-size: 18px;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user