Improve CLI
This commit is contained in:
		
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@@ -379,7 +379,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			|||||||
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
 | 
					checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "winresutil"
 | 
					name = "winres"
 | 
				
			||||||
version = "0.1.0"
 | 
					version = "0.1.0"
 | 
				
			||||||
dependencies = [
 | 
					dependencies = [
 | 
				
			||||||
 "clap",
 | 
					 "clap",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
[package]
 | 
					[package]
 | 
				
			||||||
name = "winresutil"
 | 
					name = "winresz"
 | 
				
			||||||
version = "0.1.0"
 | 
					version = "0.1.0"
 | 
				
			||||||
edition = "2021"
 | 
					edition = "2021"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										48
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -38,45 +38,33 @@ fn filter_target_windows(hwnd: &HWND, q: &TargetInformation) -> bool {
 | 
				
			|||||||
    true
 | 
					    true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn window_callback(hwnd: HWND, op: &Commands) {
 | 
					fn window_callback(hwnd: HWND, op: &Cli) {
 | 
				
			||||||
    let t = match op {
 | 
					    if !filter_target_windows(&hwnd, &op.target) {
 | 
				
			||||||
        Commands::Get { target } => target,
 | 
					 | 
				
			||||||
        Commands::Set {
 | 
					 | 
				
			||||||
            target,
 | 
					 | 
				
			||||||
            resolution: _,
 | 
					 | 
				
			||||||
        } => target,
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if !filter_target_windows(&hwnd, t) {
 | 
					 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let client_size = Size::from(hwnd.GetClientRect().unwrap());
 | 
					    let client_size = Size::from(hwnd.GetClientRect().unwrap());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    match op {
 | 
					    let Some(size) = op.size else {
 | 
				
			||||||
        Commands::Get { target: _ } => {
 | 
					        println!("{}\t", client_size - op.target.offset);
 | 
				
			||||||
            println!("{}", client_size - t.offset);
 | 
					        return;
 | 
				
			||||||
        }
 | 
					    };
 | 
				
			||||||
        Commands::Set {
 | 
					 | 
				
			||||||
            target: _,
 | 
					 | 
				
			||||||
            resolution,
 | 
					 | 
				
			||||||
        } => {
 | 
					 | 
				
			||||||
            let window_size = Size::from(hwnd.GetWindowRect().unwrap());
 | 
					 | 
				
			||||||
            let border = window_size - client_size;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            hwnd.SetWindowPos(
 | 
					    let window_size = Size::from(hwnd.GetWindowRect().unwrap());
 | 
				
			||||||
                HwndPlace::None,
 | 
					
 | 
				
			||||||
                POINT::new(0, 0),
 | 
					    let border = window_size - client_size;
 | 
				
			||||||
                (*resolution + t.offset + border).into(),
 | 
					
 | 
				
			||||||
                SWP::NOMOVE,
 | 
					    hwnd.SetWindowPos(
 | 
				
			||||||
            )
 | 
					        HwndPlace::None,
 | 
				
			||||||
            .unwrap();
 | 
					        POINT::new(0, 0),
 | 
				
			||||||
        }
 | 
					        (size + op.target.offset + border).into(),
 | 
				
			||||||
    }
 | 
					        SWP::NOMOVE,
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    .unwrap();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn main() {
 | 
					fn main() {
 | 
				
			||||||
    let c = Cli::parse().command;
 | 
					    let c = Cli::parse();
 | 
				
			||||||
    EnumWindows(|hwnd: HWND| -> bool {
 | 
					    EnumWindows(|hwnd: HWND| -> bool {
 | 
				
			||||||
        window_callback(hwnd, &c);
 | 
					        window_callback(hwnd, &c);
 | 
				
			||||||
        true
 | 
					        true
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										28
									
								
								src/model.rs
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								src/model.rs
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
use clap::{Args, Parser, Subcommand};
 | 
					use clap::{Args, Parser};
 | 
				
			||||||
use std::fmt::{self, Display};
 | 
					use std::fmt::{self, Display};
 | 
				
			||||||
use std::io::{Error, ErrorKind};
 | 
					use std::io::{Error, ErrorKind};
 | 
				
			||||||
use std::ops::{Add, Sub};
 | 
					use std::ops::{Add, Sub};
 | 
				
			||||||
@@ -6,32 +6,20 @@ use winsafe::{RECT, SIZE};
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Clone, Args)]
 | 
					#[derive(Debug, Clone, Args)]
 | 
				
			||||||
pub struct TargetInformation {
 | 
					pub struct TargetInformation {
 | 
				
			||||||
    #[arg(short, long)]
 | 
					    #[arg(short, long, help = "Filter by binary path")]
 | 
				
			||||||
    pub path_endswith: Vec<String>,
 | 
					    pub path_endswith: Vec<String>,
 | 
				
			||||||
    #[arg(short, long)]
 | 
					    #[arg(short, long, help = "Filter by title")]
 | 
				
			||||||
    pub title_contains: Vec<String>,
 | 
					    pub title_contains: Vec<String>,
 | 
				
			||||||
    #[arg(short, long, value_parser = parse_size, default_value_t = Size::default())]
 | 
					    #[arg(short, long, value_parser = parse_size, default_value_t = Size::default(), help = "Additional offset for window")]
 | 
				
			||||||
    pub offset: Size,
 | 
					    pub offset: Size,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Clone, Subcommand)]
 | 
					 | 
				
			||||||
pub enum Commands {
 | 
					 | 
				
			||||||
    Get {
 | 
					 | 
				
			||||||
        #[command(flatten)]
 | 
					 | 
				
			||||||
        target: TargetInformation,
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    Set {
 | 
					 | 
				
			||||||
        #[command(flatten)]
 | 
					 | 
				
			||||||
        target: TargetInformation,
 | 
					 | 
				
			||||||
        #[arg(value_parser = parse_size)]
 | 
					 | 
				
			||||||
        resolution: Size,
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[derive(Debug, Parser)]
 | 
					#[derive(Debug, Parser)]
 | 
				
			||||||
pub struct Cli {
 | 
					pub struct Cli {
 | 
				
			||||||
    #[command(subcommand)]
 | 
					    #[command(flatten)]
 | 
				
			||||||
    pub command: Commands,
 | 
					    pub target: TargetInformation,
 | 
				
			||||||
 | 
					    #[arg(value_parser = parse_size, help = "Set the window size if it's set.")]
 | 
				
			||||||
 | 
					    pub size: Option<Size>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Copy, Clone, Parser)]
 | 
					#[derive(Debug, Copy, Clone, Parser)]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user