Skip to content

Commit 9b9236b

Browse files
committed
JBR-8673 Disable watch.desktop.geometry on excessive event count
1 parent e62ca34 commit 9b9236b

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java

+22-5
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,12 @@ public static long getDefaultRootWindow() {
595595
}
596596
}
597597

598-
private static final boolean checkDesktopGeometry = !"false".equals(System.getProperty("watch.desktop.geometry", "true"));
598+
private static boolean checkDesktopGeometry = !"false".equals(System.getProperty("watch.desktop.geometry", "true"));
599+
// In case we are for some reason being spammed with display reconfiguration events (KDE?),
600+
// we can stop reacting to those events. The current threshold is 20 events/sec.
601+
private static final long DISABLE_WATCH_DESKTOP_GEOMETRY_TIME = 1000;
602+
private static final long DISABLE_WATCH_DESKTOP_GEOMETRY_EVENT_COUNT = 20;
603+
private static long lastDesktopGeometrySequenceTimestamp, lastDesktopGeometrySequenceEventCount;
599604

600605
void init() {
601606
awtLock();
@@ -842,11 +847,23 @@ private void dispatchEvent(XEvent ev) {
842847
final XAnyEvent xany = ev.get_xany();
843848

844849
if (xany.get_window() == getDefaultRootWindow()) {
845-
if (ev.get_type() == XConstants.ConfigureNotify ||
846-
(checkDesktopGeometry && ev.get_type() == XConstants.PropertyNotify &&
847-
ev.get_xproperty().get_atom() == XWM.XA_NET_DESKTOP_GEOMETRY.getAtom())) // possible DPI change
848-
{
850+
if (ev.get_type() == XConstants.ConfigureNotify) {
851+
dirtyDevices = true;
852+
} else if (checkDesktopGeometry && ev.get_type() == XConstants.PropertyNotify &&
853+
ev.get_xproperty().get_atom() == XWM.XA_NET_DESKTOP_GEOMETRY.getAtom()) { // possible DPI change
849854
dirtyDevices = true;
855+
// Count the number of such events and disable geometry check if we are getting spammed.
856+
long time = System.currentTimeMillis();
857+
if (time <= lastDesktopGeometrySequenceTimestamp + DISABLE_WATCH_DESKTOP_GEOMETRY_TIME) {
858+
lastDesktopGeometrySequenceEventCount++;
859+
if (lastDesktopGeometrySequenceEventCount >= DISABLE_WATCH_DESKTOP_GEOMETRY_EVENT_COUNT) {
860+
checkDesktopGeometry = false;
861+
System.err.println("XToolkit: too many _NET_DESKTOP_GEOMETRY events, disabling watch.desktop.geometry");
862+
}
863+
} else {
864+
lastDesktopGeometrySequenceTimestamp = time;
865+
lastDesktopGeometrySequenceEventCount = 1;
866+
}
850867
} else {
851868
final XAtom XA_NET_WORKAREA = XAtom.get("_NET_WORKAREA");
852869
final boolean rootWindowWorkareaResized = (ev.get_type() == XConstants.PropertyNotify

0 commit comments

Comments
 (0)