提交 d0e6938d 编写于 作者: N neugens

8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected...

8005018: X11: focus problems with openjdk 1.7.0 under gnome3 when selected keyboard is not the first in keyboard list
Summary: Don't consider extraenous bits when checking button mask, so that grabWindowRef on the window is not confused and released correctly
Reviewed-by: art, anthony
上级 8e4d54cc
...@@ -994,10 +994,7 @@ public class XBaseWindow { ...@@ -994,10 +994,7 @@ public class XBaseWindow {
return; return;
} }
int buttonState = 0; int buttonState = 0;
final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons(); buttonState = xbe.get_state() & XConstants.ALL_BUTTONS_MASK;
for (int i = 0; i<buttonsNumber; i++){
buttonState |= (xbe.get_state() & XConstants.buttonsMask[i]);
}
switch (xev.get_type()) { switch (xev.get_type()) {
case XConstants.ButtonPress: case XConstants.ButtonPress:
if (buttonState == 0) { if (buttonState == 0) {
...@@ -1034,12 +1031,12 @@ public class XBaseWindow { ...@@ -1034,12 +1031,12 @@ public class XBaseWindow {
* Checks ButtonRelease released all Mouse buttons * Checks ButtonRelease released all Mouse buttons
*/ */
static boolean isFullRelease(int buttonState, int button) { static boolean isFullRelease(int buttonState, int button) {
final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons(); final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
if (button < 0 || button > buttonsNumber) { if (button < 0 || button > buttonsNumber) {
return buttonState == 0; return buttonState == 0;
} else { } else {
return buttonState == XConstants.buttonsMask[button - 1]; return buttonState == XlibUtil.getButtonMask(button);
} }
} }
......
...@@ -130,6 +130,9 @@ final public class XConstants { ...@@ -130,6 +130,9 @@ final public class XConstants {
public static final long ColormapChangeMask = (1L<<23) ; public static final long ColormapChangeMask = (1L<<23) ;
public static final long OwnerGrabButtonMask = (1L<<24) ; public static final long OwnerGrabButtonMask = (1L<<24) ;
public static final int MAX_BUTTONS = 5;
public static final int ALL_BUTTONS_MASK = (int) (Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask);
/* Event names. Used in "type" field in XEvent structures. Not to be /* Event names. Used in "type" field in XEvent structures. Not to be
confused with event masks above. They start from 2 because 0 and 1 confused with event masks above. They start from 2 because 0 and 1
are reserved in the protocol for errors and replies. */ are reserved in the protocol for errors and replies. */
...@@ -194,34 +197,6 @@ final public class XConstants { ...@@ -194,34 +197,6 @@ final public class XConstants {
public static final int Mod4MapIndex = 6 ; public static final int Mod4MapIndex = 6 ;
public static final int Mod5MapIndex = 7 ; public static final int Mod5MapIndex = 7 ;
/* button masks. Used in same manner as Key masks above. Not to be confused
with button names below. */
public static final int [] buttonsMask = new int []{ 1<<8,
1<<9,
1<<10,
1<<11,
1<<12,
1<<13,
1<<14,
1<<15,
1<<16,
1<<17,
1<<18,
1<<19,
1<<20,
1<<21,
1<<22,
1<<23,
1<<24,
1<<25,
1<<26,
1<<27,
1<<28,
1<<29,
1<<30,
1<<31 };
public static final int AnyModifier = (1<<15) ; /* used in GrabButton, GrabKey */ public static final int AnyModifier = (1<<15) ; /* used in GrabButton, GrabKey */
......
...@@ -1543,6 +1543,10 @@ public final class XToolkit extends UNIXToolkit implements Runnable { ...@@ -1543,6 +1543,10 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
} }
} }
static int getNumberOfButtonsForMask() {
return Math.min(XConstants.MAX_BUTTONS, ((SunToolkit) (Toolkit.getDefaultToolkit())).getNumberOfButtons());
}
private final static String prefix = "DnD.Cursor."; private final static String prefix = "DnD.Cursor.";
private final static String postfix = ".32x32"; private final static String postfix = ".32x32";
private static final String dndPrefix = "DnD."; private static final String dndPrefix = "DnD.";
......
...@@ -596,12 +596,12 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { ...@@ -596,12 +596,12 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
/* this is an attempt to refactor button IDs in : MouseEvent, InputEvent, XlibWrapper and XWindow.*/ /* this is an attempt to refactor button IDs in : MouseEvent, InputEvent, XlibWrapper and XWindow.*/
//reflects a button number similar to MouseEvent.BUTTON1, 2, 3 etc. //reflects a button number similar to MouseEvent.BUTTON1, 2, 3 etc.
for (int i = 0; i < XConstants.buttonsMask.length; i ++){ for (int i = 0; i < XConstants.buttons.length; i ++){
//modifier should be added if : //modifier should be added if :
// 1) current button is now still in PRESSED state (means that user just pressed mouse but not released yet) or // 1) current button is now still in PRESSED state (means that user just pressed mouse but not released yet) or
// 2) if Xsystem reports that "state" represents that button was just released. This only happens on RELEASE with 1,2,3 buttons. // 2) if Xsystem reports that "state" represents that button was just released. This only happens on RELEASE with 1,2,3 buttons.
// ONLY one of these conditions should be TRUE to add that modifier. // ONLY one of these conditions should be TRUE to add that modifier.
if (((state & XConstants.buttonsMask[i]) != 0) != (button == XConstants.buttons[i])){ if (((state & XlibUtil.getButtonMask(i + 1)) != 0) != (button == XConstants.buttons[i])){
//exclude wheel buttons from adding their numbers as modifiers //exclude wheel buttons from adding their numbers as modifiers
if (!wheel_mouse) { if (!wheel_mouse) {
modifiers |= InputEvent.getMaskForButton(i+1); modifiers |= InputEvent.getMaskForButton(i+1);
...@@ -689,7 +689,7 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { ...@@ -689,7 +689,7 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
if (type == XConstants.ButtonPress) { if (type == XConstants.ButtonPress) {
//Allow this mouse button to generate CLICK event on next ButtonRelease //Allow this mouse button to generate CLICK event on next ButtonRelease
mouseButtonClickAllowed |= XConstants.buttonsMask[lbutton]; mouseButtonClickAllowed |= XlibUtil.getButtonMask(lbutton);
XWindow lastWindow = (lastWindowRef != null) ? ((XWindow)lastWindowRef.get()):(null); XWindow lastWindow = (lastWindowRef != null) ? ((XWindow)lastWindowRef.get()):(null);
/* /*
multiclick checking multiclick checking
...@@ -747,7 +747,7 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { ...@@ -747,7 +747,7 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
postEventToEventQueue(me); postEventToEventQueue(me);
if ((type == XConstants.ButtonRelease) && if ((type == XConstants.ButtonRelease) &&
((mouseButtonClickAllowed & XConstants.buttonsMask[lbutton]) != 0) ) // No up-button in the drag-state ((mouseButtonClickAllowed & XlibUtil.getButtonMask(lbutton)) != 0) ) // No up-button in the drag-state
{ {
postEventToEventQueue(me = new MouseEvent((Component)getEventSource(), postEventToEventQueue(me = new MouseEvent((Component)getEventSource(),
MouseEvent.MOUSE_CLICKED, MouseEvent.MOUSE_CLICKED,
...@@ -777,7 +777,7 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { ...@@ -777,7 +777,7 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
/* Update the state variable AFTER the CLICKED event post. */ /* Update the state variable AFTER the CLICKED event post. */
if (type == XConstants.ButtonRelease) { if (type == XConstants.ButtonRelease) {
/* Exclude this mouse button from allowed list.*/ /* Exclude this mouse button from allowed list.*/
mouseButtonClickAllowed &= ~XConstants.buttonsMask[lbutton]; mouseButtonClickAllowed &= ~ XlibUtil.getButtonMask(lbutton);
} }
} }
...@@ -793,12 +793,12 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { ...@@ -793,12 +793,12 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
//this doesn't work for extra buttons because Xsystem is sending state==0 for every extra button event. //this doesn't work for extra buttons because Xsystem is sending state==0 for every extra button event.
// we can't correct it in MouseEvent class as we done it with modifiers, because exact type (DRAG|MOVE) // we can't correct it in MouseEvent class as we done it with modifiers, because exact type (DRAG|MOVE)
// should be passed from XWindow. // should be passed from XWindow.
final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons(); final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
for (int i = 0; i < buttonsNumber; i++){ for (int i = 0; i < buttonsNumber; i++){
// TODO : here is the bug in WM: extra buttons doesn't have state!=0 as they should. // TODO : here is the bug in WM: extra buttons doesn't have state!=0 as they should.
if ((i != 4) && (i != 5)) { if ((i != 4) && (i != 5)) {
mouseKeyState = mouseKeyState | (xme.get_state() & XConstants.buttonsMask[i]); mouseKeyState = mouseKeyState | (xme.get_state() & XlibUtil.getButtonMask(i + 1));
} }
} }
......
...@@ -2070,12 +2070,12 @@ class XWindowPeer extends XPanelPeer implements WindowPeer, ...@@ -2070,12 +2070,12 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
} }
if (isGrabbed()) { if (isGrabbed()) {
boolean dragging = false; boolean dragging = false;
final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons(); final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
for (int i = 0; i < buttonsNumber; i++){ for (int i = 0; i < buttonsNumber; i++){
// here is the bug in WM: extra buttons doesn't have state!=0 as they should. // here is the bug in WM: extra buttons doesn't have state!=0 as they should.
if ((i != 4) && (i != 5)){ if ((i != 4) && (i != 5)){
dragging = dragging || ((xme.get_state() & XConstants.buttonsMask[i]) != 0); dragging = dragging || ((xme.get_state() & XlibUtil.getButtonMask(i + 1)) != 0);
} }
} }
// When window is grabbed, all events are dispatched to // When window is grabbed, all events are dispatched to
......
...@@ -396,4 +396,14 @@ public class XlibUtil ...@@ -396,4 +396,14 @@ public class XlibUtil
return isShapingSupported.booleanValue(); return isShapingSupported.booleanValue();
} }
static int getButtonMask(int button) {
// Button indices start with 1. The first bit in the button mask is the 8th.
// The state mask does not support button indicies > 5, so we need to
// cut there.
if (button <= 0 || button > XConstants.MAX_BUTTONS) {
return 0;
} else {
return 1 << (7 + button);
}
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册