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

Enable Gboard CJK keyboards #620

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

knyipab
Copy link
Contributor

@knyipab knyipab commented May 2, 2024

Relates to #115 and #147.

Add a preference option "Workaround to enable CJK Gboard".

  • The issue of Gboard IME showing up as QWERTY affects mostly only CJK keyboards.
  • Tested on my Samsung Z Fold5, Android 14. Gboard 14.1.04.621126403-release-arm64-v8a.
  • It is made as a preferences.xml option because the impact on other IMEs is not well known and there may be side effects. API to detect current IME in use InputMethodManager#getCurrentInputMethodInfo() is not available until recent API level (34).

@knyipab knyipab closed this May 3, 2024
@knyipab
Copy link
Contributor Author

knyipab commented May 3, 2024

Incorrect text UTF8 text sometimes sent to X clients. Not a bug of this commit, instead there are likely some problems in mInjector.sendTextEvent(). Lemme investigate and will reopen after fixing.

@knyipab
Copy link
Contributor Author

knyipab commented May 4, 2024

Cannot reproduce the aforementioned bug after re-runtermux-x11 command in Termux. In addition, it's not a bug of this PR, so I re-open this PR.

Only for record: as far as I can tell, there may be bug in XCB receiver side. Log by Java_com_termux_x11_LorieView_sendTextEvent shows that correct character is sent. However, incorrect characters shown in XFCE DE is some characters that was typed before. I tested that termux-x11 session for more than a day and perhaps changes some internal state of XCB receiver side, causing the bug. Anyways, I can't reproduce that at the moment.

@knyipab knyipab reopened this May 4, 2024
@knyipab
Copy link
Contributor Author

knyipab commented May 4, 2024

Sorry for confusion. I will stop editing here and look for @twaik your comments on this "Workaround to enable CJK Gboard" option.

More testing are done as below.

Device Android Ver. GBoard Ver. LangTag detection to activate CJK Gboard
Samsung Z Fold5 14 14.1.04.621126403-release-arm64-v8a Working
Samsung S21 14 14.0.11.612796517-release-arm64-v8a Working
Pixel 4a 13 14.0.11.612796517-release-arm64-v8a Not working, blank getLanguageTag()
Pixel 4a 13 14.1.04.621126403-release-arm64-v8a Not working, blank getLanguageTag()
Emulated (AVD Pixel 4) 13 14.1.04.621126403-release-x86_64 Not working, blank getLanguageTag()
Emulated (AVD Pixel 8) 14 12.4.05.482060964-preload-x86_64 Not working, blank getLanguageTag() and requestCursorUpdates() not even called
Emulated (AVD Pixel 8) 14 14.1.04.621126403-release-x86_64 Working

This workaround is by no mean elegant but probably the only existing workaround siince being last discussed in 2021 termux/termux-app#1539. Bit more context of the problem and welcome smarter workaround: the TYPE_TEXT_VARIATION_NORMAL can enable CJK, emoji and clipboard input from Gboard, but at the same time activates Gboard word suggestion causing backspace not working and the word suggestion can be suppressed through restartInput()/invalidateInput(), but does not work well for non-CJK Gboard such as English (when type fast and two keypresses commitText() so close in time, one of them will be ignored). Therefore, the getLanguageTag() detection is a workaround to set TYPE_TEXT_VARIATION_NORMAL only when it is needed (i.e. CJK IME).

Grateful for merging given importance to Gboard CJK users. I don't mind putting it onto an "Experimental" section of perefernces.xml. Thanks.

@twaik
Copy link
Member

twaik commented May 8, 2024

Relates to #115 and #147.

Not related.
That happened because Xwayland (used a long time ago) did not have any instruments to input custom Unicode symbols which are not in current keymap.

Only for record: as far as I can tell, there may be bug in XCB receiver side.

There is no "XCB receiver" in termux-x11. There is some custom light weight protocol to avoid XCB dependency (which adds 1MB+ for every architecture variant and 4.5MB to universal build).

However, incorrect characters shown in XFCE DE is some characters that was typed before.

Termux:X11 sends characters the same way tigervnc-server and x11vnc do. It maps characters to keycodes with no associated keysyms (

static const KeyCode fakeKeys[] = {
92, 203, 204, 205, 206, 207
};
) and sends key event to application. This method is not really reliable but it works for most text editors and does not interfere with existing hotkey handling implementations.

I did not find better way to implement this, x11vnc way is the best option I found.

@knyipab
Copy link
Contributor Author

knyipab commented May 9, 2024

Thanks. Since the bug is really not a problem of this PR and neither Gboard, I opened #625 for test result and further discussion.

Back to this PR, I tested together with #617 (which makes available the 3-finger swipe up gesture to activate soft keyboard in DeX mode) and commit another workaround for DeX mode in which InputConnection#requestCursorUpdates() is not called by Gboard at all.

Any adjustment to this PR you would like me to do before merging?

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.

None yet

2 participants