Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a profile to run mac sample #2

Merged
merged 8 commits into from Feb 26, 2024

Conversation

carldea
Copy link

@carldea carldea commented Feb 19, 2024

New support for setting dark and light mode for MacOS.

A maven profile for mac was created to detect OS. Windows is default and will build native code if it detects that it is MacOS.

mvn clean install

mvn -f FXThemes-samples javafx:run

@dukke
Copy link
Owner

dukke commented Feb 19, 2024

A general minor comment...
I usually put anything that is implementation detail and isn't strictly necessary for anyone using the library to know about, inside a "impl" directory... what do you think of putting Mac OS specific implementation detail files inside the "impl" directory (files like FXThemes.h, FXThemes.m, FXThemes.xcodeproj directory, etc)?
Do you think that makes sense (maybe that's not even possible though)?

@dukke
Copy link
Owner

dukke commented Feb 19, 2024

Great work @carldea !! Well done! Excited to have Mac support! 👏👏👌
Just added some minor comments to this PR...

After this PR, what will we need to package and publish this as a jar so this library can be used by developers (and app users) on Mac environments like any other library (or close to that experience)?

@carldea
Copy link
Author

carldea commented Feb 20, 2024

A general minor comment...

I usually put anything that is implementation detail and isn't strictly necessary for anyone using the library to know about, inside a "impl" directory... what do you think of putting Mac OS specific implementation detail files inside the "impl" directory (files like FXThemes.h, FXThemes.m, FXThemes.xcodeproj directory, etc)?

Do you think that makes sense (maybe that's not even possible though)?

Yes I noticed that.
I will try and relocate the the code and Xcode projects.

@carldea
Copy link
Author

carldea commented Feb 20, 2024

Great work @carldea !! Well done! Excited to have Mac support! 👏👏👌

Just added some minor comments to this PR...

After this PR, what will we need to package and publish this as a jar so this library can be used by developers (and app users) on Mac environments like any other library (or close to that experience)?

Agreed.
I still may need to copy the native library during runtime to be referenced.

@carldea
Copy link
Author

carldea commented Feb 23, 2024

@dukke The native macos and xcode project has been moved.

I'm am surprised when I tested my code in running the sample application and noticed JNA might already copying the native library automatically. I didn't have to pass in the following JVM options:

-Djava.library.path=FXThemes/target/classes

@dukke
Copy link
Owner

dukke commented Feb 23, 2024

@dukke The native macos and xcode project has been moved.

I'm am surprised when I tested my code in running the sample application and noticed JNA might already copying the native library automatically. I didn't have to pass in the following JVM options:

-Djava.library.path=FXThemes/target/classes

That's great carl!! 👍👍

What do you think about the other comments I made on the PR?

@dukke
Copy link
Owner

dukke commented Feb 25, 2024

Great work Carl! Thanks for looking into my small remarks in this PR.

I think there's only one remark left to address: the comment about why not just use the existing DarkThemeSample on Mac as well as Windows, to test out the feature to change the window frame to a dark color rather than a new sample?

Since we've never talked in depth about it, perhaps I can grab this opportunity and write a bit about what is my initial thinking about this library. How I imagine it to fulfill its purpose and see if you agree or have any comments about that. Just to make sure we're on the same page on this.

My thinking is that programmer users will use FXThemes by calling the same API across all Oses, as much as possible. That is, they can use the same Java code on all platforms, and internally FXThemes will call on specific native code on each platform without the programmers having to know or care about specificities of each OS.
If the programmer does want to use specific functionality that's only available on a specific OS (API that we couldn't make available as platform agnostic) he can cast the ThemeWindowManager to a specific implementation, like for instance Win11ThemeWindowManager and call on API that only exists on Win11.

As much as possible I think we could try to have as much of the API be present in ThemeWindowManager. For this we'll need to figure out what features are available across OSes and have a way to present them to the programmer user in a way that's platform agnostic. All other API that is specific to a particular OS and that we couldn't find a way to present it in ThemeWindowManager, we can put on the OS specific implementation classes of this interface.

Having said this, I think we have already managed to have one API be present in ThemeWindowManager and that is the API to change the window frame to a dark or light appearance. With this in mind I was thinking that we could present this fact (that this API is cross platform) by having only one sample for changing the window frame appearance that can be run on any OS. This would demonstrate that the same code can be run on either Windows or Mac, without change, and present the same result.

Also, if you agree with what I said above but don't agree or want to make changes to the DarkThemeSample code feel free to say so...

@carldea
Copy link
Author

carldea commented Feb 25, 2024

I agree.

Same page:
I must change or remove the profile section that runs the Mac-specific sample to run the default(cross-platform sample).

I like your thinking🙂👍. If the user/dev wants to use specific platform features, they must use the specific functions.

My reasoning & issue I encountered:
Before, when I used the default agnostic version, it did display dark or light themes fine, but it was opaque and not transparent.

Next steps:

  • I will fix it to run like before.
  • I will update the Mac-specific sample with more Javadoc documentation.

To achieve the native blur effect on Mac, the Stage and Color must be set a certain way.

Thank you!

…SampleMac has javadoc docs to demonstrate the Mac specific Blur effect
@dukke
Copy link
Owner

dukke commented Feb 26, 2024

Before, when I used the default agnostic version, it did display dark or light themes fine, but it was opaque and not transparent.

The Windows version doesn't set the background to be transparent either. If you call to change the window frame to dark, the background will be opaque on Windows too.

For reference, a video illustrating the demo running on win11: https://twitter.com/P_Duke/status/1701577162015363556

My thinking for the method themeWindowManager.setDarkModeForWindowFrame(primaryStage, true) is that it just changes the window frame decorations to dark or light (not sure if you agree?), and nothing else (something you can't achieve with the JavaFX API alone as the frame always has the same default light appearance).

However, the API is still in its early stages, and I guess it will probably change as we learn along the way.
When we get to background blur, we're likely going to discuss and see which functionality can be made available in ThemeWindowManager (in a platform agnostic way). That's likely going to require us to check which features are available in each OS regarding this particular functionality and what is the minimum common denominator (which features are available on all OSes).

Thanks! :)

@dukke dukke merged commit 0878a7f into dukke:main Feb 26, 2024
@carldea
Copy link
Author

carldea commented Feb 27, 2024

Thanks for the merge!

I like your suggestion, however, I want to play around more with what’s available (native styling abilities).

Re: boolean
Did you mention we should have a method to detect the platform’s current theme(light/dark)?
Or a callback?

Mac Styles:
A friend shared the following project:
NSWindow Styles
https://t.co/s9xcjUDtuF

It has most of all the native MacOS-supported NSWindow styles similar to your Windows effects.

We could compare to see what’s common for both operating systems. Later, we could see Gnome or Centos.

@dukke
Copy link
Owner

dukke commented Feb 27, 2024

That url with the styles is interesting. Looks like there's a considerable amount of ways to style the window on Mac.

Yes that's it, we should compare and see what's the common denominator. From that link you shared I see that setting an arbitrary color for the window frame seems to be another common feature, although on Windows you only set the window title bar color whereas on Mac you seem to set the whole window color.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants