From 89d629bdda60b43e0720d110f6d344231ad7663d Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 5 Apr 2022 20:23:17 +0000 Subject: [PATCH] reload stylesheet on change --- blinkenlicht/blinkenlicht.fnl | 39 +++++++++++++++++++++++++++-------- blinkenlicht/licht.css | 18 +++++++++------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/blinkenlicht/blinkenlicht.fnl b/blinkenlicht/blinkenlicht.fnl index 67fd1cb..79973d3 100644 --- a/blinkenlicht/blinkenlicht.fnl +++ b/blinkenlicht/blinkenlicht.fnl @@ -2,6 +2,7 @@ : GtkLayerShell : Gdk : GdkPixbuf + : Gio : GLib : cairo } (require :lgi)) @@ -13,16 +14,35 @@ (local HEIGHT 48) +(local css-provider + (let [p (Gtk.CssProvider)] + (Gtk.StyleContext.add_provider_for_screen + (Gdk.Screen.get_default) + p + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) + p)) + (fn load-styles [pathname] - (let [style-provider (Gtk.CssProvider) - (success err) (style-provider:load_from_path pathname)] - (if success - (Gtk.StyleContext.add_provider_for_screen - (Gdk.Screen.get_default) - style-provider - Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) + (let [(success err) (css-provider:load_from_path pathname)] + (or success (print "failed to load stylesheet" err)))) +(var file-monitor nil) +(fn watch-stylesheet [pathname] + (let [f (Gio.File.new_for_path pathname) + (monitor err) + (Gio.File.monitor f Gio.FileMonitorFlags.NONE nil)] + (load-styles pathname) + (if (not monitor) (print :watch-stylesheet err)) + (set file-monitor monitor) + (doto monitor + (tset + :on_changed + #(print "changed " + (load-styles (: $2 :get_path))))))) + + + (fn resolve [f] (match (type f) "string" f @@ -184,7 +204,7 @@ (each [_ b (ipairs bars)] (make-layer-shell b.window :top true (collect [_ edge (ipairs b.anchor)] - edge 1)) + edge 0)) (b.window:show_all)) (Gtk.main)) @@ -192,5 +212,6 @@ : bar : indicator : run - :stylesheet load-styles + :stylesheet watch-stylesheet + : file-monitor ;don't let this get GCed } diff --git a/blinkenlicht/licht.css b/blinkenlicht/licht.css index 015f978..4d0047f 100644 --- a/blinkenlicht/licht.css +++ b/blinkenlicht/licht.css @@ -1,13 +1,15 @@ .indicator { - background-color: #ff00ff; -} -.indicator.yellow { - background-color: #ff0; + color: #eef; + background-color: #000; + font-size: 11px; } -box.hey { - font-size: 18px; +.indicator * { + margin: 5px 8px; + padding: 5px 5px; + background-color: #225; } -label { - margin: 0px 12px; + +.bar { + background-color: #000; }