mirror of https://github.com/godotengine/godot
[macOS/Embedded] Release/recapture mouse on window focus change and exit.
This commit is contained in:
parent
0fdbf050e0
commit
e2cd3ceac9
|
|
@ -105,6 +105,13 @@ void EmbeddedProcessMacOS::reset() {
|
|||
if (current_process_id != 0 && is_embedding_completed()) {
|
||||
ds->remove_embedded_process(current_process_id);
|
||||
}
|
||||
DisplayServer *ds = DisplayServer::get_singleton();
|
||||
for (int i = 0; i < DisplayServer::CURSOR_MAX; i++) {
|
||||
ds->cursor_set_custom_image(Ref<Resource>(), (DisplayServer::CursorShape)i, Vector2());
|
||||
}
|
||||
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
|
||||
ds->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
|
||||
}
|
||||
current_process_id = 0;
|
||||
embedding_state = EmbeddingState::IDLE;
|
||||
context_id = 0;
|
||||
|
|
@ -226,12 +233,12 @@ void LayerHost::_notification(int p_what) {
|
|||
} break;
|
||||
case NOTIFICATION_FOCUS_ENTER: {
|
||||
// Restore mouse capture, if necessary.
|
||||
DisplayServer *ds = DisplayServer::get_singleton();
|
||||
if (process->get_mouse_mode() != ds->mouse_get_mode()) {
|
||||
// Restore embedded process mouse mode.
|
||||
ds->mouse_set_mode(process->get_mouse_mode());
|
||||
}
|
||||
if (!window_focused && script_debugger) {
|
||||
DisplayServer *ds = DisplayServer::get_singleton();
|
||||
if (process->get_mouse_mode() != ds->mouse_get_mode()) {
|
||||
// Restore embedded process mouse mode.
|
||||
ds->mouse_set_mode(process->get_mouse_mode());
|
||||
}
|
||||
script_debugger->send_message("embed:notification", { NOTIFICATION_APPLICATION_FOCUS_IN });
|
||||
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_IN });
|
||||
window_focused = true;
|
||||
|
|
@ -249,11 +256,11 @@ void LayerHost::_notification(int p_what) {
|
|||
} break;
|
||||
case NOTIFICATION_FOCUS_EXIT: {
|
||||
// Temporarily set mouse state back to visible, so the user can interact with the editor.
|
||||
DisplayServer *ds = DisplayServer::get_singleton();
|
||||
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
|
||||
ds->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
|
||||
}
|
||||
if (window_focused && script_debugger) {
|
||||
DisplayServer *ds = DisplayServer::get_singleton();
|
||||
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
|
||||
ds->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
|
||||
}
|
||||
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_OUT });
|
||||
script_debugger->send_message("embed:notification", { NOTIFICATION_APPLICATION_FOCUS_OUT });
|
||||
window_focused = false;
|
||||
|
|
@ -274,11 +281,22 @@ void LayerHost::_notification(int p_what) {
|
|||
for (int i = 0; i < DisplayServer::CURSOR_MAX; i++) {
|
||||
ds->cursor_set_custom_image(Ref<Resource>(), (DisplayServer::CursorShape)i, Vector2());
|
||||
}
|
||||
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
|
||||
ds->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_APPLICATION_FOCUS_IN:
|
||||
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
|
||||
if (has_focus() && !window_focused && script_debugger) {
|
||||
DisplayServer *ds = DisplayServer::get_singleton();
|
||||
if (process->get_mouse_mode() != ds->mouse_get_mode()) {
|
||||
// Restore embedded process mouse mode.
|
||||
ds->mouse_set_mode(process->get_mouse_mode());
|
||||
if (process->get_mouse_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
|
||||
get_window()->grab_focus();
|
||||
}
|
||||
}
|
||||
script_debugger->send_message("embed:notification", { NOTIFICATION_APPLICATION_FOCUS_IN });
|
||||
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_IN });
|
||||
window_focused = true;
|
||||
|
|
@ -287,6 +305,10 @@ void LayerHost::_notification(int p_what) {
|
|||
case NOTIFICATION_APPLICATION_FOCUS_OUT:
|
||||
case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
|
||||
if (has_focus() && window_focused && script_debugger) {
|
||||
DisplayServer *ds = DisplayServer::get_singleton();
|
||||
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_VISIBLE) {
|
||||
ds->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
|
||||
}
|
||||
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_OUT });
|
||||
script_debugger->send_message("embed:notification", { NOTIFICATION_APPLICATION_FOCUS_OUT });
|
||||
window_focused = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue