Skip to content

Commit ded9fcc

Browse files
committed
feature(iced): Introduce iced version
1 parent 0f4685c commit ded9fcc

16 files changed

Lines changed: 379 additions & 96 deletions

.envrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
#!/usr/bin/env bash
2-
use nix
1+
use flake

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ Cargo.lock
1212

1313
# MSVC Windows builds of rustc generate these, which store debugging information
1414
*.pdb
15-
.idea
15+
.idea
16+
17+
# direnv
18+
.envrc
19+
.direnv/

Cargo.toml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
[package]
22
name = "re_set-lib"
33
version = "5.2.5"
4-
edition = "2021"
4+
edition = "2024"
55
description = "Data structure library for ReSet"
66
repository = "https://github.com/Xetibo/ReSet-Lib"
77
license = "GPL-3.0-or-later"
88

99
[dependencies]
10-
dbus = "0.9.7"
10+
dbus = "0.9.9"
1111
dbus-crossroads = "0.5.2"
12-
pulse = { version = "2.0", package = "libpulse-binding" }
13-
once_cell = "1.19.0"
14-
libloading = "0.8.3"
15-
gtk = { version = "0.8.1", package = "gtk4", features = ["v4_12"] }
16-
serial_test = "3.0.0"
17-
toml = "0.8.12"
18-
xdg = "2.5.2"
12+
pulse = { version = "2.30.1", package = "libpulse-binding" }
13+
once_cell = "1.21.3"
14+
libloading = "0.8.9"
15+
gtk = { version = "0.10.1", package = "gtk4", features = ["v4_16"] }
16+
serial_test = "3.2.0"
17+
toml = "0.9.8"
18+
xdg = "3.0.0"
19+
zbus = "5.11.0"
20+
iced = { version = "0.14.0-dev", features = [
21+
"advanced",
22+
"canvas",
23+
"image",
24+
"svg",
25+
"tokio",
26+
], git = "https://github.com/iced-rs/iced" }
27+
serde = "1.0.228"

flake.lock

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
description = "A library for ReSet applications.";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6+
flake-parts = {
7+
url = "github:hercules-ci/flake-parts";
8+
inputs.nixpkgs-lib.follows = "nixpkgs";
9+
};
10+
rust-overlay.url = "github:oxalica/rust-overlay";
11+
};
12+
13+
outputs = inputs @ {
14+
self,
15+
flake-parts,
16+
...
17+
}:
18+
flake-parts.lib.mkFlake {inherit inputs;} {
19+
systems = [
20+
"x86_64-linux"
21+
"aarch64-linux"
22+
];
23+
24+
perSystem = {
25+
pkgs,
26+
system,
27+
...
28+
}: {
29+
_module.args.pkgs = import self.inputs.nixpkgs {
30+
inherit system;
31+
overlays = [
32+
(
33+
import
34+
inputs.rust-overlay
35+
)
36+
];
37+
};
38+
devShells.default = pkgs.mkShell {
39+
nativeBuildInputs = [
40+
pkgs.pkg-config
41+
pkgs.dbus
42+
];
43+
44+
buildInputs = [
45+
pkgs.dbus
46+
pkgs.libadwaita
47+
pkgs.pulseaudio
48+
(pkgs.rust-bin.selectLatestNightlyWith
49+
(toolchain: toolchain.default))
50+
pkgs.rust-analyzer
51+
pkgs.clippy
52+
];
53+
};
54+
};
55+
};
56+
}

shell.nix

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/audio/audio_structures.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use dbus::{
55
use pulse::context::introspect::{
66
CardInfo, CardProfileInfo, SinkInfo, SinkInputInfo, SourceInfo, SourceOutputInfo,
77
};
8+
use zbus::zvariant::{DeserializeDict, SerializeDict, Type};
89

910
use crate::network::connection::Enum;
1011

@@ -113,7 +114,8 @@ impl Enum for DeviceState {
113114
}
114115
}
115116

116-
#[derive(Debug, Clone, Default)]
117+
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
118+
#[zvariant(signature = "dict")]
117119
pub struct Source {
118120
pub index: u32,
119121
pub name: String,
@@ -227,7 +229,8 @@ impl TAudioObject for Source {
227229
}
228230
}
229231

230-
#[derive(Debug, Clone, Default)]
232+
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
233+
#[zvariant(signature = "dict")]
231234
pub struct Sink {
232235
pub index: u32,
233236
pub name: String,
@@ -341,7 +344,8 @@ impl TAudioObject for Sink {
341344
}
342345
}
343346

344-
#[derive(Debug, Clone, Default)]
347+
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
348+
#[zvariant(signature = "dict")]
345349
pub struct InputStream {
346350
pub index: u32,
347351
pub name: String,
@@ -459,7 +463,8 @@ impl TAudioStreamObject for InputStream {
459463
}
460464
}
461465

462-
#[derive(Debug, Clone, Default)]
466+
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
467+
#[zvariant(signature = "dict")]
463468
pub struct OutputStream {
464469
pub index: u32,
465470
pub name: String,
@@ -577,7 +582,8 @@ impl TAudioStreamObject for OutputStream {
577582
}
578583
}
579584

