Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Embedded Game Window with user arguments #101739

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions editor/plugins/game_view_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ void GameView::_update_arguments_for_instance(int p_idx, List<String> &r_argumen

// Remove duplicates/unwanted parameters.
List<String>::Element *E = r_arguments.front();
List<String>::Element *user_args_element = nullptr;
while (E) {
List<String>::Element *N = E->next();

Expand All @@ -583,23 +584,26 @@ void GameView::_update_arguments_for_instance(int p_idx, List<String> &r_argumen
}
} else if (E->get() == "-f" || E->get() == "--fullscreen" || E->get() == "-m" || E->get() == "--maximized" || E->get() == "-t" || E->get() == "-always-on-top") {
r_arguments.erase(E);
} else if (E->get() == "--" || E->get() == "++") {
user_args_element = E;
break;
}

E = N;
}

// Add the editor window's native ID so the started game can directly set it as its parent.
r_arguments.push_back("--wid");
r_arguments.push_back(itos(DisplayServer::get_singleton()->window_get_native_handle(DisplayServer::WINDOW_HANDLE, get_window()->get_window_id())));
List<String>::Element *N = r_arguments.insert_before(user_args_element, "--wid");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: insert_before handle nullptr as push_back, so it's fine if it's not set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first, I used a if(user_args_element) push_back else insert_before then I saw at insert_before handles nullptr as you said. Would it be preferable to manage the nullptr here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's fine as is.

N = r_arguments.insert_after(N, itos(DisplayServer::get_singleton()->window_get_native_handle(DisplayServer::WINDOW_HANDLE, get_window()->get_window_id())));

// Be sure to have the correct window size in the embedded_process control.
_update_embed_window_size();

Rect2i rect = embedded_process->get_screen_embedded_window_rect();
r_arguments.push_back("--position");
r_arguments.push_back(itos(rect.position.x) + "," + itos(rect.position.y));
r_arguments.push_back("--resolution");
r_arguments.push_back(itos(rect.size.x) + "x" + itos(rect.size.y));
N = r_arguments.insert_after(N, "--position");
N = r_arguments.insert_after(N, itos(rect.position.x) + "," + itos(rect.position.y));
N = r_arguments.insert_after(N, "--resolution");
r_arguments.insert_after(N, itos(rect.size.x) + "x" + itos(rect.size.y));
}

void GameView::_window_before_closing() {
Expand Down