Skip to content

Commit

Permalink
Implement a smal HWND blacklist to avoid recurring exceptions with in…
Browse files Browse the repository at this point in the history
…valid windows to paint.
  • Loading branch information
DARKGuy committed Nov 4, 2021
1 parent 60e8f1f commit 20c50cf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Core/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Switchie

public class WindowManager
{
static List<IntPtr> hWndBlacklist = new List<IntPtr>();

static int GetWindowZOrder(IntPtr hWnd)
{
var zOrder = -1;
Expand All @@ -26,6 +28,7 @@ public static List<Window> GetOpenWindows()

WinAPI.EnumWindows((IntPtr hWnd, int lParam) =>
{
if (hWndBlacklist.Contains(hWnd)) return true;
if (hWnd == shellWindow) return true;
if (!WinAPI.IsWindowVisible(hWnd)) return true;

Expand All @@ -45,7 +48,12 @@ public static List<Window> GetOpenWindows()

int index = 0;
WinAPI.GetWindowThreadProcessId(hWnd, out uint pid);
try { index = WindowsVirtualDesktopManager.GetInstance().FromDesktop(WindowsVirtualDesktopManager.GetInstance().FromWindow((IntPtr)hWnd)); } catch { }
try { index = WindowsVirtualDesktopManager.GetInstance().FromDesktop(WindowsVirtualDesktopManager.GetInstance().FromWindow((IntPtr)hWnd)); }
catch
{
hWndBlacklist.Add(hWnd);
return true;
}
if (index < 0) return true;

int hIcon = WinAPI.SendMessage(hWnd, WinAPI.WM_GETICON, WinAPI.ICON_SMALL2, 0);
Expand Down

0 comments on commit 20c50cf

Please sign in to comment.