@@ -2,7 +2,7 @@ use crate::{
2
2
win_utils:: { convert_to_full, convert_to_human, make_window_transparent, WindowInfo } ,
3
3
TransparencyRule ,
4
4
} ;
5
- use core:: ffi:: c_void;
5
+ use core:: { ffi:: c_void, iter :: once , mem :: transmute } ;
6
6
use serde:: { Deserialize , Serialize } ;
7
7
use std:: path:: Path ;
8
8
use windows:: {
@@ -36,49 +36,6 @@ pub struct WindowConfig {
36
36
old_class : Option < String > ,
37
37
}
38
38
39
- impl Default for WindowConfig {
40
- fn default ( ) -> Self {
41
- Self {
42
- process_name : String :: new ( ) ,
43
- window_class : String :: new ( ) ,
44
- transparency : 255 ,
45
- enabled : false ,
46
- force : false ,
47
- old_class : None ,
48
- }
49
- }
50
- }
51
-
52
- impl From < & WindowConfig > for TransparencyRule {
53
- fn from ( config : & WindowConfig ) -> Self {
54
- TransparencyRule {
55
- process_name : config. process_name . to_owned ( ) . into ( ) ,
56
- window_class : config. window_class . to_owned ( ) . into ( ) ,
57
- transparency : convert_to_human ( config. transparency ) . into ( ) ,
58
- enabled : config. enabled ,
59
- force : config. force ,
60
- old_class : config. old_class . to_owned ( ) . unwrap_or_default ( ) . into ( ) ,
61
- }
62
- }
63
- }
64
-
65
- impl From < TransparencyRule > for WindowConfig {
66
- fn from ( config : TransparencyRule ) -> Self {
67
- WindowConfig {
68
- process_name : config. process_name . to_owned ( ) . into ( ) ,
69
- window_class : config. window_class . to_owned ( ) . into ( ) ,
70
- transparency : convert_to_full ( config. transparency . try_into ( ) . unwrap_or ( 100 ) ) ,
71
- enabled : config. enabled ,
72
- force : config. force ,
73
- old_class : if config. old_class . is_empty ( ) {
74
- None
75
- } else {
76
- Some ( config. old_class . into ( ) )
77
- } ,
78
- }
79
- }
80
- }
81
-
82
39
impl WindowConfig {
83
40
pub fn new ( info : & WindowInfo , transparency : u8 ) -> Self {
84
41
Self {
@@ -163,7 +120,7 @@ impl WindowConfig {
163
120
let wide_class: Vec < u16 > = self
164
121
. get_window_class ( )
165
122
. encode_utf16 ( )
166
- . chain ( std :: iter :: once ( 0 ) )
123
+ . chain ( once ( 0 ) )
167
124
. collect ( ) ;
168
125
169
126
let class_ptr = PCWSTR :: from_raw ( wide_class. as_ptr ( ) ) ;
@@ -180,18 +137,19 @@ impl WindowConfig {
180
137
{
181
138
let mut buffer = [ 0u8 ; 260 ] ;
182
139
let len = GetProcessImageFileNameA ( process_handle, & mut buffer) ;
183
- let _ = CloseHandle ( process_handle) ;
140
+ _ = CloseHandle ( process_handle) ;
184
141
185
142
if len > 0 {
186
143
let path_str =
187
144
String :: from_utf8_lossy ( & buffer[ ..len as usize ] ) . to_string ( ) ;
188
- if let Some ( name) = Path :: new ( & path_str)
145
+ let name = Path :: new ( & path_str)
189
146
. file_name ( )
190
147
. and_then ( |n| n. to_str ( ) )
191
- . map ( |s| s. split ( '.' ) . next ( ) . unwrap_or ( s) )
192
- {
148
+ . map ( |s| s. split ( '.' ) . next ( ) . unwrap_or ( s) ) ;
149
+
150
+ if let Some ( name) = name {
193
151
if name == self . process_name {
194
- handles. push ( std :: mem :: transmute ( hwnd) ) ;
152
+ handles. push ( transmute ( hwnd) ) ;
195
153
}
196
154
}
197
155
}
@@ -292,3 +250,46 @@ fn find_window_by_class(target_class: &str) -> windows::core::Result<Option<HWND
292
250
Ok ( None )
293
251
}
294
252
}
253
+
254
+ impl Default for WindowConfig {
255
+ fn default ( ) -> Self {
256
+ Self {
257
+ process_name : String :: new ( ) ,
258
+ window_class : String :: new ( ) ,
259
+ transparency : 255 ,
260
+ enabled : false ,
261
+ force : false ,
262
+ old_class : None ,
263
+ }
264
+ }
265
+ }
266
+
267
+ impl From < & WindowConfig > for TransparencyRule {
268
+ fn from ( config : & WindowConfig ) -> Self {
269
+ TransparencyRule {
270
+ process_name : config. process_name . to_owned ( ) . into ( ) ,
271
+ window_class : config. window_class . to_owned ( ) . into ( ) ,
272
+ transparency : convert_to_human ( config. transparency ) . into ( ) ,
273
+ enabled : config. enabled ,
274
+ force : config. force ,
275
+ old_class : config. old_class . to_owned ( ) . unwrap_or_default ( ) . into ( ) ,
276
+ }
277
+ }
278
+ }
279
+
280
+ impl From < TransparencyRule > for WindowConfig {
281
+ fn from ( config : TransparencyRule ) -> Self {
282
+ WindowConfig {
283
+ process_name : config. process_name . to_owned ( ) . into ( ) ,
284
+ window_class : config. window_class . to_owned ( ) . into ( ) ,
285
+ transparency : convert_to_full ( config. transparency . try_into ( ) . unwrap_or ( 100 ) ) ,
286
+ enabled : config. enabled ,
287
+ force : config. force ,
288
+ old_class : if config. old_class . is_empty ( ) {
289
+ None
290
+ } else {
291
+ Some ( config. old_class . into ( ) )
292
+ } ,
293
+ }
294
+ }
295
+ }
0 commit comments