Toggle links on and off when ports are connected by the user.

This extends the `Application` struct to keep more advanced state.
This state is then used to determine the needed information to create
or delete a link between the two connected ports.

A message to create/delete the link is then send to the pipewire thread,
which executed the request.
This commit is contained in:
Tom A. Wagner
2021-05-08 17:57:48 +02:00
parent be240231c0
commit 13f02ad317
3 changed files with 197 additions and 36 deletions

View File

@@ -10,14 +10,18 @@ use gtk::{
use pipewire::spa::Direction;
/// Messages used GTK thread to command the pipewire thread.
#[derive(Debug)]
#[derive(Debug, Clone)]
enum GtkMessage {
/// Create a new link.
CreateLink(PipewireLink),
/// Destroy the global with the specified id.
DestroyGlobal(u32),
/// Quit the event loop and let the thread finish.
Terminate,
}
/// Messages used pipewire thread to notify the GTK thread.
#[derive(Debug)]
#[derive(Debug, Clone)]
enum PipewireMessage {
/// A new node has appeared.
NodeAdded {
@@ -38,7 +42,7 @@ enum PipewireMessage {
ObjectRemoved { id: u32 },
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct PipewireLink {
pub node_from: u32,
pub port_from: u32,
@@ -56,7 +60,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let pw_thread =
std::thread::spawn(move || pipewire_connection::thread_main(gtk_sender, pw_receiver));
let app = application::Application::new(gtk_receiver);
let app = application::Application::new(gtk_receiver, pw_sender.clone());
app.run(&std::env::args().collect::<Vec<_>>());