@@ -263,14 +263,8 @@ public Size FrameSize
263
263
{
264
264
get
265
265
{
266
- if ( DwmIsCompositionEnabled ( out var compositionEnabled ) != 0 || ! compositionEnabled )
267
- {
268
- GetWindowRect ( _hwnd , out var rcWindow ) ;
269
- return new Size ( rcWindow . Width , rcWindow . Height ) / RenderScaling ;
270
- }
271
-
272
- DwmGetWindowAttribute ( _hwnd , ( int ) DwmWindowAttribute . DWMWA_EXTENDED_FRAME_BOUNDS , out var rect , Marshal . SizeOf < RECT > ( ) ) ;
273
- return new Size ( rect . Width , rect . Height ) / RenderScaling ;
266
+ GetWindowRect ( _hwnd , out var rcWindow ) ;
267
+ return new Size ( rcWindow . Width , rcWindow . Height ) / RenderScaling ;
274
268
}
275
269
}
276
270
@@ -510,6 +504,7 @@ private unsafe bool SetUseHostBackdropBrush(bool useHostBackdropBrush)
510
504
var result = DwmSetWindowAttribute ( _hwnd , ( int ) DwmWindowAttribute . DWMWA_USE_HOSTBACKDROPBRUSH , & pvUseBackdropBrush , sizeof ( int ) ) ;
511
505
return result == 0 ;
512
506
}
507
+
513
508
public IEnumerable < object > Surfaces
514
509
=> _glSurface is null ?
515
510
new object [ ] { Handle , _framebuffer } :
@@ -520,15 +515,10 @@ public PixelPoint Position
520
515
get
521
516
{
522
517
GetWindowRect ( _hwnd , out var rc ) ;
523
-
524
- var border = HiddenBorderSize ;
525
- return new PixelPoint ( rc . left + border . Width , rc . top + border . Height ) ;
518
+ return new PixelPoint ( rc . left , rc . top ) ;
526
519
}
527
520
set
528
521
{
529
- var border = HiddenBorderSize ;
530
- value = new PixelPoint ( value . X - border . Width , value . Y - border . Height ) ;
531
-
532
522
SetWindowPos (
533
523
Handle . Handle ,
534
524
IntPtr . Zero ,
@@ -542,23 +532,6 @@ public PixelPoint Position
542
532
543
533
private bool HasFullDecorations => _windowProperties . Decorations == SystemDecorations . Full ;
544
534
545
- private PixelSize HiddenBorderSize
546
- {
547
- get
548
- {
549
- // Windows 10 and 11 add a 7 pixel invisible border on the left/right/bottom of windows for resizing
550
- if ( Win32Platform . WindowsVersion . Major < 10 || ! HasFullDecorations || GetStyle ( ) . HasFlag ( WindowStyles . WS_POPUP ) )
551
- {
552
- return PixelSize . Empty ;
553
- }
554
-
555
- DwmGetWindowAttribute ( _hwnd , ( int ) DwmWindowAttribute . DWMWA_EXTENDED_FRAME_BOUNDS , out var clientRect , Marshal . SizeOf < RECT > ( ) ) ;
556
- GetWindowRect ( _hwnd , out var frameRect ) ;
557
- var borderWidth = GetSystemMetrics ( SystemMetric . SM_CXBORDER ) ;
558
-
559
- return new PixelSize ( clientRect . left - frameRect . left - borderWidth , 0 ) ;
560
- }
561
- }
562
535
563
536
public void Move ( PixelPoint point ) => Position = point ;
564
537
@@ -594,25 +567,29 @@ public void Resize(Size value, WindowResizeReason reason)
594
567
595
568
GetWindowPlacement ( _hwnd , out var windowPlacement ) ;
596
569
597
- var clientScreenOrigin = new POINT ( ) ;
598
- ClientToScreen ( _hwnd , ref clientScreenOrigin ) ;
599
-
600
570
var requestedClientRect = new RECT
601
571
{
602
- left = clientScreenOrigin . X ,
603
- right = clientScreenOrigin . X + requestedClientWidth ,
604
-
605
- top = clientScreenOrigin . Y ,
606
- bottom = clientScreenOrigin . Y + requestedClientHeight ,
572
+ left = 0 ,
573
+ top = 0 ,
574
+ right = requestedClientWidth ,
575
+ bottom = requestedClientHeight
607
576
} ;
608
577
609
578
var requestedWindowRect = _isClientAreaExtended ? requestedClientRect : ClientRectToWindowRect ( requestedClientRect ) ;
579
+ var windowWidth = requestedWindowRect . Width ;
580
+ var windowHeight = requestedWindowRect . Height ;
610
581
611
- if ( requestedWindowRect . Width == windowPlacement . NormalPosition . Width && requestedWindowRect . Height == windowPlacement . NormalPosition . Height )
582
+ if ( windowWidth == windowPlacement . NormalPosition . Width && windowHeight == windowPlacement . NormalPosition . Height )
612
583
{
613
584
return ;
614
585
}
615
586
587
+ var position = Position ;
588
+ requestedWindowRect . left = position . X ;
589
+ requestedWindowRect . top = position . Y ;
590
+ requestedWindowRect . right = position . X + windowWidth ;
591
+ requestedWindowRect . bottom = position . Y + windowHeight ;
592
+
616
593
windowPlacement . NormalPosition = requestedWindowRect ;
617
594
618
595
windowPlacement . ShowCmd = ! _shown ? ShowWindowCommand . Hide : _lastWindowState switch
@@ -1025,14 +1002,8 @@ private void SetFullScreen(bool fullscreen)
1025
1002
if ( fullscreen )
1026
1003
{
1027
1004
GetWindowRect ( _hwnd , out var windowRect ) ;
1028
- GetClientRect ( _hwnd , out var clientRect ) ;
1029
-
1030
- clientRect . left += windowRect . left ;
1031
- clientRect . right += windowRect . left ;
1032
- clientRect . top += windowRect . top ;
1033
- clientRect . bottom += windowRect . top ;
1034
1005
1035
- _savedWindowInfo . WindowRect = clientRect ;
1006
+ _savedWindowInfo . WindowRect = windowRect ;
1036
1007
1037
1008
var current = GetStyle ( ) ;
1038
1009
var currentEx = GetExtendedStyle ( ) ;
@@ -1141,16 +1112,8 @@ private void ExtendClientArea()
1141
1112
_isClientAreaExtended = false ;
1142
1113
return ;
1143
1114
}
1144
- GetClientRect ( _hwnd , out var rcClient ) ;
1145
1115
GetWindowRect ( _hwnd , out var rcWindow ) ;
1146
1116
1147
- // Inform the application of the frame change.
1148
- SetWindowPos ( _hwnd ,
1149
- IntPtr . Zero ,
1150
- rcWindow . left , rcWindow . top ,
1151
- rcClient . Width , rcClient . Height ,
1152
- SetWindowPosFlags . SWP_FRAMECHANGED | SetWindowPosFlags . SWP_NOACTIVATE ) ;
1153
-
1154
1117
if ( _isClientAreaExtended && WindowState != WindowState . FullScreen )
1155
1118
{
1156
1119
var margins = UpdateExtendMargins ( ) ;
@@ -1170,8 +1133,6 @@ private void ExtendClientArea()
1170
1133
_offScreenMargin = new Thickness ( ) ;
1171
1134
_extendedMargins = new Thickness ( ) ;
1172
1135
1173
- Resize ( new Size ( rcWindow . Width / RenderScaling , rcWindow . Height / RenderScaling ) , WindowResizeReason . Layout ) ;
1174
-
1175
1136
unsafe
1176
1137
{
1177
1138
int cornerPreference = ( int ) DwmWindowCornerPreference . DWMWCP_DEFAULT ;
@@ -1189,6 +1150,13 @@ private void ExtendClientArea()
1189
1150
DisableCloseButton ( _hwnd ) ;
1190
1151
}
1191
1152
1153
+ // Inform the application of the frame change.
1154
+ SetWindowPos ( _hwnd ,
1155
+ IntPtr . Zero ,
1156
+ rcWindow . left , rcWindow . top ,
1157
+ 0 , 0 ,
1158
+ SetWindowPosFlags . SWP_FRAMECHANGED | SetWindowPosFlags . SWP_NOACTIVATE | SetWindowPosFlags . SWP_NOSIZE ) ;
1159
+
1192
1160
ExtendClientAreaToDecorationsChanged ? . Invoke ( _isClientAreaExtended ) ;
1193
1161
}
1194
1162
@@ -1454,7 +1422,7 @@ private void UpdateWindowProperties(WindowProperties newProperties, bool forceCh
1454
1422
{
1455
1423
style &= ~ ( fullDecorationFlags | WindowStyles . WS_THICKFRAME ) ;
1456
1424
1457
- if ( newProperties . Decorations == SystemDecorations . BorderOnly && newProperties . WindowState != WindowState . Maximized )
1425
+ if ( newProperties . Decorations == SystemDecorations . BorderOnly && newProperties . WindowState != WindowState . Maximized && newProperties . IsResizable )
1458
1426
{
1459
1427
style |= WindowStyles . WS_THICKFRAME | WindowStyles . WS_BORDER ;
1460
1428
}
@@ -1483,8 +1451,6 @@ private void UpdateWindowProperties(WindowProperties newProperties, bool forceCh
1483
1451
1484
1452
if ( ! _isFullScreenActive && ( ( oldProperties . Decorations != newProperties . Decorations ) || forceChanges ) )
1485
1453
{
1486
- var style = GetStyle ( ) ;
1487
-
1488
1454
var margin = newProperties . Decorations == SystemDecorations . BorderOnly ? 1 : 0 ;
1489
1455
1490
1456
var margins = new MARGINS
@@ -1497,23 +1463,11 @@ private void UpdateWindowProperties(WindowProperties newProperties, bool forceCh
1497
1463
1498
1464
DwmExtendFrameIntoClientArea ( _hwnd , ref margins ) ;
1499
1465
1500
-
1501
1466
if ( _shown || forceChanges )
1502
1467
{
1503
- GetClientRect ( _hwnd , out var oldClientRect ) ;
1504
- var oldClientRectOrigin = new POINT ( ) ;
1505
- ClientToScreen ( _hwnd , ref oldClientRectOrigin ) ;
1506
- oldClientRect . Offset ( oldClientRectOrigin ) ;
1507
-
1508
- var newRect = oldClientRect ;
1509
-
1510
- if ( newProperties . Decorations == SystemDecorations . Full )
1511
- {
1512
- AdjustWindowRectEx ( ref newRect , ( uint ) style , false , ( uint ) GetExtendedStyle ( ) ) ;
1513
- }
1514
-
1515
- SetWindowPos ( _hwnd , IntPtr . Zero , newRect . left , newRect . top , newRect . Width , newRect . Height ,
1468
+ SetWindowPos ( _hwnd , IntPtr . Zero , 0 , 0 , 0 , 0 ,
1516
1469
SetWindowPosFlags . SWP_NOZORDER | SetWindowPosFlags . SWP_NOACTIVATE |
1470
+ SetWindowPosFlags . SWP_NOSIZE | SetWindowPosFlags . SWP_NOMOVE |
1517
1471
SetWindowPosFlags . SWP_FRAMECHANGED ) ;
1518
1472
}
1519
1473
}
0 commit comments