#waybar #module #c-ffi #bindings #low #level #gtk

waybar-cffi-sys

Low level bindings used when creating a Waybar CFFI module

2 releases

new 0.1.1 Mar 6, 2025
0.1.0 Mar 6, 2025

#849 in GUI

38 downloads per month
Used in 2 crates (via waybar-cffi)

MIT license

13KB
192 lines

waybar-cffi

This provides Rust bindings to create CFFI modules for Waybar.

Waybar CFFI modules are shared libraries that provide modules that can be included in a Waybar. These can use the full capabilities of Gtk 3 and, more generally, native code.

Quick start

Creating and using a CFFI module is (relatively) easy.

  1. Create a cdylib crate:

    [package]
    name = "my-module-name"
    version = "0.1.0"
    edition = "2024"
    
    [lib]
    crate-type = ["cdylib"]
    
    [dependencies]
    waybar-cffi = "0.1.0"
    
  2. Implement the waybar_cffi::Module trait on a type, and use the waybar_cffi::waybar_module macro to export the required symbols. (See the hello world example or the documentation for more detail.)

  3. Build in the normal way with cargo build.

  4. Configure waybar per the CFFI instructions:

    {
      "modules-left": ["cffi/my-module-name"],
      "cffi/my-module-name": {
        "module-path": "target/debug/libmy_module_name.so"
      }
    }
    
  5. Profit!

Refer to the waybar-cffi documentation for more details.

Development

Honestly, I probably won't be devoting a tonne of time to this in the near future, but I'm definitely open to PRs.

Layout

This workspace contains two crates:

Updating bindings

New Waybar versions will likely require the bindings to be updated. This can be done by running make clean && make ffi WAYBAR_ROOT=path/to/Waybar.

Note that a full Waybar checkout is currently required as the CFFI header isn't shipped in the release packages.

Smoke tests

make hello-world will build the hello world example and run Waybar with two instances of it configured.

Dependencies

~17MB
~413K SLoC