linux下软件无法输入中文的完美解决方案:对话框+wl-clipboard+xdotool (输入法)
kimpannel
gnome-shell安装此拓展即可,不用看下面废话
https://extensions.gnome.org/extension/261/kimpanel/
症状
- blender(wayland支持fcitx5输入法,但x11下不行)
- ue for linux (5.3)
- reaper等
由于没有处理&编译linux下与输入法相关的.so文件,无法切换中文输入法。
但只要输入框支持复制、粘贴Ctrl+C/ V,就能用下面的方法。
需要
- zenity/yad/kdialog(有拉伸窗口,位置乱跳bug)
- wayland下需要手动安装 ydotool
脚本+快捷键
#!/bin/bash sleep 0.3 # wait for user release the key first if [ -n "$WAYLAND_DISPLAY" ]; then #https://askubuntu.com/questions/1413829/how-can-i-install-and-use-the-latest-ydotool-keyboard-automation-tool-working-o cc="ydotool key 29:1 46:1 46:0 29:0" # cat /usr/include/linux/input-event-codes.h | grep KEY_LEFTCTRL cv="ydotool key 29:1 47:1 47:0 29:0" c="wl-copy -n" v="wl-paste -n" else cc="xdotool key ctrl+c" cv="xdotool key ctrl+v" c="xclip -selection clipboard -r" v="$c -o" fi _PPID=$(ps -o ppid= -p $$) PARENT=$(ps -o comm= -p $_PPID) TERMINAL=(sh termina onsole tty tilix) for i in "${TERMINAL[@]}"; do if [[ "$PARENT" == *"$i"* ]]; then cc= break fi done $cc t="$($v)" lines=$(echo -n "$t"|wc -l) if [ $lines -ge 1 ]; then input=(--height=$((lines*18+30)) --text-info --editable ) #multi_line #input="--wrap --brackets --line-num --line-hl $input" #yad only #input="--smart-he=always --smart-bs $input" #yad only when coding, https://yad-guide.ingk.se/text/yad-text.html#_smart_hetype TITLE="Ctrl+Enter/Alt+O to paste" else input=(--entry --entry-text "${t[*]}") #single_line TEXT=$t fi zen=(zenity --title="${TITLE[*]}" --text="${TEXT[*]}") yad=(yad --title="${TITLE:-$TEXT}" --wrap --no-buttons --mouse) # --no-buttons set -o pipefail -x echo -n "${t[*]}"| "${yad[@]}" --width=800 "${input[@]}" | $c # 我比较喜欢用yad if [ $? -ne 0 ]; then exit 1; fi sleep 0.1 ; $cv
杂
- 穿参数,最好用数组
args=(argA argB)
+"${args[@]}"
或"${text[*]}"
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步