eww/crates/notifier_host/src/lib.rs
Temmie 1b819fb646
System Tray (#743)
* Allow tokio on gtk thread

* Basic notifier host implementation

* Implement systray widget

* Use dbusmenu-gtk3

* Update flake.nix

* US spelling of license

* Fix possible TOCTOU

* Change how hosts are started

* Add watcher

* Bunch of refactor

* Handle errors better

* Refactor service parsing

* Avoid duplicate dbus connections

* Fix watcher producing bad items

* Handle zbus::Error::NameTaken

* Refactor icon loading & don't panic on zoom

* Implement pixbuf icons

Co-authored-by: Bojan Nemčić <bnemcic@gmail.com>

* Don't panic on icon/menu error

* Improve icon error handling to make discord work

* Update comments

* Big refactor into actor model

* Reword error messages

* Remove redundant watcher_on function

* Big icon handling refactor

* Don't unnecessarily wrap StatusNotifierItem

* cargo fmt

* Documentation

* Avoid registering to StatusNotifierWatcher multiple times

* None theme means default theme

* Add dbus logging

* Add libdbusmenu-gtk3 dependency to docs

* Some code tidying

* Make Item more clearer

* Make clippy happy

* Systray widget improvements

* Remove unwraps from dbus state

* Temporarily add libdbusmenu-gtk3 to flake buildInputs

* Fix blurry tray icon for HiDPI display

* feat: dynamic icons

* fix: don't cache IconPixmap property

this fixes dynamic icons for some icons, e.g. syncthingtray

* fixup! feat: dynamic icons

* Fix unused borrow warning

* Add some documentation to notifier_host

* Rename notifier_host::dbus to more descriptive notifier_host::proxy

* fixup! Rename notifier_host::dbus to more descriptive notifier_host::proxy

* fixup! Merge remote-tracking branch 'upstream/master' into tray-3

* fixup! Merge remote-tracking branch 'upstream/master' into tray-3

* Remove commented out fields of DBusSession

* Refactor host

* Remove git conflict marker

* Various improvements

* Icon documentation

* cargo fmt

* Add dependency to CI

---------

Co-authored-by: Bojan Nemčić <bnemcic@gmail.com>
Co-authored-by: MoetaYuko <loli@yuko.moe>
Co-authored-by: hylo <hylo@posteo.de>
2024-03-30 10:55:01 +01:00

52 lines
2.1 KiB
Rust

//! The system tray side of the [notifier host DBus
//! protocols](https://freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierHost/),
//! implementing most of the relevant DBus protocol logic so system tray implementations (e.g. eww)
//! don't need to care about them.
//!
//! This crate does not implement the tray icon side of the protocol. For that, see, for example,
//! the [ksni](https://crates.io/crates/ksni) crate.
//!
//! # Overview / Notes for Contributors
//!
//! This crate makes extensive use of the `zbus` library to interact with DBus. You should read
//! through the [zbus tutorial](https://dbus2.github.io/zbus/) if you aren't familiar with DBus or
//! `zbus`.
//!
//! There are two separate services that are required for the tray side of the protocol:
//!
//! - `StatusNotifierWatcher`, a service which tracks what items and trays there are but doesn't do
//! any rendering. This is implemented by [`Watcher`] (see that for further details), and
//! should always be started alongside the `StatusNotifierHost`.
//!
//! - `StatusNotifierHost`, the actual tray, which registers itself to the StatusNotifierHost and
//! subscribes to its signals to know what items exist. This DBus service has a completely
//! empty interface, but is mainly by StatusNotifierWatcher to know when trays disappear. This
//! is represented by the [`Host`] trait.
//!
//! The actual tray implements the [`Host`] trait to be notified of when items (called
//! `StatusNotifierItem` in the spec and represented by [`Item`]) appear and disappear, then calls
//! [`run_host`] to run the DBus side of the protocol.
//!
//! If there are multiple trays running on the system, there can be multiple `StatusNotifierHost`s,
//! but only one `StatusNotifierWatcher` (usually from whatever tray was started first).
pub mod proxy;
mod host;
pub use host::*;
mod icon;
pub use icon::*;
mod item;
pub use item::*;
mod watcher;
pub use watcher::*;
pub(crate) mod names {
pub const WATCHER_BUS: &str = "org.kde.StatusNotifierWatcher";
pub const WATCHER_OBJECT: &str = "/StatusNotifierWatcher";
pub const ITEM_OBJECT: &str = "/StatusNotifierItem";
}