From d07713ba573cdae204216b628455b84231258f57 Mon Sep 17 00:00:00 2001 From: 0xmoonlight <0xmoonlight@protonmail.com> Date: Sun, 15 Feb 2026 22:17:39 +0200 Subject: [PATCH] Add IME input support for mpv chat via mp.input API Use mpv's native mp.input.get() text input (available in mpv 0.39+) which properly supports IME composition for Chinese, Japanese, Korean and other input methods. Falls back to existing key-binding system for older mpv. Also enables --input-ime=yes in mpv launch args (mpv defaults to no on Windows) so IME is active when text input is opened. Closes #732 Co-Authored-By: Claude Opus 4.6 --- syncplay/constants.py | 1 + syncplay/resources/syncplayintf.lua | 43 ++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/syncplay/constants.py b/syncplay/constants.py index 32937f72..4e5432e9 100755 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -273,6 +273,7 @@ def getValueForOS(constantDict): 'hr-seek': 'always', 'keep-open': 'always', 'input-terminal': 'no', + 'input-ime': 'yes', 'term-playing-msg': '\nANS_filename=${filename}\nANS_length=${=duration:${=length:0}}\nANS_path=${path}\n', 'keep-open-pause': 'yes' } diff --git a/syncplay/resources/syncplayintf.lua b/syncplay/resources/syncplayintf.lua index c4d822a6..d0cf9bff 100644 --- a/syncplay/resources/syncplayintf.lua +++ b/syncplay/resources/syncplayintf.lua @@ -54,6 +54,9 @@ local assdraw = require "mp.assdraw" local opt = require 'mp.options' +local has_mp_input = (mp.input ~= nil) +local using_native_input = false + local repl_active = false local insert_mode = false local line = '' @@ -459,7 +462,7 @@ function update() end function input_ass() - if not repl_active then + if using_native_input or not repl_active then return "" end last_chat_time = mp.get_time() -- to keep chat messages showing while entering input @@ -765,8 +768,42 @@ function maybe_exit() end end +-- Send a chat line to the Python client via print-text +function send_chat_line(text) + if text == nil or text == '' then + return + end + text = string.gsub(text, "\\", "\\\\") + text = string.gsub(text, "\"", "\\\"") + mp.command('print-text "'..text..'"') +end + +-- Open native text input using mp.input.get() (mpv 0.39+) +-- Supports IME composition for CJK and other input methods +function open_native_input() + using_native_input = true + last_chat_time = mp.get_time() + mp.input.get({ + prompt = opts['inputPromptStartCharacter'] .. " ", + submit = function(text) + send_chat_line(text) + using_native_input = false + end, + closed = function() + using_native_input = false + end, + }) +end + -- Run the current command and clear the line (Enter) function handle_enter() + if has_mp_input then + if not using_native_input then + open_native_input() + end + return + end + if not repl_active then set_active(true) return @@ -777,9 +814,7 @@ function handle_enter() return end key_hints_enabled = false - line = string.gsub(line,"\\", "\\\\") - line = string.gsub(line,"\"", "\\\"") - mp.command('print-text "'..line..'"') + send_chat_line(line) clear() end