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

input: Handling multiple surfaces for the text-input-v1 protocol implementation and imporve InputMethodRelay logic #5147

Merged
merged 3 commits into from Mar 19, 2024

Conversation

sujoshua
Copy link
Contributor

Describe your PR, what does it fix/add?

This PR addresses the issue where the text-input-v1 protocol could not handle cases where a client creates multiple TextInput.

The case one client creates multiple TextInput is common. e.g. chromium-based client applications create a TextInput for each separate surface. They then send activate request with surface param which indirectly specifies the TextInput. Because every TextInput object is bind to specific surface.

Previously, the code iterated through a linked list and returned upon finding a match by comparing the current focus surface's client with TextInput's client. This approach always returned the first matched TextInput, whose internal surface pointed to a different surface rather than the current focus surface. This was the root cause of issue #2708.

Moreover, the original code heavily relied on iterating through linked list is not so efficient comparing to a hash lookup way. Therefore, in the InputMethodRelay, a map from surface -> TextInput has been established, centered around the surface. The InputMethodRelay now records the current focus surface, enabling the retrieval of TextInput based on the surface. Consequently, the logic for pendingSurface in the original code has been removed, as the TextInput can now be obtained at any time through the focused surface.

About issue #2708 mentioned

Similar to the behavior of versions below electron21 mentioned at [WIP] text-input-v1 support #1778 .

yeah it's the same problem. It seems that electron below electron 21 will create a transparent surface. So in former implementation, we always caught that transparent surface's TextInput.

Is there anything you want to mention? (unchecked code, possible bugs, found problems, breaking compatibility, etc.)

Firstly, I rarely write C++, so there might be some naive mistakes. Please forgive me ~. Though this patch has been running on my main computer for two days without any issues.

Secondly, there's a comment in the InputMethodRelay.cpp code marked "BUG POSSIBLE". This is because the logic for handling surfaces in text-input-v3 is quite different from v1. It requires the server to proactively inform the client. Apart from using the client for matching, I can't think of a better method. However, using the client for matching is the original code's method, so the issue mentioned for text-input-v3 still persists. But as far as the user experience with Kitty is concerned, there doesn't seem to be any major problem.

Is it ready for merging, or does it need work?

yeah

test_text-input-v1.mp4

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

generally looks good, though needs a clang-format for sure.

src/managers/input/InputMethodRelay.cpp Outdated Show resolved Hide resolved
src/managers/input/InputMethodRelay.cpp Outdated Show resolved Hide resolved
src/managers/input/InputMethodRelay.cpp Outdated Show resolved Hide resolved
src/managers/input/InputMethodRelay.cpp Outdated Show resolved Hide resolved
Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

also it's still not clang-formatted

src/managers/input/InputMethodRelay.cpp Outdated Show resolved Hide resolved
src/managers/input/InputMethodRelay.cpp Outdated Show resolved Hide resolved
src/managers/input/InputMethodRelay.cpp Show resolved Hide resolved
src/managers/input/InputMethodRelay.cpp Outdated Show resolved Hide resolved
src/managers/input/InputMethodRelay.cpp Outdated Show resolved Hide resolved
@sujoshua
Copy link
Contributor Author

Sorry, It seems that I've picked up some bad habits from writing too much Go.

@sujoshua sujoshua requested a review from vaxerski March 19, 2024 08:23
@vaxerski
Copy link
Member

generally lgtm, but I'll clang-format it for you cuz it still isn't, lol

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

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

thanks a lot!

I've ran clang-format, rebased and fixed a few style nits. Should be gtg once tests pass.

@vaxerski vaxerski merged commit 5c1097c into hyprwm:main Mar 19, 2024
9 checks passed
@cold-bin
Copy link

good job👍🏻

lisuke pushed a commit to lisuke/Hyprland that referenced this pull request Apr 15, 2024
* input: Handling multiple surfaces for the text-input-v1 protocol implementation and imporve InputMethodRelay logic

fixes hyprwm#2708

* clang-format

* minor style nits

---------

Co-authored-by: Vaxry <vaxry@vaxry.net>
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

3 participants