< prev index next >
src/java.desktop/windows/classes/sun/awt/Win32GraphicsEnvironment.java
Print this page
@@ -24,16 +24,19 @@
*/
package sun.awt;
import java.awt.AWTError;
+import java.awt.EventQueue;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.peer.ComponentPeer;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.ListIterator;
+import java.util.Set;
import sun.awt.windows.WToolkit;
import sun.java2d.SunGraphicsEnvironment;
import sun.java2d.SurfaceManagerFactory;
import sun.java2d.WindowsSurfaceManagerFactory;
@@ -252,21 +255,34 @@
*/
public static boolean isDWMCompositionEnabled() {
return isDWMCompositionEnabled;
}
+ private static final Set<Runnable> dwmCompositionChangeListeners = new HashSet<>();
+
+ public static void addDwmCompositionChangeListener(Runnable listener) {
+ dwmCompositionChangeListeners.add(listener);
+ }
+
+ public static void removeDwmCompositionChangeListener(Runnable listener) {
+ dwmCompositionChangeListeners.remove(listener);
+ }
+
/**
- * Called from the native code when DWM composition state changed.
- * May be called multiple times during the lifetime of the application.
- * REMIND: we may want to create a listener mechanism for this.
+ * Called from the native code when DWM composition state changed. May be
+ * called multiple times during the lifetime of the application.
*
* Note: called on the Toolkit thread, no user code or locks are allowed.
*
* @param enabled indicates the state of dwm composition
*/
private static void dwmCompositionChanged(boolean enabled) {
isDWMCompositionEnabled = enabled;
+ if (dwmCompositionChangeListeners != null) {
+ EventQueue.invokeLater(()
+ -> dwmCompositionChangeListeners.forEach(Runnable::run));
+ }
}
/**
* Used to find out if the OS is Windows Vista or later.
*
< prev index next >