Skip to content

Commit 659a959

Browse files
committed
[macOS/Embedded] Release/recapture mouse on window focus change and exit.
1 parent 250ef8d commit 659a959

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

platform/macos/editor/embedded_process_macos.mm

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@
105105
if (current_process_id != 0 && is_embedding_completed()) {
106106
ds->remove_embedded_process(current_process_id);
107107
}
108+
DisplayServer *ds = DisplayServer::get_singleton();
109+
for (int i = 0; i < DisplayServer::CURSOR_MAX; i++) {
110+
ds->cursor_set_custom_image(Ref<Resource>(), (DisplayServer::CursorShape)i, Vector2());
111+
}
112+
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
113+
ds->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
114+
}
108115
current_process_id = 0;
109116
embedding_state = EmbeddingState::IDLE;
110117
context_id = 0;
@@ -222,12 +229,12 @@
222229
} break;
223230
case NOTIFICATION_FOCUS_ENTER: {
224231
// Restore mouse capture, if necessary.
225-
DisplayServer *ds = DisplayServer::get_singleton();
226-
if (process->get_mouse_mode() != ds->mouse_get_mode()) {
227-
// Restore embedded process mouse mode.
228-
ds->mouse_set_mode(process->get_mouse_mode());
229-
}
230232
if (!window_focused && script_debugger) {
233+
DisplayServer *ds = DisplayServer::get_singleton();
234+
if (process->get_mouse_mode() != ds->mouse_get_mode()) {
235+
// Restore embedded process mouse mode.
236+
ds->mouse_set_mode(process->get_mouse_mode());
237+
}
231238
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_IN });
232239
window_focused = true;
233240
}
@@ -243,11 +250,11 @@
243250
} break;
244251
case NOTIFICATION_FOCUS_EXIT: {
245252
// Temporarily set mouse state back to visible, so the user can interact with the editor.
246-
DisplayServer *ds = DisplayServer::get_singleton();
247-
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
248-
ds->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
249-
}
250253
if (window_focused && script_debugger) {
254+
DisplayServer *ds = DisplayServer::get_singleton();
255+
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
256+
ds->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
257+
}
251258
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_OUT });
252259
window_focused = false;
253260
}
@@ -266,16 +273,28 @@
266273
for (int i = 0; i < DisplayServer::CURSOR_MAX; i++) {
267274
ds->cursor_set_custom_image(Ref<Resource>(), (DisplayServer::CursorShape)i, Vector2());
268275
}
276+
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
277+
ds->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
278+
}
269279
}
270280
} break;
271281
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
272282
if (!window_focused && script_debugger) {
283+
DisplayServer *ds = DisplayServer::get_singleton();
284+
if (process->get_mouse_mode() != ds->mouse_get_mode()) {
285+
// Restore embedded process mouse mode.
286+
ds->mouse_set_mode(process->get_mouse_mode());
287+
}
273288
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_IN });
274289
window_focused = true;
275290
}
276291
} break;
277292
case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
278293
if (window_focused && script_debugger) {
294+
DisplayServer *ds = DisplayServer::get_singleton();
295+
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
296+
ds->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
297+
}
279298
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_OUT });
280299
window_focused = false;
281300
}

0 commit comments

Comments
 (0)