mirror of
https://gitlab.freedesktop.org/pipewire/helvum
synced 2026-03-15 11:36:11 +08:00
Move port coloring into view
The controller still determines the ports media type, but instead of coloring the port itself, the media type is passed to the constructor, which then colors the port.
This commit is contained in:
@@ -1,15 +1,13 @@
|
|||||||
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||||
|
|
||||||
use gtk::{
|
use gtk::glib::{self, clone};
|
||||||
glib::{self, clone},
|
|
||||||
prelude::*,
|
|
||||||
};
|
|
||||||
use libspa::{ForeignDict, ReadableDict};
|
use libspa::{ForeignDict, ReadableDict};
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use pipewire::{port::Direction, registry::GlobalObject, types::ObjectType};
|
use pipewire::{port::Direction, registry::GlobalObject, types::ObjectType};
|
||||||
|
|
||||||
use crate::{pipewire_connection::PipewireConnection, view};
|
use crate::{pipewire_connection::PipewireConnection, view};
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
pub enum MediaType {
|
pub enum MediaType {
|
||||||
Audio,
|
Audio,
|
||||||
Video,
|
Video,
|
||||||
@@ -171,6 +169,15 @@ impl Controller {
|
|||||||
.expect("Port has no node.id property!")
|
.expect("Port has no node.id property!")
|
||||||
.parse()
|
.parse()
|
||||||
.expect("Could not parse node.id property");
|
.expect("Could not parse node.id property");
|
||||||
|
|
||||||
|
// Find out the nodes media type so that the port can be colored.
|
||||||
|
let media_type = if let Some(Item::Node { media_type, .. }) = self.state.get(&node_id) {
|
||||||
|
media_type.to_owned()
|
||||||
|
} else {
|
||||||
|
warn!("Node not found for Port {}", port.id);
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let new_port = crate::view::port::Port::new(
|
let new_port = crate::view::port::Port::new(
|
||||||
port.id,
|
port.id,
|
||||||
&port_label,
|
&port_label,
|
||||||
@@ -179,20 +186,9 @@ impl Controller {
|
|||||||
} else {
|
} else {
|
||||||
Direction::Output
|
Direction::Output
|
||||||
},
|
},
|
||||||
|
media_type,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Color the port accordingly to its media class.
|
|
||||||
if let Some(Item::Node { media_type, .. }) = self.state.get(&node_id) {
|
|
||||||
match media_type {
|
|
||||||
Some(MediaType::Audio) => new_port.widget.add_css_class("audio"),
|
|
||||||
Some(MediaType::Video) => new_port.widget.add_css_class("video"),
|
|
||||||
Some(MediaType::Midi) => new_port.widget.add_css_class("midi"),
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
warn!("Node not found for Port {}", port.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.view.add_port_to_node(node_id, new_port.id, new_port);
|
self.view.add_port_to_node(node_id, new_port.id, new_port);
|
||||||
|
|
||||||
// Save node_id so we can delete this port easily.
|
// Save node_id so we can delete this port easily.
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
use gtk::WidgetExt;
|
||||||
|
|
||||||
|
use crate::controller::MediaType;
|
||||||
|
|
||||||
/// Graphical representation of a pipewire port.
|
/// Graphical representation of a pipewire port.
|
||||||
pub struct Port {
|
pub struct Port {
|
||||||
pub widget: gtk::Button,
|
pub widget: gtk::Button,
|
||||||
@@ -6,9 +10,24 @@ pub struct Port {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Port {
|
impl Port {
|
||||||
pub fn new(id: u32, name: &str, direction: pipewire::port::Direction) -> Self {
|
pub fn new(
|
||||||
|
id: u32,
|
||||||
|
name: &str,
|
||||||
|
direction: pipewire::port::Direction,
|
||||||
|
media_type: Option<MediaType>,
|
||||||
|
) -> Self {
|
||||||
|
let widget = gtk::Button::with_label(name);
|
||||||
|
|
||||||
|
// Color the port according to its media type.
|
||||||
|
match media_type {
|
||||||
|
Some(MediaType::Video) => widget.add_css_class("video"),
|
||||||
|
Some(MediaType::Audio) => widget.add_css_class("audio"),
|
||||||
|
Some(MediaType::Midi) => widget.add_css_class("midi"),
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
widget: gtk::Button::with_label(name),
|
widget,
|
||||||
id,
|
id,
|
||||||
direction,
|
direction,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user