Skip to content

Commit 4393c59

Browse files
CloudS3cZ-Kris
andauthored
feat: adds validation if frame is within any screens bounds (#42)
* chore: Added validation if frame is within any screens bounds. * refactor: improve documentation and code style --------- Co-authored-by: Kris <[email protected]>
1 parent 9873961 commit 4393c59

File tree

1 file changed

+15
-0
lines changed
  • gui/proxy-tool/src/main/kotlin/net/rsprox/gui

1 file changed

+15
-0
lines changed

gui/proxy-tool/src/main/kotlin/net/rsprox/gui/App.kt

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import net.rsprox.proxy.ProxyService
1313
import net.rsprox.proxy.config.BINARY_PATH
1414
import java.awt.Desktop
1515
import java.awt.Dimension
16+
import java.awt.GraphicsEnvironment
1617
import java.awt.event.ComponentAdapter
1718
import java.awt.event.ComponentEvent
1819
import java.awt.event.WindowAdapter
@@ -56,6 +57,9 @@ public class App {
5657
frame.size = defaultSize
5758
frame.minimumSize = UIScale.scale(Dimension(800, 600))
5859
frame.iconImages = FlatSVGUtils.createWindowIconImages("/favicon.svg")
60+
if (!validFramePosition(frame)) {
61+
frame.setLocationRelativeTo(null)
62+
}
5963
val windowHandler =
6064
object : WindowAdapter() {
6165
override fun windowClosing(e: WindowEvent) {
@@ -220,6 +224,17 @@ public class App {
220224
add(sessionsPanel)
221225
}
222226

227+
/**
228+
* Checks if the frame intersects with any screen device. If the function returns false, the window
229+
* is completely outside the device's visible area, meaning the user would not be able to interact
230+
* with the window.
231+
*/
232+
private fun validFramePosition(frame: JFrame): Boolean {
233+
return GraphicsEnvironment.getLocalGraphicsEnvironment().screenDevices.any { device ->
234+
device.defaultConfiguration.bounds.intersects(frame.bounds)
235+
}
236+
}
237+
223238
public companion object {
224239
public val service: ProxyService = ProxyService(ByteBufAllocator.DEFAULT)
225240
}

0 commit comments

Comments
 (0)