adding systray

This commit is contained in:
Chris Cochrun 2025-10-14 13:41:55 -05:00
parent aaa21aff21
commit b693e71e5f
4 changed files with 813 additions and 677 deletions

1305
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -18,7 +18,7 @@ tracing-subscriber = { version = "0.3.18", features = ["fmt", "std", "chrono", "
ron = "0.8.1"
dirs = "5.0.1"
tokio = "1.41.1"
crisp = { git = "https://git.tfcconnection.org/chris/crisp", version = "0.1.3" }
# crisp = { git = "https://git.tfcconnection.org/chris/crisp", version = "0.1.3" }
iced_layershell = "0.13.0"
chrono = "0.4.39"
sysinfo = "0.35.0"

46
flake.lock generated
View file

@ -6,11 +6,11 @@
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1735281280,
"narHash": "sha256-FgW6NkzbGlmNeY0lywjvXgrZD+UPS/+848kI30Yaup0=",
"lastModified": 1751006353,
"narHash": "sha256-icKFXb83uv2ezRCfuq5G8QSwCuaoLywLljSL+UGmPPI=",
"owner": "nix-community",
"repo": "fenix",
"rev": "3915fd69e1a2827209f3a1080cb8bcca48d11fa7",
"rev": "b37f026b49ecb295a448c96bcbb0c174c14fc91b",
"type": "github"
},
"original": {
@ -42,11 +42,11 @@
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1733346208,
"narHash": "sha256-a4WZp1xQkrnA4BbnKrzJNr+dYoQr5Xneh2syJoddFyE=",
"lastModified": 1745925850,
"narHash": "sha256-cyAAMal0aPrlb1NgzMxZqeN1mAJ2pJseDhm2m6Um8T0=",
"owner": "nix-community",
"repo": "naersk",
"rev": "378614f37a6bee5a3f2ef4f825a73d948d3ae921",
"rev": "38bc60bbc157ae266d4a0c96671c6c742ee17a5f",
"type": "github"
},
"original": {
@ -57,11 +57,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1734649271,
"narHash": "sha256-4EVBRhOjMDuGtMaofAIqzJbg4Ql7Ai0PSeuVZTHjyKQ=",
"lastModified": 1750776420,
"narHash": "sha256-/CG+w0o0oJ5itVklOoLbdn2dGB0wbZVOoDm4np6w09A=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "d70bd19e0a38ad4790d3913bf08fcbfc9eeca507",
"rev": "30a61f056ac492e3b7cdcb69c1e6abdcf00e39cf",
"type": "github"
},
"original": {
@ -73,23 +73,27 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 0,
"narHash": "sha256-Qn3nPMSopRQJgmvHzVqPcE3I03zJyl8cSbgnnltfFDY=",
"path": "/nix/store/avxvalb7xf8x4avmrbcvn1vr5yy46kxs-source",
"type": "path"
"lastModified": 1750898778,
"narHash": "sha256-DXI7+SKDlTyA+C4zp0LoIywQ+BfdH5m4nkuxbWgV4UU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "322d8a3c6940039f7cff179a8b09c5d7ca06359d",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1735291276,
"narHash": "sha256-NYVcA06+blsLG6wpAbSPTCyLvxD/92Hy4vlY9WxFI1M=",
"lastModified": 1750776420,
"narHash": "sha256-/CG+w0o0oJ5itVklOoLbdn2dGB0wbZVOoDm4np6w09A=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "634fd46801442d760e09493a794c4f15db2d0cbb",
"rev": "30a61f056ac492e3b7cdcb69c1e6abdcf00e39cf",
"type": "github"
},
"original": {
@ -110,11 +114,11 @@
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1735227773,
"narHash": "sha256-eYkxxU3Bqr7uLMKXOIb9BGlaD0W/I2pI6bh1SIuPZH4=",
"lastModified": 1750871759,
"narHash": "sha256-hMNZXMtlhfjQdu1F4Fa/UFiMoXdZag4cider2R9a648=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "1ce4de2585cb9802c4d5a99d1a904b11fdba9501",
"rev": "317542c1e4a3ec3467d21d1c25f6a43b80d83e7d",
"type": "github"
},
"original": {

View file

@ -9,11 +9,12 @@ use freedesktop_icons::lookup;
use hyprland::data::{Client, Workspace, Workspaces};
use hyprland::event_listener::{self, AsyncEventListener};
use hyprland::shared::{HyprData, HyprDataActiveOptional, HyprDataVec};
use iced::alignment::Vertical;
use iced::font::Weight;
use iced::futures::SinkExt;
use iced::stream;
use iced::widget::image::Handle;
use iced::widget::{button, container, horizontal_space, image, row, svg, text};
use iced::widget::{button, container, horizontal_space, image, row, svg, text, Button};
use iced::{stream, ContentFit};
use iced::{
time, Background, Border, Color, Element, Event, Font, Length, Shadow, Subscription, Task,
Vector,
@ -87,7 +88,8 @@ struct Panel {
active_window: String,
active_window_icon_svg: Option<svg::Handle>,
active_window_icon_raster: Option<Handle>,
system_tray: Option<SystemTray>,
system_tray_svg: Option<Vec<svg::Handle>>,
system_tray_raster: Option<Vec<Handle>>,
apps: Vec<String>,
}
@ -142,7 +144,8 @@ impl Panel {
active_window_icon_svg,
active_window_icon_raster,
battery,
system_tray: None,
system_tray_svg: None,
system_tray_raster: None,
};
let sys_task = Task::perform(add_sys_tray(), |m| m);
@ -194,7 +197,7 @@ impl Panel {
Message::SizeChange(_) => todo!(),
Message::VirtualKeyboardPressed { time, key } => todo!(),
Message::IcedEvent(event) => {
debug!(?event)
// debug!(?event)
}
Message::WorkspaceChange(workspaces) => {
// debug!(?workspaces);
@ -231,7 +234,32 @@ impl Panel {
}
Message::AddSystemTray(system_tray) => {
debug!(?system_tray);
self.system_tray = Some(system_tray);
let mut raster_vec = vec![];
let mut svg_vec = vec![];
for item in system_tray.items.into_values() {
if let Some(icon) = item.0.icon_name {
let icon_path = PathBuf::from(icon.clone());
if icon_path.exists() {
debug!(?icon_path);
raster_vec.push(image::Handle::from_path(icon_path))
} else if let Some(icon) = lookup(&icon)
.with_theme("Papirus-Dark")
.force_svg()
.with_size(16)
.find()
{
svg_vec.push(svg::Handle::from_path(icon));
} else if let Some(icons) = item.0.icon_pixmap {
for icon in icons {
raster_vec.push(image::Handle::from_bytes(icon.pixels));
}
} else {
raster_vec.push( image::Handle::from("/home/chris/pics/wojaks/reddit_the_xenomorph_s bigass wojak folder/Chads/ChristianChad.png"))
}
}
}
self.system_tray_svg = Some(svg_vec);
self.system_tray_raster = Some(raster_vec);
}
Message::None => {}
_ => unreachable!(),
@ -338,27 +366,30 @@ impl Panel {
.iter()
.filter(|w| w.name != "special:special")
.map(|w| {
text!("{}", {
match w.id {
1 => "".to_owned(),
2 => "".to_owned(),
3 => "󰈙".to_owned(),
4 => "󰭹".to_owned(),
5 => "".to_owned(),
6 => "".to_owned(),
7 => "󰕧".to_owned(),
8 => "󰭹".to_owned(),
9 => "".to_owned(),
_ => w.name.clone(),
}
})
.color({
if w.id == self.active_workspace {
Color::parse("#ff6ac1").unwrap()
} else {
Color::parse("#57c7ff").unwrap()
}
})
container(
text!("{}", {
match w.id {
1 => "".to_owned(),
2 => "".to_owned(),
3 => "󰈙".to_owned(),
4 => "󰭹".to_owned(),
5 => "".to_owned(),
6 => "".to_owned(),
7 => "󰕧".to_owned(),
8 => "󰭹".to_owned(),
9 => "".to_owned(),
_ => w.name.clone(),
}
})
.color({
if w.id == self.active_workspace {
Color::parse("#ff6ac1").unwrap()
} else {
Color::parse("#57c7ff").unwrap()
}
}),
)
.center(Length::Shrink)
.into()
})
.collect();
@ -375,7 +406,11 @@ impl Panel {
// }
// }
if let Some(handle) = &self.active_window_icon_svg {
icon = svg(handle.clone()).width(16).height(16).into();
icon = svg(handle.clone())
.width(16)
.height(16)
.content_fit(ContentFit::Fill)
.into();
} else {
if let Some(handle) = &self.active_window_icon_raster {
icon = image(handle.clone()).width(16).height(16).into();
@ -383,7 +418,7 @@ impl Panel {
icon = image("/home/chris/pics/wojaks/reddit_the_xenomorph_s bigass wojak folder/Chads/ChristianChad.png").width(16).height(16).into();
}
}
let icon = container(icon).center(Length::Shrink).padding(4);
let icon = container(icon).center(Length::Shrink).padding([2, 4]);
let window = text!("{}", self.active_window).color(Color::parse("#57c7ff").unwrap());
let disk = text!("{}", self.disk).color(Color::parse("#ff9f43").unwrap());
@ -415,13 +450,47 @@ impl Panel {
let spacer = text!(" | ");
// let sys_tray = vec![button()]
let mut sys_tray_buttons: Vec<Element<Message>> = vec![];
if let Some(sys_tray) = &self.system_tray_svg {
for item in sys_tray.iter() {
sys_tray_buttons.push(
svg(item.clone())
.width(16)
.height(16)
.content_fit(ContentFit::Fill)
.into(),
);
}
}
if let Some(sys_tray) = &self.system_tray_raster {
for item in sys_tray.iter() {
sys_tray_buttons.push(
image(item)
.width(16)
.height(16)
.content_fit(ContentFit::Fill)
.into(),
);
}
}
let row = row!(
container(row!(workspaces, icon, window, horizontal_space()).spacing(10)),
container(clock),
container(row!(horizontal_space(), disk, cpu, mem, battery).spacing(5)),
spacer,
container(
row!(
horizontal_space(),
disk,
cpu,
mem,
battery,
spacer,
row(sys_tray_buttons).spacing(5)
)
.spacing(5)
),
)
.spacing(5)
.padding([0, 20]);
@ -534,12 +603,16 @@ struct SystemTray {
impl SystemTray {
async fn new() -> Result<Self> {
let client = system_tray::client::Client::new().await.into_diagnostic()?;
let _ = tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
let receiver = client.subscribe();
let rec_length = receiver.len();
let items = client.items();
let items = items
.lock()
.map_err(|_| SystemTrayError::SomeError)
.into_diagnostic()?
.clone();
debug!(?items);
Ok(Self { client, items })
}
}