improve debug message

This commit is contained in:
Kang Yu 2025-04-26 22:29:16 -07:00
parent 769f35b681
commit e41caba220

View file

@ -1858,6 +1858,9 @@ namespace PersistentWindows.Common
if (!initialized) if (!initialized)
return; return;
if (hwnd == IntPtr.Zero)
return;
{ {
switch (eventType) switch (eventType)
{ {
@ -2674,22 +2677,6 @@ namespace PersistentWindows.Common
ApplicationDisplayMetrics prevDisplayMetrics; ApplicationDisplayMetrics prevDisplayMetrics;
if (IsWindowMoved(displayKey, hWnd, eventType, now, out curDisplayMetrics, out prevDisplayMetrics)) if (IsWindowMoved(displayKey, hWnd, eventType, now, out curDisplayMetrics, out prevDisplayMetrics))
{ {
if (debugWindows.Contains(hWnd))
{
string log = string.Format("Captured {0,-8} at {1} '{2}' fullscreen:{3} minimized:{4}",
curDisplayMetrics,
curDisplayMetrics.ScreenPosition.ToString(),
curDisplayMetrics.Title,
curDisplayMetrics.IsFullScreen,
curDisplayMetrics.IsMinimized
);
Log.Event(log);
string log2 = string.Format(" WindowPlacement.NormalPosition at {0}",
curDisplayMetrics.WindowPlacement.NormalPosition.ToString());
Log.Event(log2);
}
bool new_window = !monitorApplications[displayKey].ContainsKey(hWnd); bool new_window = !monitorApplications[displayKey].ContainsKey(hWnd);
if (eventType != 0 || new_window) if (eventType != 0 || new_window)
curDisplayMetrics.IsValid = true; curDisplayMetrics.IsValid = true;
@ -2714,6 +2701,24 @@ namespace PersistentWindows.Common
TrimQueue(displayKey, hWnd); TrimQueue(displayKey, hWnd);
} }
if (debugWindows.Contains(hWnd))
{
string log = string.Format("Captured {0} '{1}' fullscreen:{2} minimized:{3} visible:{4} at {5} {6, -8}",
curDisplayMetrics.HWnd.ToString("X"),
curDisplayMetrics.Title,
curDisplayMetrics.IsFullScreen,
curDisplayMetrics.IsMinimized,
!curDisplayMetrics.IsInvisible,
curDisplayMetrics.ScreenPosition.ToString(),
curDisplayMetrics
);
Log.Event(log);
string log2 = string.Format(" WindowPlacement.NormalPosition at {0}",
curDisplayMetrics.WindowPlacement.NormalPosition.ToString());
Log.Event(log2);
}
monitorApplications[displayKey][hWnd].Add(curDisplayMetrics); monitorApplications[displayKey][hWnd].Add(curDisplayMetrics);
ret = true; ret = true;
} }
@ -3140,13 +3145,13 @@ namespace PersistentWindows.Common
if (hwnd != kid) if (hwnd != kid)
{ {
if (prevDisplayMetrics.Title != curDisplayMetrics.Title) if (prevDisplayMetrics.Title != curDisplayMetrics.Title)
Log.Error($"Inherit position data from killed window {prevDisplayMetrics.Title} with different title {curDisplayMetrics.Title} {prevDisplayMetrics.HWnd.ToString("X")}"); Log.Error($"{hwnd.ToString("X")} Inherit position data from killed window {prevDisplayMetrics.Title} with different title {curDisplayMetrics.Title} {prevDisplayMetrics.HWnd.ToString("X")}");
else else
Log.Error($"Inherit position data from killed window {prevDisplayMetrics.Title} {prevDisplayMetrics.HWnd.ToString("X")}"); Log.Error($"{hwnd.ToString("X")} Inherit position data from killed window {prevDisplayMetrics.Title} {prevDisplayMetrics.HWnd.ToString("X")}");
ResolveWindowHandleCollision(hwnd); ResolveWindowHandleCollision(hwnd);
} }
else else
Log.Error($"Inherit position data from existing window 0x{kid.ToString("X")} for {curDisplayMetrics.Title}"); Log.Error($"{hwnd.ToString("X")} Inherit position data from existing window 0x{kid.ToString("X")} for {curDisplayMetrics.Title}");
if (initialized && autoRestoreNewWindowToLastCapture) if (initialized && autoRestoreNewWindowToLastCapture)
return true; return true;