summaryrefslogtreecommitdiff
path: root/platform/linuxbsd
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-25 09:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-25 09:44:50 +0100
commit4368191a9f9c6290805dd4094c36379776128338 (patch)
treec9d376c6a53d39b45b624d4a80f06cbc6a38cd77 /platform/linuxbsd
parent3f4b635077ededac136911e59e5e1ca3c1f300cb (diff)
parentb713cfdccd4d9c0f4fe15ad5d850866cb1707b52 (diff)
Merge pull request #72018 from bruvzg/x11_ime_loop
[X11] Prevent IME activation from entering infinite loop.
Diffstat (limited to 'platform/linuxbsd')
-rw-r--r--platform/linuxbsd/x11/display_server_x11.cpp65
1 files changed, 34 insertions, 31 deletions
diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp
index 9971fe8c79..f1159c3981 100644
--- a/platform/linuxbsd/x11/display_server_x11.cpp
+++ b/platform/linuxbsd/x11/display_server_x11.cpp
@@ -2496,6 +2496,9 @@ void DisplayServerX11::window_set_ime_active(const bool p_active, WindowID p_win
return;
}
if (!wd.focused) {
+ wd.ime_active = false;
+ im_text = String();
+ im_selection = Vector2i();
return;
}
@@ -2524,7 +2527,6 @@ void DisplayServerX11::window_set_ime_active(const bool p_active, WindowID p_win
im_text = String();
im_selection = Vector2i();
}
- OS_Unix::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_OS_IME_UPDATE);
}
void DisplayServerX11::window_set_ime_position(const Point2i &p_pos, WindowID p_window) {
@@ -3316,42 +3318,43 @@ void DisplayServerX11::_xim_preedit_draw_callback(::XIM xim, ::XPointer client_d
WindowData &wd = ds->windows[window_id];
XIMText *xim_text = call_data->text;
- if (xim_text != nullptr) {
- String changed_text;
- if (xim_text->encoding_is_wchar) {
- changed_text = String(xim_text->string.wide_char);
- } else {
- changed_text.parse_utf8(xim_text->string.multi_byte);
- }
+ if (wd.ime_active) {
+ if (xim_text != nullptr) {
+ String changed_text;
+ if (xim_text->encoding_is_wchar) {
+ changed_text = String(xim_text->string.wide_char);
+ } else {
+ changed_text.parse_utf8(xim_text->string.multi_byte);
+ }
- if (call_data->chg_length < 0) {
- ds->im_text = ds->im_text.substr(0, call_data->chg_first) + changed_text;
- } else {
- ds->im_text = ds->im_text.substr(0, call_data->chg_first) + changed_text + ds->im_text.substr(call_data->chg_length);
- }
+ if (call_data->chg_length < 0) {
+ ds->im_text = ds->im_text.substr(0, call_data->chg_first) + changed_text;
+ } else {
+ ds->im_text = ds->im_text.substr(0, call_data->chg_first) + changed_text + ds->im_text.substr(call_data->chg_length);
+ }
- // Find the start and end of the selection.
- int start = 0, count = 0;
- for (int i = 0; i < xim_text->length; i++) {
- if (xim_text->feedback[i] & XIMReverse) {
- if (count == 0) {
- start = i;
- count = 1;
- } else {
- count++;
+ // Find the start and end of the selection.
+ int start = 0, count = 0;
+ for (int i = 0; i < xim_text->length; i++) {
+ if (xim_text->feedback[i] & XIMReverse) {
+ if (count == 0) {
+ start = i;
+ count = 1;
+ } else {
+ count++;
+ }
}
}
- }
- if (count > 0) {
- ds->im_selection = Point2i(start + call_data->chg_first, count);
+ if (count > 0) {
+ ds->im_selection = Point2i(start + call_data->chg_first, count);
+ } else {
+ ds->im_selection = Point2i(call_data->caret, 0);
+ }
} else {
- ds->im_selection = Point2i(call_data->caret, 0);
+ ds->im_text = String();
+ ds->im_selection = Point2i();
}
- } else {
- ds->im_text = String();
- ds->im_selection = Point2i();
- }
- if (wd.ime_active) {
+
OS_Unix::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_OS_IME_UPDATE);
}
}