Merge pull request #92740 from bruvzg/subvp_ime_activation

Fix IME activation in subviewports.
This commit is contained in:
Rémi Verschelde 2024-06-04 10:10:30 +02:00
commit 0242e3ca9f
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 20 additions and 15 deletions

View File

@ -1088,13 +1088,14 @@ void LineEdit::_notification(int p_what) {
} }
if (has_focus()) { if (has_focus()) {
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) { DisplayServer::WindowID wid = get_window() ? get_window()->get_window_id() : DisplayServer::INVALID_WINDOW_ID;
DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id()); if (wid != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) {
DisplayServer::get_singleton()->window_set_ime_active(true, wid);
Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + theme_cache.font->get_height(theme_cache.font_size)) / 2) + get_global_position(); Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + theme_cache.font->get_height(theme_cache.font_size)) / 2) + get_global_position();
if (get_window()->get_embedder()) { if (get_window()->get_embedder()) {
pos += get_viewport()->get_popup_base_transform().get_origin(); pos += get_viewport()->get_popup_base_transform().get_origin();
} }
DisplayServer::get_singleton()->window_set_ime_position(pos, get_viewport()->get_window_id()); DisplayServer::get_singleton()->window_set_ime_position(pos, wid);
} }
} }
} break; } break;
@ -1111,13 +1112,14 @@ void LineEdit::_notification(int p_what) {
} }
} }
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) { DisplayServer::WindowID wid = get_window() ? get_window()->get_window_id() : DisplayServer::INVALID_WINDOW_ID;
DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id()); if (wid != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) {
DisplayServer::get_singleton()->window_set_ime_active(true, wid);
Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + theme_cache.font->get_height(theme_cache.font_size)) / 2) + get_global_position(); Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + theme_cache.font->get_height(theme_cache.font_size)) / 2) + get_global_position();
if (get_window()->get_embedder()) { if (get_window()->get_embedder()) {
pos += get_viewport()->get_popup_base_transform().get_origin(); pos += get_viewport()->get_popup_base_transform().get_origin();
} }
DisplayServer::get_singleton()->window_set_ime_position(pos, get_viewport()->get_window_id()); DisplayServer::get_singleton()->window_set_ime_position(pos, wid);
} }
show_virtual_keyboard(); show_virtual_keyboard();
@ -1126,9 +1128,10 @@ void LineEdit::_notification(int p_what) {
case NOTIFICATION_FOCUS_EXIT: { case NOTIFICATION_FOCUS_EXIT: {
_validate_caret_can_draw(); _validate_caret_can_draw();
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) { DisplayServer::WindowID wid = get_window() ? get_window()->get_window_id() : DisplayServer::INVALID_WINDOW_ID;
DisplayServer::get_singleton()->window_set_ime_position(Point2(), get_viewport()->get_window_id()); if (wid != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) {
DisplayServer::get_singleton()->window_set_ime_active(false, get_viewport()->get_window_id()); DisplayServer::get_singleton()->window_set_ime_position(Point2(), wid);
DisplayServer::get_singleton()->window_set_ime_active(false, wid);
} }
ime_text = ""; ime_text = "";
ime_selection = Point2(); ime_selection = Point2();

View File

@ -2831,24 +2831,26 @@ void TextEdit::_update_caches() {
} }
void TextEdit::_close_ime_window() { void TextEdit::_close_ime_window() {
if (get_viewport()->get_window_id() == DisplayServer::INVALID_WINDOW_ID || !DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) { DisplayServer::WindowID wid = get_window() ? get_window()->get_window_id() : DisplayServer::INVALID_WINDOW_ID;
if (wid == DisplayServer::INVALID_WINDOW_ID || !DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) {
return; return;
} }
DisplayServer::get_singleton()->window_set_ime_position(Point2(), get_viewport()->get_window_id()); DisplayServer::get_singleton()->window_set_ime_position(Point2(), wid);
DisplayServer::get_singleton()->window_set_ime_active(false, get_viewport()->get_window_id()); DisplayServer::get_singleton()->window_set_ime_active(false, wid);
} }
void TextEdit::_update_ime_window_position() { void TextEdit::_update_ime_window_position() {
if (get_viewport()->get_window_id() == DisplayServer::INVALID_WINDOW_ID || !DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) { DisplayServer::WindowID wid = get_window() ? get_window()->get_window_id() : DisplayServer::INVALID_WINDOW_ID;
if (wid == DisplayServer::INVALID_WINDOW_ID || !DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) {
return; return;
} }
DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id()); DisplayServer::get_singleton()->window_set_ime_active(true, wid);
Point2 pos = get_global_position() + get_caret_draw_pos(); Point2 pos = get_global_position() + get_caret_draw_pos();
if (get_window()->get_embedder()) { if (get_window()->get_embedder()) {
pos += get_viewport()->get_popup_base_transform().get_origin(); pos += get_viewport()->get_popup_base_transform().get_origin();
} }
// The window will move to the updated position the next time the IME is updated, not immediately. // The window will move to the updated position the next time the IME is updated, not immediately.
DisplayServer::get_singleton()->window_set_ime_position(pos, get_viewport()->get_window_id()); DisplayServer::get_singleton()->window_set_ime_position(pos, wid);
} }
void TextEdit::_update_ime_text() { void TextEdit::_update_ime_text() {