currently broken

This commit is contained in:
Penelope Gwen 2025-09-14 12:03:22 -07:00
parent 527977ec8d
commit 9667aae9e2
2 changed files with 42 additions and 37 deletions

View file

@ -1,22 +1,18 @@
use std::{fmt::Write};
use swayipc::WindowEvent;
use crate::config::WindowIcon;
use regex::Regex;
pub fn get_window_title(title_length: usize, window_event: WindowEvent, window_icons: Vec<WindowIcon>) -> String {
let mut window_title = window_event.container.name.unwrap().trim_end().to_string();
// println!("{}")
for pair in window_icons {
println!("{}: {}",pair.icon,pair.substring);
let substring_regex = Regex::new(&pair.substring).unwrap().captures(&window_title);
// if window_title.
println!("{:?}",substring_regex);
if window_title.contains(&pair.substring) {
window_title = pair.icon + " " + &window_title.replace(&pair.substring, "");
}
// window_title.trim();
let pretrunc_window_title = window_title.clone();
}
if window_title.len().gt(&title_length) {
window_title.truncate(title_length);
if window_title.ne(&pretrunc_window_title) {
let _ = window_title.write_str("");
let _ = window_title.write_char('…');
}
window_title
}

View file

@ -10,6 +10,8 @@ use windows::get_window_title;
#[path = "lib/monitor/workspaces.rs"]
mod workspaces;
use workspaces::get_workspace_name;
use crate::config::Config;
mod monitor;
@ -34,8 +36,9 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
/// does testing things
/// Prints the Currently Active Window Title
WindowTitle,
//
Launch,
Lock,
Rename,
@ -71,7 +74,10 @@ fn main() -> Fallible<()> {
}
match &cli.command {
Commands::WindowTitle => {
println!("Print window title")
println!("Print window title");
let sway_connection = Connection::new()?;
sway_connection.get_tree().unwrap();
// println!("{:?}", sway_connection.get_tree().map(op))
}
Commands::Monitor { monitor_type } => {
match monitor_type {
@ -79,32 +85,35 @@ fn main() -> Fallible<()> {
println!("monitoring workspace changes!")
}
MonitorTypes::Windows => {
println!("monitoring window changes!")
println!("monitoring window changes!");
monitor_events(EventType::Window, config);
}
MonitorTypes::Profile => {
println!("monitoring profile changes!")
}
}
}
Commands::Launch => todo!(),
Commands::Lock => todo!(),
Commands::Rename => todo!(),
Commands::Profile => todo!(),
Commands::Shortcuts { global } => todo!(),
}
exit(0);
}
let subs = [
EventType::Workspace,
// EventType::Output,
// EventType::Input,
EventType::Tick,
// EventType::Shutdown,
// EventType::Mode,
EventType::Window,
// EventType::BarStateUpdate,
// EventType::BarConfigUpdate,
// EventType::Binding,
];
pub fn monitor_events(event_type: EventType, config: Config) -> Fallible<()> {
/* let subs = [
// Valid EventTypes: Workspace, Output, Input, Tick, Shutdown, Mode, Window, BarStateUpdate, BarConfigUpdate, Binding
//EventType::Workspace,
//EventType::Tick,
//EventType::Window,
event_type
]; */
let sway_connection = Connection::new()?;
// for event in Connection::new()?.subscribe(subs)? {
for event in sway_connection.subscribe(subs)? {
for event in sway_connection.subscribe([event_type])? {
let e = event?;
// println!("{:?}\n", e);
match e {