You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Merge pull request #110219 from bruvzg/mac_emb_focus_3
[macOS] Make embedded window focus behavior more similar to Windows/X11.
This commit is contained in:
@@ -192,6 +192,7 @@ EmbeddedProcessMacOS::EmbeddedProcessMacOS() :
|
|||||||
EmbeddedProcessBase() {
|
EmbeddedProcessBase() {
|
||||||
layer_host = memnew(LayerHost(this));
|
layer_host = memnew(LayerHost(this));
|
||||||
add_child(layer_host);
|
add_child(layer_host);
|
||||||
|
set_focus_mode(FOCUS_NONE);
|
||||||
layer_host->set_focus_mode(FOCUS_ALL);
|
layer_host->set_focus_mode(FOCUS_ALL);
|
||||||
layer_host->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
|
layer_host->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
|
||||||
layer_host->set_custom_minimum_size(Size2(100, 100));
|
layer_host->set_custom_minimum_size(Size2(100, 100));
|
||||||
@@ -219,6 +220,9 @@ void LayerHost::_notification(int p_what) {
|
|||||||
if (script_debugger) {
|
if (script_debugger) {
|
||||||
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_MOUSE_ENTER });
|
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_MOUSE_ENTER });
|
||||||
}
|
}
|
||||||
|
if (get_window()->has_focus()) {
|
||||||
|
grab_focus();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_FOCUS_ENTER: {
|
case NOTIFICATION_FOCUS_ENTER: {
|
||||||
// Restore mouse capture, if necessary.
|
// Restore mouse capture, if necessary.
|
||||||
@@ -228,9 +232,11 @@ void LayerHost::_notification(int p_what) {
|
|||||||
ds->mouse_set_mode(process->get_mouse_mode());
|
ds->mouse_set_mode(process->get_mouse_mode());
|
||||||
}
|
}
|
||||||
if (!window_focused && script_debugger) {
|
if (!window_focused && script_debugger) {
|
||||||
|
script_debugger->send_message("embed:notification", { NOTIFICATION_APPLICATION_FOCUS_IN });
|
||||||
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_IN });
|
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_IN });
|
||||||
window_focused = true;
|
window_focused = true;
|
||||||
}
|
}
|
||||||
|
process->queue_redraw();
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_MOUSE_EXIT: {
|
case NOTIFICATION_MOUSE_EXIT: {
|
||||||
DisplayServer *ds = DisplayServer::get_singleton();
|
DisplayServer *ds = DisplayServer::get_singleton();
|
||||||
@@ -249,8 +255,10 @@ void LayerHost::_notification(int p_what) {
|
|||||||
}
|
}
|
||||||
if (window_focused && script_debugger) {
|
if (window_focused && script_debugger) {
|
||||||
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_OUT });
|
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;
|
window_focused = false;
|
||||||
}
|
}
|
||||||
|
process->queue_redraw();
|
||||||
} break;
|
} break;
|
||||||
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
|
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
|
||||||
if (script_debugger && has_focus()) {
|
if (script_debugger && has_focus()) {
|
||||||
@@ -268,26 +276,20 @@ void LayerHost::_notification(int p_what) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
case NOTIFICATION_APPLICATION_FOCUS_IN:
|
||||||
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
|
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
|
||||||
if (!window_focused && script_debugger) {
|
if (has_focus() && !window_focused && script_debugger) {
|
||||||
|
script_debugger->send_message("embed:notification", { NOTIFICATION_APPLICATION_FOCUS_IN });
|
||||||
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_IN });
|
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_IN });
|
||||||
window_focused = true;
|
window_focused = true;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
case NOTIFICATION_APPLICATION_FOCUS_OUT:
|
||||||
case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
|
case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
|
||||||
if (window_focused && script_debugger) {
|
if (has_focus() && window_focused && script_debugger) {
|
||||||
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_OUT });
|
script_debugger->send_message("embed:win_event", { DisplayServer::WINDOW_EVENT_FOCUS_OUT });
|
||||||
window_focused = false;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case NOTIFICATION_APPLICATION_FOCUS_IN: {
|
|
||||||
if (script_debugger) {
|
|
||||||
script_debugger->send_message("embed:notification", { NOTIFICATION_APPLICATION_FOCUS_IN });
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case NOTIFICATION_APPLICATION_FOCUS_OUT: {
|
|
||||||
if (script_debugger) {
|
|
||||||
script_debugger->send_message("embed:notification", { NOTIFICATION_APPLICATION_FOCUS_OUT });
|
script_debugger->send_message("embed:notification", { NOTIFICATION_APPLICATION_FOCUS_OUT });
|
||||||
|
window_focused = false;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user