-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Yubo-Cao
wants to merge
9
commits into
JabRef:main
Choose a base branch
from
Yubo-Cao:dark-titlebar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Dark titlebar #13386
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
da017b6
Add dark mode window title bar
Yubo-Cao b442fc8
Update CHANGELOG.md
Yubo-Cao 40479ff
Use FXThemes instead
Yubo-Cao fbc6908
Fix according to Trag
Yubo-Cao 9e7bbb0
Put themeWindowManager to the constructor
Yubo-Cao 1f6e3e1
Update to the latest version of pixelduke:fxthemes
Yubo-Cao 19d2c13
Fix according to OpenRewrite
Yubo-Cao 21dc53f
Remove unnecessary checks
Yubo-Cao 1f0b87a
Update CHANGELOG.md
Yubo-Cao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
jabgui/src/main/java/org/jabref/gui/desktop/os/ThemeListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.jabref.gui.desktop.os; | ||
|
||
import javafx.collections.ListChangeListener; | ||
import javafx.stage.Stage; | ||
import javafx.stage.Window; | ||
|
||
import org.jabref.gui.util.BindingsHelper; | ||
import org.jabref.logic.os.OS; | ||
|
||
import com.pixelduke.window.ThemeWindowManager; | ||
import com.pixelduke.window.ThemeWindowManagerFactory; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Listener controlling platform-specific window title bar appearance using FXThemes. | ||
*/ | ||
public class ThemeListener { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ThemeListener.class); | ||
private static final ThemeWindowManager THEME_WINDOW_MANAGER = ThemeWindowManagerFactory.create(); | ||
private static final boolean SUPPORTS_DARK_MODE = OS.WINDOWS || OS.OS_X; | ||
private static boolean initialized = false; | ||
private static boolean currentDarkMode = false; | ||
Yubo-Cao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public static void initialize(boolean darkMode) { | ||
if (initialized || !SUPPORTS_DARK_MODE) { | ||
return; | ||
} | ||
|
||
currentDarkMode = darkMode; | ||
|
||
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) { | ||
setDarkMode(stage, currentDarkMode); | ||
} | ||
}); | ||
if (stage.isShowing()) { | ||
setDarkMode(stage, currentDarkMode); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
Window.getWindows().addListener(windowsListener); | ||
setDarkMode(darkMode); | ||
|
||
initialized = true; | ||
LOGGER.debug("ThemeListener initialized with window monitoring"); | ||
} | ||
|
||
public static void setDarkMode(Stage stage, boolean darkMode) { | ||
if (!SUPPORTS_DARK_MODE || stage == null || !stage.isShowing()) { | ||
return; | ||
} | ||
|
||
THEME_WINDOW_MANAGER.setDarkModeForWindowFrame(stage, darkMode); | ||
LOGGER.debug("Applied {} mode to window: {}", darkMode ? "dark" : "light", stage); | ||
} | ||
|
||
public static void setDarkMode(boolean darkMode) { | ||
currentDarkMode = darkMode; | ||
Window.getWindows().stream() | ||
.filter(Window::isShowing) | ||
.filter(window -> window instanceof Stage) | ||
.map(window -> (Stage) window) | ||
.forEach(stage -> setDarkMode(stage, darkMode)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.