Skip to content

Dark titlebar #13386

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Dark titlebar #13386

wants to merge 9 commits into from

Conversation

Yubo-Cao
Copy link
Contributor

Closes #11457

Added a dark mode title bar for Windows.

Steps to test

  • Run JabRef with this version of the code
  • Open preferences, change theme to dark/light
  • The title bar should toggle if using Windows

A screenshot can be found here: https://imgur.com/a/aLDeZqg

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • [/] Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (if change is visible to the user)
  • [/] Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • [/] Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@calixtus
Copy link
Member

This seems to be too much micromanagement here. as this needs to be maintained in future.
We should rely on a library instead here.
Use FXThemes from Pixelduke. https://www.pixelduke.com/2024/05/02/fxthemes-version-1-5-released/

@calixtus
Copy link
Member

Do not introduce custom monitoring, use proper bindings in javafx' platfrom api.
https://download.java.net/java/GA/javafx24/docs/api/javafx.graphics/javafx/application/Platform.Preferences.html#colorSchemeProperty

@Siedlerchr
Copy link
Member

FxTheme does the same and we would just introduce another dependency.
One could also take a look at how xpipe does this https://github.com/xpipe-io/xpipe/blob/8389c4073bbc7e69cfeb7cf329fcabb666f9c338/app/src/main/java/io/xpipe/app/core/window/NativeWinWindowControl.java because then it could work for mac as well

@calixtus
Copy link
Member

Yes, but fxtheme is not maintained by us. Introducing a new library is in that case not necessary, if another library already supports what we need. But in this case, I have no interest in fixing changing apis and keeping it compatible to other OSs. That is what literally using an external library is meant for.

Comment on lines 105 to 124
ListChangeListener<Window> windowsListener = change -> {
while (change.next()) {
if (!change.wasAdded()) {
continue;
}
change.getAddedSubList().stream()
.filter(Stage.class::isInstance)
.map(Stage.class::cast)
.forEach(stage -> {
BindingsHelper.subscribeFuture(stage.showingProperty(), showing -> {
if (showing) {
applyDarkModeToWindow(stage, isDarkMode);
}
});
if (stage.isShowing()) {
applyDarkModeToWindow(stage, isDarkMode);
}
});
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can maybe simplified with platform preferences api

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why the platform preferences API would work? The dark title bar must be applied to each new window, nor does the platform preferences API understand "use system theme" settings in the JabRef application.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The platform preferences provide the binding colorSchemeProperty, which can be subscribed to, which notifies you every time the color scheme is changed in the system settings. Only thing left is if the user manually changes the theme in JabRef itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aah, wait... Maybe there is no something I overlooked.... Right now I'm on my cellphone, I will take a deeper look in a few hours

@@ -49,13 +55,16 @@ public class ThemeManager {
);

private static final Logger LOGGER = LoggerFactory.getLogger(ThemeManager.class);
private static final boolean SUPPORTS_DARK_MODE = OS.WINDOWS || OS.OS_X;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please comment why it is not supported on Linux. Add a link. I think, KDE supports dark mode, doesn't it?

Copy link
Member

@Siedlerchr Siedlerchr Jun 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminded me that there is a thing they are working on https://bugs.openjdk.org/browse/JDK-8313424

Copy link
Contributor Author

@Yubo-Cao Yubo-Cao Jun 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux would automatically enforce a dark/light titlebar based on the system settings. The actual implementation of FXThemes on a Linux environment is a method that is empty. https://github.com/dukke/FXThemes/blob/main/FXThemes/src/main/java/com/pixelduke/window/LinuxThemeWindowManager.java

Would it be better for me to just have called the stub methods anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better for me to just have called the stub methods anyway

Yes, I think so. Maybe, there are some Window managers we never thought of supported? Icewm, dwm, ...

Comment on lines 115 to 122
BindingsHelper.subscribeFuture(stage.showingProperty(), showing -> {
if (showing) {
applyDarkModeToWindow(stage, isDarkMode);
}
});
if (stage.isShowing()) {
applyDarkModeToWindow(stage, isDarkMode);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplication can be solved with EasyBind::subscribe

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure but i think this may cause a memory leak. if a window is closed, the reference is not removed and the garbage collector wont remove this. or am i wrong here? @Siedlerchr @koppor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yubo-Cao do not close converstations with questions raised that have not been answered. Maybe you already know, but I want to know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I thought the code was updated such that this duplication is not present, so this conversation is no longer relevant. But I think it's unlikely that we will have a memory leak, since this listener is anonymous, so the only reference to the window object would be inside the list of listeners that the window object creates for itself, which won't prevent the window from being recycled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For resolving just write a "done" or something like this if you addressed the comment

@Siedlerchr
Copy link
Member

Doesn't seem to make any difference on macOS
grafik

Only if my system theme is set to dark mode it gets a dark color:

grafik

@Yubo-Cao
Copy link
Contributor Author

Doesn't seem to make any difference on macOS grafik

Only if my system theme is set to dark mode it gets a dark color:
grafik

... I cannot really test how the application behaves on Mac. But just to confirm, can you try setting the theme to dark in the settings, then set it back to light and see if that makes a difference?

@Siedlerchr
Copy link
Member

Didn't really make any difference so far, I also don't know if that should work on newer macs or not. No idea

Co-authored-by: Subhramit Basu <subhramit.bb@live.in>
Copy link

trag-bot bot commented Jun 29, 2025

@trag-bot didn't find any issues in the code! ✅✨

@jabref-machine
Copy link
Collaborator

JUnit tests of jabkit are failing. You can see which checks are failing by locating the box "Some checks were not successful" on the pull request page. To see the test output, locate "Tests / Unit tests (pull_request)" and click on it.

You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

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.

Support Windows dark title bar
6 participants