From 73957b1370305b9f7900044016444e3c3f6cc159 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 23 May 2025 23:14:12 -0500 Subject: [PATCH] trying to add icons --- Cargo.lock | 309 +++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 +- src/main.rs | 64 +++++++++-- 3 files changed, 364 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e27d842..bba31bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -407,6 +407,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bit-set" version = "0.5.3" @@ -422,6 +428,12 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" +[[package]] +name = "bit_field" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" + [[package]] name = "bitflags" version = "1.3.2" @@ -708,6 +720,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + [[package]] name = "colorchoice" version = "1.0.3" @@ -845,7 +863,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59fd57d82eb4bfe7ffa9b1cec0c05e2fd378155b47f255a67983cb4afe0e80c2" dependencies = [ "bitflags 2.6.0", - "fontdb", + "fontdb 0.16.2", "log", "rangemap", "rayon", @@ -1006,6 +1024,12 @@ dependencies = [ "syn 2.0.92", ] +[[package]] +name = "data-url" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a" + [[package]] name = "dconf_rs" version = "0.3.0" @@ -1278,6 +1302,21 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "exr" +version = "1.73.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83197f59927b46c04a183a619b7c29df34e63e63c7869320862268c0ef687e0" +dependencies = [ + "bit_field", + "half", + "lebe", + "miniz_oxide", + "rayon-core", + "smallvec", + "zune-inflate", +] + [[package]] name = "fast-srgb8" version = "1.0.0" @@ -1320,6 +1359,12 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" + [[package]] name = "fnv" version = "1.0.7" @@ -1358,6 +1403,20 @@ dependencies = [ "ttf-parser 0.20.0", ] +[[package]] +name = "fontdb" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e32eac81c1135c1df01d4e6d4233c47ba11f6a6d07f33e0bba09d18797077770" +dependencies = [ + "fontconfig-parser", + "log", + "memmap2", + "slotmap", + "tinyvec", + "ttf-parser 0.21.1", +] + [[package]] name = "foreign-types" version = "0.5.0" @@ -1385,6 +1444,20 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" +[[package]] +name = "freedesktop-icons" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95f87364ea709292a3b3f74014ce3ee78412c89807eea75a358c8e029b000994" +dependencies = [ + "dirs 5.0.1", + "ini_core", + "once_cell", + "thiserror 1.0.69", + "tracing", + "xdg", +] + [[package]] name = "futures" version = "0.3.31" @@ -1519,6 +1592,16 @@ dependencies = [ "wasi", ] +[[package]] +name = "gif" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2" +dependencies = [ + "color_quant", + "weezl", +] + [[package]] name = "gimli" version = "0.31.1" @@ -1779,6 +1862,7 @@ dependencies = [ "iced_renderer", "iced_widget", "iced_winit", + "image", "thiserror 1.0.69", ] @@ -1842,6 +1926,8 @@ dependencies = [ "half", "iced_core", "iced_futures", + "image", + "kamadak-exif", "log", "once_cell", "raw-window-handle", @@ -1919,8 +2005,9 @@ dependencies = [ "bytemuck", "cosmic-text", "iced_graphics", - "kurbo", + "kurbo 0.10.4", "log", + "resvg", "rustc-hash 2.1.0", "softbuffer", "tiny-skia", @@ -1941,6 +2028,7 @@ dependencies = [ "iced_graphics", "log", "once_cell", + "resvg", "rustc-hash 2.1.0", "thiserror 1.0.69", "wgpu", @@ -1987,6 +2075,30 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "image" +version = "0.24.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d" +dependencies = [ + "bytemuck", + "byteorder", + "color_quant", + "exr", + "gif", + "jpeg-decoder", + "num-traits", + "png", + "qoi", + "tiff", +] + +[[package]] +name = "imagesize" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "029d73f573d8e8d63e6d5020011d3255b28c3ba85d6cf870a07184ed23de9284" + [[package]] name = "indexmap" version = "2.7.0" @@ -1997,6 +2109,15 @@ dependencies = [ "hashbrown 0.15.2", ] +[[package]] +name = "ini_core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a467a31a9f439b5262fa99c17084537bff57f24703d5a09a2b5c9657ec73a61" +dependencies = [ + "cfg-if", +] + [[package]] name = "instant" version = "0.1.13" @@ -2055,6 +2176,15 @@ dependencies = [ "libc", ] +[[package]] +name = "jpeg-decoder" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" +dependencies = [ + "rayon", +] + [[package]] name = "js-sys" version = "0.3.76" @@ -2065,6 +2195,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kamadak-exif" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef4fc70d0ab7e5b6bafa30216a6b48705ea964cdfc29c050f2412295eba58077" +dependencies = [ + "mutate_once", +] + [[package]] name = "khronos-egl" version = "6.0.0" @@ -2092,6 +2231,16 @@ dependencies = [ "smallvec", ] +[[package]] +name = "kurbo" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89234b2cc610a7dd927ebde6b41dd1a5d4214cffaef4cf1fb2195d592f92518f" +dependencies = [ + "arrayvec", + "smallvec", +] + [[package]] name = "layershellev" version = "0.13.0" @@ -2120,6 +2269,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +[[package]] +name = "lebe" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" + [[package]] name = "libc" version = "0.2.172" @@ -2330,6 +2485,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "mutate_once" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16cf681a23b4d0a43fc35024c176437f9dcd818db34e0f42ab456a0ee5ad497b" + [[package]] name = "naga" version = "0.19.2" @@ -2938,9 +3099,15 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" dependencies = [ - "siphasher", + "siphasher 0.3.11", ] +[[package]] +name = "pico-args" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" + [[package]] name = "pin-project" version = "1.1.7" @@ -3084,6 +3251,15 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afbdc74edc00b6f6a218ca6a5364d6226a259d4b8ea1af4a0ea063f27e179f4d" +[[package]] +name = "qoi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" +dependencies = [ + "bytemuck", +] + [[package]] name = "quick-xml" version = "0.36.2" @@ -3278,13 +3454,38 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" +[[package]] +name = "resvg" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "944d052815156ac8fa77eaac055220e95ba0b01fa8887108ca710c03805d9051" +dependencies = [ + "gif", + "jpeg-decoder", + "log", + "pico-args", + "rgb", + "svgtypes", + "tiny-skia", + "usvg", +] + +[[package]] +name = "rgb" +version = "0.8.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" +dependencies = [ + "bytemuck", +] + [[package]] name = "ron" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" dependencies = [ - "base64", + "base64 0.21.7", "bitflags 2.6.0", "serde", "serde_derive", @@ -3493,6 +3694,7 @@ dependencies = [ "clap", "crisp", "dirs 5.0.1", + "freedesktop-icons", "hyprland", "iced", "iced_layershell", @@ -3529,12 +3731,27 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" +[[package]] +name = "simplecss" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a9c6883ca9c3c7c90e888de77b7a5c849c779d25d74a1269b0218b14e8b136c" +dependencies = [ + "log", +] + [[package]] name = "siphasher" version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + [[package]] name = "skrifa" version = "0.22.3" @@ -3676,6 +3893,9 @@ name = "strict-num" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" +dependencies = [ + "float-cmp", +] [[package]] name = "strsim" @@ -3710,6 +3930,16 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce5d813d71d82c4cbc1742135004e4a79fd870214c155443451c139c9470a0aa" +[[package]] +name = "svgtypes" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68c7541fff44b35860c1a7a47a7cadf3e4a304c457b58f9870d9706ece028afc" +dependencies = [ + "kurbo 0.11.1", + "siphasher 1.0.1", +] + [[package]] name = "swash" version = "0.1.19" @@ -3872,6 +4102,17 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tiff" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + [[package]] name = "time" version = "0.3.37" @@ -4152,6 +4393,12 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" +[[package]] +name = "unicode-vo" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94" + [[package]] name = "unicode-width" version = "0.1.14" @@ -4164,6 +4411,33 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "usvg" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84ea542ae85c715f07b082438a4231c3760539d902e11d093847a0b22963032" +dependencies = [ + "base64 0.22.1", + "data-url", + "flate2", + "fontdb 0.18.0", + "imagesize", + "kurbo 0.11.1", + "log", + "pico-args", + "roxmltree", + "rustybuzz", + "simplecss", + "siphasher 1.0.1", + "strict-num", + "svgtypes", + "tiny-skia-path", + "unicode-bidi", + "unicode-script", + "unicode-vo", + "xmlwriter", +] + [[package]] name = "utf8parse" version = "0.2.2" @@ -4438,6 +4712,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "weezl" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" + [[package]] name = "wgpu" version = "0.19.4" @@ -5047,6 +5327,12 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ef33da6b1660b4ddbfb3aef0ade110c8b8a781a3b6382fa5f2b5b040fd55f61" +[[package]] +name = "xdg" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546" + [[package]] name = "xdg-home" version = "1.3.0" @@ -5082,6 +5368,12 @@ version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea8b391c9a790b496184c29f7f93b9ed5b16abb306c05415b68bcc16e4d06432" +[[package]] +name = "xmlwriter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" + [[package]] name = "yansi" version = "1.0.1" @@ -5238,6 +5530,15 @@ dependencies = [ "syn 2.0.92", ] +[[package]] +name = "zune-inflate" +version = "0.2.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02" +dependencies = [ + "simd-adler32", +] + [[package]] name = "zvariant" version = "4.2.0" diff --git a/Cargo.toml b/Cargo.toml index de6a2e9..b2f7292 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ description = "A shell for a computadora" [dependencies] clap = { version = "4.5.20", features = ["debug", "derive"] } -iced = { version = "0.13", features = ["tokio", "advanced"]} +iced = { version = "0.13.1", features = ["tokio", "advanced", "svg", "image", "wgpu"]} iced_runtime = { version = "0.13", features = [ "multi-window" ] } miette = { version = "7.2.0", features = ["fancy"] } pretty_assertions = "1.4.1" @@ -24,4 +24,5 @@ chrono = "0.4.39" sysinfo = "0.35.0" hyprland = { git = "https://github.com/hyprland-community/hyprland-rs", branch = "master" } system-tray = "0.7.0" +freedesktop-icons = "0.4.0" diff --git a/src/main.rs b/src/main.rs index c390d54..1032ae6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,15 +2,18 @@ use std::cmp; use std::collections::HashMap; use std::fmt::Display; use std::fs::read_to_string; +use std::path::PathBuf; use chrono::prelude::*; +use freedesktop_icons::lookup; use hyprland::data::{Client, Workspace, Workspaces}; use hyprland::event_listener::{self, AsyncEventListener}; use hyprland::shared::{HyprData, HyprDataActiveOptional, HyprDataVec}; use iced::font::Weight; use iced::futures::SinkExt; use iced::stream; -use iced::widget::{container, horizontal_space, row, text}; +use iced::widget::image::Handle; +use iced::widget::{container, horizontal_space, image, row, svg, text}; use iced::{ time, Background, Border, Color, Element, Event, Font, Length, Shadow, Subscription, Task, Vector, @@ -82,6 +85,8 @@ struct Panel { workspaces: Vec, active_workspace: i32, active_window: String, + active_window_icon_svg: Option, + active_window_icon_raster: Option, system_tray: Option, apps: Vec, } @@ -94,7 +99,7 @@ enum Message { IcedEvent(Event), WorkspaceChange(Vec), ActiveWorkspaceChange(event_listener::WorkspaceEventData), - ActiveWindowChange(String), + ActiveWindowChange((String, String)), } impl Panel { @@ -103,7 +108,17 @@ impl Panel { error!("Couldn't get hyprland info: {}", e); e }); - let active_window = Client::get_active().unwrap().unwrap().title; + let client = Client::get_active().unwrap().unwrap(); + let icon = lookup(&client.class) + .with_theme("Papirus Dark") + .with_cache() + .find(); + let active_window_icon_svg = icon + .clone() + .filter(|icon| icon.ends_with("svg")) + .map(|icon| svg::Handle::from_path(icon)); + let active_window_icon_raster = icon.map(|icon| image::Handle::from_path(icon)); + let active_window = client.title; let battery = match Battery::get() { Ok(b) => Some(b), Err(e) => { @@ -123,6 +138,8 @@ impl Panel { disk: String::new(), apps: vec![String::new()], active_window, + active_window_icon_svg, + active_window_icon_raster, battery, system_tray: None, }, @@ -185,7 +202,21 @@ impl Panel { self.active_workspace = data.id; } Message::ActiveWindowChange(w) => { - self.active_window = w; + debug!(?w); + self.active_window = w.0; + let icon = lookup(&w.1) + .with_theme("Papirus-Dark") + .force_svg() + .with_size(16) + .find(); + debug!(?icon); + self.active_window_icon_raster = icon + .clone() + .filter(|icon| !icon.ends_with("svg")) + .map(|icon| image::Handle::from_path(icon)); + self.active_window_icon_svg = icon + .filter(|icon| icon.ends_with("svg")) + .map(|icon| svg::Handle::from_path(icon)); } _ => unreachable!(), } @@ -221,7 +252,10 @@ impl Panel { if let Ok(window) = Client::get_active_async().await { if let Some(w) = window { sender - .send(Message::ActiveWindowChange(w.title.trim().to_owned())) + .send(Message::ActiveWindowChange(( + w.title.trim().to_owned(), + w.initial_class.trim().to_owned(), + ))) .await .unwrap_or_else(|e| { error!("Trying to send window failed with err: {e}"); @@ -236,8 +270,12 @@ impl Panel { let mut sender = senderx.clone(); Box::pin(async move { if let Some(data) = data { + let client = Client::get_active().unwrap().unwrap(); sender - .send(Message::ActiveWindowChange(data.title)) + .send(Message::ActiveWindowChange(( + client.title, + client.initial_class, + ))) .await .unwrap(); } @@ -310,6 +348,18 @@ impl Panel { .collect(); let workspaces = row(workspaces).spacing(20).padding([0, 5]); + let icon: Element; + if let Some(handle) = &self.active_window_icon_raster { + icon = image(handle).into(); + } else { + if let Some(handle) = &self.active_window_icon_svg { + icon = svg(handle.clone()).width(24).height(24).into(); + } else { + icon = image("/home/chris/pics/wojaks/reddit_the_xenomorph_s bigass wojak folder/Chads/ChristianChad.png").into(); + } + } + let icon = container(icon).padding(4); + let window = text!("{}", self.active_window).color(Color::parse("#57c7ff").unwrap()); let disk = text!("{}", self.disk).color(Color::parse("#ff9f43").unwrap()); let mem = text!("{}", self.memory).color(Color::parse("#f3f99d").unwrap()); @@ -339,7 +389,7 @@ impl Panel { .color(Color::parse("#ff6ac1").unwrap()); let row = row!( - container(row!(workspaces, window, horizontal_space()).spacing(10)), + container(row!(workspaces, icon, window, horizontal_space()).spacing(10)), container(clock), container(row!(horizontal_space(), disk, cpu, mem, battery).spacing(5)) )