Rust bindings for libnotify
This crate exposes a user friendly (at least I hope), Rust api for libnotify. Made using bindgen.
Structure
Project is split into two modules:
- functions
- notifications
Which resembles libnotify structure. Every function is named similarly to its libnotify counterpart and it does the same things.
There are some helper structs and enums to make it more approachable to rust folks.
Documentation
Available at github pages;
Add to project
Type in:
cargo add --git "https://github.com/szymon-jozef/libnotify-rs"
Dependencies
To use this crate you need to have installed:
- libnotify, duh (version 0.8.8 >= is supported)
- clang for bindgen
- pkg-config, to find the above
Examples
Refer to examples dir
Sneak peek for making a notification:
use libnotify_rs::{
functions::{init, uninit},
notification::Notification,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
init("I love coffee")?;
let mut notify = Notification::new(
"Remember to drink coffe!",
"Coffee is very important for your mental health!",
None,
)?;
notify.set_timeout(libnotify_rs::notification::Timeout::Custom(1000 * 10)); // 10 secs
notify.set_urgency(libnotify_rs::notification::Urgency::Critical); // coffee is very important
notify.set_category("Coffee")?;
notify.show()?;
uninit();
Ok(())
}
To test those examples use:
cargo r --example <example name>
Why?
Why write this when there is already rust-libnotify?
Two reasons:
- That crate is really, really old. Almost a decade old, as of now. This crate is not old.
- Rust-libnotify doesn't support setting callbacks.
I decided to write these bindings, when I thought the original doesn't support settings notification urgency level. Then I realised it did, but the project was fun, so I decided to finish it.
Why not notify-rust? Well, I found it yesterday, that's why. But it looks great! You should definitely check it out. This crate is just a thin wrapper around libnotify c-calls.
AI use
AI was used only for two things:
- Code review
- As a faster search engine
It didn't write any of the actual code, nor any documentation.
Roadmap
I will be happy to fix any bugs that you may find! Just create a new issue, or better yet a pull request.
I'm thinking about a small wrapper around other code, which would initialize libnotify by itself, cleanup after itself, etc. Maybe someday…