Skip to content

Commit

Permalink
Add Input (capture) devices tab.
Browse files Browse the repository at this point in the history
  • Loading branch information
saivert committed Apr 29, 2024
1 parent 9db1342 commit ac72bdf
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
41 changes: 41 additions & 0 deletions data/resources/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,47 @@
</child>


<child>
<object class="AdwViewStackPage">
<property name="visible">true</property>
<property name="name">inputdevices</property>
<property name="title" translatable="yes">Input Devices</property>
<property name="icon-name">soundcard-symbolic</property>
<property name="child">
<object class="GtkScrolledWindow">
<property name="hscrollbar-policy">never</property>
<property name="min-content-height">200</property>
<property name="hexpand">0</property>
<property name="vexpand">1</property>
<child>
<object class="GtkViewport">
<property name="scroll-to-focus">1</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="margin-start">10</property>
<property name="margin-end">10</property>
<property name="margin-top">5</property>
<property name="margin-bottom">5</property>
<child>
<object class="GtkListBox" id="inputlist">
<property name="selection-mode">none</property>
<property name="show-separators">1</property>
<style>
<class name="boxed-list" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</child>


<child>
<object class="AdwViewStackPage">
<property name="visible">true</property>
Expand Down
5 changes: 4 additions & 1 deletion src/backend/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mod imp {
pub wp_object_manager: OnceCell<wp::registry::ObjectManager>,

pub nodemodel: PwNodeModel,
pub sourcemodel: PwNodeModel,
pub sinkmodel: PwNodeModel,
pub devicemodel: OnceCell<gio::ListStore>,

Expand Down Expand Up @@ -105,7 +106,7 @@ mod imp {
let interest = wp::registry::ObjectInterest::new(
wp::pw::Node::static_type(),
);
let variant = glib::Variant::from_str("('Stream/Output/Audio', 'Stream/Input/Audio', 'Audio/Sink')")
let variant = glib::Variant::from_str("('Stream/Output/Audio', 'Stream/Input/Audio', 'Audio/Source', 'Audio/Sink')")
.expect("variant");
interest.add_constraint(
wp::registry::ConstraintType::PwGlobalProperty,
Expand Down Expand Up @@ -168,6 +169,7 @@ mod imp {
let pwobj = PwNodeObject::new(node);
let model = match pwobj.nodetype() {
NodeType::Sink => &imp.sinkmodel,
NodeType::Source => &imp.sourcemodel,
_ => &imp.nodemodel
};
model.append(&pwobj);
Expand All @@ -187,6 +189,7 @@ mod imp {
pwvucontrol_info!("removed: {:?} id: {}", node.name(), node.bound_id());
let model = match pwnodeobject::get_node_type_for_node(node) {
NodeType::Sink => &imp.sinkmodel,
NodeType::Source => &imp.sourcemodel,
_ => &imp.nodemodel
};
model.remove(node.bound_id());
Expand Down
1 change: 1 addition & 0 deletions src/backend/pwnodeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ pub(crate) fn get_node_type_for_node(node: &wp::pw::Node) -> NodeType {
match node.get_pw_property("media.class").as_deref() {
Some("Stream/Output/Audio") => NodeType::Output,
Some("Stream/Input/Audio") => NodeType::Input,
Some("Audio/Source") => NodeType::Source,
Some("Audio/Sink") => NodeType::Sink,
_ => NodeType::Undefined,
}
Expand Down
37 changes: 30 additions & 7 deletions src/ui/route_dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::ui::PwProfileRow;
use crate::macros::*;

mod imp {
use crate::backend::{PwNodeObject, PwRouteObject};
use crate::backend::{NodeType, PwNodeObject, PwRouteFilterModel, PwRouteObject};

use super::*;

Expand Down Expand Up @@ -44,27 +44,50 @@ mod imp {

impl PwRouteDropDown {
pub fn update_selected(&self) {
if let Some(index) = self.get_route_index() {
pwvucontrol_info!("update_selected with index {index}");
self.obj().set_selected_no_send(index);
}
}

fn get_route_index(&self) -> Option<u32> {
let nodeobject = self.nodeobject.borrow();
let nodeobject = nodeobject.as_ref().unwrap();

let deviceobject = nodeobject.get_device().expect("device");
match nodeobject.nodetype() {
NodeType::Input => Some(deviceobject.route_index_input()),
NodeType::Output => Some(deviceobject.route_index_output()),
_ => None
}
}

pwvucontrol_info!("update_selected with index {}", deviceobject.route_index_output());
self.obj().set_selected_no_send(deviceobject.route_index_output());
fn get_route_model(&self) -> Option<PwRouteFilterModel> {
let nodeobject = self.nodeobject.borrow();
let nodeobject = nodeobject.as_ref().unwrap();

let deviceobject = nodeobject.get_device().expect("device");
match nodeobject.nodetype() {
NodeType::Source => Some(deviceobject.routemodel_input()),
NodeType::Sink => Some(deviceobject.routemodel_output()),
_ => None
}
}

pub fn set_nodeobject(&self, new_nodeobject: Option<&PwNodeObject>) {
self.nodeobject.replace(new_nodeobject.cloned());

if let Some(nodeobject) = new_nodeobject {

let deviceobject = nodeobject.get_device().expect("device");

self.block_signal.set(true);
pwvucontrol_info!("self.route_dropdown.set_model({});", deviceobject.wpdevice().bound_id());
self.route_dropdown.set_model(Some(&deviceobject.routemodel_output()));
pwvucontrol_info!("self.route_dropdown.set_selected({});", deviceobject.route_index_output());

self.route_dropdown.set_selected(deviceobject.route_index_output());
self.route_dropdown.set_model(self.get_route_model().as_ref());
if let Some(index) = self.get_route_index() {
pwvucontrol_info!("self.route_dropdown.set_selected({index});");
self.route_dropdown.set_selected(index);
}

self.block_signal.set(false);

Expand Down
16 changes: 16 additions & 0 deletions src/ui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ mod imp {
#[template_child]
pub recordlist: TemplateChild<gtk::ListBox>,
#[template_child]
pub inputlist: TemplateChild<gtk::ListBox>,
#[template_child]
pub outputlist: TemplateChild<gtk::ListBox>,
#[template_child]
pub cardlist: TemplateChild<gtk::ListBox>,
Expand All @@ -56,6 +58,7 @@ mod imp {
stack: TemplateChild::default(),
playbacklist: TemplateChild::default(),
recordlist: TemplateChild::default(),
inputlist: TemplateChild::default(),
outputlist: TemplateChild::default(),
cardlist: TemplateChild::default(),
viewstack: TemplateChild::default(),
Expand Down Expand Up @@ -95,10 +98,12 @@ mod imp {

self.obj().setup_scroll_blocker(&self.playbacklist);
self.obj().setup_scroll_blocker(&self.recordlist);
self.obj().setup_scroll_blocker(&self.inputlist);
self.obj().setup_scroll_blocker(&self.outputlist);

let manager = PwvucontrolManager::default();
let model = &manager.imp().nodemodel;
let sourcemodel = &manager.imp().sourcemodel;
let sinkmodel = &manager.imp().sinkmodel;
let devicemodel = manager.imp().devicemodel.get().expect("Device model");
let window = self;
Expand Down Expand Up @@ -141,6 +146,17 @@ mod imp {
}),
);

self.inputlist.bind_model(
Some(sourcemodel),
clone!(@weak window => @default-panic, move |item| {
PwSinkBox::new(
item.downcast_ref::<PwNodeObject>()
.expect("RowData is of wrong type"),
)
.upcast::<gtk::Widget>()
}),
);

self.outputlist.bind_model(
Some(sinkmodel),
clone!(@weak window => @default-panic, move |item| {
Expand Down

0 comments on commit ac72bdf

Please sign in to comment.