Skip to content
Merged
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
34 changes: 33 additions & 1 deletion src/pw/PwState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,39 @@ void CPipewireState::onGlobal(uint32_t id, uint32_t permissions, const char* typ
}
}

// If node goes away, drop all ports and links that belonged to it
void CPipewireState::onGlobalRemoved(uint32_t id) {
// Remove links
std::erase_if(m_pwState.links, [id](const auto& l) { return l->m_id == id || l->m_nodeAID == id || l->m_nodeBID == id || l->m_portAID == id || l->m_portBID == id; });

// Remove ports from global list and their node
std::erase_if(m_pwState.ports, [id](const auto& p) {
const bool isThisPort = (p->m_id == id);
const bool isPortsNode = (p->m_nodeID == id);

// Port is gone
if (isThisPort) {
if (p->m_node)
std::erase_if(p->m_node->m_ports, [id](const auto& e) { return e && e->m_id == id; });
return true;
}

// Node this port belonged to is gone
if (isPortsNode) {
if (p->m_node)
std::erase_if(p->m_node->m_ports, [nodeId = id](const auto& e) { return e && e->m_nodeID == nodeId; });
return true;
}

// Port was not affected by this removal
return false;
});

// Remove node
std::erase_if(m_pwState.nodes, [id](const auto& n) { return n->m_id == id; });

// Remove device
std::erase_if(m_pwState.devices, [id](const auto& d) { return d->m_id == id; });
}

void CPipewireState::setVolume(uint32_t id, float x) {
Expand Down Expand Up @@ -142,8 +173,9 @@ void CPipewireState::checkNodePorts(WP<IPwNode> node) {
if (p->m_nodeID != node->m_id)
continue;

// There might be more matching ports so continue
if (std::ranges::contains(node->m_ports, p))
break;
continue;

node->m_ports.emplace_back(p);
g_ui->updateNode(node);
Expand Down
12 changes: 6 additions & 6 deletions src/ui/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ void CUI::run() {
void CUI::updateNode(WP<IPwNode> node) {
m_tabs.graphTab.graphView->addNode(node);

const bool SHOW = !node->m_ports.empty() && (trim(node->m_name) != "" || node->m_volume > 0) && node->controllable();

recheckNodeVisibility(node);

if (!node->controllable())
// Don't create/reuse slider when not showable
if (!SHOW)
return;

const auto N = sliderFromNode(node);

if (N) {
// From here on the node is showable: reuse or create
if (const auto N = sliderFromNode(node)) {
N->setVolume(node->m_volume);
N->setMuted(node->m_muted);
return;
Expand All @@ -186,8 +188,6 @@ void CUI::updateNode(WP<IPwNode> node) {

x->setVolume(node->m_volume);
x->setMuted(node->m_muted);

recheckNodeVisibility(node);
}

void CUI::nodeRemoved(WP<IPwNode> node) {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/graph/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void CGraphView::removeNode(WP<IPwNode> node) {
std::erase_if(m_nodes, [node](const auto& e) { return !e || !e->m_node || e->m_node == node; });
std::erase_if(m_connections, [node](const auto& e) { return !e || !e->m_a || !e->m_b; });

scheduleUpdateConnections();
rearrange();
}

void CGraphView::addLink(WP<CPipewireLink> link) {
Expand Down