mirror of
https://gitlab.freedesktop.org/pipewire/helvum.git
synced 2026-05-09 02:48:01 +02:00
Deps update
This commit is contained in:
parent
eb3b3cf298
commit
ee2c5b29ba
19 changed files with 830 additions and 657 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -3,3 +3,4 @@
|
|||
/.vscode
|
||||
/_build
|
||||
/target
|
||||
/*.Dockerfile
|
||||
|
|
|
|||
|
|
@ -1,18 +1,30 @@
|
|||
stages:
|
||||
- build
|
||||
- test
|
||||
- lint
|
||||
- deploy
|
||||
|
||||
workflow:
|
||||
rules:
|
||||
- if: $CI_MERGE_REQUEST_IID
|
||||
- if: $CI_COMMIT_TAG
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||
|
||||
.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
|
||||
APP_FLATPAK_MODULE: Helvum
|
||||
before_script:
|
||||
- flatpak --version
|
||||
- flatpak remote-add --if-not-exists --user flathub https://flathub.org/repo/flathub.flatpakrepo
|
||||
- flatpak install -y --user flathub org.gnome.Platform//50 org.gnome.Sdk//50
|
||||
- flatpak install -y --user flathub org.freedesktop.Sdk.Extension.llvm22//25.08
|
||||
- flatpak install -y --user flathub org.freedesktop.Sdk.Extension.rust-stable//25.08
|
||||
- flatpak info org.gnome.Platform
|
||||
- flatpak info org.gnome.Sdk
|
||||
- flatpak info org.freedesktop.Sdk.Extension.llvm16
|
||||
- flatpak info org.freedesktop.Sdk.Extension.llvm22
|
||||
- flatpak info org.freedesktop.Sdk.Extension.rust-stable
|
||||
- flatpak-builder --version
|
||||
|
||||
|
|
@ -21,33 +33,56 @@ build:
|
|||
extends: .flatpak
|
||||
script:
|
||||
- flatpak-builder --keep-build-dirs --user --disable-rofiles-fuse ${FLATPAK_BUILD_DIR} ${MANIFEST_PATH}
|
||||
artifacts:
|
||||
when: always
|
||||
paths:
|
||||
- ${FLATPAK_BUILD_DIR}
|
||||
- .flatpak-builder/build/${APP_FLATPAK_MODULE}-1/_flatpak_build
|
||||
expire_in: 1 day
|
||||
|
||||
# TODO: Run meson test
|
||||
meson-test:
|
||||
stage: test
|
||||
extends: .flatpak
|
||||
script:
|
||||
- >-
|
||||
flatpak-builder --run ${FLATPAK_BUILD_DIR} ${MANIFEST_PATH}
|
||||
bash -c "meson test -C ${CI_PROJECT_DIR}/.flatpak-builder/build/${APP_FLATPAK_MODULE}-1/_flatpak_build --no-rebuild --print-errorlogs"
|
||||
needs: ["build"]
|
||||
|
||||
clippy:
|
||||
stage: lint
|
||||
extends: .flatpak
|
||||
script:
|
||||
- flatpak-builder --keep-build-dirs --user --disable-rofiles-fuse --stop-at=${APP_FLATPAK_MODULE} ${FLATPAK_BUILD_DIR} ${MANIFEST_PATH}
|
||||
- >-
|
||||
flatpak-builder --run ${FLATPAK_BUILD_DIR} ${MANIFEST_PATH}
|
||||
cargo clippy --color=always --all-targets -- -D warnings
|
||||
needs: ["build"]
|
||||
|
||||
rustfmt:
|
||||
stage: lint
|
||||
image: "rust:slim" # TODO: Check image
|
||||
image: "rust:1.94-slim"
|
||||
script:
|
||||
- rustup component add rustfmt
|
||||
- rustc -Vv && cargo -Vv
|
||||
- cargo fmt --version
|
||||
- cargo fmt --all -- --color=always --check
|
||||
|
||||
rustdoc:
|
||||
stage: lint
|
||||
extends: .flatpak
|
||||
script:
|
||||
- flatpak-builder --keep-build-dirs --user --disable-rofiles-fuse --stop-at=${APP_FLATPAK_MODULE} ${FLATPAK_BUILD_DIR} ${MANIFEST_PATH}
|
||||
- >-
|
||||
flatpak-builder --run ${FLATPAK_BUILD_DIR} ${MANIFEST_PATH}
|
||||
env RUSTDOCFLAGS=-Dwarnings cargo doc --no-deps
|
||||
needs: ["build"]
|
||||
|
||||
release:
|
||||
stage: deploy
|
||||
extends: .flatpak
|
||||
script:
|
||||
- flatpak-builder --repo=repo --force-clean ${FLATPAK_BUILD_DIR} ${MANIFEST_PATH}
|
||||
- flatpak build-bundle repo helvum.flatpak org.pipewire.Helvum
|
||||
artifacts:
|
||||
paths:
|
||||
- helvum.flatpak
|
||||
expire_in: never
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
|
|
|
|||
682
Cargo.lock
generated
682
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
20
Cargo.toml
20
Cargo.toml
|
|
@ -1,9 +1,9 @@
|
|||
[package]
|
||||
name = "helvum"
|
||||
version = "0.5.1"
|
||||
authors = ["Tom Wagner <tom.a.wagner@protonmail.com>"]
|
||||
authors = ["Tom Wagner <tom.a.wagner@protonmail.com>", "Naveen Prashanth <gnpaone@gmail.com>"]
|
||||
edition = "2021"
|
||||
rust-version = "1.70"
|
||||
rust-version = "1.94"
|
||||
license = "GPL-3.0-only"
|
||||
description = "A GTK patchbay for pipewire"
|
||||
repository = "https://gitlab.freedesktop.org/pipewire/helvum"
|
||||
|
|
@ -14,12 +14,14 @@ 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"] }
|
||||
pipewire = "0.9.2"
|
||||
libspa = "0.9.2"
|
||||
async-channel = "2.5.0"
|
||||
adw = { version = "0.9.1", package = "libadwaita", features = ["v1_9", "gtk_v4_22"] }
|
||||
glib = { version = "0.22.7", features = ["log", "v2_88"] }
|
||||
gtk4 = "0.11.3"
|
||||
|
||||
log = "0.4.11"
|
||||
log = "0.4.29"
|
||||
|
||||
once_cell = "1.7.2"
|
||||
|
||||
libc = "0.2"
|
||||
libc = "0.2.186"
|
||||
futures-util = "0.3.32"
|
||||
|
|
|
|||
22
README.md
22
README.md
|
|
@ -6,9 +6,9 @@ Helvum is a GTK-based patchbay for pipewire, inspired by the JACK tool [catia](h
|
|||
|
||||

|
||||
|
||||
<a href="https://flathub.org/apps/details/org.pipewire.Helvum"><img src="https://flathub.org/assets/badges/flathub-badge-en.png" width="300"/></a>
|
||||
`<a href="https://flathub.org/apps/details/org.pipewire.Helvum"><img src="https://flathub.org/assets/badges/flathub-badge-en.png" width="300"/>``</a>`
|
||||
|
||||
<a href="https://repology.org/project/helvum/versions"><img src="https://repology.org/badge/vertical-allrepos/helvum.svg" width="300"/></a>
|
||||
`<a href="https://repology.org/project/helvum/versions"><img src="https://repology.org/badge/vertical-allrepos/helvum.svg" width="300"/>``</a>`
|
||||
|
||||
# Features planned
|
||||
|
||||
|
|
@ -20,33 +20,40 @@ More suggestions are welcome!
|
|||
# Building
|
||||
|
||||
## Via flatpak
|
||||
|
||||
If you don't have the flathub repo in your remote-list for flatpak you will need to add that first:
|
||||
|
||||
```shell
|
||||
$ flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
|
||||
```
|
||||
|
||||
Then install the required flatpak platform and SDK, if you dont have them already:
|
||||
|
||||
```shell
|
||||
$ flatpak install org.gnome.{Platform,Sdk}//45 org.freedesktop.Sdk.Extension.rust-stable//23.08 org.freedesktop.Sdk.Extension.llvm16//23.08
|
||||
$ flatpak install org.gnome.{Platform,Sdk}//50 org.freedesktop.Sdk.Extension.rust-stable//25.08 org.freedesktop.Sdk.Extension.llvm22//25.08
|
||||
```
|
||||
|
||||
To compile and install as a flatpak, clone the project, change to the project directory, and run:
|
||||
|
||||
```shell
|
||||
$ flatpak-builder --install flatpak-build/ build-aux/org.pipewire.Helvum.json
|
||||
```
|
||||
|
||||
You can then run the app via
|
||||
|
||||
```shell
|
||||
$ flatpak run org.pipewire.Helvum
|
||||
```
|
||||
|
||||
## Manually
|
||||
|
||||
For compilation, you will need:
|
||||
|
||||
- Meson
|
||||
- An up-to-date rust toolchain
|
||||
- `libclang-3.7` or higher
|
||||
- `libadwaita-1` and `libpipewire-0.3` development packages and their dependencies
|
||||
- **Meson** (>= 1.9.0)
|
||||
- **Rust Toolchain** (>= 1.94.0)
|
||||
- **GTK4** (>= 4.22.0) development packages
|
||||
- **libadwaita-1** (>= 1.9.0) development packages
|
||||
- **libpipewire-0.3** (>= 1.6.0) development packages and their dependencies
|
||||
|
||||
To compile and install, run
|
||||
|
||||
|
|
@ -60,6 +67,7 @@ in the repository root.
|
|||
This will install the compiled project files into `/usr/local`.
|
||||
|
||||
# License and Credits
|
||||
|
||||
Helvum is distributed under the terms of the GPL3 license.
|
||||
See LICENSE for more information.
|
||||
|
||||
|
|
|
|||
|
|
@ -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.llvm22"
|
||||
],
|
||||
"command": "helvum",
|
||||
"finish-args": [
|
||||
|
|
@ -13,11 +13,12 @@
|
|||
"--socket=wayland",
|
||||
"--device=dri",
|
||||
"--share=ipc",
|
||||
"--filesystem=xdg-run/pipewire-0"
|
||||
"--filesystem=xdg-run/pipewire-0",
|
||||
"--filesystem=host"
|
||||
],
|
||||
"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/llvm22/bin",
|
||||
"prepend-ld-library-path": "/usr/lib/sdk/llvm22/lib",
|
||||
"build-args": [
|
||||
"--share=network"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ desktop_file = configure_file(
|
|||
if desktop_file_validate.found()
|
||||
test(
|
||||
'validate-desktop',
|
||||
desktop_file_validate,
|
||||
sh,
|
||||
args: [
|
||||
desktop_file
|
||||
],
|
||||
'-c',
|
||||
'desktop-file-validate data/' + base_id + '.desktop'
|
||||
]
|
||||
)
|
||||
endif
|
||||
|
||||
|
|
@ -36,10 +37,11 @@ appdata_file = configure_file(
|
|||
if appstream_util.found()
|
||||
test(
|
||||
'validate-appdata',
|
||||
appstream_util,
|
||||
sh,
|
||||
args: [
|
||||
'validate', '--nonet', appdata_file
|
||||
],
|
||||
'-c',
|
||||
'appstream-util validate --nonet data/' + base_id + '.metainfo.xml'
|
||||
]
|
||||
)
|
||||
endif
|
||||
|
||||
|
|
|
|||
15
meson.build
15
meson.build
|
|
@ -3,21 +3,26 @@ project(
|
|||
'rust',
|
||||
version: '0.5.1',
|
||||
license: 'GPL-3.0',
|
||||
meson_version: '>=0.59.0'
|
||||
meson_version: '>=1.9.0',
|
||||
default_options: [
|
||||
'warning_level=2',
|
||||
'buildtype=debugoptimized',
|
||||
],
|
||||
)
|
||||
|
||||
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('libpipewire-0.3')
|
||||
dependency('glib-2.0', version: '>= 2.88.0')
|
||||
dependency('gtk4', version: '>= 4.22.0')
|
||||
dependency('libadwaita-1', version: '>= 1.9.0')
|
||||
dependency('libpipewire-0.3', version: '>= 1.6.0')
|
||||
|
||||
desktop_file_validate = find_program('desktop-file-validate', required: false)
|
||||
appstream_util = find_program('appstream-util', required: false)
|
||||
cargo = find_program('cargo', required: true)
|
||||
sh = find_program('sh', required: true)
|
||||
|
||||
prefix = get_option('prefix')
|
||||
bindir = prefix / get_option('bindir')
|
||||
|
|
|
|||
|
|
@ -16,11 +16,12 @@
|
|||
|
||||
use adw::{
|
||||
gio,
|
||||
glib::{self, clone, Receiver},
|
||||
glib::{self, clone},
|
||||
gtk,
|
||||
prelude::*,
|
||||
subclass::prelude::*,
|
||||
};
|
||||
use async_channel::Receiver;
|
||||
use pipewire::channel::Sender;
|
||||
|
||||
use crate::{graph_manager::GraphManager, ui, GtkMessage, PipewireMessage};
|
||||
|
|
@ -34,7 +35,7 @@ mod imp {
|
|||
use super::*;
|
||||
|
||||
use adw::subclass::prelude::AdwApplicationImpl;
|
||||
use once_cell::unsync::OnceCell;
|
||||
use std::cell::OnceCell;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Application {
|
||||
|
|
@ -60,13 +61,17 @@ 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) {
|
||||
|
|
@ -78,7 +83,7 @@ mod imp {
|
|||
|
||||
// Load CSS from the STYLE variable.
|
||||
let provider = gtk::CssProvider::new();
|
||||
provider.load_from_data(STYLE);
|
||||
provider.load_from_string(STYLE);
|
||||
gtk::style_context_add_provider_for_display(
|
||||
>k::gdk::Display::default().expect("Error initializing gtk css provider."),
|
||||
&provider,
|
||||
|
|
@ -97,9 +102,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,8 +125,7 @@ mod imp {
|
|||
let window = obj.active_window().unwrap();
|
||||
let authors: Vec<&str> = AUTHORS.split(':').collect();
|
||||
|
||||
let about_window = adw::AboutWindow::builder()
|
||||
.transient_for(&window)
|
||||
let about_dialog = adw::AboutDialog::builder()
|
||||
.application_icon(APP_ID)
|
||||
.application_name("Helvum")
|
||||
.developer_name("Tom Wagner")
|
||||
|
|
@ -128,7 +136,7 @@ mod imp {
|
|||
.license_type(gtk::License::Gpl30Only)
|
||||
.build();
|
||||
|
||||
about_window.present();
|
||||
about_dialog.present(Some(&window));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,20 +23,18 @@ use crate::{ui::graph::GraphView, GtkMessage, PipewireMessage};
|
|||
mod imp {
|
||||
use super::*;
|
||||
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
|
||||
use once_cell::unsync::OnceCell;
|
||||
use std::{cell::OnceCell, cell::RefCell, collections::HashMap};
|
||||
|
||||
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>,
|
||||
#[property(get, set, construct_only, nullable)]
|
||||
pub graph: RefCell<Option<crate::ui::graph::GraphView>>,
|
||||
|
||||
#[property(get, set, construct_only)]
|
||||
pub connection_banner: OnceCell<adw::Banner>,
|
||||
#[property(get, set, construct_only, nullable)]
|
||||
pub connection_banner: RefCell<Option<adw::Banner>>,
|
||||
|
||||
pub pw_sender: OnceCell<PwSender<crate::GtkMessage>>,
|
||||
pub items: RefCell<HashMap<u32, glib::Object>>,
|
||||
|
|
@ -53,36 +51,69 @@ 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| {
|
||||
pub fn attach_receiver(&self, receiver: async_channel::Receiver<crate::PipewireMessage>) {
|
||||
let obj = self.obj().clone();
|
||||
glib::MainContext::default().spawn_local(async move {
|
||||
while let Ok(msg) = receiver.recv().await {
|
||||
let imp = obj.imp();
|
||||
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::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
|
||||
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::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::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);
|
||||
if let Some(banner) = imp.connection_banner.borrow().as_ref() {
|
||||
banner.set_revealed(true);
|
||||
}
|
||||
}
|
||||
PipewireMessage::Connected => {
|
||||
imp.obj().connection_banner().set_revealed(false);
|
||||
},
|
||||
if let Some(banner) = imp.connection_banner.borrow().as_ref() {
|
||||
banner.set_revealed(false);
|
||||
}
|
||||
}
|
||||
PipewireMessage::Disconnected => {
|
||||
imp.clear();
|
||||
},
|
||||
};
|
||||
glib::ControlFlow::Continue
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
fn graph_view(&self) -> crate::ui::graph::GraphView {
|
||||
self.graph.borrow().clone().expect("graph should be set")
|
||||
}
|
||||
|
||||
/// Add a new node to the view.
|
||||
|
|
@ -93,7 +124,7 @@ mod imp {
|
|||
|
||||
self.items.borrow_mut().insert(id, node.clone().upcast());
|
||||
|
||||
self.obj().graph().add_node(node, node_type);
|
||||
self.graph_view().add_node(node, node_type);
|
||||
}
|
||||
|
||||
/// Update a node tooltip to the view.
|
||||
|
|
@ -126,11 +157,11 @@ mod imp {
|
|||
return;
|
||||
};
|
||||
|
||||
self.obj().graph().remove_node(&node);
|
||||
self.graph_view().remove_node(&node);
|
||||
}
|
||||
|
||||
/// 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: libspa::utils::Direction) {
|
||||
log::info!("Adding port to graph: id {}", id);
|
||||
|
||||
let mut items = self.items.borrow_mut();
|
||||
|
|
@ -150,15 +181,20 @@ 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_default]
|
||||
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());
|
||||
|
|
@ -248,7 +284,8 @@ mod imp {
|
|||
|
||||
// Update graph to contain the new link.
|
||||
self.graph
|
||||
.get()
|
||||
.borrow()
|
||||
.as_ref()
|
||||
.expect("graph should be set")
|
||||
.add_link(link);
|
||||
}
|
||||
|
|
@ -273,7 +310,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: libspa::param::format::MediaType) {
|
||||
let items = self.items.borrow();
|
||||
|
||||
let Some(link) = items.get(&id) else {
|
||||
|
|
@ -308,12 +345,12 @@ mod imp {
|
|||
return;
|
||||
};
|
||||
|
||||
self.obj().graph().remove_link(&link);
|
||||
self.graph_view().remove_link(&link);
|
||||
}
|
||||
|
||||
fn clear(&self) {
|
||||
self.items.borrow_mut().clear();
|
||||
self.obj().graph().clear();
|
||||
self.graph_view().clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -327,7 +364,7 @@ impl GraphManager {
|
|||
graph: &GraphView,
|
||||
connection_banner: &adw::Banner,
|
||||
sender: PwSender<GtkMessage>,
|
||||
receiver: glib::Receiver<PipewireMessage>,
|
||||
receiver: async_channel::Receiver<PipewireMessage>,
|
||||
) -> Self {
|
||||
let res: Self = glib::Object::builder()
|
||||
.property("graph", graph)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ mod pipewire_connection;
|
|||
mod ui;
|
||||
|
||||
use adw::{gtk, prelude::*};
|
||||
use pipewire::spa::{format::MediaType, Direction};
|
||||
use libspa::{param::format::MediaType, utils::Direction};
|
||||
|
||||
/// Messages sent by the GTK thread to notify the pipewire thread.
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -120,7 +120,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
// 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) = async_channel::bounded::<PipewireMessage>(64);
|
||||
let (pw_sender, pw_receiver) = pipewire::channel::channel();
|
||||
let pw_thread =
|
||||
std::thread::spawn(move || pipewire_connection::thread_main(gtk_sender, pw_receiver));
|
||||
|
|
|
|||
|
|
@ -23,22 +23,21 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
|
||||
use adw::glib::{self, clone};
|
||||
use libspa::{
|
||||
param::{ParamInfoFlags, ParamType},
|
||||
utils::dict::DictRef,
|
||||
};
|
||||
use log::{debug, error, info, warn};
|
||||
use pipewire::{
|
||||
context::ContextRc,
|
||||
core::CoreRc,
|
||||
keys,
|
||||
link::{Link, LinkChangeMask, LinkInfo, LinkListener, LinkState},
|
||||
node::{Node, NodeInfo, NodeListener},
|
||||
port::{Port, PortChangeMask, PortInfo, PortListener},
|
||||
prelude::*,
|
||||
properties,
|
||||
registry::{GlobalObject, Registry},
|
||||
spa::{
|
||||
param::{ParamInfoFlags, ParamType},
|
||||
ForeignDict, SpaResult,
|
||||
},
|
||||
link::{Link, LinkChangeMask, LinkListener, LinkState},
|
||||
main_loop::MainLoopRc,
|
||||
node::{Node, NodeListener},
|
||||
port::{Port, PortChangeMask, PortListener},
|
||||
registry::{GlobalObject, RegistryRc},
|
||||
types::ObjectType,
|
||||
Context, Core, MainLoop,
|
||||
};
|
||||
|
||||
use crate::{GtkMessage, MediaType, NodeType, PipewireMessage};
|
||||
|
|
@ -61,50 +60,45 @@ enum ProxyItem {
|
|||
|
||||
/// The "main" function of the pipewire thread.
|
||||
pub(super) fn thread_main(
|
||||
gtk_sender: glib::Sender<PipewireMessage>,
|
||||
gtk_sender: async_channel::Sender<PipewireMessage>,
|
||||
mut pw_receiver: pipewire::channel::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! {
|
||||
"media.category" => "Manager"
|
||||
})) {
|
||||
Ok(core) => Rc::new(core),
|
||||
let core = match context.connect_rc(None) {
|
||||
Ok(core) => core,
|
||||
Err(_) => {
|
||||
if !is_connecting {
|
||||
is_connecting = true;
|
||||
gtk_sender
|
||||
.send(PipewireMessage::Connecting)
|
||||
.send_blocking(PipewireMessage::Connecting)
|
||||
.expect("Failed to send message");
|
||||
}
|
||||
|
||||
// If connection is failed, try to connect again in 200ms
|
||||
// If connection failed, try again in 200ms
|
||||
let interval = Some(Duration::from_millis(200));
|
||||
|
||||
let timer = mainloop.add_timer(clone!(@strong mainloop => move |_| {
|
||||
mainloop.quit();
|
||||
}));
|
||||
|
||||
let ml = mainloop.clone();
|
||||
let timer = mainloop.loop_().add_timer(move |_| {
|
||||
ml.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();
|
||||
}
|
||||
)
|
||||
let ml2 = mainloop.clone();
|
||||
let is_stopped2 = is_stopped.clone();
|
||||
let receiver = pw_receiver.attach(mainloop.loop_(), move |msg| {
|
||||
if let GtkMessage::Terminate = msg {
|
||||
is_stopped2.set(true);
|
||||
ml2.quit();
|
||||
}
|
||||
});
|
||||
|
||||
mainloop.run();
|
||||
pw_receiver = receiver.deattach();
|
||||
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
|
@ -112,73 +106,92 @@ pub(super) fn thread_main(
|
|||
if is_connecting {
|
||||
is_connecting = false;
|
||||
gtk_sender
|
||||
.send(PipewireMessage::Connected)
|
||||
.send_blocking(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 proxies: Rc<RefCell<HashMap<u32, ProxyItem>>> = 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();
|
||||
}
|
||||
})
|
||||
// Attach receiver to process GTK→PW messages
|
||||
let ml3 = mainloop.clone();
|
||||
let core2 = core.clone();
|
||||
let registry2 = registry.clone();
|
||||
let state2 = state.clone();
|
||||
let is_stopped2 = is_stopped.clone();
|
||||
let receiver = pw_receiver.attach(mainloop.loop_(), move |msg| match msg {
|
||||
GtkMessage::ToggleLink { port_from, port_to } => {
|
||||
toggle_link(port_from, port_to, &core2, ®istry2, &state2)
|
||||
}
|
||||
GtkMessage::Terminate => {
|
||||
is_stopped2.set(true);
|
||||
ml3.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 {
|
||||
// Listen for core errors (e.g. disconnection)
|
||||
let gtk_sender2 = gtk_sender.clone();
|
||||
let ml4 = mainloop.clone();
|
||||
let _listener = core
|
||||
.add_listener_local()
|
||||
.error(move |id, _seq, res, message| {
|
||||
if id != 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
if res == -libc::EPIPE {
|
||||
gtk_sender.send(PipewireMessage::Disconnected)
|
||||
gtk_sender2
|
||||
.send_blocking(PipewireMessage::Disconnected)
|
||||
.expect("Failed to send message");
|
||||
mainloop.quit();
|
||||
ml4.quit();
|
||||
} else {
|
||||
use libspa::utils::result::SpaResult;
|
||||
let serr = SpaResult::from_c(res).into_result().unwrap_err();
|
||||
error!("Pipewire Core received error {serr}: {message}");
|
||||
}
|
||||
}))
|
||||
})
|
||||
.register();
|
||||
|
||||
// Listen for registry events (nodes, ports, links appearing / disappearing)
|
||||
let gtk_sender3 = gtk_sender.clone();
|
||||
let registry3 = registry.clone();
|
||||
let proxies2 = proxies.clone();
|
||||
let state3 = state.clone();
|
||||
let proxies_remove = proxies.clone();
|
||||
let state_remove = state.clone();
|
||||
let gtk_sender4 = gtk_sender.clone();
|
||||
let _listener = registry
|
||||
.add_listener_local()
|
||||
.global(clone!(@strong gtk_sender, @weak 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),
|
||||
_ => {
|
||||
// Other objects are not interesting to us
|
||||
}
|
||||
.global(move |global| match global.type_ {
|
||||
ObjectType::Node => {
|
||||
handle_node(global, >k_sender3, ®istry3, &proxies2, &state3)
|
||||
}
|
||||
))
|
||||
.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");
|
||||
ObjectType::Port => {
|
||||
handle_port(global, >k_sender3, ®istry3, &proxies2, &state3)
|
||||
}
|
||||
ObjectType::Link => {
|
||||
handle_link(global, >k_sender3, ®istry3, &proxies2, &state3)
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.global_remove(move |id| {
|
||||
if let Some(item) = state_remove.borrow_mut().remove(id) {
|
||||
gtk_sender4
|
||||
.send_blocking(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_remove.borrow_mut().remove(&id);
|
||||
})
|
||||
.register();
|
||||
|
||||
mainloop.run();
|
||||
|
|
@ -187,7 +200,7 @@ 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) -> &str {
|
||||
props
|
||||
.get(&keys::NODE_DESCRIPTION)
|
||||
.or_else(|| props.get(&keys::NODE_NICK))
|
||||
|
|
@ -197,9 +210,9 @@ fn get_node_name(props: &ForeignDict) -> &str {
|
|||
|
||||
/// Handle a new node being added
|
||||
fn handle_node(
|
||||
node: &GlobalObject<ForeignDict>,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
registry: &Rc<Registry>,
|
||||
node: &GlobalObject<&DictRef>,
|
||||
sender: &async_channel::Sender<PipewireMessage>,
|
||||
registry: &RegistryRc,
|
||||
proxies: &Rc<RefCell<HashMap<u32, ProxyItem>>>,
|
||||
state: &Rc<RefCell<State>>,
|
||||
) {
|
||||
|
|
@ -233,7 +246,7 @@ fn handle_node(
|
|||
state.borrow_mut().insert(node.id, Item::Node);
|
||||
|
||||
sender
|
||||
.send(PipewireMessage::NodeAdded {
|
||||
.send_blocking(PipewireMessage::NodeAdded {
|
||||
id: node.id,
|
||||
name,
|
||||
node_type,
|
||||
|
|
@ -241,11 +254,13 @@ fn handle_node(
|
|||
.expect("Failed to send message");
|
||||
|
||||
let proxy: Node = registry.bind(node).expect("Failed to bind to node proxy");
|
||||
let sender2 = sender.clone();
|
||||
let proxies2 = proxies.clone();
|
||||
let listener = proxy
|
||||
.add_listener_local()
|
||||
.info(clone!(@strong sender, @strong proxies => move |info| {
|
||||
handle_node_info(info, &sender, &proxies);
|
||||
}))
|
||||
.info(move |info| {
|
||||
handle_node_info(info, &sender2, &proxies2);
|
||||
})
|
||||
.register();
|
||||
|
||||
proxies.borrow_mut().insert(
|
||||
|
|
@ -258,8 +273,8 @@ fn handle_node(
|
|||
}
|
||||
|
||||
fn handle_node_info(
|
||||
info: &NodeInfo,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
info: &pipewire::node::NodeInfoRef,
|
||||
sender: &async_channel::Sender<PipewireMessage>,
|
||||
proxies: &Rc<RefCell<HashMap<u32, ProxyItem>>>,
|
||||
) {
|
||||
debug!("Received node info: {:?}", info);
|
||||
|
|
@ -276,7 +291,7 @@ fn handle_node_info(
|
|||
let name = get_node_name(props).to_string();
|
||||
|
||||
sender
|
||||
.send(PipewireMessage::NodeNameChanged {
|
||||
.send_blocking(PipewireMessage::NodeNameChanged {
|
||||
id,
|
||||
name,
|
||||
media_name: media_name.to_string(),
|
||||
|
|
@ -287,26 +302,29 @@ 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: &async_channel::Sender<PipewireMessage>,
|
||||
registry: &RegistryRc,
|
||||
proxies: &Rc<RefCell<HashMap<u32, ProxyItem>>>,
|
||||
state: &Rc<RefCell<State>>,
|
||||
) {
|
||||
let port_id = port.id;
|
||||
let proxy: Port = registry.bind(port).expect("Failed to bind to port proxy");
|
||||
|
||||
let sender2 = sender.clone();
|
||||
let proxies2 = proxies.clone();
|
||||
let state2 = state.clone();
|
||||
let sender3 = sender.clone();
|
||||
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| {
|
||||
.info(move |info| {
|
||||
handle_port_info(info, &proxies2, &state2, &sender2);
|
||||
})
|
||||
.param(move |_, param_id, _, _, param| {
|
||||
if param_id == ParamType::EnumFormat {
|
||||
handle_port_enum_format(port_id, param, &sender)
|
||||
handle_port_enum_format(port_id, param, &sender3)
|
||||
}
|
||||
}))
|
||||
})
|
||||
.register();
|
||||
|
||||
proxies.borrow_mut().insert(
|
||||
|
|
@ -319,10 +337,10 @@ fn handle_port(
|
|||
}
|
||||
|
||||
fn handle_port_info(
|
||||
info: &PortInfo,
|
||||
info: &pipewire::port::PortInfoRef,
|
||||
proxies: &Rc<RefCell<HashMap<u32, ProxyItem>>>,
|
||||
state: &Rc<RefCell<State>>,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
sender: &async_channel::Sender<PipewireMessage>,
|
||||
) {
|
||||
debug!("Received port info: {:?}", info);
|
||||
|
||||
|
|
@ -341,7 +359,7 @@ fn handle_port_info(
|
|||
// TODO: React to param changes
|
||||
}
|
||||
} else {
|
||||
// First time we get info. We can now notify the gtk thread of a new link.
|
||||
// First time we get info. We can now notify the gtk thread of a new port.
|
||||
let props = info.props().expect("Port object is missing properties");
|
||||
let name = props.get("port.name").unwrap_or_default().to_string();
|
||||
let node_id: u32 = props
|
||||
|
|
@ -363,7 +381,7 @@ fn handle_port_info(
|
|||
}
|
||||
|
||||
sender
|
||||
.send(PipewireMessage::PortAdded {
|
||||
.send_blocking(PipewireMessage::PortAdded {
|
||||
id,
|
||||
node_id,
|
||||
name,
|
||||
|
|
@ -375,16 +393,16 @@ fn handle_port_info(
|
|||
|
||||
fn handle_port_enum_format(
|
||||
port_id: u32,
|
||||
param: Option<&pipewire::spa::pod::Pod>,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
param: Option<&libspa::pod::Pod>,
|
||||
sender: &async_channel::Sender<PipewireMessage>,
|
||||
) {
|
||||
let media_type = param
|
||||
.and_then(|param| pipewire::spa::param::format_utils::parse_format(param).ok())
|
||||
.and_then(|param| libspa::param::format_utils::parse_format(param).ok())
|
||||
.map(|(media_type, _media_subtype)| media_type)
|
||||
.unwrap_or(MediaType::Unknown);
|
||||
|
||||
sender
|
||||
.send(PipewireMessage::PortFormatChanged {
|
||||
.send_blocking(PipewireMessage::PortFormatChanged {
|
||||
id: port_id,
|
||||
media_type,
|
||||
})
|
||||
|
|
@ -393,11 +411,11 @@ fn handle_port_enum_format(
|
|||
|
||||
/// Handle a new link being added
|
||||
fn handle_link(
|
||||
link: &GlobalObject<ForeignDict>,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
registry: &Rc<Registry>,
|
||||
link: &GlobalObject<&DictRef>,
|
||||
sender: &async_channel::Sender<PipewireMessage>,
|
||||
registry: &RegistryRc,
|
||||
proxies: &Rc<RefCell<HashMap<u32, ProxyItem>>>,
|
||||
state: &Rc<RefCell<State>>,
|
||||
_state: &Rc<RefCell<State>>,
|
||||
) {
|
||||
debug!(
|
||||
"New link (id:{}) appeared, setting up info listener.",
|
||||
|
|
@ -405,11 +423,13 @@ fn handle_link(
|
|||
);
|
||||
|
||||
let proxy: Link = registry.bind(link).expect("Failed to bind to link proxy");
|
||||
let sender2 = sender.clone();
|
||||
let state_link = _state.clone();
|
||||
let listener = proxy
|
||||
.add_listener_local()
|
||||
.info(clone!(@strong state, @strong sender => move |info| {
|
||||
handle_link_info(info, &state, &sender);
|
||||
}))
|
||||
.info(move |info| {
|
||||
handle_link_info(info, &state_link, &sender2);
|
||||
})
|
||||
.register();
|
||||
|
||||
proxies.borrow_mut().insert(
|
||||
|
|
@ -422,9 +442,9 @@ fn handle_link(
|
|||
}
|
||||
|
||||
fn handle_link_info(
|
||||
info: &LinkInfo,
|
||||
info: &pipewire::link::LinkInfoRef,
|
||||
state: &Rc<RefCell<State>>,
|
||||
sender: &glib::Sender<PipewireMessage>,
|
||||
sender: &async_channel::Sender<PipewireMessage>,
|
||||
) {
|
||||
debug!("Received link info: {:?}", info);
|
||||
|
||||
|
|
@ -432,10 +452,9 @@ fn handle_link_info(
|
|||
|
||||
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 {
|
||||
.send_blocking(PipewireMessage::LinkStateChanged {
|
||||
id,
|
||||
active: matches!(info.state(), LinkState::Active),
|
||||
})
|
||||
|
|
@ -443,21 +462,20 @@ fn handle_link_info(
|
|||
}
|
||||
if info.change_mask().contains(LinkChangeMask::FORMAT) {
|
||||
sender
|
||||
.send(PipewireMessage::LinkFormatChanged {
|
||||
.send_blocking(PipewireMessage::LinkFormatChanged {
|
||||
id,
|
||||
media_type: get_link_media_type(info),
|
||||
})
|
||||
.expect("Failed to send message");
|
||||
}
|
||||
} else {
|
||||
// First time we get info. We can now notify the gtk thread of a new link.
|
||||
let port_from = info.output_port_id();
|
||||
let port_to = info.input_port_id();
|
||||
|
||||
state.insert(id, Item::Link { port_from, port_to });
|
||||
|
||||
sender
|
||||
.send(PipewireMessage::LinkAdded {
|
||||
.send_blocking(PipewireMessage::LinkAdded {
|
||||
id,
|
||||
port_from,
|
||||
port_to,
|
||||
|
|
@ -472,15 +490,13 @@ fn handle_link_info(
|
|||
fn toggle_link(
|
||||
port_from: u32,
|
||||
port_to: u32,
|
||||
core: &Rc<Core>,
|
||||
registry: &Rc<Registry>,
|
||||
core: &CoreRc,
|
||||
registry: &RegistryRc,
|
||||
state: &Rc<RefCell<State>>,
|
||||
) {
|
||||
let state = state.borrow_mut();
|
||||
let state = state.borrow();
|
||||
if let Some(id) = state.get_link_id(port_from, port_to) {
|
||||
info!("Requesting removal of link with id {}", id);
|
||||
|
||||
// FIXME: Handle error
|
||||
registry.destroy_global(id);
|
||||
} else {
|
||||
info!(
|
||||
|
|
@ -495,9 +511,9 @@ 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! {
|
||||
&pipewire::properties::properties! {
|
||||
"link.output.node" => node_from.to_string(),
|
||||
"link.output.port" => port_from.to_string(),
|
||||
"link.input.node" => node_to.to_string(),
|
||||
|
|
@ -510,12 +526,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: &pipewire::link::LinkInfoRef) -> MediaType {
|
||||
link_info
|
||||
.format()
|
||||
.and_then(|format| pipewire::spa::param::format_utils::parse_format(format).ok())
|
||||
.and_then(|format| libspa::param::format_utils::parse_format(format).ok())
|
||||
.map(|(media_type, _media_subtype)| media_type)
|
||||
.unwrap_or(MediaType::Unknown);
|
||||
|
||||
media_type
|
||||
.unwrap_or(MediaType::Unknown)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ mod imp {
|
|||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use adw::gtk::gdk::{self};
|
||||
use libspa::param::format::MediaType;
|
||||
use libspa::utils::Direction;
|
||||
use log::warn;
|
||||
use once_cell::sync::Lazy;
|
||||
use pipewire::spa::format::MediaType;
|
||||
use pipewire::spa::Direction;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
pub struct Colors {
|
||||
audio: gdk::RGBA,
|
||||
|
|
@ -151,7 +151,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 +228,25 @@ mod imp {
|
|||
|
||||
fn snapshot(&self, snapshot: >k::Snapshot) {
|
||||
let widget = &*self.obj();
|
||||
let alloc = widget.allocation();
|
||||
let (width, height) = (widget.width(), widget.height());
|
||||
|
||||
// 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, _)| {
|
||||
let n_width = node.width() as f32;
|
||||
let n_height = node.height() as f32;
|
||||
let p = node
|
||||
.compute_point(widget, &Point::new(0.0, 0.0))
|
||||
.unwrap_or(Point::new(0.0, 0.0));
|
||||
let (n_x, n_y) = (p.x(), p.y());
|
||||
n_x < width as f32
|
||||
&& n_y < height as f32
|
||||
&& n_x + n_width > 0.0
|
||||
&& n_y + n_height > 0.0
|
||||
})
|
||||
.for_each(|(node, _)| widget.snapshot_child(node, snapshot));
|
||||
|
||||
self.snapshot_links(widget, snapshot);
|
||||
|
|
@ -276,6 +287,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 +327,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 +361,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 +371,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 +381,7 @@ mod imp {
|
|||
controller.connect_leave(|controller| {
|
||||
let graph = controller
|
||||
.widget()
|
||||
.unwrap()
|
||||
.downcast::<super::GraphView>()
|
||||
.expect("Widget should be a graphview");
|
||||
|
||||
|
|
@ -386,14 +402,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 +450,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 +466,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 +482,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 +509,7 @@ mod imp {
|
|||
drag_controller.connect_drag_begin(|drag_controller, _, _| {
|
||||
let widget = drag_controller
|
||||
.widget()
|
||||
.unwrap()
|
||||
.downcast::<super::GraphView>()
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -489,6 +519,7 @@ mod imp {
|
|||
drag_controller.connect_drag_update(|drag_controller, x, y| {
|
||||
let widget = drag_controller
|
||||
.widget()
|
||||
.unwrap()
|
||||
.downcast::<super::GraphView>()
|
||||
.unwrap();
|
||||
|
||||
|
|
@ -601,34 +632,18 @@ mod imp {
|
|||
}
|
||||
|
||||
fn snapshot_links(&self, widget: &super::GraphView, snapshot: >k::Snapshot) {
|
||||
let alloc = widget.allocation();
|
||||
let (width, height) = (widget.width(), widget.height());
|
||||
|
||||
let link_cr = snapshot.append_cairo(&graphene::Rect::new(
|
||||
0.0,
|
||||
0.0,
|
||||
alloc.width() as f32,
|
||||
alloc.height() as f32,
|
||||
));
|
||||
let link_cr =
|
||||
snapshot.append_cairo(&graphene::Rect::new(0.0, 0.0, width as f32, 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"),
|
||||
audio: gdk::RGBA::new(50.0 / 255.0, 100.0 / 255.0, 240.0 / 255.0, 1.0),
|
||||
video: gdk::RGBA::new(200.0 / 255.0, 200.0 / 255.0, 0.0, 1.0),
|
||||
midi: gdk::RGBA::new(200.0 / 255.0, 0.0, 50.0 / 255.0, 1.0),
|
||||
unknown: gdk::RGBA::new(128.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 1.0),
|
||||
};
|
||||
|
||||
for link in self.links.borrow().iter() {
|
||||
|
|
@ -688,8 +703,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 +738,7 @@ mod imp {
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct GraphView(ObjectSubclass<imp::GraphView>)
|
||||
@extends gtk::Widget;
|
||||
@extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Scrollable;
|
||||
}
|
||||
|
||||
impl GraphView {
|
||||
|
|
@ -748,12 +766,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 +836,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();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use adw::{glib, prelude::*, subclass::prelude::*};
|
||||
use pipewire::spa::format::MediaType;
|
||||
use libspa::param::format::MediaType;
|
||||
|
||||
use super::Port;
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ mod imp {
|
|||
|
||||
use std::cell::Cell;
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
pub struct Link {
|
||||
pub output_port: glib::WeakRef<Port>,
|
||||
|
|
@ -53,7 +53,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)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use adw::{glib, gtk, prelude::*, subclass::prelude::*};
|
||||
use pipewire::spa::Direction;
|
||||
use libspa::utils::Direction;
|
||||
|
||||
use super::Port;
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ mod imp {
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct Node(ObjectSubclass<imp::Node>)
|
||||
@extends gtk::Widget;
|
||||
@extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
|
||||
}
|
||||
|
||||
impl Node {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use adw::{
|
|||
prelude::*,
|
||||
subclass::prelude::*,
|
||||
};
|
||||
use pipewire::spa::Direction;
|
||||
use libspa::utils::Direction;
|
||||
|
||||
use super::PortHandle;
|
||||
|
||||
|
|
@ -30,8 +30,8 @@ mod imp {
|
|||
|
||||
use std::cell::Cell;
|
||||
|
||||
use once_cell::{sync::Lazy, unsync::OnceCell};
|
||||
use pipewire::spa::{format::MediaType, Direction};
|
||||
use libspa::{param::format::MediaType, utils::Direction};
|
||||
use std::sync::LazyLock;
|
||||
|
||||
/// Graphical representation of a pipewire port.
|
||||
#[derive(gtk::CompositeTemplate, glib::Properties)]
|
||||
|
|
@ -39,7 +39,7 @@ mod imp {
|
|||
#[template(file = "port.ui")]
|
||||
pub struct Port {
|
||||
#[property(get, set, construct_only)]
|
||||
pub(super) pipewire_id: OnceCell<u32>,
|
||||
pub(super) pipewire_id: Cell<u32>,
|
||||
#[property(
|
||||
type = u32,
|
||||
get = |_| self.media_type.get().as_raw(),
|
||||
|
|
@ -70,7 +70,7 @@ mod imp {
|
|||
impl Default for Port {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pipewire_id: OnceCell::default(),
|
||||
pipewire_id: Cell::new(0),
|
||||
media_type: Cell::new(MediaType::Unknown),
|
||||
direction: Cell::new(Direction::Output),
|
||||
label: TemplateChild::default(),
|
||||
|
|
@ -112,7 +112,7 @@ mod imp {
|
|||
}
|
||||
|
||||
fn signals() -> &'static [Signal] {
|
||||
static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
|
||||
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()])
|
||||
|
|
@ -218,6 +218,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 +227,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 +243,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 +263,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 +332,7 @@ mod imp {
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct Port(ObjectSubclass<imp::Port>)
|
||||
@extends gtk::Widget;
|
||||
@extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
|
||||
}
|
||||
|
||||
impl Port {
|
||||
|
|
@ -341,21 +345,13 @@ 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 imp = self.imp();
|
||||
let handle = &imp.handle;
|
||||
let (width, height) = (handle.width() as f32, handle.height() as f32);
|
||||
|
||||
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,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
self.height() as f32 / 2.0,
|
||||
)
|
||||
handle
|
||||
.compute_point(self, &graphene::Point::new(width / 2.0, height / 2.0))
|
||||
.expect("Failed to compute link anchor")
|
||||
}
|
||||
|
||||
pub fn is_linkable_to(&self, other_port: &Self) -> bool {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ mod imp {
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct PortHandle(ObjectSubclass<imp::PortHandle>)
|
||||
@extends gtk::Widget;
|
||||
@extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
|
||||
}
|
||||
|
||||
impl PortHandle {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ mod imp {
|
|||
use super::*;
|
||||
|
||||
use gtk::{gio, glib::clone};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
#[derive(gtk::CompositeTemplate)]
|
||||
#[template(file = "zoomentry.ui")]
|
||||
|
|
@ -65,37 +65,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.set_visible(true);
|
||||
}
|
||||
}));
|
||||
}
|
||||
));
|
||||
|
||||
self.popover.set_parent(&self.entry.get());
|
||||
}
|
||||
|
|
@ -109,7 +121,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::ParamSpecObject::builder::<GraphView>("zoomed-widget")
|
||||
.flags(glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT)
|
||||
.build()]
|
||||
|
|
@ -132,9 +144,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 +177,7 @@ mod imp {
|
|||
|
||||
glib::wrapper! {
|
||||
pub struct ZoomEntry(ObjectSubclass<imp::ZoomEntry>)
|
||||
@extends gtk::Box, gtk::Widget;
|
||||
@extends gtk::Box, gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Orientable;
|
||||
}
|
||||
|
||||
impl ZoomEntry {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ 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 gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager, gio::ActionGroup, gio::ActionMap;
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue