mirror of
https://github.com/JakeStanger/ironbar.git
synced 2024-11-23 08:11:48 +03:00
feat(ipc): support for injecting additional stylesheets
This commit is contained in:
parent
ded50cca6f
commit
c6319b78fd
@ -27,4 +27,11 @@ pub enum Command {
|
||||
/// Variable key.
|
||||
key: Box<str>,
|
||||
},
|
||||
|
||||
/// Load an additional CSS stylesheet.
|
||||
/// The sheet is automatically hot-reloaded.
|
||||
LoadCss {
|
||||
/// The path to the sheet.
|
||||
path: PathBuf,
|
||||
},
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ use super::Ipc;
|
||||
use crate::bridge_channel::BridgeChannel;
|
||||
use crate::ipc::{Command, Response};
|
||||
use crate::ironvar::get_variable_manager;
|
||||
use crate::style::load_css;
|
||||
use crate::{read_lock, send_async, try_send, write_lock};
|
||||
use color_eyre::{Report, Result};
|
||||
use glib::Continue;
|
||||
@ -106,7 +107,7 @@ impl Ipc {
|
||||
Command::Inspect => {
|
||||
gtk::Window::set_interactive_debugging(true);
|
||||
Response::Ok
|
||||
},
|
||||
}
|
||||
Command::Set { key, value } => {
|
||||
let variable_manager = get_variable_manager();
|
||||
let mut variable_manager = write_lock!(variable_manager);
|
||||
@ -123,6 +124,14 @@ impl Ipc {
|
||||
None => Response::error("Variable not found"),
|
||||
}
|
||||
}
|
||||
Command::LoadCss { path } => {
|
||||
if path.exists() {
|
||||
load_css(path);
|
||||
Response::Ok
|
||||
} else {
|
||||
Response::error("File not found")
|
||||
}
|
||||
}
|
||||
Command::Ping => Response::Ok,
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::send;
|
||||
use color_eyre::{Help, Report};
|
||||
use glib::Continue;
|
||||
use gtk::ffi::GTK_STYLE_PROVIDER_PRIORITY_USER;
|
||||
use gtk::prelude::CssProviderExt;
|
||||
use gtk::{gdk, gio, CssProvider, StyleContext};
|
||||
use notify::event::{DataChange, ModifyKind};
|
||||
@ -29,7 +30,11 @@ pub fn load_css(style_path: PathBuf) {
|
||||
};
|
||||
|
||||
let screen = gdk::Screen::default().expect("Failed to get default GTK screen");
|
||||
StyleContext::add_provider_for_screen(&screen, &provider, 800);
|
||||
StyleContext::add_provider_for_screen(
|
||||
&screen,
|
||||
&provider,
|
||||
GTK_STYLE_PROVIDER_PRIORITY_USER as u32,
|
||||
);
|
||||
|
||||
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user