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

View file

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