Emotional Code|

Nolca

园龄:6年9个月粉丝:12关注:9

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[*]}"

本文作者:Nolca

本文链接:https://www.cnblogs.com/nolca/p/18654305

版权声明:本作品采用 收益分享revenue sharing 许可协议进行许可。

posted @   Nolca  阅读(71)  评论(0编辑  收藏  举报
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 ⏩intro 山姆精
  2. 2 🎸吉他 马叉
  3. 3 ☁升调 山姆精
  4. 4 🐦Flutter Virtual Riot/Madi
  5. 5 🎶纯律 山姆精
  6. 6 👻yeah~Color Bass! VR
⏩intro - 山姆精
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.
点击右上角即可分享
微信分享提示