Crates.io | bspc_rust_lib |
lib.rs | bspc_rust_lib |
version | 0.2.0 |
source | src |
created_at | 2024-08-30 09:58:43.211833 |
updated_at | 2024-09-14 16:15:22.342591 |
description | A library that allows bspc commands to be executed through rust programs |
homepage | |
repository | https://github.com/BenKenobie31415/bspc_rust_lib |
max_upload_size | |
id | 1357545 |
size | 70,655 |
The goal of this library is to offer a nice way to use as many bspc feature as possible through rust. This is a project I do because I use bspwm and want to practice rust. If you have something to contribute or discover an issue, please use the github-repo to contact me.
In general: The man pages for bspc are a bit lackluster and I couldn't find really good explainations some things. For example, I don't fully understand how the order in which constraints for nodes/desktops/monitors are set in queries affects the result, only that it does. So again, if I did something dumb and you notice, please let me know.
use bspc_rust_lib::bspc::{events::Event, node::{descriptor::NodeDescriptor, selector::NodeSelector}, query::QueryCommand, selector::Selector, subscription::SubscriptionHandler};
fn main() {
let mut sub_handler = SubscriptionHandler::new();
sub_handler.subscribe(Event::NodeAdd, callback, "added node", 0);
sub_handler.subscribe(Event::DesktopFocus, callback2, 73, 3);
sub_handler.await_threads();
}
fn callback(payload: Vec<&str>, callback_args: &&str) {
let prev_node = QueryCommand::CNodes(NodeSelector::new()
.set_reference_selector(NodeSelector::new().set_descriptor(NodeDescriptor::Focused))
.set_descriptor(NodeDescriptor::Last)).get_response();
println!("previously focused node: {:?}", prev_node);
println!("added node: {}", payload[Event::NodeAdd.get_payload_count() - 1]);
println!("callback_args: {:?}", callback_args);
}
fn callback2(payload: Vec<&str>, callback_args: &i32) {
println!("payload: {:?}", payload);
println!("callback_args: {:?}", callback_args);
}
This program runs the callback callback
each time a node gets added and passes the string "added node" to it.
callback
:
This program also runs the callback callback2
each time a new desktop gets focused for a total of 3 times and passes the i32
73
to it.
callback2
:
desktop_focus
event ("man bspc" section Events
-> [<monitor_id>, <desktop_id>]).73
).let windows = QueryCommand::Nodes(
Some(NodeSelector::new().add_modifier(NodeModifier::Window)),
Some(DesktopSelector::new().set_descriptor(DesktopDescriptor::Focused)),
None).get_response();
println!("{:?}", util::get_node_classes_from_id_list(&windows));
}
This snippet:
window_class_names
for all queried nodes and prints them.The same result is achievable by using the provided utility functions:
let focused_desktop = util::get_focused_desktop(false);
let windows = util::get_windows(focused_desktop);
println!("{:?}", util::get_node_classes_from_id_list(&windows));