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

A Button pressed with a non-default keyboard layout grabs the window for events

XMLWordPrintable

    • x86
    • linux_ubuntu

      FULL PRODUCT VERSION :
      java version "1.7.0_07"
      Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
      Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux it319k5 3.2.0-29-generic #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      If a Button was pressed when a keyboard layout is non-default, the button grabs the window with sun.awt.X11.setGrabWindow and does not release it when the button is released.

      The code below tries to determine pressed/released button's number from XButtonEvent using bits 8 through 31 (see sun.awt.X11.XConstants), however XButtonEvent supports only 5 buttons with bits 8 through 12 (see X.h ButtonNMotionMask constants). Other bits may be set if keymap is changed, so sun.awt.X11.XBaseWindow.isFullRelease cannot properly handle this case and the Button grabs the current window forever.

      src/solaris/classes/sun/awt/X11/XBaseWindow.java
      /**
           * Activate automatic grab on first ButtonPress,
           * deactivate on full mouse release
           */
          public void handleButtonPressRelease(XEvent xev) {
              XButtonEvent xbe = xev.get_xbutton();
              /*
               * Ignore the buttons above 20 due to the bit limit for
               * InputEvent.BUTTON_DOWN_MASK.
               * One more bit is reserved for FIRST_HIGH_BIT.
               */
              if (xbe.get_button() > SunToolkit.MAX_BUTTONS_SUPPORTED) {
                  return;
              }
              int buttonState = 0;
              final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
              for (int i = 0; i<buttonsNumber; i++){
                  buttonState |= (xbe.get_state() & XConstants.buttonsMask[i]);
              }
              switch (xev.get_type()) {
              case XConstants.ButtonPress:
                  if (buttonState == 0) {
                      XAwtState.setAutoGrabWindow(this);
                  }
                  break;
              case XConstants.ButtonRelease:
                  if (isFullRelease(buttonState, xbe.get_button())) {
                      XAwtState.setAutoGrabWindow(null);
                  }
                  break;
              }
          }

      It is a regression of changes for
      http://bugs.sun.com/view_bug.do?bug_id=6315717

      REGRESSION. Last worked in version 6u31

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Set a focus to JTextField, change a keyboard layout to the non-default one, press the JButton.

      ACTUAL -
      All mouse events are now sending to the window with JButton. You cannot change focus to the second JTextField with a mouse.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.FlowLayout;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JTextField;
      import javax.swing.SwingUtilities;

      public class SwingMain
      {
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      JFrame f2 = new JFrame();
                      f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                      f2.add(new JButton("test"));
                      f2.pack();
                      f2.setVisible(true);

                      JFrame f1 = new JFrame();
                      f1.setLayout(new FlowLayout());
                      f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                      f1.add(new JTextField(10));
                      f1.add(new JTextField(10));

                      f1.pack();
                      f1.setLocationRelativeTo(null);
                      f1.setVisible(true);
                  }
              });
          }
      }
      ---------- END SOURCE ----------

            ssadetsky Semyon Sadetsky (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: