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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
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]]
|
[[package]]
|
||||||
name = "aligned-vec"
|
name = "aligned-vec"
|
||||||
version = "0.6.4"
|
version = "0.6.4"
|
||||||
|
@ -439,6 +448,29 @@ version = "1.15.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
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]]
|
[[package]]
|
||||||
name = "equator"
|
name = "equator"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
|
@ -818,6 +850,30 @@ version = "1.0.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
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]]
|
[[package]]
|
||||||
name = "jobserver"
|
name = "jobserver"
|
||||||
version = "0.1.34"
|
version = "0.1.34"
|
||||||
|
@ -1155,6 +1211,21 @@ dependencies = [
|
||||||
"miniz_oxide",
|
"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]]
|
[[package]]
|
||||||
name = "ppv-lite86"
|
name = "ppv-lite86"
|
||||||
version = "0.2.21"
|
version = "0.2.21"
|
||||||
|
@ -1356,6 +1427,35 @@ dependencies = [
|
||||||
"thiserror 2.0.16",
|
"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]]
|
[[package]]
|
||||||
name = "rgb"
|
name = "rgb"
|
||||||
version = "0.8.52"
|
version = "0.8.52"
|
||||||
|
@ -1514,7 +1614,9 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"confy",
|
"confy",
|
||||||
|
"env_logger",
|
||||||
"image",
|
"image",
|
||||||
|
"log",
|
||||||
"miette",
|
"miette",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
|
@ -6,7 +6,9 @@ edition = "2024"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.45", features = ["derive"] }
|
clap = { version = "4.5.45", features = ["derive"] }
|
||||||
confy = "1.0.0"
|
confy = "1.0.0"
|
||||||
|
env_logger = "0.11.8"
|
||||||
image = "0.25.8"
|
image = "0.25.8"
|
||||||
|
log = "0.4.28"
|
||||||
miette = "7.6.0"
|
miette = "7.6.0"
|
||||||
serde = "1.0.219"
|
serde = "1.0.219"
|
||||||
serde_json = "1.0.142"
|
serde_json = "1.0.142"
|
||||||
|
|
|
@ -11,6 +11,7 @@ pub struct Profile {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
pub program_args: Option<HashMap<String, Vec<String>>>,
|
pub program_args: Option<HashMap<String, Vec<String>>>,
|
||||||
|
pub scripts: Option<Vec<ScriptConf>>
|
||||||
}
|
}
|
||||||
#[derive(Serialize,Deserialize,Clone,Debug)]
|
#[derive(Serialize,Deserialize,Clone,Debug)]
|
||||||
pub struct Programs {
|
pub struct Programs {
|
||||||
|
@ -24,11 +25,17 @@ pub struct LockConf {
|
||||||
pub blur: f32,
|
pub blur: f32,
|
||||||
pub scale: 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)]
|
#[derive(Serialize,Deserialize,Clone,Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub title_length: Option<usize>,
|
pub title_length: Option<usize>,
|
||||||
pub window_icons: Vec<WindowIcon>,
|
pub window_icons: Vec<WindowIcon>,
|
||||||
pub programs: HashMap<String, Programs>,
|
pub programs: HashMap<String, Programs>,
|
||||||
pub lock: LockConf,
|
pub lock: LockConf,
|
||||||
pub profiles: Vec<Profile>
|
pub profiles: Vec<Profile>,
|
||||||
}
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
use swayipc::{Connection, EventType};
|
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> {
|
pub fn run_sway_command(sway_connection: &mut Connection,payload: String) -> Result<(),ErrorMessage> {
|
||||||
match sway_connection.run_command(&payload) {
|
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) {
|
pub fn monitor_events(event_type: Vec<EventType>, cli: Cli, config: Config) {
|
||||||
let sway_connection = Connection::new().unwrap();
|
let sway_connection = Connection::new().unwrap();
|
||||||
for event in sway_connection.subscribe(event_type).unwrap() {
|
for event in sway_connection.subscribe(event_type).unwrap() {
|
||||||
|
let start = Instant::now();
|
||||||
let e = event.unwrap();
|
let e = event.unwrap();
|
||||||
match e {
|
match e {
|
||||||
swayipc::Event::Window(w) => print_window_title(w.container, &cli, &config),
|
swayipc::Event::Window(w) => {
|
||||||
swayipc::Event::Workspace(_) => print_workspace_array(self::Connection::get_workspaces(&mut self::Connection::new().unwrap()).unwrap()),
|
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!(),
|
swayipc::Event::Tick(_) => todo!(),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
log::debug!("time taken: {:?}",start.elapsed());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,14 +1,14 @@
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use swayipc::Node;
|
use swayipc::{Connection, Node};
|
||||||
use crate::{config::Config, Cli, ErrorMessage};
|
use crate::{config::Config, Cli, ErrorMessage};
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
pub struct WindowInfo {
|
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> {
|
pub fn get_window_name(window_node: Node, cli: &Cli, config: &Config) -> Result<String,ErrorMessage> {
|
||||||
// println!("{:#?}",window_node);
|
|
||||||
match window_node.name {
|
match window_node.name {
|
||||||
Some(mut window_title) => {
|
Some(mut window_title) => {
|
||||||
for pair in config.window_icons.clone() {
|
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) {
|
pub fn print_window_info(window_node: Node,cli: &Cli,config: &Config) {
|
||||||
// let mut window_title_display: String = window_node.name.unwrap();
|
let mut sc = Connection::new().unwrap();
|
||||||
/* for pair in &config.window_icons {
|
let window_count = sc.get_workspaces().unwrap().iter().find(|x|x.focused).unwrap().focus.len();
|
||||||
if window_title_display.contains(&pair.substring) {
|
let window_title = match window_count.gt(&0) {
|
||||||
window_title_display = pair.icon.clone() + " " + &window_title_display.replace(&pair.substring, "");
|
true => get_window_name(window_node, cli, config).unwrap(),
|
||||||
}
|
false => "".to_string(),
|
||||||
}
|
};
|
||||||
if !cli.no_truncate_title.unwrap() && window_title_display.chars().count().gt(&config.title_length) {
|
let window_info = WindowInfo { title: window_title, window_count};
|
||||||
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() };
|
|
||||||
let window_output = json!(window_info);
|
let window_output = json!(window_info);
|
||||||
println!("{}",window_output)
|
println!("{}",window_output);
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@ pub struct WorkspaceInfo {
|
||||||
pub position: char
|
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 current_ws = workspaces.iter().find(|&x| x.focused).unwrap().num;
|
||||||
let mut workspaces_info: Vec<WorkspaceInfo> = vec![];
|
let mut workspaces_info: Vec<WorkspaceInfo> = vec![];
|
||||||
for workspace in workspaces {
|
for workspace in workspaces {
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -1,6 +1,6 @@
|
||||||
#![warn(unused_crate_dependencies)]
|
#![warn(unused_crate_dependencies)]
|
||||||
|
|
||||||
use std::process::exit;
|
use std::{process::exit, time::Instant};
|
||||||
|
|
||||||
use clap::{ArgAction, Parser, Subcommand};
|
use clap::{ArgAction, Parser, Subcommand};
|
||||||
use swayipc::{Connection, EventType, Fallible};
|
use swayipc::{Connection, EventType, Fallible};
|
||||||
|
@ -8,10 +8,10 @@ use swayipc::{Connection, EventType, Fallible};
|
||||||
mod config;
|
mod config;
|
||||||
#[path = "lib/windows.rs"]
|
#[path = "lib/windows.rs"]
|
||||||
mod windows;
|
mod windows;
|
||||||
use windows::print_window_title;
|
use windows::print_window_info;
|
||||||
#[path = "lib/workspaces.rs"]
|
#[path = "lib/workspaces.rs"]
|
||||||
mod workspaces;
|
mod workspaces;
|
||||||
use workspaces::print_workspace_array;
|
use workspaces::print_workspace_info;
|
||||||
#[path = "lib/lock.rs"]
|
#[path = "lib/lock.rs"]
|
||||||
mod lock;
|
mod lock;
|
||||||
use lock::lock_screen;
|
use lock::lock_screen;
|
||||||
|
@ -144,18 +144,19 @@ pub struct ErrorMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_handler(error: ErrorMessage) {
|
pub fn error_handler(error: ErrorMessage) {
|
||||||
println!("ERROR: {}",error.message);
|
log::debug!("ERROR: {}",error.message);
|
||||||
exit(error.code)
|
exit(error.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_runtime_dir(xdg_directories: BaseDirectories) {
|
pub fn setup_runtime_dir(xdg_directories: BaseDirectories) {
|
||||||
match xdg_directories.create_runtime_directory("sway-profiles-rs") {
|
match xdg_directories.create_runtime_directory("sway-profiles-rs") {
|
||||||
Ok(_) => println!("success"),
|
Ok(_) => log::debug!("success"),
|
||||||
Err(_) => println!("failed"),
|
Err(_) => log::debug!("failed"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Fallible<()> {
|
fn main() -> Fallible<()> {
|
||||||
|
env_logger::init();
|
||||||
let xdg_directories = BaseDirectories::new();
|
let xdg_directories = BaseDirectories::new();
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
let config = confy::load("sway-profiles-rs", "config").unwrap();
|
let config = confy::load("sway-profiles-rs", "config").unwrap();
|
||||||
|
@ -163,13 +164,15 @@ fn main() -> Fallible<()> {
|
||||||
let mut sway_connection = Connection::new()?;
|
let mut sway_connection = Connection::new()?;
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
Commands::Windows => {
|
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() {
|
if cli.monitor.unwrap() {
|
||||||
sway::monitor_events(vec![EventType::Window,EventType::Workspace], cli, config);
|
sway::monitor_events(vec![EventType::Window,EventType::Workspace], cli, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Commands::Workspaces => {
|
Commands::Workspaces => {
|
||||||
print_workspace_array(sway_connection.get_workspaces().unwrap());
|
print_workspace_info(sway_connection.get_workspaces().unwrap());
|
||||||
if cli.monitor.unwrap() {
|
if cli.monitor.unwrap() {
|
||||||
sway::monitor_events(vec![EventType::Workspace], cli, config);
|
sway::monitor_events(vec![EventType::Workspace], cli, config);
|
||||||
}
|
}
|
||||||
|
@ -193,7 +196,7 @@ fn main() -> Fallible<()> {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
Commands::Profile { profile_command} => {
|
Commands::Profile { profile_command} => {
|
||||||
println!("{:?}",xdg_directories.get_runtime_directory());
|
log::debug!("{:?}",xdg_directories.get_runtime_directory());
|
||||||
setup_runtime_dir(xdg_directories.clone());
|
setup_runtime_dir(xdg_directories.clone());
|
||||||
match profile_command {
|
match profile_command {
|
||||||
ProfileCommand::Init => {
|
ProfileCommand::Init => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue