Skip to content

Commit

Permalink
Find/replace overlay: react to target relocation instead of paint events
Browse files Browse the repository at this point in the history
The FindReplaceOverlay currently registers a paint listener to the target
in order to reposition itself upon move or resize events of the parent
(paint events subsume resize and move events). This has two drawbacks:
1. The update is performed too often, as paint events happen more often
than move or resize events
2. Due to limitations in Wayland, repositioning the overlay does not
work there. A combination of processed repaint events and failing
position updates even leads to the shell contents moving out of the
shell.

This change replaces the repaint listener with a move and resize
listener. In consequence, less (unnecessary) updates of the overlay's
position and size are executed and on Wayland at least the shell
contents do not move out of the window anymore.

Contributes to
eclipse-platform/eclipse.platform.swt#1447
  • Loading branch information
HeikoKlare committed Sep 12, 2024
1 parent 6368b06 commit 52470ac
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
Expand All @@ -42,6 +41,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Scrollable;
import org.eclipse.swt.widgets.Shell;
Expand Down Expand Up @@ -204,7 +204,7 @@ public void controlResized(ControlEvent e) {
}
};

private PaintListener widgetMovementListener = __ -> asyncExecIfOpen(
private Listener targetRelocationListener = __ -> asyncExecIfOpen(
FindReplaceOverlay.this::updatePlacementAndVisibility);

private void asyncExecIfOpen(Runnable operation) {
Expand Down Expand Up @@ -423,7 +423,8 @@ private void unbindListeners() {
Control targetWidget = textEditor.getAdapter(ITextViewer.class).getTextWidget();
if (targetWidget != null) {
targetWidget.getShell().removeControlListener(shellMovementListener);
targetWidget.removePaintListener(widgetMovementListener);
targetWidget.removeListener(SWT.Move, targetRelocationListener);
targetWidget.removeListener(SWT.Resize, targetRelocationListener);
targetWidget.removeKeyListener(closeOnTargetEscapeListener);
targetPart.getSite().getPage().removePartListener(targetPartVisibilityHandler);
}
Expand All @@ -436,7 +437,8 @@ private void bindListeners() {
Control targetWidget = textEditor.getAdapter(ITextViewer.class).getTextWidget();

targetWidget.getShell().addControlListener(shellMovementListener);
targetWidget.addPaintListener(widgetMovementListener);
targetWidget.addListener(SWT.Move, targetRelocationListener);
targetWidget.addListener(SWT.Resize, targetRelocationListener);
targetWidget.addKeyListener(closeOnTargetEscapeListener);
targetPart.getSite().getPage().addPartListener(targetPartVisibilityHandler);
}
Expand Down

0 comments on commit 52470ac

Please sign in to comment.