On 10/23/2013 08:49 PM, David DeHaven wrote:
Not sure about this part. We already force this property to be set in
Embedded without needing any changes in the code you have modified and
I'm not sure if your changes will break what we already do. Why do you
need to do it?
I'm getting concerned about this change touching stuff outside of OSX.
I think I agree with David. E.g. I'm not sure I like changing
j/l/System.c for this fix.
Given the time constraints, perhaps going with HToolkit would be a good
enough solution for now?
Artem, what's your opinion?
I'm personally fine with the current version. The fix is now Mac OS X specific,
as sprops.awt_headless is only set within #ifdef MACOSX, it won't have any
impact on other platforms. At the same time it enables headless functionality
on Mac OS X, while HToolkit doesn't.
Note that it can be improved further. As it stands now, the only purpose of
getPreferredToolkit() is to check if Aqua session is active. The toolkit we use
is always CToolkit, regardless of what this method returns, so the method can
be removed, and isInAquaSession() can be called instead. Leaving this further
cleanup up to David D., though.
The only reason I left it in there was for the AWT_TOOLKIT environment variable
support. Right now if you set AWT_TOOLKIT to HToolkit it will start in headless
mode regardless of what isAquaSession() returns. If we don't care about that
then I'll happily remove it (I'm asking because I don't know if it's used or
not).
For example:
$ AWT_TOOLKIT=HToolkit ./build/macosx-x86_64-normal-server-release/jdk/bin/java
-jar ~/Desktop/SwingSet2.jar
2013-10-23 09:26:21.726 java[23276:707] [JRSAppKitAWT markAppIsDaemon]: Process
manager already initialized: can't fully enable headless mode.
Exception in thread "main" java.awt.HeadlessException
at
sun.java2d.HeadlessGraphicsEnvironment.getDefaultScreenDevice(HeadlessGraphicsEnvironment.java:77)
at SwingSet2.main(SwingSet2.java:224)
But it's *only* implemented on Mac OS X so it doesn't appear to be all that
useful unless we want it implemented for other platforms, which would be a
whole separate issue.
There's a documented way to choose a toolkit: it is the awt.toolkit
system property.
We don't care about AWT_TOOLKIT anymore. It was only relevant at the
time of 1.5 and 1.6 to allow users to switch between MToolkit and
XToolkit. Now that MToolkit is gone, this environment variable isn't needed.
Another option (I think would make everyone happy) would be to add a native
method to LWCToolkit.{java,m} that implements isAquaSession and returns a
boolean. Call this new method in the static initializer and use it's return
value to set java.awt.headless before calling initIDs. This will still be done
early enough that Toolkit.java will end up wrapping LWCToolkit in a
HeadlessToolkit, since it first initializes the wrapped toolkit *then* checks
to see if it needs to be wrapped. Then all that code in java_props* and
System.c could be removed.
I like this idea. But it needs testing.
--
best regards,
Anthony