diff --git a/src/Window.zig b/src/Window.zig index 6717a96..6cb1361 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -51,6 +51,8 @@ pub fn shouldManage(window: Window) bool { if (window.isCloaked()) return false; + if (window.isSystemWindow()) return false; + const styles: win32.ui.windows_and_messaging.WINDOW_STYLE = window.style(); const ex_styles: win32.ui.windows_and_messaging.WINDOW_EX_STYLE = window.exStyle(); @@ -130,6 +132,35 @@ fn owner(window: Window) ?win32.foundation.HWND { ); } +const class_name_max_len: usize = 256; + +fn className(window: Window, buf: *[class_name_max_len:0]u16) []const u16 { + const len: i32 = win32.ui.windows_and_messaging.GetClassNameW(window.handle, buf, class_name_max_len); + if (len <= 0) return &.{}; + return buf[0..@intCast(len)]; +} + +const system_classes: [4][]const u16 = .{ + std.unicode.utf8ToUtf16LeStringLiteral("SysListView32"), + std.unicode.utf8ToUtf16LeStringLiteral("WorkerW"), + std.unicode.utf8ToUtf16LeStringLiteral("Shell_TrayWnd"), + std.unicode.utf8ToUtf16LeStringLiteral("Shell_SecondaryTrayWnd"), +}; + +fn isSystemWindow(window: Window) bool { + if (window.handle == win32.ui.windows_and_messaging.GetDesktopWindow()) return true; + if (window.handle == win32.ui.windows_and_messaging.GetShellWindow()) return true; + + var buf: [class_name_max_len:0]u16 = undefined; + const name: []const u16 = window.className(&buf); + + for (system_classes) |sys_class| { + if (std.mem.eql(u16, name, sys_class)) return true; + } + + return false; +} + const log = std.log.scoped(.window); const Monitor = @import("Monitor.zig");