Removed old Windows 8 logic, which caused #403 (which is a very unlucky issue number LOL)

This should actually make Greenshot a tiny bit faster and use less resources, but I am not 100% sure about the effects as some windows still seem to have the window class for Windows 8.
This commit is contained in:
Robin Krom 2022-06-28 16:28:26 +02:00
commit f50f205b70
No known key found for this signature in database
GPG key ID: BCC01364F1371490
2 changed files with 34 additions and 192 deletions

View file

@ -42,8 +42,6 @@ namespace Greenshot.Base.Core
{ {
private const string AppWindowClass = "Windows.UI.Core.CoreWindow"; //Used for Windows 8(.1) private const string AppWindowClass = "Windows.UI.Core.CoreWindow"; //Used for Windows 8(.1)
private const string AppFrameWindowClass = "ApplicationFrameWindow"; // Windows 10 uses ApplicationFrameWindow private const string AppFrameWindowClass = "ApplicationFrameWindow"; // Windows 10 uses ApplicationFrameWindow
private const string ApplauncherClass = "ImmersiveLauncher";
private const string GutterClass = "ImmersiveGutter";
private static readonly IList<string> IgnoreClasses = new List<string>(new[] private static readonly IList<string> IgnoreClasses = new List<string>(new[]
{ {
@ -89,13 +87,7 @@ namespace Greenshot.Base.Core
private IntPtr _parentHandle = IntPtr.Zero; private IntPtr _parentHandle = IntPtr.Zero;
private WindowDetails _parent; private WindowDetails _parent;
private bool _frozen; private bool _frozen;
/// <summary>
/// This checks if the window is a Windows 8 App
/// For Windows 10 most normal code works, as it's hosted inside "ApplicationFrameWindow"
/// </summary>
public bool IsApp => AppWindowClass.Equals(ClassName);
/// <summary> /// <summary>
/// This checks if the window is a Windows 10 App /// This checks if the window is a Windows 10 App
/// For Windows 10 apps are hosted inside "ApplicationFrameWindow" /// For Windows 10 apps are hosted inside "ApplicationFrameWindow"
@ -108,20 +100,6 @@ namespace Greenshot.Base.Core
public bool IsBackgroundWin10App => WindowsVersion.IsWindows10OrLater && AppFrameWindowClass.Equals(ClassName) && public bool IsBackgroundWin10App => WindowsVersion.IsWindows10OrLater && AppFrameWindowClass.Equals(ClassName) &&
!Children.Any(window => string.Equals(window.ClassName, AppWindowClass)); !Children.Any(window => string.Equals(window.ClassName, AppWindowClass));
/// <summary>
/// Check if the window is the metro gutter (sizeable separator)
/// </summary>
public bool IsGutter => GutterClass.Equals(ClassName);
/// <summary>
/// Test if this window is for the App-Launcher
/// </summary>
public bool IsAppLauncher => ApplauncherClass.Equals(ClassName);
/// <summary>
/// Check if this window is the window of a metro app
/// </summary>
public bool IsMetroApp => IsAppLauncher || IsApp;
/// <summary> /// <summary>
/// To allow items to be compared, the hash code /// To allow items to be compared, the hash code
@ -226,12 +204,6 @@ namespace Greenshot.Base.Core
Log.Warn(ex); Log.Warn(ex);
} }
if (IsMetroApp)
{
// No method yet to get the metro icon
return null;
}
try try
{ {
return PluginUtils.GetCachedExeIcon(ProcessPath, 0); return PluginUtils.GetCachedExeIcon(ProcessPath, 0);
@ -467,11 +439,6 @@ namespace Greenshot.Base.Core
{ {
get get
{ {
if (IsMetroApp)
{
return !Visible;
}
return User32Api.IsIconic(Handle) || Location.X <= -32000; return User32Api.IsIconic(Handle) || Location.X <= -32000;
} }
set set
@ -494,22 +461,6 @@ namespace Greenshot.Base.Core
{ {
get get
{ {
if (IsApp)
{
if (Visible)
{
foreach (var displayInfo in DisplayInfo.AllDisplayInfos)
{
if (WindowRectangle.Equals(displayInfo.Bounds))
{
return true;
}
}
}
return false;
}
return User32Api.IsZoomed(Handle); return User32Api.IsZoomed(Handle);
} }
set set
@ -546,50 +497,6 @@ namespace Greenshot.Base.Core
return false; return false;
} }
if (IsApp)
{
var windowRectangle = WindowRectangle;
foreach (var displayInfo in DisplayInfo.AllDisplayInfos)
{
if (!displayInfo.Bounds.Contains(windowRectangle)) continue;
if (windowRectangle.Equals(displayInfo.Bounds))
{
// Fullscreen, it's "visible" when AppVisibilityOnMonitor says yes
// Although it might be the other App, this is not "very" important
NativeRect rect = displayInfo.Bounds;
IntPtr monitor = User32Api.MonitorFromRect(ref rect, MonitorFrom.DefaultToNull);
if (monitor != IntPtr.Zero)
{
MONITOR_APP_VISIBILITY? monitorAppVisibility = AppVisibility?.GetAppVisibilityOnMonitor(monitor);
//LOG.DebugFormat("App {0} visible: {1} on {2}", Text, monitorAppVisibility, screen.Bounds);
if (monitorAppVisibility == MONITOR_APP_VISIBILITY.MAV_APP_VISIBLE)
{
return true;
}
}
}
else
{
// Is only partly on the screen, when this happens the app is always visible!
return true;
}
}
return false;
}
if (IsGutter)
{
// gutter is only made available when it's visible
return true;
}
if (IsAppLauncher)
{
return IsAppLauncherVisible;
}
return User32Api.IsWindowVisible(Handle); return User32Api.IsWindowVisible(Handle);
} }
} }
@ -653,7 +560,7 @@ namespace Greenshot.Base.Core
if (DwmApi.IsDwmEnabled) if (DwmApi.IsDwmEnabled)
{ {
bool gotFrameBounds = GetExtendedFrameBounds(out windowRect); bool gotFrameBounds = GetExtendedFrameBounds(out windowRect);
if (IsApp) if (IsWin10App)
{ {
// Pre-Cache for maximized call, this is only on Windows 8 apps (full screen) // Pre-Cache for maximized call, this is only on Windows 8 apps (full screen)
if (gotFrameBounds) if (gotFrameBounds)
@ -683,8 +590,8 @@ namespace Greenshot.Base.Core
} }
} }
// Correction for maximized windows, only if it's not an app // Correction for maximized windows
if (!HasParent && !IsApp && Maximised) if (!HasParent && Maximised)
{ {
// Only if the border size can be retrieved // Only if the border size can be retrieved
if (GetBorderSize(out var size)) if (GetBorderSize(out var size))
@ -928,7 +835,7 @@ namespace Greenshot.Base.Core
{ {
// if GDI is allowed.. (a screenshot won't be better than we comes if we continue) // if GDI is allowed.. (a screenshot won't be better than we comes if we continue)
using Process thisWindowProcess = Process; using Process thisWindowProcess = Process;
if (!IsMetroApp && WindowCapture.IsGdiAllowed(thisWindowProcess)) if (WindowCapture.IsGdiAllowed(thisWindowProcess))
{ {
// we return null which causes the capturing code to try another method. // we return null which causes the capturing code to try another method.
return null; return null;
@ -973,11 +880,8 @@ namespace Greenshot.Base.Core
tempForm.BackColor = Color.Black; tempForm.BackColor = Color.Black;
// Make sure everything is visible // Make sure everything is visible
tempForm.Refresh(); tempForm.Refresh();
if (!IsMetroApp) // Make sure the application window is active, so the colors & buttons are right
{ ToForeground();
// Make sure the application window is active, so the colors & buttons are right
ToForeground();
}
// Make sure all changes are processed and visible // Make sure all changes are processed and visible
Application.DoEvents(); Application.DoEvents();
@ -1013,11 +917,8 @@ namespace Greenshot.Base.Core
// Make sure everything is visible // Make sure everything is visible
tempForm.Refresh(); tempForm.Refresh();
if (!IsMetroApp) // Make sure the application window is active, so the colors & buttons are right
{ ToForeground();
// Make sure the application window is active, so the colors & buttons are right
ToForeground();
}
// Make sure all changes are processed and visible // Make sure all changes are processed and visible
Application.DoEvents(); Application.DoEvents();
@ -1154,6 +1055,13 @@ namespace Greenshot.Base.Core
return targetBuffer.UnlockAndReturnBitmap(); return targetBuffer.UnlockAndReturnBitmap();
} }
/// <summary>
/// If a window is hidden (Iconic), it also has the specified dimensions.
/// </summary>
/// <param name="rect">NativeRect</param>
/// <returns>bool true if hidden</returns>
private bool IsHidden(NativeRect rect) => rect.Width == 65535 && rect.Height == 65535 && rect.Left == 32767 && rect.Top == 32767;
/// <summary> /// <summary>
/// Helper method to get the window size for DWM Windows /// Helper method to get the window size for DWM Windows
/// </summary> /// </summary>
@ -1164,6 +1072,10 @@ namespace Greenshot.Base.Core
var result = DwmApi.DwmGetWindowAttribute(Handle, DwmWindowAttributes.ExtendedFrameBounds, out NativeRect rect, Marshal.SizeOf(typeof(NativeRect))); var result = DwmApi.DwmGetWindowAttribute(Handle, DwmWindowAttributes.ExtendedFrameBounds, out NativeRect rect, Marshal.SizeOf(typeof(NativeRect)));
if (result.Succeeded()) if (result.Succeeded())
{ {
if (IsHidden(rect))
{
rect = NativeRect.Empty;
}
rectangle = rect; rectangle = rect;
return true; return true;
} }
@ -1196,7 +1108,14 @@ namespace Greenshot.Base.Core
var windowInfo = new WindowInfo(); var windowInfo = new WindowInfo();
// Get the Window Info for this window // Get the Window Info for this window
bool result = User32Api.GetWindowInfo(Handle, ref windowInfo); bool result = User32Api.GetWindowInfo(Handle, ref windowInfo);
rectangle = result ? windowInfo.Bounds : NativeRect.Empty; if (IsHidden(windowInfo.Bounds))
{
rectangle = NativeRect.Empty;
}
else
{
rectangle = result ? windowInfo.Bounds : NativeRect.Empty;
}
return result; return result;
} }
@ -1577,7 +1496,7 @@ namespace Greenshot.Base.Core
// Skip everything which is not rendered "normally", trying to fix BUG-2017 // Skip everything which is not rendered "normally", trying to fix BUG-2017
var exWindowStyle = window.ExtendedWindowStyle; var exWindowStyle = window.ExtendedWindowStyle;
if (!window.IsApp && !window.IsWin10App && (exWindowStyle & ExtendedWindowStyleFlags.WS_EX_NOREDIRECTIONBITMAP) != 0) if (!window.IsWin10App && (exWindowStyle & ExtendedWindowStyleFlags.WS_EX_NOREDIRECTIONBITMAP) != 0)
{ {
return false; return false;
} }
@ -1592,13 +1511,6 @@ namespace Greenshot.Base.Core
public static IEnumerable<WindowDetails> GetVisibleWindows() public static IEnumerable<WindowDetails> GetVisibleWindows()
{ {
var screenBounds = DisplayInfo.ScreenBounds; var screenBounds = DisplayInfo.ScreenBounds;
foreach (var window in GetAppWindows())
{
if (IsVisible(window, screenBounds))
{
yield return window;
}
}
foreach (var window in GetAllWindows()) foreach (var window in GetAllWindows())
{ {
@ -1609,38 +1521,6 @@ namespace Greenshot.Base.Core
} }
} }
/// <summary>
/// Get the WindowDetails for all Metro Apps
/// These are all Windows with Classname "Windows.UI.Core.CoreWindow"
/// </summary>
/// <returns>List WindowDetails with visible metro apps</returns>
public static IEnumerable<WindowDetails> GetAppWindows()
{
// if the appVisibility != null we have Windows 8.
if (AppVisibility == null)
{
yield break;
}
var nextHandle = User32Api.FindWindow(AppWindowClass, null);
while (nextHandle != IntPtr.Zero)
{
var metroApp = new WindowDetails(nextHandle);
yield return metroApp;
// Check if we have a gutter!
if (metroApp.Visible && !metroApp.Maximised)
{
var gutterHandle = User32Api.FindWindow(GutterClass, null);
if (gutterHandle != IntPtr.Zero)
{
yield return new WindowDetails(gutterHandle);
}
}
nextHandle = User32Api.FindWindowEx(IntPtr.Zero, nextHandle, AppWindowClass, null);
}
}
/// <summary> /// <summary>
/// Check if the window is a top level /// Check if the window is a top level
/// </summary> /// </summary>
@ -1671,7 +1551,7 @@ namespace Greenshot.Base.Core
} }
// Skip everything which is not rendered "normally", trying to fix BUG-2017 // Skip everything which is not rendered "normally", trying to fix BUG-2017
if (!window.IsApp && !window.IsWin10App && (exWindowStyle & ExtendedWindowStyleFlags.WS_EX_NOREDIRECTIONBITMAP) != 0) if (!window.IsWin10App && (exWindowStyle & ExtendedWindowStyleFlags.WS_EX_NOREDIRECTIONBITMAP) != 0)
{ {
return false; return false;
} }
@ -1707,14 +1587,6 @@ namespace Greenshot.Base.Core
/// <returns>List WindowDetails with all the top level windows</returns> /// <returns>List WindowDetails with all the top level windows</returns>
public static IEnumerable<WindowDetails> GetTopLevelWindows() public static IEnumerable<WindowDetails> GetTopLevelWindows()
{ {
foreach (var possibleTopLevel in GetAppWindows())
{
if (IsTopLevel(possibleTopLevel))
{
yield return possibleTopLevel;
}
}
foreach (var possibleTopLevel in GetAllWindows()) foreach (var possibleTopLevel in GetAllWindows())
{ {
if (IsTopLevel(possibleTopLevel)) if (IsTopLevel(possibleTopLevel))
@ -1790,27 +1662,6 @@ namespace Greenshot.Base.Core
} }
} }
/// <summary>
/// Get the AppLauncher
/// </summary>
/// <returns></returns>
public static WindowDetails GetAppLauncher()
{
// Only if Windows 8 (or higher)
if (AppVisibility == null)
{
return null;
}
IntPtr appLauncher = User32Api.FindWindow(ApplauncherClass, null);
if (appLauncher != IntPtr.Zero)
{
return new WindowDetails(appLauncher);
}
return null;
}
/// <summary> /// <summary>
/// Return true if the metro-app-launcher is visible /// Return true if the metro-app-launcher is visible
/// </summary> /// </summary>
@ -1842,7 +1693,6 @@ namespace Greenshot.Base.Core
result.AppendLine($"Size: {WindowRectangle.Size}"); result.AppendLine($"Size: {WindowRectangle.Size}");
result.AppendLine($"HasParent: {HasParent}"); result.AppendLine($"HasParent: {HasParent}");
result.AppendLine($"IsWin10App: {IsWin10App}"); result.AppendLine($"IsWin10App: {IsWin10App}");
result.AppendLine($"IsApp: {IsApp}");
result.AppendLine($"Visible: {Visible}"); result.AppendLine($"Visible: {Visible}");
result.AppendLine($"IsWindowVisible: {User32Api.IsWindowVisible(Handle)}"); result.AppendLine($"IsWindowVisible: {User32Api.IsWindowVisible(Handle)}");
result.AppendLine($"IsCloaked: {IsCloaked}"); result.AppendLine($"IsCloaked: {IsCloaked}");

View file

@ -564,14 +564,6 @@ namespace Greenshot.Helpers
{ {
_windows = new List<WindowDetails>(); _windows = new List<WindowDetails>();
// If the App Launcher is visible, no other windows are active
WindowDetails appLauncherWindow = WindowDetails.GetAppLauncher();
if (appLauncherWindow != null && appLauncherWindow.Visible)
{
_windows.Add(appLauncherWindow);
return null;
}
Thread getWindowDetailsThread = new Thread(RetrieveWindowDetails) Thread getWindowDetailsThread = new Thread(RetrieveWindowDetails)
{ {
Name = "Retrieve window details", Name = "Retrieve window details",
@ -984,7 +976,7 @@ namespace Greenshot.Helpers
else else
{ {
// Change to GDI, if allowed // Change to GDI, if allowed
if (!windowToCapture.IsMetroApp && WindowCapture.IsGdiAllowed(process)) if (WindowCapture.IsGdiAllowed(process))
{ {
if (!dwmEnabled && IsWpf(process)) if (!dwmEnabled && IsWpf(process))
{ {
@ -1000,7 +992,7 @@ namespace Greenshot.Helpers
// Change to DWM, if enabled and allowed // Change to DWM, if enabled and allowed
if (dwmEnabled) if (dwmEnabled)
{ {
if (windowToCapture.IsMetroApp || WindowCapture.IsDwmAllowed(process)) if (WindowCapture.IsDwmAllowed(process))
{ {
windowCaptureMode = WindowCaptureMode.Aero; windowCaptureMode = WindowCaptureMode.Aero;
} }
@ -1009,7 +1001,7 @@ namespace Greenshot.Helpers
} }
else if (windowCaptureMode == WindowCaptureMode.Aero || windowCaptureMode == WindowCaptureMode.AeroTransparent) else if (windowCaptureMode == WindowCaptureMode.Aero || windowCaptureMode == WindowCaptureMode.AeroTransparent)
{ {
if (!dwmEnabled || (!windowToCapture.IsMetroApp && !WindowCapture.IsDwmAllowed(process))) if (!dwmEnabled || !WindowCapture.IsDwmAllowed(process))
{ {
// Take default screen // Take default screen
windowCaptureMode = WindowCaptureMode.Screen; windowCaptureMode = WindowCaptureMode.Screen;
@ -1115,7 +1107,7 @@ namespace Greenshot.Helpers
break; break;
case WindowCaptureMode.Aero: case WindowCaptureMode.Aero:
case WindowCaptureMode.AeroTransparent: case WindowCaptureMode.AeroTransparent:
if (windowToCapture.IsMetroApp || WindowCapture.IsDwmAllowed(process)) if (WindowCapture.IsDwmAllowed(process))
{ {
tmpCapture = windowToCapture.CaptureDwmWindow(captureForWindow, windowCaptureMode, isAutoMode); tmpCapture = windowToCapture.CaptureDwmWindow(captureForWindow, windowCaptureMode, isAutoMode);
} }