mirror of
https://gitlab.freedesktop.org/pipewire/helvum.git
synced 2026-05-23 22:38:13 +02:00
Merge branch 'update-dependencies' into 'main'
deps: Update dependencies and migrate to blueprints See merge request pipewire/helvum!78
This commit is contained in:
commit
41c2daaa35
30 changed files with 1153 additions and 977 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,3 +3,4 @@
|
|||
/.vscode
|
||||
/_build
|
||||
/target
|
||||
/repo
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ stages:
|
|||
- lint
|
||||
|
||||
.flatpak:
|
||||
image: 'quay.io/gnome_infrastructure/gnome-runtime-images:gnome-45'
|
||||
image: 'quay.io/gnome_infrastructure/gnome-runtime-images:gnome-50'
|
||||
variables:
|
||||
FLATPAK_BUILD_DIR: _build
|
||||
MANIFEST_PATH: build-aux/org.pipewire.Helvum.json
|
||||
|
|
@ -12,7 +12,7 @@ stages:
|
|||
- flatpak --version
|
||||
- flatpak info org.gnome.Platform
|
||||
- flatpak info org.gnome.Sdk
|
||||
- flatpak info org.freedesktop.Sdk.Extension.llvm16
|
||||
- flatpak info org.freedesktop.Sdk.Extension.llvm21
|
||||
- flatpak info org.freedesktop.Sdk.Extension.rust-stable
|
||||
- flatpak-builder --version
|
||||
|
||||
|
|
@ -50,4 +50,3 @@ rustdoc:
|
|||
- >-
|
||||
flatpak-builder --run ${FLATPAK_BUILD_DIR} ${MANIFEST_PATH}
|
||||
env RUSTDOCFLAGS=-Dwarnings cargo doc --no-deps
|
||||
|
||||
|
|
|
|||
658
Cargo.lock
generated
658
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
22
Cargo.toml
22
Cargo.toml
|
|
@ -1,9 +1,11 @@
|
|||
[package]
|
||||
name = "helvum"
|
||||
version = "0.5.1"
|
||||
authors = ["Tom Wagner <tom.a.wagner@protonmail.com>"]
|
||||
edition = "2021"
|
||||
rust-version = "1.70"
|
||||
authors = [
|
||||
"Tom Wagner <tom.a.wagner@protonmail.com>",
|
||||
"Jaŭhien Lavonćjeŭ <jauhien.lavoncjeu@gmail.com>"
|
||||
]
|
||||
edition = "2024"
|
||||
license = "GPL-3.0-only"
|
||||
description = "A GTK patchbay for pipewire"
|
||||
repository = "https://gitlab.freedesktop.org/pipewire/helvum"
|
||||
|
|
@ -14,12 +16,10 @@ categories = ["gui", "multimedia"]
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
pipewire = "0.7.1"
|
||||
adw = { version = "0.5", package = "libadwaita", features = ["v1_4"] }
|
||||
glib = { version = "0.18", features = ["log"] }
|
||||
|
||||
log = "0.4.11"
|
||||
|
||||
once_cell = "1.7.2"
|
||||
|
||||
pipewire = "0.9.2"
|
||||
adw = { version = "0.9.1", package = "libadwaita", features = ["v1_9"] }
|
||||
gtk = { package = "gtk4", version = "0.11.2", features = ["gnome_50"] }
|
||||
glib = { version = "0.22.7", features = ["log"] }
|
||||
futures = "0.3.32"
|
||||
log = "0.4.29"
|
||||
libc = "0.2"
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
"id": "org.pipewire.Helvum",
|
||||
"runtime": "org.gnome.Platform",
|
||||
"runtime-version": "45",
|
||||
"runtime-version": "50",
|
||||
"sdk": "org.gnome.Sdk",
|
||||
"sdk-extensions": [
|
||||
"org.freedesktop.Sdk.Extension.rust-stable",
|
||||
"org.freedesktop.Sdk.Extension.llvm16"
|
||||
"org.freedesktop.Sdk.Extension.llvm21"
|
||||
],
|
||||
"command": "helvum",
|
||||
"finish-args": [
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
"--filesystem=xdg-run/pipewire-0"
|
||||
],
|
||||
"build-options": {
|
||||
"append-path": "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm16/bin",
|
||||
"prepend-ld-library-path": "/usr/lib/sdk/llvm16/lib",
|
||||
"append-path": "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm21/bin",
|
||||
"prepend-ld-library-path": "/usr/lib/sdk/llvm21/lib",
|
||||
"build-args": [
|
||||
"--share=network"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,11 +1,22 @@
|
|||
subdir('icons')
|
||||
blueprints = custom_target('blueprints',
|
||||
input: files(
|
||||
'ui/window.blp',
|
||||
'ui/node.blp',
|
||||
'ui/port.blp',
|
||||
'ui/zoomentry.blp',
|
||||
),
|
||||
output: '.',
|
||||
command: [find_program('blueprint-compiler'), 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],)
|
||||
|
||||
# Desktop file
|
||||
desktop_conf = configuration_data()
|
||||
desktop_conf.set('icon', base_id)
|
||||
desktop_file = configure_file(
|
||||
input: '@0@.desktop.in'.format(base_id),
|
||||
output: '@BASENAME@',
|
||||
configuration: desktop_conf
|
||||
configuration: desktop_conf,
|
||||
install: true,
|
||||
install_dir: join_paths(datadir, 'applications')
|
||||
)
|
||||
|
||||
if desktop_file_validate.found()
|
||||
|
|
@ -18,18 +29,15 @@ if desktop_file_validate.found()
|
|||
)
|
||||
endif
|
||||
|
||||
install_data(
|
||||
desktop_file,
|
||||
install_dir: datadir / 'applications'
|
||||
)
|
||||
|
||||
|
||||
# Appdata
|
||||
appdata_conf = configuration_data()
|
||||
appdata_conf.set('app-id', base_id)
|
||||
appdata_file = configure_file(
|
||||
input: '@0@.metainfo.xml.in'.format(base_id),
|
||||
output: '@BASENAME@',
|
||||
configuration: appdata_conf
|
||||
configuration: appdata_conf,
|
||||
install: true,
|
||||
install_dir: join_paths(datadir, 'metainfo')
|
||||
)
|
||||
|
||||
# Validate Appdata
|
||||
|
|
@ -43,7 +51,42 @@ if appstream_util.found()
|
|||
)
|
||||
endif
|
||||
|
||||
install_data(
|
||||
appdata_file,
|
||||
install_dir: datadir / 'metainfo'
|
||||
# Resources
|
||||
conf = configuration_data()
|
||||
conf.set('PATH_ID', path_id)
|
||||
configure_file(
|
||||
input: '@0@.gresource.xml.in'.format(base_id),
|
||||
output: '@0@.gresource.xml'.format(base_id),
|
||||
configuration: conf,
|
||||
)
|
||||
|
||||
gnome.compile_resources(
|
||||
base_id,
|
||||
join_paths(meson.project_build_root(), 'data', '@0@.gresource.xml'.format(base_id)),
|
||||
gresource_bundle: true,
|
||||
source_dir: join_paths(meson.project_build_root(), 'data'),
|
||||
install: true,
|
||||
install_dir: join_paths(datadir, meson.project_name()),
|
||||
dependencies: [appdata_file, blueprints],
|
||||
)
|
||||
|
||||
gnome.post_install(
|
||||
gtk_update_icon_cache: true,
|
||||
glib_compile_schemas: false,
|
||||
update_desktop_database: true,
|
||||
)
|
||||
|
||||
# D-Bus service file
|
||||
conf = configuration_data()
|
||||
conf.set('APP_ID', base_id)
|
||||
conf.set('PKGNAME', meson.project_name())
|
||||
conf.set('BINDIR', bindir)
|
||||
configure_file(
|
||||
input: '@0@.service.in'.format(base_id),
|
||||
output: '@0@.service'.format(base_id),
|
||||
configuration: conf,
|
||||
install: true,
|
||||
install_dir: join_paths(datadir,'dbus-1', 'services')
|
||||
)
|
||||
|
||||
subdir('icons')
|
||||
|
|
|
|||
11
data/org.pipewire.Helvum.gresource.xml.in
Normal file
11
data/org.pipewire.Helvum.gresource.xml.in
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="@PATH_ID@">
|
||||
<file preprocess="xml-stripblanks">ui/window.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/node.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/port.ui</file>
|
||||
<file preprocess="xml-stripblanks">ui/zoomentry.ui</file>
|
||||
|
||||
<file compressed="true" alias="style.css">ui/style.css</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
3
data/org.pipewire.Helvum.service.in
Normal file
3
data/org.pipewire.Helvum.service.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[D-BUS Service]
|
||||
Name=@APP_ID@
|
||||
Exec=@BINDIR@/@PKGNAME@ --gapplication-service
|
||||
50
data/ui/node.blp
Normal file
50
data/ui/node.blp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template $HelvumNode: Widget {
|
||||
styles [
|
||||
"card",
|
||||
]
|
||||
|
||||
Box {
|
||||
orientation: vertical;
|
||||
|
||||
Box {
|
||||
styles [
|
||||
"node-title",
|
||||
]
|
||||
|
||||
orientation: vertical;
|
||||
spacing: 1;
|
||||
|
||||
Label node_name {
|
||||
styles [
|
||||
"heading",
|
||||
]
|
||||
|
||||
wrap: true;
|
||||
ellipsize: end;
|
||||
lines: 2;
|
||||
max-width-chars: 20;
|
||||
}
|
||||
|
||||
Label media_name {
|
||||
styles [
|
||||
"dim-label",
|
||||
"caption",
|
||||
]
|
||||
|
||||
visible: false;
|
||||
wrap: true;
|
||||
ellipsize: end;
|
||||
lines: 2;
|
||||
max-width-chars: 20;
|
||||
}
|
||||
}
|
||||
|
||||
Separator separator {
|
||||
visible: false;
|
||||
}
|
||||
|
||||
Grid port_grid {}
|
||||
}
|
||||
}
|
||||
14
data/ui/port.blp
Normal file
14
data/ui/port.blp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template $HelvumPort: Widget {
|
||||
hexpand: true;
|
||||
|
||||
Label label {
|
||||
wrap: true;
|
||||
ellipsize: end;
|
||||
lines: 2;
|
||||
max-width-chars: 20;
|
||||
}
|
||||
|
||||
$HelvumPortHandle handle {}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
/* Copyright 2021 Tom A. Wagner <tom.a.wagner@protonmail.com>
|
||||
|
||||
Copyright 2026 Jaŭhien Lavonćjeŭ <jauhien.lavoncjeu@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 3 as published by
|
||||
the Free Software Foundation.
|
||||
|
|
@ -15,30 +16,25 @@
|
|||
SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
@define-color media-type-audio rgb( 50, 100, 240);
|
||||
@define-color media-type-video rgb(200, 200, 0);
|
||||
@define-color media-type-midi rgb(200, 0, 50);
|
||||
@define-color media-type-unknown rgb(128, 128, 128);
|
||||
|
||||
.audio {
|
||||
background: @media-type-audio;
|
||||
color: black;
|
||||
background: var(--accent-blue);
|
||||
color: var(--accent-blue);
|
||||
}
|
||||
|
||||
.video {
|
||||
background: @media-type-video;
|
||||
color: black;
|
||||
background: var(--accent-yellow);
|
||||
color: var(--accent-yellow);
|
||||
}
|
||||
|
||||
.midi {
|
||||
background: @media-type-midi;
|
||||
color: black;
|
||||
background: var(--accent-red);
|
||||
color: var(--accent-red);
|
||||
}
|
||||
|
||||
node {
|
||||
/* Compared to the default card color, this is not transparent in dark-mode
|
||||
and provides a better contrast to the background in light mode */
|
||||
background-color: @headerbar_bg_color;
|
||||
background-color: var(--headerbar-bg-color);
|
||||
}
|
||||
|
||||
node .node-title {
|
||||
|
|
@ -51,7 +47,8 @@ port label {
|
|||
|
||||
port-handle {
|
||||
border-radius: 50%;
|
||||
background-color: @media-type-unknown;
|
||||
background-color: var(--accent-slate);
|
||||
color: var(--accent-slate);
|
||||
}
|
||||
|
||||
button.rounded {
|
||||
55
data/ui/window.blp
Normal file
55
data/ui/window.blp
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using Gtk 4.0;
|
||||
using Adw 1;
|
||||
|
||||
menu primary_menu {
|
||||
section {
|
||||
item {
|
||||
label: "_About Helvum";
|
||||
action: "app.about";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template $HelvumWindow: Adw.ApplicationWindow {
|
||||
default-width: 1280;
|
||||
default-height: 720;
|
||||
title: _("Helvum - Pipewire Patchbay");
|
||||
|
||||
Adw.ToolbarView {
|
||||
[top]
|
||||
Adw.HeaderBar header_bar {
|
||||
[end]
|
||||
MenuButton {
|
||||
icon-name: "open-menu-symbolic";
|
||||
menu-model: primary_menu;
|
||||
}
|
||||
}
|
||||
|
||||
content: Box {
|
||||
orientation: vertical;
|
||||
|
||||
Adw.Banner connection_banner {
|
||||
title: _("Disconnected");
|
||||
revealed: false;
|
||||
}
|
||||
|
||||
Overlay {
|
||||
ScrolledWindow {
|
||||
$HelvumGraphView graph {
|
||||
hexpand: "true";
|
||||
vexpand: "true";
|
||||
}
|
||||
}
|
||||
|
||||
[overlay]
|
||||
$HelvumZoomEntry {
|
||||
zoomed-widget: "graph";
|
||||
halign: "end";
|
||||
valign: "end";
|
||||
margin-end: "24";
|
||||
margin-bottom: "24";
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
36
data/ui/zoomentry.blp
Normal file
36
data/ui/zoomentry.blp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template $HelvumZoomEntry: Box {
|
||||
spacing: 12;
|
||||
|
||||
Entry entry {
|
||||
secondary-icon-name: "go-down-symbolic";
|
||||
input-purpose: digits;
|
||||
max-width-chars: 5;
|
||||
|
||||
styles [
|
||||
"osd",
|
||||
"rounded",
|
||||
]
|
||||
}
|
||||
|
||||
Button zoom_out_button {
|
||||
icon-name: "zoom-out-symbolic";
|
||||
tooltip-text: _("Zoom out");
|
||||
|
||||
styles [
|
||||
"osd",
|
||||
"rounded",
|
||||
]
|
||||
}
|
||||
|
||||
Button zoom_in_button {
|
||||
icon-name: "zoom-in-symbolic";
|
||||
tooltip-text: _("Zoom in");
|
||||
|
||||
styles [
|
||||
"osd",
|
||||
"rounded",
|
||||
]
|
||||
}
|
||||
}
|
||||
11
meson.build
11
meson.build
|
|
@ -11,9 +11,10 @@ gnome = import('gnome')
|
|||
base_id = 'org.pipewire.Helvum'
|
||||
|
||||
dependency('glib-2.0', version: '>= 2.66')
|
||||
dependency('gtk4', version: '>= 4.4.0')
|
||||
dependency('libadwaita-1', version: '>= 1.4')
|
||||
dependency('gtk4', version: '>= 4.22.0')
|
||||
dependency('libadwaita-1', version: '>= 1.9')
|
||||
dependency('libpipewire-0.3')
|
||||
dependency('blueprint-compiler')
|
||||
|
||||
desktop_file_validate = find_program('desktop-file-validate', required: false)
|
||||
appstream_util = find_program('appstream-util', required: false)
|
||||
|
|
@ -23,6 +24,7 @@ prefix = get_option('prefix')
|
|||
bindir = prefix / get_option('bindir')
|
||||
datadir = prefix / get_option('datadir')
|
||||
iconsdir = datadir / 'icons'
|
||||
path_id = '/org/pipewire/Helvum'
|
||||
|
||||
meson.add_dist_script(
|
||||
'build-aux/dist-vendor.sh',
|
||||
|
|
@ -32,8 +34,3 @@ meson.add_dist_script(
|
|||
|
||||
subdir('src')
|
||||
subdir('data')
|
||||
|
||||
gnome.post_install(
|
||||
gtk_update_icon_cache: true,
|
||||
update_desktop_database: true,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2021 Tom A. Wagner <tom.a.wagner@protonmail.com>
|
||||
// Copyright 2026 Jaŭhien Lavonćjeŭ <jauhien.lavoncjeu@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 3 as published by
|
||||
|
|
@ -14,28 +15,28 @@
|
|||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use futures::channel::mpsc::UnboundedReceiver;
|
||||
use pipewire::channel::Sender;
|
||||
use std::cell::OnceCell;
|
||||
|
||||
use adw::{
|
||||
gio,
|
||||
glib::{self, clone, Receiver},
|
||||
glib::{self, clone},
|
||||
gtk,
|
||||
prelude::*,
|
||||
subclass::prelude::*,
|
||||
};
|
||||
use pipewire::channel::Sender;
|
||||
|
||||
use crate::{graph_manager::GraphManager, ui, GtkMessage, PipewireMessage};
|
||||
use crate::{GtkMessage, PipewireMessage, graph_manager::GraphManager, ui};
|
||||
|
||||
static STYLE: &str = include_str!("style.css");
|
||||
static APP_ID: &str = "org.pipewire.Helvum";
|
||||
static VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
static AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
|
||||
static APP_ID: Option<&str> = option_env!("APP_ID");
|
||||
static PATH_ID: Option<&str> = option_env!("PATH_ID");
|
||||
static VERSION: Option<&str> = option_env!("VERSION");
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
use adw::subclass::prelude::AdwApplicationImpl;
|
||||
use once_cell::unsync::OnceCell;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Application {
|
||||
pub(super) window: ui::Window,
|
||||
|
|
@ -60,31 +61,21 @@ mod imp {
|
|||
|
||||
let zoom_set_action =
|
||||
gio::SimpleAction::new("set-zoom", Some(&f64::static_variant_type()));
|
||||
zoom_set_action.connect_activate(clone!(@weak graphview => move|_, param| {
|
||||
let zoom_factor = param.unwrap().get::<f64>().unwrap();
|
||||
graphview.set_zoom_factor(zoom_factor, None)
|
||||
}));
|
||||
zoom_set_action.connect_activate(clone!(
|
||||
#[weak]
|
||||
graphview,
|
||||
move |_, param| {
|
||||
let zoom_factor = param.unwrap().get::<f64>().unwrap();
|
||||
graphview.set_zoom_factor(zoom_factor, None)
|
||||
}
|
||||
));
|
||||
self.window.add_action(&zoom_set_action);
|
||||
|
||||
self.window.show();
|
||||
self.window.present();
|
||||
}
|
||||
|
||||
fn startup(&self) {
|
||||
self.parent_startup();
|
||||
|
||||
self.obj()
|
||||
.style_manager()
|
||||
.set_color_scheme(adw::ColorScheme::PreferDark);
|
||||
|
||||
// Load CSS from the STYLE variable.
|
||||
let provider = gtk::CssProvider::new();
|
||||
provider.load_from_data(STYLE);
|
||||
gtk::style_context_add_provider_for_display(
|
||||
>k::gdk::Display::default().expect("Error initializing gtk css provider."),
|
||||
&provider,
|
||||
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
);
|
||||
|
||||
self.setup_actions();
|
||||
}
|
||||
}
|
||||
|
|
@ -97,9 +88,13 @@ mod imp {
|
|||
|
||||
// Add <Control-Q> shortcut for quitting the application.
|
||||
let quit = gtk::gio::SimpleAction::new("quit", None);
|
||||
quit.connect_activate(clone!(@weak obj => move |_, _| {
|
||||
obj.quit();
|
||||
}));
|
||||
quit.connect_activate(clone!(
|
||||
#[weak]
|
||||
obj,
|
||||
move |_, _| {
|
||||
obj.quit();
|
||||
}
|
||||
));
|
||||
obj.set_accels_for_action("app.quit", &["<Control>Q"]);
|
||||
obj.add_action(&quit);
|
||||
|
||||
|
|
@ -116,19 +111,18 @@ mod imp {
|
|||
let window = obj.active_window().unwrap();
|
||||
let authors: Vec<&str> = AUTHORS.split(':').collect();
|
||||
|
||||
let about_window = adw::AboutWindow::builder()
|
||||
.transient_for(&window)
|
||||
.application_icon(APP_ID)
|
||||
let about_dialog = adw::AboutDialog::builder()
|
||||
.application_icon(APP_ID.unwrap())
|
||||
.application_name("Helvum")
|
||||
.developer_name("Tom Wagner")
|
||||
.developers(authors)
|
||||
.version(VERSION)
|
||||
.version(VERSION.unwrap())
|
||||
.website("https://gitlab.freedesktop.org/pipewire/helvum")
|
||||
.issue_url("https://gitlab.freedesktop.org/pipewire/helvum/-/issues")
|
||||
.license_type(gtk::License::Gpl30Only)
|
||||
.build();
|
||||
|
||||
about_window.present();
|
||||
about_dialog.present(Some(&window));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -143,11 +137,12 @@ impl Application {
|
|||
/// Create the view.
|
||||
/// This will set up the entire user interface and prepare it for being run.
|
||||
pub(super) fn new(
|
||||
gtk_receiver: Receiver<PipewireMessage>,
|
||||
gtk_receiver: UnboundedReceiver<PipewireMessage>,
|
||||
pw_sender: Sender<GtkMessage>,
|
||||
) -> Self {
|
||||
let app: Application = glib::Object::builder()
|
||||
.property("application-id", APP_ID)
|
||||
.property("resource-base-path", PATH_ID)
|
||||
.build();
|
||||
|
||||
let imp = app.imp();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2021 Tom A. Wagner <tom.a.wagner@protonmail.com>
|
||||
// Copyright 2026 Jaŭhien Lavonćjeŭ <jauhien.lavoncjeu@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 3 as published by
|
||||
|
|
@ -14,31 +15,34 @@
|
|||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use adw::{glib, prelude::*, subclass::prelude::*};
|
||||
use futures::{channel::mpsc::UnboundedReceiver, prelude::*};
|
||||
use std::{
|
||||
cell::{OnceCell, RefCell},
|
||||
collections::HashMap,
|
||||
};
|
||||
|
||||
use pipewire::channel::Sender as PwSender;
|
||||
use adw::{glib::clone, prelude::*, subclass::prelude::*};
|
||||
|
||||
use crate::{ui::graph::GraphView, GtkMessage, PipewireMessage};
|
||||
use pipewire::{
|
||||
channel::Sender,
|
||||
spa::{param::format::MediaType, utils::Direction},
|
||||
};
|
||||
|
||||
use crate::{GtkMessage, NodeType, PipewireMessage, ui::graph, ui::graph::GraphView};
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
|
||||
use once_cell::unsync::OnceCell;
|
||||
|
||||
use crate::{ui::graph, MediaType, NodeType};
|
||||
|
||||
#[derive(Default, glib::Properties)]
|
||||
#[properties(wrapper_type = super::GraphManager)]
|
||||
pub struct GraphManager {
|
||||
#[property(get, set, construct_only)]
|
||||
pub graph: OnceCell<crate::ui::graph::GraphView>,
|
||||
pub graph: OnceCell<GraphView>,
|
||||
|
||||
#[property(get, set, construct_only)]
|
||||
pub connection_banner: OnceCell<adw::Banner>,
|
||||
|
||||
pub pw_sender: OnceCell<PwSender<crate::GtkMessage>>,
|
||||
pub pw_sender: OnceCell<Sender<crate::GtkMessage>>,
|
||||
pub items: RefCell<HashMap<u32, glib::Object>>,
|
||||
}
|
||||
|
||||
|
|
@ -53,34 +57,61 @@ mod imp {
|
|||
impl ObjectImpl for GraphManager {}
|
||||
|
||||
impl GraphManager {
|
||||
pub fn attach_receiver(&self, receiver: glib::Receiver<crate::PipewireMessage>) {
|
||||
receiver.attach(None, glib::clone!(
|
||||
@weak self as imp => @default-return glib::ControlFlow::Continue,
|
||||
move |msg| {
|
||||
match msg {
|
||||
PipewireMessage::NodeAdded { id, name, node_type } => imp.add_node(id, name.as_str(), node_type),
|
||||
PipewireMessage::NodeNameChanged { id, name, media_name } => imp.node_name_changed(id, &name, &media_name),
|
||||
PipewireMessage::PortAdded { id, node_id, name, direction } => imp.add_port(id, name.as_str(), node_id, direction),
|
||||
PipewireMessage::PortFormatChanged { id, media_type } => imp.port_media_type_changed(id, media_type),
|
||||
PipewireMessage::LinkAdded {
|
||||
id, port_from, port_to, active, media_type
|
||||
} => imp.add_link(id, port_from, port_to, active, media_type),
|
||||
PipewireMessage::LinkStateChanged { id, active } => imp.link_state_changed(id, active),
|
||||
PipewireMessage::LinkFormatChanged { id, media_type } => imp.link_format_changed(id, media_type),
|
||||
PipewireMessage::NodeRemoved { id } => imp.remove_node(id),
|
||||
PipewireMessage::PortRemoved { id, node_id } => imp.remove_port(id, node_id),
|
||||
PipewireMessage::LinkRemoved { id } => imp.remove_link(id),
|
||||
PipewireMessage::Connecting => {
|
||||
imp.obj().connection_banner().set_revealed(true);
|
||||
}
|
||||
PipewireMessage::Connected => {
|
||||
imp.obj().connection_banner().set_revealed(false);
|
||||
},
|
||||
PipewireMessage::Disconnected => {
|
||||
imp.clear();
|
||||
},
|
||||
};
|
||||
glib::ControlFlow::Continue
|
||||
pub fn attach_receiver(&self, mut receiver: UnboundedReceiver<PipewireMessage>) {
|
||||
glib::MainContext::default().spawn_local(clone!(
|
||||
#[weak(rename_to = imp)]
|
||||
self,
|
||||
async move {
|
||||
while let Some(msg) = receiver.next().await {
|
||||
match msg {
|
||||
PipewireMessage::NodeAdded {
|
||||
id,
|
||||
name,
|
||||
node_type,
|
||||
} => imp.add_node(id, name.as_str(), node_type),
|
||||
PipewireMessage::NodeNameChanged {
|
||||
id,
|
||||
name,
|
||||
media_name,
|
||||
} => imp.node_name_changed(id, &name, &media_name),
|
||||
PipewireMessage::PortAdded {
|
||||
id,
|
||||
node_id,
|
||||
name,
|
||||
direction,
|
||||
} => imp.add_port(id, name.as_str(), node_id, direction),
|
||||
PipewireMessage::PortFormatChanged { id, media_type } => {
|
||||
imp.port_media_type_changed(id, media_type)
|
||||
}
|
||||
PipewireMessage::LinkAdded {
|
||||
id,
|
||||
port_from,
|
||||
port_to,
|
||||
active,
|
||||
media_type,
|
||||
} => imp.add_link(id, port_from, port_to, active, media_type),
|
||||
PipewireMessage::LinkStateChanged { id, active } => {
|
||||
imp.link_state_changed(id, active)
|
||||
}
|
||||
PipewireMessage::LinkFormatChanged { id, media_type } => {
|
||||
imp.link_format_changed(id, media_type)
|
||||
}
|
||||
PipewireMessage::NodeRemoved { id } => imp.remove_node(id),
|
||||
PipewireMessage::PortRemoved { id, node_id } => {
|
||||
imp.remove_port(id, node_id)
|
||||
}
|
||||
PipewireMessage::LinkRemoved { id } => imp.remove_link(id),
|
||||
PipewireMessage::Connecting => {
|
||||
imp.obj().connection_banner().set_revealed(true);
|
||||
}
|
||||
PipewireMessage::Connected => {
|
||||
imp.obj().connection_banner().set_revealed(false);
|
||||
}
|
||||
PipewireMessage::Disconnected => {
|
||||
imp.clear();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
|
@ -130,7 +161,7 @@ mod imp {
|
|||
}
|
||||
|
||||
/// Add a new port to the view.
|
||||
fn add_port(&self, id: u32, name: &str, node_id: u32, direction: pipewire::spa::Direction) {
|
||||
fn add_port(&self, id: u32, name: &str, node_id: u32, direction: Direction) {
|
||||
log::info!("Adding port to graph: id {}", id);
|
||||
|
||||
let mut items = self.items.borrow_mut();
|
||||
|
|
@ -150,15 +181,21 @@ mod imp {
|
|||
port.connect_local(
|
||||
"port_toggled",
|
||||
false,
|
||||
glib::clone!(@weak self as app => @default-return None, move |args| {
|
||||
// Args always look like this: &[widget, id_port_from, id_port_to]
|
||||
let port_from = args[1].get::<u32>().unwrap();
|
||||
let port_to = args[2].get::<u32>().unwrap();
|
||||
glib::clone!(
|
||||
#[weak(rename_to = app)]
|
||||
self,
|
||||
#[upgrade_or]
|
||||
None,
|
||||
move |args| {
|
||||
// Args always look like this: &[widget, id_port_from, id_port_to]
|
||||
let port_from = args[1].get::<u32>().unwrap();
|
||||
let port_to = args[2].get::<u32>().unwrap();
|
||||
|
||||
app.toggle_link(port_from, port_to);
|
||||
app.toggle_link(port_from, port_to);
|
||||
|
||||
None
|
||||
}),
|
||||
None
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
items.insert(id, port.clone().upcast());
|
||||
|
|
@ -222,7 +259,9 @@ mod imp {
|
|||
let mut items = self.items.borrow_mut();
|
||||
|
||||
let Some(output_port) = items.get(&output_port_id) else {
|
||||
log::warn!("Output port (id: {output_port_id}) for link (id: {id}) not found in graph manager");
|
||||
log::warn!(
|
||||
"Output port (id: {output_port_id}) for link (id: {id}) not found in graph manager"
|
||||
);
|
||||
return;
|
||||
};
|
||||
let Ok(output_port) = output_port.clone().dynamic_cast::<graph::Port>() else {
|
||||
|
|
@ -230,7 +269,9 @@ mod imp {
|
|||
return;
|
||||
};
|
||||
let Some(input_port) = items.get(&input_port_id) else {
|
||||
log::warn!("Output port (id: {input_port_id}) for link (id: {id}) not found in graph manager");
|
||||
log::warn!(
|
||||
"Output port (id: {input_port_id}) for link (id: {id}) not found in graph manager"
|
||||
);
|
||||
return;
|
||||
};
|
||||
let Ok(input_port) = input_port.clone().dynamic_cast::<graph::Port>() else {
|
||||
|
|
@ -273,7 +314,7 @@ mod imp {
|
|||
link.set_active(active);
|
||||
}
|
||||
|
||||
fn link_format_changed(&self, id: u32, media_type: pipewire::spa::format::MediaType) {
|
||||
fn link_format_changed(&self, id: u32, media_type: MediaType) {
|
||||
let items = self.items.borrow();
|
||||
|
||||
let Some(link) = items.get(&id) else {
|
||||
|
|
@ -326,8 +367,8 @@ impl GraphManager {
|
|||
pub fn new(
|
||||
graph: &GraphView,
|
||||
connection_banner: &adw::Banner,
|
||||
sender: PwSender<GtkMessage>,
|
||||
receiver: glib::Receiver<PipewireMessage>,
|
||||
sender: Sender<GtkMessage>,
|
||||
receiver: UnboundedReceiver<PipewireMessage>,
|
||||
) -> Self {
|
||||
let res: Self = glib::Object::builder()
|
||||
.property("graph", graph)
|
||||
|
|
|
|||
25
src/main.rs
25
src/main.rs
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2021 Tom A. Wagner <tom.a.wagner@protonmail.com>
|
||||
// Copyright 2026 Jaŭhien Lavonćjeŭ <jauhien.lavoncjeu@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 3 as published by
|
||||
|
|
@ -19,8 +20,14 @@ mod graph_manager;
|
|||
mod pipewire_connection;
|
||||
mod ui;
|
||||
|
||||
use adw::{gtk, prelude::*};
|
||||
use pipewire::spa::{format::MediaType, Direction};
|
||||
use futures::channel::mpsc::unbounded;
|
||||
use pipewire::spa::{param::format::MediaType, utils::Direction};
|
||||
|
||||
use adw::{gio, gtk, prelude::*};
|
||||
|
||||
static APP_ID: Option<&str> = option_env!("APP_ID");
|
||||
static PKGNAME: Option<&str> = option_env!("PKGNAME");
|
||||
static DATADIR: Option<&str> = option_env!("DATADIR");
|
||||
|
||||
/// Messages sent by the GTK thread to notify the pipewire thread.
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -112,21 +119,21 @@ fn init_glib_logger() {
|
|||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
init_glib_logger();
|
||||
gtk::init()?;
|
||||
|
||||
// Aquire main context so that we can attach the gtk channel later.
|
||||
let ctx = glib::MainContext::default();
|
||||
let _guard = ctx.acquire().unwrap();
|
||||
let path = std::path::PathBuf::from(DATADIR.unwrap())
|
||||
.join(PKGNAME.unwrap())
|
||||
.join(format!("{}.gresource", APP_ID.unwrap()));
|
||||
let resources = gio::Resource::load(path.to_str().unwrap()).expect("Could not load resources");
|
||||
gio::resources_register(&resources);
|
||||
|
||||
// Start the pipewire thread with channels in both directions.
|
||||
|
||||
let (gtk_sender, gtk_receiver) = glib::MainContext::channel(glib::Priority::DEFAULT);
|
||||
let (gtk_sender, gtk_receiver) = unbounded::<PipewireMessage>();
|
||||
let (pw_sender, pw_receiver) = pipewire::channel::channel();
|
||||
let pw_thread =
|
||||
std::thread::spawn(move || pipewire_connection::thread_main(gtk_sender, pw_receiver));
|
||||
|
||||
gtk::init()?;
|
||||
let app = application::Application::new(gtk_receiver, pw_sender.clone());
|
||||
|
||||
app.run();
|
||||
|
||||
pw_sender
|
||||
|
|
|
|||
|
|
@ -1,3 +1,13 @@
|
|||
cargo_env = [
|
||||
'CARGO_HOME=' + meson.project_build_root() / 'cargo-home',
|
||||
'PKGNAME=' + meson.project_name(),
|
||||
'VERSION=' + '@0@'.format(meson.project_version()),
|
||||
'APP_ID=' + base_id,
|
||||
'PATH_ID=' + path_id,
|
||||
'PREFIX=' + prefix,
|
||||
'DATADIR=' + datadir
|
||||
]
|
||||
|
||||
cargo_options = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ]
|
||||
cargo_options += [ '--target-dir', meson.project_build_root() / 'src' ]
|
||||
|
||||
|
|
@ -10,8 +20,6 @@ else
|
|||
message('Building in debug mode')
|
||||
endif
|
||||
|
||||
cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
|
||||
|
||||
custom_target(
|
||||
'cargo-build',
|
||||
build_by_default: true,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2021 Tom A. Wagner <tom.a.wagner@protonmail.com>
|
||||
// Copyright 2026 Jaŭhien Lavonćjeŭ <jauhien.lavoncjeu@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 3 as published by
|
||||
|
|
@ -23,22 +24,25 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
|
||||
use adw::glib::{self, clone};
|
||||
use futures::channel::mpsc::UnboundedSender;
|
||||
use glib::clone;
|
||||
use log::{debug, error, info, warn};
|
||||
use pipewire::{
|
||||
channel::Receiver,
|
||||
context::ContextRc,
|
||||
core::{CoreRc, PW_ID_CORE},
|
||||
keys,
|
||||
link::{Link, LinkChangeMask, LinkInfo, LinkListener, LinkState},
|
||||
node::{Node, NodeInfo, NodeListener},
|
||||
port::{Port, PortChangeMask, PortInfo, PortListener},
|
||||
prelude::*,
|
||||
properties,
|
||||
registry::{GlobalObject, Registry},
|
||||
link::{Link, LinkChangeMask, LinkInfoRef, LinkListener, LinkState},
|
||||
main_loop::MainLoopRc,
|
||||
node::{Node, NodeInfoRef, NodeListener},
|
||||
port::{Port, PortChangeMask, PortInfoRef, PortListener},
|
||||
properties::properties,
|
||||
registry::{GlobalObject, RegistryRc},
|
||||
spa::{
|
||||
param::{ParamInfoFlags, ParamType},
|
||||
ForeignDict, SpaResult,
|
||||
utils::{dict::DictRef, result::SpaResult},
|
||||
},
|
||||
types::ObjectType,
|
||||
Context, Core, MainLoop,
|
||||
};
|
||||
|
||||
use crate::{GtkMessage, MediaType, NodeType, PipewireMessage};
|
||||
|
|
@ -61,124 +65,181 @@ enum ProxyItem {
|
|||
|
||||
/// The "main" function of the pipewire thread.
|
||||
pub(super) fn thread_main(
|
||||
gtk_sender: glib::Sender<PipewireMessage>,
|
||||
mut pw_receiver: pipewire::channel::Receiver<GtkMessage>,
|
||||
gtk_sender: UnboundedSender<PipewireMessage>,
|
||||
mut pw_receiver: Receiver<GtkMessage>,
|
||||
) {
|
||||
let mainloop = MainLoop::new().expect("Failed to create mainloop");
|
||||
let context = Rc::new(Context::new(&mainloop).expect("Failed to create context"));
|
||||
let mainloop = MainLoopRc::new(None).expect("Failed to create mainloop");
|
||||
let context = ContextRc::new(&mainloop, None).expect("Failed to create context");
|
||||
let is_stopped = Rc::new(Cell::new(false));
|
||||
let mut is_connecting = false;
|
||||
|
||||
while !is_stopped.get() {
|
||||
// Try to connect
|
||||
let core = match context.connect(Some(properties! {
|
||||
let Ok(core) = context.connect_rc(Some(properties! {
|
||||
"media.category" => "Manager"
|
||||
})) {
|
||||
Ok(core) => Rc::new(core),
|
||||
Err(_) => {
|
||||
if !is_connecting {
|
||||
is_connecting = true;
|
||||
gtk_sender
|
||||
.send(PipewireMessage::Connecting)
|
||||
.expect("Failed to send message");
|
||||
}
|
||||
|
||||
// If connection is failed, try to connect again in 200ms
|
||||
let interval = Some(Duration::from_millis(200));
|
||||
|
||||
let timer = mainloop.add_timer(clone!(@strong mainloop => move |_| {
|
||||
mainloop.quit();
|
||||
}));
|
||||
|
||||
timer.update_timer(interval, None).into_result().unwrap();
|
||||
|
||||
let receiver = pw_receiver.attach(&mainloop, {
|
||||
clone!(@strong mainloop, @strong is_stopped => move |msg|
|
||||
if let GtkMessage::Terminate = msg {
|
||||
// main thread requested stop
|
||||
is_stopped.set(true);
|
||||
mainloop.quit();
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
mainloop.run();
|
||||
pw_receiver = receiver.deattach();
|
||||
|
||||
continue;
|
||||
})) else {
|
||||
if !is_connecting {
|
||||
is_connecting = true;
|
||||
gtk_sender
|
||||
.unbounded_send(PipewireMessage::Connecting)
|
||||
.expect("Failed to send message");
|
||||
}
|
||||
|
||||
// If connection is failed, try to connect again in 200ms
|
||||
let interval = Some(Duration::from_millis(200));
|
||||
|
||||
let timer = mainloop.loop_().add_timer(clone!(
|
||||
#[strong]
|
||||
mainloop,
|
||||
move |_| {
|
||||
mainloop.quit();
|
||||
}
|
||||
));
|
||||
|
||||
timer.update_timer(interval, None).into_result().unwrap();
|
||||
|
||||
let receiver = pw_receiver.attach(mainloop.loop_(), {
|
||||
clone!(
|
||||
#[strong]
|
||||
mainloop,
|
||||
#[strong]
|
||||
is_stopped,
|
||||
move |msg| if let GtkMessage::Terminate = msg {
|
||||
// main thread requested stop
|
||||
is_stopped.set(true);
|
||||
mainloop.quit();
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
mainloop.run();
|
||||
pw_receiver = receiver.deattach();
|
||||
|
||||
continue;
|
||||
};
|
||||
|
||||
if is_connecting {
|
||||
is_connecting = false;
|
||||
gtk_sender
|
||||
.send(PipewireMessage::Connected)
|
||||
.unbounded_send(PipewireMessage::Connected)
|
||||
.expect("Failed to send message");
|
||||
}
|
||||
|
||||
let registry = Rc::new(core.get_registry().expect("Failed to get registry"));
|
||||
let registry = core.get_registry_rc().expect("Failed to get registry");
|
||||
|
||||
// Keep proxies and their listeners alive so that we can receive info events.
|
||||
let proxies = Rc::new(RefCell::new(HashMap::new()));
|
||||
let state = Rc::new(RefCell::new(State::new()));
|
||||
|
||||
let receiver = pw_receiver.attach(&mainloop, {
|
||||
clone!(@strong mainloop, @weak core, @weak registry, @strong state, @strong is_stopped => move |msg| match msg {
|
||||
GtkMessage::ToggleLink { port_from, port_to } => toggle_link(port_from, port_to, &core, ®istry, &state),
|
||||
GtkMessage::Terminate => {
|
||||
// main thread requested stop
|
||||
is_stopped.set(true);
|
||||
mainloop.quit();
|
||||
let receiver = pw_receiver.attach(mainloop.loop_(), {
|
||||
clone!(
|
||||
#[strong]
|
||||
mainloop,
|
||||
#[strong]
|
||||
core,
|
||||
#[strong]
|
||||
registry,
|
||||
#[strong]
|
||||
state,
|
||||
#[strong]
|
||||
is_stopped,
|
||||
move |msg| match msg {
|
||||
GtkMessage::ToggleLink { port_from, port_to } =>
|
||||
toggle_link(port_from, port_to, &core, ®istry, &state.borrow()),
|
||||
GtkMessage::Terminate => {
|
||||
// main thread requested stop
|
||||
is_stopped.set(true);
|
||||
mainloop.quit();
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
});
|
||||
|
||||
let gtk_sender = gtk_sender.clone();
|
||||
let _listener = core.add_listener_local()
|
||||
.error(clone!(@strong mainloop, @strong gtk_sender, @strong is_stopped => move |id, _seq, res, message| {
|
||||
if id != pipewire::PW_ID_CORE {
|
||||
return;
|
||||
}
|
||||
let _listener = core
|
||||
.add_listener_local()
|
||||
.error(clone!(
|
||||
#[strong]
|
||||
mainloop,
|
||||
#[strong]
|
||||
gtk_sender,
|
||||
move |id, _seq, res, message| {
|
||||
if id != PW_ID_CORE {
|
||||
return;
|
||||
}
|
||||
|
||||
if res == -libc::EPIPE {
|
||||
gtk_sender.send(PipewireMessage::Disconnected)
|
||||
.expect("Failed to send message");
|
||||
mainloop.quit();
|
||||
} else {
|
||||
let serr = SpaResult::from_c(res).into_result().unwrap_err();
|
||||
error!("Pipewire Core received error {serr}: {message}");
|
||||
if res == -libc::EPIPE {
|
||||
gtk_sender
|
||||
.unbounded_send(PipewireMessage::Disconnected)
|
||||
.expect("Failed to send message");
|
||||
mainloop.quit();
|
||||
} else {
|
||||
let serr = SpaResult::from_c(res).into_result().unwrap_err();
|
||||
error!("Pipewire Core received error {serr}: {message}");
|
||||
}
|
||||
}
|
||||
}))
|
||||
))
|
||||
.register();
|
||||
|
||||
let _listener = registry
|
||||
.add_listener_local()
|
||||
.global(clone!(@strong gtk_sender, @weak registry, @strong proxies, @strong state =>
|
||||
.global(clone!(
|
||||
#[strong]
|
||||
gtk_sender,
|
||||
#[strong]
|
||||
registry,
|
||||
#[strong]
|
||||
proxies,
|
||||
#[strong]
|
||||
state,
|
||||
move |global| match global.type_ {
|
||||
ObjectType::Node => handle_node(global, >k_sender, ®istry, &proxies, &state),
|
||||
ObjectType::Port => handle_port(global, >k_sender, ®istry, &proxies, &state),
|
||||
ObjectType::Link => handle_link(global, >k_sender, ®istry, &proxies, &state),
|
||||
ObjectType::Node => handle_node(
|
||||
global,
|
||||
>k_sender,
|
||||
®istry,
|
||||
&proxies,
|
||||
&mut state.borrow_mut()
|
||||
),
|
||||
ObjectType::Port =>
|
||||
handle_port(global, >k_sender, ®istry, &proxies, &state),
|
||||
ObjectType::Link => handle_link(
|
||||
global,
|
||||
>k_sender,
|
||||
®istry,
|
||||
&mut proxies.borrow_mut(),
|
||||
&state
|
||||
),
|
||||
_ => {
|
||||
// Other objects are not interesting to us
|
||||
}
|
||||
}
|
||||
))
|
||||
.global_remove(clone!(@strong proxies, @strong state => move |id| {
|
||||
if let Some(item) = state.borrow_mut().remove(id) {
|
||||
gtk_sender.send(match item {
|
||||
Item::Node { .. } => PipewireMessage::NodeRemoved {id},
|
||||
Item::Port { node_id } => PipewireMessage::PortRemoved {id, node_id},
|
||||
Item::Link { .. } => PipewireMessage::LinkRemoved {id},
|
||||
}).expect("Failed to send message");
|
||||
} else {
|
||||
warn!(
|
||||
"Attempted to remove item with id {} that is not saved in state",
|
||||
id
|
||||
);
|
||||
}
|
||||
.global_remove(clone!(
|
||||
#[strong]
|
||||
proxies,
|
||||
#[strong]
|
||||
state,
|
||||
move |id| {
|
||||
if let Some(item) = state.borrow_mut().remove(id) {
|
||||
gtk_sender
|
||||
.unbounded_send(match item {
|
||||
Item::Node => PipewireMessage::NodeRemoved { id },
|
||||
Item::Port { node_id } => {
|
||||
PipewireMessage::PortRemoved { id, node_id }
|
||||
}
|
||||
Item::Link { .. } => PipewireMessage::LinkRemoved { id },
|
||||
})
|
||||
.expect("Failed to send message");
|
||||
} else {
|
||||
warn!(
|
||||
"Attempted to remove item with id {} that is not saved in state",
|
||||
id
|
||||
);
|
||||
}
|
||||
|
||||
proxies.borrow_mut().remove(&id);
|
||||
}))
|
||||
proxies.borrow_mut().remove(&id);
|
||||
}
|
||||
))
|
||||
.register();
|
||||
|
||||
mainloop.run();
|
||||
|
|
@ -187,21 +248,22 @@ pub(super) fn thread_main(
|
|||
}
|
||||
|
||||
/// Get the nicest possible name for the node, using a fallback chain of possible name attributes
|
||||
fn get_node_name(props: &ForeignDict) -> &str {
|
||||
fn get_node_name(props: &DictRef) -> String {
|
||||
props
|
||||
.get(&keys::NODE_DESCRIPTION)
|
||||
.or_else(|| props.get(&keys::NODE_NICK))
|
||||
.or_else(|| props.get(&keys::NODE_NAME))
|
||||
.unwrap_or_default()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
/// Handle a new node being added
|
||||
fn handle_node(
|
||||
node: &GlobalObject<ForeignDict>,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
registry: &Rc<Registry>,
|
||||
node: &GlobalObject<&DictRef>,
|
||||
sender: &UnboundedSender<PipewireMessage>,
|
||||
registry: &RegistryRc,
|
||||
proxies: &Rc<RefCell<HashMap<u32, ProxyItem>>>,
|
||||
state: &Rc<RefCell<State>>,
|
||||
state: &mut State,
|
||||
) {
|
||||
let props = node
|
||||
.props
|
||||
|
|
@ -230,10 +292,10 @@ fn handle_node(
|
|||
})
|
||||
.or_else(|| props.get("media.class").and_then(media_class));
|
||||
|
||||
state.borrow_mut().insert(node.id, Item::Node);
|
||||
state.insert(node.id, Item::Node);
|
||||
|
||||
sender
|
||||
.send(PipewireMessage::NodeAdded {
|
||||
.unbounded_send(PipewireMessage::NodeAdded {
|
||||
id: node.id,
|
||||
name,
|
||||
node_type,
|
||||
|
|
@ -243,9 +305,15 @@ fn handle_node(
|
|||
let proxy: Node = registry.bind(node).expect("Failed to bind to node proxy");
|
||||
let listener = proxy
|
||||
.add_listener_local()
|
||||
.info(clone!(@strong sender, @strong proxies => move |info| {
|
||||
handle_node_info(info, &sender, &proxies);
|
||||
}))
|
||||
.info(clone!(
|
||||
#[strong]
|
||||
sender,
|
||||
#[strong]
|
||||
proxies,
|
||||
move |info| {
|
||||
handle_node_info(info, &sender, &proxies.borrow());
|
||||
}
|
||||
))
|
||||
.register();
|
||||
|
||||
proxies.borrow_mut().insert(
|
||||
|
|
@ -258,14 +326,13 @@ fn handle_node(
|
|||
}
|
||||
|
||||
fn handle_node_info(
|
||||
info: &NodeInfo,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
proxies: &Rc<RefCell<HashMap<u32, ProxyItem>>>,
|
||||
info: &NodeInfoRef,
|
||||
sender: &UnboundedSender<PipewireMessage>,
|
||||
proxies: &HashMap<u32, ProxyItem>,
|
||||
) {
|
||||
debug!("Received node info: {:?}", info);
|
||||
|
||||
let id = info.id();
|
||||
let proxies = proxies.borrow();
|
||||
let Some(ProxyItem::Node { .. }) = proxies.get(&id) else {
|
||||
error!("Received info on unknown node with id {id}");
|
||||
return;
|
||||
|
|
@ -276,7 +343,7 @@ fn handle_node_info(
|
|||
let name = get_node_name(props).to_string();
|
||||
|
||||
sender
|
||||
.send(PipewireMessage::NodeNameChanged {
|
||||
.unbounded_send(PipewireMessage::NodeNameChanged {
|
||||
id,
|
||||
name,
|
||||
media_name: media_name.to_string(),
|
||||
|
|
@ -287,9 +354,9 @@ fn handle_node_info(
|
|||
|
||||
/// Handle a new port being added
|
||||
fn handle_port(
|
||||
port: &GlobalObject<ForeignDict>,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
registry: &Rc<Registry>,
|
||||
port: &GlobalObject<&DictRef>,
|
||||
sender: &UnboundedSender<PipewireMessage>,
|
||||
registry: &RegistryRc,
|
||||
proxies: &Rc<RefCell<HashMap<u32, ProxyItem>>>,
|
||||
state: &Rc<RefCell<State>>,
|
||||
) {
|
||||
|
|
@ -297,16 +364,26 @@ fn handle_port(
|
|||
let proxy: Port = registry.bind(port).expect("Failed to bind to port proxy");
|
||||
let listener = proxy
|
||||
.add_listener_local()
|
||||
.info(
|
||||
clone!(@strong proxies, @strong state, @strong sender => move |info| {
|
||||
handle_port_info(info, &proxies, &state, &sender);
|
||||
}),
|
||||
)
|
||||
.param(clone!(@strong sender => move |_, param_id, _, _, param| {
|
||||
if param_id == ParamType::EnumFormat {
|
||||
handle_port_enum_format(port_id, param, &sender)
|
||||
.info(clone!(
|
||||
#[strong]
|
||||
proxies,
|
||||
#[strong]
|
||||
state,
|
||||
#[strong]
|
||||
sender,
|
||||
move |info| {
|
||||
handle_port_info(info, &proxies.borrow(), &mut state.borrow_mut(), &sender);
|
||||
}
|
||||
}))
|
||||
))
|
||||
.param(clone!(
|
||||
#[strong]
|
||||
sender,
|
||||
move |_, param_id, _, _, param| {
|
||||
if param_id == ParamType::EnumFormat {
|
||||
handle_port_enum_format(port_id, param, &sender)
|
||||
}
|
||||
}
|
||||
))
|
||||
.register();
|
||||
|
||||
proxies.borrow_mut().insert(
|
||||
|
|
@ -319,22 +396,19 @@ fn handle_port(
|
|||
}
|
||||
|
||||
fn handle_port_info(
|
||||
info: &PortInfo,
|
||||
proxies: &Rc<RefCell<HashMap<u32, ProxyItem>>>,
|
||||
state: &Rc<RefCell<State>>,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
info: &PortInfoRef,
|
||||
proxies: &HashMap<u32, ProxyItem>,
|
||||
state: &mut State,
|
||||
sender: &UnboundedSender<PipewireMessage>,
|
||||
) {
|
||||
debug!("Received port info: {:?}", info);
|
||||
|
||||
let id = info.id();
|
||||
let proxies = proxies.borrow();
|
||||
let Some(ProxyItem::Port { proxy, .. }) = proxies.get(&id) else {
|
||||
log::error!("Received info on unknown port with id {id}");
|
||||
return;
|
||||
};
|
||||
|
||||
let mut state = state.borrow_mut();
|
||||
|
||||
if let Some(Item::Port { .. }) = state.get(id) {
|
||||
// Info was an update, figure out if we should notify the GTK thread
|
||||
if info.change_mask().contains(PortChangeMask::PARAMS) {
|
||||
|
|
@ -356,14 +430,14 @@ fn handle_port_info(
|
|||
let enum_format_info = params
|
||||
.iter()
|
||||
.find(|param| param.id() == ParamType::EnumFormat);
|
||||
if let Some(enum_format_info) = enum_format_info {
|
||||
if enum_format_info.flags().contains(ParamInfoFlags::READ) {
|
||||
proxy.enum_params(0, Some(ParamType::EnumFormat), 0, u32::MAX);
|
||||
}
|
||||
if let Some(enum_format_info) = enum_format_info
|
||||
&& enum_format_info.flags().contains(ParamInfoFlags::READ)
|
||||
{
|
||||
proxy.enum_params(0, Some(ParamType::EnumFormat), 0, u32::MAX);
|
||||
}
|
||||
|
||||
sender
|
||||
.send(PipewireMessage::PortAdded {
|
||||
.unbounded_send(PipewireMessage::PortAdded {
|
||||
id,
|
||||
node_id,
|
||||
name,
|
||||
|
|
@ -376,7 +450,7 @@ fn handle_port_info(
|
|||
fn handle_port_enum_format(
|
||||
port_id: u32,
|
||||
param: Option<&pipewire::spa::pod::Pod>,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
sender: &UnboundedSender<PipewireMessage>,
|
||||
) {
|
||||
let media_type = param
|
||||
.and_then(|param| pipewire::spa::param::format_utils::parse_format(param).ok())
|
||||
|
|
@ -384,19 +458,19 @@ fn handle_port_enum_format(
|
|||
.unwrap_or(MediaType::Unknown);
|
||||
|
||||
sender
|
||||
.send(PipewireMessage::PortFormatChanged {
|
||||
.unbounded_send(PipewireMessage::PortFormatChanged {
|
||||
id: port_id,
|
||||
media_type,
|
||||
})
|
||||
.expect("Failed to send message")
|
||||
.expect("Failed to send message");
|
||||
}
|
||||
|
||||
/// Handle a new link being added
|
||||
fn handle_link(
|
||||
link: &GlobalObject<ForeignDict>,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
registry: &Rc<Registry>,
|
||||
proxies: &Rc<RefCell<HashMap<u32, ProxyItem>>>,
|
||||
link: &GlobalObject<&DictRef>,
|
||||
sender: &UnboundedSender<PipewireMessage>,
|
||||
registry: &RegistryRc,
|
||||
proxies: &mut HashMap<u32, ProxyItem>,
|
||||
state: &Rc<RefCell<State>>,
|
||||
) {
|
||||
debug!(
|
||||
|
|
@ -407,12 +481,18 @@ fn handle_link(
|
|||
let proxy: Link = registry.bind(link).expect("Failed to bind to link proxy");
|
||||
let listener = proxy
|
||||
.add_listener_local()
|
||||
.info(clone!(@strong state, @strong sender => move |info| {
|
||||
handle_link_info(info, &state, &sender);
|
||||
}))
|
||||
.info(clone!(
|
||||
#[strong]
|
||||
state,
|
||||
#[strong]
|
||||
sender,
|
||||
move |info| {
|
||||
handle_link_info(info, &mut state.borrow_mut(), &sender);
|
||||
}
|
||||
))
|
||||
.register();
|
||||
|
||||
proxies.borrow_mut().insert(
|
||||
proxies.insert(
|
||||
link.id,
|
||||
ProxyItem::Link {
|
||||
_proxy: proxy,
|
||||
|
|
@ -422,20 +502,19 @@ fn handle_link(
|
|||
}
|
||||
|
||||
fn handle_link_info(
|
||||
info: &LinkInfo,
|
||||
state: &Rc<RefCell<State>>,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
info: &LinkInfoRef,
|
||||
state: &mut State,
|
||||
sender: &UnboundedSender<PipewireMessage>,
|
||||
) {
|
||||
debug!("Received link info: {:?}", info);
|
||||
|
||||
let id = info.id();
|
||||
|
||||
let mut state = state.borrow_mut();
|
||||
if let Some(Item::Link { .. }) = state.get(id) {
|
||||
// Info was an update - figure out if we should notify the gtk thread
|
||||
if info.change_mask().contains(LinkChangeMask::STATE) {
|
||||
sender
|
||||
.send(PipewireMessage::LinkStateChanged {
|
||||
.unbounded_send(PipewireMessage::LinkStateChanged {
|
||||
id,
|
||||
active: matches!(info.state(), LinkState::Active),
|
||||
})
|
||||
|
|
@ -443,7 +522,7 @@ fn handle_link_info(
|
|||
}
|
||||
if info.change_mask().contains(LinkChangeMask::FORMAT) {
|
||||
sender
|
||||
.send(PipewireMessage::LinkFormatChanged {
|
||||
.unbounded_send(PipewireMessage::LinkFormatChanged {
|
||||
id,
|
||||
media_type: get_link_media_type(info),
|
||||
})
|
||||
|
|
@ -457,7 +536,7 @@ fn handle_link_info(
|
|||
state.insert(id, Item::Link { port_from, port_to });
|
||||
|
||||
sender
|
||||
.send(PipewireMessage::LinkAdded {
|
||||
.unbounded_send(PipewireMessage::LinkAdded {
|
||||
id,
|
||||
port_from,
|
||||
port_to,
|
||||
|
|
@ -469,14 +548,7 @@ fn handle_link_info(
|
|||
}
|
||||
|
||||
/// Toggle a link between the two specified ports.
|
||||
fn toggle_link(
|
||||
port_from: u32,
|
||||
port_to: u32,
|
||||
core: &Rc<Core>,
|
||||
registry: &Rc<Registry>,
|
||||
state: &Rc<RefCell<State>>,
|
||||
) {
|
||||
let state = state.borrow_mut();
|
||||
fn toggle_link(port_from: u32, port_to: u32, core: &CoreRc, registry: &RegistryRc, state: &State) {
|
||||
if let Some(id) = state.get_link_id(port_from, port_to) {
|
||||
info!("Requesting removal of link with id {}", id);
|
||||
|
||||
|
|
@ -495,7 +567,7 @@ fn toggle_link(
|
|||
.get_node_of_port(port_to)
|
||||
.expect("Requested port not in state");
|
||||
|
||||
if let Err(e) = core.create_object::<Link, _>(
|
||||
if let Err(e) = core.create_object::<Link>(
|
||||
"link-factory",
|
||||
&properties! {
|
||||
"link.output.node" => node_from.to_string(),
|
||||
|
|
@ -510,12 +582,10 @@ fn toggle_link(
|
|||
}
|
||||
}
|
||||
|
||||
fn get_link_media_type(link_info: &LinkInfo) -> MediaType {
|
||||
let media_type = link_info
|
||||
fn get_link_media_type(link_info: &LinkInfoRef) -> MediaType {
|
||||
link_info
|
||||
.format()
|
||||
.and_then(|format| pipewire::spa::param::format_utils::parse_format(format).ok())
|
||||
.map(|(media_type, _media_subtype)| media_type)
|
||||
.unwrap_or(MediaType::Unknown);
|
||||
|
||||
media_type
|
||||
.unwrap_or(MediaType::Unknown)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2021 Tom A. Wagner <tom.a.wagner@protonmail.com>
|
||||
// Copyright 2026 Jaŭhien Lavonćjeŭ <jauhien.lavoncjeu@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 3 as published by
|
||||
|
|
@ -14,19 +15,28 @@
|
|||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
cmp::Ordering,
|
||||
collections::{HashMap, HashSet},
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
use pipewire::spa::utils::Direction;
|
||||
|
||||
use adw::{
|
||||
gio,
|
||||
glib::{self, clone},
|
||||
gtk::{
|
||||
self, cairo,
|
||||
graphene::{self, Point},
|
||||
gsk,
|
||||
},
|
||||
prelude::*,
|
||||
subclass::prelude::*,
|
||||
};
|
||||
use gtk::{
|
||||
self, cairo, gdk,
|
||||
graphene::{self, Point, Rect},
|
||||
gsk,
|
||||
};
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use log::warn;
|
||||
|
||||
use super::{Link, Node, Port};
|
||||
use crate::NodeType;
|
||||
|
|
@ -36,33 +46,6 @@ const CANVAS_SIZE: f64 = 5000.0;
|
|||
mod imp {
|
||||
use super::*;
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use adw::gtk::gdk::{self};
|
||||
use log::warn;
|
||||
use once_cell::sync::Lazy;
|
||||
use pipewire::spa::format::MediaType;
|
||||
use pipewire::spa::Direction;
|
||||
|
||||
pub struct Colors {
|
||||
audio: gdk::RGBA,
|
||||
video: gdk::RGBA,
|
||||
midi: gdk::RGBA,
|
||||
unknown: gdk::RGBA,
|
||||
}
|
||||
|
||||
impl Colors {
|
||||
pub fn color_for_media_type(&self, media_type: MediaType) -> &gdk::RGBA {
|
||||
match media_type {
|
||||
MediaType::Audio => &self.audio,
|
||||
MediaType::Video => &self.video,
|
||||
MediaType::Stream | MediaType::Application => &self.midi,
|
||||
_ => &self.unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DragState {
|
||||
node: glib::WeakRef<Node>,
|
||||
/// This stores the offset of the pointer to the origin of the node,
|
||||
|
|
@ -151,7 +134,7 @@ mod imp {
|
|||
}
|
||||
|
||||
fn properties() -> &'static [glib::ParamSpec] {
|
||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
||||
static PROPERTIES: LazyLock<Vec<glib::ParamSpec>> = LazyLock::new(|| {
|
||||
vec![
|
||||
glib::ParamSpecOverride::for_interface::<gtk::Scrollable>("hadjustment"),
|
||||
glib::ParamSpecOverride::for_interface::<gtk::Scrollable>("vadjustment"),
|
||||
|
|
@ -228,14 +211,19 @@ mod imp {
|
|||
|
||||
fn snapshot(&self, snapshot: >k::Snapshot) {
|
||||
let widget = &*self.obj();
|
||||
let alloc = widget.allocation();
|
||||
|
||||
let widget_rect = Rect::new(0.0, 0.0, widget.width() as f32, widget.height() as f32);
|
||||
|
||||
// Draw all visible children
|
||||
self.nodes
|
||||
.borrow()
|
||||
.iter()
|
||||
// Cull nodes from rendering when they are outside the visible canvas area
|
||||
.filter(|(node, _)| alloc.intersect(&node.allocation()).is_some())
|
||||
.filter(|(node, _)| {
|
||||
widget_rect
|
||||
.intersection(&node.compute_bounds(widget).unwrap())
|
||||
.is_some()
|
||||
})
|
||||
.for_each(|(node, _)| widget.snapshot_child(node, snapshot));
|
||||
|
||||
self.snapshot_links(widget, snapshot);
|
||||
|
|
@ -276,6 +264,7 @@ mod imp {
|
|||
drag_controller.connect_drag_begin(|drag_controller, x, y| {
|
||||
let widget = drag_controller
|
||||
.widget()
|
||||
.unwrap()
|
||||
.dynamic_cast::<super::GraphView>()
|
||||
.expect("drag-begin event is not on the GraphView");
|
||||
let mut dragged_node = widget.imp().dragged_node.borrow_mut();
|
||||
|
|
@ -315,6 +304,7 @@ mod imp {
|
|||
drag_controller.connect_drag_update(|drag_controller, x, y| {
|
||||
let widget = drag_controller
|
||||
.widget()
|
||||
.unwrap()
|
||||
.dynamic_cast::<super::GraphView>()
|
||||
.expect("drag-update event is not on the GraphView");
|
||||
let dragged_node = widget.imp().dragged_node.borrow();
|
||||
|
|
@ -348,6 +338,7 @@ mod imp {
|
|||
controller.connect_enter(|controller, x, y| {
|
||||
let graph = controller
|
||||
.widget()
|
||||
.unwrap()
|
||||
.downcast::<super::GraphView>()
|
||||
.expect("Widget should be a graphview");
|
||||
|
||||
|
|
@ -357,6 +348,7 @@ mod imp {
|
|||
controller.connect_motion(|controller, x, y| {
|
||||
let graph = controller
|
||||
.widget()
|
||||
.unwrap()
|
||||
.downcast::<super::GraphView>()
|
||||
.expect("Widget should be a graphview");
|
||||
|
||||
|
|
@ -366,6 +358,7 @@ mod imp {
|
|||
controller.connect_leave(|controller| {
|
||||
let graph = controller
|
||||
.widget()
|
||||
.unwrap()
|
||||
.downcast::<super::GraphView>()
|
||||
.expect("Widget should be a graphview");
|
||||
|
||||
|
|
@ -386,14 +379,18 @@ mod imp {
|
|||
Port::static_type(),
|
||||
glib::Priority::DEFAULT,
|
||||
Option::<&gio::Cancellable>::None,
|
||||
clone!(@weak self as imp => move|value| {
|
||||
let Ok(value) = value else {
|
||||
return;
|
||||
};
|
||||
let port: &Port = value.get().expect("Value should contain a port");
|
||||
clone!(
|
||||
#[weak(rename_to = imp)]
|
||||
self,
|
||||
move |value| {
|
||||
let Ok(value) = value else {
|
||||
return;
|
||||
};
|
||||
let port: &Port = value.get().expect("Value should contain a port");
|
||||
|
||||
imp.dragged_port.set(Some(port));
|
||||
}),
|
||||
imp.dragged_port.set(Some(port));
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
self.obj().queue_draw();
|
||||
|
|
@ -430,6 +427,7 @@ mod imp {
|
|||
{
|
||||
let widget = eventcontroller
|
||||
.widget()
|
||||
.unwrap()
|
||||
.downcast::<super::GraphView>()
|
||||
.unwrap();
|
||||
widget.set_zoom_factor(widget.zoom_factor() + (0.1 * -delta_y), None);
|
||||
|
|
@ -445,7 +443,11 @@ mod imp {
|
|||
fn setup_zoom_gesture(&self) {
|
||||
let zoom_gesture = gtk::GestureZoom::new();
|
||||
zoom_gesture.connect_begin(|gesture, _| {
|
||||
let widget = gesture.widget().downcast::<super::GraphView>().unwrap();
|
||||
let widget = gesture
|
||||
.widget()
|
||||
.unwrap()
|
||||
.downcast::<super::GraphView>()
|
||||
.unwrap();
|
||||
|
||||
widget
|
||||
.imp()
|
||||
|
|
@ -457,7 +459,11 @@ mod imp {
|
|||
.set(gesture.bounding_box_center());
|
||||
});
|
||||
zoom_gesture.connect_scale_changed(move |gesture, delta| {
|
||||
let widget = gesture.widget().downcast::<super::GraphView>().unwrap();
|
||||
let widget = gesture
|
||||
.widget()
|
||||
.unwrap()
|
||||
.downcast::<super::GraphView>()
|
||||
.unwrap();
|
||||
|
||||
let initial_zoom = widget
|
||||
.imp()
|
||||
|
|
@ -480,6 +486,7 @@ mod imp {
|
|||
drag_controller.connect_drag_begin(|drag_controller, _, _| {
|
||||
let widget = drag_controller
|
||||
.widget()
|
||||
.unwrap()
|
||||
.downcast::<super::GraphView>()
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -489,6 +496,7 @@ mod imp {
|
|||
drag_controller.connect_drag_update(|drag_controller, x, y| {
|
||||
let widget = drag_controller
|
||||
.widget()
|
||||
.unwrap()
|
||||
.downcast::<super::GraphView>()
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -518,7 +526,7 @@ mod imp {
|
|||
output_anchor: &Point,
|
||||
input_anchor: &Point,
|
||||
active: bool,
|
||||
color: &gdk::RGBA,
|
||||
color: gdk::RGBA,
|
||||
) {
|
||||
let output_x: f64 = output_anchor.x().into();
|
||||
let output_y: f64 = output_anchor.y().into();
|
||||
|
|
@ -567,7 +575,7 @@ mod imp {
|
|||
};
|
||||
}
|
||||
|
||||
fn draw_dragged_link(&self, port: &Port, link_cr: &cairo::Context, colors: &Colors) {
|
||||
fn draw_dragged_link(&self, port: &Port, link_cr: &cairo::Context) {
|
||||
let Some(port_anchor) = port.compute_point(&*self.obj(), &port.link_anchor()) else {
|
||||
return;
|
||||
};
|
||||
|
|
@ -595,51 +603,34 @@ mod imp {
|
|||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let color = &colors.color_for_media_type(MediaType::from_raw(port.media_type()));
|
||||
|
||||
self.draw_link(link_cr, output_anchor, input_anchor, false, color);
|
||||
self.draw_link(
|
||||
link_cr,
|
||||
output_anchor,
|
||||
input_anchor,
|
||||
false,
|
||||
port.get_handle().color(),
|
||||
);
|
||||
}
|
||||
|
||||
fn snapshot_links(&self, widget: &super::GraphView, snapshot: >k::Snapshot) {
|
||||
let alloc = widget.allocation();
|
||||
|
||||
let link_cr = snapshot.append_cairo(&graphene::Rect::new(
|
||||
0.0,
|
||||
0.0,
|
||||
alloc.width() as f32,
|
||||
alloc.height() as f32,
|
||||
widget.width() as f32,
|
||||
widget.height() as f32,
|
||||
));
|
||||
|
||||
link_cr.set_line_width(2.0 * self.zoom_factor.get());
|
||||
|
||||
let colors = Colors {
|
||||
audio: widget
|
||||
.style_context()
|
||||
.lookup_color("media-type-audio")
|
||||
.expect("color not found"),
|
||||
video: widget
|
||||
.style_context()
|
||||
.lookup_color("media-type-video")
|
||||
.expect("color not found"),
|
||||
midi: widget
|
||||
.style_context()
|
||||
.lookup_color("media-type-midi")
|
||||
.expect("color not found"),
|
||||
unknown: widget
|
||||
.style_context()
|
||||
.lookup_color("media-type-unknown")
|
||||
.expect("color not found"),
|
||||
};
|
||||
|
||||
for link in self.links.borrow().iter() {
|
||||
let color = &colors.color_for_media_type(link.media_type());
|
||||
|
||||
// TODO: Do not draw links when they are outside the view
|
||||
let Some((output_anchor, input_anchor)) = self.get_link_coordinates(link) else {
|
||||
warn!("Could not get allocation of ports of link: {:?}", link);
|
||||
continue;
|
||||
};
|
||||
|
||||
let color = link.output_port().unwrap().get_handle().color();
|
||||
|
||||
self.draw_link(
|
||||
&link_cr,
|
||||
&output_anchor,
|
||||
|
|
@ -650,7 +641,7 @@ mod imp {
|
|||
}
|
||||
|
||||
if let Some(port) = self.dragged_port.upgrade() {
|
||||
self.draw_dragged_link(&port, &link_cr, &colors);
|
||||
self.draw_dragged_link(&port, &link_cr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -688,8 +679,11 @@ mod imp {
|
|||
}
|
||||
|
||||
if let Some(adjustment) = adjustment {
|
||||
adjustment
|
||||
.connect_value_changed(clone!(@weak obj => move |_| obj.queue_allocate() ));
|
||||
adjustment.connect_value_changed(clone!(
|
||||
#[weak]
|
||||
obj,
|
||||
move |_| obj.queue_allocate()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -720,7 +714,8 @@ mod imp {
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct GraphView(ObjectSubclass<imp::GraphView>)
|
||||
@extends gtk::Widget;
|
||||
@extends gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::ConstraintTarget, gtk::Buildable, gtk::Scrollable;
|
||||
}
|
||||
|
||||
impl GraphView {
|
||||
|
|
@ -748,12 +743,8 @@ impl GraphView {
|
|||
pub fn set_zoom_factor(&self, zoom_factor: f64, anchor: Option<(f64, f64)>) {
|
||||
let zoom_factor = zoom_factor.clamp(Self::ZOOM_MIN, Self::ZOOM_MAX);
|
||||
|
||||
let (anchor_x_screen, anchor_y_screen) = anchor.unwrap_or_else(|| {
|
||||
(
|
||||
self.allocation().width() as f64 / 2.0,
|
||||
self.allocation().height() as f64 / 2.0,
|
||||
)
|
||||
});
|
||||
let (anchor_x_screen, anchor_y_screen) =
|
||||
anchor.unwrap_or_else(|| (self.width() as f64 / 2.0, self.height() as f64 / 2.0));
|
||||
|
||||
let old_zoom = self.imp().zoom_factor.get();
|
||||
let hadjustment_ref = self.imp().hadjustment.borrow();
|
||||
|
|
@ -822,15 +813,23 @@ impl GraphView {
|
|||
pub fn add_link(&self, link: Link) {
|
||||
link.connect_notify_local(
|
||||
Some("active"),
|
||||
glib::clone!(@weak self as graph => move |_, _| {
|
||||
graph.queue_draw();
|
||||
}),
|
||||
glib::clone!(
|
||||
#[weak(rename_to = graph)]
|
||||
self,
|
||||
move |_, _| {
|
||||
graph.queue_draw();
|
||||
}
|
||||
),
|
||||
);
|
||||
link.connect_notify_local(
|
||||
Some("media-type"),
|
||||
glib::clone!(@weak self as graph => move |_, _| {
|
||||
graph.queue_draw();
|
||||
}),
|
||||
glib::clone!(
|
||||
#[weak(rename_to = graph)]
|
||||
self,
|
||||
move |_, _| {
|
||||
graph.queue_draw();
|
||||
}
|
||||
),
|
||||
);
|
||||
self.imp().links.borrow_mut().insert(link);
|
||||
self.queue_draw();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2021 Tom A. Wagner <tom.a.wagner@protonmail.com>
|
||||
// Copyright 2026 Jaŭhien Lavonćjeŭ <jauhien.lavoncjeu@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 3 as published by
|
||||
|
|
@ -14,18 +15,16 @@
|
|||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use pipewire::spa::param::format::MediaType;
|
||||
use std::{cell::Cell, sync::LazyLock};
|
||||
|
||||
use adw::{glib, prelude::*, subclass::prelude::*};
|
||||
use pipewire::spa::format::MediaType;
|
||||
|
||||
use super::Port;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
pub struct Link {
|
||||
pub output_port: glib::WeakRef<Port>,
|
||||
pub input_port: glib::WeakRef<Port>,
|
||||
|
|
@ -53,7 +52,7 @@ mod imp {
|
|||
|
||||
impl ObjectImpl for Link {
|
||||
fn properties() -> &'static [glib::ParamSpec] {
|
||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
||||
static PROPERTIES: LazyLock<Vec<glib::ParamSpec>> = LazyLock::new(|| {
|
||||
vec![
|
||||
glib::ParamSpecObject::builder::<Port>("output-port")
|
||||
.flags(glib::ParamFlags::READWRITE)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2021 Tom A. Wagner <tom.a.wagner@protonmail.com>
|
||||
// Copyright 2026 Jaŭhien Lavonćjeŭ <jauhien.lavoncjeu@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 3 as published by
|
||||
|
|
@ -14,22 +15,22 @@
|
|||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use pipewire::spa::utils::Direction;
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
collections::HashSet,
|
||||
};
|
||||
|
||||
use adw::{glib, gtk, prelude::*, subclass::prelude::*};
|
||||
use pipewire::spa::Direction;
|
||||
|
||||
use super::Port;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
collections::HashSet,
|
||||
};
|
||||
|
||||
#[derive(glib::Properties, gtk::CompositeTemplate, Default)]
|
||||
#[properties(wrapper_type = super::Node)]
|
||||
#[template(file = "node.ui")]
|
||||
#[template(resource = "/org/pipewire/Helvum/ui/node.ui")]
|
||||
pub struct Node {
|
||||
#[property(get, set, construct_only)]
|
||||
pub(super) pipewire_id: Cell<u32>,
|
||||
|
|
@ -149,7 +150,8 @@ mod imp {
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct Node(ObjectSubclass<imp::Node>)
|
||||
@extends gtk::Widget;
|
||||
@extends gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::ConstraintTarget, gtk::Buildable;
|
||||
}
|
||||
|
||||
impl Node {
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<template class="HelvumNode" parent="GtkWidget">
|
||||
<style>
|
||||
<class name="card"></class>
|
||||
</style>>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<style>
|
||||
<class name="node-title"></class>
|
||||
</style>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">1</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="node_name">
|
||||
<style>
|
||||
<class name="heading"></class>
|
||||
</style>
|
||||
<property name="wrap">true</property>
|
||||
<property name="ellipsize">PANGO_ELLIPSIZE_END</property>
|
||||
<property name="lines">2</property>
|
||||
<property name="max-width-chars">20</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="media_name">
|
||||
<style>
|
||||
<class name="dim-label"></class>
|
||||
<class name="caption"></class>
|
||||
</style>
|
||||
<property name="visible">false</property>
|
||||
<property name="wrap">true</property>
|
||||
<property name="ellipsize">PANGO_ELLIPSIZE_END</property>
|
||||
<property name="lines">2</property>
|
||||
<property name="max-width-chars">20</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparator" id="separator">
|
||||
<!-- The node will show the seperator only once ports are added to it -->
|
||||
<property name="visible">false</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkGrid" id="port_grid"></object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2021 Tom A. Wagner <tom.a.wagner@protonmail.com>
|
||||
// Copyright 2026 Jaŭhien Lavonćjeŭ <jauhien.lavoncjeu@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 3 as published by
|
||||
|
|
@ -14,6 +15,12 @@
|
|||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use pipewire::spa::{param::format::MediaType, utils::Direction};
|
||||
use std::{
|
||||
cell::{Cell, OnceCell},
|
||||
sync::LazyLock,
|
||||
};
|
||||
|
||||
use adw::{
|
||||
gdk,
|
||||
glib::{self, subclass::Signal},
|
||||
|
|
@ -21,22 +28,16 @@ use adw::{
|
|||
prelude::*,
|
||||
subclass::prelude::*,
|
||||
};
|
||||
use pipewire::spa::Direction;
|
||||
|
||||
use super::PortHandle;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
use once_cell::{sync::Lazy, unsync::OnceCell};
|
||||
use pipewire::spa::{format::MediaType, Direction};
|
||||
|
||||
/// Graphical representation of a pipewire port.
|
||||
#[derive(gtk::CompositeTemplate, glib::Properties)]
|
||||
#[properties(wrapper_type = super::Port)]
|
||||
#[template(file = "port.ui")]
|
||||
#[template(resource = "/org/pipewire/Helvum/ui/port.ui")]
|
||||
pub struct Port {
|
||||
#[property(get, set, construct_only)]
|
||||
pub(super) pipewire_id: OnceCell<u32>,
|
||||
|
|
@ -112,11 +113,13 @@ mod imp {
|
|||
}
|
||||
|
||||
fn signals() -> &'static [Signal] {
|
||||
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
|
||||
vec![Signal::builder("port-toggled")
|
||||
// Provide id of output port and input port to signal handler.
|
||||
.param_types([<u32>::static_type(), <u32>::static_type()])
|
||||
.build()]
|
||||
static SIGNALS: LazyLock<Vec<Signal>> = LazyLock::new(|| {
|
||||
vec![
|
||||
Signal::builder("port-toggled")
|
||||
// Provide id of output port and input port to signal handler.
|
||||
.param_types([<u32>::static_type(), <u32>::static_type()])
|
||||
.build(),
|
||||
]
|
||||
});
|
||||
|
||||
SIGNALS.as_ref()
|
||||
|
|
@ -218,6 +221,7 @@ mod imp {
|
|||
drag_src.connect_drag_begin(|drag_source, _| {
|
||||
let port = drag_source
|
||||
.widget()
|
||||
.unwrap()
|
||||
.dynamic_cast::<super::Port>()
|
||||
.expect("Widget should be a Port");
|
||||
|
||||
|
|
@ -226,6 +230,7 @@ mod imp {
|
|||
drag_src.connect_drag_cancel(|drag_source, _, _| {
|
||||
let port = drag_source
|
||||
.widget()
|
||||
.unwrap()
|
||||
.dynamic_cast::<super::Port>()
|
||||
.expect("Widget should be a Port");
|
||||
|
||||
|
|
@ -241,6 +246,7 @@ mod imp {
|
|||
drop_target.connect_value_notify(|drop_target| {
|
||||
let port = drop_target
|
||||
.widget()
|
||||
.unwrap()
|
||||
.dynamic_cast::<super::Port>()
|
||||
.expect("Widget should be a Port");
|
||||
|
||||
|
|
@ -260,6 +266,7 @@ mod imp {
|
|||
drop_target.connect_drop(|drop_target, val, _, _| {
|
||||
let port = drop_target
|
||||
.widget()
|
||||
.unwrap()
|
||||
.dynamic_cast::<super::Port>()
|
||||
.expect("Widget should be a Port");
|
||||
let other_port = val
|
||||
|
|
@ -328,7 +335,8 @@ mod imp {
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct Port(ObjectSubclass<imp::Port>)
|
||||
@extends gtk::Widget;
|
||||
@extends gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::ConstraintTarget, gtk::Buildable;
|
||||
}
|
||||
|
||||
impl Port {
|
||||
|
|
@ -341,17 +349,11 @@ impl Port {
|
|||
}
|
||||
|
||||
pub fn link_anchor(&self) -> graphene::Point {
|
||||
let style_context = self.style_context();
|
||||
let padding_right: f32 = style_context.padding().right().into();
|
||||
let border_right: f32 = style_context.border().right().into();
|
||||
let padding_left: f32 = style_context.padding().left().into();
|
||||
let border_left: f32 = style_context.border().left().into();
|
||||
|
||||
let direction = Direction::from_raw(self.direction());
|
||||
graphene::Point::new(
|
||||
match direction {
|
||||
Direction::Output => self.width() as f32 + padding_right + border_right,
|
||||
Direction::Input => 0.0 - padding_left - border_left,
|
||||
Direction::Output => self.width() as f32,
|
||||
Direction::Input => 0.0,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
self.height() as f32 / 2.0,
|
||||
|
|
@ -361,4 +363,8 @@ impl Port {
|
|||
pub fn is_linkable_to(&self, other_port: &Self) -> bool {
|
||||
self.direction() != other_port.direction()
|
||||
}
|
||||
|
||||
pub fn get_handle(&self) -> &PortHandle {
|
||||
&self.imp().handle
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<template class="HelvumPort" parent="GtkWidget">
|
||||
<property name="hexpand">true</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label">
|
||||
<property name="wrap">true</property>
|
||||
<property name="ellipsize">PANGO_ELLIPSIZE_END</property>
|
||||
<property name="lines">2</property>
|
||||
<property name="max-width-chars">20</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="HelvumPortHandle" id="handle"></object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
||||
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2021 Tom A. Wagner <tom.a.wagner@protonmail.com>
|
||||
// Copyright 2026 Jaŭhien Lavonćjeŭ <jauhien.lavoncjeu@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 3 as published by
|
||||
|
|
@ -61,7 +62,8 @@ mod imp {
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct PortHandle(ObjectSubclass<imp::PortHandle>)
|
||||
@extends gtk::Widget;
|
||||
@extends gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::ConstraintTarget, gtk::Buildable;
|
||||
}
|
||||
|
||||
impl PortHandle {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,20 @@
|
|||
use adw::{glib, gtk, prelude::*, subclass::prelude::*};
|
||||
use std::{cell::RefCell, sync::LazyLock};
|
||||
|
||||
use adw::{
|
||||
gio,
|
||||
glib::{self, clone},
|
||||
gtk,
|
||||
prelude::*,
|
||||
subclass::prelude::*,
|
||||
};
|
||||
|
||||
use super::GraphView;
|
||||
|
||||
mod imp {
|
||||
use std::cell::RefCell;
|
||||
|
||||
use super::*;
|
||||
|
||||
use gtk::{gio, glib::clone};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
#[derive(gtk::CompositeTemplate)]
|
||||
#[template(file = "zoomentry.ui")]
|
||||
#[template(resource = "/org/pipewire/Helvum/ui/zoomentry.ui")]
|
||||
pub struct ZoomEntry {
|
||||
pub graphview: RefCell<Option<GraphView>>,
|
||||
#[template_child]
|
||||
|
|
@ -65,37 +68,49 @@ mod imp {
|
|||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
|
||||
self.zoom_out_button
|
||||
.connect_clicked(clone!(@weak self as imp => move |_| {
|
||||
self.zoom_out_button.connect_clicked(clone!(
|
||||
#[weak(rename_to = imp)]
|
||||
self,
|
||||
move |_| {
|
||||
let graphview = imp.graphview.borrow();
|
||||
if let Some(ref graphview) = *graphview {
|
||||
graphview.set_zoom_factor(graphview.zoom_factor() - 0.1, None);
|
||||
}
|
||||
}));
|
||||
}
|
||||
));
|
||||
|
||||
self.zoom_in_button
|
||||
.connect_clicked(clone!(@weak self as imp => move |_| {
|
||||
self.zoom_in_button.connect_clicked(clone!(
|
||||
#[weak(rename_to = imp)]
|
||||
self,
|
||||
move |_| {
|
||||
let graphview = imp.graphview.borrow();
|
||||
if let Some(ref graphview) = *graphview {
|
||||
graphview.set_zoom_factor(graphview.zoom_factor() + 0.1, None);
|
||||
}
|
||||
}));
|
||||
}
|
||||
));
|
||||
|
||||
self.entry
|
||||
.connect_activate(clone!(@weak self as imp => move |entry| {
|
||||
self.entry.connect_activate(clone!(
|
||||
#[weak(rename_to = imp)]
|
||||
self,
|
||||
move |entry| {
|
||||
if let Ok(zoom_factor) = entry.text().trim_matches('%').parse::<f64>() {
|
||||
let graphview = imp.graphview.borrow();
|
||||
if let Some(ref graphview) = *graphview {
|
||||
graphview.set_zoom_factor(zoom_factor / 100.0, None);
|
||||
}
|
||||
}
|
||||
}));
|
||||
self.entry
|
||||
.connect_icon_press(clone!(@weak self as imp => move |_, pos| {
|
||||
}
|
||||
));
|
||||
self.entry.connect_icon_press(clone!(
|
||||
#[weak(rename_to = imp)]
|
||||
self,
|
||||
move |_, pos| {
|
||||
if pos == gtk::EntryIconPosition::Secondary {
|
||||
imp.popover.show();
|
||||
imp.popover.popup();
|
||||
}
|
||||
}));
|
||||
}
|
||||
));
|
||||
|
||||
self.popover.set_parent(&self.entry.get());
|
||||
}
|
||||
|
|
@ -109,10 +124,12 @@ mod imp {
|
|||
}
|
||||
|
||||
fn properties() -> &'static [glib::ParamSpec] {
|
||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
||||
vec![glib::ParamSpecObject::builder::<GraphView>("zoomed-widget")
|
||||
.flags(glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT)
|
||||
.build()]
|
||||
static PROPERTIES: LazyLock<Vec<glib::ParamSpec>> = LazyLock::new(|| {
|
||||
vec![
|
||||
glib::ParamSpecObject::builder::<GraphView>("zoomed-widget")
|
||||
.flags(glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT)
|
||||
.build(),
|
||||
]
|
||||
});
|
||||
|
||||
PROPERTIES.as_ref()
|
||||
|
|
@ -132,9 +149,13 @@ mod imp {
|
|||
if let Some(ref widget) = widget {
|
||||
widget.connect_notify_local(
|
||||
Some("zoom-factor"),
|
||||
clone!(@weak self as imp => move |graphview, _| {
|
||||
imp.update_zoom_factor_text(graphview.zoom_factor());
|
||||
}),
|
||||
clone!(
|
||||
#[weak(rename_to = imp)]
|
||||
self,
|
||||
move |graphview, _| {
|
||||
imp.update_zoom_factor_text(graphview.zoom_factor());
|
||||
}
|
||||
),
|
||||
);
|
||||
self.update_zoom_factor_text(widget.zoom_factor());
|
||||
}
|
||||
|
|
@ -161,7 +182,8 @@ mod imp {
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct ZoomEntry(ObjectSubclass<imp::ZoomEntry>)
|
||||
@extends gtk::Box, gtk::Widget;
|
||||
@extends gtk::Box, gtk::Widget,
|
||||
@implements gtk::Accessible, gtk::ConstraintTarget, gtk::Buildable;
|
||||
}
|
||||
|
||||
impl ZoomEntry {
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="HelvumZoomEntry" parent="GtkBox">
|
||||
<property name="spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="entry">
|
||||
<property name="secondary-icon-name">go-down-symbolic</property>
|
||||
<property name="input-purpose">digits</property>
|
||||
<property name="max-width-chars">5</property>
|
||||
<style>
|
||||
<class name="osd"/>
|
||||
<class name="rounded"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="zoom_out_button">
|
||||
<property name="icon-name">zoom-out-symbolic</property>
|
||||
<property name="tooltip-text">Zoom out</property>
|
||||
<style>
|
||||
<class name="osd"/>
|
||||
<class name="rounded"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="zoom_in_button">
|
||||
<property name="icon-name">zoom-in-symbolic</property>
|
||||
<property name="tooltip-text">Zoom in</property>
|
||||
<style>
|
||||
<class name="osd"/>
|
||||
<class name="rounded"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
||||
|
|
@ -7,7 +7,7 @@ mod imp {
|
|||
|
||||
#[derive(Default, gtk::CompositeTemplate, glib::Properties)]
|
||||
#[properties(wrapper_type = super::Window)]
|
||||
#[template(file = "window.ui")]
|
||||
#[template(resource = "/org/pipewire/Helvum/ui/window.ui")]
|
||||
pub struct Window {
|
||||
#[template_child]
|
||||
pub header_bar: TemplateChild<adw::HeaderBar>,
|
||||
|
|
@ -49,7 +49,8 @@ mod imp {
|
|||
glib::wrapper! {
|
||||
pub struct Window(ObjectSubclass<imp::Window>)
|
||||
@extends adw::ApplicationWindow, gtk::ApplicationWindow, gtk::Window, gtk::Widget,
|
||||
@implements gio::ActionGroup, gio::ActionMap;
|
||||
@implements gio::ActionGroup, gio::ActionMap, gtk::Accessible, gtk::Buildable,
|
||||
gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<requires lib="Adw" version="1.4"/>
|
||||
<menu id="primary_menu">
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="label">_About Helvum</attribute>
|
||||
<attribute name="action">app.about</attribute>
|
||||
</item>
|
||||
</section>
|
||||
</menu>
|
||||
<template class="HelvumWindow" parent="AdwApplicationWindow">
|
||||
<property name="default-width">1280</property>
|
||||
<property name="default-height">720</property>
|
||||
<property name="title">Helvum - Pipewire Patchbay</property>
|
||||
<child>
|
||||
<object class="AdwToolbarView">
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar" id="header_bar">
|
||||
<child type="end">
|
||||
<object class="GtkMenuButton">
|
||||
<property name="icon-name">open-menu-symbolic</property>
|
||||
<property name="menu-model">primary_menu</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<property name="content">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="AdwBanner" id="connection_banner">
|
||||
<property name="title" translatable="yes">Disconnected</property>
|
||||
<property name="revealed">false</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkOverlay">
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<child>
|
||||
<object class="HelvumGraphView" id="graph">
|
||||
<property name="hexpand">true</property>
|
||||
<property name="vexpand">true</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="overlay">
|
||||
<object class="HelvumZoomEntry">
|
||||
<property name="zoomed-widget">graph</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">end</property>
|
||||
<property name="margin-end">24</property>
|
||||
<property name="margin-bottom">24</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
||||
Loading…
Add table
Reference in a new issue