Skip to content

Commit 1d204f1

Browse files
committed
Merge pull request #109724 from bruvzg/mac_emb_app_focus
[macOS] Forward application focus events to the embedded process.
2 parents d9d12ab + 7858030 commit 1d204f1

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

platform/macos/editor/embedded_process_macos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class LayerHost final : public Control {
4040

4141
ScriptEditorDebugger *script_debugger = nullptr;
4242
EmbeddedProcessMacOS *process = nullptr;
43+
bool window_focused = true;
4344

4445
struct CustomCursor {
4546
Ref<Image> image;

platform/macos/editor/embedded_process_macos.mm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@
252252
// Restore embedded process mouse mode.
253253
ds->mouse_set_mode(process->get_mouse_mode());
254254
}
255+
if (!window_focused && script_debugger) {
256+
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_IN });
257+
window_focused = true;
258+
}
255259
} break;
256260
case NOTIFICATION_MOUSE_EXIT: {
257261
DisplayServer *ds = DisplayServer::get_singleton();
@@ -268,6 +272,10 @@
268272
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
269273
ds->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
270274
}
275+
if (window_focused && script_debugger) {
276+
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_OUT });
277+
window_focused = false;
278+
}
271279
} break;
272280
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
273281
if (script_debugger && has_focus()) {
@@ -285,6 +293,28 @@
285293
}
286294
}
287295
} break;
296+
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
297+
if (!window_focused && script_debugger) {
298+
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_IN });
299+
window_focused = true;
300+
}
301+
} break;
302+
case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
303+
if (window_focused && script_debugger) {
304+
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_OUT });
305+
window_focused = false;
306+
}
307+
} break;
308+
case NOTIFICATION_APPLICATION_FOCUS_IN: {
309+
if (script_debugger) {
310+
script_debugger->send_message("embed:notification", { NOTIFICATION_APPLICATION_FOCUS_IN });
311+
}
312+
} break;
313+
case NOTIFICATION_APPLICATION_FOCUS_OUT: {
314+
if (script_debugger) {
315+
script_debugger->send_message("embed:notification", { NOTIFICATION_APPLICATION_FOCUS_OUT });
316+
}
317+
} break;
288318
}
289319
}
290320

platform/macos/embedded_debugger.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class EmbeddedDebugger {
6060
Error _msg_mouse_set_mode(const Array &p_args);
6161
Error _msg_event(const Array &p_args);
6262
Error _msg_win_event(const Array &p_args);
63+
Error _msg_notification(const Array &p_args);
6364
Error _msg_ime_update(const Array &p_args);
6465
Error _msg_joy_add(const Array &p_args);
6566
Error _msg_joy_del(const Array &p_args);

platform/macos/embedded_debugger.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
parse_message_handlers["mouse_set_mode"] = &EmbeddedDebugger::_msg_mouse_set_mode;
7474
parse_message_handlers["event"] = &EmbeddedDebugger::_msg_event;
7575
parse_message_handlers["win_event"] = &EmbeddedDebugger::_msg_win_event;
76+
parse_message_handlers["notification"] = &EmbeddedDebugger::_msg_notification;
7677
parse_message_handlers["ime_update"] = &EmbeddedDebugger::_msg_ime_update;
7778
parse_message_handlers["joy_add"] = &EmbeddedDebugger::_msg_joy_add;
7879
parse_message_handlers["joy_del"] = &EmbeddedDebugger::_msg_joy_del;
@@ -151,6 +152,15 @@
151152
return OK;
152153
}
153154

155+
Error EmbeddedDebugger::_msg_notification(const Array &p_args) {
156+
ERR_FAIL_COND_V_MSG(p_args.size() != 1, ERR_INVALID_PARAMETER, "Invalid number of arguments for 'notification' message.");
157+
int notification = p_args[0];
158+
if (OS::get_singleton()->get_main_loop()) {
159+
OS::get_singleton()->get_main_loop()->notification(notification);
160+
}
161+
return OK;
162+
}
163+
154164
Error EmbeddedDebugger::_msg_joy_add(const Array &p_args) {
155165
ERR_FAIL_COND_V_MSG(p_args.size() != 2, ERR_INVALID_PARAMETER, "Invalid number of arguments for 'joy_add' message.");
156166
int idx = p_args[0];

0 commit comments

Comments
 (0)