Skip to content

Commit 1a7eaaf

Browse files
committed
Fix always-on-top notification popup
1 parent 219e540 commit 1a7eaaf

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

app/src/cc/arduino/contributions/ContributionsSelfCheck.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@
3636
import cc.arduino.view.NotificationPopup;
3737
import processing.app.Base;
3838
import processing.app.BaseNoGui;
39+
import processing.app.Editor;
3940
import processing.app.I18n;
4041

4142
import javax.swing.*;
4243
import javax.swing.event.HyperlinkListener;
44+
45+
import java.awt.event.WindowEvent;
46+
import java.awt.event.WindowFocusListener;
4347
import java.util.TimerTask;
4448

4549
import static processing.app.I18n.tr;
@@ -95,8 +99,30 @@ public void run() {
9599
}
96100

97101
SwingUtilities.invokeLater(() -> {
98-
notificationPopup = new NotificationPopup(base.getActiveEditor(), hyperlinkListener, text);
99-
notificationPopup.setVisible(true);
102+
Editor ed = base.getActiveEditor();
103+
notificationPopup = new NotificationPopup(ed, hyperlinkListener, text);
104+
if (ed.isFocused()) {
105+
notificationPopup.setVisible(true);
106+
return;
107+
}
108+
109+
// If the IDE is not focused wait until it is focused again to
110+
// display the notification, this avoids the annoying side effect
111+
// to "steal" the focus from another application.
112+
WindowFocusListener wfl = new WindowFocusListener() {
113+
@Override
114+
public void windowLostFocus(WindowEvent evt) {
115+
}
116+
117+
@Override
118+
public void windowGainedFocus(WindowEvent evt) {
119+
notificationPopup.setVisible(true);
120+
for (Editor e : base.getEditors())
121+
e.removeWindowFocusListener(this);
122+
}
123+
};
124+
for (Editor e : base.getEditors())
125+
e.addWindowFocusListener(wfl);
100126
});
101127
}
102128

app/src/cc/arduino/view/NotificationPopup.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public NotificationPopup(Frame parent, HyperlinkListener hyperlinkListener,
6161
super(parent, false);
6262
setLayout(new FlowLayout());
6363
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
64-
setAlwaysOnTop(true);
6564
setUndecorated(true);
6665
setResizable(false);
6766

0 commit comments

Comments
 (0)