[External] : Re: Platform preferences theme detection
Kevin Rushforth
kevin.rushforth at oracle.com
Mon Feb 12 17:53:56 UTC 2024
Never mind about not knowing whether it's a JavaFX or an AWT bug. It's
either a JavaFX bug or an inherent limitation.
The problem you are running into is that when the AWT toolkit is
initialized before the JavaFX toolkit, then necessarily, AWT is in
charge of the NSApplication. Prior to the macOS 14 fixes I was
mentioning, AWT used to take change even when it shouldn't have, but now
that's been fixed (both in AWT and JavaFX). Whichever toolkit is started
first owns the NSApplication, and installs its NSApplicationDelegate.
This means that NSApplication{Delegate} callbacks are only delivered to
the toolkit that owns it.
I haven't checked this, but my guess is that the
"NSDistributedNotificationCenter" methods being used to listen to
preferences don't get called when JavaFX is not the NSApplication owner.
-- Kevin
On 2/12/2024 9:26 AM, Kevin Rushforth wrote:
> Actually, it's worse than not detecting changes, it's simply not
> getting the right values at all. If I run the program when the system
> appearance is already in Dark mode, it doesn't get the correct values
> at start up.
>
> -- Kevin
>
> On 2/12/2024 9:20 AM, Kevin Rushforth wrote:
>> I can reproduce this on macOS 13.x using JDK 21.0.2 and the latest
>> JavaFX. If I run the PlatformPreferencesChangedTest program in
>> tests/manual/events we correctly detect the appearance changes. If I
>> first initialize the AWT toollkit as follows, then it doesn't detect
>> the changes:
>>
>> public static void main(String[] args) {
>> java.awt.Toolkit.getDefaultToolkit();
>> PlatformPreferencesChangedTest.main(args);
>> }
>>
>> I'll file a bug...not sure yet whether it is AWT or JavaFX.
>>
>> -- Kevin
>>
>> On 2/12/2024 9:00 AM, Christopher Schnick wrote:
>>>
>>> Just tested with JDK 21.0.2 and the behavior is unchanged. I don't
>>> have an older macOS version <14 to test whether this issue is
>>> actually specific to 14 or not.
>>>
>>> On 12/02/2024 17:49, Kevin Rushforth wrote:
>>>> There were changes to AWT in JDK 22 for macOS 14, so it might be
>>>> worth trying JDK 21.0.2. In the mean time, I'll do some testing of
>>>> this as well now that I know it is related to initializing the AWT
>>>> toolkit.
>>>>
>>>> -- Kevin
>>>>
>>>>
>>>> On 2/12/2024 8:36 AM, Christopher Schnick wrote:
>>>>>
>>>>> I am using JDK 21+35 and JavaFX 22-ea+28 to run the project on
>>>>> macOS. I guess I can try upgrading to JDK 21.0.2, but I will just
>>>>> assume that there haven't been many changes to awt in that time.
>>>>>
>>>>> Interestingly, I found another issue that occurs when that call to
>>>>> |GraphicsEnvironment| is made/not made where it is not possible to
>>>>> quit a JavaFX application via the dock quit operation when it is
>>>>> minimized to an AWT tray icon. I can file a separate issue for that.
>>>>>
>>>>> On 12/02/2024 17:20, Kevin Rushforth wrote:
>>>>>> That likely means that initializing the AWT toolkit is
>>>>>> interfering with this functionality.
>>>>>>
>>>>>> I presume you are using a very recent ea build of JavaFX 22. What
>>>>>> version of JDK are you using?
>>>>>>
>>>>>> -- Kevin
>>>>>>
>>>>>>
>>>>>> On 2/10/2024 9:05 PM, Christopher Schnick wrote:
>>>>>>>
>>>>>>> Well, that is going to be a fun one to debug ... In my
>>>>>>> application I check for a headless environment with
>>>>>>> GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices().
>>>>>>> If you call that one before you initialize your application, the
>>>>>>> preferences detection does no longer update. So if you augment
>>>>>>> your PlatformPreferencesChangedTest application with this main
>>>>>>> method, it no longer works. Also, it throws another exception
>>>>>>> when clicking on the fail button.
>>>>>>>
>>>>>>> | public static void main(String[] args) {
>>>>>>> GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
>>>>>>> Application.launch(args);
>>>>>>> }|
>>>>>>>
>>>>>>> On 10/02/2024 18:44, Michael Strauß wrote:
>>>>>>>> Since I can't reproduce the error on macOS, it's hard to say what
>>>>>>>> could be causing it.
>>>>>>>>
>>>>>>>> If you have the chance, maybe you could run the
>>>>>>>> PlatformPreferencesChangedTest application:
>>>>>>>> https://github.com/openjdk/jfx/blob/master/tests/manual/events/PlatformPreferencesChangedTest.java
>>>>>>>>
>>>>>>>> That might rule out that the differences we're seeing have anything to
>>>>>>>> do with the way we're using the API.
>>>>>>>>
>>>>>>>>
>>>>>>>> On Sat, Feb 10, 2024 at 6:23 PM Christopher Schnick<crschnick at xpipe.io> wrote:
>>>>>>>>> I checked again, restarted everything, but still the same problem:
>>>>>>>>>
>>>>>>>>> Furthermore, I also tested it on my Asahi Fedora Linux with the latest KDE Plasma. The preferences values there are all detected correctly, but are never updated at runtime when changed in the settings menu.
>>>>>>
>>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20240212/83c9b9a7/attachment.htm>
More information about the openjfx-dev
mailing list