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

Improve editor popups with multiple screens #37506

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion editor/animation_bezier_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid() && mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
menu_insert_key = mb->get_position();
if (menu_insert_key.x >= timeline->get_name_limit() && menu_insert_key.x <= get_size().width - timeline->get_buttons_width()) {
Vector2 popup_pos = get_global_transform().xform(mb->get_position());
Vector2 popup_pos = get_screen_transform().xform(mb->get_position());

menu->clear();
menu->add_icon_item(bezier_icon, TTR("Insert Key Here"), MENU_KEY_INSERT);
Expand Down
6 changes: 3 additions & 3 deletions editor/connections_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,13 +827,13 @@ void ConnectionsDock::_rmb_pressed(Vector2 position) {
return;
}

Vector2 global_position = tree->get_global_position() + position;
Vector2 screen_position = tree->get_screen_position() + position;

if (_is_item_signal(*item)) {
signal_menu->set_position(global_position);
signal_menu->set_position(screen_position);
signal_menu->popup();
} else {
slot_menu->set_position(global_position);
slot_menu->set_position(screen_position);
slot_menu->popup();
}
}
Expand Down
2 changes: 1 addition & 1 deletion editor/debugger/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ void ScriptEditorDebugger::_error_tree_item_rmb_selected(const Vector2 &p_pos) {
}

if (item_menu->get_item_count() > 0) {
item_menu->set_position(error_tree->get_global_position() + p_pos);
item_menu->set_position(error_tree->get_screen_position() + p_pos);
item_menu->popup();
}
}
Expand Down
2 changes: 1 addition & 1 deletion editor/dependency_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void DependencyEditorOwners::_list_rmb_select(int p_item, const Vector2 &p_pos)
file_options->add_item(TTR("Open"), FILE_OPEN);
}

file_options->set_position(owners->get_global_position() + p_pos);
file_options->set_position(owners->get_screen_position() + p_pos);
file_options->popup();
}

Expand Down
6 changes: 3 additions & 3 deletions editor/editor_audio_buses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ void EditorAudioBus::_effect_edited() {
if (effect->get_metadata(0) == Variant()) {
Rect2 area = effects->get_item_rect(effect);

effect_options->set_position(effects->get_global_position() + area.position + Vector2(0, area.size.y));
effect_options->set_position(effects->get_screen_position() + area.position + Vector2(0, area.size.y));
effect_options->popup();
//add effect
} else {
Expand Down Expand Up @@ -540,7 +540,7 @@ void EditorAudioBus::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) {
Vector2 pos = Vector2(mb->get_position().x, mb->get_position().y);
bus_popup->set_position(get_global_position() + pos);
bus_popup->set_position(get_screen_position() + pos);
bus_popup->popup();
}
}
Expand Down Expand Up @@ -730,7 +730,7 @@ void EditorAudioBus::_effect_rmb(const Vector2 &p_pos) {
return;
}

delete_effect_popup->set_position(get_global_mouse_position());
delete_effect_popup->set_position(get_screen_transform().xform(get_local_mouse_position()));
delete_effect_popup->popup();
}

Expand Down
4 changes: 2 additions & 2 deletions editor/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ void EditorFileDialog::_item_list_item_rmb_selected(int p_item, const Vector2 &p
}

if (item_menu->get_item_count() > 0) {
item_menu->set_position(item_list->get_global_position() + p_pos);
item_menu->set_position(item_list->get_screen_position() + p_pos);
item_menu->popup();
}
}
Expand All @@ -596,7 +596,7 @@ void EditorFileDialog::_item_list_rmb_clicked(const Vector2 &p_pos) {
item_menu->add_separator();
item_menu->add_icon_item(item_list->get_theme_icon("Filesystem", "EditorIcons"), TTR("Open in File Manager"), ITEM_MENU_SHOW_IN_EXPLORER);

item_menu->set_position(item_list->get_global_position() + p_pos);
item_menu->set_position(item_list->get_screen_position() + p_pos);
item_menu->popup();
}

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4575,7 +4575,7 @@ void EditorNode::_scene_tab_input(const Ref<InputEvent> &p_input) {
scene_tabs_context_menu->add_item(TTR("Close Tabs to the Right"), FILE_CLOSE_RIGHT);
scene_tabs_context_menu->add_item(TTR("Close All Tabs"), FILE_CLOSE_ALL);
}
scene_tabs_context_menu->set_position(mb->get_global_position());
scene_tabs_context_menu->set_position(scene_tabs->get_screen_transform().xform(mb->get_position()));
scene_tabs_context_menu->popup();
}
}
Expand Down
8 changes: 4 additions & 4 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2288,7 +2288,7 @@ void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) {
tree_popup->clear();
tree_popup->set_size(Size2(1, 1));
_file_and_folders_fill_popup(tree_popup, paths);
tree_popup->set_position(tree->get_global_position() + p_pos);
tree_popup->set_position(tree->get_screen_position() + p_pos);
tree_popup->popup();
}
}
Expand All @@ -2302,7 +2302,7 @@ void FileSystemDock::_tree_rmb_empty(const Vector2 &p_pos) {
tree_popup->add_icon_item(get_theme_icon("PackedScene", "EditorIcons"), TTR("New Scene..."), FILE_NEW_SCENE);
tree_popup->add_icon_item(get_theme_icon("Script", "EditorIcons"), TTR("New Script..."), FILE_NEW_SCRIPT);
tree_popup->add_icon_item(get_theme_icon("Object", "EditorIcons"), TTR("New Resource..."), FILE_NEW_RESOURCE);
tree_popup->set_position(tree->get_global_position() + p_pos);
tree_popup->set_position(tree->get_screen_position() + p_pos);
tree_popup->popup();
}

