diff --git a/src/application.rs b/src/application.rs index 98155a4..5ec064e 100644 --- a/src/application.rs +++ b/src/application.rs @@ -108,9 +108,9 @@ impl Application { @weak app => @default-return Continue(true), move |msg| { match msg { - PipewireMessage::NodeAdded{ id, name } => app.add_node(id,name), - PipewireMessage::PortAdded{ id, node_id, name, direction, media_type} => app.add_port(id,name,node_id,direction,media_type), - PipewireMessage::LinkAdded{ id, node_from, port_from, node_to, port_to} => app.add_link(id,node_from,port_from,node_to,port_to), + PipewireMessage::NodeAdded{ id, name } => app.add_node(id, name.as_str()), + PipewireMessage::PortAdded{ id, node_id, name, direction, media_type} => app.add_port(id, name.as_str(), node_id, direction, media_type), + PipewireMessage::LinkAdded{ id, node_from, port_from, node_to, port_to} => app.add_link(id, node_from, port_from, node_to, port_to), PipewireMessage::NodeRemoved { id } => app.remove_node(id), PipewireMessage::PortRemoved { id, node_id } => app.remove_port(id, node_id), PipewireMessage::LinkRemoved { id } => app.remove_link(id) @@ -124,19 +124,19 @@ impl Application { } /// Add a new node to the view. - pub fn add_node(&self, id: u32, name: String) { + pub fn add_node(&self, id: u32, name: &str) { info!("Adding node to graph: id {}", id); imp::Application::from_instance(self) .graphview - .add_node(id, view::Node::new(name.as_str())); + .add_node(id, view::Node::new(name)); } /// Add a new port to the view. pub fn add_port( &self, id: u32, - name: String, + name: &str, node_id: u32, direction: Direction, media_type: Option, @@ -145,7 +145,7 @@ impl Application { let imp = imp::Application::from_instance(self); - let port = view::Port::new(id, name.as_str(), direction, media_type); + let port = view::Port::new(id, name, direction, media_type); // Create or delete a link if the widget emits the "port-toggled" signal. if let Err(e) = port.connect_local( diff --git a/src/pipewire_connection.rs b/src/pipewire_connection.rs index f99aebd..37ec270 100644 --- a/src/pipewire_connection.rs +++ b/src/pipewire_connection.rs @@ -100,20 +100,17 @@ fn handle_node( ); // FIXME: Instead of checking these props, the "EnumFormat" parameter should be checked instead. - let media_type = props - .get("media.class") - .map(|class| { - if class.contains("Audio") { - Some(MediaType::Audio) - } else if class.contains("Video") { - Some(MediaType::Video) - } else if class.contains("Midi") { - Some(MediaType::Midi) - } else { - None - } - }) - .flatten(); + let media_type = props.get("media.class").and_then(|class| { + if class.contains("Audio") { + Some(MediaType::Audio) + } else if class.contains("Video") { + Some(MediaType::Video) + } else if class.contains("Midi") { + Some(MediaType::Midi) + } else { + None + } + }); state.borrow_mut().insert( node.id, diff --git a/src/pipewire_connection/state.rs b/src/pipewire_connection/state.rs index 4f42ba2..0275a89 100644 --- a/src/pipewire_connection/state.rs +++ b/src/pipewire_connection/state.rs @@ -34,7 +34,7 @@ pub(super) struct State { impl State { /// Create a new, empty state. pub fn new() -> Self { - Default::default() + Self::default() } /// Add a new item under the specified id. diff --git a/src/view/graph_view.rs b/src/view/graph_view.rs index f2c16ad..013fe18 100644 --- a/src/view/graph_view.rs +++ b/src/view/graph_view.rs @@ -119,13 +119,13 @@ mod imp { let mut y = 0.0; while y < alloc.height.into() { cr.move_to(0.0, y); - cr.line_to(alloc.width as f64, y); + cr.line_to(alloc.width.into(), y); y += 20.0; // TODO: Change to em; } let mut x = 0.0; - while x < alloc.width as f64 { + while x < alloc.width.into() { cr.move_to(x, 0.0); - cr.line_to(x, alloc.height as f64); + cr.line_to(x, alloc.height.into()); x += 20.0; // TODO: Change to em; } if let Err(e) = cr.stroke() { @@ -159,7 +159,7 @@ mod imp { /// Get coordinates for the drawn link to start at and to end at. /// /// # Returns - /// Some((from_x, from_y, to_x, to_y)) if all objects the links refers to exist as widgets. + /// `Some((from_x, from_y, to_x, to_y))` if all objects the links refers to exist as widgets. fn get_link_coordinates(&self, link: &crate::PipewireLink) -> Option<(f64, f64, f64, f64)> { let nodes = self.nodes.borrow(); @@ -194,7 +194,7 @@ mod imp { tx += tnx; ty += tny + (th / 2); - Some((fx as f64, fy as f64, tx as f64, ty as f64)) + Some((fx.into(), fy.into(), tx.into(), ty.into())) } } } diff --git a/src/view/node.rs b/src/view/node.rs index 23f9d67..6d1bc57 100644 --- a/src/view/node.rs +++ b/src/view/node.rs @@ -12,8 +12,8 @@ mod imp { pub(super) grid: gtk::Grid, pub(super) label: gtk::Label, pub(super) ports: RefCell>>, - pub(super) num_ports_in: Cell, - pub(super) num_ports_out: Cell, + pub(super) num_ports_in: Cell, + pub(super) num_ports_out: Cell, } #[glib::object_subclass] @@ -81,13 +81,13 @@ impl Node { Direction::Input => { private .grid - .attach(&port, 0, private.num_ports_in.get() as i32 + 1, 1, 1); + .attach(&port, 0, private.num_ports_in.get() + 1, 1, 1); private.num_ports_in.set(private.num_ports_in.get() + 1); } Direction::Output => { private .grid - .attach(&port, 1, private.num_ports_out.get() as i32 + 1, 1, 1); + .attach(&port, 1, private.num_ports_out.get() + 1, 1, 1); private.num_ports_out.set(private.num_ports_out.get() + 1); } }