I made some bugfixes in order to improve support for JMEDesktop on Mac. The buggy behavior for HelloJMEDesktop and TestJMEDesktop is to freeze user input as soon as the mouse enters the window. I identified that much of the problem is related to how Mac handles focus and focusability. I created a minimal patch that makes most of the mouse behavior work on a Mac (testing on 10.5), and I tested that behavior is unchanged on PC. Note that on Mac, this patch removes some focusing functionality which is required for keyboard accessibility, so there is no keyboard accessibility in this version (on Mac); hopefully someone can resolve this in a future version now that basic mouse functionality is working. I've attached the patch file as well as the new modified JMEDesktop file. Please let me know if you have any questions or comments.
Thanks,
Sam Reid
Can you post it as a patch?, that way its easier to see what has changed and also to apply it later.
I included the patch as an attachment to the original email; thanks for pointing out that it was omitted. Let me know if I should also include paste a version in the forum message body to facilitate discussion.
Thanks,
Sam Reid
Will this also fix http://code.google.com/p/jmonkeyengine/issues/detail?id=25 ?
Yes, I verified that this patch allows proper propagation and handling of mouse events in HelloJMEDesktop on Mac 10.5.
Can you please post it using code tags?
Here's my attempt to insert the patch (attached above) in code tags, we'll see how it looks:
Index: JMEDesktop.java
===================================================================
--- JMEDesktop.java (revision 4347)
+++ JMEDesktop.java (working copy)
@@ -221,7 +221,11 @@
}
public boolean isFocused() {
- return true;
+ if (isMac())
+ return super.isFocused();//returning true here causes mac problems regarding mouse control, so we skip it.
+ //This probably causes other problems on mac such as keyboard-mismanagement.
+ else
+ return true;
}
};
awtWindow.setFocusableWindowState( false );
@@ -258,7 +262,7 @@
// this internal frame is a workaround for key binding problems in JDK1.5
// todo: this workaround does not seem to work on mac
- if ( System.getProperty( "os.name" ).toLowerCase().indexOf( "mac" ) < 0 ) {
+ if ( !isMac() ) {
final JInternalFrame internalFrame = new JInternalFrame();
internalFrame.setUI( new BasicInternalFrameUI( internalFrame ) {
protected void installComponents() {
@@ -282,6 +286,11 @@
RepaintManager.currentManager( null ).setDoubleBufferingEnabled( false );
}
+ //Several behaviors are working incorrectly on a mac, mainly regarding focus, mouse events, key events and aqua rendering (though metal rendering looks good).
+ private boolean isMac() {
+ return System.getProperty( "os.name" ).toLowerCase().indexOf( "mac" ) >=0;
+ }
+
/**
* Create a quad with a Swing-Texture.
* Note that for the texture a width and height that is a power of 2 is used if the graphics card does
@@ -876,7 +885,10 @@
}
}
}
- awtWindow.setFocusableWindowState( true );
+ //Setfocusablewindowstate causes a problem on Macs in which the cursor is no longer under control.
+ if (!isMac()){
+ awtWindow.setFocusableWindowState( true );
+ }
Component oldFocusOwner = getFocusOwner();
if ( comp == desktop ) {
comp = null;
@@ -1368,4 +1380,4 @@
public void resize( float width, float height ) {
super.resize(width, height);
}
-}
+}
No newline at end of file