@@ -3006,7 +3006,8 @@ public Point map (Control from, Control to, int x, int y) {
30063006 checkDevice ();
30073007 Point mappedPointInPoints ;
30083008 if (from == null ) {
3009- Point mappedPointInpixels = mapInPixels (from , to , getPixelsFromPoint (to .getShell ().getMonitor (), x , y ));
3009+ Point translatedPoint = translatePointIfInDisplayCoordinateGap (x , y );
3010+ Point mappedPointInpixels = mapInPixels (from , to , getPixelsFromPoint (to .getShell ().getMonitor (), translatedPoint .x , translatedPoint .y ));
30103011 mappedPointInPoints = DPIUtil .scaleDown (mappedPointInpixels , to .getZoom ());
30113012 } else if (to == null ) {
30123013 Point mappedPointInpixels = mapInPixels (from , to , DPIUtil .scaleUp (new Point (x , y ), from .getZoom ()));
@@ -3119,7 +3120,8 @@ public Rectangle map (Control from, Control to, int x, int y, int width, int hei
31193120 checkDevice ();
31203121 Rectangle mappedRectangleInPoints ;
31213122 if (from == null ) {
3122- Rectangle mappedRectangleInPixels = mapInPixels (from , to , translateRectangleInPixelsInDisplayCoordinateSystem (x , y , width , height , to .getShell ().getMonitor ()));
3123+ Point translatedPoint = translatePointIfInDisplayCoordinateGap (x , y );
3124+ Rectangle mappedRectangleInPixels = mapInPixels (from , to , translateRectangleInPixelsInDisplayCoordinateSystem (translatedPoint .x , translatedPoint .y , width , height , to .getShell ().getMonitor ()));
31233125 mappedRectangleInPoints = DPIUtil .scaleDown (mappedRectangleInPixels , to .getZoom ());
31243126 } else if (to == null ) {
31253127 Rectangle mappedRectangleInPixels = mapInPixels (from , to , DPIUtil .scaleUp (new Rectangle (x , y , width , height ), from .getZoom ()));
@@ -3147,8 +3149,9 @@ Rectangle mapInPixels (Control from, Control to, int x, int y, int width, int he
31473149}
31483150
31493151Point translateLocationInPixelsInDisplayCoordinateSystem (int x , int y ) {
3150- Monitor monitor = getContainingMonitor (x , y );
3151- return getPixelsFromPoint (monitor , x , y );
3152+ Point translatedPoint = translatePointIfInDisplayCoordinateGap (x , y );
3153+ Monitor monitor = getContainingMonitor (translatedPoint .x , translatedPoint .y );
3154+ return getPixelsFromPoint (monitor , translatedPoint .x , translatedPoint .y );
31523155}
31533156
31543157Point translateLocationInPointInDisplayCoordinateSystem (int x , int y ) {
@@ -3157,9 +3160,10 @@ Point translateLocationInPointInDisplayCoordinateSystem(int x, int y) {
31573160}
31583161
31593162Rectangle translateRectangleInPixelsInDisplayCoordinateSystemByContainment (int x , int y , int width , int height ) {
3160- Monitor monitorByLocation = getContainingMonitor (x , y );
3161- Monitor monitorByContainment = getContainingMonitor (x , y , width , height );
3162- return translateRectangleInPixelsInDisplayCoordinateSystem (x , y , width , height , monitorByLocation , monitorByContainment );
3163+ Point translatedPoint = translatePointIfInDisplayCoordinateGap (x , y );
3164+ Monitor monitorByLocation = getContainingMonitor (translatedPoint .x , translatedPoint .y );
3165+ Monitor monitorByContainment = getContainingMonitor (translatedPoint .x , translatedPoint .y , width , height );
3166+ return translateRectangleInPixelsInDisplayCoordinateSystem (translatedPoint .x , translatedPoint .y , width , height , monitorByLocation , monitorByContainment );
31633167}
31643168
31653169private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem (int x , int y , int width , int height , Monitor monitor ) {
@@ -5459,14 +5463,25 @@ private boolean setDPIAwareness(int desiredDpiAwareness) {
54595463}
54605464
54615465private Monitor getContainingMonitor (int x , int y ) {
5466+ return getContainingMonitorOptional (x , y ).orElse (getPrimaryMonitor ());
5467+ }
5468+
5469+ private Optional <Monitor > getContainingMonitorOptional (int x , int y ) {
54625470 Monitor [] monitors = getMonitors ();
54635471 for (Monitor currentMonitor : monitors ) {
54645472 Rectangle clientArea = currentMonitor .getClientArea ();
54655473 if (clientArea .contains (x , y )) {
5466- return currentMonitor ;
5474+ return Optional . of ( currentMonitor ) ;
54675475 }
54685476 }
5469- return getPrimaryMonitor ();
5477+ return Optional .empty ();
5478+ }
5479+
5480+ Point translatePointIfInDisplayCoordinateGap (int x , int y ) {
5481+ if (getContainingMonitorOptional (x , y ).isEmpty () && getContainingMonitorInPixelsCoordinateOptional (x , y ).isPresent ()) {
5482+ return translateLocationInPointInDisplayCoordinateSystem (x , y );
5483+ }
5484+ return new Point (x , y );
54705485}
54715486
54725487private Monitor getContainingMonitor (int x , int y , int width , int height ) {
@@ -5487,14 +5502,18 @@ private Monitor getContainingMonitor(int x, int y, int width, int height) {
54875502}
54885503
54895504private Monitor getContainingMonitorInPixelsCoordinate (int xInPixels , int yInPixels ) {
5505+ return getContainingMonitorInPixelsCoordinateOptional (xInPixels , yInPixels ).orElse (getPrimaryMonitor ());
5506+ }
5507+
5508+ private Optional <Monitor > getContainingMonitorInPixelsCoordinateOptional (int xInPixels , int yInPixels ) {
54905509 Monitor [] monitors = getMonitors ();
54915510 for (Monitor current : monitors ) {
54925511 Rectangle clientArea = getMonitorClientAreaInPixels (current );
54935512 if (clientArea .contains (xInPixels , yInPixels )) {
5494- return current ;
5513+ return Optional . of ( current ) ;
54955514 }
54965515 }
5497- return getPrimaryMonitor ();
5516+ return Optional . empty ();
54985517}
54995518
55005519private Rectangle getMonitorClientAreaInPixels (Monitor monitor ) {
0 commit comments