Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#!/usr/bin/env bash
use nix
use flake
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
.idea
.idea

# direnv
.envrc
.direnv/
27 changes: 18 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
[package]
name = "re_set-lib"
version = "5.2.5"
edition = "2021"
edition = "2024"
description = "Data structure library for ReSet"
repository = "https://github.com/Xetibo/ReSet-Lib"
license = "GPL-3.0-or-later"

[dependencies]
dbus = "0.9.7"
dbus = "0.9.9"
dbus-crossroads = "0.5.2"
pulse = { version = "2.0", package = "libpulse-binding" }
once_cell = "1.19.0"
libloading = "0.8.3"
gtk = { version = "0.8.1", package = "gtk4", features = ["v4_12"] }
serial_test = "3.0.0"
toml = "0.8.12"
xdg = "2.5.2"
pulse = { version = "2.30.1", package = "libpulse-binding" }
once_cell = "1.21.3"
libloading = "0.8.9"
gtk = { version = "0.10.1", package = "gtk4", features = ["v4_16"] }
serial_test = "3.2.0"
toml = "0.9.8"
xdg = "3.0.0"
zbus = "5.11.0"
iced = { version = "0.14.0-dev", features = [
"advanced",
"canvas",
"image",
"svg",
"tokio",
], git = "https://github.com/iced-rs/iced" }
serde = "1.0.228"
83 changes: 83 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
description = "A library for ReSet applications.";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
rust-overlay.url = "github:oxalica/rust-overlay";
};

outputs = inputs @ {
self,
flake-parts,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = [
"x86_64-linux"
"aarch64-linux"
];

perSystem = {
pkgs,
system,
...
}: {
_module.args.pkgs = import self.inputs.nixpkgs {
inherit system;
overlays = [
(
import
inputs.rust-overlay
)
];
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
pkgs.pkg-config
pkgs.dbus
];

buildInputs = [
pkgs.dbus
pkgs.libadwaita
pkgs.pulseaudio
(pkgs.rust-bin.selectLatestNightlyWith
(toolchain: toolchain.default))
pkgs.rust-analyzer
pkgs.clippy
];
};
};
};
}
16 changes: 0 additions & 16 deletions shell.nix

This file was deleted.

