Embedded Popups store their safe_rect in their embedder

Storing it in the DisplayServer didn't make sense in this case,
because the embedded window is unknown to the DisplayServer.
This commit is contained in:
Markus Sauermann 2023-06-20 15:50:44 +02:00
parent d7af287ce3
commit a12627765f
3 changed files with 27 additions and 4 deletions

View File

@ -244,7 +244,12 @@ void PopupMenu::_activate_submenu(int p_over, bool p_by_keyboard) {
Rect2 safe_area = this_rect;
safe_area.position.y += items[p_over]._ofs_cache + scroll_offset + theme_cache.panel_style->get_offset().height - theme_cache.v_separation / 2;
safe_area.size.y = items[p_over]._height_cache + theme_cache.v_separation;
DisplayServer::get_singleton()->window_set_popup_safe_rect(submenu_popup->get_window_id(), safe_area);
Viewport *vp = submenu_popup->get_embedder();
if (vp) {
vp->subwindow_set_popup_safe_rect(submenu_popup, safe_area);
} else {
DisplayServer::get_singleton()->window_set_popup_safe_rect(submenu_popup->get_window_id(), safe_area);
}
// Make the position of the parent popup relative to submenu popup.
this_rect.position = this_rect.position - submenu_pum->get_position();
@ -273,7 +278,7 @@ void PopupMenu::_parent_focused() {
window_parent = Object::cast_to<Window>(window_parent->get_parent()->get_viewport());
}
Rect2 safe_area = DisplayServer::get_singleton()->window_get_popup_safe_rect(get_window_id());
Rect2 safe_area = get_embedder()->subwindow_get_popup_safe_rect(this);
Point2 pos = DisplayServer::get_singleton()->mouse_get_position() - mouse_pos_adjusted;
if (safe_area == Rect2i() || !safe_area.has_point(pos)) {
Popup::_parent_focused();

View File

@ -462,7 +462,7 @@ void Viewport::_sub_window_remove(Window *p_window) {
RenderingServer::get_singleton()->viewport_set_parent_viewport(p_window->viewport, p_window->parent ? p_window->parent->viewport : RID());
}
int Viewport::_sub_window_find(Window *p_window) {
int Viewport::_sub_window_find(Window *p_window) const {
for (int i = 0; i < gui.sub_windows.size(); i++) {
if (gui.sub_windows[i].window == p_window) {
return i;
@ -3482,6 +3482,21 @@ bool Viewport::is_embedding_subwindows() const {
return gui.embed_subwindows_hint;
}
void Viewport::subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect) {
int index = _sub_window_find(p_window);
ERR_FAIL_COND(index == -1);
SubWindow sw = gui.sub_windows[index];
sw.parent_safe_rect = p_rect;
}
Rect2i Viewport::subwindow_get_popup_safe_rect(Window *p_window) const {
int index = _sub_window_find(p_window);
ERR_FAIL_COND_V(index == -1, Rect2i());
return gui.sub_windows[index].parent_safe_rect;
}
void Viewport::pass_mouse_focus_to(Viewport *p_viewport, Control *p_control) {
ERR_MAIN_THREAD_GUARD;
ERR_FAIL_NULL(p_viewport);

View File

@ -338,6 +338,7 @@ private:
struct SubWindow {
Window *window = nullptr;
RID canvas_item;
Rect2i parent_safe_rect;
};
// VRS
@ -461,7 +462,7 @@ private:
void _sub_window_update(Window *p_window);
void _sub_window_grab_focus(Window *p_window);
void _sub_window_remove(Window *p_window);
int _sub_window_find(Window *p_window);
int _sub_window_find(Window *p_window) const;
bool _sub_windows_forward_input(const Ref<InputEvent> &p_event);
SubWindowResize _sub_window_get_resize_margin(Window *p_subwindow, const Point2 &p_point);
@ -644,6 +645,8 @@ public:
void set_embedding_subwindows(bool p_embed);
bool is_embedding_subwindows() const;
void subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect);
Rect2i subwindow_get_popup_safe_rect(Window *p_window) const;
Viewport *get_parent_viewport() const;
Window *get_base_window() const;