dukke / FXThemes

Utility classes for advanced Theme development for JavaFX (Java)
https://pixelduke.com/fxthemes
37 stars 4 forks source link

Windows 10 - Issue with getting acrylic working... #7

Open regice202 opened 1 month ago

regice202 commented 1 month ago

Hello @dukke! I've finally gotten this library working for me, but I'm having an issue still atm... I'm trying to go off of the examples you sent, and it's working for the most part. I can get dark theme to work just fine. Acrylic on Windows 10, I haven't gotten quite working just yet.. I'm posting my code and some photos down below to help illustrate the issue I'm having. Thanks for your time and help!

stage.addEventHandler(WindowEvent.ANY, new EventHandler<WindowEvent>(){
            @Override
            public void handle(WindowEvent e){
                String type = e.getEventType().getName();

                System.out.println("Window event: " + type);
                switch(type){
                    case "WINDOW_SHOWING": case "WINDOW_SHOWN":
                        if (type.equals("WINDOW_SHOWING")) themeManager = ThemeWindowManagerFactory.create();

                        switch(themeManager.getClass().getSimpleName().replaceFirst(ThemeWindowManager.class.getSimpleName(), "")){
                            case "Mac":
                                MacThemeWindowManager mac = (MacThemeWindowManager) themeManager;
                                break;
                            case "Win10":
                                Win10ThemeWindowManager win10 = (Win10ThemeWindowManager) themeManager;

//                                System.setProperty("prism.forceUploadingPainter", "true");
                                if (type.equals("WINDOW_SHOWING")){
                                    stage.getScene().getRoot().setStyle("-fx-background-color: transparent;");
                                    stage.getScene().setFill(Color.TRANSPARENT);
                                    stage.initStyle(StageStyle.TRANSPARENT);
                                }else{
                                    /*Frost - Alpha|AA| Blue,Green,Red|BBGGRR|*/
                                    int opacity = 0x7D, background = 0xFFFFFF;
//                                    System.out.println("Gradient: " + Integer.toHexString(opacity << 24 | background & 16777215));
                                    win10.enableAcrylic(stage, opacity, background);
//                                    win10.enableAcrylic(stage, 100, 0x990500);
                                }
                                break;
                            case "Win11":
                                Win11ThemeWindowManager win11 = (Win11ThemeWindowManager) themeManager;
                                break;
                            default:
                                themeManager = null;
                                break;
                        }

                        if (themeManager != null){
//                            themeManager.setDarkModeForWindowFrame(stage, true);
                        }
                        break;
                }
            }
        });

It appears for a moment to be working... java_40mjgReksk

Then.. it just removes the entire window and makes it Undecorated basically.. java_4yMXvb5Uq9

And here you can see Dark Mode working! :D java_1abjNL3YdU

dukke commented 1 month ago

Hi @regice202

Yes, it isn't yet working for windows 10, that's in the documentation under the "A few considerations" section.

I've spent quite some time trying to make it work on win10 but wasn't able to. However, it's curious that you made it work for some time which I wasn't even able to. Did you do anything special to make it work?

A few things we have to consider: we're sometimes hacking our way through JavaFX. JavaFX doesn't support this feature out of the box and sometimes it can also make it almost impossible to work. On windows11 I was able to make it work but I had to set the "prism.forceUploadingPainter" to true. In windows 10 even if you do that it still doesn't seem to work. One other thing is that you also have to consider that different graphics cards might also yield different results (not just different OSes).

All in all, it seems that JavaFX doesn't actually honor when you set your stage and scene's contents to transparent because they still appear opaque, if I remember it correctly. I have to do some more testing but if that's the case I think we can start a debate on the openjfx developers discussion mailing list and try to see if they add built-in support for true transparent stages and scenes. I think that would make this library's job easier.

Thoughts...?

regice202 commented 1 month ago

Hey @dukke!

I do know there are ways to make the entire Scene transparent. I haven't looked at it for quite some time, so I'd have to do some digging to find out how to do it again.. Maybe that's the root of the issue. Windows might notice that the contents of the area doesn't have any transparency and just complete remove the Title Bar LOL. Could also just be a bug with JavaFX, I'm not too sure. I really just wanted the dark theme option at the moment, but I'm adding support for my application to apply the different themes that are currently available through this project. I might come back to this at a later date.

dukke commented 1 month ago

The dark theme support is working on win10. The background drop I still haven't been able to make it work.

regice202 commented 1 month ago

Check this out! I even got it working for DialogPanes and Alerts! 😄

image

Edit: I also tried messing around with getting the Acrylic to work some more. Couldn't quite nail anything down yet.. I think we'll find something soon enough though. Also found this little article kind of interesting, may be of use. 🤷‍♂️

dukke commented 1 month ago

Nice!