Browse Source

Improve debug focus behavior
Fix focusing debugged game on Windows
Add re-focusing editor on continue

(cherry picked from commit 66dac878ac9fc278044281b7f67fbed668e4523d)

Pedro J. Estébanez 9 years ago
parent
commit
12d4d65668

+ 1 - 0
core/os/os.h

@@ -364,6 +364,7 @@ public:
 	virtual void set_screen_orientation(ScreenOrientation p_orientation);
 	virtual void set_screen_orientation(ScreenOrientation p_orientation);
 	ScreenOrientation get_screen_orientation() const;
 	ScreenOrientation get_screen_orientation() const;
 
 
+	virtual void enable_for_stealing_focus(ProcessID pid) {}
 	virtual void move_window_to_foreground() {}
 	virtual void move_window_to_foreground() {}
 
 
 	virtual void debug_break();
 	virtual void debug_break();

+ 3 - 0
core/script_debugger_remote.cpp

@@ -134,6 +134,8 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script,bool p_can_continue) {
 		ERR_FAIL();
 		ERR_FAIL();
 	}
 	}
 
 
+	OS::get_singleton()->enable_for_stealing_focus(Globals::get_singleton()->get("editor_pid"));
+
 	packet_peer_stream->put_var("debug_enter");
 	packet_peer_stream->put_var("debug_enter");
 	packet_peer_stream->put_var(2);
 	packet_peer_stream->put_var(2);
 	packet_peer_stream->put_var(p_can_continue);
 	packet_peer_stream->put_var(p_can_continue);
@@ -273,6 +275,7 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script,bool p_can_continue) {
 
 
 				set_depth(-1);
 				set_depth(-1);
 				set_lines_left(-1);
 				set_lines_left(-1);
+				OS::get_singleton()->move_window_to_foreground();
 				break;
 				break;
 			} else if (command=="break") {
 			} else if (command=="break") {
 				ERR_PRINT("Got break when already broke!");
 				ERR_PRINT("Got break when already broke!");

+ 10 - 0
main/main.cpp

@@ -558,6 +558,16 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
 			} else {
 			} else {
 				goto error;
 				goto error;
 
 
+			}
+		} else if (I->get()=="-epid") {
+			if (I->next()) {
+
+				int editor_pid=I->next()->get().to_int();
+				Globals::get_singleton()->set("editor_pid",editor_pid);
+				N=I->next()->next();
+			} else {
+				goto error;
+
 			}
 			}
 		} else {
 		} else {
 
 

+ 6 - 1
platform/windows/os_windows.cpp

@@ -2157,10 +2157,15 @@ String OS_Windows::get_stdin_string(bool p_block) {
 }
 }
 
 
 
 
+void OS_Windows::enable_for_stealing_focus(ProcessID pid) {
+
+	AllowSetForegroundWindow(pid);
+
+}
+
 void OS_Windows::move_window_to_foreground() {
 void OS_Windows::move_window_to_foreground() {
 
 
 	SetForegroundWindow(hWnd);
 	SetForegroundWindow(hWnd);
-	BringWindowToTop(hWnd);
 
 
 }
 }
 
 

+ 1 - 0
platform/windows/os_windows.h

@@ -269,6 +269,7 @@ public:
 	virtual String get_locale() const;
 	virtual String get_locale() const;
 	virtual LatinKeyboardVariant get_latin_keyboard_variant() const; 
 	virtual LatinKeyboardVariant get_latin_keyboard_variant() const; 
 
 
+	virtual void enable_for_stealing_focus(ProcessID pid);
 	virtual void move_window_to_foreground();
 	virtual void move_window_to_foreground();
 	virtual String get_data_dir() const;
 	virtual String get_data_dir() const;
 	virtual String get_system_dir(SystemDir p_dir) const;
 	virtual String get_system_dir(SystemDir p_dir) const;

+ 1 - 0
tools/editor/editor_node.h

@@ -679,6 +679,7 @@ public:
 
 
 	void notify_child_process_exited();
 	void notify_child_process_exited();
 
 
+	OS::ProcessID get_child_process_id() const { return editor_run.get_pid(); }
 	void stop_child_process();
 	void stop_child_process();
 
 
 	Ref<Theme> get_editor_theme() const { return theme; }
 	Ref<Theme> get_editor_theme() const { return theme; }

+ 4 - 0
tools/editor/editor_run.cpp

@@ -52,6 +52,9 @@ Error EditorRun::run(const String& p_scene,const String p_custom_args,const List
 		args.push_back("localhost:"+String::num(GLOBAL_DEF("debug/debug_port", 6007)));
 		args.push_back("localhost:"+String::num(GLOBAL_DEF("debug/debug_port", 6007)));
 	}
 	}
 
 
+	args.push_back("-epid");
+	args.push_back(String::num(OS::get_singleton()->get_process_ID()));
+
 	if (p_custom_args!="") {
 	if (p_custom_args!="") {
 
 
 		Vector<String> cargs=p_custom_args.split(" ",false);
 		Vector<String> cargs=p_custom_args.split(" ",false);
@@ -132,6 +135,7 @@ Error EditorRun::run(const String& p_scene,const String p_custom_args,const List
 	}
 	}
 
 
 
 
+
 	if (p_breakpoints.size()) {
 	if (p_breakpoints.size()) {
 
 
 		args.push_back("-bp");
 		args.push_back("-bp");

+ 2 - 0
tools/editor/editor_run.h

@@ -53,6 +53,8 @@ public:
 	void run_native_notify() { status=STATUS_PLAY; }
 	void run_native_notify() { status=STATUS_PLAY; }
 	void stop();
 	void stop();
 
 
+	OS::ProcessID get_pid() const { return pid; }
+
 	void set_debug_collisions(bool p_debug);
 	void set_debug_collisions(bool p_debug);
 	bool get_debug_collisions() const;
 	bool get_debug_collisions() const;
 
 

+ 2 - 0
tools/editor/script_editor_debugger.cpp

@@ -216,6 +216,8 @@ void ScriptEditorDebugger::debug_continue() {
 	ERR_FAIL_COND(connection.is_null());
 	ERR_FAIL_COND(connection.is_null());
 	ERR_FAIL_COND(!connection->is_connected());
 	ERR_FAIL_COND(!connection->is_connected());
 
 
+	OS::get_singleton()->enable_for_stealing_focus(EditorNode::get_singleton()->get_child_process_id());
+
 	Array msg;
 	Array msg;
 	msg.push_back("continue");
 	msg.push_back("continue");
 	ppeer->put_var(msg);
 	ppeer->put_var(msg);