summaryrefslogtreecommitdiff
path: root/platform/linuxbsd/x11/display_server_x11.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/linuxbsd/x11/display_server_x11.cpp')
-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);
}
}