Browse Source

Fix window unvailable when opening on nonexisting screen

Leonardo Jeanteur 3 years ago
parent
commit
2a22345919
2 changed files with 42 additions and 1 deletions
  1. 10 1
      hide/Ide.hx
  2. 32 0
      libs/nw/Screen.hx

+ 10 - 1
hide/Ide.hx

@@ -100,12 +100,21 @@ class Ide {
 			}
 		}
 
+		nw.Screen.Init();
+		var xMax = 1;
+		var yMax = 1;
+		for( s in nw.Screen.screens ) {
+			if( s.work_area.x + s.work_area.width > xMax )
+				xMax = s.work_area.x + s.work_area.width;
+			if( s.work_area.y + s.work_area.height > yMax )
+				yMax = s.work_area.y + s.work_area.height;
+		}
 		if( subView == null ) {
 			var wp = ideConfig.windowPos;
 			if( wp != null ) {
 				if( wp.w > 400 && wp.h > 300 )
 					window.resizeBy(wp.w - Std.int(window.window.outerWidth), wp.h - Std.int(window.window.outerHeight));
-				if( wp.x >= 0 && wp.y >= 0 )
+				if( wp.x >= 0 && wp.y >= 0 && wp.x < xMax && wp.y < yMax)
 					window.moveTo(wp.x, wp.y);
 				if( wp.max ) {
 					window.maximize();

+ 32 - 0
libs/nw/Screen.hx

@@ -0,0 +1,32 @@
+package nw;
+
+typedef IndividualScreen = {
+    var id : Int;
+
+    // physical screen resolution, can be negative, not necessarily start from 0,depending on screen arrangement
+    var bounds : {
+        x : Int,
+        y : Int,
+        width : Int,
+        height : Int,
+    };
+    // useable area within the screen bound
+    var work_area : {
+        x : Int,
+        y : Int,
+        width : Int,
+        height : Int,
+    };
+    var scaleFactor : Float;
+    var isBuiltIn : Bool;
+    var rotation : Int;
+    var touchSupport : Int;
+}
+
+extern class Screen {
+	public static var screens(default, never) : Array<IndividualScreen>;
+	public static function Init() : Void;
+	public static function on( event : String, callb : IndividualScreen -> Void ) : Void;
+	public static function chooseDesktopMedia(sources : Array<String>, callb : Dynamic -> Void) : Void;
+
+}