backup 2025-10-01
This commit is contained in:
parent
38e5d317f8
commit
cb40f72c6a
7 changed files with 158 additions and 31 deletions
102
Cargo.lock
generated
102
Cargo.lock
generated
|
@ -17,6 +17,15 @@ version = "2.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aligned-vec"
|
||||
version = "0.6.4"
|
||||
|
@ -439,6 +448,29 @@ version = "1.15.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "env_filter"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0"
|
||||
dependencies = [
|
||||
"log",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.11.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"env_filter",
|
||||
"jiff",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equator"
|
||||
version = "0.4.2"
|
||||
|
@ -818,6 +850,30 @@ version = "1.0.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "jiff"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be1f93b8b1eb69c77f24bbb0afdf66f54b632ee39af40ca21c4365a1d7347e49"
|
||||
dependencies = [
|
||||
"jiff-static",
|
||||
"log",
|
||||
"portable-atomic",
|
||||
"portable-atomic-util",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jiff-static"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.34"
|
||||
|
@ -1155,6 +1211,21 @@ dependencies = [
|
|||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic-util"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"
|
||||
dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.21"
|
||||
|
@ -1356,6 +1427,35 @@ dependencies = [
|
|||
"thiserror 2.0.16",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b5288124840bee7b386bc413c487869b360b2b4ec421ea56425128692f2a82c"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "833eb9ce86d40ef33cb1306d8accf7bc8ec2bfea4355cbdebb3df68b40925cad"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001"
|
||||
|
||||
[[package]]
|
||||
name = "rgb"
|
||||
version = "0.8.52"
|
||||
|
@ -1514,7 +1614,9 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"clap",
|
||||
"confy",
|
||||
"env_logger",
|
||||
"image",
|
||||
"log",
|
||||
"miette",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
|
|
@ -6,7 +6,9 @@ edition = "2024"
|
|||
[dependencies]
|
||||
clap = { version = "4.5.45", features = ["derive"] }
|
||||
confy = "1.0.0"
|
||||
env_logger = "0.11.8"
|
||||
image = "0.25.8"
|
||||
log = "0.4.28"
|
||||
miette = "7.6.0"
|
||||
serde = "1.0.219"
|
||||
serde_json = "1.0.142"
|
||||
|
|
|
@ -11,6 +11,7 @@ pub struct Profile {
|
|||
pub name: String,
|
||||
pub icon: String,
|
||||
pub program_args: Option<HashMap<String, Vec<String>>>,
|
||||
pub scripts: Option<Vec<ScriptConf>>
|
||||
}
|
||||
#[derive(Serialize,Deserialize,Clone,Debug)]
|
||||
pub struct Programs {
|
||||
|
@ -24,11 +25,17 @@ pub struct LockConf {
|
|||
pub blur: f32,
|
||||
pub scale: f32,
|
||||
}
|
||||
#[derive(Serialize,Deserialize,Clone,Debug)]
|
||||
pub struct ScriptConf {
|
||||
pub name: String,
|
||||
pub icon: String,
|
||||
pub command: String
|
||||
}
|
||||
#[derive(Serialize,Deserialize,Clone,Default)]
|
||||
pub struct Config {
|
||||
pub title_length: Option<usize>,
|
||||
pub window_icons: Vec<WindowIcon>,
|
||||
pub programs: HashMap<String, Programs>,
|
||||
pub lock: LockConf,
|
||||
pub profiles: Vec<Profile>
|
||||
pub profiles: Vec<Profile>,
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
use std::time::Instant;
|
||||
|
||||
use swayipc::{Connection, EventType};
|
||||
use crate::{config::Config, windows::print_window_title, workspaces::print_workspace_array, Cli, ErrorMessage};
|
||||
use crate::{config::Config, windows::print_window_info, workspaces::print_workspace_info, Cli, ErrorMessage};
|
||||
|
||||
pub fn run_sway_command(sway_connection: &mut Connection,payload: String) -> Result<(),ErrorMessage> {
|
||||
match sway_connection.run_command(&payload) {
|
||||
|
@ -14,12 +16,28 @@ pub fn run_sway_command(sway_connection: &mut Connection,payload: String) -> Res
|
|||
pub fn monitor_events(event_type: Vec<EventType>, cli: Cli, config: Config) {
|
||||
let sway_connection = Connection::new().unwrap();
|
||||
for event in sway_connection.subscribe(event_type).unwrap() {
|
||||
let start = Instant::now();
|
||||
let e = event.unwrap();
|
||||
match e {
|
||||
swayipc::Event::Window(w) => print_window_title(w.container, &cli, &config),
|
||||
swayipc::Event::Workspace(_) => print_workspace_array(self::Connection::get_workspaces(&mut self::Connection::new().unwrap()).unwrap()),
|
||||
swayipc::Event::Window(w) => {
|
||||
print_window_info(w.container, &cli, &config)
|
||||
},
|
||||
swayipc::Event::Workspace(_) => {
|
||||
match cli.command {
|
||||
crate::Commands::Windows => {
|
||||
let mut con = Connection::new().unwrap();
|
||||
print_window_info(con.get_tree().unwrap().find(|x|x.focused).unwrap(), &cli, &config)
|
||||
},
|
||||
crate::Commands::Workspaces => {
|
||||
let mut con = Connection::new().unwrap();
|
||||
print_workspace_info(con.get_workspaces().unwrap())
|
||||
},
|
||||
_ => todo!(),
|
||||
}
|
||||
},
|
||||
swayipc::Event::Tick(_) => todo!(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
log::debug!("time taken: {:?}",start.elapsed());
|
||||
}
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
use serde_json::json;
|
||||
use swayipc::Node;
|
||||
use swayipc::{Connection, Node};
|
||||
use crate::{config::Config, Cli, ErrorMessage};
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct WindowInfo {
|
||||
pub title: String
|
||||
pub title: String,
|
||||
pub window_count: usize
|
||||
}
|
||||
|
||||
pub fn get_window_name(window_node: Node, cli: &Cli, config: &Config) -> Result<String,ErrorMessage> {
|
||||
// println!("{:#?}",window_node);
|
||||
match window_node.name {
|
||||
Some(mut window_title) => {
|
||||
for pair in config.window_icons.clone() {
|
||||
|
@ -29,19 +29,14 @@ pub fn get_window_name(window_node: Node, cli: &Cli, config: &Config) -> Result<
|
|||
}
|
||||
}
|
||||
|
||||
pub fn print_window_title(window_node: Node,cli: &Cli,config: &Config) {
|
||||
// let mut window_title_display: String = window_node.name.unwrap();
|
||||
/* for pair in &config.window_icons {
|
||||
if window_title_display.contains(&pair.substring) {
|
||||
window_title_display = pair.icon.clone() + " " + &window_title_display.replace(&pair.substring, "");
|
||||
}
|
||||
}
|
||||
if !cli.no_truncate_title.unwrap() && window_title_display.chars().count().gt(&config.title_length) {
|
||||
let trunc_point = window_title_display.char_indices().map(|(i, _)| i).nth(config.title_length).unwrap_or(window_title_display.chars().count());
|
||||
window_title_display.truncate(trunc_point);
|
||||
let _ = window_title_display.write_char('…');
|
||||
} */
|
||||
let window_info = WindowInfo { title: get_window_name(window_node, cli, config).unwrap() };
|
||||
pub fn print_window_info(window_node: Node,cli: &Cli,config: &Config) {
|
||||
let mut sc = Connection::new().unwrap();
|
||||
let window_count = sc.get_workspaces().unwrap().iter().find(|x|x.focused).unwrap().focus.len();
|
||||
let window_title = match window_count.gt(&0) {
|
||||
true => get_window_name(window_node, cli, config).unwrap(),
|
||||
false => "".to_string(),
|
||||
};
|
||||
let window_info = WindowInfo { title: window_title, window_count};
|
||||
let window_output = json!(window_info);
|
||||
println!("{}",window_output)
|
||||
println!("{}",window_output);
|
||||
}
|
|
@ -9,7 +9,7 @@ pub struct WorkspaceInfo {
|
|||
pub position: char
|
||||
}
|
||||
|
||||
pub fn print_workspace_array(workspaces: Vec<Workspace>) {
|
||||
pub fn print_workspace_info(workspaces: Vec<Workspace>) {
|
||||
let current_ws = workspaces.iter().find(|&x| x.focused).unwrap().num;
|
||||
let mut workspaces_info: Vec<WorkspaceInfo> = vec![];
|
||||
for workspace in workspaces {
|
||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -1,6 +1,6 @@
|
|||
#![warn(unused_crate_dependencies)]
|
||||
|
||||
use std::process::exit;
|
||||
use std::{process::exit, time::Instant};
|
||||
|
||||
use clap::{ArgAction, Parser, Subcommand};
|
||||
use swayipc::{Connection, EventType, Fallible};
|
||||
|
@ -8,10 +8,10 @@ use swayipc::{Connection, EventType, Fallible};
|
|||
mod config;
|
||||
#[path = "lib/windows.rs"]
|
||||
mod windows;
|
||||
use windows::print_window_title;
|
||||
use windows::print_window_info;
|
||||
#[path = "lib/workspaces.rs"]
|
||||
mod workspaces;
|
||||
use workspaces::print_workspace_array;
|
||||
use workspaces::print_workspace_info;
|
||||
#[path = "lib/lock.rs"]
|
||||
mod lock;
|
||||
use lock::lock_screen;
|
||||
|
@ -144,18 +144,19 @@ pub struct ErrorMessage {
|
|||
}
|
||||
|
||||
pub fn error_handler(error: ErrorMessage) {
|
||||
println!("ERROR: {}",error.message);
|
||||
log::debug!("ERROR: {}",error.message);
|
||||
exit(error.code)
|
||||
}
|
||||
|
||||
pub fn setup_runtime_dir(xdg_directories: BaseDirectories) {
|
||||
match xdg_directories.create_runtime_directory("sway-profiles-rs") {
|
||||
Ok(_) => println!("success"),
|
||||
Err(_) => println!("failed"),
|
||||
Ok(_) => log::debug!("success"),
|
||||
Err(_) => log::debug!("failed"),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Fallible<()> {
|
||||
env_logger::init();
|
||||
let xdg_directories = BaseDirectories::new();
|
||||
let cli = Cli::parse();
|
||||
let config = confy::load("sway-profiles-rs", "config").unwrap();
|
||||
|
@ -163,13 +164,15 @@ fn main() -> Fallible<()> {
|
|||
let mut sway_connection = Connection::new()?;
|
||||
match &cli.command {
|
||||
Commands::Windows => {
|
||||
print_window_title(sway_connection.get_tree().unwrap().iter().find(|&x | x.focused).unwrap().clone(), &cli, &config);
|
||||
let start = Instant::now();
|
||||
print_window_info(sway_connection.get_tree().unwrap().iter().find(|&x | x.focused).unwrap().clone(), &cli, &config);
|
||||
log::debug!("time taken: {:?}",start.elapsed());
|
||||
if cli.monitor.unwrap() {
|
||||
sway::monitor_events(vec![EventType::Window,EventType::Workspace], cli, config);
|
||||
}
|
||||
}
|
||||
Commands::Workspaces => {
|
||||
print_workspace_array(sway_connection.get_workspaces().unwrap());
|
||||
print_workspace_info(sway_connection.get_workspaces().unwrap());
|
||||
if cli.monitor.unwrap() {
|
||||
sway::monitor_events(vec![EventType::Workspace], cli, config);
|
||||
}
|
||||
|
@ -193,7 +196,7 @@ fn main() -> Fallible<()> {
|
|||
};
|
||||
},
|
||||
Commands::Profile { profile_command} => {
|
||||
println!("{:?}",xdg_directories.get_runtime_directory());
|
||||
log::debug!("{:?}",xdg_directories.get_runtime_directory());
|
||||
setup_runtime_dir(xdg_directories.clone());
|
||||
match profile_command {
|
||||
ProfileCommand::Init => {
|
||||
|
|
Loading…
Add table
Reference in a new issue