Skip to content

Commit 57ad4c1

Browse files
authored
feat: ignore topmost windows (#188)
1 parent 135e4b7 commit 57ad4c1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/utils/window.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@ use windows::Win32::{
2323
EnumWindows, GetCursorPos, GetForegroundWindow, GetWindow, GetWindowLongPtrW,
2424
GetWindowPlacement, GetWindowTextW, GetWindowThreadProcessId, IsIconic,
2525
SetForegroundWindow, ShowWindow, GWL_EXSTYLE, GWL_STYLE, GWL_USERDATA, GW_OWNER,
26-
SW_RESTORE, WINDOWPLACEMENT, WS_EX_TOOLWINDOW, WS_ICONIC, WS_VISIBLE,
26+
SW_RESTORE, WINDOWPLACEMENT, WS_EX_TOOLWINDOW, WS_EX_TOPMOST, WS_ICONIC, WS_VISIBLE,
2727
},
2828
},
2929
};
3030

31-
pub fn get_window_state(hwnd: HWND) -> (bool, bool, bool) {
31+
pub fn get_window_state(hwnd: HWND) -> (bool, bool, bool, bool) {
3232
let style = unsafe { GetWindowLongPtrW(hwnd, GWL_STYLE) } as u32;
3333
let exstyle = unsafe { GetWindowLongPtrW(hwnd, GWL_EXSTYLE) } as u32;
3434

3535
let is_visible = style & WS_VISIBLE.0 != 0;
3636
let is_iconic = style & WS_ICONIC.0 != 0;
3737
let is_tool = exstyle & WS_EX_TOOLWINDOW.0 != 0;
38+
let is_topmost = exstyle & WS_EX_TOPMOST.0 != 0;
3839

39-
(is_visible, is_iconic, is_tool)
40+
(is_visible, is_iconic, is_tool, is_topmost)
4041
}
4142

4243
pub fn is_iconic_window(hwnd: HWND) -> bool {
@@ -219,10 +220,11 @@ pub fn list_windows(
219220
let mut valid_hwnds = vec![];
220221
let mut owner_hwnds = vec![];
221222
for hwnd in hwnds.iter().cloned() {
222-
let (is_visible, is_iconic, is_tool) = get_window_state(hwnd);
223+
let (is_visible, is_iconic, is_tool, is_topmost) = get_window_state(hwnd);
223224
let ok = is_visible
224225
&& (if ignore_minimal { !is_iconic } else { true })
225226
&& !is_tool
227+
&& !is_topmost
226228
&& !is_cloaked_window(hwnd, only_current_desktop)
227229
&& !is_small_window(hwnd);
228230
if ok {

tools/inspect-windows/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() -> Result<()> {
1212
for hwnd in hwnds {
1313
let title = get_window_title(hwnd);
1414
let cloak_type = get_window_cloak_type(hwnd);
15-
let (is_visible, is_iconic, is_tool) = get_window_state(hwnd);
15+
let (is_visible, is_iconic, is_tool, _is_topmost) = get_window_state(hwnd);
1616
let (width, height) = get_window_size(hwnd);
1717
let owner_hwnd: HWND = unsafe { GetWindow(hwnd, GW_OWNER) }.unwrap_or_default();
1818
let owner_title = if !owner_hwnd.is_invalid() {

0 commit comments

Comments
 (0)