Skip to content

Commit 0726a0c

Browse files
committed
nit
1 parent 3a5aaf6 commit 0726a0c

File tree

5 files changed

+58
-15
lines changed

5 files changed

+58
-15
lines changed

.cargo/Config.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
[unstable]
2-
build-std =["alloc", "core", "panic_abort", "proc_macro", "std"]
3-
build-std-features=["panic_immediate_abort"]
1+
# [unstable]
2+
# build-std =["alloc", "core", "panic_abort", "proc_macro", "std"]
3+
# build-std-features=["panic_immediate_abort"]
44

5-
[build]
6-
rustflags=["--cfg=has_std", "-C", "panic=abort", "target-cpu=native"]
5+
# [build]
6+
# rustflags=["--cfg=has_std", "-C", "panic=abort", "target-cpu=native"]
77

8-
[target.x86_64-pc-windows-msvc]
9-
rustflags=["-C", "link-arg=/LIMIT:10240"]
8+
# [target.x86_64-pc-windows-msvc]
9+
# rustflags=["-C", "link-arg=/LIMIT:10240"]
10+
# #

src/app_state.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::PathBuf;
33
use std::sync::Arc;
44
use tokio::sync::{broadcast, RwLock};
55

6+
use crate::monitor::{refresh_config, reset_config};
67
use crate::transparency::create_rules_window;
78
use crate::util::Config;
89
use crate::win_utils::{self, create_percentage_window};
@@ -99,6 +100,7 @@ impl AppState {
99100
Ok(class) => {
100101
if let Some(info) = class {
101102
window_config.set_window_class(info.1);
103+
refresh_config(window_config.clone());
102104
config.get_windows().remove(&window_config.get_key());
103105
window_config.set_old_classname(Some(old_class));
104106
}
@@ -108,17 +110,32 @@ impl AppState {
108110
}
109111

110112
if !window_config.is_wide() {
113+
println!("d");
111114
match find_parent_from_child_class(window_config.get_window_class()) {
112115
Ok(class) => {
113116
if let Some(info) = class {
114-
config.get_windows().remove(&format!(
115-
"{}|{}",
116-
window_config.get_name(),
117-
info.1
118-
));
117+
let key = &format!("{}|{}", window_config.get_name(), info.1);
118+
println!("hrere {:?}", info);
119+
if config.get_windows().contains_key(key) {
120+
println!("key yo {:?}", key);
121+
let clone_config = window_config.clone();
122+
let real_class = clone_config.get_window_class();
123+
window_config.set_window_class(info.1);
124+
reset_config(window_config.clone());
125+
// let handles = window_config.get_window_hwnds();
126+
window_config.set_window_class(real_class.to_string());
127+
// println!("handles yo {:?}", handles);
128+
129+
config.get_windows().remove(key);
130+
}
131+
} else {
132+
println!("2{:?}", class);
119133
}
120134
}
121-
Err(_) => (),
135+
Err(_) => {
136+
println!("2");
137+
()
138+
}
122139
}
123140
}
124141

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![windows_subsystem = "windows"]
1+
// #![windows_subsystem = "windows"]
22
#![feature(let_chains)]
33
use anyhow::Result;
44
use std::sync::Arc;

src/monitor.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::window_config::WindowConfig;
12
use crate::{app_state::AppState, util::Config, win_utils::make_window_transparent};
23

34
use core::time::Duration;
@@ -53,6 +54,7 @@ pub async fn monitor_windows(app_state: Arc<AppState>) {
5354
let mut config = app_state.get_config().await;
5455
let mut is_enabled = app_state.is_enabled().await;
5556
let mut config_rx = app_state.subscribe_config_updates();
57+
5658
let mut enabled_rx = app_state.subscribe_enabled_updates();
5759

5860
loop {
@@ -63,6 +65,7 @@ pub async fn monitor_windows(app_state: Arc<AppState>) {
6365
Ok(new_config) = config_rx.recv() => {
6466
config = new_config;
6567
}
68+
6669
Ok(state) = enabled_rx.recv() => {
6770
if state != is_enabled && is_enabled {
6871
reset_windows(&mut window_cache);
@@ -140,3 +143,21 @@ fn reset_windows(window_cache: &mut HashMap<String, Vec<WindowHandleState>>) {
140143
}
141144
});
142145
}
146+
147+
pub fn reset_config(window_config: WindowConfig) {
148+
let handles = window_config.get_window_hwnds();
149+
for handle in handles {
150+
if make_window_transparent(HWND(handle as *mut c_void), 255).is_ok() {}
151+
}
152+
}
153+
pub fn refresh_config(window_config: WindowConfig) {
154+
let handles = window_config.get_window_hwnds();
155+
for handle in handles {
156+
if make_window_transparent(
157+
HWND(handle as *mut c_void),
158+
window_config.get_transparency(),
159+
)
160+
.is_ok()
161+
{}
162+
}
163+
}

src/window_config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,12 @@ fn get_window_class_name(hwnd: HWND) -> Option<String> {
216216
pub fn find_parent_from_child_class(
217217
child_class: &str,
218218
) -> windows::core::Result<Option<(HWND, String)>> {
219+
println!("{:?}", child_class);
219220
let child_hwnd = match find_window_by_class(child_class)? {
220-
Some(hwnd) => hwnd,
221+
Some(hwnd) => {
222+
println!("s3");
223+
hwnd
224+
}
221225
None => {
222226
return Ok(None);
223227
}

0 commit comments

Comments
 (0)