Skip to content

Commit

Permalink
#1121 Notifications: Multimonitor support
Browse files Browse the repository at this point in the history
  • Loading branch information
diego4zeiss committed Apr 1, 2019
1 parent 05a5f32 commit 382a22e
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions controlsfx/src/main/java/org/controlsfx/control/Notifications.java
Expand Up @@ -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;
Expand Down Expand Up @@ -122,7 +124,7 @@ public class Notifications {
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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 382a22e

Please sign in to comment.