19 changes: 13 additions & 6 deletions src/audio/audio_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use dbus::{
use pulse::context::introspect::{
CardInfo, CardProfileInfo, SinkInfo, SinkInputInfo, SourceInfo, SourceOutputInfo,
};
use zbus::zvariant::{DeserializeDict, SerializeDict, Type};

use crate::network::connection::Enum;

Expand Down Expand Up @@ -113,7 +114,8 @@ impl Enum for DeviceState {
}
}

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
#[zvariant(signature = "dict")]
pub struct Source {
pub index: u32,
pub name: String,
Expand Down Expand Up @@ -227,7 +229,8 @@ impl TAudioObject for Source {
}
}

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
#[zvariant(signature = "dict")]
pub struct Sink {
pub index: u32,
pub name: String,
Expand Down Expand Up @@ -341,7 +344,8 @@ impl TAudioObject for Sink {
}
}

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
#[zvariant(signature = "dict")]
pub struct InputStream {
pub index: u32,
pub name: String,
Expand Down Expand Up @@ -459,7 +463,8 @@ impl TAudioStreamObject for InputStream {
}
}

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
#[zvariant(signature = "dict")]
pub struct OutputStream {
pub index: u32,
pub name: String,
Expand Down Expand Up @@ -577,7 +582,8 @@ impl TAudioStreamObject for OutputStream {
}
}

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
#[zvariant(signature = "dict")]
pub struct Card {
pub index: u32,
pub name: String,
Expand Down Expand Up @@ -642,7 +648,8 @@ impl From<&CardInfo<'_>> for Card {
}
}

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
#[zvariant(signature = "dict")]
pub struct CardProfile {
pub name: String,
pub description: String,
Expand Down
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#![feature(trait_upcasting)]
#![feature(string_remove_matches)]
#![feature(unsized_fn_params)]
#![feature(unboxed_closures)]
#![feature(fn_traits)]
use std::{
Expand Down Expand Up @@ -40,14 +38,14 @@ impl fmt::Display for PathNotFoundError {

pub fn create_config_directory(project_name: &str) -> Option<PathBuf> {
let base_dir = xdg::BaseDirectories::new();
if let Err(_error) = base_dir {
if base_dir.config_home.is_none() {
ERROR!(
format!("Could not get base directories: {}", _error),
format!("Could not get base directories"),
ErrorLevel::Critical
);
return None;
}
let base_dir = base_dir.unwrap().get_config_home();
let base_dir = base_dir.config_home.unwrap();
let base_dir = flatpak_fix(base_dir);
let project_dir = base_dir.join(project_name);
let res = fs::create_dir_all(&project_dir);
Expand Down
4 changes: 2 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serial_test::serial;
#[cfg(test)]
use crate::utils::plugin::plugin_tests;
#[cfg(test)]
use crate::{utils::macros::ErrorLevel, write_log_to_file, ERROR, LOG};
use crate::{ERROR, LOG, utils::macros::ErrorLevel, write_log_to_file};
#[cfg(test)]
use crate::{utils::plugin::PluginTestError, utils::plugin::PluginTestFunc};

Expand All @@ -19,8 +19,8 @@ fn test_config_dir() {
assert_eq!(
config_file,
xdg::BaseDirectories::new()
.unwrap()
.get_config_home()
.unwrap()
.join("globiTM/ReSet.toml")
.to_str()
.unwrap()
Expand Down
68 changes: 68 additions & 0 deletions src/utils/any.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use std::any::TypeId;
use std::fmt::Debug;

use iced::advanced::graphics::futures::MaybeSend;

// Taken from https://doc.rust-lang.org/stable/src/core/any.rs.html
// adjusted to fit ReSet
pub trait ReSetAny: 'static + MaybeSend + Debug + Send + Sync {
fn type_id(&self) -> TypeId;
}

impl<T: 'static + ?Sized + Debug + MaybeSend + Send + Sync> ReSetAny for T {
fn type_id(&self) -> TypeId {
TypeId::of::<T>()
}
}

impl dyn ReSetAny {
#[inline]
pub fn is<T: ReSetAny>(&self) -> bool {
// Get `TypeId` of the type this function is instantiated with.
let t = TypeId::of::<T>();
// Get `TypeId` of the type in the trait object (`self`).
let concrete = self.type_id();
// Compare both `TypeId`s on equality.
t == concrete
}

#[inline]
pub fn downcast_ref<T: ReSetAny>(&self) -> Option<&T> {
if self.is::<T>() {
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
// that check for memory safety because we have implemented Any for all types; no other
// impls can exist as they would conflict with our impl.
unsafe { Some(self.downcast_ref_unchecked()) }
} else {
None
}
}

#[inline]
pub fn downcast_mut<T: ReSetAny>(&mut self) -> Option<&mut T> {
if self.is::<T>() {
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
// that check for memory safety because we have implemented Any for all types; no other
// impls can exist as they would conflict with our impl.
unsafe { Some(self.downcast_mut_unchecked()) }
} else {
None
}
}

#[inline]
/// # Safety
pub unsafe fn downcast_mut_unchecked<T: ReSetAny>(&mut self) -> &mut T {
debug_assert!(self.is::<T>());
// SAFETY: caller guarantees that T is the correct type
unsafe { &mut *(self as *mut dyn ReSetAny as *mut T) }
}

#[inline]
/// # Safety
pub unsafe fn downcast_ref_unchecked<T: ReSetAny>(&self) -> &T {
debug_assert!(self.is::<T>());
// SAFETY: caller guarantees that T is the correct type
unsafe { &*(self as *const dyn ReSetAny as *const T) }
}
}
Loading
Loading