File tree Expand file tree Collapse file tree 4 files changed +15
-23
lines changed
Expand file tree Collapse file tree 4 files changed +15
-23
lines changed Original file line number Diff line number Diff line change @@ -1601,18 +1601,12 @@ void ColorPicker::_pick_button_pressed_legacy() {
16011601 // Add the Texture of each Window to the Image.
16021602 Vector<DisplayServer::WindowID> wl = ds->get_window_list ();
16031603 // FIXME: sort windows by visibility.
1604- for (int index = 0 ; index < wl. size (); index++ ) {
1605- DisplayServer::WindowID wid = wl[index] ;
1606- if (wid == DisplayServer::INVALID_WINDOW_ID ) {
1604+ for (const DisplayServer::WindowID &window_id : wl ) {
1605+ Window *w = Window::get_from_id (window_id) ;
1606+ if (!w ) {
16071607 continue ;
16081608 }
16091609
1610- ObjectID woid = DisplayServer::get_singleton ()->window_get_attached_instance_id (wid);
1611- if (woid == ObjectID ()) {
1612- continue ;
1613- }
1614-
1615- Window *w = Object::cast_to<Window>(ObjectDB::get_instance (woid));
16161610 Ref<Image> img = w->get_texture ()->get_image ();
16171611 if (!img.is_valid () || img->is_empty ()) {
16181612 continue ;
Original file line number Diff line number Diff line change @@ -3772,19 +3772,9 @@ void Viewport::set_embedding_subwindows(bool p_embed) {
37723772 }
37733773
37743774 if (allow_change) {
3775- Vector<int > wl = DisplayServer::get_singleton ()->get_window_list ();
3776- for (int index = 0 ; index < wl.size (); index++) {
3777- DisplayServer::WindowID wid = wl[index];
3778- if (wid == DisplayServer::INVALID_WINDOW_ID) {
3779- continue ;
3780- }
3781-
3782- ObjectID woid = DisplayServer::get_singleton ()->window_get_attached_instance_id (wid);
3783- if (woid.is_null ()) {
3784- continue ;
3785- }
3786-
3787- Window *w = Object::cast_to<Window>(ObjectDB::get_instance (woid));
3775+ Vector<DisplayServer::WindowID> wl = DisplayServer::get_singleton ()->get_window_list ();
3776+ for (const DisplayServer::WindowID &window_id : wl) {
3777+ const Window *w = Window::get_from_id (window_id);
37883778 if (w && is_ancestor_of (w)) {
37893779 // Prevent change when this viewport has child windows that are displayed as native windows.
37903780 allow_change = false ;
Original file line number Diff line number Diff line change @@ -270,6 +270,13 @@ void Window::_validate_property(PropertyInfo &p_property) const {
270270
271271//
272272
273+ Window *Window::get_from_id (DisplayServer::WindowID p_window_id) {
274+ if (p_window_id == DisplayServer::INVALID_WINDOW_ID) {
275+ return nullptr ;
276+ }
277+ return Object::cast_to<Window>(ObjectDB::get_instance (DisplayServer::get_singleton ()->window_get_attached_instance_id (p_window_id)));
278+ }
279+
273280void Window::set_title (const String &p_title) {
274281 ERR_MAIN_THREAD_GUARD;
275282
@@ -912,7 +919,7 @@ void Window::_make_transient() {
912919 if (!is_embedded () && transient_to_focused) {
913920 DisplayServer::WindowID focused_window_id = DisplayServer::get_singleton ()->get_focused_window ();
914921 if (focused_window_id != DisplayServer::INVALID_WINDOW_ID) {
915- window = Object::cast_to< Window>( ObjectDB::get_instance ( DisplayServer::get_singleton ()-> window_get_attached_instance_id ( focused_window_id)) );
922+ window = Window::get_from_id ( focused_window_id);
916923 }
917924 }
918925
Original file line number Diff line number Diff line change @@ -271,6 +271,7 @@ class Window : public Viewport {
271271 };
272272
273273 static void set_root_layout_direction (int p_root_dir);
274+ static Window *get_from_id (DisplayServer::WindowID p_window_id);
274275
275276 void set_title (const String &p_title);
276277 String get_title () const ;
You can’t perform that action at this time.
0 commit comments