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

Add ibus unicode input support #3058

Merged
merged 21 commits into from
May 20, 2024
Merged

Conversation

seflerZ
Copy link
Contributor

@seflerZ seflerZ commented May 5, 2024

Close #1990 . This PR was made by me and @matt335672. It introduced serveral unicode input interfaces and has the ibus interface implemented (That means you should have ibus configured in the server side first).

The unicode input is a kind of method of sending unicode codes directly from the client to the server. With it, you can input any characters or glyphs (like Emoji 😁) even if they are not present in the keymap of the keyboard. It is typically used by mobile devices like Android\iOS phones, especially in Asia languages.

Another benifit of the unicode input is you can use your device's voice input to generate a bunch of texts quickly. Although we only have the ibus implemented now, it is easy to do for other input services like fcitx.

@matt335672 This is the latest rebased. Sorry I made merge before.

matt335672 and others added 18 commits May 5, 2024 10:44
Fixes a packet in the format send between xrdp and chansrv.
UTF-16 surrogate pairs sent from the client are remapped
to full unicode characters.
- xrdp is not now built with XRDP_IBUS to allow other input
  methods to be more easily supported.
- chansrv is only aked to start an input method if the client
  supports it.
- chansrv sends a status report back to xrdp when asked to start
  and input method.
- ./configure without --enable-ibus now works.
// we can use it
if ((inputFlags & INPUT_FLAG_UNICODE) != 0)
{
self->client_info.unicode_input_support = UIS_SUPPORTED;

Choose a reason for hiding this comment

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

In my client, resizing the window repeatedly triggers the function xrdp_caps_process_input. The original UIS_ACTIVE state is reset to UIS_SUPPORTED, which results in subsequent failure to deliver.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @poetic-edge - that's a good spot.

The way we're currently doing client resizes involves using the RDP Deactivation-Reactivation Sequence

Can you try this patch? I've run out of time today.

--- a/libxrdp/xrdp_caps.c
+++ b/libxrdp/xrdp_caps.c
@@ -424,16 +424,23 @@ xrdp_caps_process_input(struct xrdp_rdp *self, struct stream *s,
     }
 
     // We always advertise Unicode support, so if the client supports it too,
-    // we can use it
-    if ((inputFlags & INPUT_FLAG_UNICODE) != 0)
+    // we can use it.
+    //
+    // If Unicode support is already active, the CAPSTYPE_INPUT
+    // PDU has been received as part of a Deactivation-Reactivation sequence.
+    // In this case, ignore the flag.
+    if (self->client_info.unicode_input_support != UIS_ACTIVE)
     {
-        self->client_info.unicode_input_support = UIS_SUPPORTED;
-        LOG(LOG_LEVEL_INFO, "Client supports Unicode input");
-    }
-    else
-    {
-        self->client_info.unicode_input_support = UIS_UNSUPPORTED;
-        LOG(LOG_LEVEL_INFO, "Client does not support Unicode input");
+        if ((inputFlags & INPUT_FLAG_UNICODE) != 0)
+        {
+            self->client_info.unicode_input_support = UIS_SUPPORTED;
+            LOG(LOG_LEVEL_INFO, "Client supports Unicode input");
+        }
+        else
+        {
+            self->client_info.unicode_input_support = UIS_UNSUPPORTED;
+            LOG(LOG_LEVEL_INFO, "Client does not support Unicode input");
+        }
     }
 
     return 0;

Choose a reason for hiding this comment

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

Thank you. It is now functioning properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I'll apply the patch.

@matt335672
Copy link
Member

@seflerZ - I've had a weekend break and have come back to discover a slightly fuller inbox than I was expecting. I'll got on to this as soon as I've cleared the backlog. Sorry.

@seflerZ
Copy link
Contributor Author

seflerZ commented May 9, 2024 via email

xrdp/xrdp_mm.c Outdated
@@ -2447,6 +2559,9 @@ xrdp_mm_chan_process_msg(struct xrdp_mm *self, struct trans *trans,
case 18:
rv = xrdp_mm_trans_process_drdynvc_data(self, s);
break;
case 20:
rv = xrdp_mm_trans_process_unicode_ack(self, s);

Choose a reason for hiding this comment

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

break; lost here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice cactch!

@matt335672
Copy link
Member

Great to see people using this before we've merged it into devel.

@seflerZ - thanks again for driving this.

@matt335672 matt335672 merged commit 98d0003 into neutrinolabs:devel May 20, 2024
14 checks passed
@JulyIghor
Copy link

Hi, does anyone know how to make it work with password fields in a browser like a chrome?

@seflerZ
Copy link
Contributor Author

seflerZ commented Jun 15, 2024

This feature takes advantage of iBus input. Have you tested whether iBus works with the password field?

@JulyIghor
Copy link

JulyIghor commented Jun 15, 2024

This feature takes advantage of iBus input. Have you tested whether iBus works with the password field?

iBus not works for me with password fields in chrome, maybe because of the custom engine, I don't know, but I would like to find a way to fix it, is it working for you?

@seflerZ
Copy link
Contributor Author

seflerZ commented Jun 16, 2024

@JulyIghor I'm using Microsoft Edge, but I think it's similar. I don't have problems about password input fields.

@JulyIghor
Copy link

@JulyIghor I'm using Microsoft Edge, but I think it's similar. I don't have problems about password input fields.

Thanks for confirming, did you try to enter non latin characters?

@seflerZ
Copy link
Contributor Author

seflerZ commented Jun 17, 2024

@JulyIghor Sorry, no. I think it is the field's word limitation which prevent you from entering non-latin passwords. Usually this is enforced by the website programmer or JS framework.

@JulyIghor
Copy link

@JulyIghor Sorry, no. I think it is the field's word limitation which prevent you from entering non-latin passwords. Usually this is enforced by the website programmer or JS framework.

I pushed latin characters via iBus and they are still ignored. Maybe it is some security feature forcing to use XIM for passwords.
Thanks for confirming that

@mengsongshan
Copy link

mengsongshan commented Aug 29, 2024

@seflerZ
I had a problem when I used this feature. I'm using Ubuntu 22.04 LTS desktop.
Chinese input does not work sometimes. View the following logs:

8月 29 14:29:23 qingteng /usr/libexec/gdm-wayland-session[1523]: dbus-daemon[1523]: [session uid=132 pid=1523] Activating service name='org.freedesktop.portal.IBus' requested by ':1.35' (uid=132 pid=2191 c>
8月 29 14:29:23 qingteng /usr/libexec/gdm-wayland-session[1523]: dbus-daemon[1523]: [session uid=132 pid=1523] Successfully activated service 'org.freedesktop.portal.IBus'
8月 29 14:29:44 qingteng xrdp-chansrv[2331]: [ERROR] [xrdp_input_unicode_init(input_ibus.c:232)] xrdp_ibus_init: Timed out waiting for iBus daemon
8月 29 14:29:45 qingteng systemd[2301]: Starting IBus Daemon for GNOME...
8月 29 14:29:45 qingteng dbus-daemon[2317]: [session uid=1000 pid=2317] Activating service name='org.freedesktop.portal.IBus' requested by ':1.65' (uid=1000 pid=2674 comm="/usr/bin/ibus-daemon --panel disa>
8月 29 14:29:45 qingteng systemd[2301]: Started IBus Daemon for GNOME.
8月 29 14:29:45 qingteng dbus-daemon[2317]: [session uid=1000 pid=2317] Successfully activated service 'org.freedesktop.portal.IBus'
8月 29 14:30:07 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_unicode_init(input_ibus.c:237)] xrdp_ibus_init: Initializing the iBus engine
8月 29 14:30:07 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_unicode_init(input_ibus.c:248)] xrdp_ibus_init: iBus connected
8月 29 14:32:26 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_ibus_engine_enable(input_ibus.c:94)] xrdp_ibus_engine_enable: IM enabled
8月 29 14:32:26 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_enable(input_ibus.c:70)] xrdp_ibus_init: input method switched sucessfully, old input name: xkb:us::eng
8月 29 14:36:03 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_unicode_destroy(input_ibus.c:197)] xrdp_input_unicode_destory: ibus engine rolling back to origin: xkb:us::eng
8月 29 14:36:03 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_ibus_engine_disable(input_ibus.c:101)] xrdp_ibus_engine_disable: IM disabled
8月 29 14:36:05 qingteng xrdp-chansrv[2331]: An object is already exported for the interface org.freedesktop.IBus.Service at /org/freedesktop/IBus/Factory
8月 29 14:36:05 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_unicode_init(input_ibus.c:237)] xrdp_ibus_init: Initializing the iBus engine
8月 29 14:36:05 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_unicode_init(input_ibus.c:248)] xrdp_ibus_init: iBus connected
8月 29 14:36:13 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_enable(input_ibus.c:70)] xrdp_ibus_init: input method switched sucessfully, old input name: xkb:us::eng
8月 29 14:36:13 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_ibus_engine_enable(input_ibus.c:94)] xrdp_ibus_engine_enable: IM enabled
8月 29 14:36:13 qingteng xrdp-chansrv[2331]: ibus_engine_commit_text: assertion 'IBUS_IS_ENGINE (engine)' failed
8月 29 14:36:13 qingteng xrdp-chansrv[2331]: ibus_engine_commit_text: assertion 'IBUS_IS_ENGINE (engine)' failed
8月 29 14:36:13 qingteng xrdp-chansrv[2331]: ibus_engine_commit_text: assertion 'IBUS_IS_ENGINE (engine)' failed
8月 29 14:36:13 qingteng xrdp-chansrv[2331]: ibus_engine_commit_text: assertion 'IBUS_IS_ENGINE (engine)' failed
8月 29 14:36:42 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_unicode_destroy(input_ibus.c:197)] xrdp_input_unicode_destory: ibus engine rolling back to origin: xkb:us::eng
8月 29 14:36:42 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_ibus_engine_disable(input_ibus.c:101)] xrdp_ibus_engine_disable: IM disabled
8月 29 14:36:44 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_unicode_init(input_ibus.c:237)] xrdp_ibus_init: Initializing the iBus engine
8月 29 14:36:44 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_unicode_init(input_ibus.c:248)] xrdp_ibus_init: iBus connected
8月 29 14:36:44 qingteng xrdp-chansrv[2331]: An object is already exported for the interface org.freedesktop.IBus.Service at /org/freedesktop/IBus/Factory
8月 29 14:36:55 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_ibus_engine_enable(input_ibus.c:94)] xrdp_ibus_engine_enable: IM enabled
8月 29 14:36:55 qingteng xrdp-chansrv[2331]: [INFO ] [xrdp_input_enable(input_ibus.c:70)] xrdp_ibus_init: input method switched sucessfully, old input name: xkb:us::eng

ibus_engine_commit_text: assertion 'IBUS_IS_ENGINE (engine)' failed . --- always this error.

截图20240829202707

I looked at the process information on the system , both gnome-shell and systemctl started an ibus process at the same time. When I disable the ibus process started by systemctl, the effect is the same. I don't know what the problem is. I'm not familiar with ibus. Can you help me analyze it?

@seflerZ
Copy link
Contributor Author

seflerZ commented Aug 29, 2024

@mengsongshan Open an issue if you encountered problems. The log tells everything goes, but the assersion fail unexpectly. You can describe the issue with more details. That is, can you input the ASCII text only or totally unavailable.

@matt335672
Copy link
Member

Agreed - we need a separate issue to look into this.

@mengsongshan
Copy link

mengsongshan commented Aug 31, 2024

@mengsongshan Open an issue if you encountered problems. The log tells everything goes, but the assersion fail unexpectly. You can describe the issue with more details. That is, can you input the ASCII text only or totally unavailable.

input the ASCII text no pro. I'm going to sort out the various scenarios, analyze the causes, and if I'm going to determine the various scenarios of the problem, I'm opening a issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Unicode Keyboard events in xrdp
5 participants