author Mark Jansen Wed, 9 Jan 2019 21:27:41 +0000 (22:27 +0100) committer Mark Jansen Thu, 10 Jan 2019 18:55:39 +0000 (19:55 +0100)
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

index 0dc6bac..b817759 100644 (file)
x -= width - xanchor;

if( x + width > monitor->rcMonitor.right)
-            x = monitor->rcMonitor.right - width;
+        {
+            /* If we would flip around our origin, would we go off screen on the other side? */
+            if (x - width < monitor->rcMonitor.left)
+                x = monitor->rcMonitor.right - width;
+            else
+                x -= width;
+        }
+    }
+    if( x < monitor->rcMonitor.left )
+    {
+        /* If we would flip around our origin, would we go off screen on the other side? */
+        if (x + width > monitor->rcMonitor.right)
+            x = monitor->rcMonitor.left;
+        else
+            x += width;
}
-    if( x < monitor->rcMonitor.left ) x = monitor->rcMonitor.left;

if( y + height > monitor->rcMonitor.bottom)
{
y -= height + yanchor;

if( y + height > monitor->rcMonitor.bottom)
-            y = monitor->rcMonitor.bottom - height;
+        {
+            /* If we would flip around our origin, would we go off screen on the other side? */
+            if (y - height < monitor->rcMonitor.top)
+                y = monitor->rcMonitor.bottom - height;
+            else
+                y -= height;
+        }
+    }
+    if( y < monitor->rcMonitor.top )
+    {
+        /* If we would flip around our origin, would we go off screen on the other side? */
+        if (y + height > monitor->rcMonitor.bottom)
+            y = monitor->rcMonitor.top;
+        else
+            y += height;
}
-    if( y < monitor->rcMonitor.top ) y = monitor->rcMonitor.top;