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

Wayland related modifications #5

Open
wants to merge 17 commits into
base: im-support
Choose a base branch
from

Conversation

xfangfang
Copy link

The content of this PR has only been tested under textInputV3, as my understanding of Wayland is limited, so it may contain issues.

1. Improves

The current Wayland implementation defaults to automatically enabling the input method when the application starts, leading to:

Therefore, I directly removed the keyboard activation functions of textInputV1Enter and textInputV3Enter, and at the same time, simply implemented the IME status-related functions, allowing users to enable or disable the keyboard through glfwSetInputMode.

2. Fix for endless preedit cursor update

While implementing the above, I found that textInputV3Done is called repeatedly after the application starts.

After reading the documentation:

  • When the client receives a done event with a serial different
  • than the number of past commit requests, it must proceed with
  • evaluating and applying the changes as normal, except it should
  • not change the current state of the zwp_text_input_v3 object.

I made a simple adjustment, calling zwp_text_input_v3_set_cursor_rectangle / zwp_text_input_v1_set_cursor_rectangle only when the coordinates change. As I tested with an on-screen keyboard, I am not sure if it will affect the other input method, but it did indeed stop the loop of textInputV3Done being called repeatedly.

daipom and others added 17 commits April 2, 2024 08:38
This fix is based on shibukawa's fix:
  glfw#658
  shibukawa@d36a164

Some minor coding style changes are made, but not yet follow glfw's one,
and some comments doesn't follow recent changes. So further work is
needed.

Co-authored-by: Yoshiki Shibukawa <[email protected]>
Co-authored-by: Takuro Ashie <[email protected]>
This commit re-organizes 9d9af13.

* Use dynamic load for Imm32.
* Generalize platform-specific features to _GLFWplatform.
* Add caret-position info to preedit-callback.
* Add cursorWidth to preeditCursor and related APIs.
* Handle UTF16 data correctly.
* Handle GCS_RESULTSTR so that committed texts are processed correctly.
* Handle WM_IME_ENDCOMPOSITION to clear preedit.
* Handle WM_IME_SETCONTEXT.
    * https://learn.microsoft.com/en-us/windows/win32/intl/wm-ime-setcontext#remarks
* Refactor code shapes and variable names.

Co-authored-by: Takuro Ashie <[email protected]>
This fix is based on shibukawa's fix:
  glfw#658
  shibukawa@d36a164

Co-authored-by: Yoshiki Shibukawa <[email protected]>
Co-authored-by: Takuro Ashie <[email protected]>
This commit re-organizes 31b12b7.

* Use dynamic load for TIS functions and stop using Carbon.
* Generalize platform-specific features to _GLFWplatform.
* Add caret-position info to preedit-callback.
* Handle UTF16 data correctly.
* Implement `firstRectForCharacterRange:actualRange:` to display preedit candidate window correctly.
* Suppress _glfwInputKey during preediting.
* Ensure preedit cleared after committed.
* Fix wrong length of markedRange.
* Improve IME status APIs.
* Refactor code shapes and variable names.

Co-authored-by: Takuro Ashie <[email protected]>
Co-authored-by: xfangfang <[email protected]>
This fix is based on shibukawa's fix:
  glfw#658

The differences is the following.

* Remove `X_HAVE_UTF8_STRING` branching since the current logic doesn't use it
* Replace `XNDestroyCallback` for `XNPreeditAttributes` in `XCreateIC`

Co-authored-by: Yoshiki Shibukawa <[email protected]>
Co-authored-by: Takuro Ashie <[email protected]>
This commit re-organizes 6e7f939.

* Load missing XIM related function symbols.
* Generalize platform-specific features to _GLFWplatform.
* Change the defalut input style to over-the-spot style.
* Rename `decodeUTF8()` to `_glfwDecodeUTF8()` to make it as internal API.
    * It will be also needed to implment input method for Wayland.
* Refactor code shapes and variable names.

About over-the-spot style and on-the-spot style on X11:

* In over-the-spot mode, almost all APIs are disabled since applications only
  need to specify the preedit candidate window position by `glfwSetPreeditCursorPos()`.
* We can change the style by enabling `GLFW_X11_ONTHESPOT` init hint, but it
  has the following problems.
    * Status APIs don't work because status callbacks don't work.
      (at least in my ibus environment).
    * Can't specify the candidate window position.

Known problems:

* Some keys (arrow, Enter, BackSpace, ...) are passed to applications during preediting.
    * This will be fixed in PR glfw#1972 : glfw#1972

Co-authored-by: Takuro Ashie <[email protected]>
They are wayland protocols to support input methods:
https://cgit.freedesktop.org/wayland/wayland-protocols/tree/unstable/text-input/text-input-unstable-v3.xml
https://cgit.freedesktop.org/wayland/wayland-protocols/tree/unstable/text-input/text-input-unstable-v1.xml

text_input_unstable_v3 is widely supported by major desktop environment
on GNU/Linux such as GNOME or KDE.

text_input_unstable_v1 isn't so popular but Weston which is the
reference Wayland implementation supports only it and doesn't support
text_input_unstable_v3 so that we also implement it.
new

- Daijiro Fukuda
- Ryo Ichinose (from glfw#658)
- Yasutaka Kumei (from glfw#658)
- xfangfang

already in the list

- Takuro Ashie
- Yoshiki Shibukawa
You can use this feature when you need to manage the drawing of
the preedit candidates on the application side.
Load it dynamically instead.
@ashie
Copy link
Member

ashie commented Sep 18, 2024

While implementing the above, I found that textInputV3Done is called repeatedly after the application starts.

After reading the documentation:

  • When the client receives a done event with a serial different
  • than the number of past commit requests, it must proceed with
  • evaluating and applying the changes as normal, except it should
  • not change the current state of the zwp_text_input_v3 object.

ref: https://wayland.app/protocols/text-input-unstable-v3#zwp_text_input_v3:event:done

@ashie
Copy link
Member

ashie commented Sep 18, 2024

Thanks for your feedback!

  1. Fix for endless preedit cursor update

The fix for this issue looks good.

  1. Improves

I have some concerns on this fix.
It seems that it introduces different UX with other platform especially Windows.
(We consider that the Windows backend is the reference implementation of multi-platform IM feature.)
In this context, IM can be always enabled or disabled by one of these elements:

  • Short keys
  • Panel UI provided by IM frame work
  • Application

and the status should be synchronized no matter what element you use.
But this fix doesn't seem synchronized, and only the application can enable IM at start up.

@xfangfang
Copy link
Author

It seems that it introduces different UX with other platform especially Windows.

This is indeed a problem. I have only tested the touchscreen experience in the Wayland desktop environment (SteamDeck) of KDE, and have not found a way to manually turn off the on-screen keyboard. I have also not tested the support for other input methods.

I may install Wayland on my new computer for more detailed testing in about a week or two.

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.

4 participants