Compare commits
4 Commits
91d6c2be29
...
659f2c8e5e
Author | SHA1 | Date | |
---|---|---|---|
659f2c8e5e | |||
78a4f8b75e | |||
163da695e8 | |||
4aac16093c |
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -379,7 +379,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
||||
|
||||
[[package]]
|
||||
name = "winresutil"
|
||||
name = "winresz"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "winresutil"
|
||||
name = "winresz"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
|
58
src/main.rs
58
src/main.rs
|
@ -14,7 +14,10 @@ fn filter_target_windows(hwnd: &HWND, q: &TargetInformation) -> bool {
|
|||
return false;
|
||||
};
|
||||
|
||||
if q.title_contains.iter().all(|s| !title.contains(s)) {
|
||||
if q.title_contains
|
||||
.iter()
|
||||
.all(|s| !title.to_ascii_lowercase().contains(&s.to_ascii_lowercase()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +33,10 @@ fn filter_target_windows(hwnd: &HWND, q: &TargetInformation) -> bool {
|
|||
return false;
|
||||
};
|
||||
|
||||
if q.path_endswith.iter().all(|s| !path.ends_with(s)) {
|
||||
if q.path_endswith
|
||||
.iter()
|
||||
.all(|s| !path.to_ascii_lowercase().ends_with(&s.to_ascii_lowercase()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -38,45 +44,33 @@ fn filter_target_windows(hwnd: &HWND, q: &TargetInformation) -> bool {
|
|||
true
|
||||
}
|
||||
|
||||
fn window_callback(hwnd: HWND, op: &Commands) {
|
||||
let t = match op {
|
||||
Commands::Get { target } => target,
|
||||
Commands::Set {
|
||||
target,
|
||||
resolution: _,
|
||||
} => target,
|
||||
};
|
||||
|
||||
if !filter_target_windows(&hwnd, t) {
|
||||
fn window_callback(hwnd: HWND, op: &Cli) {
|
||||
if !filter_target_windows(&hwnd, &op.target) {
|
||||
return;
|
||||
}
|
||||
|
||||
let client_size = Size::from(hwnd.GetClientRect().unwrap());
|
||||
|
||||
match op {
|
||||
Commands::Get { target: _ } => {
|
||||
println!("{}", client_size - t.offset);
|
||||
}
|
||||
Commands::Set {
|
||||
target: _,
|
||||
resolution,
|
||||
} => {
|
||||
let window_size = Size::from(hwnd.GetWindowRect().unwrap());
|
||||
let border = window_size - client_size;
|
||||
let Some(size) = op.size else {
|
||||
println!("{}\t", client_size - op.target.offset);
|
||||
return;
|
||||
};
|
||||
|
||||
hwnd.SetWindowPos(
|
||||
HwndPlace::None,
|
||||
POINT::new(0, 0),
|
||||
(*resolution + t.offset + border).into(),
|
||||
SWP::NOMOVE,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
let window_size = Size::from(hwnd.GetWindowRect().unwrap());
|
||||
|
||||
let border = window_size - client_size;
|
||||
|
||||
hwnd.SetWindowPos(
|
||||
HwndPlace::None,
|
||||
POINT::new(0, 0),
|
||||
(size + op.target.offset + border).into(),
|
||||
SWP::NOMOVE,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let c = Cli::parse().command;
|
||||
let c = Cli::parse();
|
||||
EnumWindows(|hwnd: HWND| -> bool {
|
||||
window_callback(hwnd, &c);
|
||||
true
|
||||
|
|
36
src/model.rs
36
src/model.rs
|
@ -1,4 +1,4 @@
|
|||
use clap::{Args, Parser, Subcommand};
|
||||
use clap::{Args, Parser};
|
||||
use std::fmt::{self, Display};
|
||||
use std::io::{Error, ErrorKind};
|
||||
use std::ops::{Add, Sub};
|
||||
|
@ -6,35 +6,23 @@ use winsafe::{RECT, SIZE};
|
|||
|
||||
#[derive(Debug, Clone, Args)]
|
||||
pub struct TargetInformation {
|
||||
#[arg(short, long)]
|
||||
#[arg(short, long, help = "Filter by binary path")]
|
||||
pub path_endswith: Vec<String>,
|
||||
#[arg(short, long)]
|
||||
#[arg(short, long, help = "Filter by title")]
|
||||
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,
|
||||
}
|
||||
|
||||
#[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)]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub command: Commands,
|
||||
#[command(flatten)]
|
||||
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, Default)]
|
||||
pub struct Size {
|
||||
pub x: usize,
|
||||
pub y: usize,
|
||||
|
@ -78,12 +66,6 @@ impl From<Size> for SIZE {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for Size {
|
||||
fn default() -> Self {
|
||||
Self { x: 0, y: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Size {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}x{}", self.x, self.y)
|
||||
|
|
Loading…
Reference in New Issue
Block a user