580-
#[derive(Debug, Clone, Default)]
585+
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
586+
#[zvariant(signature = "dict")]
581587
pub struct Card {
582588
pub index: u32,
583589
pub name: String,
@@ -642,7 +648,8 @@ impl From<&CardInfo<'_>> for Card {
642648
}
643649
}
644650

645-
#[derive(Debug, Clone, Default)]
651+
#[derive(Debug, Clone, Default, DeserializeDict, SerializeDict, Type)]
652+
#[zvariant(signature = "dict")]
646653
pub struct CardProfile {
647654
pub name: String,
648655
pub description: String,

src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#![feature(trait_upcasting)]
21
#![feature(string_remove_matches)]
3-
#![feature(unsized_fn_params)]
42
#![feature(unboxed_closures)]
53
#![feature(fn_traits)]
64
use std::{
@@ -40,14 +38,14 @@ impl fmt::Display for PathNotFoundError {
4038

4139
pub fn create_config_directory(project_name: &str) -> Option<PathBuf> {
4240
let base_dir = xdg::BaseDirectories::new();
43-
if let Err(_error) = base_dir {
41+
if base_dir.config_home.is_none() {
4442
ERROR!(
45-
format!("Could not get base directories: {}", _error),
43+
format!("Could not get base directories"),
4644
ErrorLevel::Critical
4745
);
4846
return None;
4947
}
50-
let base_dir = base_dir.unwrap().get_config_home();
48+
let base_dir = base_dir.config_home.unwrap();
5149
let base_dir = flatpak_fix(base_dir);
5250
let project_dir = base_dir.join(project_name);
5351
let res = fs::create_dir_all(&project_dir);

src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serial_test::serial;
44
#[cfg(test)]
55
use crate::utils::plugin::plugin_tests;
66
#[cfg(test)]
7-
use crate::{utils::macros::ErrorLevel, write_log_to_file, ERROR, LOG};
7+
use crate::{ERROR, LOG, utils::macros::ErrorLevel, write_log_to_file};
88
#[cfg(test)]
99
use crate::{utils::plugin::PluginTestError, utils::plugin::PluginTestFunc};
1010

@@ -19,8 +19,8 @@ fn test_config_dir() {
1919
assert_eq!(
2020
config_file,
2121
xdg::BaseDirectories::new()
22-
.unwrap()
2322
.get_config_home()
23+
.unwrap()
2424
.join("globiTM/ReSet.toml")
2525
.to_str()
2626
.unwrap()

src/utils/any.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
use std::any::TypeId;
2+
use std::fmt::Debug;
3+
4+
use iced::advanced::graphics::futures::MaybeSend;
5+
6+
// Taken from https://doc.rust-lang.org/stable/src/core/any.rs.html
7+
// adjusted to fit ReSet
8+
pub trait ReSetAny: 'static + MaybeSend + Debug + Send + Sync {
9+
fn type_id(&self) -> TypeId;
10+
}
11+
12+
impl<T: 'static + ?Sized + Debug + MaybeSend + Send + Sync> ReSetAny for T {
13+
fn type_id(&self) -> TypeId {
14+
TypeId::of::<T>()
15+
}
16+
}
17+
18+
impl dyn ReSetAny {
19+
#[inline]
20+
pub fn is<T: ReSetAny>(&self) -> bool {
21+
// Get `TypeId` of the type this function is instantiated with.
22+
let t = TypeId::of::<T>();
23+
// Get `TypeId` of the type in the trait object (`self`).
24+
let concrete = self.type_id();
25+
// Compare both `TypeId`s on equality.
26+
t == concrete
27+
}
28+
29+
#[inline]
30+
pub fn downcast_ref<T: ReSetAny>(&self) -> Option<&T> {
31+
if self.is::<T>() {
32+
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
33+
// that check for memory safety because we have implemented Any for all types; no other
34+
// impls can exist as they would conflict with our impl.
35+
unsafe { Some(self.downcast_ref_unchecked()) }
36+
} else {
37+
None
38+
}
39+
}
40+
41+
#[inline]
42+
pub fn downcast_mut<T: ReSetAny>(&mut self) -> Option<&mut T> {
43+
if self.is::<T>() {
44+
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
45+
// that check for memory safety because we have implemented Any for all types; no other
46+
// impls can exist as they would conflict with our impl.
47+
unsafe { Some(self.downcast_mut_unchecked()) }
48+
} else {
49+
None
50+
}
51+
}
52+
53+
#[inline]
54+
/// # Safety
55+
pub unsafe fn downcast_mut_unchecked<T: ReSetAny>(&mut self) -> &mut T {
56+
debug_assert!(self.is::<T>());
57+
// SAFETY: caller guarantees that T is the correct type
58+
unsafe { &mut *(self as *mut dyn ReSetAny as *mut T) }
59+
}
60+
61+
#[inline]
62+
/// # Safety
63+
pub unsafe fn downcast_ref_unchecked<T: ReSetAny>(&self) -> &T {
64+
debug_assert!(self.is::<T>());
65+
// SAFETY: caller guarantees that T is the correct type
66+
unsafe { &*(self as *const dyn ReSetAny as *const T) }
67+
}
68+
}

0 commit comments

Comments
 (0)