Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8055834

Window.setShape does not work, window fails to pass mouse events through

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3
    • 9
    • 7, 7u5, 7u6, 8, 9
    • client-libs
    • x86
    • os_x

    Description

      FULL PRODUCT VERSION :
      java version "1.7.0_06-ea"
      Java(TM) SE Runtime Environment (build 1.7.0_06-ea-b19)
      Java HotSpot(TM) 64-Bit Server VM (build 23.2-b08, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X 10.7.4 11E53

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      MacPro2,1 2 x 4-core Intel Xeon @ 3GHz, 10 GB RAM
      ATI Radeon X1900 XT 512 MB
      2 Displays (Dell 2007WFB 1050x1680, LG L204WTX 1680x1050)

      A DESCRIPTION OF THE PROBLEM :
      Calls to Window.setShape fail to set the shape of the window, as a result mouse events are not passed through the portions of the rectangular window frame that are not part of the shape. Note that Window.setShape actually throws an exception:

          java.lang.UnsupportedOperationException: PERPIXEL_TRANSPARENT translucency is not supported.

      This is in spite of GraphicsDevice.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT) returning true.

      The older Apple JREs (both Java 1.6 and Java 1.5) provided shaped window support based on the alpha channel of the pixels painted to the window. Transparent pixels passed mouse events. The Apple Java 1.6 AWTUtilities.setWindowShape method also threw this exception, presumably because the window shape was being handled through the painted pixel data. The Oracle/OpenJDK Java 1.7 JRE does not pass mouse events based on the painted pixel data. As a result, mouse events are not passed through as expected.

      The expectation is that the Window.setShape method should work on OS X as it does on other platforms -- setting a shape on the window will allow mouse events to pass through portions of the window that are not part of the provided Shape.

      Note that the demo app at http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html fails to launch with a different exception:

      Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is decorated
      at java.awt.Frame.setOpacity(Frame.java:960)
      at misc.TranslucentWindowDemo$1.run(TranslucentWindowDemo.java:73)

      Clearly there are other issues with the translucent window API in the Mac OS X port. This particular other issue is not effecting our app (it uses an undecorated window).

      REGRESSION. Last worked in version 6u31

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached Java program under Java 1.7.0_06-ea-b19 or 1.7.0_05. Attempt to click on a window below the Java window through the "corners" of the rectangular window that are not covered by the translucent blue ellipse.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Mouse events (i.e. clicks, motion events) should pass through the "corner" regions to underlying windows. Note the output:

      Default screen supports per-pixel translucency
      Default GC is capable

      Clearly the setShape operation should be expected to succeed, and it most certainly should not be claiming that PERPIXEL_TRANSPARENT translucency is not supported.
      ACTUAL -
      Mouse events do not reach the underlying windows.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.UnsupportedOperationException: PERPIXEL_TRANSPARENT translucency is not supported.
      at java.awt.Window.setShape(Window.java:3692)
      at java.awt.Frame.setShape(Frame.java:975)
      at TransWin7$1.run(TransWin7.java:19)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:701)
      at java.awt.EventQueue.access$000(EventQueue.java:102)
      at java.awt.EventQueue$3.run(EventQueue.java:662)
      at java.awt.EventQueue$3.run(EventQueue.java:660)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:671)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.geom.*;
      import javax.swing.*;

      public class TransWin7 {

          public static void main(String[] args) {
      Runnable r = new Runnable() {
      public void run() {
      JFrame f = new JFrame("Shaped Window", findConfig());
      MainPane mainPane = new MainPane();
      f.setUndecorated(true);
      f.setBackground(new Color(0, 0, 0, 0));
      mainPane.setForeground(new Color(0, 0, 255, 127));
      mainPane.setOpaque(false);
      f.getContentPane().add(mainPane);
      f.setBounds(64, 64, 512, 384);
      try {
      f.setShape(new Ellipse2D.Double(0, 0, 511, 383));
      } catch (Throwable t) {
      t.printStackTrace();
      }
      f.setVisible(true);
      }
      };

      SwingUtilities.invokeLater(r);
          }

          public static GraphicsConfiguration findConfig() {
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice gd = ge.getDefaultScreenDevice();
      GraphicsConfiguration gc = gd.getDefaultConfiguration();

      boolean perpixel = gd.isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSLUCENT);
      System.err.println("Default screen " + (perpixel ? "supports" : "does not support") + " per-pixel translucency");
      System.err.println("Default GC is " + (gc.isTranslucencyCapable() ? "capable" : "not capable"));

      return gc;
          }

          private static class MainPane extends JPanel {
      public void paintComponent (Graphics g) {
      g.setColor(getForeground());
      g.fillOval(0, 0, getWidth(), getHeight());
      }
          };
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No workaround found.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              alitvinov Anton Litvinov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: