Skip to content

Commit 1d47cfd

Browse files
learn-moreJoachimHenze
authored andcommitted
[0.4.11] [WIN32K:NTUSER] Find a better position for a menu that is off-screen
Previously, we would just stick the menu on the edge of the screen. We should actually try to flip the menu around the point of origin, and only when that fails move it to the edge of the screen. CORE-15001 CORE-9037 cherry picked from commit 0.4.12-dev-346-g d2626f0
1 parent ff0886d commit 1d47cfd

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

win32ss/user/ntuser/menu.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,19 +2903,45 @@ static BOOL FASTCALL MENU_ShowPopup(PWND pwndOwner, PMENU menu, UINT id, UINT fl
29032903
x -= width - xanchor;
29042904

29052905
if( x + width > monitor->rcMonitor.right)
2906-
x = monitor->rcMonitor.right - width;
2906+
{
2907+
/* If we would flip around our origin, would we go off screen on the other side? */
2908+
if (x - width < monitor->rcMonitor.left)
2909+
x = monitor->rcMonitor.right - width;
2910+
else
2911+
x -= width;
2912+
}
2913+
}
2914+
if( x < monitor->rcMonitor.left )
2915+
{
2916+
/* If we would flip around our origin, would we go off screen on the other side? */
2917+
if (x + width > monitor->rcMonitor.right)
2918+
x = monitor->rcMonitor.left;
2919+
else
2920+
x += width;
29072921
}
2908-
if( x < monitor->rcMonitor.left ) x = monitor->rcMonitor.left;
29092922

29102923
if( y + height > monitor->rcMonitor.bottom)
29112924
{
29122925
if( yanchor && y >= height + yanchor )
29132926
y -= height + yanchor;
29142927

29152928
if( y + height > monitor->rcMonitor.bottom)
2916-
y = monitor->rcMonitor.bottom - height;
2929+
{
2930+
/* If we would flip around our origin, would we go off screen on the other side? */
2931+
if (y - height < monitor->rcMonitor.top)
2932+
y = monitor->rcMonitor.bottom - height;
2933+
else
2934+
y -= height;
2935+
}
2936+
}
2937+
if( y < monitor->rcMonitor.top )
2938+
{
2939+
/* If we would flip around our origin, would we go off screen on the other side? */
2940+
if (y + height > monitor->rcMonitor.bottom)
2941+
y = monitor->rcMonitor.top;
2942+
else
2943+
y += height;
29172944
}
2918-
if( y < monitor->rcMonitor.top ) y = monitor->rcMonitor.top;
29192945

29202946
pWnd = ValidateHwndNoErr( menu->hWnd );
29212947

0 commit comments

Comments
 (0)