mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-02 11:11:04 +02:00
chore: initial commit
This commit is contained in:
commit
e37d8f2b14
36 changed files with 4948 additions and 0 deletions
47
src/style.rs
Normal file
47
src/style.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
use glib::Continue;
|
||||
use gtk::prelude::CssProviderExt;
|
||||
use gtk::{gdk, gio, CssProvider, StyleContext};
|
||||
use notify::{DebouncedEvent, RecursiveMode, Watcher};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::mpsc;
|
||||
use std::time::Duration;
|
||||
use tokio::spawn;
|
||||
|
||||
pub fn load_css(style_path: PathBuf) {
|
||||
let provider = CssProvider::new();
|
||||
provider
|
||||
.load_from_file(&gio::File::for_path(&style_path))
|
||||
.expect("Couldn't load custom style");
|
||||
StyleContext::add_provider_for_screen(
|
||||
&gdk::Screen::default().expect("Couldn't get default GDK screen"),
|
||||
&provider,
|
||||
800,
|
||||
);
|
||||
|
||||
let (watcher_tx, watcher_rx) = mpsc::channel::<DebouncedEvent>();
|
||||
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||
|
||||
spawn(async move {
|
||||
let mut watcher = notify::watcher(watcher_tx, Duration::from_millis(500)).unwrap();
|
||||
watcher
|
||||
.watch(&style_path, RecursiveMode::NonRecursive)
|
||||
.unwrap();
|
||||
|
||||
loop {
|
||||
if let Ok(DebouncedEvent::Write(path)) = watcher_rx.recv() {
|
||||
tx.send(path).unwrap();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
{
|
||||
rx.attach(None, move |path| {
|
||||
println!("Reloading CSS");
|
||||
provider
|
||||
.load_from_file(&gio::File::for_path(path))
|
||||
.expect("Couldn't load custom style");
|
||||
|
||||
Continue(true)
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue