[X11] Prevent IME activation from entering infinite loop.
This commit is contained in:
parent
a3a42159e3
commit
b713cfdccd
1 changed files with 34 additions and 31 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue