a man needs a maid
This commit is contained in:
parent
e191d600ce
commit
4161bdb411
8 changed files with 2 additions and 71 deletions
|
|
@ -33,9 +33,7 @@ pub struct ScriptConf {
|
|||
}
|
||||
#[derive(Serialize,Deserialize,Clone,Debug)]
|
||||
pub struct Config {
|
||||
// pub title_length: Option<usize>,
|
||||
pub preserve_keyboard_order: bool,
|
||||
// pub initial_workspace: Option<usize>,
|
||||
pub window_icons: Vec<WindowIcon>,
|
||||
pub programs: HashMap<String, Programs>,
|
||||
pub lock: LockConf,
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@ pub fn profile_info(profiles: Vec<Profile>,info: ProfileGetCommand) -> String {
|
|||
match info {
|
||||
ProfileGetCommand::Json => json!(active_profile).to_string(),
|
||||
ProfileGetCommand::Name => active_profile.name,
|
||||
ProfileGetCommand::Icon => active_profile.icon,
|
||||
//ProfileGetCommand::Shortcuts => json!(active_profile.scripts).to_string(),
|
||||
ProfileGetCommand::Icon => active_profile.icon
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,13 +94,11 @@ pub fn lock(lock_config: LockConf,force_bg_render: bool) -> Result<(),SDUError>
|
|||
}
|
||||
|
||||
pub fn generate_image(orig_img_data: DynamicImage,gen_image_path: PathBuf, lock_conf: LockConf) {// Result<(), ImageError> {
|
||||
//let img_data = image::open(image_path).unwrap();
|
||||
let w = orig_img_data.width() as f32 * lock_conf.scale;
|
||||
let h = orig_img_data.height() as f32 * lock_conf.scale;
|
||||
let blurred_img_data = orig_img_data
|
||||
.resize(w as u32, h as u32, image::imageops::FilterType::Nearest)
|
||||
.blur_advanced(GaussianBlurParameters::new_from_sigma(lock_conf.blur));
|
||||
//let gen_image_path = cache_dir.clone().unwrap().join(format!("sway-profiles-rs/lock/{}.jpg",output.name));
|
||||
match blurred_img_data.save(gen_image_path) {
|
||||
Ok(_) => println!("Image saved successfully"),
|
||||
Err(e) => println!("error: {:?}",e),
|
||||
|
|
|
|||
|
|
@ -20,13 +20,10 @@ use {
|
|||
};
|
||||
|
||||
pub fn profile(profile_command: &ProfileCommand, profiles_config: Vec<Profile>, preserve_keyboard_order: bool) -> Result<(),SDUError> {
|
||||
// debug!("{:?}",xdg_directories.get_runtime_directory());
|
||||
let xdg_dirs = get_xdg_dirs();
|
||||
setup_runtime_dir(xdg_dirs);
|
||||
match profile_command {
|
||||
ProfileCommand::Init => {
|
||||
//let index_start = if config.preserve_keyboard_order { 1 } else { 0 };
|
||||
//debug!("profile index will start at {}",index_start);
|
||||
let active_profile_index = active_profile_index();
|
||||
match switch_by_index(profiles_config, active_profile_index, preserve_keyboard_order) {
|
||||
Ok(_) => {
|
||||
|
|
@ -100,15 +97,12 @@ pub fn profile(profile_command: &ProfileCommand, profiles_config: Vec<Profile>,
|
|||
}
|
||||
|
||||
pub fn initialize(mut sway_connection: Connection, profile: Profile,uindex: usize, preserve_keyboard_order: bool) -> Result<(),SDUError> { //payload: String) {
|
||||
//let payload = "bindsym $mod+{} workspace number {}{}:{}";
|
||||
// let profile_initial_workspace: usize = if preserve_keyboard_order { 1 } else { 0 };
|
||||
for i in 0..10 {
|
||||
let workspace = (uindex*10) + match i.eq(&0) && !preserve_keyboard_order {
|
||||
true => 10,
|
||||
false => i,
|
||||
};
|
||||
debug!("key {}: workspace {}",i,workspace);
|
||||
//debug!("profile index: {}, uindex: {}",profile_index,uindex);
|
||||
debug!("bindsym $mod+{} workspace number {}:{}",i,workspace,profile.icon);
|
||||
|
||||
match run_sway_command(&mut sway_connection, format!("bindsym $mod+{} workspace number {}:{}",i,workspace,profile.icon)) {
|
||||
|
|
@ -135,8 +129,7 @@ pub fn initialize(mut sway_connection: Connection, profile: Profile,uindex: usiz
|
|||
}
|
||||
|
||||
pub fn profile_from_index(profiles: Vec<Profile>, index: usize) -> Profile {
|
||||
profiles.get(index).expect("Profile not found for index").clone() // {
|
||||
// Some(p) => Ok(p.clone())
|
||||
profiles.get(index).expect("Profile not found for index").clone()
|
||||
}
|
||||
|
||||
pub fn _profile_from_name(config: Config, name: String) -> Result<Profile,SDUError> {
|
||||
|
|
@ -173,45 +166,14 @@ pub fn switch_by_name(profiles_config: Vec<Profile>,name: String,preserve_keyboa
|
|||
pub fn active_profile_index() -> usize {
|
||||
let base_directories = BaseDirectories::new();
|
||||
let active_profile_cache_json = base_directories.get_runtime_directory().expect("xdg dirs do not exist?").join("sway-desktop-utils/active-profile.json");
|
||||
/* match active_profile_cache_json.exists().then(|| fs::File::open(active_profile_cache_json).and_then(|f| Ok(serde_json::from_reader::<fs::File,usize>(f)))) {
|
||||
Some(a) => todo!(),
|
||||
None => todo!(),
|
||||
} */
|
||||
/* Ok(u) => {
|
||||
Ok(u)
|
||||
},
|
||||
Err(_) => Err(ErrorMessage { message: "could not parse json from active profile cache file".to_string(), code: 3 }),
|
||||
Err(_) => Err(ErrorMessage { message: "could not open active profile cache file".to_string(), code: 3 }),
|
||||
} */
|
||||
if active_profile_cache_json.exists() {
|
||||
fs::File::open(active_profile_cache_json).ok()
|
||||
.and_then(|f|serde_json::from_reader::<fs::File,usize>(f).ok())
|
||||
.expect("could not parse active profile cache file")
|
||||
//serde_json::from_reader::<fs::File,usize>(cache_json_reader).expect("could not parse json from active profile cache file")
|
||||
// let cache_json_reader = fs::File::open(active_profile_cache_json).expect("could not open active profile cache file");
|
||||
// serde_json::from_reader::<fs::File,usize>(cache_json_reader).expect("could not parse json from active profile cache file")
|
||||
} else {
|
||||
error!("no active profile cache file");
|
||||
0
|
||||
}
|
||||
/* match fs::File::open(active_profile_cache_json) {
|
||||
Ok(f) => {
|
||||
match serde_json::from_reader::<fs::File,usize>(f) {
|
||||
Ok(u) => {
|
||||
Ok(u)
|
||||
},
|
||||
Err(_) => Err(ErrorMessage { message: "could not parse json from active profile cache file".to_string(), code: 3 }),
|
||||
}
|
||||
},
|
||||
Err(_) => Err(ErrorMessage { message: "could not open active profile cache file".to_string(), code: 3 }),
|
||||
} */
|
||||
// )
|
||||
/* {
|
||||
true => {
|
||||
|
||||
},
|
||||
false => Err(ErrorMessage { message: "no active profile cache file".to_string(), code: 3 }),
|
||||
} */
|
||||
}
|
||||
|
||||
pub fn active_profile(profiles: Vec<Profile>) -> Result<Profile,SDUError> {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ pub fn monitor_events(event_type: Vec<EventType>, get_command: &SwayGetCommand,
|
|||
SwayGetCommand::Full => get_sway_info(window_icons),
|
||||
}
|
||||
},
|
||||
//swayipc::Event::Tick(_) => todo!(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
println!("{}",sway_json);
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@ use {
|
|||
crate::config::WindowIcon,
|
||||
};
|
||||
|
||||
/*#[derive(serde::Serialize)]
|
||||
pub struct WindowContext {
|
||||
pub window_count: usize,
|
||||
pub
|
||||
}*/
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct WindowInfo {
|
||||
pub title: String,
|
||||
|
|
@ -22,16 +17,6 @@ pub struct WindowInfo {
|
|||
pub fn get_window_info(window_icons: &[WindowIcon]) -> Value {
|
||||
let mut sway_connection = Connection::new().expect("Unable to connect to sway ipc socket");
|
||||
let nodes_tree = sway_connection.get_tree().expect("Unable to parse Sway node tree");
|
||||
/* RETRIEVING NODE LAYOUT
|
||||
for output in nodes_tree.nodes.iter() {
|
||||
println!("|({:#?}) {:#?}", output.node_type, output.name.clone().unwrap());
|
||||
for workspace in output.nodes.iter() {
|
||||
println!("||({:#?}) {}", workspace.node_type, workspace.name.clone().unwrap());
|
||||
println!("|||Children: {:#?}",workspace.iter().filter(|x|(x.node_type.eq(&swayipc::NodeType::Con) || x.node_type.eq(&swayipc::NodeType::FloatingCon)) && x.name.is_some()).count());
|
||||
println!("|||Focused: {:#?}",workspace.iter().find(|x|x.focused).is_some());
|
||||
}
|
||||
}
|
||||
*/
|
||||
let focused_workspace_raw = nodes_tree.iter()
|
||||
.find(|x|x.node_type.eq(&swayipc::NodeType::Workspace) && x.iter().any(|x|x.focused));
|
||||
let window_count = match focused_workspace_raw {
|
||||
|
|
@ -59,6 +44,4 @@ pub fn get_window_info(window_icons: &[WindowIcon]) -> Value {
|
|||
};
|
||||
let window_info = WindowInfo { title: window_title.unwrap_or_default(), window_count};
|
||||
json!(window_info)
|
||||
// let window_output = json!(window_info);
|
||||
// window_output.to_string()
|
||||
}
|
||||
|
|
@ -30,6 +30,4 @@ pub fn get_workspace_info() -> Value {
|
|||
}
|
||||
workspaces_info.sort_by(|a, b| a.num.cmp(&b.num));
|
||||
json!(workspaces_info)
|
||||
// let workspace_output = json!(workspaces_info);
|
||||
// workspace_output.to_string()
|
||||
}
|
||||
|
|
@ -58,11 +58,6 @@ pub struct SDUError {
|
|||
message: String
|
||||
}
|
||||
|
||||
/*pub fn error_handler(error: ErrorMessage) {
|
||||
debug!("ERROR: {}",error.message);
|
||||
exit(error.code)
|
||||
}*/
|
||||
|
||||
pub fn setup_runtime_dir(xdg_directories: BaseDirectories) {
|
||||
match xdg_directories.create_runtime_directory("sway-desktop-utils") {
|
||||
Ok(_) => debug!("created runtime directories"),
|
||||
|
|
@ -76,7 +71,6 @@ pub fn get_xdg_dirs() -> BaseDirectories {
|
|||
|
||||
fn main() -> Result<(),()> {
|
||||
env_logger::init();
|
||||
// let xdg_directories = BaseDirectories::new();
|
||||
let cli = Cli::parse();
|
||||
let config = if confy::get_configuration_file_path("sway-desktop-utils", "config").expect("Unable to determine config file location").exists() {
|
||||
confy::load("sway-desktop-utils", "config").unwrap_or_default()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue