Skip to content

Commit

Permalink
Open sub-windows as embedded if the OS does not support them
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Mar 26, 2020
1 parent 441f1a5 commit c7b4dca
Show file tree
Hide file tree
Showing 32 changed files with 1,023 additions and 632 deletions.
5 changes: 4 additions & 1 deletion editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2853,7 +2853,10 @@ void AnimationTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
Vector2 theme_ofs = path->get_theme_stylebox("normal", "LineEdit")->get_offset();
path->set_position(get_global_position() + path_rect.position - theme_ofs);
path->set_size(path_rect.size);
path->show_modal();
#ifndef _MSC_VER
#warning show modal not supported any longer, need to move this to a popup
#endif
path->show();
path->grab_focus();
path->set_cursor_position(path->get_text().length());
clicking_on_name = false;
Expand Down
5 changes: 1 addition & 4 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,8 @@ void EditorNode::_update_title() {

void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) {

if (Node::get_viewport()->get_modal_stack_top())
return; //ignore because of modal window

Ref<InputEventKey> k = p_event;
if (k.is_valid() && k->is_pressed() && !k->is_echo() && !gui_base->get_viewport()->gui_has_modal_stack()) {
if (k.is_valid() && k->is_pressed() && !k->is_echo()) {

EditorPlugin *old_editor = editor_plugin_screen;

Expand Down
19 changes: 10 additions & 9 deletions editor/editor_themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,15 +911,16 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
style_window->set_border_width(MARGIN_TOP, 24 * EDSCALE);
style_window->set_expand_margin_size(MARGIN_TOP, 24 * EDSCALE);

theme->set_stylebox("panel", "AcceptDialog", style_default);
theme->set_stylebox("panel_window", "AcceptDialog", style_window);
theme->set_color("title_color", "AcceptDialog", font_color);
theme->set_icon("close", "AcceptDialog", theme->get_icon("GuiClose", "EditorIcons"));
theme->set_icon("close_highlight", "AcceptDialog", theme->get_icon("GuiClose", "EditorIcons"));
theme->set_constant("close_h_ofs", "AcceptDialog", 22 * EDSCALE);
theme->set_constant("close_v_ofs", "AcceptDialog", 20 * EDSCALE);
theme->set_constant("title_height", "AcceptDialog", 24 * EDSCALE);
theme->set_font("title_font", "AcceptDialog", theme->get_font("title", "EditorFonts"));
theme->set_stylebox("panel", "Window", style_default);
theme->set_stylebox("panel_window", "Window", style_window);
theme->set_color("title_color", "Window", font_color);
theme->set_icon("close", "Window", theme->get_icon("GuiClose", "EditorIcons"));
theme->set_icon("close_highlight", "Window", theme->get_icon("GuiClose", "EditorIcons"));
theme->set_constant("close_h_ofs", "Window", 22 * EDSCALE);
theme->set_constant("close_v_ofs", "Window", 20 * EDSCALE);
theme->set_constant("title_height", "Window", 24 * EDSCALE);
theme->set_constant("resize_margin", "Window", 4 * EDSCALE);
theme->set_font("title_font", "Window", theme->get_font("title", "EditorFonts"));

// complex window, for now only Editor settings and Project settings
Ref<StyleBoxFlat> style_complex_window = style_window->duplicate();
Expand Down
4 changes: 0 additions & 4 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2350,8 +2350,6 @@ void FileSystemDock::_file_multi_selected(int p_index, bool p_selected) {
}

void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) {
if (get_viewport()->get_modal_stack_top())
return; // Ignore because of modal window.

Ref<InputEventKey> key = p_event;
if (key.is_valid() && key->is_pressed() && !key->is_echo()) {
Expand All @@ -2368,8 +2366,6 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) {
}

void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) {
if (get_viewport()->get_modal_stack_top())
return; // Ignore because of modal window.

Ref<InputEventKey> key = p_event;
if (key.is_valid() && key->is_pressed() && !key->is_echo()) {
Expand Down
6 changes: 5 additions & 1 deletion editor/plugins/animation_state_machine_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv
name_edit->set_global_position(state_machine_draw->get_global_transform().xform(edit_rect.position));
name_edit->set_size(edit_rect.size);
name_edit->set_text(node_rects[i].node_name);
name_edit->show_modal();
#ifndef _MSC_VER
#warning no more show modal, so it must replaced by a popup
#endif
//name_edit->show_modal();
name_edit->show();
name_edit->grab_focus();
name_edit->select_all();

Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {

Ref<InputEventKey> k = p_ev;

if (!is_visible_in_tree() || get_viewport()->gui_has_modal_stack())
if (!is_visible_in_tree())
return;

if (k->get_keycode() == KEY_CONTROL || k->get_keycode() == KEY_ALT || k->get_keycode() == KEY_SHIFT) {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/spatial_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5718,7 +5718,7 @@ void SpatialEditor::snap_selected_nodes_to_floor() {

void SpatialEditor::_unhandled_key_input(Ref<InputEvent> p_event) {

if (!is_visible_in_tree() || get_viewport()->gui_has_modal_stack())
if (!is_visible_in_tree())
return;

snap_key_enabled = InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL);
Expand Down
3 changes: 0 additions & 3 deletions editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ void SceneTreeDock::_input(Ref<InputEvent> p_event) {

void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) {

if (get_viewport()->get_modal_stack_top())
return; //ignore because of modal window

if (get_focus_owner() && get_focus_owner()->is_text_field())
return;

Expand Down
8 changes: 8 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ static int audio_driver_idx = -1;

// Engine config/tools

static bool single_window = false;
static bool editor = false;
static bool project_manager = false;
static String locale;
Expand Down Expand Up @@ -303,6 +304,7 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" --no-window Disable window creation (Windows only). Useful together with --script.\n");
OS::get_singleton()->print(" --enable-vsync-via-compositor When vsync is enabled, vsync via the OS' window compositor (Windows only).\n");
OS::get_singleton()->print(" --disable-vsync-via-compositor Disable vsync via the OS' window compositor (Windows only).\n");
OS::get_singleton()->print(" --single-window Use a single window (no separate subwindows).\n");
OS::get_singleton()->print("\n");
#endif

Expand Down Expand Up @@ -576,6 +578,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
} else if (I->get() == "--gpu-abort") { // force windowed window

Engine::singleton->abort_on_gpu_errors = true;
} else if (I->get() == "--single-window") { // force single window

single_window = true;
} else if (I->get() == "-t" || I->get() == "--always-on-top") { // force always-on-top window

init_always_on_top = true;
Expand Down Expand Up @@ -1710,6 +1715,9 @@ bool Main::start() {
}
#endif

if (single_window) {
sml->get_root()->set_embed_subwindows_hint(true);
}
ResourceLoader::add_custom_loaders();
ResourceSaver::add_custom_savers();

Expand Down
12 changes: 6 additions & 6 deletions platform/linuxbsd/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,13 @@ void DisplayServerX11::window_set_title(const String &p_title, WindowID p_window
XChangeProperty(x11_display, wd.x11_window, _net_wm_name, utf8_string, 8, PropModeReplace, (unsigned char *)p_title.utf8().get_data(), p_title.utf8().length());
}

void DisplayServerX11::window_set_resize_callback(const Callable &p_callable, WindowID p_window) {
void DisplayServerX11::window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window) {

_THREAD_SAFE_METHOD_

ERR_FAIL_COND(!windows.has(p_window));
WindowData &wd = windows[p_window];
wd.resize_callback = p_callable;
wd.rect_changed_callback = p_callable;
}

void DisplayServerX11::window_set_window_event_callback(const Callable &p_callable, WindowID p_window) {
Expand Down Expand Up @@ -2224,12 +2224,12 @@ void DisplayServerX11::_window_changed(XEvent *event) {
}
#endif

if (!wd.resize_callback.is_null()) {
Variant size = wd.size;
Variant *sizep = &size;
if (!wd.rect_changed_callback.is_null()) {
Variant rect = Rect2i(wd.im_position, wd.size);
Variant *rectp = &rect;
Variant ret;
Callable::CallError ce;
wd.resize_callback.call((const Variant **)&sizep, 1, ret, ce);
wd.rect_changed_callback.call((const Variant **)&rectp, 1, ret, ce);
}
}

Expand Down
4 changes: 2 additions & 2 deletions platform/linuxbsd/display_server_x11.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class DisplayServerX11 : public DisplayServer {
Size2i size;
Size2i im_position;
bool im_active = false;
Callable resize_callback;
Callable rect_changed_callback;
Callable event_callback;
Callable input_event_callback;
Callable input_text_callback;
Expand Down Expand Up @@ -268,7 +268,7 @@ class DisplayServerX11 : public DisplayServer {
virtual void delete_sub_window(WindowID p_id);

virtual void window_set_title(const String &p_title, WindowID p_window = MAIN_WINDOW_ID);
virtual void window_set_resize_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
virtual void window_set_input_text_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
Expand Down
57 changes: 43 additions & 14 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ DisplayServer::WindowID DisplayServerWindows::create_sub_window(WindowMode p_mod
}
}

ShowWindow(windows[window_id].hWnd, SW_SHOW); // Show The Window
SetForegroundWindow(windows[window_id].hWnd); // Slightly Higher Priority
SetFocus(windows[window_id].hWnd); // Sets Keyboard Focus To

return window_id;
}
void DisplayServerWindows::delete_sub_window(WindowID p_window) {
Expand Down Expand Up @@ -449,12 +453,12 @@ void DisplayServerWindows::delete_sub_window(WindowID p_window) {
windows.erase(p_window);
}

void DisplayServerWindows::window_set_resize_callback(const Callable &p_callable, WindowID p_window) {
void DisplayServerWindows::window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window) {

_THREAD_SAFE_METHOD_

ERR_FAIL_COND(!windows.has(p_window));
windows[p_window].resize_callback = p_callable;
windows[p_window].rect_changed_callback = p_callable;
}

void DisplayServerWindows::window_set_window_event_callback(const Callable &p_callable, WindowID p_window) {
Expand Down Expand Up @@ -757,20 +761,32 @@ void DisplayServerWindows::_update_window_style(WindowID p_window, bool p_repain
ERR_FAIL_COND(!windows.has(p_window));
WindowData &wd = windows[p_window];

DWORD style = 0;
DWORD style_ex = WS_EX_WINDOWEDGE;
if (p_window == MAIN_WINDOW_ID) {
style_ex |= WS_EX_APPWINDOW;
}

if (wd.fullscreen || wd.borderless) {
SetWindowLongPtr(wd.hWnd, GWL_STYLE, WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE);
style = WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE;
if (wd.borderless) {
style_ex |= WS_EX_TOOLWINDOW;
}
} else {
if (wd.resizable) {
if (p_maximized) {
SetWindowLongPtr(wd.hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_MAXIMIZE);
style = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_MAXIMIZE;
} else {
SetWindowLongPtr(wd.hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE);
style = GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE;
}
} else {
SetWindowLongPtr(wd.hWnd, GWL_STYLE, WS_CAPTION | WS_MINIMIZEBOX | WS_POPUPWINDOW | WS_VISIBLE);
style = WS_CAPTION | WS_MINIMIZEBOX | WS_POPUPWINDOW | WS_VISIBLE;
}
}

SetWindowLongPtr(wd.hWnd, GWL_STYLE, style);
SetWindowLongPtr(wd.hWnd, GWL_EXSTYLE, style_ex);

SetWindowPos(wd.hWnd, wd.always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);

if (p_repaint) {
Expand Down Expand Up @@ -2208,6 +2224,15 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
int x = LOWORD(lParam);
int y = HIWORD(lParam);
windows[window_id].last_pos = Point2(x, y);

if (!windows[window_id].rect_changed_callback.is_null()) {

Variant size = Rect2i(windows[window_id].last_pos.x, windows[window_id].last_pos.y, windows[window_id].width, windows[window_id].height);
Variant *sizep = &size;
Variant ret;
Callable::CallError ce;
windows[window_id].rect_changed_callback.call((const Variant **)&sizep, 1, ret, ce);
}
}
} break;

Expand All @@ -2232,13 +2257,13 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
}

if (!windows[window_id].resize_callback.is_null()) {
if (!windows[window_id].rect_changed_callback.is_null()) {

Variant size = Size2(windows[window_id].width, windows[window_id].height);
Variant size = Rect2i(windows[window_id].last_pos.x, windows[window_id].last_pos.y, windows[window_id].width, windows[window_id].height);
Variant *sizep = &size;
Variant ret;
Callable::CallError ce;
windows[window_id].resize_callback.call((const Variant **)&sizep, 1, ret, ce);
windows[window_id].rect_changed_callback.call((const Variant **)&sizep, 1, ret, ce);
}

if (wParam == SIZE_MAXIMIZED) {
Expand Down Expand Up @@ -2541,9 +2566,13 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,
DWORD dwExStyle;
DWORD dwStyle;

dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwExStyle = WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;

if (window_id_counter == MAIN_WINDOW_ID) {
dwExStyle |= WS_EX_APPWINDOW;
}

RECT WindowRect;

WindowRect.left = p_rect.position.x;
Expand Down Expand Up @@ -2594,10 +2623,6 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,

DragAcceptFiles(wd.hWnd, true);

ShowWindow(wd.hWnd, SW_SHOW); // Show The Window
SetForegroundWindow(wd.hWnd); // Slightly Higher Priority
SetFocus(wd.hWnd); // Sets Keyboard Focus To

// IME
wd.im_himc = ImmGetContext(wd.hWnd);
ImmReleaseContext(wd.hWnd, wd.im_himc);
Expand Down Expand Up @@ -2743,6 +2768,10 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
}
}

ShowWindow(windows[MAIN_WINDOW_ID].hWnd, SW_SHOW); // Show The Window
SetForegroundWindow(windows[MAIN_WINDOW_ID].hWnd); // Slightly Higher Priority
SetFocus(windows[MAIN_WINDOW_ID].hWnd); // Sets Keyboard Focus To

#if defined(VULKAN_ENABLED)

if (rendering_driver == "vulkan") {
Expand Down
4 changes: 2 additions & 2 deletions platform/windows/display_server_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class DisplayServerWindows : public DisplayServer {

bool layered_window = false;

Callable resize_callback;
Callable rect_changed_callback;
Callable event_callback;
Callable input_event_callback;
Callable input_text_callback;
Expand Down Expand Up @@ -293,7 +293,7 @@ class DisplayServerWindows : public DisplayServer {
virtual WindowID create_sub_window(WindowMode p_mode, uint32_t p_flags, const Rect2i &p_rect = Rect2i());
virtual void delete_sub_window(WindowID p_window);

virtual void window_set_resize_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
virtual void window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);

virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID);
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/canvas_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ Transform2D CanvasItem::get_screen_transform() const {
Transform2D xform = get_global_transform_with_canvas();

Window *w = Object::cast_to<Window>(get_viewport());
if (w) {
if (w && !w->is_embedding_subwindows()) {
Transform2D s;
s.set_origin(w->get_position());

Expand Down
3 changes: 0 additions & 3 deletions scene/gui/base_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,6 @@ void BaseButton::_unhandled_input(Ref<InputEvent> p_event) {

if (!is_disabled() && is_visible_in_tree() && !p_event->is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) {

if (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this))
return; //ignore because of modal window

on_action_event(p_event);
}
}
Expand Down
5 changes: 4 additions & 1 deletion scene/gui/color_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,10 @@ void ColorPicker::_screen_pick_pressed() {
screen->call_deferred("connect", "hide", Callable(btn_pick, "set_pressed"), varray(false));
}
screen->raise();
screen->show_modal();
#ifndef _MSC_VER
#warning show modal no longer works, needs to be converted to a popup
#endif
//screen->show_modal();
}

void ColorPicker::_focus_enter() {
Expand Down
Loading

0 comments on commit c7b4dca

Please sign in to comment.