Expand description
A crate that allows Waybar modules to be built in Rust.
Waybar modules are written using its experimental CFFI module interface, and implement their UI using Gtk 3. Modules are built as a shared library that is loaded by Waybar at runtime.
This version of the bindings was built against Waybar version 0.12.0.
§Example
Implementing a module is done by implementing the Module trait, and then
calling waybar_module to export the required symbols from the shared
library:
use serde::Deserialize;
use waybar_cffi::{
gtk::{prelude::ContainerExt, Label},
waybar_module, InitInfo, Module,
};
struct HelloWorld;
impl Module for HelloWorld {
type Config = Config;
fn init(info: &InitInfo, config: Config) -> Self {
let container = info.get_root_widget();
let label = Label::new(Some(&format!(
"Hello {}!",
config.name.as_deref().unwrap_or("World")
)));
container.add(&label);
HelloWorld
}
}
waybar_module!(HelloWorld);
#[derive(Deserialize)]
struct Config {
name: Option<String>,
}This example is also available in examples/hello-world.rs, and can be built and run with:
$ cargo build --example hello-world
$ waybar -c examples/hello-world.json§Gtk
Waybar still uses Gtk 3 for its UI, so modules are required to also use it.
This crate re-exports the gtk crate, and it is strongly suggested that
you use this re-export, rather than including gtk as a dependency in your
own crate.
§Async
If you need async functionality, you should use
glib::MainContext as the reactor via methods
like MainContext::spawn_local,
rather than trying to start up a new async runtime. This will ensure that
your module integrates properly with the main Waybar event loop.
Re-exports§
pub use waybar_cffi_sys::gtk;
Macros§
- waybar_
module - Defines and exports the C functions required for the module to be used by Waybar.
Structs§
- Init
Info - Metadata provided by Waybar when initialising a module.
Traits§
- Module
- A Waybar CFFI module.