From 2fcbf9dd8105940cefecb9c1d666bf3002869996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Mon, 28 May 2018 21:49:48 +0200 Subject: [PATCH] Fix debugger focus stealing At least on Windows, the authorization must be given every time, not only at startup. --- core/script_debugger_remote.cpp | 9 +++++++++ core/script_debugger_remote.h | 5 +++++ main/main.cpp | 5 +---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp index 75bcedbbc83..4922a03f928 100644 --- a/core/script_debugger_remote.cpp +++ b/core/script_debugger_remote.cpp @@ -169,6 +169,10 @@ void ScriptDebuggerRemote::debug(ScriptLanguage *p_script, bool p_can_continue) ERR_FAIL(); } + if (allow_focus_steal_pid) { + OS::get_singleton()->enable_for_stealing_focus(allow_focus_steal_pid); + } + packet_peer_stream->put_var("debug_enter"); packet_peer_stream->put_var(2); packet_peer_stream->put_var(p_can_continue); @@ -1044,6 +1048,10 @@ void ScriptDebuggerRemote::profiling_set_frame_times(float p_frame_time, float p physics_frame_time = p_physics_frame_time; } +void ScriptDebuggerRemote::set_allow_focus_steal_pid(OS::ProcessID p_pid) { + allow_focus_steal_pid = p_pid; +} + ScriptDebuggerRemote::ResourceUsageFunc ScriptDebuggerRemote::resource_usage_func = NULL; ScriptDebuggerRemote::ScriptDebuggerRemote() : @@ -1065,6 +1073,7 @@ ScriptDebuggerRemote::ScriptDebuggerRemote() : n_errors_dropped(0), last_msec(0), msec_count(0), + allow_focus_steal_pid(0), locking(false), poll_every(0), request_scene_tree(NULL), diff --git a/core/script_debugger_remote.h b/core/script_debugger_remote.h index cc12d978d6c..b68fc4f9c90 100644 --- a/core/script_debugger_remote.h +++ b/core/script_debugger_remote.h @@ -34,6 +34,7 @@ #include "io/packet_peer.h" #include "io/stream_peer_tcp.h" #include "list.h" +#include "os/os.h" #include "script_language.h" class ScriptDebuggerRemote : public ScriptDebugger { @@ -98,6 +99,8 @@ class ScriptDebuggerRemote : public ScriptDebugger { uint64_t last_msec; uint64_t msec_count; + OS::ProcessID allow_focus_steal_pid; + bool locking; //hack to avoid a deadloop static void _print_handler(void *p_this, const String &p_string, bool p_error); @@ -171,6 +174,8 @@ public: virtual void profiling_end(); virtual void profiling_set_frame_times(float p_frame_time, float p_idle_time, float p_physics_time, float p_physics_frame_time); + void set_allow_focus_steal_pid(OS::ProcessID p_pid); + ScriptDebuggerRemote(); ~ScriptDebuggerRemote(); }; diff --git a/main/main.cpp b/main/main.cpp index 1c5540fd197..954e143b83a 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -726,6 +726,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph memdelete(sdr); } else { script_debugger = sdr; + sdr->set_allow_focus_steal_pid(allow_focus_steal_pid); } } else if (debug_mode == "local") { @@ -1188,10 +1189,6 @@ Error Main::setup2(Thread::ID p_main_tid_override) { #endif - if (allow_focus_steal_pid) { - OS::get_singleton()->enable_for_stealing_focus(allow_focus_steal_pid); - } - MAIN_PRINT("Main: Load Modules, Physics, Drivers, Scripts"); register_platform_apis();