Expand All @@ -2329,7 +2329,7 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) {
file_list_popup->clear();
file_list_popup->set_size(Size2(1, 1));
_file_and_folders_fill_popup(file_list_popup, paths, searched_string.length() == 0);
file_list_popup->set_position(files->get_global_position() + p_pos);
file_list_popup->set_position(files->get_screen_position() + p_pos);
file_list_popup->popup();
}
}
Expand All @@ -2349,7 +2349,7 @@ void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) {
file_list_popup->add_icon_item(get_theme_icon("Object", "EditorIcons"), TTR("New Resource..."), FILE_NEW_RESOURCE);
file_list_popup->add_separator();
file_list_popup->add_icon_item(get_theme_icon("Filesystem", "EditorIcons"), TTR("Open in File Manager"), FILE_SHOW_IN_EXPLORER);
file_list_popup->set_position(files->get_global_position() + p_pos);
file_list_popup->set_position(files->get_screen_position() + p_pos);
file_list_popup->popup();
}

Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/animation_blend_tree_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request() {
void AnimationNodeBlendTreeEditor::_popup_request(const Vector2 &p_position) {
_update_options_menu();
use_popup_menu_position = true;
popup_menu_position = graph->get_local_mouse_position();
popup_menu_position = get_screen_transform().xform(graph->get_local_mouse_position());
add_node->get_popup()->set_position(p_position);
add_node->get_popup()->popup();
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/curve_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
switch (mb.get_button_index()) {
case BUTTON_RIGHT:
_context_click_pos = mpos;
open_context_menu(get_global_transform().xform(mpos));
open_context_menu(get_screen_transform().xform(mpos));
break;

case BUTTON_MIDDLE:
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2483,7 +2483,7 @@ void ScriptEditor::_make_script_list_context_menu() {
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_sort"), WINDOW_SORT);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/toggle_scripts_panel"), TOGGLE_SCRIPTS_PANEL);

context_menu->set_position(get_global_transform().xform(get_local_mouse_position()));
context_menu->set_position(get_screen_transform().xform(get_local_mouse_position()));
context_menu->set_size(Vector2(1, 1));
context_menu->popup();
}
Expand Down
4 changes: 2 additions & 2 deletions editor/plugins/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
float alpha = color.size() > 3 ? color[3] : 1.0f;
color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha));
}
color_panel->set_position(get_global_transform().xform(local_pos));
color_panel->set_position(get_screen_transform().xform(local_pos));
} else {
has_color = false;
}
Expand Down Expand Up @@ -1717,7 +1717,7 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p
}
}

context_menu->set_position(get_global_transform().xform(p_pos));
context_menu->set_position(get_screen_transform().xform(p_pos));
giarve marked this conversation as resolved.
Show resolved Hide resolved
context_menu->set_size(Vector2(1, 1));
context_menu->popup();
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ void ShaderEditor::_make_context_menu(bool p_selection, Vector2 p_position) {
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE);

context_menu->set_position(get_global_transform().xform(p_position));
context_menu->set_position(get_screen_transform().xform(p_position));
context_menu->set_size(Vector2(1, 1));
context_menu->popup();
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE);
}

