Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.10.2 #21

Merged
merged 7 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ This is mainly here so I remember how to do a release when I haven't done one in
Steps:

1. Create GH PR from `next` to `master`
2. Push commit with version bump
2. Push commit with $NEW_VERSION
3. Check CI is green
4. Cargo publish $NEW_VERSION
5. Git tag $NEW_VERSION
4. `just publish`
5. `git tag $NEW_VERSION`
6. Update [`i3stat` AUR package](https://aur.archlinux.org/packages/i3stat)
7. Update [`i3stat-bin` AUR package](https://aur.archlinux.org/packages/i3stat-bin)
8. Merge GH PR
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "i3stat"
version = "0.10.1"
version = "0.10.2"
edition = "2021"
authors = ["acheronfail <[email protected]>"]
description = "A lightweight and batteries-included status_command for i3 and sway"
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ run bin *args:

# install locally, copy sample configuration and restart i3
install *args:
RUSTFLAGS="--emit=asm" cargo install --offline --path . "$@"
cargo install --offline --path . "$@"
mkdir -p ~/.config/i3stat/
-cp --no-clobber ./sample_config.toml ~/.config/i3stat/config.toml
i3-msg restart
Expand Down
101 changes: 90 additions & 11 deletions src/bar_items/pulse/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde_derive::{Deserialize, Serialize};
use serde_json::{json, Value};
use tokio::sync::oneshot;

use super::{InOut, Object, PulseState, Vol};
use super::{Dir, InOut, Object, Port, PortAvailable, PulseState, Vol};
use crate::context::CustomResponse;
use crate::util::RcCell;

Expand Down Expand Up @@ -39,13 +39,39 @@ impl From<Bool> for bool {
#[command(name = "pulse", no_binary_name = true)]
enum PulseCommand {
Info,
List { what: Object },
VolumeUp { what: Object },
VolumeDown { what: Object },
VolumeSet { what: Object, vol: u32 },
Mute { what: Object, mute: Bool },
MuteToggle { what: Object },
SetDefault { what: Object, name: String },
List {
what: Object,
},
VolumeUp {
what: Object,
},
VolumeDown {
what: Object,
},
VolumeSet {
what: Object,
vol: u32,
},
Mute {
what: Object,
mute: Bool,
},
MuteToggle {
what: Object,
},
SetDefault {
what: Object,
name: String,
},
SetPort {
what: Object,
obj_name: String,
port_name: String,
},
Cycle {
what: Object,
dir: Dir,
},
}

#[derive(Debug, Serialize, Deserialize)]
Expand All @@ -57,14 +83,30 @@ pub enum PulseResponse {
Failure(String),
}

impl Port {
fn to_value(&self) -> Value {
json!({
"name": self.name,
"description": self.description,
"available": match self.available {
PortAvailable::Unknown => "unknown",
PortAvailable::No => "no",
PortAvailable::Yes => "yes",
},
"port_type": self.port_type.to_i64(),
})
}
}

impl InOut {
fn to_value(&self) -> Value {
json!({
"index": self.index,
"name": self.name,
"volume": self.volume_pct(),
"mute": self.mute,
"port_type": self.active_port.as_ref().map(|t| t.port_type.to_i64()).flatten()
"ports": self.ports.iter().map(|p| p.to_value()).collect::<Vec<_>>(),
"active_port": self.active_port.as_ref().map_or(Value::Null, |p| p.to_value()),
})
}
}
Expand All @@ -73,12 +115,15 @@ impl RcCell<PulseState> {
// NOTE: since pulse's callback API requires `FnMut`, but `oneshot::tx.send` consumes itself
// we wrap it in an option so it's only send once. This should be fine, because pulse only runs
// this callback once anyway.
fn custom_responder<F>(tx: oneshot::Sender<CustomResponse>, f: F) -> impl FnMut(bool) + 'static
fn custom_responder<F>(
tx: oneshot::Sender<CustomResponse>,
failure_fn: F,
) -> impl FnMut(bool) + 'static
where
F: FnOnce() -> String + 'static,
{
let mut tx = Some(tx);
let mut f = Some(f);
let mut f = Some(failure_fn);
move |success| match (tx.take(), f.take()) {
(Some(tx), Some(f)) => {
let _ = tx.send(CustomResponse::Json(json!(match success {
Expand Down Expand Up @@ -168,6 +213,40 @@ impl RcCell<PulseState> {
}),
);
}
PulseCommand::SetPort {
what,
obj_name,
port_name,
} => {
let obj_name = obj_name.into();
let obj = match what {
Object::Sink => self.sinks.iter().find(|o| o.name == obj_name),
Object::Source => self.sinks.iter().find(|o| o.name == obj_name),
};

match obj {
Some(obj) => {
return self.set_object_port(
what,
obj.index,
port_name.clone(),
Self::custom_responder(tx, move || {
format!("failed to set {what} port to {port_name}, is the port name right?")
})
);
}
None => PulseResponse::Failure(String::from(
"failed to find {what} with name {obj_name}",
)),
}
}
PulseCommand::Cycle { what, dir } => {
return self.cycle_objects_and_ports(
what,
dir,
Self::custom_responder(tx, move || format!("failed to cycle {what}")),
);
}
};

CustomResponse::Json(json!(resp))
Expand Down
Loading
Loading