Skip to content
Permalink
Browse files

Merge pull request #1130 from Ciruman/feat/Notifications_Multimonitor…

…_support

#1121 Notifications: Multimonitor support
  • Loading branch information...
abhinayagarwal committed Apr 8, 2019
2 parents 819bf84 + 382a22e commit 0d47743c07f988af328305124724b95b81965cfb
Showing with 18 additions and 4 deletions.
  1. +18 −4 controlsfx/src/main/java/org/controlsfx/control/Notifications.java
@@ -35,6 +35,8 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
@@ -122,7 +124,7 @@
private boolean hideCloseButton;
private EventHandler<ActionEvent> onAction;
private Window owner;
private Screen screen = Screen.getPrimary();
private Screen screen = null;

private List<String> styleClass = new ArrayList<>();
private int threshold;
@@ -335,13 +337,15 @@ public void show(Notifications notification) {
/*
* If the owner is not set, we work with the whole screen.
*/
Rectangle2D screenBounds = notification.screen.getVisualBounds();
window = Utils.getWindow(null);
Screen screen = notification.screen != null
? notification.screen
: getScreenBounds(window).orElse(Screen.getPrimary());
Rectangle2D screenBounds = screen.getBounds();
startX = screenBounds.getMinX();
startY = screenBounds.getMinY();
screenWidth = screenBounds.getWidth();
screenHeight = screenBounds.getHeight();

window = Utils.getWindow(null);
} else {
/*
* If the owner is set, we will make the notifications popup
@@ -356,6 +360,16 @@ public void show(Notifications notification) {
show(window, notification);
}

private Optional<Screen> getScreenBounds(Window window) {
final ObservableList<Screen> screensForRectangle = Screen.getScreensForRectangle(window.getX(),
window.getY(),
window.getWidth(),
window.getHeight());
return screensForRectangle.stream()
.filter(Objects::nonNull)
.findFirst();
}

private void show(Window owner, final Notifications notification) {
// Stylesheets which are added to the scene of a popup aren't
// considered for styling. For this reason, we need to find the next

0 comments on commit 0d47743

Please sign in to comment.
You can’t perform that action at this time.