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

Add support for embedding subwindows and dual screen GameViews #104079

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions core/config/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ bool Engine::is_embedded_in_editor() const {
return embedded_in_editor;
}

void Engine::add_embedded_subwindow(String p_subwindow_title, int64_t p_parent_id) {
embedded_subwindows[p_subwindow_title] = p_parent_id;
}

int64_t Engine::get_embedded_subwindow(String p_subwindow_title) {
if (embedded_subwindows.has(p_subwindow_title)) {
return embedded_subwindows[p_subwindow_title];
}
return 0;
}

Engine::Engine() {
singleton = this;
}
Expand Down
3 changes: 3 additions & 0 deletions core/config/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class Engine {
bool project_manager_hint = false;
bool extension_reloading = false;
bool embedded_in_editor = false;
HashMap<String, int64_t> embedded_subwindows;
bool recovery_mode_hint = false;

bool _print_header = true;
Expand Down Expand Up @@ -145,6 +146,8 @@ class Engine {
void set_frame_delay(uint32_t p_msec);
uint32_t get_frame_delay() const;

void add_embedded_subwindow(String p_subwindow_title, int64_t p_parent_id);
int64_t get_embedded_subwindow(String p_subwindow_title);
void add_singleton(const Singleton &p_singleton);
void get_singletons(List<Singleton> *p_singletons);
bool has_singleton(const StringName &p_name) const;
Expand Down
9 changes: 5 additions & 4 deletions editor/plugins/embedded_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ int EmbeddedProcess::get_embedded_pid() const {
return current_process_id;
}

void EmbeddedProcess::embed_process(OS::ProcessID p_pid) {
void EmbeddedProcess::embed_process(OS::ProcessID p_pid, String p_embedded_window) {
if (!window) {
return;
}
Expand All @@ -169,6 +169,7 @@ void EmbeddedProcess::embed_process(OS::ProcessID p_pid) {
reset();

current_process_id = p_pid;
current_embedded_window = p_embedded_window;
start_embedding_time = OS::get_singleton()->get_ticks_msec();
embedding_grab_focus = has_focus();
timer_update_embedded_process->start();
Expand All @@ -182,7 +183,7 @@ void EmbeddedProcess::embed_process(OS::ProcessID p_pid) {

void EmbeddedProcess::reset() {
if (current_process_id != 0 && embedding_completed) {
DisplayServer::get_singleton()->remove_embedded_process(current_process_id);
DisplayServer::get_singleton()->remove_embedded_process(current_process_id, current_embedded_window);
}
current_process_id = 0;
embedding_completed = false;
Expand All @@ -203,7 +204,7 @@ void EmbeddedProcess::request_close() {

void EmbeddedProcess::_try_embed_process() {
bool is_visible = is_visible_in_tree();
Error err = DisplayServer::get_singleton()->embed_process(window->get_window_id(), current_process_id, get_screen_embedded_window_rect(), is_visible, is_visible && application_has_focus && embedding_grab_focus);
Error err = DisplayServer::get_singleton()->embed_process(window->get_window_id(), current_process_id, current_embedded_window, get_screen_embedded_window_rect(), is_visible, is_visible && application_has_focus && embedding_grab_focus);
if (err == OK) {
embedding_completed = true;
queue_redraw();
Expand Down Expand Up @@ -262,7 +263,7 @@ void EmbeddedProcess::_update_embedded_process() {
last_updated_embedded_process_focused = focus;
}

DisplayServer::get_singleton()->embed_process(window->get_window_id(), current_process_id, get_screen_embedded_window_rect(), is_visible_in_tree(), must_grab_focus);
DisplayServer::get_singleton()->embed_process(window->get_window_id(), current_process_id, current_embedded_window, get_screen_embedded_window_rect(), is_visible_in_tree(), must_grab_focus);
emit_signal(SNAME("embedded_process_updated"));
}

Expand Down
3 changes: 2 additions & 1 deletion editor/plugins/embedded_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class EmbeddedProcess : public Control {
uint64_t last_application_focus_time = 0;
OS::ProcessID focused_process_id = 0;
OS::ProcessID current_process_id = 0;
String current_embedded_window = "";
bool embedding_grab_focus = false;
bool embedding_completed = false;
uint64_t start_embedding_time = 0;
Expand Down Expand Up @@ -74,7 +75,7 @@ class EmbeddedProcess : public Control {
void _notification(int p_what);

public:
void embed_process(OS::ProcessID p_pid);
void embed_process(OS::ProcessID p_pid, String p_embedded_window);
void reset();
void request_close();

Expand Down
Loading