[−][src]Crate cnx
A simple X11 status bar for use with simple WMs.
Cnx is written to be customisable, simple and fast. Where possible, it
prefers to asynchronously wait for changes in the underlying data sources
(and uses mio
/tokio
to achieve this), rather than periodically
calling out to external programs.
How to use
Cnx is a library that allows you to make your own status bar.
In normal usage, you will create a new binary project that relies on the
cnx
crate, and customize it through options passed to the main Cnx
object and its widgets. (It's inspired by QTile
and dwm
, in that the
configuration is done entirely in code, allowing greater extensibility
without needing complex configuration handling).
An simple example of a binary using Cnx is:
#[macro_use] extern crate cnx; use cnx::*; use cnx::text::*; use cnx::widgets::*; fn main() -> Result<()> { let attr = Attributes { font: Font::new("SourceCodePro 21"), fg_color: Color::white(), bg_color: None, padding: Padding::new(8.0, 8.0, 0.0, 0.0), }; let mut cnx = Cnx::new(Position::Top)?; cnx_add_widget!(cnx, ActiveWindowTitle::new(&cnx, attr.clone())); cnx_add_widget!(cnx, Clock::new(&cnx, attr.clone())); Ok(cnx.run()?) }
A more complex example is given in src/bin/cnx.rs
alongside the project.
(This is the default [bin]
target for the crate, so you could use it by
either executing cargo run
from the crate root, or even running cargo install cnx; cnx
. However, neither of these are recommended as options for
customizing Cnx are then limited).
Before running Cnx, you'll need to make sure your system has the required
dependencies, which are described in the README
.
Built-in widgets
There are currently these widgets available:
Active Window Title
— Shows the title (EWMH
's_NET_WM_NAME
) for the currently focused window (EWMH
's_NEW_ACTIVE_WINDOW
).Pager
— Shows the WM's workspaces/groups, highlighting whichever is currently active. (UsesEWMH
's_NET_DESKTOP_NAMES
,_NET_NUMBER_OF_DESKTOPS
and_NET_CURRENT_DESKTOP
).Sensors
— Periodically parses and displays the output of thelm_sensors
utility, allowing CPU temperature to be displayed.Volume
— Usesalsa-lib
to show the current volume/mute status of the default output device. (Disable by removing default featurevolume-control
).Battery
— Uses/sys/class/power_supply/
to show details on the remaining battery and charge status.Clock
— Shows the time.
Dependencies
In addition to the Rust dependencies in Cargo.toml
, Cnx also depends on
these system libraries:
xcb-util
:xcb-ewmh
/xcb-icccm
/xcb-keysyms
x11-xcb
pango
cairo
pangocairo
Some widgets have additional dependencies:
Volume
widget relies onalsa-lib
Sensors
widget relies onlm_sensors
being installed.
Creating new widgets
Cnx is designed such that thirdparty widgets can be written in external
crates and used with the main Cnx
instance. However, this API is
currently very unstable and isn't recommended.
The adventurous may choose to ignore this warning and look into the
documentation of the Widget
trait. The built-in widgets
should give you
some examples on which to base your work.
Re-exports
pub use crate::widgets::Widget; |
Modules
text | |
widgets | Built-in widgets |
Macros
cnx_add_widget | Adds a |
Structs
Cnx | The main object, used to instantiate an instance of Cnx. |
Enums
Position | An enum specifying the position of the Cnx bar. |
Type Definitions
Result |