trying to add icons
This commit is contained in:
parent
42fdbe5df1
commit
73957b1370
3 changed files with 364 additions and 12 deletions
64
src/main.rs
64
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<Workspace>,
|
||||
active_workspace: i32,
|
||||
active_window: String,
|
||||
active_window_icon_svg: Option<svg::Handle>,
|
||||
active_window_icon_raster: Option<Handle>,
|
||||
system_tray: Option<SystemTray>,
|
||||
apps: Vec<String>,
|
||||
}
|
||||
|
@ -94,7 +99,7 @@ enum Message {
|
|||
IcedEvent(Event),
|
||||
WorkspaceChange(Vec<Workspace>),
|
||||
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<Message>;
|
||||
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))
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue