Skip to content

Commit 5d27af7

Browse files
committed
Tooltip Infinite Loop fix for per-monitor #557
This commit contributes to fixing the infinite looping effect on showing a tooltip of the tree using per-monitor (V2) awareness on win32 when a tooltip is spans over two monitors having more area on the other monitor than the one on which the cursor is placed. The fix makes sure that the tooltip is not drawn on the other monitors by shifting or adjusting the width. contributes to #557
1 parent c2136c9 commit 5d27af7

File tree

1 file changed

+20
-0
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+20
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8161,6 +8161,26 @@ LRESULT wmNotifyToolTip (NMHDR hdr, long wParam, long lParam) {
81618161
int height = toolRect.bottom - toolRect.top;
81628162
int flags = OS.SWP_NOACTIVATE | OS.SWP_NOZORDER | OS.SWP_NOSIZE;
81638163
if (isCustomToolTip ()) flags &= ~OS.SWP_NOSIZE;
8164+
// Retrieve the monitor containing the cursor position, as tooltip placement
8165+
// must occur on the same monitor to avoid potential infinite loops. When a tooltip
8166+
// appears on a different monitor than the cursor, the operating system may
8167+
// attempt to rescale it based on that monitor's settings. This rescaling
8168+
// triggers additional display messages to SWT, creating an infinite loop
8169+
// of positioning and rescaling events.
8170+
Point cursorLocation = display.getCursorLocation();
8171+
if (cursorLocation instanceof MonitorAwarePoint map) {
8172+
Monitor monitor = map.getMonitor();
8173+
Rectangle monitorBounds = new Rectangle(monitor.x, monitor.y, DPIUtil.scaleUp(monitor.width, monitor.zoom), DPIUtil.scaleUp(monitor.height, monitor.zoom));
8174+
System.out.println(monitor.x + " " + toolRect.left);
8175+
if(toolRect.left < monitor.x) {
8176+
int offset = monitor.x - toolRect.left;
8177+
toolRect.left += offset;
8178+
}
8179+
if((toolRect.left + width) > (monitorBounds.x + monitorBounds.width)) {
8180+
int offset = (toolRect.left + width) - (monitorBounds.x + monitorBounds.width);
8181+
width -= offset;
8182+
}
8183+
}
81648184
OS.SetWindowPos (itemToolTipHandle, 0, toolRect.left, toolRect.top, width, height, flags);
81658185
return LRESULT.ONE;
81668186
}

0 commit comments

Comments
 (0)