mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-03 03:31:03 +02:00
feat: new cairo module
Resolves #105 Co-authored-by: A-Cloud-Ninja <5809177+A-Cloud-Ninja@users.noreply.github.com>
This commit is contained in:
parent
7b089495ad
commit
b0a05b7cda
13 changed files with 587 additions and 21 deletions
41
src/clients/lua.rs
Normal file
41
src/clients/lua.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
use mlua::Lua;
|
||||
use std::ops::Deref;
|
||||
use std::path::Path;
|
||||
use tracing::{debug, error};
|
||||
|
||||
/// Wrapper around Lua instance
|
||||
/// to create a singleton and handle initialization.
|
||||
#[derive(Debug)]
|
||||
pub struct LuaEngine {
|
||||
lua: Lua,
|
||||
}
|
||||
|
||||
impl LuaEngine {
|
||||
pub fn new(config_dir: &Path) -> Self {
|
||||
let lua = unsafe { Lua::unsafe_new() };
|
||||
|
||||
let user_init = config_dir.join("init.lua");
|
||||
if user_init.exists() {
|
||||
debug!("loading user init script");
|
||||
|
||||
if let Err(err) = lua.load(user_init).exec() {
|
||||
error!("{err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
debug!("loading internal init script");
|
||||
if let Err(err) = lua.load(include_str!("../../lua/init.lua")).exec() {
|
||||
error!("{err:?}");
|
||||
}
|
||||
|
||||
Self { lua }
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for LuaEngine {
|
||||
type Target = Lua;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.lua
|
||||
}
|
||||
}
|
|
@ -1,11 +1,15 @@
|
|||
use crate::{await_sync, Ironbar};
|
||||
use color_eyre::Result;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[cfg(feature = "clipboard")]
|
||||
pub mod clipboard;
|
||||
#[cfg(feature = "workspaces")]
|
||||
pub mod compositor;
|
||||
#[cfg(feature = "cairo")]
|
||||
pub mod lua;
|
||||
#[cfg(feature = "music")]
|
||||
pub mod music;
|
||||
#[cfg(feature = "notifications")]
|
||||
|
@ -27,6 +31,8 @@ pub struct Clients {
|
|||
workspaces: Option<Arc<dyn compositor::WorkspaceClient>>,
|
||||
#[cfg(feature = "clipboard")]
|
||||
clipboard: Option<Arc<clipboard::Client>>,
|
||||
#[cfg(feature = "cairo")]
|
||||
lua: Option<Rc<lua::LuaEngine>>,
|
||||
#[cfg(feature = "music")]
|
||||
music: std::collections::HashMap<music::ClientType, Arc<dyn music::MusicClient>>,
|
||||
#[cfg(feature = "notifications")]
|
||||
|
@ -75,6 +81,13 @@ impl Clients {
|
|||
Ok(client)
|
||||
}
|
||||
|
||||
#[cfg(feature = "cairo")]
|
||||
pub fn lua(&mut self, config_dir: &Path) -> Rc<lua::LuaEngine> {
|
||||
self.lua
|
||||
.get_or_insert_with(|| Rc::new(lua::LuaEngine::new(config_dir)))
|
||||
.clone()
|
||||
}
|
||||
|
||||
#[cfg(feature = "music")]
|
||||
pub fn music(&mut self, client_type: music::ClientType) -> Arc<dyn music::MusicClient> {
|
||||
self.music
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue