@@ -221,31 +221,28 @@ parameters.XPosition is not null &&
221221 // Get display area DPI
222222 uint dpi = displayArea . GetDpi ( ) ;
223223
224- double maxWidth = workArea . Width . ToDips ( dpi ) ;
225- double maxHeight = workArea . Height . ToDips ( dpi ) ;
226-
227- // Ensure the window size is within the work area limits
228- double windowWidth = parameters . Width . Clamp ( window . MinWidth , maxWidth ) ;
229- double windowHeight = parameters . Height . Clamp ( window . MinHeight , maxHeight ) ;
224+ // Ensure the window size is within the work area limits (size is calculated in DIPs)
225+ double windowWidth = parameters . Width . Clamp ( window . MinWidth , workArea . Width . ToDips ( dpi ) ) ;
226+ double windowHeight = parameters . Height . Clamp ( window . MinHeight , workArea . Height . ToDips ( dpi ) ) ;
230227
231228 double windowPositionX ;
232229 double windowPositionY ;
233230 if ( isPositionSpecified )
234231 {
235- // Ensure the window position is within the work area bounds
236- windowPositionX = parameters . XPosition ! . Value . Clamp ( workArea . X , workArea . X + maxWidth - windowWidth ) ;
237- windowPositionY = parameters . YPosition ! . Value . Clamp ( workArea . Y , workArea . Y + maxHeight - windowHeight ) ;
232+ // Ensure the window position is within the work area bounds (position is calculated in pixels)
233+ windowPositionX = parameters . XPosition ! . Value . Clamp ( workArea . X , workArea . X + workArea . Width - windowWidth . ToPixels ( dpi ) ) ;
234+ windowPositionY = parameters . YPosition ! . Value . Clamp ( workArea . Y , workArea . Y + workArea . Height - windowHeight . ToPixels ( dpi ) ) ;
238235 }
239236 else
240237 {
241- // No position specified, center the window on the current monitor.
242- windowPositionX = workArea . X + ( ( maxWidth - windowWidth ) / 2 ) ;
243- windowPositionY = workArea . Y + ( ( maxHeight - windowHeight ) / 2 ) ;
238+ // No position specified, center the window on the current monitor (position is calculated in pixels)
239+ windowPositionX = workArea . X + ( ( workArea . Width - windowWidth . ToPixels ( dpi ) ) / 2 ) ;
240+ windowPositionY = workArea . Y + ( ( workArea . Height - windowHeight . ToPixels ( dpi ) ) / 2 ) ;
244241 }
245242
246243 window . MoveAndResize (
247- x : windowPositionX . ToPixels ( dpi ) ,
248- y : windowPositionY . ToPixels ( dpi ) ,
244+ x : windowPositionX ,
245+ y : windowPositionY ,
249246 width : windowWidth ,
250247 height : windowHeight ) ;
251248 }
@@ -270,28 +267,25 @@ public static void MoveNearTray(this BaseWindow window, double width, double hei
270267 uint dpi = displayArea . GetDpi ( ) ;
271268 TaskbarEdge taskbarEdge = MonitorCalculator . GetTaskbarEdge ( ) ;
272269
273- double maxWidth = workArea . Width . ToDips ( dpi ) ;
274- double maxHeight = workArea . Height . ToDips ( dpi ) ;
275-
276- // Ensure the window size is within the work area limits
277- double windowWidth = width . Clamp ( window . MinWidth , maxWidth - ( 2 * margin ) ) ;
278- double windowHeight = height . Clamp ( window . MinHeight , maxHeight - ( 2 * margin ) ) ;
270+ // Ensure the window size is within the work area limits (size is calculated in DIPs)
271+ double windowWidth = width . Clamp ( window . MinWidth , workArea . Width . ToDips ( dpi ) - ( 2 * margin ) ) ;
272+ double windowHeight = height . Clamp ( window . MinHeight , workArea . Height . ToDips ( dpi ) - ( 2 * margin ) ) ;
279273
280- // Calculate the position based on the taskbar edge
274+ // Calculate the position based on the taskbar edge (position is calculated in pixels)
281275 double windowPositionX = taskbarEdge switch
282276 {
283277 TaskbarEdge . Left => workArea . X + margin , // Dock to the left
284- _ => workArea . X + maxWidth - windowWidth - margin // Dock to the right
278+ _ => workArea . X + workArea . Width - windowWidth . ToPixels ( dpi ) - margin // Dock to the right
285279 } ;
286280 double windowPositionY = taskbarEdge switch
287281 {
288282 TaskbarEdge . Top => workArea . Y + margin , // Dock to the top
289- _ => workArea . Y + maxHeight - windowHeight - margin // Dock to the bottom
283+ _ => workArea . Y + workArea . Height - windowHeight . ToPixels ( dpi ) - margin // Dock to the bottom
290284 } ;
291285
292286 window . MoveAndResize (
293- x : windowPositionX . ToPixels ( dpi ) ,
294- y : windowPositionY . ToPixels ( dpi ) ,
287+ x : windowPositionX ,
288+ y : windowPositionY ,
295289 width : windowWidth ,
296290 height : windowHeight ) ;
297291 }
0 commit comments