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

video/out/wayland_common: support IME usage via text-input-v3 #15707

Merged
merged 1 commit into from
Jan 25, 2025

Conversation

layercak3
Copy link
Contributor

This is useful for text input in, for example, console.lua. Each character in the commit string gets turned into an mpv key press. Pre-edit strings are not handled, since there's currently no good way to handle that or make it useful to text input scripts. Like win32, which I tested in wine, another limitation is that the composition window is always positioned at the top left of the window, since we cannot get useful positioning hints from mpv scripts. It allows the composition window to be within the window and avoids obstructing the console prompt.

This can be enabled/disabled with --wayland-ime=<yes|no> (default: yes).

Copy link

github-actions bot commented Jan 19, 2025

Download the artifacts for this pull request:

Windows
macOS

@layercak3
Copy link
Contributor Author

The amount of utf-8 characters that get added to the console.lua prompt seems to be a maximum of 7 for me. If the commit string is submitted while the console is hidden, log messages input: No key binding found for key correctly get printed for all characters in the commit string, so this seems like a problem with how input is getting fed to into the scripts.

Similar happens with win32 on wine, though only when the video is playing, and the amount of characters that get added to the prompt differs randomly. If the video is paused, all characters get added to the console prompt.
Also with the terminal cplayer on linux, if I paste some text, only the first few characters appear on the prompt. Definitely a bug with how input gets fed into scripts.

@na-na-hi
Copy link
Contributor

The amount of utf-8 characters that get added to the console.lua prompt seems to be a maximum of 7 for me.

The limit can be changed with --input-key-fifo-size.

@layercak3
Copy link
Contributor Author

The limit can be changed with --input-key-fifo-size.

Ah, that fixes it. Thanks.

DOCS/man/options.rst Outdated Show resolved Hide resolved
@Dudemanguy
Copy link
Member

Dudemanguy commented Jan 23, 2025

Just adding this makes runtime toggling work more intuitively.

diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index 6f6b10a0de..06a157b4b5 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -2833,6 +2833,30 @@ static void toggle_fullscreen(struct vo_wayland_state *wl)
     }
 }
 
+static void toggle_ime(struct vo_wayland_state *wl)
+{
+    struct vo_wayland_seat *seat;
+    wl_list_for_each(seat, &wl->seat_list, link) {
+        struct vo_wayland_text_input *ti = seat->text_input;
+        if (!ti)
+            continue;
+        if (wl->opts->wl_ime) {
+            zwp_text_input_v3_enable(ti->text_input);
+            zwp_text_input_v3_set_content_type(
+                ti->text_input,
+                ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE,
+                ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL);
+            zwp_text_input_v3_set_cursor_rectangle(ti->text_input, 0, 0, 0, 0);
+            zwp_text_input_v3_commit(ti->text_input);
+            ti->serial++;
+        } else {
+            zwp_text_input_v3_disable(ti->text_input);
+            zwp_text_input_v3_commit(ti->text_input);
+            ti->serial++;
+        }
+    }
+}
+
 static void toggle_maximized(struct vo_wayland_state *wl)
 {
     if (wl->opts->window_maximized) {
@@ -3024,6 +3048,8 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
                 set_content_type(wl);
             if (opt == &opts->cursor_passthrough)
                 set_input_region(wl, opts->cursor_passthrough);
+            if (opt == &opts->wl_ime)
+                toggle_ime(wl);
             if (opt == &opts->fullscreen)
                 toggle_fullscreen(wl);
             if (opt == &opts->window_maximized)

Probably just split off the enable/disable stuff into separate functions to avoid code duplication.

@layercak3
Copy link
Contributor Author

Thanks, added this change. For me, when I enable it with a command while not having the surface focused, the compositor doesn't enable the IME when I enable it again on the next enter event (then on the next enter event after that, the compositor enables the IME). So I won't enable it whilst not having focus since that seems to cause issues, and is redundant as it will be enabled on the coming enter event.

@Dudemanguy
Copy link
Member

Ah that's logical. I didn't test that specific case. I think this takes care of all the functionality now.

DOCS/man/options.rst Outdated Show resolved Hide resolved
Copy link
Member

@Dudemanguy Dudemanguy left a comment

Choose a reason for hiding this comment

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

Sorry I forgot but could you also add an entry under interface-changes documenting the addition?

This is useful for text input in, for example, console.lua. Each
character in the commit string gets turned into an mpv key press.
Pre-edit strings are not handled, since there's currently no good way to
handle that or make it useful to text input scripts. Like win32, which I
tested in wine, another limitation is that the composition window is
always positioned at the top left of the window, since we cannot get
useful positioning hints from mpv scripts. It allows the composition
window to be within the window and avoids obstructing the console
prompt.

This can be enabled/disabled with --input-ime=<yes|no> (default: yes).
Copy link
Member

@Dudemanguy Dudemanguy left a comment

Choose a reason for hiding this comment

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

Thanks again.

@Dudemanguy Dudemanguy merged commit 51dc628 into mpv-player:master Jan 25, 2025
27 checks passed
@layercak3 layercak3 deleted the wayland-ime branch January 25, 2025 03:39
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.

3 participants