context_menu->set_position(get_global_transform().xform(p_position));
context_menu->set_position(get_screen_transform().xform(p_position));
context_menu->set_size(Vector2(1, 1));
context_menu->popup();
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/visual_shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,7 @@ void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos) {
} else {
members_dialog->popup();
saved_node_pos_dirty = false;
members_dialog->set_position(graph->get_global_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
members_dialog->set_position(graph->get_screen_position() + Point2(5 * EDSCALE, 65 * EDSCALE));
}

// keep dialog within window bounds
Expand Down
2 changes: 1 addition & 1 deletion editor/project_settings_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ void ProjectSettingsEditor::_action_button_pressed(Object *p_obj, int p_column,

if (p_id == 1) {
// Add action event
Point2 ofs = input_editor->get_global_position();
Point2 ofs = input_editor->get_screen_position();
Rect2 ir = input_editor->get_item_rect(ti);
ir.position.y -= input_editor->get_scroll().y;
ofs += ir.position + ir.size;
Expand Down
3 changes: 2 additions & 1 deletion editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2381,8 +2381,9 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
menu->add_icon_shortcut(get_theme_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
}

Vector2 screen_menu_pos = get_screen_transform().xform(p_menu_pos);
menu->set_size(Size2(1, 1));
menu->set_position(p_menu_pos);
menu->set_position(screen_menu_pos);
menu->popup();
return;
}
Expand Down
34 changes: 24 additions & 10 deletions platform/linuxbsd/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,8 @@ int DisplayServerX11::window_get_current_screen(WindowID p_window) const {
const WindowData &wd = windows[p_window];

int x, y;
Window child;
XTranslateCoordinates(x11_display, wd.x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child);
x = wd.position.x;
y = wd.position.y;

int count = get_screen_count();
for (int i = 0; i < count; i++) {
Expand All @@ -816,7 +816,6 @@ void DisplayServerX11::window_set_current_screen(int p_screen, WindowID p_window
_THREAD_SAFE_METHOD_

ERR_FAIL_COND(!windows.has(p_window));
WindowData &wd = windows[p_window];

int count = get_screen_count();
if (p_screen >= count) {
Expand All @@ -827,11 +826,16 @@ void DisplayServerX11::window_set_current_screen(int p_screen, WindowID p_window
Point2i position = screen_get_position(p_screen);
Size2i size = screen_get_size(p_screen);

WindowData &wd = windows[p_window];
XMoveResizeWindow(x11_display, wd.x11_window, position.x, position.y, size.x, size.y);
} else {
if (p_screen != window_get_current_screen(p_window)) {
Point2i position = screen_get_position(p_screen);
XMoveWindow(x11_display, wd.x11_window, position.x, position.y);
int current_screen = window_get_current_screen(p_window);
if (p_screen != current_screen) {
Point2i to_screen_pos = screen_get_position(p_screen);
Copy link
Member

@bruvzg bruvzg Apr 13, 2020

Choose a reason for hiding this comment

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

Notes for the future improvemet:

  • Special Fullscreen case probably should be ported to Windows and macOS as well.
  • In case current window position (relative to the current screen) is bigger than target screen size, window will be moved to the wrong screen (not handled on any platform).

e.g. with the following display config, moving window to screen 1 will move it to screen 2 instead:
Screenshot 2020-04-13 at 12 14 49

Point2i from_window_pos = window_get_position(p_window) - screen_get_position(current_screen);

Point2i to_move_to = from_window_pos + to_screen_pos;
window_set_position(to_move_to, p_window);
}
}
}
Expand Down Expand Up @@ -908,7 +912,10 @@ void DisplayServerX11::window_set_position(const Point2i &p_position, WindowID p
}
}
}

XMoveWindow(x11_display, wd.x11_window, p_position.x - x, p_position.y - y);
XSync(x11_display, False);

_update_real_mouse_position(wd);
}

Expand Down Expand Up @@ -1256,10 +1263,16 @@ void DisplayServerX11::_set_wm_fullscreen(WindowID p_window, bool p_enabled) {
XFree(xsh);

// put back or remove decorations according to the last set borderless state
bool borderless_state = window_get_flag(WINDOW_FLAG_BORDERLESS, p_window) ? 0 : 1;

// restore borders always for main window
// it has become borderless before entering fullscreen
borderless_state = (p_window == MAIN_WINDOW_ID) ? 1 : borderless_state;

Hints hints;
Atom property;
hints.flags = 2;
hints.decorations = window_get_flag(WINDOW_FLAG_BORDERLESS, p_window) ? 0 : 1;
hints.decorations = borderless_state;
property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True);
XChangeProperty(x11_display, wd.x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
}
Expand Down Expand Up @@ -3304,7 +3317,7 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, u
my_hints.height = p_rect.size.height;

XSetNormalHints(x11_display, wd.x11_window, &my_hints);
XMoveWindow(x11_display, wd.x11_window, p_rect.position.x, p_rect.position.y);
XMoveResizeWindow(x11_display, wd.x11_window, p_rect.position.x, p_rect.position.y, p_rect.size.width, p_rect.size.height);
}

#if defined(VULKAN_ENABLED)
Expand Down Expand Up @@ -3334,8 +3347,9 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, u
XSync(x11_display, False);
XGetWindowAttributes(x11_display, wd.x11_window, &xwa);

wd.position.x = xwa.x;
wd.position.y = xwa.y;
wd.position.x = p_rect.position.x;
wd.position.y = p_rect.position.y;
giarve marked this conversation as resolved.
Show resolved Hide resolved

wd.size.width = xwa.width;
wd.size.height = xwa.height;

Expand Down
2 changes: 1 addition & 1 deletion scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,7 @@ Control *Control::get_focus_owner() const {

void Control::warp_mouse(const Point2 &p_to_pos) {
ERR_FAIL_COND(!is_inside_tree());
get_viewport()->warp_mouse(get_global_transform().xform(p_to_pos));
get_viewport()->warp_mouse(get_screen_transform().xform(p_to_pos));
}

bool Control::is_text_field() const {
Expand Down
4 changes: 2 additions & 2 deletions scene/gui/line_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {

if (b.is_valid()) {
if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT && context_menu_enabled) {
menu->set_position(get_global_transform().xform(get_local_mouse_position()));
menu->set_position(get_screen_transform().xform(get_local_mouse_position()));
menu->set_size(Vector2(1, 1));
//menu->set_scale(get_global_transform().get_scale());
menu->popup();
Expand Down Expand Up @@ -546,7 +546,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case KEY_MENU: {
if (context_menu_enabled) {
Point2 pos = Point2(get_cursor_pixel_pos(), (get_size().y + get_theme_font("font")->get_height()) / 2);
menu->set_position(get_global_transform().xform(pos));
menu->set_position(get_screen_transform().xform(pos));
menu->set_size(Vector2(1, 1));
// menu->set_scale(get_global_transform().get_scale());
menu->popup();
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/popup_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void PopupMenu::_activate_submenu(int over) {
Point2 pos = p + Point2(get_size().width, items[over]._ofs_cache - style->get_offset().y);
Size2 size = pm->get_size();
// fix pos
if (pos.x + size.width > get_parent_rect().size.width) {
if (pos.x + size.width > get_parent_rect().position.x + get_parent_rect().size.width) {
pos.x = p.x - size.width;
}

Expand Down
2 changes: 1 addition & 1 deletion scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3704,7 +3704,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {

case KEY_MENU: {
if (context_menu_enabled) {
menu->set_position(get_global_transform().xform(_get_cursor_pixel_pos()));
menu->set_position(get_screen_transform().xform(_get_cursor_pixel_pos()));
menu->set_size(Vector2(1, 1));
// menu->set_scale(get_global_transform().get_scale());
menu->popup();
Expand Down
4 changes: 2 additions & 2 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ void Viewport::_gui_show_tooltip() {
}

Control *which = nullptr;
String tooltip = _gui_get_tooltip(gui.tooltip, gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos), &which);
String tooltip = _gui_get_tooltip(gui.tooltip, gui.tooltip->get_screen_transform().xform_inv(gui.tooltip_pos), &which);
tooltip = tooltip.strip_edges();
if (tooltip.length() == 0) {
return; // bye
Expand Down Expand Up @@ -2043,7 +2043,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {

if (gui.tooltip_popup) {
if (can_tooltip && gui.tooltip) {
String tooltip = _gui_get_tooltip(over, gui.tooltip->get_global_transform().xform_inv(mpos));
String tooltip = _gui_get_tooltip(over, gui.tooltip->get_screen_transform().xform_inv(mpos));

if (tooltip.length() == 0) {
_gui_cancel_tooltip();
Expand Down
3 changes: 2 additions & 1 deletion scene/main/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ void Window::_make_window() {

window_id = DisplayServer::get_singleton()->create_sub_window(DisplayServer::WindowMode(mode), f, Rect2i(position, size));
ERR_FAIL_COND(window_id == DisplayServer::INVALID_WINDOW_ID);
DisplayServer::get_singleton()->window_set_current_screen(current_screen, window_id);
DisplayServer::WindowID parent_id = get_parent_visible_window()->get_window_id();
set_current_screen(DisplayServer::get_singleton()->window_get_current_screen(parent_id));
DisplayServer::get_singleton()->window_set_max_size(max_size, window_id);
DisplayServer::get_singleton()->window_set_min_size(min_size, window_id);
DisplayServer::get_singleton()->window_set_title(title, window_id);
Expand Down