Skip to content
Open
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
1 change: 0 additions & 1 deletion .direnv/flake-profile

This file was deleted.

1 change: 0 additions & 1 deletion .direnv/flake-profile-11-link

This file was deleted.

2 changes: 0 additions & 2 deletions .envrc

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
debug/
target/

# Direnv
.direnv/
.envrc

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
Expand All @@ -19,4 +23,4 @@ Cargo.lock
/target
./test_plugin/target/
./test_plugin/Cargo.lock
.idea
.idea
17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ repository = "https://github.com/Xetibo/ReSet-Daemon"
license = "GPL-3.0-or-later"

[dependencies]
re_set-lib = "5.2.5"
#re_set-lib = "5.2.5"
re_set-lib = { git = "https://github.com/Xetibo/ReSet-Lib", branch = "dashie-2" }
dbus = "0.9.7"
dbus-crossroads = "0.5.2"
dbus-tokio = "0.7.6"
tokio = { version = "1.33.0", features = [
"rt",
"time",
"net",
"macros",
"rt-multi-thread",
"sync",
"rt",
"time",
"net",
"macros",
"rt-multi-thread",
"sync",
] }
pulse = { version = "2.0", package = "libpulse-binding" }
crossbeam = "0.8.4"
once_cell = "1.19.0"
libloading = "0.8.3"
libloading = "0.8.6"
serial_test = "3.0.0"
toml = "0.8.12"
30 changes: 15 additions & 15 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@
rust-overlay.url = "github:oxalica/rust-overlay";
};

outputs = inputs @ { self, flake-parts, ... }:
outputs =
inputs@{ self, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" ];
systems = [
"x86_64-linux"
"aarch64-linux"
];

perSystem =
{ config
, self'
, inputs'
, pkgs
, system
, ...
{
self',
pkgs,
system,
...
}:
{
_module.args.pkgs = import self.inputs.nixpkgs {
inherit system;
overlays = [
(import
inputs.rust-overlay
)
(import inputs.rust-overlay)
];
};
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self'.packages;
packages = with pkgs; [
(rust-bin.selectLatestNightlyWith
(toolchain: toolchain.default))
rust-analyzer
clippy
(rust-bin.selectLatestNightlyWith (toolchain: toolchain.default))
#rust-analyzer
#clippy
];
buildInputs = with pkgs; [
gtk4
Expand Down
64 changes: 62 additions & 2 deletions src/audio/audio_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use pulse::{
mainloop::threaded::Mainloop,
proplist::Proplist,
};
use re_set_lib::audio::audio_structures::{InputStream, OutputStream, Sink, Source};
use re_set_lib::audio::audio_structures::{Card, InputStream, OutputStream, Sink, Source};
use re_set_lib::ERROR;
#[cfg(debug_assertions)]
use re_set_lib::{utils::macros::ErrorLevel, write_log_to_file};
Expand Down Expand Up @@ -106,6 +106,7 @@ impl PulseServer {
mask.insert(InterestMaskSet::SOURCE);
mask.insert(InterestMaskSet::SINK_INPUT);
mask.insert(InterestMaskSet::SOURCE_OUTPUT);
mask.insert(InterestMaskSet::CARD);

context.borrow_mut().subscribe(mask, |_| {});
let connection_ref = connection.clone();
Expand All @@ -118,6 +119,7 @@ impl PulseServer {
let connection_source = connection_ref.clone();
let connection_input_stream = connection_ref.clone();
let connection_output_stream = connection_ref.clone();
let connection_card = connection_ref.clone();
let operation = operation.unwrap();
let facility = facility.unwrap();
match facility {
Expand Down Expand Up @@ -199,6 +201,21 @@ impl PulseServer {
ListResult::End => (),
});
}
pulse::context::subscribe::Facility::Card => {
if operation == Operation::Removed {
handle_card_removed(&connection, index);
return;
}
introspector.get_card_info_by_index(index, move |result| match result {
ListResult::Item(card) => {
handle_card_events(&connection_card, Card::from(card), operation);
}
ListResult::Error => {
ERROR!("Could not get card info", ErrorLevel::PartialBreakage);
}
ListResult::End => (),
});
}
_ => (),
}
})));
Expand Down Expand Up @@ -1021,6 +1038,49 @@ fn handle_output_stream_removed(conn: &Arc<SyncConnection>, index: u32) {
.append1(index);
let res = conn.send(msg);
if res.is_err() {
ERROR!("Could not get send message", ErrorLevel::PartialBreakage);
ERROR!("Could not send message", ErrorLevel::PartialBreakage);
}
}

fn handle_card_events(conn: &Arc<SyncConnection>, card: Card, operation: Operation) {
match operation {
Operation::New => {
let msg = Message::signal(
&Path::from(DBUS_PATH!()),
&AUDIO.into(),
&"CardAdded".into(),
)
.append1(card);
let res = conn.send(msg);
if res.is_err() {
ERROR!("Could not send message", ErrorLevel::PartialBreakage);
}
}
Operation::Changed => {
let msg = Message::signal(
&Path::from(DBUS_PATH!()),
&AUDIO.into(),
&"CardChanged".into(),
)
.append1(card);
let res = conn.send(msg);
if res.is_err() {
ERROR!("Could not send message", ErrorLevel::PartialBreakage);
}
}
Operation::Removed => (),
}
}

fn handle_card_removed(conn: &Arc<SyncConnection>, index: u32) {
let msg = Message::signal(
&Path::from(DBUS_PATH!()),
&AUDIO.into(),
&"CardRemoved".into(),
)
.append1(index);
let res = conn.send(msg);
if res.is_err() {
ERROR!("Could not send message", ErrorLevel::PartialBreakage);
}
}
3 changes: 3 additions & 0 deletions src/audio/audio_manager_dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub fn setup_audio_manager(cross: &mut Crossroads) -> dbus_crossroads::IfaceToke
c.signal::<(OutputStream,), _>("OutputStreamChanged", ("output_stream",));
c.signal::<(OutputStream,), _>("OutputStreamAdded", ("output_stream",));
c.signal::<(u32,), _>("OutputStreamRemoved", ("output_stream",));
c.signal::<(Card,), _>("CardChanged", ("card",));
c.signal::<(Card,), _>("CardAdded", ("card",));
c.signal::<(u32,), _>("CardRemoved", ("card",));
c.method_with_cr_async(
"GetDefaultSink",
(),
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
/// // your other code here...
/// ```
pub async fn run_daemon(ready: Option<Arc<AtomicBool>>) {
#[allow(clippy::borrow_interior_mutable_const)]
for flag in FLAGS.0.iter() {
// more configuration possible in the future
match flag {
Expand Down Expand Up @@ -166,10 +167,9 @@ pub async fn run_daemon(ready: Option<Arc<AtomicBool>>) {
}
let data = data.unwrap();

if data
if !data
.audio_listener_active
.load(std::sync::atomic::Ordering::SeqCst)
== false
{
let mut index = -1;
for (i, feature) in feature_strings.iter().enumerate() {
Expand Down
Loading