Compare commits

...

2 Commits

Author SHA1 Message Date
1f5a8f2c21 dev-2025-11-08T02:57:58+01:00 2025-11-08 02:57:58 +01:00
96e7390a2b dev-2025-11-08T00:54:40+01:00 2025-11-08 00:54:40 +01:00
3 changed files with 85 additions and 10 deletions

4
run.sh
View File

@ -6,8 +6,8 @@ cd "$SRC_DIR" || exit
#export DESTDIR=~/.local #export DESTDIR=~/.local
#export PKGDATADIR=~/.local/share #export PKGDATADIR=~/.local/share
~/.local/bin/meson build || exit meson build || exit
sudo ~/.local/bin/meson install -C build || exit sudo meson install -C build || exit
RUST_BACKTRACE=1 audio-device-manager || exit RUST_BACKTRACE=1 audio-device-manager || exit
#git add . #git add .

View File

@ -42,7 +42,7 @@ enum Command {
} }
struct RegisteredObjects { struct RegisteredObjects {
profile_combo_rows: HashMap<uuid::Uuid, (usize, adw::ComboRow, gtk::StringList)> profile_combo_rows: HashMap<uuid::Uuid, (usize, adw::ComboRow, adw::gio::ListStore)>
} }
impl RegisteredObjects { impl RegisteredObjects {
@ -166,8 +166,11 @@ fn handle_profile_discovered(device_id: usize, registered_objects: Rc<RefCell<Re
let mut i = 0; let mut i = 0;
while let Some(p) = model.string(i) { while let Some(p) = model.item(i) {
match p.to_string().cmp(&profile_name) {
let label = p.downcast::<gtk::Label>().unwrap().label().to_string();
match label.cmp(&profile_name) {
Ordering::Less => {} Ordering::Less => {}
Ordering::Equal => return, Ordering::Equal => return,
Ordering::Greater => {break;} Ordering::Greater => {break;}
@ -175,7 +178,9 @@ fn handle_profile_discovered(device_id: usize, registered_objects: Rc<RefCell<Re
i += 1 i += 1
} }
model.splice(i, 0, &[&profile_name]); let profile_label = gtk::Label::new(Some(&profile_name));
model.splice(i, 0, &[profile_label]);
} }
} }
@ -193,7 +198,17 @@ fn handle_active_profile_set(device_id: usize, registered_objects: Rc<RefCell<Re
continue; continue;
} }
let i = model.find(&profile_name); let mut i = 0;
while let Some(p) = model.item(i) {
let label = p.downcast::<gtk::Label>().unwrap().label().to_string();
if label == profile_name {
break;
}
i += 1;
}
combo_row.set_selected(i); combo_row.set_selected(i);
@ -257,9 +272,38 @@ impl PipewireManager {
Some((id, self.devices.borrow()[&device_id].profiles[&id].description.clone())) Some((id, self.devices.borrow()[&device_id].profiles[&id].description.clone()))
}); });
let model = gtk::StringList::new(&[]); let factory = gtk::SignalListItemFactory::new();
factory.connect_setup(move |factory, item| {
let label = gtk::Label::new(None);
item.downcast_ref::<gtk::ListItem>()
.unwrap()
.set_child(Some(&label));
});
factory.connect_bind(move |factory, item| {
let list_item = item.downcast_ref::<gtk::ListItem>().unwrap();
let label = list_item.child().unwrap().downcast::<gtk::Label>().unwrap();
// using list_item.set_child( Some(&>label<) )
// instead of label.set_label( >label<.label() )
// results in weird broken behavior
label.set_label(&list_item.item().unwrap().downcast::<gtk::Label>().unwrap().label())
});
combo_row.set_factory(Some(&factory));
let model = adw::gio::ListStore::new::<gtk::Label>();
//let model = gtk::StringList::new(&[]);
for name in &profile_names { for name in &profile_names {
model.append(name);
let label = gtk::Label::new(Some(name));
label.set_tooltip_text(Some(name));
model.append(&label);
} }
combo_row.set_model(Some(&model)); combo_row.set_model(Some(&model));
@ -273,7 +317,12 @@ impl PipewireManager {
self.tx, self.tx,
move |c| { move |c| {
let model_entry = c.selected(); let model_entry = c.selected();
let selected_profile_name = model.string(model_entry).unwrap().to_string(); let selected_profile_name = model
.item(model_entry)
.unwrap()
.downcast::<gtk::Label>()
.unwrap()
.label();
let mut selected_profile_id = None; let mut selected_profile_id = None;
for (profile_id, profile) in &devices.borrow()[&device_id].profiles { for (profile_id, profile) in &devices.borrow()[&device_id].profiles {
@ -287,9 +336,35 @@ impl PipewireManager {
tx.send( tx.send(
Command::DeviceCommand(device_id, DeviceCommand::SetProfile(selected_profile_id)) Command::DeviceCommand(device_id, DeviceCommand::SetProfile(selected_profile_id))
).unwrap(); ).unwrap();
println!("{}", &selected_profile_name);
} }
)); ));
/*
// works, TODO: figure out preferred style
combo_row.set_use_subtitle(true);
combo_row.connect_subtitle_notify(clone!(
#[weak]
model,
move |c| {
let model_entry = c.selected();
let selected_profile_name = model
.item(model_entry)
.unwrap()
.downcast::<gtk::Label>()
.unwrap()
.label();
c.set_subtitle(&selected_profile_name);
}
));
*/
if let Some((_, name)) = active_profile { if let Some((_, name)) = active_profile {
if let Ok(position) = profile_names.binary_search(&&name) { if let Ok(position) = profile_names.binary_search(&&name) {
combo_row.set_selected(position as u32) combo_row.set_selected(position as u32)

0
subprojects/.wraplock Normal file
View File