From d9236a7b154a402f573d249723ae6664b3bf0621 Mon Sep 17 00:00:00 2001 From: Robinson Date: Sun, 20 Aug 2023 13:40:57 +0200 Subject: [PATCH] fixed api updates --- src/dorkbox/notify/DesktopNotify.kt | 4 ++-- src/dorkbox/notify/LAFUtil.kt | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/dorkbox/notify/DesktopNotify.kt b/src/dorkbox/notify/DesktopNotify.kt index 1637c94..4383301 100755 --- a/src/dorkbox/notify/DesktopNotify.kt +++ b/src/dorkbox/notify/DesktopNotify.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -141,7 +141,7 @@ internal class DesktopNotify(override val notification: Notify) : JWindow(), Not * have to adjust for offsets when the window-manager has a toolbar that consumes space and prevents overlap. */ private fun calculateOffset(showFromTop: Boolean, point: Point): Int { - val gc = ScreenUtil.getMonitorAtLocation(point).defaultConfiguration + val gc = ScreenUtil.getMonitorAtLocation(point)?.defaultConfiguration ?: return 0 val screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc) if (showFromTop) { diff --git a/src/dorkbox/notify/LAFUtil.kt b/src/dorkbox/notify/LAFUtil.kt index 872c88e..f7a27d1 100755 --- a/src/dorkbox/notify/LAFUtil.kt +++ b/src/dorkbox/notify/LAFUtil.kt @@ -1,5 +1,5 @@ /* - * Copyright 2015 dorkbox, llc + * Copyright 2023 dorkbox, llc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package dorkbox.notify import dorkbox.swingActiveRender.SwingActiveRender import dorkbox.tweenEngine.TweenEngine.Companion.create import dorkbox.util.ScreenUtil +import java.awt.GraphicsDevice import java.awt.GraphicsEnvironment import java.awt.MouseInfo import java.awt.Rectangle @@ -37,11 +38,15 @@ internal object LAFUtil { val RANDOM = Random() fun getGraphics(screen: Int): Rectangle { - val device = if (screen == Short.MIN_VALUE.toInt()) { + var device: GraphicsDevice? = null + + if (screen == Short.MIN_VALUE.toInt()) { // set screen position based on mouse val mouseLocation = MouseInfo.getPointerInfo().location - ScreenUtil.getMonitorAtLocation(mouseLocation) - } else { + device = ScreenUtil.getMonitorAtLocation(mouseLocation) + } + + if (device == null) { // set screen position based on specified screen var screenNumber = screen val ge = GraphicsEnvironment.getLocalGraphicsEnvironment() @@ -53,10 +58,10 @@ internal object LAFUtil { screenNumber = screenDevices.size - 1 } - screenDevices[screenNumber] + device = screenDevices[screenNumber] } - return device.defaultConfiguration.bounds + return device!!.defaultConfiguration.bounds } // only called on the swing EDT thread