@@ -213,26 +213,37 @@ public static Dictionary<string, string> LoadResxFromStream( Stream stream )
213213 return dictionary ;
214214 }
215215
216- public static bool IsWindowBoundsVisible ( Rectangle bounds )
216+ private const double WindowTitleBarHeightInDIPs = 32.0 ;
217+
218+ // Tests whether enough of the window's title bar is on a screen for the user to grab it with the
219+ // mouse. Both the bounds and the screen working areas are in physical pixels - convert WPF DIPs
220+ // using the window's DPI scale before calling (they diverge whenever any monitor is not at 100%
221+ // scaling). Screens are tested individually rather than against the virtual desktop bounding box,
222+ // so the dead zones of non-rectangular multi-monitor layouts correctly count as off-screen.
223+ public static bool IsWindowTitleBarVisible ( Rectangle boundsInPixels , double dpiScale )
217224 {
218- var totalWindowArea = bounds . Width * bounds . Height ;
219-
220- if ( totalWindowArea <= 0 )
225+ if ( ( boundsInPixels . Width <= 0 ) || ( boundsInPixels . Height <= 0 ) )
221226 {
222227 return false ;
223228 }
224229
230+ var titleBarHeightInPixels = Math . Max ( 1 , ( int ) Math . Round ( WindowTitleBarHeightInDIPs * dpiScale ) ) ;
231+
232+ var titleBarBounds = new Rectangle ( boundsInPixels . X , boundsInPixels . Y , boundsInPixels . Width , titleBarHeightInPixels ) ;
233+
234+ var totalTitleBarArea = titleBarBounds . Width * titleBarBounds . Height ;
235+
225236 var totalVisibleArea = 0 ;
226237
227238 foreach ( var screen in Screen . AllScreens )
228239 {
229- var intersection = Rectangle . Intersect ( screen . WorkingArea , bounds ) ;
240+ var intersection = Rectangle . Intersect ( screen . WorkingArea , titleBarBounds ) ;
230241
231242 totalVisibleArea += intersection . Width * intersection . Height ;
232243 }
233244
234- // Require at least 10 % of the window to be visible on screen
235- return totalVisibleArea >= totalWindowArea * 0.10 ;
245+ // Require at least 25 % of the title bar to be visible so there is enough of it to grab
246+ return totalVisibleArea >= totalTitleBarArea * 0.25 ;
236247 }
237248
238249 public static void BringExistingInstanceToFront ( )
0 commit comments