Skip to content

Commit

Permalink
JBR-8254 Buffer X11GraphicsEnvironment.rebuildDevices calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
YaaZ committed Feb 12, 2025
1 parent 3430135 commit 2531d9c
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/java.desktop/unix/classes/sun/awt/X11/XToolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ public void run() {

private int cachedScreenResolution = 72;

private boolean dirtyDevices = false;

/**
* XSETTINGS for the default screen.
* <p>
Expand Down Expand Up @@ -614,28 +616,6 @@ void init() {
System.setProperty(extraButtons, "" + areExtraMouseButtonsEnabled);
// Detect display mode changes
XlibWrapper.XSelectInput(XToolkit.getDisplay(), XToolkit.getDefaultRootWindow(), XConstants.StructureNotifyMask);
XToolkit.addEventDispatcher(XToolkit.getDefaultRootWindow(), new XEventDispatcher() {
@Override
public void dispatchEvent(XEvent ev) {
if (ev.get_type() == XConstants.ConfigureNotify ||
(checkDesktopGeometry && ev.get_type() == XConstants.PropertyNotify &&
ev.get_xproperty().get_atom() == XWM.XA_NET_DESKTOP_GEOMETRY.getAtom())) // possible DPI change
{
awtUnlock();
try {
((X11GraphicsEnvironment)GraphicsEnvironment.
getLocalGraphicsEnvironment()).rebuildDevices();
} finally {
awtLock();
}
} else {
final XAtom XA_NET_WORKAREA = XAtom.get("_NET_WORKAREA");
final boolean rootWindowWorkareaResized = (ev.get_type() == XConstants.PropertyNotify
&& ev.get_xproperty().get_atom() == XA_NET_WORKAREA.getAtom());
if (rootWindowWorkareaResized) resetScreenInsetsCache();
}
}
});
} finally {
awtUnlock();
}
Expand Down Expand Up @@ -861,6 +841,29 @@ private void notifyListeners(XEvent xev) {
private void dispatchEvent(XEvent ev) {
final XAnyEvent xany = ev.get_xany();

if (xany.get_window() == getDefaultRootWindow()) {
if (ev.get_type() == XConstants.ConfigureNotify ||
(checkDesktopGeometry && ev.get_type() == XConstants.PropertyNotify &&
ev.get_xproperty().get_atom() == XWM.XA_NET_DESKTOP_GEOMETRY.getAtom())) // possible DPI change
{
dirtyDevices = true;
} else {
final XAtom XA_NET_WORKAREA = XAtom.get("_NET_WORKAREA");
final boolean rootWindowWorkareaResized = (ev.get_type() == XConstants.PropertyNotify
&& ev.get_xproperty().get_atom() == XA_NET_WORKAREA.getAtom());
if (rootWindowWorkareaResized) resetScreenInsetsCache();
}
} else if (dirtyDevices) {
awtUnlock();
try {
((X11GraphicsEnvironment)GraphicsEnvironment.
getLocalGraphicsEnvironment()).rebuildDevices();
dirtyDevices = false;
} finally {
awtLock();
}
}

XBaseWindow baseWindow = windowToXWindow(xany.get_window());
if (baseWindow != null && (ev.get_type() == XConstants.MotionNotify
|| ev.get_type() == XConstants.EnterNotify
Expand Down

0 comments on commit 2531d9c

Please sign in to comment.